-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repl: Enable tab completion for global properties
When `useGlobal` is false, tab completion in the repl does not enumerate global properties. Instead of just setting these properties blindly on the global context, e.g. context[prop] = global[prop] Use `Object.defineProperty` and the property descriptor found on `global` for the new property in `context`. Also addresses a previously unnoticed issue where `console` is writable when `useGlobal` is false. If the binary has been built with `./configure --without-intl` then the `Intl` builtin type will not be available in a repl runtime. Check for this in the test. Fixes: #7353 PR-URL: #7369 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
1 parent
2e29b76
commit 8198dbc
Showing
4 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const repl = require('repl'); | ||
|
||
// Create a dummy stream that does nothing | ||
const stream = new common.ArrayStream(); | ||
|
||
// Test when useGlobal is false | ||
testContext(repl.start({ | ||
input: stream, | ||
output: stream, | ||
useGlobal: false | ||
})); | ||
|
||
function testContext(repl) { | ||
const context = repl.createContext(); | ||
// ensure that the repl context gets its own "console" instance | ||
assert(context.console instanceof require('console').Console); | ||
|
||
// ensure that the repl's global property is the context | ||
assert(context.global === context); | ||
|
||
// ensure that the repl console instance does not have a setter | ||
assert.throws(() => context.console = 'foo'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters