(Computed Property Names) Re-organize, add assertion messages.

This commit is contained in:
Rick Waldron 2015-03-05 13:39:30 -05:00
parent bd682d8e37
commit e7a6c05d36
41 changed files with 507 additions and 305 deletions

View File

@ -17,8 +17,11 @@ var object = {
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']));
assert.sameValue(object.a, 'A', "The value of `object.a` is `'A'`. Defined in `object` as `a: 'A'`");
assert.sameValue(object[1], 'B', "The value of `object[1]` is `'B'`. Defined in `object` as `[1]: 'B'`");
assert.sameValue(object.c, 'C', "The value of `object.c` is `'C'`. Defined in `object` as `c: 'C'`");
assert.sameValue(object[2], 'D', "The value of `object[2]` is `'D'`. Defined in `object` as `[ID(2)]: 'D'`");
assert(
compareArray(Object.keys(object), ['1', '2', 'a', 'c']),
"`compareArray(Object.keys(object), ['1', '2', 'a', 'c'])` returns `true`"
);

View File

@ -16,8 +16,11 @@ var object = {
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']));
assert.sameValue(object.a, 'A', "The value of `object.a` is `'A'`. Defined in `object` as `a: 'A'`");
assert.sameValue(object.b, 'B', "The value of `object.b` is `'B'`. Defined in `object` as `['b']: 'B'`");
assert.sameValue(object.c, 'C', "The value of `object.c` is `'C'`. Defined in `object` as `c: 'C'`");
assert.sameValue(object.d, 'D', "The value of `object.d` is `'D'`. Defined in `object` as `[ID('d')]: 'D'`");
assert(
compareArray(Object.keys(object), ['a', 'b', 'c', 'd']),
"`compareArray(Object.keys(object), ['a', 'b', 'c', 'd'])` returns `true`"
);

View File

@ -19,11 +19,14 @@ var object = {
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']));
assert.sameValue(object.a, 'A', "The value of `object.a` is `'A'`. Defined in `object` as `a: 'A'`");
assert.sameValue(object[sym1], 'B', "The value of `object[sym1]` is `'B'`. Defined in `object` as `[sym1]: 'B'`");
assert.sameValue(object.c, 'C', "The value of `object.c` is `'C'`. Defined in `object` as `c: 'C'`");
assert.sameValue(object[sym2], 'D', "The value of `object[sym2]` is `'D'`. Defined in `object` as `[ID(sym2)]: 'D'`");
assert(
compareArray(Object.keys(object), ['a', 'c']),
"`compareArray(Object.keys(object), ['a', 'c'])` returns `true`"
);
// compareArray expects arguments to be sorted,
// which will cause an array containing symbols to
@ -36,6 +39,12 @@ assert(compareArray(Object.keys(object), ['a', 'c']));
//
var symbols = Object.getOwnPropertySymbols(object);
assert(symbols.indexOf(sym1) !== -1);
assert(symbols.indexOf(sym2) !== -1);
assert.sameValue(symbols.length, 2);
assert(
symbols.indexOf(sym1) !== -1,
"The result of `symbols.indexOf(sym1) !== -1` is `true`, after executing `var symbols = Object.getOwnPropertySymbols(object);`"
);
assert(
symbols.indexOf(sym2) !== -1,
"The result of `symbols.indexOf(sym2) !== -1` is `true`, after executing `var symbols = Object.getOwnPropertySymbols(object);`"
);
assert.sameValue(symbols.length, 2, "The value of `symbols.length` is `2`, after executing `var symbols = Object.getOwnPropertySymbols(object);`");

View File

@ -11,37 +11,37 @@ class C {
return 'A';
}
}
assert.sameValue(new C().a, 'A');
assert.sameValue(new C().a, 'A', "The value of `new C().a` is `'A'`");
class C2 {
get b() {
assert(false);
$ERROR("The first `b` getter definition in `C2` is unreachable");
}
get ['b']() {
return 'B';
}
}
assert.sameValue(new C2().b, 'B');
assert.sameValue(new C2().b, 'B', "The value of `new C2().b` is `'B'`");
class C3 {
get c() {
assert(false);
$ERROR("The first `c` getter definition in `C3` is unreachable");
}
get ['c']() {
assert(false);
$ERROR("The second `c` getter definition in `C3` is unreachable");
}
get ['c']() {
return 'C';
}
}
assert.sameValue(new C3().c, 'C');
assert.sameValue(new C3().c, 'C', "The value of `new C3().c` is `'C'`");
class C4 {
get ['d']() {
assert(false);
$ERROR("The first `d` getter definition in `C4` is unreachable");
}
get d() {
return 'D';
}
}
assert.sameValue(new C4().d, 'D');
assert.sameValue(new C4().d, 'D', "The value of `new C4().d` is `'D'`");

View File

@ -10,4 +10,4 @@ class C {
return 'A';
}
}
assert.sameValue(new C().a, 'A');
assert.sameValue(new C().a, 'A', "The value of `new C().a` is `'A'`");

View File

@ -13,43 +13,43 @@ class C {
}
}
new C().a = 'A';
assert.sameValue(calls, 1);
assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `new C().a = 'A';`");
calls = 0;
class C2 {
set b(_) {
assert(false);
$ERROR("The first `b` setter definition in `C2` is unreachable");
}
set ['b'](_) {
calls++;
}
}
new C2().b = 'B';
assert.sameValue(calls, 1);
assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `new C2().b = 'B';`");
calls = 0;
class C3 {
set c(_) {
assert(false)
$ERROR("The first `c` setter definition in `C3` is unreachable");
}
set ['c'](_) {
assert(false)
$ERROR("The second `c` setter definition in `C3` is unreachable");
}
set ['c'](_) {
calls++
}
}
new C3().c = 'C';
assert.sameValue(calls, 1);
assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `new C3().c = 'C';`");
calls = 0;
class C4 {
set ['d'](_) {
assert(false)
$ERROR("The first `d` setter definition in `C4` is unreachable");
}
set d(_) {
calls++
}
}
new C4().d = 'D';
assert.sameValue(calls, 1);
assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `new C4().d = 'D';`");

View File

@ -12,4 +12,4 @@ class C {
}
}
new C().a = 'A';
assert.sameValue(calls, 1);
assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `new C().a = 'A';`");

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: 14.5.3
description: >
computed property generator method names cannot be "constructor"
negative: SyntaxError
---*/
class C4 {
*['constructor']() {
}
}

View File

@ -0,0 +1,11 @@
// 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: 14.5.3
description: >
computed property getter names cannot be "constructor"
negative: SyntaxError
---*/
class C4 {
get ['constructor']() {}
}

View File

@ -0,0 +1,11 @@
// 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: 14.5.3
description: >
computed property setter names cannot be "constructor"
negative: SyntaxError
---*/
class C4 {
set ['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: >
computed property names can be "constructor", but duplicates are not allowed, 1
negative: SyntaxError
---*/
class C {
constructor() {}
['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: >
computed property names can be "constructor", but duplicates are not allowed, 2
negative: SyntaxError
---*/
class C {
['constructor']() {}
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: >
computed property names can be "constructor", but duplicates are not allowed, 2
negative: SyntaxError
---*/
class C {
['constructor']() {}
['constructor']() {}
}

View File

@ -10,32 +10,8 @@ class C {
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);
assert(
C !== C.prototype.constructor,
"The result of `C !== C.prototype.constructor` is `true`"
);
assert.sameValue(new C().constructor(), 1, "`new C().constructor()` returns `1`");

View File

@ -12,5 +12,12 @@ class C {
yield 2;
}
}
assert.sameValue(Object.keys(C.prototype).length, 0);
assert(compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a']));
assert.sameValue(
Object.keys(C.prototype).length,
0,
"The value of `Object.keys(C.prototype).length` is `0`"
);
assert(
compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a']),
"`compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a'])` returns `true`"
);

View File

@ -17,9 +17,15 @@ class C {
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']));
assert.sameValue(new C().a(), 'A', "`new C().a()` returns `'A'`, from `a() { return 'A'; }`");
assert.sameValue(new C()[1](), 'B', "`new C()[1]()` returns `'B'`, from `[1]() { return 'B'; }`");
assert.sameValue(new C().c(), 'C', "`new C().c()` returns `'C'`, from `c() { return 'C'; }`");
assert.sameValue(new C()[2](), 'D', "`new C()[2]()` returns `'D'`, from `[ID(2)]() { return 'D'; }`");
assert(
compareArray(Object.keys(C.prototype), []),
"`compareArray(Object.keys(C.prototype), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C.prototype), ['1', '2', 'constructor', 'a', 'c']),
"`compareArray(Object.getOwnPropertyNames(C.prototype), ['1', '2', 'constructor', 'a', 'c'])` returns `true`"
);

View File

@ -17,9 +17,15 @@ class C {
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']));
assert.sameValue(new C().a(), 'A', "`new C().a()` returns `'A'`. Defined as `a() { return 'A'}`");
assert.sameValue(new C().b(), 'B', "`new C().b()` returns `'B'`. Defined as `['b']() { return 'B'; }`");
assert.sameValue(new C().c(), 'C', "`new C().c()` returns `'C'`. Defined as `c() { return 'C'; }`");
assert.sameValue(new C().d(), 'D', "`new C().d()` returns `'D'`. Defined as `[ID('d')]() { return 'D'; }`");
assert(
compareArray(Object.keys(C.prototype), []),
"`compareArray(Object.keys(C.prototype), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'b', 'c', 'd']),
"`compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'b', 'c', 'd'])` returns `true`"
);

View File

@ -19,12 +19,18 @@ class C {
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']));
assert.sameValue(new C().a(), 'A', "`new C().a()` returns `'A'`. Defined as `a() { return 'A'; }`");
assert.sameValue(new C()[sym1](), 'B', "`new C()[sym1]()` returns `'B'`. Defined as `[sym1]() { return 'B'; }`");
assert.sameValue(new C().c(), 'C', "`new C().c()` returns `'C'`. Defined as `c() { return 'C'; }`");
assert.sameValue(new C()[sym2](), 'D', "`new C()[sym2]()` returns `'D'`. Defined as `[ID(sym2)]() { return 'D'; }`");
assert(
compareArray(Object.keys(C.prototype), []),
"`compareArray(Object.keys(C.prototype), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'c']),
"`compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'c'])` returns `true`"
);
// compareArray expects arguments to be sorted,
// which will cause an array containing symbols to
@ -37,6 +43,12 @@ assert(compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a'
//
var symbols = Object.getOwnPropertySymbols(C.prototype);
assert(symbols.indexOf(sym1) !== -1);
assert(symbols.indexOf(sym2) !== -1);
assert.sameValue(symbols.length, 2);
assert(
symbols.indexOf(sym1) !== -1,
"The result of `symbols.indexOf(sym1) !== -1` is `true`, after executing `var symbols = Object.getOwnPropertySymbols(C.prototype);`"
);
assert(
symbols.indexOf(sym2) !== -1,
"The result of `symbols.indexOf(sym2) !== -1` is `true`, after executing `var symbols = Object.getOwnPropertySymbols(C.prototype);`"
);
assert.sameValue(symbols.length, 2, "The value of `symbols.length` is `2`, after executing `var symbols = Object.getOwnPropertySymbols(C.prototype);`");

View File

@ -8,5 +8,5 @@ description: >
negative: SyntaxError
---*/
class C {
static * ['constructor']() {}
static *['constructor']() {}
}

View File

@ -12,9 +12,15 @@ class C {
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']));
assert.sameValue(C.a(), 'A', "`C.a()` returns `'A'`. Defined as `static a() { return 'A'; }`");
assert.sameValue(C[1](), 'B', "`C[1]()` returns `'B'`. Defined as `static [1]() { return 'B'; }`");
assert.sameValue(C.c(), 'C', "`C.c()` returns `'C'`. Defined as `static c() { return 'C'; }`");
assert.sameValue(C[2](), 'D', "`C[2]()` returns `'D'`. Defined as `static [2]() { return 'D'; }`");
assert(
compareArray(Object.keys(C), []),
"`compareArray(Object.keys(C), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'name', 'prototype', 'a', 'c']),
"`compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'name', 'prototype', 'a', 'c'])` returns `true`"
);

View File

@ -12,9 +12,15 @@ class C {
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']));
assert.sameValue(C.a(), 'A', "`C.a()` returns `'A'`. Defined as `static a() { return 'A'}`");
assert.sameValue(C.b(), 'B', "`C.b()` returns `'B'`. Defined as `static ['b']() { return 'B'; }`");
assert.sameValue(C.c(), 'C', "`C.c()` returns `'C'`. Defined as `static c() { return 'C'; }`");
assert.sameValue(C.d(), 'D', "`C.d()` returns `'D'`. Defined as `static ['d']() { return 'D'; }`");
assert(
compareArray(Object.keys(C), []),
"`compareArray(Object.keys(C), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype', 'a', 'b', 'c', 'd']),
"`compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype', 'a', 'b', 'c', 'd'])` returns `true`"
);

View File

@ -14,12 +14,18 @@ class C {
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']));
assert.sameValue(C.a(), 'A', "`C.a()` returns `'A'`. Defined as `static a() { return 'A'; }`");
assert.sameValue(C[sym1](), 'B', "`C[sym1]()` returns `'B'`. Defined as `static [sym1]() { return 'B'; }`");
assert.sameValue(C.c(), 'C', "`C.c()` returns `'C'`. Defined as `static c() { return 'C'; }`");
assert.sameValue(C[sym2](), 'D', "`C[sym2]()` returns `'D'`. Defined as `static [sym2]() { return 'D'; }`");
assert(
compareArray(Object.keys(C), []),
"`compareArray(Object.keys(C), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype', 'a', 'c']),
"`compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype', 'a', 'c'])` returns `true`"
);
// compareArray expects arguments to be sorted,
@ -33,6 +39,16 @@ assert(compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype
//
var symbols = Object.getOwnPropertySymbols(C);
assert(symbols.indexOf(sym1) !== -1);
assert(symbols.indexOf(sym2) !== -1);
assert.sameValue(symbols.length, 2);
assert(
symbols.indexOf(sym1) !== -1,
"The result of `symbols.indexOf(sym1) !== -1` is `true`, after executing `var symbols = Object.getOwnPropertySymbols(C);`"
);
assert(
symbols.indexOf(sym2) !== -1,
"The result of `symbols.indexOf(sym2) !== -1` is `true`, after executing `var symbols = Object.getOwnPropertySymbols(C);`"
);
assert.sameValue(
symbols.length,
2,
"The value of `symbols.length` is `2`, after executing `var symbols = Object.getOwnPropertySymbols(C);`"
);

View File

@ -1,13 +0,0 @@
// 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

@ -1,13 +0,0 @@
// 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

@ -1,23 +0,0 @@
// 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,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 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'`");

View File

@ -24,7 +24,23 @@ var object = {
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');
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(); }`"
);

View File

@ -3,45 +3,11 @@
/*---
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.
Computed property names for getters
---*/
var object = {
get ['a']() {
return 'A';
var A = {
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');
assert.sameValue(A.a, "A", "The value of `A.a` is `'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 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`");

View File

@ -26,10 +26,10 @@ var object = {
Object.setPrototypeOf(object, proto);
object.a = 2;
assert.sameValue(value, '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');
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');
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');
assert.sameValue(value, '1 5', "The value of `value` is `'1 5'`, after executing `object[1] = 5;`");

View File

@ -7,49 +7,10 @@ description: >
that name, whose value is the value of the last property of that name.
---*/
var calls = 0;
var object = {
var A = {
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);
A.a = 'A';
assert.sameValue(calls, 1, "The value of `calls` is `1`, after executing `A.a = 'A';`");

View File

@ -12,4 +12,7 @@ var object = {
yield 2;
}
};
assert(compareArray(Object.keys(object), ['a']));
assert(
compareArray(Object.keys(object), ['a']),
"`compareArray(Object.keys(object), ['a'])` returns `true`"
);

View File

@ -17,8 +17,11 @@ var object = {
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']));
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.keys(object), ['1', '2', 'a', 'c']),
"`compareArray(Object.keys(object), ['1', '2', 'a', 'c'])` returns `true`"
);

View File

@ -17,8 +17,11 @@ var object = {
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']));
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.keys(object), ['a', 'b', 'c', 'd']),
"`compareArray(Object.keys(object), ['a', 'b', 'c', 'd'])` returns `true`"
);

View File

@ -24,7 +24,7 @@ var object = {
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');
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);`");

View File

@ -19,11 +19,14 @@ var object = {
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']));
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.keys(object), ['a', 'c']),
"`compareArray(Object.keys(object), ['a', 'c'])` returns `true`"
);
// compareArray expects arguments to be sorted,
// which will cause an array containing symbols to
@ -36,6 +39,12 @@ assert(compareArray(Object.keys(object), ['a', 'c']));
//
var symbols = Object.getOwnPropertySymbols(object);
assert(symbols.indexOf(sym1) !== -1);
assert(symbols.indexOf(sym2) !== -1);
assert.sameValue(symbols.length, 2);
assert(
symbols.indexOf(sym1) !== -1,
"The result of `symbols.indexOf(sym1) !== -1` is `true`, after executing `var symbols = Object.getOwnPropertySymbols(object);`"
);
assert(
symbols.indexOf(sym2) !== -1,
"The result of `symbols.indexOf(sym2) !== -1` is `true`, after executing `var symbols = Object.getOwnPropertySymbols(object);`"
);
assert.sameValue(symbols.length, 2, "The value of `symbols.length` is `2`, after executing `var symbols = Object.getOwnPropertySymbols(object);`");

View File

@ -0,0 +1,50 @@
// 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',
"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'`"
);

View File

@ -9,13 +9,13 @@ includes: [compareArray.js]
var counter = 0;
var key1 = {
toString: function() {
assert.sameValue(counter++, 0);
assert.sameValue(counter++, 0, "The result of `counter++` is `0`");
return 'b';
}
};
var key2 = {
toString: function() {
assert.sameValue(counter++, 1);
assert.sameValue(counter++, 1, "The result of `counter++` is `1`");
return 'd';
}
};
@ -25,10 +25,16 @@ class C {
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']));
assert.sameValue(counter, 2, "The value of `counter` is `2`");
assert.sameValue(new C().a(), 'A', "`new C().a()` returns `'A'`. Defined as `a() { return 'A'; }`");
assert.sameValue(new C().b(), 'B', "`new C().b()` returns `'B'`. Defined as `[key1]() { return 'B'; }`");
assert.sameValue(new C().c(), 'C', "`new C().c()` returns `'C'`. Defined as `c() { return 'C'; }`");
assert.sameValue(new C().d(), 'D', "`new C().d()` returns `'D'`. Defined as `[key2]() { return 'D'; }`");
assert(
compareArray(Object.keys(C.prototype), []),
"`compareArray(Object.keys(C.prototype), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'b', 'c', 'd']),
"`compareArray(Object.getOwnPropertyNames(C.prototype), ['constructor', 'a', 'b', 'c', 'd'])` returns `true`"
);

View File

@ -9,14 +9,14 @@ includes: [compareArray.js]
var counter = 0;
var key1 = {
valueOf: function() {
assert.sameValue(counter++, 0);
assert.sameValue(counter++, 0, "The result of `counter++` is `0`");
return 1;
},
toString: null
};
var key2 = {
valueOf: function() {
assert.sameValue(counter++, 1);
assert.sameValue(counter++, 1, "The result of `counter++` is `1`");
return 2;
},
toString: null
@ -28,10 +28,16 @@ class C {
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']));
assert.sameValue(counter, 2, "The value of `counter` is `2`");
assert.sameValue(new C().a(), 'A', "`new C().a()` returns `'A'`. Defined as `a() { return 'A'; }`");
assert.sameValue(new C()[1](), 'B', "`new C()[1]()` returns `'B'`. Defined as `[key1]() { return 'B'; }`");
assert.sameValue(new C().c(), 'C', "`new C().c()` returns `'C'`. Defined as `c() { return 'C'; }`");
assert.sameValue(new C()[2](), 'D', "`new C()[2]()` returns `'D'`. Defined as `[key2]() { return 'D'; }`");
assert(
compareArray(Object.keys(C.prototype), []),
"`compareArray(Object.keys(C.prototype), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C.prototype), ['1', '2', 'constructor', 'a', 'c']),
"`compareArray(Object.getOwnPropertyNames(C.prototype), ['1', '2', 'constructor', 'a', 'c'])` returns `true`"
);

View File

@ -9,14 +9,14 @@ includes: [compareArray.js]
var counter = 0;
var key1 = {
valueOf: function() {
assert.sameValue(counter++, 0);
assert.sameValue(counter++, 0, "The result of `counter++` is `0`");
return 1;
},
toString: null
};
var key2 = {
valueOf: function() {
assert.sameValue(counter++, 1);
assert.sameValue(counter++, 1, "The result of `counter++` is `1`");
return 2;
},
toString: null
@ -28,9 +28,12 @@ var object = {
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']));
assert.sameValue(counter, 2, "The value of `counter` is `2`");
assert.sameValue(object.a, 'A', "The value of `object.a` is `'A'`. Defined as `a: 'A'`");
assert.sameValue(object[1], 'B', "The value of `object[1]` is `'B'`. Defined as `[key1]: 'B'`");
assert.sameValue(object.c, 'C', "The value of `object.c` is `'C'`. Defined as `c: 'C'`");
assert.sameValue(object[2], 'D', "The value of `object[2]` is `'D'`. Defined as `[key2]: 'D'`");
assert(
compareArray(Object.keys(object), ['1', '2', 'a', 'c']),
"`compareArray(Object.keys(object), ['1', '2', 'a', 'c'])` returns `true`"
);

View File

@ -9,13 +9,13 @@ includes: [compareArray.js]
var counter = 0;
var key1 = {
toString: function() {
assert.sameValue(counter++, 0);
assert.sameValue(counter++, 0, "The result of `counter++` is `0`");
return 'b';
}
};
var key2 = {
toString: function() {
assert.sameValue(counter++, 1);
assert.sameValue(counter++, 1, "The result of `counter++` is `1`");
return 'd';
}
};
@ -25,9 +25,12 @@ var object = {
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']));
assert.sameValue(counter, 2, "The value of `counter` is `2`");
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 `[key1]() { 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 `[key2]() { return 'D'; }`");
assert(
compareArray(Object.keys(object), ['a', 'b', 'c', 'd']),
"`compareArray(Object.keys(object), ['a', 'b', 'c', 'd'])` returns `true`"
);