Skip to content

REPL: {} instanceof Object === false with nodejs 11 and nodejs 12  #27859

Description

@iam4x

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?

Activity

  1. added
    confirmed-bugIssues and PRs for confirmed bugs.
    vmIssues and PRs related to the vm subsystem.
    replIssues and PRs related to the REPL subsystem.
    and removed
    vmIssues and PRs related to the vm subsystem.
    on May 24, 2019
  2. bnoordhuis commented on May 24, 2019

    @bnoordhuis
    Member

    It's caused by this code:

    node/lib/repl.js

    Lines 877 to 880 in 5b8df5e

    for (const name of Object.getOwnPropertyNames(global)) {
    Object.defineProperty(context, name,
    Object.getOwnPropertyDescriptor(global, name));
    }

    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 })

  3. iam4x commented on May 24, 2019

    @iam4x
    Author

    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
  4. starkwang commented on May 29, 2019

    @starkwang
    Contributor

    Maybe this bug is related to e3055dc?
    cc @BridgeAR.

  5. added a commit that references this issue on Jul 18, 2019
  6. added a commit that references this issue on Jul 20, 2019
  7. added a commit that references this issue on Aug 13, 2019
  8. ZYSzys commented on Dec 9, 2019

    @ZYSzys
    Member

    Closed since it was already fixed via #28561.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions