Bug 247429 - Order of properties for class as static field
Summary: Order of properties for class as static field
Status: REOPENED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2022-11-03 08:57 PDT by Kanguk Lee
Modified: 2022-11-21 17:41 PST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kanguk Lee 2022-11-03 08:57:03 PDT
// 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
Comment 1 Radar WebKit Bug Importer 2022-11-10 07:57:17 PST
<rdar://problem/102193968>
Comment 2 Mark Lam 2022-11-10 08:13:43 PST
Does the spec actually say anything about the order that property names need to be listed?  If not, then this is not a bug.
Comment 3 Mark Lam 2022-11-10 09:04:58 PST
On Firefox, the order of the properties are:
Array(3) [ "prototype", "length", "name" ]

… which is different from WebKit and Chrome.
Comment 4 Mark Lam 2022-11-10 09:18:58 PST
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.
Comment 5 Kanguk Lee 2022-11-10 12:00:01 PST
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)
Comment 6 Mark Lam 2022-11-10 12:18:16 PST
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"?
Comment 7 Mark Lam 2022-11-10 12:35:30 PST
(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"?
Comment 8 Kanguk Lee 2022-11-10 12:52:22 PST
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
Comment 9 Mark Lam 2022-11-10 14:30:30 PST
Thank you for pointing out how the order is laid out in the spec.
Comment 10 Mark Lam 2022-11-10 14:36:11 PST
Here's some interesting test cases:

function foo() {}; // foo => ["length", "name", "prototype"]
class clz { }; // clz => ["length", "name", "prototype"]
y = class { }; // y => ["length", "prototype", "name"]
Comment 11 Kanguk Lee 2022-11-11 00:35:57 PST
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.
Comment 12 Ross Kirsling 2022-11-21 17:41:58 PST
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