Bug 247429
Summary: | Order of properties for class as static field | ||
---|---|---|---|
Product: | WebKit | Reporter: | Kanguk Lee <p51lee> |
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
Status: | REOPENED | ||
Severity: | Normal | CC: | karlcow, mark.lam, ross.kirsling, webkit-bug-importer, ysuzuki |
Priority: | P2 | Keywords: | BrowserCompat, InRadar |
Version: | WebKit Local Build | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
Kanguk Lee
// input.js
class x { static y = class { } ; }
print(Object.getOwnPropertyNames(x.y));
__________________________________________
Hello,
Executing the input.js using JSC prints `length,prototype,name`.
However, it is expected to print `length,name,prototype` since 'DefinePropertyOrThrow' (ECMA262 2022 section 7.3.9)
is called 3 times with argument in order of "length", "name" and "prototype".
Running the input.js with JSC prints:
---
$ jsc input.js
length,prototype,name
---
while other engines behave like:
---
# V8
$ node input.js
length,name,prototype
# GraalJS
$ js input.js
length,name,prototype
---
WebKit version: 615.1.10
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/102193968>
Mark Lam
Does the spec actually say anything about the order that property names need to be listed? If not, then this is not a bug.
Mark Lam
On Firefox, the order of the properties are:
Array(3) [ "prototype", "length", "name" ]
… which is different from WebKit and Chrome.
Mark Lam
Looking at the spec of ECMA spec 20.1.2.10 Object.getOwnPropertyNames (ref: https://262.ecma-international.org/#sec-object.getownpropertynames), I see nothing that says the order in which properties should be listed.
Hence, this test is simply making a bad assumption.
Kanguk Lee
Hello,
Object.getOwnPropertyNames calls GetOwnPropertyKeys() and it iterates over obj.[[OwnPropertyKeys]].
You can get information of the order of property names in section 10.1.11.1 of the spec. (https://262.ecma-international.org/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys)
Mark Lam
Ah yes, section 10.1.11.1 does indeed say to "ascending chronological order of property creation" for String and Symbol properties.
OK, next question, why do you think that the properties were added in order of "length", "name" and "prototype"?
Mark Lam
(In reply to Mark Lam from comment #6)
> Ah yes, section 10.1.11.1 does indeed say to "ascending chronological order
> of property creation" for String and Symbol properties.
>
> OK, next question, why do you think that the properties were added in order
> of "length", "name" and "prototype"?
I meant, why do you think that the properties were *created* in the order of "length", "name" and "prototype"?
Kanguk Lee
Thanks for your comment.
Evaluation of class definition is described in section 15.7.14 (ref: https://262.ecma-international.org/#sec-runtime-semantics-classdefinitionevaluation).
1. "length" property
During the evaluation of ClassDefinitionEvaluation, length property is defined in line 14-b, CreateBuiltinFunction(line 10, ref: https://262.ecma-international.org/#sec-createbuiltinfunction).
2. "name" property
It is defined right after when "length" property is defined; line 11-a of CreateBuiltinFunction.
3. "prototype" property
"prototype" property is defined in line 16 of ClassDefinitionEvaluation. In MakeConstructor(ref: https://262.ecma-international.org/#sec-makeconstructor) function, see line 6.
By the way, SpiderMonkey (Firefox) has a similar problem: https://bugzilla.mozilla.org/show_bug.cgi?id=1629803
Mark Lam
Thank you for pointing out how the order is laid out in the spec.
Mark Lam
Here's some interesting test cases:
function foo() {}; // foo => ["length", "name", "prototype"]
class clz { }; // clz => ["length", "name", "prototype"]
y = class { }; // y => ["length", "prototype", "name"]
Kanguk Lee
I've found some more cases below:
class x { }; - { ... x } ; // x => ["prototype", "length", "name"]
class x { * [ "f" ] ( ) { } } // (new x).f => ["length", "prototype", "name"]
(expected: ["length", "name", "prototype"])
Thank you.
Ross Kirsling
I believe this corresponds to the following test262 failures:
test/language/statements/class/definition/fn-length-static-precedence-order.js
test/language/statements/class/definition/fn-name-static-precedence-order.js