Skip to content

Commit

Permalink
Add tests for accessor names
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and leobalter committed Mar 1, 2017
1 parent d93bee5 commit 228851f
Show file tree
Hide file tree
Showing 41 changed files with 1,204 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/accessor-names/computed-err-evaluation.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Abrupt completion when evaluating expression
template: error
info: |
12.2.6.7 Runtime Semantics: Evaluation

ComputedPropertyName : [ AssignmentExpression ]

1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
---*/

//- setup
var thrower = function() {
throw new Test262Error();
};

//- error
Test262Error
//- name
thrower()
39 changes: 39 additions & 0 deletions src/accessor-names/computed-err-to-prop-key.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Abrupt completion when coercing to property key value
template: error
info: |
12.2.6.7 Runtime Semantics: Evaluation

[...]

ComputedPropertyName : [ AssignmentExpression ]

1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).

7.1.14 ToPropertyKey

1. Let key be ? ToPrimitive(argument, hint String).

7.1.1 ToPrimitive

[...]
7. Return ? OrdinaryToPrimitive(input, hint).

7.1.1.1 OrdinaryToPrimitive

5. For each name in methodNames in List order, do
[...]
6. Throw a TypeError exception.
---*/

//- setup
var badKey = Object.create(null);

//- error
TypeError
//- name
badKey
20 changes: 20 additions & 0 deletions src/accessor-names/computed-err-unresolvable.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Abrupt completion when resolving reference value
template: error
info: |
12.2.6.7 Runtime Semantics: Evaluation

[...]

ComputedPropertyName : [ AssignmentExpression ]

1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
---*/

//- error
ReferenceError
//- name
test262unresolvable
24 changes: 24 additions & 0 deletions src/accessor-names/computed.case
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Computed values as accessor property names (AssignmentExpression)
template: default
info: |
12.2.6.7 Runtime Semantics: Evaluation

[...]

ComputedPropertyName : [ AssignmentExpression ]

1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
---*/

//- setup
var _;

//- declareWith
[_ = 'str' + 'ing']
//- referenceWith
'string'
26 changes: 26 additions & 0 deletions src/accessor-names/default/cls-decl-inst.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/accessor-name-inst-
name: Class declaration, instance method
esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14
info: |
[...]
21. For each ClassElement m in order from methods
a. If IsStatic of m is false, then
i. Let status be the result of performing PropertyDefinitionEvaluation
for m with arguments proto and false.
---*/

var stringSet;

class C {
get /*{ declareWith }*/() { return 'get string'; }
set /*{ declareWith }*/(param) { stringSet = param; }
}

assert.sameValue(C.prototype[/*{ referenceWith }*/], 'get string');

C.prototype[/*{ referenceWith }*/] = 'set string';
assert.sameValue(stringSet, 'set string');
28 changes: 28 additions & 0 deletions src/accessor-names/default/cls-decl-static.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/accessor-name-static-
name: Class declaration, static method
esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14
info: |
[...]
21. For each ClassElement m in order from methods
a. If IsStatic of m is false, then
[...]
b. Else,
a. Let status be the result of performing PropertyDefinitionEvaluation
for m with arguments F and false.
---*/

var stringSet;

class C {
static get /*{ declareWith }*/() { return 'get string'; }
static set /*{ declareWith }*/(param) { stringSet = param; }
}

assert.sameValue(C[/*{ referenceWith }*/], 'get string');

C[/*{ referenceWith }*/] = 'set string';
assert.sameValue(stringSet, 'set string');
26 changes: 26 additions & 0 deletions src/accessor-names/default/cls-expr-inst.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/accessor-name-inst-
name: Class expression, instance method
esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14
info: |
[...]
21. For each ClassElement m in order from methods
a. If IsStatic of m is false, then
i. Let status be the result of performing PropertyDefinitionEvaluation
for m with arguments proto and false.
---*/

var stringSet;

var C = class {
get /*{ declareWith }*/() { return 'get string'; }
set /*{ declareWith }*/(param) { stringSet = param; }
};

assert.sameValue(C.prototype[/*{ referenceWith }*/], 'get string');

C.prototype[/*{ referenceWith }*/] = 'set string';
assert.sameValue(stringSet, 'set string');
28 changes: 28 additions & 0 deletions src/accessor-names/default/cls-expr-static.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/accessor-name-static-
name: Class expression, static method
esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14
info: |
[...]
21. For each ClassElement m in order from methods
a. If IsStatic of m is false, then
[...]
b. Else,
a. Let status be the result of performing PropertyDefinitionEvaluation
for m with arguments F and false.
---*/

var stringSet;

var C = class {
static get /*{ declareWith }*/() { return 'get string'; }
static set /*{ declareWith }*/(param) { stringSet = param; }
};

assert.sameValue(C[/*{ referenceWith }*/], 'get string');

C[/*{ referenceWith }*/] = 'set string';
assert.sameValue(stringSet, 'set string');
27 changes: 27 additions & 0 deletions src/accessor-names/default/obj.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/object/accessor-name-
name: Object initializer
esid: sec-object-initializer-runtime-semantics-evaluation
es6id: 12.2.6.8
info: |
ObjectLiteral :
{ PropertyDefinitionList }
{ PropertyDefinitionList , }

1. Let obj be ObjectCreate(%ObjectPrototype%).
2. Let status be the result of performing PropertyDefinitionEvaluation of
PropertyDefinitionList with arguments obj and true.
---*/

var stringSet;
var obj = {
get [/*{ declareWith }*/]() { return 'get string'; },
set [/*{ declareWith }*/](param) { stringSet = param; }
};

assert.sameValue(obj[/*{ referenceWith }*/], 'get string');

obj[/*{ referenceWith }*/] = 'set string';
assert.sameValue(stringSet, 'set string');
26 changes: 26 additions & 0 deletions src/accessor-names/error/cls-decl-inst.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/accessor-name-inst-
name: Class declaration, instance method
esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14
info: |
[...]
21. For each ClassElement m in order from methods
a. If IsStatic of m is false, then
i. Let status be the result of performing PropertyDefinitionEvaluation
for m with arguments proto and false.
---*/

assert.throws(/*{ error }*/, function() {
class C {
get [/*{ name }*/]() {}
}
}, '`get` accessor');

assert.throws(/*{ error }*/, function() {
class C {
set [/*{ name }*/](_) {}
}
}, '`set` accessor');
28 changes: 28 additions & 0 deletions src/accessor-names/error/cls-decl-static.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/accessor-name-static-
name: Class declaration, static method
esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14
info: |
[...]
21. For each ClassElement m in order from methods
a. If IsStatic of m is false, then
[...]
b. Else,
a. Let status be the result of performing PropertyDefinitionEvaluation
for m with arguments F and false.
---*/

assert.throws(/*{ error }*/, function() {
class C {
static get [/*{ name }*/]() {}
}
}, '`get` accessor');

assert.throws(/*{ error }*/, function() {
class C {
static set [/*{ name }*/](_) {}
}
}, '`set` accessor');
26 changes: 26 additions & 0 deletions src/accessor-names/error/cls-expr-inst.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/accessor-name-inst-
name: Class expression, instance method
esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14
info: |
[...]
21. For each ClassElement m in order from methods
a. If IsStatic of m is false, then
i. Let status be the result of performing PropertyDefinitionEvaluation
for m with arguments proto and false.
---*/

assert.throws(/*{ error }*/, function() {
0, class {
get [/*{ name }*/]() {}
};
}, '`get` accessor');

assert.throws(/*{ error }*/, function() {
0, class {
set [/*{ name }*/](_) {}
};
}, '`set` accessor');
28 changes: 28 additions & 0 deletions src/accessor-names/error/cls-expr-static.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/accessor-name-static-
name: Class expression, static method
esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14
info: |
[...]
21. For each ClassElement m in order from methods
a. If IsStatic of m is false, then
[...]
b. Else,
a. Let status be the result of performing PropertyDefinitionEvaluation
for m with arguments F and false.
---*/

assert.throws(/*{ error }*/, function() {
0, class {
static get [/*{ name }*/]() {}
};
}, '`get` accessor');

assert.throws(/*{ error }*/, function() {
0, class {
static set [/*{ name }*/](_) {}
};
}, '`set` accessor');
28 changes: 28 additions & 0 deletions src/accessor-names/error/obj.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2017 Mike Pennisi. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/object/accessor-name-
name: Object initializer
esid: sec-object-initializer-runtime-semantics-evaluation
es6id: 12.2.6.8
info: |
ObjectLiteral :
{ PropertyDefinitionList }
{ PropertyDefinitionList , }

1. Let obj be ObjectCreate(%ObjectPrototype%).
2. Let status be the result of performing PropertyDefinitionEvaluation of
PropertyDefinitionList with arguments obj and true.
---*/

assert.throws(/*{ error }*/, function() {
({
get [/*{ name }*/]() {}
});
}, '`get` accessor');

assert.throws(/*{ error }*/, function() {
({
set [/*{ name }*/](_) {}
});
}, '`set` accessor');
Loading

0 comments on commit 228851f

Please sign in to comment.