Skip to content
Snippets Groups Projects
Unverified Commit 228851fb authored by Mike Pennisi's avatar Mike Pennisi Committed by Leonardo Balter
Browse files

Add tests for accessor names

parent d93bee59
No related branches found
No related tags found
No related merge requests found
Showing
with 503 additions and 0 deletions
// 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()
// 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
// 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
// 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'
// 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');
// 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');
// 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');
// 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');
// 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');
// 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');
// 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');
// 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');
// 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');
// 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');
// 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 (numeric literal in binary notation)
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).
---*/
//- declareWith
0b10
//- referenceWith
'2'
// 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 (numeric literal in exponent notation)
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).
---*/
//- declareWith
1E+9
//- referenceWith
'1000000000'
// 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 (numeric literal in hexadecimal notation)
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).
---*/
//- declareWith
0x10
//- referenceWith
'16'
// 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 (numeric literal with leading decimal point)
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).
---*/
//- declareWith
.1
//- referenceWith
'0.1'
// 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 (numeric literal with non-canonical representation)
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).
---*/
//- declareWith
0.0000001
//- referenceWith
'1e-7'
// 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 (numeric literal in octal notation)
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).
---*/
//- declareWith
0o10
//- referenceWith
'8'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment