diff options
Diffstat (limited to 'js/src/tests/test262/language/computed-property-names/object')
20 files changed, 422 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/computed-property-names/object/accessor/browser.js b/js/src/tests/test262/language/computed-property-names/object/accessor/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/accessor/browser.js diff --git a/js/src/tests/test262/language/computed-property-names/object/accessor/getter-duplicates.js b/js/src/tests/test262/language/computed-property-names/object/accessor/getter-duplicates.js new file mode 100644 index 0000000000..94aece21e1 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/accessor/getter-duplicates.js @@ -0,0 +1,49 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + In an object, duplicate computed property getter names produce only a single property of + that name, whose value is the value of the last property of that name. +---*/ +var A = { + get ['a']() { + return 'A'; + } +}; +assert.sameValue(A.a, 'A', "The value of `A.a` is `'A'`"); + +var B = { + get b() { + $ERROR("The `b` getter definition in `B` is unreachable"); + }, + get ['b']() { + return 'B'; + } +}; +assert.sameValue(B.b, 'B', "The value of `B.b` is `'B'`"); + +var C = { + get c() { + $ERROR("The `c` getter definition in `C` is unreachable"); + }, + get ['c']() { + $ERROR("The `['c']` getter definition in `C` is unreachable"); + }, + get ['c']() { + return 'C'; + } +}; +assert.sameValue(C.c, 'C', "The value of `C.c` is `'C'`"); + +var D = { + get ['d']() { + $ERROR("The `['d']` getter definition in `D` is unreachable"); + }, + get d() { + return 'D'; + } +}; +assert.sameValue(D.d, 'D', "The value of `D.d` is `'D'`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/accessor/getter-super.js b/js/src/tests/test262/language/computed-property-names/object/accessor/getter-super.js new file mode 100644 index 0000000000..5835827edb --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/accessor/getter-super.js @@ -0,0 +1,48 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + computed property getters can call super methods +---*/ + +function ID(x) { + return x; +} + +var proto = { + m() { + return ' proto m'; + } +}; +var object = { + get ['a']() { return 'a' + super.m(); }, + get [ID('b')]() { return 'b' + super.m(); }, + get [0]() { return '0' + super.m(); }, + get [ID(1)]() { return '1' + super.m(); }, +}; + +Object.setPrototypeOf(object, proto); + +assert.sameValue( + object.a, + 'a proto m', + "The value of `object.a` is `'a proto m'`. Defined as `get ['a']() { return 'a' + super.m(); }`" +); +assert.sameValue( + object.b, + 'b proto m', + "The value of `object.b` is `'b proto m'`. Defined as `get [ID('b')]() { return 'b' + super.m(); }`" +); +assert.sameValue( + object[0], + '0 proto m', + "The value of `object[0]` is `'0 proto m'`. Defined as `get [0]() { return '0' + super.m(); }`" +); +assert.sameValue( + object[1], + '1 proto m', + "The value of `object[1]` is `'1 proto m'`. Defined as `get [ID(1)]() { return '1' + super.m(); }`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/accessor/getter.js b/js/src/tests/test262/language/computed-property-names/object/accessor/getter.js new file mode 100644 index 0000000000..2125ee6139 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/accessor/getter.js @@ -0,0 +1,15 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + Computed property names for getters +---*/ +var A = { + get ["a"]() { + return "A"; + } +}; +assert.sameValue(A.a, "A", "The value of `A.a` is `'A'`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/accessor/setter-duplicates.js b/js/src/tests/test262/language/computed-property-names/object/accessor/setter-duplicates.js new file mode 100644 index 0000000000..cffcc048a3 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/accessor/setter-duplicates.js @@ -0,0 +1,57 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + In an object, duplicate computed property getter names produce only a single property of + that name, whose value is the value of the last property of that name. +---*/ +var calls = 0; +var A = { + set ['a'](_) { + calls++; + } +}; +A.a = 'A'; +assert.sameValue(calls, 1, "The value of `calls` is `1`"); + +calls = 0; +var B = { + set b(_) { + $ERROR("The `b` setter definition in `B` is unreachable"); + }, + set ['b'](_) { + calls++; + } +}; +B.b = 'B'; +assert.sameValue(calls, 1, "The value of `calls` is `1`"); + +calls = 0; +var C = { + set c(_) { + $ERROR("The `c` setter definition in `C` is unreachable"); + }, + set ['c'](_) { + $ERROR("The first `['c']` setter definition in `C` is unreachable"); + }, + set ['c'](_) { + calls++ + } +}; +C.c = 'C'; +assert.sameValue(calls, 1, "The value of `calls` is `1`"); + +calls = 0; +var D = { + set ['d'](_) { + $ERROR("The `['d']` setter definition in `D` is unreachable"); + }, + set d(_) { + calls++ + } +}; +D.d = 'D'; +assert.sameValue(calls, 1, "The value of `calls` is `1`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/accessor/setter-super.js b/js/src/tests/test262/language/computed-property-names/object/accessor/setter-super.js new file mode 100644 index 0000000000..2fdba56bf9 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/accessor/setter-super.js @@ -0,0 +1,37 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + computed property setters can call super methods +---*/ + +function ID(x) { + return x; +} + +var value; +var proto = { + m(name, v) { + value = name + ' ' + v; + } +}; +var object = { + set ['a'](v) { super.m('a', v); }, + set [ID('b')](v) { super.m('b', v); }, + set [0](v) { super.m('0', v); }, + set [ID(1)](v) { super.m('1', v); }, +}; + +Object.setPrototypeOf(object, proto); + +object.a = 2; +assert.sameValue(value, 'a 2', "The value of `value` is `'a 2'`, after executing `object.a = 2;`"); +object.b = 3; +assert.sameValue(value, 'b 3', "The value of `value` is `'b 3'`, after executing `object.b = 3;`"); +object[0] = 4; +assert.sameValue(value, '0 4', "The value of `value` is `'0 4'`, after executing `object[0] = 4;`"); +object[1] = 5; +assert.sameValue(value, '1 5', "The value of `value` is `'1 5'`, after executing `object[1] = 5;`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/accessor/setter.js b/js/src/tests/test262/language/computed-property-names/object/accessor/setter.js new file mode 100644 index 0000000000..cb0b327dcf --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/accessor/setter.js @@ -0,0 +1,18 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + In an object, duplicate computed property getter names produce only a single property of + that name, whose value is the value of the last property of that name. +---*/ +var calls = 0; +var A = { + set ['a'](_) { + calls++; + } +}; +A.a = 'A'; +assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `A.a = 'A';`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/accessor/shell.js b/js/src/tests/test262/language/computed-property-names/object/accessor/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/accessor/shell.js diff --git a/js/src/tests/test262/language/computed-property-names/object/browser.js b/js/src/tests/test262/language/computed-property-names/object/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/browser.js diff --git a/js/src/tests/test262/language/computed-property-names/object/method/browser.js b/js/src/tests/test262/language/computed-property-names/object/method/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/method/browser.js diff --git a/js/src/tests/test262/language/computed-property-names/object/method/generator.js b/js/src/tests/test262/language/computed-property-names/object/method/generator.js new file mode 100644 index 0000000000..a78e310da7 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/method/generator.js @@ -0,0 +1,20 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + computed property names can be used as the name of a generator method in an object +includes: [compareArray.js] +---*/ +var object = { + *['a']() { + yield 1; + yield 2; + } +}; +assert( + compareArray(Object.keys(object), ['a']), + "`compareArray(Object.keys(object), ['a'])` returns `true`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/method/number.js b/js/src/tests/test262/language/computed-property-names/object/method/number.js new file mode 100644 index 0000000000..f8c75c2d41 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/method/number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + computed property method names can be a number +includes: [compareArray.js] +---*/ + +function ID(x) { + return x; +} + +var object = { + a() { return 'A'; }, + [1]() { return 'B'; }, + c() { return 'C'; }, + [ID(2)]() { return 'D'; }, +}; +assert.sameValue(object.a(), 'A', "`object.a()` returns `'A'`. Defined as `a() { return 'A'; }`"); +assert.sameValue(object[1](), 'B', "`object[1]()` returns `'B'`. Defined as `[1]() { return 'B'; }`"); +assert.sameValue(object.c(), 'C', "`object.c()` returns `'C'`. Defined as `c() { return 'C'; }`"); +assert.sameValue(object[2](), 'D', "`object[2]()` returns `'D'`. Defined as `[ID(2)]() { return 'D'; }`"); +assert( + compareArray(Object.getOwnPropertyNames(object), ['1', '2', 'a', 'c']), + "`compareArray(Object.getOwnPropertyNames(object), ['1', '2', 'a', 'c'])` returns `true`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/method/shell.js b/js/src/tests/test262/language/computed-property-names/object/method/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/method/shell.js diff --git a/js/src/tests/test262/language/computed-property-names/object/method/string.js b/js/src/tests/test262/language/computed-property-names/object/method/string.js new file mode 100644 index 0000000000..6a25cd49a6 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/method/string.js @@ -0,0 +1,29 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + computed property method names can be a string +includes: [compareArray.js] +---*/ + +function ID(x) { + return x; +} + +var object = { + a() { return 'A'}, + ['b']() { return 'B'; }, + c() { return 'C'; }, + [ID('d')]() { return 'D'; }, +}; +assert.sameValue(object.a(), 'A', "`object.a()` returns `'A'`. Defined as `a() { return 'A'}`"); +assert.sameValue(object.b(), 'B', "`object.b()` returns `'B'`. Defined as `['b']() { return 'B'; }`"); +assert.sameValue(object.c(), 'C', "`object.c()` returns `'C'`. Defined as `c() { return 'C'; }`"); +assert.sameValue(object.d(), 'D', "`object.d()` returns `'D'`. Defined as `[ID('d')]() { return 'D'; }`"); +assert( + compareArray(Object.getOwnPropertyNames(object), ['a', 'b', 'c', 'd']), + "`compareArray(Object.getOwnPropertyNames(object), ['a', 'b', 'c', 'd'])` returns `true`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/method/super.js b/js/src/tests/test262/language/computed-property-names/object/method/super.js new file mode 100644 index 0000000000..3f7484e318 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/method/super.js @@ -0,0 +1,32 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + computed property methods can call super methods +---*/ + +function ID(x) { + return x; +} + +var proto = { + m() { + return ' proto m'; + } +}; +var object = { + ['a']() { return 'a' + super.m(); }, + [ID('b')]() { return 'b' + super.m(); }, + [0]() { return '0' + super.m(); }, + [ID(1)]() { return '1' + super.m(); }, +}; + +Object.setPrototypeOf(object, proto); + +assert.sameValue(object.a(), 'a proto m', "`object.a()` returns `'a proto m'`, after executing `Object.setPrototypeOf(object, proto);`"); +assert.sameValue(object.b(), 'b proto m', "`object.b()` returns `'b proto m'`, after executing `Object.setPrototypeOf(object, proto);`"); +assert.sameValue(object[0](), '0 proto m', "`object[0]()` returns `'0 proto m'`, after executing `Object.setPrototypeOf(object, proto);`"); +assert.sameValue(object[1](), '1 proto m', "`object[1]()` returns `'1 proto m'`, after executing `Object.setPrototypeOf(object, proto);`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/method/symbol.js b/js/src/tests/test262/language/computed-property-names/object/method/symbol.js new file mode 100644 index 0000000000..f5631a2c79 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/method/symbol.js @@ -0,0 +1,36 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + computed property method names can be a symbol +includes: [compareArray.js] +features: [Symbol] +---*/ + +function ID(x) { + return x; +} + +var sym1 = Symbol(); +var sym2 = Symbol(); +var object = { + a() { return 'A'; }, + [sym1]() { return 'B'; }, + c() { return 'C'; }, + [ID(sym2)]() { return 'D'; }, +}; +assert.sameValue(object.a(), 'A', "`object.a()` returns `'A'`. Defined as `a() { return 'A'; }`"); +assert.sameValue(object[sym1](), 'B', "`object[sym1]()` returns `'B'`. Defined as `[sym1]() { return 'B'; }`"); +assert.sameValue(object.c(), 'C', "`object.c()` returns `'C'`. Defined as `c() { return 'C'; }`"); +assert.sameValue(object[sym2](), 'D', "`object[sym2]()` returns `'D'`. Defined as `[ID(sym2)]() { return 'D'; }`"); +assert( + compareArray(Object.getOwnPropertyNames(object), ['a', 'c']), + "`compareArray(Object.getOwnPropertyNames(object), ['a', 'c'])` returns `true`" +); +assert( + compareArray(Object.getOwnPropertySymbols(object), [sym1, sym2]), + "`compareArray(Object.getOwnPropertySymbols(object), [sym1, sym2])` returns `true`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/property/browser.js b/js/src/tests/test262/language/computed-property-names/object/property/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/property/browser.js diff --git a/js/src/tests/test262/language/computed-property-names/object/property/number-duplicates.js b/js/src/tests/test262/language/computed-property-names/object/property/number-duplicates.js new file mode 100644 index 0000000000..8f0ec366d7 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/property/number-duplicates.js @@ -0,0 +1,52 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.2.5 +description: > + computed property names can be numbers +---*/ +var object = { + [1.2]: 'A', + [1e55]: 'B', + [0.000001]: 'C', + [-0]: 'D', + [Infinity]: 'E', + [-Infinity]: 'F', + [NaN]: 'G', +}; +assert.sameValue( + object['1.2'], + 'A', + "The value of `object['1.2']` is `'A'`. Defined as `[1.2]: 'A'`" +); +assert.sameValue( + object['1e+55'], + 'B', + "The value of `object['1e+55']` is `'B'`. Defined as `[1e55]: 'B'`" +); +assert.sameValue( + object['0.000001'], + 'C', + "The value of `object['0.000001']` is `'C'`. Defined as `[0.000001]: 'C'`" +); +assert.sameValue( + object[0], + 'D', + "The value of `object[0]` is `'D'`. Defined as `[-0]: 'D'`" +); +assert.sameValue(object[Infinity], + 'E', + "The value of `object[Infinity]` is `'E'`. Defined as `[Infinity]: 'E'`" +); +assert.sameValue( + object[-Infinity], + 'F', + "The value of `object[-Infinity]` is `'F'`. Defined as `[-Infinity]: 'F'`" +); +assert.sameValue( + object[NaN], + 'G', + "The value of `object[NaN]` is `'G'`. Defined as `[NaN]: 'G'`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/computed-property-names/object/property/shell.js b/js/src/tests/test262/language/computed-property-names/object/property/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/property/shell.js diff --git a/js/src/tests/test262/language/computed-property-names/object/shell.js b/js/src/tests/test262/language/computed-property-names/object/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/computed-property-names/object/shell.js |