Skip to content

Lacking support for ES6 block scoping #575

@tido64

Description

@tido64

Bug Description

There is a bug in Object.defineProperty that always returns the last set property regardless of what property is being accessed.

  • I have run gradle clean and confirmed this bug does not occur with JSC

Hermes version: 0.8.1
React Native version: n/a
OS version: n/a
Platform: arm64-v8a, x86_64

Steps To Reproduce

Run the following code example with hermes-engine-cli and node, and compare the output:

const target = {
  a: "a",
  b: "b",
  c: "c",
};

const copy = {};
let keys = "";
for (const prop in target) {
  keys += " " + prop;
  Object.defineProperty(copy, prop, {
    get: () => target[prop],
    enumerable: true,
  });
}

// I don't know how to output to console so I'm just using a throw 😛
throw new Error(`copy: a = ${copy.a}, b = ${copy.b}, c = ${copy.c} (keys:${keys})`);

Output:

Uncaught Error: copy: a = c, b = c, c = c (keys: a b c)
    at global (repro.js:18:16)

The Expected Behavior

This should throw copy: a = a, b = b, c = c, as Node does:

Error: copy: a = a, b = b, c = c (keys: a b c)
    at Object.<anonymous> (/~/repro.js:18:7)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions