Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) lib: fix beforeExit not working with -e #9680

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@
// Defer evaluation for a tick. This is a workaround for deferred
// events not firing when evaluating scripts from the command line,
// see https://github.com/nodejs/node/issues/1600.
process.nextTick(function() {
setImmediate(function() {
var result = module._compile(script, `${name}-wrapper`);
if (process._print_eval) console.log(result);
});
Expand Down
20 changes: 8 additions & 12 deletions test/message/eval_messages.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ SyntaxError: Strict mode code may not include a with statement
at Object.exports.runInThisContext (vm.js:*)
at Object.<anonymous> ([eval]-wrapper:*:*)
at Module._compile (module.js:*:*)
at node.js:*:*
at nextTickCallbackWith0Args (node.js:*:*)
at process._tickCallback (node.js:*:*)
at Immediate._onImmediate (node.js:*:*)
at processImmediate [as _immediateCallback] (timers.js:*:*)
42
42
[eval]:1
Expand All @@ -19,9 +18,8 @@ Error: hello
at Object.exports.runInThisContext (vm.js:*)
at Object.<anonymous> ([eval]-wrapper:*:*)
at Module._compile (module.js:*:*)
at node.js:*:*
at nextTickCallbackWith0Args (node.js:*:*)
at process._tickCallback (node.js:*:*)
at Immediate._onImmediate (node.js:*:*)
at processImmediate [as _immediateCallback] (timers.js:*:*)
[eval]:1
throw new Error("hello")
^
Expand All @@ -30,9 +28,8 @@ Error: hello
at Object.exports.runInThisContext (vm.js:*)
at Object.<anonymous> ([eval]-wrapper:*:*)
at Module._compile (module.js:*:*)
at node.js:*:*
at nextTickCallbackWith0Args (node.js:*:*)
at process._tickCallback (node.js:*:*)
at Immediate._onImmediate (node.js:*:*)
at processImmediate [as _immediateCallback] (timers.js:*:*)
100
[eval]:1
var x = 100; y = x;
Expand All @@ -42,9 +39,8 @@ ReferenceError: y is not defined
at Object.exports.runInThisContext (vm.js:*)
at Object.<anonymous> ([eval]-wrapper:*:*)
at Module._compile (module.js:*:*)
at node.js:*:*
at nextTickCallbackWith0Args (node.js:*:*)
at process._tickCallback (node.js:*:*)
at Immediate._onImmediate (node.js:*:*)
at processImmediate [as _immediateCallback] (timers.js:*:*)
[eval]:1
var ______________________________________________; throw 10
^
Expand Down
20 changes: 8 additions & 12 deletions test/message/stdin_messages.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ SyntaxError: Strict mode code may not include a with statement
at Object.exports.runInThisContext (vm.js:*)
at Object.<anonymous> ([stdin]-wrapper:*:*)
at Module._compile (module.js:*:*)
at node.js:*:*
at nextTickCallbackWith0Args (node.js:*:*)
at process._tickCallback (node.js:*:*)
at Immediate._onImmediate (node.js:*:*)
at processImmediate [as _immediateCallback] (timers.js:*:*)
42
42

Expand All @@ -21,9 +20,8 @@ Error: hello
at Object.exports.runInThisContext (vm.js:*)
at Object.<anonymous> ([stdin]-wrapper:*:*)
at Module._compile (module.js:*:*)
at node.js:*:*
at nextTickCallbackWith0Args (node.js:*:*)
at process._tickCallback (node.js:*:*)
at Immediate._onImmediate (node.js:*:*)
at processImmediate [as _immediateCallback] (timers.js:*:*)

[stdin]:1
throw new Error("hello")
Expand All @@ -33,9 +31,8 @@ Error: hello
at Object.exports.runInThisContext (vm.js:*)
at Object.<anonymous> ([stdin]-wrapper:*:*)
at Module._compile (module.js:*:*)
at node.js:*:*
at nextTickCallbackWith0Args (node.js:*:*)
at process._tickCallback (node.js:*:*)
at Immediate._onImmediate (node.js:*:*)
at processImmediate [as _immediateCallback] (timers.js:*:*)
100

[stdin]:1
Expand All @@ -46,9 +43,8 @@ ReferenceError: y is not defined
at Object.exports.runInThisContext (vm.js:*)
at Object.<anonymous> ([stdin]-wrapper:*:*)
at Module._compile (module.js:*:*)
at node.js:*:*
at nextTickCallbackWith0Args (node.js:*:*)
at process._tickCallback (node.js:*:*)
at Immediate._onImmediate (node.js:*:*)
at processImmediate [as _immediateCallback] (timers.js:*:*)

[stdin]:1
var ______________________________________________; throw 10
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-cli-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,18 @@ child.exec(nodejs + ` -e 'require("child_process").fork("${emptyFile}")'`,
assert.equal(stdout, '');
assert.equal(stderr, '');
});

// Regression test for https://github.com/nodejs/node/issues/8534.
{
const script = `
// console.log() can revive the event loop so we must be careful
// to write from a 'beforeExit' event listener only once.
process.once("beforeExit", () => console.log("beforeExit"));
process.on("exit", () => console.log("exit"));
console.log("start");
`;
const options = { encoding: 'utf8' };
const proc = child.spawnSync(process.execPath, ['-e', script], options);
assert.strictEqual(proc.stderr, '');
assert.strictEqual(proc.stdout, 'start\nbeforeExit\nexit\n');
}