| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9f6d1f6 commit fc2db50
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -721,9 +721,7 @@ REPLServer.prototype.createContext = function() { | |||
| 721 | 721 | ||
| 722 | 722 | Object.defineProperty(context, '_', { | |
| 723 | 723 | configurable: true, | |
| 724 | - get: () => { | ||
| 725 | - return this.last; | ||
| 726 | - }, | ||
| 724 | + get: () => this.last, | ||
| 727 | 725 | set: (value) => { | |
| 728 | 726 | this.last = value; | |
| 729 | 727 | if (!this.underscoreAssigned) { | |
@@ -1265,9 +1263,10 @@ function defineDefaultCommands(repl) { | |||
| 1265 | 1263 | help: 'Print this help message', | |
| 1266 | 1264 | action: function() { | |
| 1267 | 1265 | const names = Object.keys(this.commands).sort(); | |
| 1268 | - const longestNameLength = names.reduce((max, name) => { | ||
| 1269 | - return Math.max(max, name.length); | ||
| 1270 | - }, 0); | ||
| 1266 | + const longestNameLength = names.reduce( | ||
| 1267 | + (max, name) => Math.max(max, name.length), | ||
| 1268 | + 0 | ||
| 1269 | + ); | ||
| 1271 | 1270 | names.forEach((name) => { | |
| 1272 | 1271 | const cmd = this.commands[name]; | |
| 1273 | 1272 | const spaces = ' '.repeat(longestNameLength - name.length + 3); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ const stream = require('stream'); | |||
| 8 | 8 | testSloppyMode(); | |
| 9 | 9 | testStrictMode(); | |
| 10 | 10 | testResetContext(); | |
| 11 | + testResetContextGlobal(); | ||
| 11 | 12 | testMagicMode(); | |
| 12 | 13 | ||
| 13 | 14 | function testSloppyMode() { | |
@@ -131,7 +132,28 @@ function testResetContext() { | |||
| 131 | 132 | ]); | |
| 132 | 133 | } | |
| 133 | 134 | ||
| 134 | - function initRepl(mode) { | ||
| 135 | + function testResetContextGlobal() { | ||
| 136 | + const r = initRepl(repl.REPL_MODE_STRICT, true); | ||
| 137 | + | ||
| 138 | + r.write(`_ = 10; // explicitly set to 10 | ||
| 139 | + _; // 10 from user input | ||
| 140 | + .clear // No output because useGlobal is true | ||
| 141 | + _; // remains 10 | ||
| 142 | + `); | ||
| 143 | + | ||
| 144 | + assertOutput(r.output, [ | ||
| 145 | + 'Expression assignment to _ now disabled.', | ||
| 146 | + '10', | ||
| 147 | + '10', | ||
| 148 | + '10', | ||
| 149 | + ]); | ||
| 150 | + | ||
| 151 | + // delete globals leaked by REPL when `useGlobal` is `true` | ||
| 152 | + delete global.module; | ||
| 153 | + delete global.require; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + function initRepl(mode, useGlobal) { | ||
| 135 | 157 | const inputStream = new stream.PassThrough(); | |
| 136 | 158 | const outputStream = new stream.PassThrough(); | |
| 137 | 159 | outputStream.accum = ''; | |
@@ -146,7 +168,8 @@ function initRepl(mode) { | |||
| 146 | 168 | useColors: false, | |
| 147 | 169 | terminal: false, | |
| 148 | 170 | prompt: '', | |
| 149 | - replMode: mode | ||
| 171 | + replMode: mode, | ||
| 172 | + useGlobal: useGlobal | ||
| 150 | 173 | }); | |
| 151 | 174 | } | |
| 152 | 175 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments