Add tests for MethodDefinition forms new to ES6

This commit is contained in:
Mike Pennisi 2015-05-19 17:51:59 -04:00
parent cde990b79c
commit 31bdf48bec
35 changed files with 686 additions and 0 deletions

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Generator functions declared as methods may be used as constructors.
es6id: 14.4.13
features: [generators]
---*/
var method = { *method() {} }.method;
var instance = new method();
assert.sameValue(instance instanceof method, true);

View File

@ -0,0 +1,23 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
In the absence of the "use strict" directive, generator functions declared
as methods obey "global" ThisMode semantics.
es6id: 14.4.13
flags: [noStrict]
features: [generators]
---*/
var global = (function() { return this; }());
var thisValue = null;
var method = {
*method() {
thisValue = this;
}
}.method;
method().next();
assert.sameValue(thisValue, global);

View File

@ -0,0 +1,23 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
In the presence of the "use strict" directive, generator functions declared
as methods obey "strict" ThisMode semantics.
es6id: 14.4.13
flags: [noStrict]
features: [generators]
---*/
var thisValue = null;
var method = {
*method() {
'use strict';
thisValue = this;
}
}.method;
method().next();
assert.sameValue(thisValue, undefined);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Generator functions declared as methods have a `length` property that
describes the number of formal parameters.
es6id: 14.4.13
includes: [propertyHelper.js]
features: [generators]
---*/
var method = { *method(a, b, c) {} }.method;
assert.sameValue(method.length, 3);
verifyNotEnumerable(method, 'length');
verifyNotWritable(method, 'length');
verifyConfigurable(method, 'length');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Generator functions declared as methods are assigned a `name` property
according to the string value of their property name.
es6id: 14.4.13
includes: [propertyHelper.js]
features: [generators]
---*/
var method = { *method() {} }.method;
assert.sameValue(method.name, 'method');
verifyNotEnumerable(method, 'name');
verifyNotWritable(method, 'name');
verifyConfigurable(method, 'name');

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Generator functions declared as methods are assigned a `name` property
according to the string value of their property name.
es6id: 14.4.13
includes: [propertyHelper.js]
features: [Symbol, generators]
---*/
var name = Symbol('method');
var method = { *[name]() {} }[name];
assert.sameValue(method.name, '[method]');
verifyNotEnumerable(method, 'name');
verifyNotWritable(method, 'name');
verifyConfigurable(method, 'name');

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
The BindingIdentifier of a SingleNameBinding witihn the FormalParameters of
a GeneratorMethod may not be the `yield` keyword.
es6id: 14.4
features: [generators]
flags: [noStrict]
negative: SyntaxError
---*/
({
*method(yield) {}
});

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
When the `yield` keyword occurs within the Initializer of a
SingleNameBinding witihn the FormalParameters of a GeneratorMethod, it
behaves as a YieldExpression.
es6id: 14.4
features: [generators]
flags: [noStrict]
---*/
var yield = 'defaultViaIdentifier';
var obj;
var iter = (function*() {
obj = {
*method(x = yield) {
return x;
}
};
}());
iter.next();
iter.next('defaultViaExpression');
assert.sameValue(obj.method().next(), 'defaultViaExpression');

View File

