Skip to content

Node 10.0.0 Object.values() returns incorrect array #20278

Description

@raymondfeng
  • Version: v10.0.0
  • Platform: Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64

To reproduce the problem, create the following js files:

  1. values.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class X {
}
exports.X = X;
  1. test.js
const x = require('./values.js');
console.log(x);
console.log(Object.values(x));
  1. test1.js
const x = require('./values.js');
console.log(Object.values(x));

Now node test prints:

{ X: [Function: X] }
[]

Interestingly, node test1 prints:

[ [Function: X] ]

Please note Object.values(x) in test.js returns []. I expect it to print:

{ X: [Function: X] }
[ [Function: X] ]

I tried Node 8.x, both test and test1 work as expected.

Activity

  1. apapirovski commented on Apr 25, 2018

    @apapirovski
    Contributor

    @AyushG3112 Are you sure? I can definitely reproduce, on multiple platforms.

  2. AyushG3112 commented on Apr 25, 2018

    @AyushG3112
    Contributor

    @apapirovski nevermind, looks like my PC had some version conflicts while installing v10.0.0 from nvm. Will try fixing those and will try again. (deleting previous comment till then)

  3. apapirovski commented on Apr 25, 2018

    @apapirovski
    Contributor

    Ouch...

    'use strict';
    const obj = {};
    Object.defineProperty(obj, 'ibreakyourobjects', { value: true });
    obj.X = true;
    console.log(Object.values(obj));
    // [ true ]
    Object.keys(obj);
    console.log(Object.values(obj));
    // []

    ping @nodejs/v8 this looks bad to me...

  4. apapirovski commented on Apr 25, 2018

    @apapirovski
    Contributor

    Also, adding enumerable: true on ibreakyourobjects fixes the bug... (setting it to false breaks it again)

  5. ChALkeR commented on Apr 25, 2018

    @ChALkeR
    Member

    I can definitely reproduce this in Chromium 66.0.3359.117.

  6. added
    v8 engineIssues and PRs related to the V8 dependency.
    on Apr 25, 2018
  7. apapirovski commented on Apr 25, 2018

    @apapirovski
    Contributor

    Also, swapping order of declarations like so:

    'use strict';
    const obj = {};
    obj.X = true;
    Object.defineProperty(obj, 'ibreakyourobjects', { value: true });
    obj.Y =  true;
    console.log(Object.values(obj));
    // [ true, true ]
    Object.keys(obj);
    console.log(Object.values(obj));
    // [ true ]

    Note how the one before the defineProperty is still there but the one after isn't.

    Edit: I can reproduce on 67.0.3396.10

  8. hashseed commented on Apr 25, 2018

    @hashseed
    Member

    I can reproduce in V8, and will bisect.

  9. targos commented on Apr 25, 2018

    @targos
    Member

    I can reproduce with V8 canary.

    Opened https://bugs.chromium.org/p/v8/issues/detail?id=7687 upstream.

  10. xaviergonz commented on Apr 25, 2018

    @xaviergonz
    Contributor
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.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo