mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Signed-off-by: Aviv Keller <me@aviv.sh> PR-URL: https://github.com/nodejs/node/pull/64034 Fixes: https://github.com/nodejs/node/issues/64523 Closes: https://github.com/nodejs/node/pull/64534 Fixes: https://github.com/nodejs/node/issues/39387 Closes: https://github.com/nodejs/node/pull/39392 Fixes: https://github.com/nodejs/node/issues/61390 Fixes: https://github.com/nodejs/node/issues/63126 Fixes: https://github.com/nodejs/node/issues/38503 Fixes: https://github.com/nodejs/node/issues/37445 Fixes: https://github.com/nodejs/node/issues/38145 Fixes: https://github.com/nodejs/node/issues/33369 Fixes: https://github.com/nodejs/node/issues/48131 Fixes: https://github.com/nodejs/node/issues/8309 Fixes: https://github.com/nodejs/node/issues/39689 Fixes: https://github.com/nodejs/node/issues/18931 Reviewed-By: Dario Piotrowicz <dario.piotrowicz@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
import '../common/index.mjs';
|
|
import assert from 'node:assert';
|
|
import vm from 'node:vm';
|
|
import { Console } from 'node:console';
|
|
import { startNewREPLServer } from '../common/repl.js';
|
|
|
|
// Test context when useGlobal is false.
|
|
{
|
|
const { replServer, output, run } = startNewREPLServer({
|
|
terminal: false,
|
|
useGlobal: false
|
|
});
|
|
|
|
// Ensure that the repl context gets its own "console" instance.
|
|
assert(replServer.context.console);
|
|
|
|
// Ensure that the repl console instance is not the global one.
|
|
assert.notStrictEqual(replServer.context.console, console);
|
|
assert.notStrictEqual(replServer.context.Object, Object);
|
|
|
|
await run('({} instanceof Object)\n');
|
|
|
|
assert.strictEqual(output.accumulator, 'true\n');
|
|
|
|
const context = replServer.createContext();
|
|
// Ensure that the repl context gets its own "console" instance.
|
|
assert(context.console instanceof Console);
|
|
|
|
// Ensure that the repl's global property is the context.
|
|
assert.strictEqual(context.global, context);
|
|
|
|
// Ensure that the repl console instance is writable.
|
|
context.console = 'foo';
|
|
replServer.close();
|
|
}
|
|
|
|
// Test for context side effects.
|
|
{
|
|
const { replServer, run } = startNewREPLServer({
|
|
useGlobal: false
|
|
});
|
|
|
|
assert.ok(!replServer.underscoreAssigned);
|
|
assert.strictEqual(replServer.lines.length, 0);
|
|
|
|
// An assignment to '_' in the repl server
|
|
await run('_ = 500;\n');
|
|
assert.ok(replServer.underscoreAssigned);
|
|
assert.strictEqual(replServer.lines.length, 1);
|
|
assert.strictEqual(replServer.lines[0], '_ = 500;');
|
|
assert.strictEqual(replServer.last, 500);
|
|
|
|
// Use the server to create a new context
|
|
const context = replServer.createContext();
|
|
|
|
// Ensure that creating a new context does not
|
|
// have side effects on the server
|
|
assert.ok(replServer.underscoreAssigned);
|
|
assert.strictEqual(replServer.lines.length, 1);
|
|
assert.strictEqual(replServer.lines[0], '_ = 500;');
|
|
assert.strictEqual(replServer.last, 500);
|
|
|
|
// Reset the server context
|
|
replServer.resetContext();
|
|
assert.ok(!replServer.underscoreAssigned);
|
|
assert.strictEqual(replServer.lines.length, 0);
|
|
|
|
// Ensure that assigning to '_' in the new context
|
|
// does not change the value in our server.
|
|
assert.ok(!replServer.underscoreAssigned);
|
|
vm.runInContext('_ = 1000;\n', context);
|
|
|
|
assert.ok(!replServer.underscoreAssigned);
|
|
assert.strictEqual(replServer.lines.length, 0);
|
|
replServer.close();
|
|
}
|