Improve coverage for section 14: Functions and Classes (#717)

* Add tests for early errors in functions

* Improve tests for class accessors

Use the `propertyHelper.js` utility in order to functionally test the
property descriptors of class methods.

* Remove redundant tests

The semantics of an IdentifierReference as a PropertyDefinition within
an object initializer are exhaustively tested by the files in this
directory whose name match the pattern `prop-def-id-*.js`.

Delete the redundant tests in favor of the more descriptively-named and
more exhaustive alternatives.

* Rename tests

* Update test names to be more descriptive

* Add tests for property descriptors of accessors

* Add tests for runtime error during method dfn

* Add test for observable iteration
This commit is contained in:
jugglinmike 2016-07-08 21:43:32 -04:00 committed by Tom Care
parent 2bfaa0d895
commit da0a8e33f0
23 changed files with 314 additions and 41 deletions

View File

@ -0,0 +1,14 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function-definitions-static-semantics-early-errors
es6id: 14.1.2
description: Body may not contain a "super" call
info: >
It is a Syntax Error if FunctionBody Contains SuperCall is true.
negative: SyntaxError
---*/
0, function() {
super();
};

View File

@ -0,0 +1,14 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function-definitions-static-semantics-early-errors
es6id: 14.1.2
description: Body may not contain a "super" property reference
info: >
It is a Syntax Error if FunctionBody Contains SuperProperty is true.
negative: SyntaxError
---*/
0, function() {
super.x;
};

View File

@ -0,0 +1,12 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function-definitions-static-semantics-early-errors
es6id: 14.1.2
description: Parameters may not contain a "super" call
info: >
It is a Syntax Error if FormalParameters Contains SuperProperty is true.
negative: SyntaxError
---*/
0, function(x = super()) {};

View File

@ -0,0 +1,12 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function-definitions-static-semantics-early-errors
es6id: 14.1.2
description: Parameters may not contain a "super" property reference
info: >
It is a Syntax Error if FunctionBody Contains SuperProperty is true.
negative: SyntaxError
---*/
0, function(x = super.x) {};

View File

@ -1,14 +0,0 @@
// Copyright (C) 2015 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: >
object literal property shorthand desciptor defaults
---*/
var x = 1;
var object = {x};
var desc = Object.getOwnPropertyDescriptor(object, 'x');
assert.sameValue(desc.value, 1, "The value of `desc.value` is `1`, where `var desc = Object.getOwnPropertyDescriptor(object, 'x');`");
assert.sameValue(desc.enumerable, true, "The value of `desc.enumerable` is `true`, where `var desc = Object.getOwnPropertyDescriptor(object, 'x');`");
assert.sameValue(desc.writable, true, "The value of `desc.writable` is `true`, where `var desc = Object.getOwnPropertyDescriptor(object, 'x');`");
assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`, where `var desc = Object.getOwnPropertyDescriptor(object, 'x');`");

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object-initializer-runtime-semantics-evaluation
es6id: 12.2.6.8
description: Property descriptor of "set" accessor methods
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.
3. ReturnIfAbrupt(status).
4. Return obj.
14.3.8 Runtime Semantics: PropertyDefinitionEvaluation
MethodDefinition : get PropertyName ( ) { FunctionBody}
[...]
9. Let desc be the PropertyDescriptor{[[Get]]: closure, [[Enumerable]]:
enumerable, [[Configurable]]: true}.
[...]
includes: [propertyHelper.js]
---*/
var obj = { get m() { return 1234; } };
var desc = Object.getOwnPropertyDescriptor(obj, 'm');
verifyEnumerable(obj, 'm');
verifyConfigurable(obj, 'm');
assert.sameValue(desc.value, undefined, '`value` field');
assert.sameValue(desc.set, undefined, '`set` field');
assert.sameValue(typeof desc.get, 'function', 'type of `get` field');
assert.sameValue(desc.get(), 1234, '`get` function return value');

View File

@ -1,9 +0,0 @@
// Copyright (C) 2015 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: >
Basic identifier reference property initialization
---*/
var p = "1";
var o = {p};

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-object-initializer-runtime-semantics-evaluation
es6id: 12.2.6.8
description: Property descriptor of "set" accessor methods
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.
3. ReturnIfAbrupt(status).
4. Return obj.
14.3.8 Runtime Semantics: PropertyDefinitionEvaluation
MethodDefinition : set PropertyName ( PropertySetParameterList ) { FunctionBody }
[...]
8. Let desc be the PropertyDescriptor{[[Set]]: closure, [[Enumerable]]:
enumerable, [[Configurable]]: true}.
[...]
includes: [propertyHelper.js]
---*/
var obj = { set m(x) { return x; } };
var desc = Object.getOwnPropertyDescriptor(obj, 'm');
verifyEnumerable(obj, 'm');
verifyConfigurable(obj, 'm');
assert.sameValue(desc.value, undefined, '`value` field');
assert.sameValue(desc.get, undefined, '`get` field');
assert.sameValue(typeof desc.set, 'function', 'type of `set` field');
assert.sameValue(desc.set(436), 436, '`set` function return value');

View File

@ -0,0 +1,47 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classdefinitionevaluation
es6id: 14.5.14
description: >
Observable iteration of arguments during execution of "inferred" constructor
info: |
[...]
10. If constructor is empty, then
a. If ClassHeritageopt is present and protoParent is not null, then
i. Let constructor be the result of parsing the source text
constructor(... args){ super (...args);}
using the syntactic grammar with the goal symbol MethodDefinition[~Yield].
features: [Symbol.iterator]
---*/
var otherIterator = ['fifth', 'sixth', 'seventh'][Symbol.iterator]();
var spread, parentArgs;
function Parent() {
parentArgs = arguments;
}
class C extends Parent {}
Array.prototype[Symbol.iterator] = function() {
spread = this;
return otherIterator;
};
new C('first', 'second', 'third', 'fourth');
assert.sameValue(Object.getPrototypeOf(spread), Array.prototype);
assert.sameValue(spread.length, 4);
assert.sameValue(spread[0], 'first');
assert.sameValue(spread[1], 'second');
assert.sameValue(spread[2], 'third');
assert.sameValue(spread[3], 'fourth');
assert.sameValue(
typeof parentArgs, 'object', 'parent arguments object'
);
assert.sameValue(parentArgs.length, 3);
assert.sameValue(parentArgs[0], 'fifth');
assert.sameValue(parentArgs[1], 'sixth');
assert.sameValue(parentArgs[2], 'seventh');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation
es6id: 14.3.9
description: Failure to define property for static method
info: |
[...]
9. Let desc be the PropertyDescriptor{[[Get]]: closure, [[Enumerable]]:
enumerable, [[Configurable]]: true}.
10. Return ? DefinePropertyOrThrow(object, propKey, desc).
features: [generators]
---*/
assert.throws(TypeError, function() {
class C { static get ['prototype']() {} }
});

View File

@ -1,15 +1,16 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions
es6id: 14.5
description: >
class getters
description: Class methods - "get" accessors
includes: [propertyHelper.js]
---*/
function assertGetterDescriptor(object, name) {
var desc = Object.getOwnPropertyDescriptor(object, name);
assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`");
assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`");
verifyNotEnumerable(object, name);
verifyConfigurable(object, name);
assert.sameValue(typeof desc.get, 'function', "`typeof desc.get` is `'function'`");
assert.sameValue('prototype' in desc.get, false, "The result of `'prototype' in desc.get` is `false`");
assert.sameValue(desc.set, undefined, "The value of `desc.set` is `undefined`");
@ -22,12 +23,12 @@ class C {
static get staticY() { return 4; }
}
assertGetterDescriptor(C.prototype, 'x');
assertGetterDescriptor(C.prototype, 'y');
assertGetterDescriptor(C, 'staticX');
assertGetterDescriptor(C, 'staticY');
assert.sameValue(new C().x, 1, "The value of `new C().x` is `1`. Defined as `get x() { return 1; }`");
assert.sameValue(C.staticX, 2, "The value of `C.staticX` is `2`. Defined as `static get staticX() { return 2; }`");
assert.sameValue(new C().y, 3, "The value of `new C().y` is `3`. Defined as `get y() { return 3; }`");
assert.sameValue(C.staticY, 4, "The value of `C.staticY` is `4`. Defined as `static get staticY() { return 4; }`");
assertGetterDescriptor(C.prototype, 'x');
assertGetterDescriptor(C.prototype, 'y');
assertGetterDescriptor(C, 'staticX');
assertGetterDescriptor(C, 'staticY');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation
es6id: 14.3.9
description: Failure to define property for static method
info: |
[...]
8. Let desc be the PropertyDescriptor{[[Set]]: closure, [[Enumerable]]:
enumerable, [[Configurable]]: true}.
9. Return ? DefinePropertyOrThrow(object, propKey, desc).
features: [generators]
---*/
assert.throws(TypeError, function() {
class C { static set ['prototype'](_) {} }
});

View File

@ -1,14 +1,16 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions
es6id: 14.5
description: >
class setters
description: Class methods - "set" accessors
includes: [propertyHelper.js]
---*/
function assertSetterDescriptor(object, name) {
var descr = Object.getOwnPropertyDescriptor(object, name);
assert.sameValue(descr.configurable, true, "The value of `descr.configurable` is `true`");
assert.sameValue(descr.enumerable, false, "The value of `descr.enumerable` is `false`");
verifyNotEnumerable(object, name);
verifyConfigurable(object, name);
assert.sameValue(typeof descr.set, 'function', "`typeof descr.set` is `'function'`");
assert.sameValue('prototype' in descr.set, false, "The result of `'prototype' in descr.set` is `false`");
assert.sameValue(descr.get, undefined, "The value of `descr.get` is `undefined`");
@ -22,11 +24,6 @@ class C {
static set staticY(v) { staticY = v; }
}
assertSetterDescriptor(C.prototype, 'x');
assertSetterDescriptor(C.prototype, 'y');
assertSetterDescriptor(C, 'staticX');
assertSetterDescriptor(C, 'staticY');
assert.sameValue(new C().x = 1, 1, "`new C().x = 1` is `1`");
assert.sameValue(x, 1, "The value of `x` is `1`");
assert.sameValue(C.staticX = 2, 2, "`C.staticX = 2` is `2`");
@ -35,3 +32,8 @@ assert.sameValue(new C().y = 3, 3, "`new C().y = 3` is `3`");
assert.sameValue(y, 3, "The value of `y` is `3`");
assert.sameValue(C.staticY = 4, 4, "`C.staticY = 4` is `4`");
assert.sameValue(staticY, 4, "The value of `staticY` is `4`");
assertSetterDescriptor(C.prototype, 'x');
assertSetterDescriptor(C.prototype, 'y');
assertSetterDescriptor(C, 'staticX');
assertSetterDescriptor(C, 'staticY');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-generator-function-definitions-runtime-semantics-propertydefinitionevaluation
es6id: 14.4.13
description: Failure to define property for static generator method
info: |
[...]
10. Let desc be the PropertyDescriptor{[[Value]]: closure, [[Writable]]:
true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
11. Return ? DefinePropertyOrThrow(object, propKey, desc).
features: [generators]
---*/
assert.throws(TypeError, function() {
class C { static *['prototype']() {} }
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-method-definitions-runtime-semantics-propertydefinitionevaluation
es6id: 14.3.9
description: Failure to define property for static method
info: |
[...]
10. Let desc be the PropertyDescriptor{[[Value]]: closure, [[Writable]]:
true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
11. Return ? DefinePropertyOrThrow(object, propKey, desc).
features: [generators]
---*/
assert.throws(TypeError, function() {
class C { static ['prototype']() {} }
});

View File

@ -0,0 +1,14 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function-definitions-static-semantics-early-errors
es6id: 14.1.2
description: Body may not contain a "super" call
info: >
It is a Syntax Error if FunctionBody Contains SuperCall is true.
negative: SyntaxError
---*/
function f() {
super();
}

View File

@ -0,0 +1,14 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function-definitions-static-semantics-early-errors
es6id: 14.1.2
description: Body may not contain a "super" property reference
info: >
It is a Syntax Error if FunctionBody Contains SuperProperty is true.
negative: SyntaxError
---*/
function f() {
super.x;
}

View File

@ -0,0 +1,12 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function-definitions-static-semantics-early-errors
es6id: 14.1.2
description: Parameters may not contain a "super" call
info: >
It is a Syntax Error if FormalParameters Contains SuperProperty is true.
negative: SyntaxError
---*/
function f(x = super()) {}

View File

@ -0,0 +1,12 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-function-definitions-static-semantics-early-errors
es6id: 14.1.2
description: Parameters may not contain a "super" property reference
info: >
It is a Syntax Error if FunctionBody Contains SuperProperty is true.
negative: SyntaxError
---*/
function f(x = super.x) {}