@ -0,0 +1,28 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Generator functions declared as methods honor their declared formal
parameters.
es6id: 14.4.13
features: [generators]
---*/
var value1 = {};
var value2 = {};
var value3 = {};
var arg1, arg2, arg3;
var obj = {
*method(a, b, c) {
arg1 = a;
arg2 = b;
arg3 = c;
}
};
obj.method(value1, value2, value3).next();
assert.sameValue(arg1, value1);
assert.sameValue(arg2, value2);
assert.sameValue(arg3, value3);

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Errors thrown during method definition are forwarded to the runtime.
es6id: 14.4.13
features: [generators]
---*/
assert.throws(Test262Error, function() {
({
*[(function() { throw new Test262Error(); }())]() {}
});
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
When the `yield` keyword occurs within the PropertyName of a
GeneratorMethod within a generator function, it behaves as a
YieldExpression.
es6id: 14.4
features: [generators]
flags: [noStrict]
---*/
var obj = null;
var yield = 'propNameViaIdentifier';
var iter = (function*() {
obj = {
*[yield]() {}
};
})();
iter.next();
assert.sameValue(obj, null);
iter.next('propNameViaExpression');
assert.sameValue(
Object.hasOwnProperty.call(obj, 'propNameViaIdentifier'), false
);
assert.sameValue(
Object.hasOwnProperty.call(obj, 'propNameViaExpression'), true
);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
When the `yield` keyword occurs within the PropertyName of a
GeneratorMethod outside of a generator function, it behaves as an
Identifier.
es6id: 14.4
features: [generators]
flags: [noStrict]
---*/
var yield = 'propName';
var obj = {
*[yield]() {}
};
assert.sameValue(Object.hasOwnProperty.call(obj, 'propName'), true);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Generator functions declared as methods are defined as enumerable,
writable, configurable properties on the initialized object.
es6id: 14.4.13
includes: [propertyHelper.js]
features: [generators]
---*/
var obj = { *method() {} };
verifyEnumerable(obj, 'method');
verifyWritable(obj, 'method');
verifyConfigurable(obj, 'method');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Generator functions declared as methods define a `prototype` property.
es6id: 14.4.13
includes: [propertyHelper.js]
features: [generators]
---*/
var GeneratorPrototype = Object.getPrototypeOf(function* () {}).prototype;
var method = { *method() {} }.method;
verifyNotEnumerable(method, 'prototype');
verifyWritable(method, 'prototype');
verifyNotConfigurable(method, 'prototype');
assert.sameValue(
Object.getPrototypeOf(method.prototype),
GeneratorPrototype
);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
The prototype of generator functions declared as methods is the
Generator Prototype.
es6id: 14.4.13
features: [generators]
---*/
var obj = { *method() {} };
assert.sameValue(
Object.getPrototypeOf(obj.method),
Object.getPrototypeOf(function*() {})
);

View File

@ -0,0 +1,13 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Functions declared as methods may not be used as constructors.
es6id: 14.3.8
---*/
var obj = { method() {} };
assert.throws(TypeError, function() {
new obj.method();
});

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
In the absence of the "use strict" directive, functions declared as methods
obey "global" ThisMode semantics.
es6id: 14.3.8
flags: [noStrict]
---*/
var global = (function() { return this; }());
var thisValue = null;
var method = {
method() {
thisValue = this;
}
}.method;
method();
assert.sameValue(thisValue, global);

View File

@ -0,0 +1,22 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
In the presence of the "use strict" directive, functions declared as
methods obey "strict" ThisMode semantics.
es6id: 14.3.8
flags: [noStrict]
---*/
var thisValue = null;
var method = {
method() {
'use strict';
thisValue = this;
}
}.method;
method();
assert.sameValue(thisValue, undefined);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Functions declared as methods have a `length` property that describes the
number of formal parameters.
es6id: 14.3.8
includes: [propertyHelper.js]
---*/
var method = { method(a, b, c) {} }.method;
assert.sameValue(method.length, 3);
verifyNotEnumerable(method, 'length');
verifyNotWritable(method, 'length');
verifyConfigurable(method, 'length');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Functions declared as methods are assigned a `name` property according to
the string value of their property name.
es6id: 14.3.8
includes: [propertyHelper.js]
---*/
var method = { method() {} }.method;
assert.sameValue(method.name, 'method');
verifyNotEnumerable(method, 'name');
verifyNotWritable(method, 'name');
verifyConfigurable(method, 'name');

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Functions declared as methods are assigned a `name` property according to
the string value of their property name.
es6id: 14.3.8
includes: [propertyHelper.js]
features: [Symbol]
---*/
var name = Symbol('method');
var method = { [name]() {} }[name];
assert.sameValue(method.name, '[method]');
verifyNotEnumerable(method, 'name');
verifyNotWritable(method, 'name');
verifyConfigurable(method, 'name');

View File

@ -0,0 +1,19 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
The BindingIdentifier of a SingleNameBinding witihn the FormalParameters of
a non-generator MethodDefinition may be the `yield` keyword.
es6id: 14.3
flags: [noStrict]
---*/
var obj = {
method(yield) {
return yield;
}
};
assert.sameValue(obj.method('arg'), 'arg');

View File

@ -0,0 +1,21 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
When the `yield` keyword occurs within the Initializer of a
SingleNameBinding within the FormalParameters of a non-generator
MethodDefinition, it behaves as an Identifier.
es6id: 14.3
flags: [noStrict]
---*/
var yield = 'default';
var obj = {
method(x = yield) {
return x;
}
};
assert.sameValue(obj.method(), 'default');

View File

@ -0,0 +1,17 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
It is a Syntax Error if any element of the BoundNames of
StrictFormalParameters also occurs in the LexicallyDeclaredNames of
FunctionBody.
es6id: 14.3.1
negative: SyntaxError
---*/
var obj = {
method(param) {
let param;
}
};

View File

@ -0,0 +1,26 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Functions declared as methods honor their declared formal parameters.
es6id: 14.3.8
---*/
var value1 = {};
var value2 = {};
var value3 = {};
var arg1, arg2, arg3;
var obj = {
method(a, b, c) {
arg1 = a;
arg2 = b;
arg3 = c;
}
};
obj.method(value1, value2, value3);
assert.sameValue(arg1, value1);
assert.sameValue(arg2, value2);
assert.sameValue(arg3, value3);

View File

@ -0,0 +1,14 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Errors thrown during method definition are forwarded to the runtime.
es6id: 14.3.8
---*/
assert.throws(Test262Error, function() {
({
[(function() { throw new Test262Error(); }())]() {}
});
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
When the `yield` keyword occurs within the PropertyName of a
non-generator MethodDefinition within a generator function, it behaves as a
YieldExpression.
es6id: 14.3
features: [generators]
flags: [noStrict]
---*/
var obj = null;
var yield = 'propNameViaIdentifier';
var iter = (function*() {
obj = {
[yield]() {}
};
})();
iter.next();
assert.sameValue(obj, null);
iter.next('propNameViaExpression');
assert.sameValue(
Object.hasOwnProperty.call(obj, 'propNameViaIdentifier'), false
);
assert.sameValue(
Object.hasOwnProperty.call(obj, 'propNameViaExpression'), true
);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
When the `yield` keyword occurs within the PropertyName of a
non-generator MethodDefinition outside of a generator function, it behaves
as an Identifier.
es6id: 14.3
flags: [noStrict]
---*/
var yield = 'propName';
var obj = {
[yield]() {}
};
assert.sameValue(Object.hasOwnProperty.call(obj, 'propName'), true);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Functions declared as methods are defined as enumerable, writable,
configurable properties on the initialized object.
es6id: 14.3.8
includes: [propertyHelper.js]
---*/
var obj = { method() {} };
verifyEnumerable(obj, 'method');
verifyWritable(obj, 'method');
verifyConfigurable(obj, 'method');

View File

@ -0,0 +1,12 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Functions declared as methods do not define a `prototype` property.
es6id: 14.3.9
---*/
var method = { method() {} }.method;
assert.sameValue(Object.hasOwnProperty.call(method, 'prototype'), false);

View File

@ -0,0 +1,11 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
The prototype of functions declared as methods is the Function prototype.
es6id: 14.3.8
---*/
var obj = { method() {} };
assert.sameValue(Object.getPrototypeOf(obj.method), Function.prototype);

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
It is a Syntax Error if HasDirectSuper of MethodDefinition is true.
es6id: 12.2.5.1
negative: SyntaxError
---*/
({
method() {
super;
}
});

View File

@ -0,0 +1,13 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
It is a Syntax Error if HasDirectSuper of MethodDefinition is true.
es6id: 12.2.5.1
negative: SyntaxError
---*/
({
method(param = super) {}
});

View File

@ -0,0 +1,25 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
The HomeObject of Functions declared as methods is the Object prototype.
es6id: 14.3.8
features: [super]
---*/
var value = {};
var obj;
try {
Object.prototype.Test262Attr = value;
obj = {
Test262Attr: null,
method() {
return super.Test262Attr;
}
};
assert.sameValue(obj.method(), value);
} finally {
delete Object.prototype.Test262Attr;
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
The HomeObject of Functions declared as methods is the Object prototype.
es6id: 14.3.8
features: [super]
---*/
var value = {};
var obj;
try {
Object.prototype.Test262Attr = value;
obj = {
Test262Attr: null,
method(x = super.Test262Attr) {
return x;
}
};
assert.sameValue(obj.method(), value);
} finally {
delete Object.prototype.Test262Attr;
}