diff --git a/test/language/computed-property-names/basics/number.js b/test/language/computed-property-names/basics/number.js new file mode 100644 index 0000000000000000000000000000000000000000..389e22050d39ac08af593c8509ebd47f813bf5da --- /dev/null +++ b/test/language/computed-property-names/basics/number.js @@ -0,0 +1,24 @@ +// Copyright (C) Copyright 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 a number +includes: [compareArray.js] +---*/ + +function ID(x) { + return x; +} + +var object = { + a: 'A', + [1]: 'B', + c: 'C', + [ID(2)]: 'D', +}; +assert.sameValue(object.a, 'A'); +assert.sameValue(object[1], 'B'); +assert.sameValue(object.c, 'C'); +assert.sameValue(object[2], 'D'); +assert(compareArray(Object.keys(object), ['1', '2', 'a', 'c'])); diff --git a/test/language/computed-property-names/basics/string.js b/test/language/computed-property-names/basics/string.js new file mode 100644 index 0000000000000000000000000000000000000000..f597ee5f5e9e458221818dba85444bbeff308673 --- /dev/null +++ b/test/language/computed-property-names/basics/string.js @@ -0,0 +1,23 @@ +// Copyright (C) Copyright 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 a string +includes: [compareArray.js] +---*/ +function ID(x) { + return x; +} + +var object = { + a: 'A', + ['b']: 'B', + c: 'C', + [ID('d')]: 'D', +}; +assert.sameValue(object.a, 'A'); +assert.sameValue(object.b, 'B'); +assert.sameValue(object.c, 'C'); +assert.sameValue(object.d, 'D'); +assert(compareArray(Object.keys(object), ['a', 'b', 'c', 'd'])); diff --git a/test/language/computed-property-names/basics/symbol.js b/test/language/computed-property-names/basics/symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..c57b7addfcace0183ceb1030ad3bf8358e0ffae7 --- /dev/null +++ b/test/language/computed-property-names/basics/symbol.js @@ -0,0 +1,41 @@ +// Copyright (C) Copyright 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 a symbol +includes: [compareArray.js] +---*/ + +function ID(x) { + return x; +} + +var sym1 = Symbol(); +var sym2 = Symbol(); +var object = { + a: 'A', + [sym1]: 'B', + c: 'C', + [ID(sym2)]: 'D', +}; +assert.sameValue(object.a, 'A'); +assert.sameValue(object[sym1], 'B'); +assert.sameValue(object.c, 'C'); +assert.sameValue(object[sym2], 'D'); +assert(compareArray(Object.keys(object), ['a', 'c'])); + +// compareArray expects arguments to be sorted, +// which will cause an array containing symbols to +// throw an exception when toString() is called. +// +// Since there is no guarantee of order: +// +// - Assert only that the symbol is present +// - Assert that the length is correct +// +var symbols = Object.getOwnPropertySymbols(object); + +assert(symbols.indexOf(sym1) !== -1); +assert(symbols.indexOf(sym2) !== -1); +assert.sameValue(symbols.length, 2); diff --git a/test/language/computed-property-names/class/accessor/getter-duplicates.js b/test/language/computed-property-names/class/accessor/getter-duplicates.js new file mode 100644 index 0000000000000000000000000000000000000000..436ea48319b85ca4b606f8d12deadb25b24af2f0 --- /dev/null +++ b/test/language/computed-property-names/class/accessor/getter-duplicates.js @@ -0,0 +1,47 @@ +// Copyright (C) Copyright 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 a class, 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. +---*/ +class C { + get ['a']() { + return 'A'; + } +} +assert.sameValue(new C().a, 'A'); + +class C2 { + get b() { + assert(false); + } + get ['b']() { + return 'B'; + } +} +assert.sameValue(new C2().b, 'B'); + +class C3 { + get c() { + assert(false); + } + get ['c']() { + assert(false); + } + get ['c']() { + return 'C'; + } +} +assert.sameValue(new C3().c, 'C'); + +class C4 { + get ['d']() { + assert(false); + } + get d() { + return 'D'; + } +} +assert.sameValue(new C4().d, 'D'); diff --git a/test/language/computed-property-names/class/accessor/getter.js b/test/language/computed-property-names/class/accessor/getter.js new file mode 100644 index 0000000000000000000000000000000000000000..eb8faa9914fcf84501f18521877a27baf592b537 --- /dev/null +++ b/test/language/computed-property-names/class/accessor/getter.js @@ -0,0 +1,13 @@ +// Copyright (C) Copyright 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 +---*/ +class C { + get ['a']() { + return 'A'; + } +} +assert.sameValue(new C().a, 'A'); diff --git a/test/language/computed-property-names/class/accessor/setter-duplicates.js b/test/language/computed-property-names/class/accessor/setter-duplicates.js new file mode 100644 index 0000000000000000000000000000000000000000..ac6d4fad9476da59bb42e8904354d73e03d675a8 --- /dev/null +++ b/test/language/computed-property-names/class/accessor/setter-duplicates.js @@ -0,0 +1,55 @@ +// Copyright (C) Copyright 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 a class, duplicate computed property setter names produce only a single property of + that name, whose value is the value of the last property of that name. +---*/ +var calls = 0; +class C { + set ['a'](_) { + calls++; + } +} +new C().a = 'A'; +assert.sameValue(calls, 1); + +calls = 0; +class C2 { + set b(_) { + assert(false); + } + set ['b'](_) { + calls++; + } +} +new C2().b = 'B'; +assert.sameValue(calls, 1); + +calls = 0; +class C3 { + set c(_) { + assert(false) + } + set ['c'](_) { + assert(false) + } + set ['c'](_) { + calls++ + } +} +new C3().c = 'C'; +assert.sameValue(calls, 1); + +calls = 0; +class C4 { + set ['d'](_) { + assert(false) + } + set d(_) { + calls++ + } +} +new C4().d = 'D'; +assert.sameValue(calls, 1); diff --git a/test/language/computed-property-names/class/accessor/setter.js b/test/language/computed-property-names/class/accessor/setter.js new file mode 100644 index 0000000000000000000000000000000000000000..b0cd0a9c6eb11d6ce3b38b4d0e6ed1197dbf9622 --- /dev/null +++ b/test/language/computed-property-names/class/accessor/setter.js @@ -0,0 +1,15 @@ +// Copyright (C) Copyright 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 setters +---*/ +var calls = 0; +class C { + set ['a'](_) { + calls++; + } +} +new C().a = 'A'; +assert.sameValue(calls, 1); diff --git a/test/language/computed-property-names/class/method/constructor.js b/test/language/computed-property-names/class/method/constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..82ec2f92113d833bed2a4f049a9273c360263033 --- /dev/null +++ b/test/language/computed-property-names/class/method/constructor.js @@ -0,0 +1,41 @@ +// Copyright (C) Copyright 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 "constructor" +---*/ +class C { + ['constructor']() { + return 1; + } +} +assert(C !== C.prototype.constructor); +assert.sameValue(new C().constructor(), 1); + +class C2 { + get ['constructor']() { + return 2; + } +} +assert.sameValue(new C2().constructor, 2); + +var calls = 0; +class C3 { + set ['constructor'](x) { + assert.sameValue(x, 3); + calls++; + } +} +new C3().constructor = 3; +assert.sameValue(calls, 1); + +class C4 { + *['constructor']() { + yield 1; + yield 2; + } +} + +assert(C4 !== C4.prototype.constructor); +assert.sameValue(new C().constructor(), 1); diff --git a/test/language/computed-property-names/class/method/generator.js b/test/language/computed-property-names/class/method/generator.js new file mode 100644 index 0000000000000000000000000000000000000000..d243c13c1915f9897ce34018892b3548cb6dc795 --- /dev/null +++ b/test/language/computed-property-names/class/method/generator.js @@ -0,0 +1,16 @@ +// Copyright (C) Copyright 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 a class +includes: [compareArray.js] +---*/ +class C { + *['a']() { + yield 1; + yield 2; + } +} +assert.sameValue(Object.keys(C.prototype).length, 0); +assert(compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a'])); diff --git a/test/language/computed-property-names/class/method/number.js b/test/language/computed-property-names/class/method/number.js new file mode 100644 index 0000000000000000000000000000000000000000..b09c103909acd5c10c22d170b78fcebe7f681d06 --- /dev/null +++ b/test/language/computed-property-names/class/method/number.js @@ -0,0 +1,25 @@ +// Copyright (C) Copyright 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 class method names can be a number +includes: [compareArray.js] +---*/ + +function ID(x) { + return x; +} + +class C { + a() { return 'A'; } + [1]() { return 'B'; } + c() { return 'C'; } + [ID(2)]() { return 'D'; } +} +assert.sameValue(new C().a(), 'A'); +assert.sameValue(new C()[1](), 'B'); +assert.sameValue(new C().c(), 'C'); +assert.sameValue(new C()[2](), 'D'); +assert(compareArray(Object.keys(C.prototype), [])); +assert(compareArray(Object.getOwnPropertyNames(C.prototype), ['1', '2', 'constructor', 'a', 'c'])); diff --git a/test/language/computed-property-names/class/method/string.js b/test/language/computed-property-names/class/method/string.js new file mode 100644 index 0000000000000000000000000000000000000000..f4ddb8942b633d5b3da4f7b70fd8d54681822f93 --- /dev/null +++ b/test/language/computed-property-names/class/method/string.js @@ -0,0 +1,25 @@ +// Copyright (C) Copyright 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 class method names can be a string +includes: [compareArray.js] +---*/ + +function ID(x) { + return x; +} + +class C { + a() { return 'A'} + ['b']() { return 'B'; } + c() { return 'C'; } + [ID('d')]() { return 'D'; } +} +assert.sameValue(new C().a(), 'A'); +assert.sameValue(new C().b(), 'B'); +assert.sameValue(new C().c(), 'C'); +assert.sameValue(new C().d(), 'D'); +assert(compareArray(Object.keys(C.prototype), [])); +assert(compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'b', 'c', 'd'])); diff --git a/test/language/computed-property-names/class/method/symbol.js b/test/language/computed-property-names/class/method/symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..2f5f023aed856f7d77b5daf001bc32c707eb6887 --- /dev/null +++ b/test/language/computed-property-names/class/method/symbol.js @@ -0,0 +1,42 @@ +// Copyright (C) Copyright 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 class method names can be a symbol +includes: [compareArray.js] +---*/ + +function ID(x) { + return x; +} + +var sym1 = Symbol(); +var sym2 = Symbol(); +class C { + a() { return 'A'; } + [sym1]() { return 'B'; } + c() { return 'C'; } + [ID(sym2)]() { return 'D'; } +} +assert.sameValue(new C().a(), 'A'); +assert.sameValue(new C()[sym1](), 'B'); +assert.sameValue(new C().c(), 'C'); +assert.sameValue(new C()[sym2](), 'D'); +assert(compareArray(Object.keys(C.prototype), [])); +assert(compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'c'])); + +// compareArray expects arguments to be sorted, +// which will cause an array containing symbols to +// throw an exception when toString() is called. +// +// Since there is no guarantee of order: +// +// - Assert only that the symbol is present +// - Assert that the length is correct +// +var symbols = Object.getOwnPropertySymbols(C.prototype); + +assert(symbols.indexOf(sym1) !== -1); +assert(symbols.indexOf(sym2) !== -1); +assert.sameValue(symbols.length, 2); diff --git a/test/language/computed-property-names/class/static/generator-constructor.js b/test/language/computed-property-names/class/static/generator-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..bb7108b605fac5fa07c7a759e2b6ed5b2e2b24e8 --- /dev/null +++ b/test/language/computed-property-names/class/static/generator-constructor.js @@ -0,0 +1,12 @@ +// Copyright (C) Copyright 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 a class, computed property names for static + generators cannot be "constructor" +negative: SyntaxError +---*/ +class C { + static * ['constructor']() {} +} diff --git a/test/language/computed-property-names/class/static/generator-prototype.js b/test/language/computed-property-names/class/static/generator-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..16c558217b979db7e4c3f9b2f7bca28afb3a6370 --- /dev/null +++ b/test/language/computed-property-names/class/static/generator-prototype.js @@ -0,0 +1,12 @@ +// Copyright (C) Copyright 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 a class, computed property names for static + generators cannot be "prototype" +negative: SyntaxError +---*/ +class C { + static *['prototype']() {} +} diff --git a/test/language/computed-property-names/class/static/getter-constructor.js b/test/language/computed-property-names/class/static/getter-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..3b576dd53a3b7df231d7fa26d2bbb8be64d79000 --- /dev/null +++ b/test/language/computed-property-names/class/static/getter-constructor.js @@ -0,0 +1,12 @@ +// Copyright (C) Copyright 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 a class, computed property names for static + getters cannot be "constructor" +negative: SyntaxError +---*/ +class C { + static get ['constructor']() {} +} diff --git a/test/language/computed-property-names/class/static/getter-prototype.js b/test/language/computed-property-names/class/static/getter-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..f445ee0f3dd0102d8275f885da346f0ea87d361f --- /dev/null +++ b/test/language/computed-property-names/class/static/getter-prototype.js @@ -0,0 +1,12 @@ +// Copyright (C) Copyright 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 a class, computed property names for static + getters cannot be "prototype" +negative: SyntaxError +---*/ +class C { + static get ['prototype']() {} +} diff --git a/test/language/computed-property-names/class/static/method-constructor.js b/test/language/computed-property-names/class/static/method-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..a47c8038353112b52ab91a0a443a9b7d666ed79c --- /dev/null +++ b/test/language/computed-property-names/class/static/method-constructor.js @@ -0,0 +1,12 @@ +// Copyright (C) Copyright 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 a class, computed property names for static + methods cannot be "constructor" +negative: SyntaxError +---*/ +class C { + static ['constructor']() {} +} diff --git a/test/language/computed-property-names/class/static/method-number.js b/test/language/computed-property-names/class/static/method-number.js new file mode 100644 index 0000000000000000000000000000000000000000..8b76d120a910dd524965cbd4aeb0aa382ba8ff77 --- /dev/null +++ b/test/language/computed-property-names/class/static/method-number.js @@ -0,0 +1,20 @@ +// Copyright (C) Copyright 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 a class, static computed property method names can be a number +includes: [compareArray.js] +---*/ +class C { + static a() { return 'A'; } + static [1]() { return 'B'; } + static c() { return 'C'; } + static [2]() { return 'D'; } +} +assert.sameValue(C.a(), 'A'); +assert.sameValue(C[1](), 'B'); +assert.sameValue(C.c(), 'C'); +assert.sameValue(C[2](), 'D'); +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-prototype.js b/test/language/computed-property-names/class/static/method-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..df2f59af1285972ddce90cde49085460440255b7 --- /dev/null +++ b/test/language/computed-property-names/class/static/method-prototype.js @@ -0,0 +1,12 @@ +// Copyright (C) Copyright 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 a class, computed property names for static + methods cannot be "prototype" +negative: SyntaxError +---*/ +class C { + static ['prototype']() {} +} diff --git a/test/language/computed-property-names/class/static/method-string.js b/test/language/computed-property-names/class/static/method-string.js new file mode 100644 index 0000000000000000000000000000000000000000..facc40dc695383b4a39b2a6d7c2bfd5be8470f73 --- /dev/null +++ b/test/language/computed-property-names/class/static/method-string.js @@ -0,0 +1,20 @@ +// Copyright (C) Copyright 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 a class, static computed property method names can be a string +includes: [compareArray.js] +---*/ +class C { + static a() { return 'A'} + static ['b']() { return 'B'; } + static c() { return 'C'; } + static ['d']() { return 'D'; } +} +assert.sameValue(C.a(), 'A'); +assert.sameValue(C.b(), 'B'); +assert.sameValue(C.c(), 'C'); +assert.sameValue(C.d(), 'D'); +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.js b/test/language/computed-property-names/class/static/method-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..a6c43a962d3320a14181f9c6009b689508029081 --- /dev/null +++ b/test/language/computed-property-names/class/static/method-symbol.js @@ -0,0 +1,38 @@ +// Copyright (C) Copyright 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 a class, static computed property method names can be a symbol +includes: [compareArray.js] +---*/ +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.sameValue(C.a(), 'A'); +assert.sameValue(C[sym1](), 'B'); +assert.sameValue(C.c(), 'C'); +assert.sameValue(C[sym2](), 'D'); +assert(compareArray(Object.keys(C), [])); +assert(compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype', 'a', 'c'])); + + +// compareArray expects arguments to be sorted, +// which will cause an array containing symbols to +// throw an exception when toString() is called. +// +// Since there is no guarantee of order: +// +// - Assert only that the symbol is present +// - Assert that the length is correct +// +var symbols = Object.getOwnPropertySymbols(C); + +assert(symbols.indexOf(sym1) !== -1); +assert(symbols.indexOf(sym2) !== -1); +assert.sameValue(symbols.length, 2); diff --git a/test/language/computed-property-names/class/static/setter-constructor.js b/test/language/computed-property-names/class/static/setter-constructor.js new file mode 100644 index 0000000000000000000000000000000000000000..4ee7466c7dbf99169f7e6921723ecfe04fc73d24 --- /dev/null +++ b/test/language/computed-property-names/class/static/setter-constructor.js @@ -0,0 +1,12 @@ +// Copyright (C) Copyright 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 a class, computed property names for static + setters cannot be "constructor" +negative: SyntaxError +---*/ +class C { + static set ['constructor'](x) {} +} diff --git a/test/language/computed-property-names/class/static/setter-prototype.js b/test/language/computed-property-names/class/static/setter-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..56505eab057b29cbaa225551d230bfbbe97dc4c4 --- /dev/null +++ b/test/language/computed-property-names/class/static/setter-prototype.js @@ -0,0 +1,12 @@ +// Copyright (C) Copyright 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 a class, computed property names for static + setters cannot be "prototype" +negative: SyntaxError +---*/ +class C { + static set ['prototype'](x) {} +} diff --git a/test/language/computed-property-names/duplicate-keys/data.js b/test/language/computed-property-names/duplicate-keys/data.js new file mode 100644 index 0000000000000000000000000000000000000000..679077b6b7ae3dc75dc4b3b9d54a68ace1d1ff6a --- /dev/null +++ b/test/language/computed-property-names/duplicate-keys/data.js @@ -0,0 +1,13 @@ +// Copyright (C) Copyright 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: > + duplicate computed property names produce only a single property of + that name, whose value is the value of the last property of that name. +---*/ +var object = { + a: 1, + ['a']: 2, +}; +assert.sameValue(object.a, 2); diff --git a/test/language/computed-property-names/duplicate-keys/method.js b/test/language/computed-property-names/duplicate-keys/method.js new file mode 100644 index 0000000000000000000000000000000000000000..350256d5307120c0075e623570830546c50f018c --- /dev/null +++ b/test/language/computed-property-names/duplicate-keys/method.js @@ -0,0 +1,13 @@ +// Copyright (C) Copyright 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: > + duplicate computed property method names produce only a single property of + that name, whose value is the value of the last property of that name. +---*/ +var object = { + a() { return 1; }, + ['a']() { return 2; }, +}; +assert.sameValue(object.a(), 2); diff --git a/test/language/computed-property-names/duplicate-keys/numbers.js b/test/language/computed-property-names/duplicate-keys/numbers.js new file mode 100644 index 0000000000000000000000000000000000000000..95417ecc048521716656b7ecd67208f1c1039b3b --- /dev/null +++ b/test/language/computed-property-names/duplicate-keys/numbers.js @@ -0,0 +1,23 @@ +// Copyright (C) Copyright 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'); +assert.sameValue(object['1e+55'], 'B'); +assert.sameValue(object['0.000001'], 'C'); +assert.sameValue(object[0], 'D'); +assert.sameValue(object[Infinity], 'E'); +assert.sameValue(object[-Infinity], 'F'); +assert.sameValue(object[NaN], 'G'); diff --git a/test/language/computed-property-names/object/accessor/getter-super.js b/test/language/computed-property-names/object/accessor/getter-super.js new file mode 100644 index 0000000000000000000000000000000000000000..f59b3ce922aa554bc51ef5f69b7e0b4c2716d476 --- /dev/null +++ b/test/language/computed-property-names/object/accessor/getter-super.js @@ -0,0 +1,30 @@ +// Copyright (C) Copyright 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'); +assert.sameValue(object.b, 'b proto m'); +assert.sameValue(object[0], '0 proto m'); +assert.sameValue(object[1], '1 proto m'); diff --git a/test/language/computed-property-names/object/accessor/getter.js b/test/language/computed-property-names/object/accessor/getter.js new file mode 100644 index 0000000000000000000000000000000000000000..d3ee4c01328f179de70bd91fcd9ecae0586246c1 --- /dev/null +++ b/test/language/computed-property-names/object/accessor/getter.js @@ -0,0 +1,47 @@ +// Copyright (C) Copyright 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 object = { + get ['a']() { + return 'A'; + } +}; +assert.sameValue(object.a, 'A'); + +object = { + get b() { + assert(false); + }, + get ['b']() { + return 'B'; + } +}; +assert.sameValue(object.b, 'B'); + +object = { + get c() { + assert(false); + }, + get ['c']() { + assert(false); + }, + get ['c']() { + return 'C'; + } +}; +assert.sameValue(object.c, 'C'); + +object = { + get ['d']() { + assert(false); + }, + get d() { + return 'D'; + } +}; +assert.sameValue(object.d, 'D'); diff --git a/test/language/computed-property-names/object/accessor/setter-super.js b/test/language/computed-property-names/object/accessor/setter-super.js new file mode 100644 index 0000000000000000000000000000000000000000..25fd54dc0a6813970c667f962d6df16a23e640b8 --- /dev/null +++ b/test/language/computed-property-names/object/accessor/setter-super.js @@ -0,0 +1,35 @@ +// Copyright (C) Copyright 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'); +object.b = 3; +assert.sameValue(value, 'b 3'); +object[0] = 4; +assert.sameValue(value, '0 4'); +object[1] = 5; +assert.sameValue(value, '1 5'); diff --git a/test/language/computed-property-names/object/accessor/setter.js b/test/language/computed-property-names/object/accessor/setter.js new file mode 100644 index 0000000000000000000000000000000000000000..3aed7b6051a00a1de0eb5ab1c256de3b18c38699 --- /dev/null +++ b/test/language/computed-property-names/object/accessor/setter.js @@ -0,0 +1,55 @@ +// Copyright (C) Copyright 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 object = { + set ['a'](_) { + calls++; + } +}; +object.a = 'A'; +assert.sameValue(calls, 1); + +calls = 0; +object = { + set b(_) { + assert(false); + }, + set ['b'](_) { + calls++; + } +}; +object.b = 'B'; +assert.sameValue(calls, 1); + +calls = 0; +object = { + set c(_) { + assert(false) + }, + set ['c'](_) { + assert(false) + }, + set ['c'](_) { + calls++ + } +}; +object.c = 'C'; +assert.sameValue(calls, 1); + +calls = 0; +object = { + set ['d'](_) { + assert(false) + }, + set d(_) { + calls++ + } +}; +object.d = 'D'; +assert.sameValue(calls, 1); diff --git a/test/language/computed-property-names/object/method/generator.js b/test/language/computed-property-names/object/method/generator.js new file mode 100644 index 0000000000000000000000000000000000000000..35d0d53fe30da130e79896e1a787f2c9c65a5de3 --- /dev/null +++ b/test/language/computed-property-names/object/method/generator.js @@ -0,0 +1,15 @@ +// Copyright (C) Copyright 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'])); diff --git a/test/language/computed-property-names/object/method/number.js b/test/language/computed-property-names/object/method/number.js new file mode 100644 index 0000000000000000000000000000000000000000..cd1c6582197a36dbf7ffa65ba4be6f1821b1b7fd --- /dev/null +++ b/test/language/computed-property-names/object/method/number.js @@ -0,0 +1,24 @@ +// Copyright (C) Copyright 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'); +assert.sameValue(object[1](), 'B'); +assert.sameValue(object.c(), 'C'); +assert.sameValue(object[2](), 'D'); +assert(compareArray(Object.keys(object), ['1', '2', 'a', 'c'])); diff --git a/test/language/computed-property-names/object/method/string.js b/test/language/computed-property-names/object/method/string.js new file mode 100644 index 0000000000000000000000000000000000000000..0a6bc55ba4531474ff04ae4db6f752494b49af97 --- /dev/null +++ b/test/language/computed-property-names/object/method/string.js @@ -0,0 +1,24 @@ +// Copyright (C) Copyright 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'); +assert.sameValue(object.b(), 'B'); +assert.sameValue(object.c(), 'C'); +assert.sameValue(object.d(), 'D'); +assert(compareArray(Object.keys(object), ['a', 'b', 'c', 'd'])); diff --git a/test/language/computed-property-names/object/method/super.js b/test/language/computed-property-names/object/method/super.js new file mode 100644 index 0000000000000000000000000000000000000000..dd71af7f01a2db0b33a7970ec36ebd3306439d10 --- /dev/null +++ b/test/language/computed-property-names/object/method/super.js @@ -0,0 +1,30 @@ +// Copyright (C) Copyright 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'); +assert.sameValue(object.b(), 'b proto m'); +assert.sameValue(object[0](), '0 proto m'); +assert.sameValue(object[1](), '1 proto m'); diff --git a/test/language/computed-property-names/object/method/symbol.js b/test/language/computed-property-names/object/method/symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..136904ce145e5d2ac1fa2be90d4d12ccf48e70bb --- /dev/null +++ b/test/language/computed-property-names/object/method/symbol.js @@ -0,0 +1,41 @@ +// Copyright (C) Copyright 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] +---*/ + +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'); +assert.sameValue(object[sym1](), 'B'); +assert.sameValue(object.c(), 'C'); +assert.sameValue(object[sym2](), 'D'); +assert(compareArray(Object.keys(object), ['a', 'c'])); + +// compareArray expects arguments to be sorted, +// which will cause an array containing symbols to +// throw an exception when toString() is called. +// +// Since there is no guarantee of order: +// +// - Assert only that the symbol is present +// - Assert that the length is correct +// +var symbols = Object.getOwnPropertySymbols(object); + +assert(symbols.indexOf(sym1) !== -1); +assert(symbols.indexOf(sym2) !== -1); +assert.sameValue(symbols.length, 2); diff --git a/test/language/computed-property-names/to-name-side-effects/class.js b/test/language/computed-property-names/to-name-side-effects/class.js new file mode 100644 index 0000000000000000000000000000000000000000..5336b67ff1d0b1b8483b0455b3b8b0b30980e53d --- /dev/null +++ b/test/language/computed-property-names/to-name-side-effects/class.js @@ -0,0 +1,34 @@ +// Copyright (C) Copyright 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: > + to name, accessor side effects 3 +includes: [compareArray.js] +---*/ +var counter = 0; +var key1 = { + toString: function() { + assert.sameValue(counter++, 0); + return 'b'; + } +}; +var key2 = { + toString: function() { + assert.sameValue(counter++, 1); + return 'd'; + } +}; +class C { + a() { return 'A'; } + [key1]() { return 'B'; } + c() { return 'C'; } + [key2]() { return 'D'; } +} +assert.sameValue(counter, 2); +assert.sameValue(new C().a(), 'A'); +assert.sameValue(new C().b(), 'B'); +assert.sameValue(new C().c(), 'C'); +assert.sameValue(new C().d(), 'D'); +assert(compareArray(Object.keys(C.prototype), [])); +assert(compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'b', 'c', 'd'])); diff --git a/test/language/computed-property-names/to-name-side-effects/numbers-class.js b/test/language/computed-property-names/to-name-side-effects/numbers-class.js new file mode 100644 index 0000000000000000000000000000000000000000..1a9f6d1dff9219d11404d9ea2e77e87ccbd60366 --- /dev/null +++ b/test/language/computed-property-names/to-name-side-effects/numbers-class.js @@ -0,0 +1,37 @@ +// Copyright (C) Copyright 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: > + to name, accessor side effects numbers 2 +includes: [compareArray.js] +---*/ +var counter = 0; +var key1 = { + valueOf: function() { + assert.sameValue(counter++, 0); + return 1; + }, + toString: null +}; +var key2 = { + valueOf: function() { + assert.sameValue(counter++, 1); + return 2; + }, + toString: null +}; + +class C { + a() { return 'A'; } + [key1]() { return 'B'; } + c() { return 'C'; } + [key2]() { return 'D'; } +} +assert.sameValue(counter, 2); +assert.sameValue(new C().a(), 'A'); +assert.sameValue(new C()[1](), 'B'); +assert.sameValue(new C().c(), 'C'); +assert.sameValue(new C()[2](), 'D'); +assert(compareArray(Object.keys(C.prototype), [])); +assert(compareArray(Object.getOwnPropertyNames(C.prototype), ['1', '2', 'constructor', 'a', 'c'])); diff --git a/test/language/computed-property-names/to-name-side-effects/numbers-object.js b/test/language/computed-property-names/to-name-side-effects/numbers-object.js new file mode 100644 index 0000000000000000000000000000000000000000..1ea795e5c7df3cadccc4cdad3be13f84f551fe5d --- /dev/null +++ b/test/language/computed-property-names/to-name-side-effects/numbers-object.js @@ -0,0 +1,36 @@ +// Copyright (C) Copyright 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: > + to name side effects numbers +includes: [compareArray.js] +---*/ +var counter = 0; +var key1 = { + valueOf: function() { + assert.sameValue(counter++, 0); + return 1; + }, + toString: null +}; +var key2 = { + valueOf: function() { + assert.sameValue(counter++, 1); + return 2; + }, + toString: null +}; + +var object = { + a: 'A', + [key1]: 'B', + c: 'C', + [key2]: 'D', +}; +assert.sameValue(counter, 2); +assert.sameValue(object.a, 'A'); +assert.sameValue(object[1], 'B'); +assert.sameValue(object.c, 'C'); +assert.sameValue(object[2], 'D'); +assert(compareArray(Object.keys(object), ['1', '2', 'a', 'c'])); diff --git a/test/language/computed-property-names/to-name-side-effects/object.js b/test/language/computed-property-names/to-name-side-effects/object.js new file mode 100644 index 0000000000000000000000000000000000000000..c5baf406afc813fd80f1c28502c07df7f1e531c6 --- /dev/null +++ b/test/language/computed-property-names/to-name-side-effects/object.js @@ -0,0 +1,33 @@ +// Copyright (C) Copyright 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: > + to name, accessor side effects object literal +includes: [compareArray.js] +---*/ +var counter = 0; +var key1 = { + toString: function() { + assert.sameValue(counter++, 0); + return 'b'; + } +}; +var key2 = { + toString: function() { + assert.sameValue(counter++, 1); + return 'd'; + } +}; +var object = { + a() { return 'A'; }, + [key1]() { return 'B'; }, + c() { return 'C'; }, + [key2]() { return 'D'; }, +}; +assert.sameValue(counter, 2); +assert.sameValue(object.a(), 'A'); +assert.sameValue(object.b(), 'B'); +assert.sameValue(object.c(), 'C'); +assert.sameValue(object.d(), 'D'); +assert(compareArray(Object.keys(object), ['a', 'b', 'c', 'd']));