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 |
Description
Kanguk Lee
2022-11-03 08:57:03 PDT
Does the spec actually say anything about the order that property names need to be listed? If not, then this is not a bug. On Firefox, the order of the properties are: Array(3) [ "prototype", "length", "name" ] … which is different from WebKit and Chrome. 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. 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) 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"? (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"? 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 Thank you for pointing out how the order is laid out in the spec. Here's some interesting test cases: function foo() {}; // foo => ["length", "name", "prototype"] class clz { }; // clz => ["length", "name", "prototype"] y = class { }; // y => ["length", "prototype", "name"] 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. 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 |