mozilla / rhino

Rhino is an open-source implementation of JavaScript written entirely in Java
https://rhino.github.io
Other
4.19k stars 852 forks source link

A question about Object.defineProperty #777

Open YiWen-y opened 4 years ago

YiWen-y commented 4 years ago
Version

rhino-1.7.13

Test case
var a = 6; 
Object.defineProperty(this,"a",{
    writable: false
});
Execution steps
java -jar rhino-1.7.13.jar -debug -version 200 testcase.js
Output
TypeError: Cannot change the enumerable attribute of "a" because configurable is false.
Expected behavior
Description

When executing this test case, other engines passed normally without throwing any exceptions, such as v8, spiderMonkey, JavaScriptCore, etc. But rhino throws a TypeError exception. I would like to ask how this is achieved?

tonygermano commented 3 years ago

This appears to be an issue with the implementation of abstract operation ValidateAndApplyPropertyDescriptor, specifically part 4.b. https://tc39.es/ecma262/#sec-validateandapplypropertydescriptor

4. If current.[[Configurable]] is false, then
  a. If Desc.[[Configurable]] is present and its value is true, return false.
  b. If Desc.[[Enumerable]] is present and ! SameValue(Desc.[[Enumerable]], current.[[Enumerable]]) is false, return false.

Desc.[[Enumerable]] is not present, but it appears to be using a default value of false, which is not the same value as current.[[Enumerable]]