Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ada41b0

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
repl: make console, module and require non-enumerable
This aligns these globals with the regular context. PR-URL: #20717 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 5ffce3e commit ada41b0
Copy full SHA for ada41b0

File tree

Expand file treeCollapse file tree

8 files changed

+36
-75
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+36
-75
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ REPLServer.prototype.createContext = function() {
793793
const _console = new Console(this.outputStream);
794794
Object.defineProperty(context, 'console', {
795795
configurable: true,
796-
enumerable: true,
796+
writable: true,
797797
value: _console
798798
});
799799

@@ -813,9 +813,16 @@ REPLServer.prototype.createContext = function() {
813813
module.paths =
814814
CJSModule._resolveLookupPaths('<repl>', parentModule, true) || [];
815815

816-
var require = makeRequireFunction(module);
817-
context.module = module;
818-
context.require = require;
816+
Object.defineProperty(context, 'module', {
817+
configurable: true,
818+
writable: true,
819+
value: module
820+
});
821+
Object.defineProperty(context, 'require', {
822+
configurable: true,
823+
writable: true,
824+
value: makeRequireFunction(module)
825+
});
819826

820827
addBuiltinLibsToObject(context);
821828

Collapse file

‎test/parallel/test-repl-console.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-console.js
-44Lines changed: 0 additions & 44 deletions
This file was deleted.
Collapse file

‎test/parallel/test-repl-context.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-context.js
+23-16Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,39 @@ const assert = require('assert');
44
const repl = require('repl');
55
const vm = require('vm');
66

7-
// Create a dummy stream that does nothing
7+
// Create a dummy stream that does nothing.
88
const stream = new common.ArrayStream();
99

10-
// Test when useGlobal is false
11-
testContext(repl.start({
12-
input: stream,
13-
output: stream,
14-
useGlobal: false
15-
}));
10+
// Test context when useGlobal is false.
11+
{
12+
const r = repl.start({
13+
input: stream,
14+
output: stream,
15+
useGlobal: false
16+
});
1617

17-
function testContext(repl) {
18-
const context = repl.createContext();
19-
// ensure that the repl context gets its own "console" instance
18+
// Ensure that the repl context gets its own "console" instance.
19+
assert(r.context.console);
20+
21+
// Ensure that the repl console instance is not the global one.
22+
assert.notStrictEqual(r.context.console, console);
23+
24+
const context = r.createContext();
25+
// Ensure that the repl context gets its own "console" instance.
2026
assert(context.console instanceof require('console').Console);
2127

22-
// ensure that the repl's global property is the context
28+
// Ensure that the repl's global property is the context.
2329
assert.strictEqual(context.global, context);
2430

25-
// ensure that the repl console instance does not have a setter
26-
assert.throws(() => context.console = 'foo', TypeError);
27-
repl.close();
31+
// Ensure that the repl console instance is writable.
32+
context.console = 'foo';
33+
r.close();
2834
}
2935

30-
testContextSideEffects(repl.start({ input: stream, output: stream }));
36+
// Test for context side effects.
37+
{
38+
const server = repl.start({ input: stream, output: stream });
3139

32-
function testContextSideEffects(server) {
3340
assert.ok(!server.underscoreAssigned);
3441
assert.strictEqual(server.lines.length, 0);
3542

Collapse file

‎test/parallel/test-repl-function-definition-edge-case.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-function-definition-edge-case.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// Reference: https://github.com/nodejs/node/pull/7624
22
'use strict';
3-
const common = require('../common');
3+
require('../common');
44
const assert = require('assert');
55
const repl = require('repl');
66
const stream = require('stream');
77

8-
common.globalCheck = false;
9-
108
const r = initRepl();
119

1210
r.input.emit('data', 'function a() { return 42; } (1)\n');
Collapse file

‎test/parallel/test-repl-let-process.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-let-process.js
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
const common = require('../common');
33
const repl = require('repl');
44

5-
common.globalCheck = false;
6-
75
// Regression test for https://github.com/nodejs/node/issues/6802
86
const input = new common.ArrayStream();
97
repl.start({ input, output: process.stdout, useGlobal: true });
Collapse file

‎test/parallel/test-repl-mode.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-mode.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
'use strict';
2-
const common = require('../common');
2+
require('../common');
33
const assert = require('assert');
44
const Stream = require('stream');
55
const repl = require('repl');
66

7-
common.globalCheck = false;
8-
97
const tests = [
108
testSloppyMode,
119
testStrictMode,
Collapse file

‎test/parallel/test-repl-options.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-options.js
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ const common = require('../common');
2424
const assert = require('assert');
2525
const repl = require('repl');
2626

27-
common.globalCheck = false;
28-
2927
// Create a dummy stream that does nothing
3028
const stream = new common.ArrayStream();
3129

Collapse file

‎test/parallel/test-repl-reset-event.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-reset-event.js
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
'use strict';
2323
const common = require('../common');
24-
common.globalCheck = false;
2524

2625
const assert = require('assert');
2726
const repl = require('repl');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.