From 47be34cef7ea8d3879ad301505ba92ef99840285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Tue, 3 Aug 2021 10:17:40 -0700 Subject: [PATCH] Split files which test for the property order of functions So SpiderMonkey can run the other parts of these tests. --- ...der-after-define-property-with-function.js | 38 +++++++++ .../entries/order-after-define-property.js | 7 -- ...der-after-define-property-with-function.js | 37 +++++++++ .../keys/order-after-define-property.js | 6 -- .../class/static/method-number-order.js | 68 ++++++++++++++++ .../class/static/method-number.js | 4 - .../class/static/method-string-order.js | 68 ++++++++++++++++ .../class/static/method-string.js | 4 - .../class/static/method-symbol-order.js | 79 +++++++++++++++++++ .../class/static/method-symbol.js | 8 -- .../fn-length-static-precedence-order.js | 72 +++++++++++++++++ .../definition/fn-length-static-precedence.js | 6 -- .../fn-name-static-precedence-order.js | 69 ++++++++++++++++ .../definition/fn-name-static-precedence.js | 6 -- 14 files changed, 431 insertions(+), 41 deletions(-) create mode 100644 test/built-ins/Object/entries/order-after-define-property-with-function.js create mode 100644 test/built-ins/Object/keys/order-after-define-property-with-function.js create mode 100644 test/language/computed-property-names/class/static/method-number-order.js create mode 100644 test/language/computed-property-names/class/static/method-string-order.js create mode 100644 test/language/computed-property-names/class/static/method-symbol-order.js create mode 100644 test/language/statements/class/definition/fn-length-static-precedence-order.js create mode 100644 test/language/statements/class/definition/fn-name-static-precedence-order.js diff --git a/test/built-ins/Object/entries/order-after-define-property-with-function.js b/test/built-ins/Object/entries/order-after-define-property-with-function.js new file mode 100644 index 0000000000..f936ef1fd4 --- /dev/null +++ b/test/built-ins/Object/entries/order-after-define-property-with-function.js @@ -0,0 +1,38 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.entries +description: > + Property names are returned in ascending chronological order of creation + that is unaffected by [[DefineOwnProperty]]. +info: | + Object.entries ( O ) + + [...] + 2. Let nameList be ? EnumerableOwnPropertyNames(obj, key+value). + 3. Return CreateArrayFromList(nameList). + + EnumerableOwnPropertyNames ( O, kind ) + + [...] + 2. Let ownKeys be ? O.[[OwnPropertyKeys]](). + [...] + + OrdinaryOwnPropertyKeys ( O ) + + [...] + 3. For each own property key P of O that is a String but is not an array index, + in ascending chronological order of property creation, do + a. Add P as the last element of keys. + [...] + 5. Return keys. +features: [arrow-function] +includes: [compareArray.js] +---*/ + +var fn = () => {}; +fn.a = 1; +Object.defineProperty(fn, "name", {enumerable: true}); +var fnKeys = Object.entries(fn).map(e => e[0]); +assert.compareArray(fnKeys, ["name", "a"]); diff --git a/test/built-ins/Object/entries/order-after-define-property.js b/test/built-ins/Object/entries/order-after-define-property.js index 907d0f9b92..af0ecbe872 100644 --- a/test/built-ins/Object/entries/order-after-define-property.js +++ b/test/built-ins/Object/entries/order-after-define-property.js @@ -27,7 +27,6 @@ info: | a. Add P as the last element of keys. [...] 5. Return keys. -features: [arrow-function] includes: [compareArray.js] ---*/ @@ -37,9 +36,3 @@ obj.b = 2; Object.defineProperty(obj, "a", {writable: false}); var objKeys = Object.entries(obj).map(e => e[0]); assert.compareArray(objKeys, ["a", "b"]); - -var fn = () => {}; -fn.a = 1; -Object.defineProperty(fn, "name", {enumerable: true}); -var fnKeys = Object.entries(fn).map(e => e[0]); -assert.compareArray(fnKeys, ["name", "a"]); diff --git a/test/built-ins/Object/keys/order-after-define-property-with-function.js b/test/built-ins/Object/keys/order-after-define-property-with-function.js new file mode 100644 index 0000000000..32b9f11e8f --- /dev/null +++ b/test/built-ins/Object/keys/order-after-define-property-with-function.js @@ -0,0 +1,37 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.keys +description: > + Property names are returned in ascending chronological order of creation + that is unaffected by [[DefineOwnProperty]]. +info: | + Object.keys ( O ) + + [...] + 2. Let nameList be ? EnumerableOwnPropertyNames(obj, key). + 3. Return CreateArrayFromList(nameList). + + EnumerableOwnPropertyNames ( O, kind ) + + [...] + 2. Let ownKeys be ? O.[[OwnPropertyKeys]](). + [...] + + OrdinaryOwnPropertyKeys ( O ) + + [...] + 3. For each own property key P of O that is a String but is not an array index, + in ascending chronological order of property creation, do + a. Add P as the last element of keys. + [...] + 5. Return keys. +features: [arrow-function] +includes: [compareArray.js] +---*/ + +var fn = () => {}; +fn.a = 1; +Object.defineProperty(fn, "length", {enumerable: true}); +assert.compareArray(Object.keys(fn), ["length", "a"]); diff --git a/test/built-ins/Object/keys/order-after-define-property.js b/test/built-ins/Object/keys/order-after-define-property.js index 2f77c52ada..b9be98a951 100644 --- a/test/built-ins/Object/keys/order-after-define-property.js +++ b/test/built-ins/Object/keys/order-after-define-property.js @@ -27,7 +27,6 @@ info: | a. Add P as the last element of keys. [...] 5. Return keys. -features: [Proxy] includes: [compareArray.js] ---*/ @@ -41,8 +40,3 @@ Object.defineProperty(obj, "a", { obj.b = 2; Object.defineProperty(obj, "a", {value: 1}); assert.compareArray(Object.keys(obj), ["a", "b"]); - -var fn = () => {}; -fn.a = 1; -Object.defineProperty(fn, "length", {enumerable: true}); -assert.compareArray(Object.keys(fn), ["length", "a"]); diff --git a/test/language/computed-property-names/class/static/method-number-order.js b/test/language/computed-property-names/class/static/method-number-order.js new file mode 100644 index 0000000000..d616e34e13 --- /dev/null +++ b/test/language/computed-property-names/class/static/method-number-order.js @@ -0,0 +1,68 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-runtime-semantics-classdefinitionevaluation +description: > + In a class, static computed property method names can be a number +info: | + Set order: "length", "name", "prototype", static methods + + Runtime Semantics: ClassDefinitionEvaluation + + ... + 11. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent. + 12. Let F be constructorInfo.[[Closure]]. + 13. Perform SetFunctionName(F, className). + 14. Perform MakeConstructor(F, false, proto). + ... + 19. Else, let methods be NonConstructorMethodDefinitions of ClassBody. + 20. For each ClassElement m in order from methods, do + a. If IsStatic of m is false, then + ... + b. Else, + i. Let status be PropertyDefinitionEvaluation of m with arguments F and false. + ... + + --- + + Object.getOwnPropertyNames ( O ) + + 1. Return ? GetOwnPropertyKeys(O, string). + + Runtime Semantics: GetOwnPropertyKeys ( O, type ) + + 1. Let obj be ? ToObject(O). + 2. Let keys be ? obj.[[OwnPropertyKeys]](). + 3. Let nameList be a new empty List. + 4. For each element nextKey of keys in List order, do + a. If Type(nextKey) is Symbol and type is symbol or Type(nextKey) is String and type is string, then + i. Append nextKey as the last element of nameList. + 5. Return CreateArrayFromList(nameList). + + [[OwnPropertyKeys]] ( ) + + 1. Return ! OrdinaryOwnPropertyKeys(O). + + OrdinaryOwnPropertyKeys ( O ) + + 1. Let keys be a new empty List. + 2. For each own property key P of O such that P is an array index, in ascending numeric index order, do + a. Add P as the last element of keys. + 3. For each own property key P of O such that Type(P) is String and P is not an array index, in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 4. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 5. Return keys. +includes: [compareArray.js] +---*/ + +class C { + static a() { return 'A'; } + static [1]() { return 'B'; } + static c() { return 'C'; } + static [2]() { return 'D'; } +} +assert.compareArray( + Object.getOwnPropertyNames(C), + ['1', '2', 'length', 'name', 'prototype', 'a', 'c'] +); diff --git a/test/language/computed-property-names/class/static/method-number.js b/test/language/computed-property-names/class/static/method-number.js index 459b6dc8c8..dea571b955 100644 --- a/test/language/computed-property-names/class/static/method-number.js +++ b/test/language/computed-property-names/class/static/method-number.js @@ -70,7 +70,3 @@ assert.compareArray( Object.keys(C), [] ); -assert.compareArray( - Object.getOwnPropertyNames(C), - ['1', '2', 'length', 'name', 'prototype', 'a', 'c'] -); diff --git a/test/language/computed-property-names/class/static/method-string-order.js b/test/language/computed-property-names/class/static/method-string-order.js new file mode 100644 index 0000000000..45de82002e --- /dev/null +++ b/test/language/computed-property-names/class/static/method-string-order.js @@ -0,0 +1,68 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-runtime-semantics-classdefinitionevaluation +description: > + In a class, static computed property method names can be a string +info: | + Set order: "length", "name", "prototype", static methods + + Runtime Semantics: ClassDefinitionEvaluation + + ... + 11. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent. + 12. Let F be constructorInfo.[[Closure]]. + 13. Perform SetFunctionName(F, className). + 14. Perform MakeConstructor(F, false, proto). + ... + 19. Else, let methods be NonConstructorMethodDefinitions of ClassBody. + 20. For each ClassElement m in order from methods, do + a. If IsStatic of m is false, then + ... + b. Else, + i. Let status be PropertyDefinitionEvaluation of m with arguments F and false. + ... + + --- + + Object.getOwnPropertyNames ( O ) + + 1. Return ? GetOwnPropertyKeys(O, string). + + Runtime Semantics: GetOwnPropertyKeys ( O, type ) + + 1. Let obj be ? ToObject(O). + 2. Let keys be ? obj.[[OwnPropertyKeys]](). + 3. Let nameList be a new empty List. + 4. For each element nextKey of keys in List order, do + a. If Type(nextKey) is Symbol and type is symbol or Type(nextKey) is String and type is string, then + i. Append nextKey as the last element of nameList. + 5. Return CreateArrayFromList(nameList). + + [[OwnPropertyKeys]] ( ) + + 1. Return ! OrdinaryOwnPropertyKeys(O). + + OrdinaryOwnPropertyKeys ( O ) + + 1. Let keys be a new empty List. + 2. For each own property key P of O such that P is an array index, in ascending numeric index order, do + a. Add P as the last element of keys. + 3. For each own property key P of O such that Type(P) is String and P is not an array index, in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 4. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 5. Return keys. +includes: [compareArray.js] +---*/ + +class C { + static a() { return 'A'} + static ['b']() { return 'B'; } + static c() { return 'C'; } + static ['d']() { return 'D'; } +} +assert.compareArray( + Object.getOwnPropertyNames(C), + ['length', 'name', 'prototype', 'a', 'b', 'c', 'd'] +); diff --git a/test/language/computed-property-names/class/static/method-string.js b/test/language/computed-property-names/class/static/method-string.js index 1a93950c35..3e01ac884c 100644 --- a/test/language/computed-property-names/class/static/method-string.js +++ b/test/language/computed-property-names/class/static/method-string.js @@ -70,7 +70,3 @@ assert.compareArray( Object.keys(C), [] ); -assert.compareArray( - Object.getOwnPropertyNames(C), - ['length', 'name', 'prototype', 'a', 'b', 'c', 'd'] -); diff --git a/test/language/computed-property-names/class/static/method-symbol-order.js b/test/language/computed-property-names/class/static/method-symbol-order.js new file mode 100644 index 0000000000..b1e42252ab --- /dev/null +++ b/test/language/computed-property-names/class/static/method-symbol-order.js @@ -0,0 +1,79 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-runtime-semantics-classdefinitionevaluation +description: > + In a class, static computed property method names can be a symbol +info: | + Set order: "length", "name", "prototype", static methods + + Runtime Semantics: ClassDefinitionEvaluation + + ... + 11. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent. + 12. Let F be constructorInfo.[[Closure]]. + 13. Perform SetFunctionName(F, className). + 14. Perform MakeConstructor(F, false, proto). + ... + 19. Else, let methods be NonConstructorMethodDefinitions of ClassBody. + 20. For each ClassElement m in order from methods, do + a. If IsStatic of m is false, then + ... + b. Else, + i. Let status be PropertyDefinitionEvaluation of m with arguments F and false. + ... + + --- + + Object.getOwnPropertyNames ( O ) + + 1. Return ? GetOwnPropertyKeys(O, string). + + Object.getOwnPropertySymbols ( O ) + + 1. Return ? GetOwnPropertyKeys(O, symbol). + + Runtime Semantics: GetOwnPropertyKeys ( O, type ) + + 1. Let obj be ? ToObject(O). + 2. Let keys be ? obj.[[OwnPropertyKeys]](). + 3. Let nameList be a new empty List. + 4. For each element nextKey of keys in List order, do + a. If Type(nextKey) is Symbol and type is symbol or Type(nextKey) is String and type is string, then + i. Append nextKey as the last element of nameList. + 5. Return CreateArrayFromList(nameList). + + [[OwnPropertyKeys]] ( ) + + 1. Return ! OrdinaryOwnPropertyKeys(O). + + OrdinaryOwnPropertyKeys ( O ) + + 1. Let keys be a new empty List. + 2. For each own property key P of O such that P is an array index, in ascending numeric index order, do + a. Add P as the last element of keys. + 3. For each own property key P of O such that Type(P) is String and P is not an array index, in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 4. For each own property key P of O such that Type(P) is Symbol, in ascending chronological order of property creation, do + a. Add P as the last element of keys. + 5. Return keys. +includes: [compareArray.js] +features: [Symbol] +---*/ + +var sym1 = Symbol(); +var sym2 = Symbol(); +class C { + static a() { return 'A'; } + static [sym1]() { return 'B'; } + static c() { return 'C'; } + static [sym2]() { return 'D'; } +} +assert.compareArray( + Object.getOwnPropertyNames(C), + ['length', 'name', 'prototype', 'a', 'c'] +); +assert.compareArray( + Object.getOwnPropertySymbols(C), + [sym1, sym2] +); diff --git a/test/language/computed-property-names/class/static/method-symbol.js b/test/language/computed-property-names/class/static/method-symbol.js index cf8662653a..cbefbccf73 100644 --- a/test/language/computed-property-names/class/static/method-symbol.js +++ b/test/language/computed-property-names/class/static/method-symbol.js @@ -77,11 +77,3 @@ assert.compareArray( Object.keys(C), [] ); -assert.compareArray( - Object.getOwnPropertyNames(C), - ['length', 'name', 'prototype', 'a', 'c'] -); -assert.compareArray( - Object.getOwnPropertySymbols(C), - [sym1, sym2] -); diff --git a/test/language/statements/class/definition/fn-length-static-precedence-order.js b/test/language/statements/class/definition/fn-length-static-precedence-order.js new file mode 100644 index 0000000000..6aa57673a2 --- /dev/null +++ b/test/language/statements/class/definition/fn-length-static-precedence-order.js @@ -0,0 +1,72 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-runtime-semantics-classdefinitionevaluation +description: > + Function `length` attribute not inferred in presence of static `length` method +info: | + ClassTail : ClassHeritage_opt { ClassBody_opt } + + 14. If constructor is empty, then [...] + b. Let F be ! CreateBuiltinFunction(steps, 0, className, « [[ConstructorKind]], [[SourceText]] », empty, constructorParent). + 15. Else, + a. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent. + [ This sets the length property on constructorInfo.[[Closure]]. ] + b. Let F be constructorInfo.[[Closure]]. + [...] + 25. For each ClassElement e of elements, do + a. If IsStatic of e is false, then [...] + b. Else, + i. Let field be ClassElementEvaluation of e with arguments F and false. + [ This overwrites the length property on F. ] +includes: [compareArray.js] +features: [generators] +---*/ + +class A { + static method() { + throw new Test262Error('Static method should not be executed during definition'); + } + static length() { + throw new Test262Error('Static method should not be executed during definition'); + } +} + +assert(compareArray(Object.getOwnPropertyNames(A), ['length', 'name', 'prototype', 'method'])) + +var attr = 'length'; +class B { + static [attr]() { + throw new Test262Error( + 'Static method defined via computed property should not be executed ' + + 'during definition' + ); + } +} + +assert(compareArray(Object.getOwnPropertyNames(B), ['length', 'name', 'prototype'])) + +class C { + static get length() { + throw new Test262Error('Static `get` accessor should not be executed during definition'); + } +} + +assert(compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype'])) + +class D { + static set length(_) { + throw new Test262Error('Static `set` accessor should not be executed during definition'); + } +} + +assert(compareArray(Object.getOwnPropertyNames(D), ['length', 'name', 'prototype'])) + +class E { + static *length() { + throw new Test262Error('Static GeneratorMethod should not be executed during definition'); + } +} + +assert(compareArray(Object.getOwnPropertyNames(E), ['length', 'name', 'prototype'])) diff --git a/test/language/statements/class/definition/fn-length-static-precedence.js b/test/language/statements/class/definition/fn-length-static-precedence.js index 1fccc46e0f..4fb4492e2c 100644 --- a/test/language/statements/class/definition/fn-length-static-precedence.js +++ b/test/language/statements/class/definition/fn-length-static-precedence.js @@ -20,7 +20,6 @@ info: | b. Else, i. Let field be ClassElementEvaluation of e with arguments F and false. [ This overwrites the length property on F. ] -includes: [compareArray.js] features: [generators] ---*/ @@ -34,7 +33,6 @@ class A { } assert.sameValue(typeof A.length, 'function'); -assert(compareArray(Object.getOwnPropertyNames(A), ['length', 'name', 'prototype', 'method'])) var attr = 'length'; class B { @@ -47,7 +45,6 @@ class B { } assert.sameValue(typeof B.length, 'function'); -assert(compareArray(Object.getOwnPropertyNames(B), ['length', 'name', 'prototype'])) var isDefined = false; class C { @@ -61,7 +58,6 @@ class C { isDefined = true; assert.sameValue(C.length, 'pass'); -assert(compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype'])) class D { static set length(_) { @@ -70,7 +66,6 @@ class D { } assert.sameValue(D.length, undefined); -assert(compareArray(Object.getOwnPropertyNames(D), ['length', 'name', 'prototype'])) class E { static *length() { @@ -79,4 +74,3 @@ class E { } assert.sameValue(typeof E.length, 'function'); -assert(compareArray(Object.getOwnPropertyNames(E), ['length', 'name', 'prototype'])) diff --git a/test/language/statements/class/definition/fn-name-static-precedence-order.js b/test/language/statements/class/definition/fn-name-static-precedence-order.js new file mode 100644 index 0000000000..4612767b6e --- /dev/null +++ b/test/language/statements/class/definition/fn-name-static-precedence-order.js @@ -0,0 +1,69 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-runtime-semantics-classdefinitionevaluation +description: > + Function `name` attribute not inferred in presence of static `name` method +info: | + ClassTail : ClassHeritage_opt { ClassBody_opt } + + 14. If constructor is empty, then [...] + b. Let F be ! CreateBuiltinFunction(steps, 0, className, « [[ConstructorKind]], [[SourceText]] », empty, constructorParent). + 15. Else, [...] + d. Perform ! SetFunctionName(F, className). + 25. For each ClassElement e of elements, do + a. If IsStatic of e is false, then [...] + b. Else, + i. Let field be ClassElementEvaluation of e with arguments F and false. + [ This overwrites the name property on F. ] +includes: [compareArray.js] +features: [generators] +---*/ + +class A { + static method() { + throw new Test262Error('Static method should not be executed during definition'); + } + static name() { + throw new Test262Error('Static method should not be executed during definition'); + } +} + +assert(compareArray(Object.getOwnPropertyNames(A), ['length', 'name', 'prototype', 'method'])) + +var attr = 'name'; +class B { + static [attr]() { + throw new Test262Error( + 'Static method defined via computed property should not be executed ' + + 'during definition' + ); + } +} + +assert(compareArray(Object.getOwnPropertyNames(B), ['length', 'name', 'prototype'])) + +class C { + static get name() { + throw new Test262Error('Static `get` accessor should not be executed during definition'); + } +} + +assert(compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype'])) + +class D { + static set name(_) { + throw new Test262Error('Static `set` accessor should not be executed during definition'); + } +} + +assert(compareArray(Object.getOwnPropertyNames(D), ['length', 'name', 'prototype'])) + +class E { + static *name() { + throw new Test262Error('Static GeneratorMethod should not be executed during definition'); + } +} + +assert(compareArray(Object.getOwnPropertyNames(E), ['length', 'name', 'prototype'])) diff --git a/test/language/statements/class/definition/fn-name-static-precedence.js b/test/language/statements/class/definition/fn-name-static-precedence.js index 4d62d1e4b6..8948c10b68 100644 --- a/test/language/statements/class/definition/fn-name-static-precedence.js +++ b/test/language/statements/class/definition/fn-name-static-precedence.js @@ -17,7 +17,6 @@ info: | b. Else, i. Let field be ClassElementEvaluation of e with arguments F and false. [ This overwrites the name property on F. ] -includes: [compareArray.js] features: [generators] ---*/ @@ -31,7 +30,6 @@ class A { } assert.sameValue(typeof A.name, 'function'); -assert(compareArray(Object.getOwnPropertyNames(A), ['length', 'name', 'prototype', 'method'])) var attr = 'name'; class B { @@ -44,7 +42,6 @@ class B { } assert.sameValue(typeof B.name, 'function'); -assert(compareArray(Object.getOwnPropertyNames(B), ['length', 'name', 'prototype'])) var isDefined = false; class C { @@ -58,7 +55,6 @@ class C { isDefined = true; assert.sameValue(C.name, 'pass'); -assert(compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype'])) class D { static set name(_) { @@ -67,7 +63,6 @@ class D { } assert.sameValue(D.name, undefined); -assert(compareArray(Object.getOwnPropertyNames(D), ['length', 'name', 'prototype'])) class E { static *name() { @@ -76,4 +71,3 @@ class E { } assert.sameValue(typeof E.name, 'function'); -assert(compareArray(Object.getOwnPropertyNames(E), ['length', 'name', 'prototype']))