Repository navigation
REPL: {} instanceof Object === false with nodejs 11 and nodejs 12 #27859
Copy link
Copy link
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.replIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.
Description
Activity
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.replIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.and removedvmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
on May 24, 2019 It's caused by this code:
Lines 877 to 880 in 5b8df5e
for (const name of Object.getOwnPropertyNames(global)) { Object.defineProperty(context, name, Object.getOwnPropertyDescriptor(global, name)); }
That copies theObjectfrom the main context to the REPL context.I'm not completely sure what commit introduced this but cc @BridgeAR since you were the last one to touch that code. :-)
Workaround until it's fixed:
repl.start({ prompt: '> ', useGlobal: true })Reacted by Nikita Skovoroda and Jiawen GengReacted by iam4x, In, Olivier Thierry, Anna Henningsen and Renan BastosHi @bnoordhuis, thank you for the workaround.
With some more experiments, I can reproduce on nodejs 10 the bug with this piece of code:
const repl = require('repl'); function test(obj) { return obj instanceof Object; } repl.start('> ').context.test = test;
$ node console.js > test({}) false
But with
{ useGlobal: true }it does work correctly:const repl = require('repl'); function test(obj) { return obj instanceof Object; } repl.start({prompt: '> ', useGlobal: true}).context.test = test;
$ node console.js > test({}) true
- added a commit that references this issue
on Jul 18, 2019 - added a commit that references this issue
on Jul 20, 2019 Closed since it was already fixed via #28561.
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.replIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.
With the given file:
console.js
Then running in nodejs 11 & 12:
But running with nodejs 10:
I am expecting to be
truein all cases, did I miss something?