Skip to content
Snippets Groups Projects
Commit 31bdf48b authored by Mike Pennisi's avatar Mike Pennisi
Browse files

Add tests for MethodDefinition forms new to ES6

parent cde990b7
Branches
No related tags found
No related merge requests found
Showing
with 401 additions and 0 deletions
// 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);
// 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);
// 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);
// 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');
// 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');
// 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');
// 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) {}
});
// 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');
// 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);
// 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(); }())]() {}
});
});
// 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
);
// 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);
// 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');
// 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
);
// 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*() {})
);
// 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();
});
// 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);
// 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);
// 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');
// 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');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment