Import tests from Google V8 (Computed Property Names)

These tests are derived from the following files within the Google V8
project:

        test/mjsunit/harmony/computed-property-names-classes.js
        test/mjsunit/harmony/computed-property-names-object-literals-methods.js
        test/mjsunit/harmony/computed-property-names-super.js
        test/mjsunit/harmony/computed-property-names.js
This commit is contained in:
Rick Waldron 2015-03-02 14:10:32 -05:00
parent 2eca2c71e8
commit bd682d8e37
39 changed files with 1031 additions and 0 deletions

View File

@ -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']));

View File

@ -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']));

View File

@ -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);

View File

@ -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');

View File

@ -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');

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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']));

View File

@ -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']));

View File

@ -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']));

View File

@ -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);

View File

@ -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']() {}
}

View File

@ -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']() {}
}

View File

@ -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']() {}
}

View File

@ -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']() {}
}

View File

@ -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']() {}
}

View File

@ -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']));

View File

@ -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']() {}
}

View File

@ -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']));

View File

@ -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);

View File

@ -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) {}
}

View File

@ -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) {}
}

View File

@ -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);

View File

@ -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);

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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);

View File

@ -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']));

View File

@ -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']));

View File

@ -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']));

View File

@ -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');

View File

@ -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);

View File

@ -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']));

View File

@ -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']));

View File

@ -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']));

View File

@ -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']));