Skip to content

Object.entries/values include non-enumerable defineProperty slots (Object.keys is correct) #5046

Closed

Description

@proggeramlug

Found while validating #5039 / PR #5045.

Repro

const o: any = {};
Object.defineProperty(o, 'hidden', { value: 1 }); // enumerable defaults to false
o.shown = 2;
console.log(JSON.stringify(Object.entries(o)), JSON.stringify(Object.keys(o)));

Actual (Perry)

[["hidden",1],["shown",2]] ["shown"]

Expected (Node)

[["shown",2]] ["shown"]

Object.keys filters non-enumerable properties correctly; Object.entries (and presumably Object.values) does not. Real-world sighting: chalk's vendored ansi-styles assembles its style object with several non-enumerable defineProperty slots (codes, rgbToAnsi256, hexToRgb, …) — Object.entries(ansiStyles) returns 55 entries under Perry vs Node's 45, so chalk defines 10 extra (unused) style getters. Harmless there, but any code branching on entries/values length or content over such objects diverges.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions