Node: REPL: `{} instanceof Object === false` with nodejs 11 and nodejs 12

Created on 24 May 2019  路  4Comments  路  Source: nodejs/node

With the given file:

console.js

const repl = require('repl');
repl.start('> ');

Then running in nodejs 11 & 12:

$ node console.js

> console.log({} instanceof Object)
false

But running with nodejs 10:

$ node console.js

> console.log({} instanceof Object)
true

I am expecting to be true in all cases, did I miss something?

confirmed-bug repl

Most helpful comment

It's caused by this code:
https://github.com/nodejs/node/blob/5b8df5e956680dc1a38b631e53f5e70a905fd917/lib/repl.js#L877-L880
That copies the Object from 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 })

All 4 comments

It's caused by this code:
https://github.com/nodejs/node/blob/5b8df5e956680dc1a38b631e53f5e70a905fd917/lib/repl.js#L877-L880
That copies the Object from 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 })

Hi @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

Closed since it was already fixed via https://github.com/nodejs/node/pull/28561.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akdor1154 picture akdor1154  路  3Comments

addaleax picture addaleax  路  3Comments

willnwhite picture willnwhite  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments

seishun picture seishun  路  3Comments