From 31bdf48bec9833d03d52d92fb5b425d22818b972 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Tue, 19 May 2015 17:51:59 -0400 Subject: [PATCH] Add tests for MethodDefinition forms new to ES6 --- .../generator-invoke-ctor.js | 15 +++++++++ .../generator-invoke-fn-no-strict.js | 23 +++++++++++++ .../generator-invoke-fn-strict.js | 23 +++++++++++++ .../method-definition/generator-length.js | 18 ++++++++++ .../generator-name-prop-string.js | 18 ++++++++++ .../generator-name-prop-symbol.js | 19 +++++++++++ .../generator-param-id-yield.js | 16 +++++++++ .../generator-param-init-yield.js | 28 ++++++++++++++++ .../method-definition/generator-params.js | 28 ++++++++++++++++ .../generator-prop-name-eval-error.js | 15 +++++++++ .../generator-prop-name-yield-expr.js | 33 +++++++++++++++++++ .../generator-prop-name-yield-id.js | 19 +++++++++++ .../generator-property-desc.js | 17 ++++++++++ .../generator-prototype-prop.js | 22 +++++++++++++ .../method-definition/generator-prototype.js | 16 +++++++++ .../method-definition/name-invoke-ctor.js | 13 ++++++++ .../name-invoke-fn-no-strict.js | 22 +++++++++++++ .../name-invoke-fn-strict.js | 22 +++++++++++++ .../object/method-definition/name-length.js | 17 ++++++++++ .../name-name-prop-string.js | 17 ++++++++++ .../name-name-prop-symbol.js | 19 +++++++++++ .../method-definition/name-param-id-yield.js | 19 +++++++++++ .../name-param-init-yield.js | 21 ++++++++++++ .../method-definition/name-param-redecl.js | 17 ++++++++++ .../object/method-definition/name-params.js | 26 +++++++++++++++ .../name-prop-name-eval-error.js | 14 ++++++++ .../name-prop-name-yield-expr.js | 33 +++++++++++++++++++ .../name-prop-name-yield-id.js | 18 ++++++++++ .../method-definition/name-property-desc.js | 16 +++++++++ .../method-definition/name-prototype-prop.js | 12 +++++++ .../method-definition/name-prototype.js | 11 +++++++ .../method-definition/name-super-call-body.js | 15 +++++++++ .../name-super-call-param.js | 13 ++++++++ .../method-definition/name-super-prop-body.js | 25 ++++++++++++++ .../name-super-prop-param.js | 26 +++++++++++++++ 35 files changed, 686 insertions(+) create mode 100644 test/language/expressions/object/method-definition/generator-invoke-ctor.js create mode 100644 test/language/expressions/object/method-definition/generator-invoke-fn-no-strict.js create mode 100644 test/language/expressions/object/method-definition/generator-invoke-fn-strict.js create mode 100644 test/language/expressions/object/method-definition/generator-length.js create mode 100644 test/language/expressions/object/method-definition/generator-name-prop-string.js create mode 100644 test/language/expressions/object/method-definition/generator-name-prop-symbol.js create mode 100644 test/language/expressions/object/method-definition/generator-param-id-yield.js create mode 100644 test/language/expressions/object/method-definition/generator-param-init-yield.js create mode 100644 test/language/expressions/object/method-definition/generator-params.js create mode 100644 test/language/expressions/object/method-definition/generator-prop-name-eval-error.js create mode 100644 test/language/expressions/object/method-definition/generator-prop-name-yield-expr.js create mode 100644 test/language/expressions/object/method-definition/generator-prop-name-yield-id.js create mode 100644 test/language/expressions/object/method-definition/generator-property-desc.js create mode 100644 test/language/expressions/object/method-definition/generator-prototype-prop.js create mode 100644 test/language/expressions/object/method-definition/generator-prototype.js create mode 100644 test/language/expressions/object/method-definition/name-invoke-ctor.js create mode 100644 test/language/expressions/object/method-definition/name-invoke-fn-no-strict.js create mode 100644 test/language/expressions/object/method-definition/name-invoke-fn-strict.js create mode 100644 test/language/expressions/object/method-definition/name-length.js create mode 100644 test/language/expressions/object/method-definition/name-name-prop-string.js create mode 100644 test/language/expressions/object/method-definition/name-name-prop-symbol.js create mode 100644 test/language/expressions/object/method-definition/name-param-id-yield.js create mode 100644 test/language/expressions/object/method-definition/name-param-init-yield.js create mode 100644 test/language/expressions/object/method-definition/name-param-redecl.js create mode 100644 test/language/expressions/object/method-definition/name-params.js create mode 100644 test/language/expressions/object/method-definition/name-prop-name-eval-error.js create mode 100644 test/language/expressions/object/method-definition/name-prop-name-yield-expr.js create mode 100644 test/language/expressions/object/method-definition/name-prop-name-yield-id.js create mode 100644 test/language/expressions/object/method-definition/name-property-desc.js create mode 100644 test/language/expressions/object/method-definition/name-prototype-prop.js create mode 100644 test/language/expressions/object/method-definition/name-prototype.js create mode 100644 test/language/expressions/object/method-definition/name-super-call-body.js create mode 100644 test/language/expressions/object/method-definition/name-super-call-param.js create mode 100644 test/language/expressions/object/method-definition/name-super-prop-body.js create mode 100644 test/language/expressions/object/method-definition/name-super-prop-param.js diff --git a/test/language/expressions/object/method-definition/generator-invoke-ctor.js b/test/language/expressions/object/method-definition/generator-invoke-ctor.js new file mode 100644 index 0000000000..6bbe5d855b --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-invoke-ctor.js @@ -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); diff --git a/test/language/expressions/object/method-definition/generator-invoke-fn-no-strict.js b/test/language/expressions/object/method-definition/generator-invoke-fn-no-strict.js new file mode 100644 index 0000000000..cfe10af7d2 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-invoke-fn-no-strict.js @@ -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); diff --git a/test/language/expressions/object/method-definition/generator-invoke-fn-strict.js b/test/language/expressions/object/method-definition/generator-invoke-fn-strict.js new file mode 100644 index 0000000000..2eb1841490 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-invoke-fn-strict.js @@ -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); diff --git a/test/language/expressions/object/method-definition/generator-length.js b/test/language/expressions/object/method-definition/generator-length.js new file mode 100644 index 0000000000..1ca0321b43 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-length.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/generator-name-prop-string.js b/test/language/expressions/object/method-definition/generator-name-prop-string.js new file mode 100644 index 0000000000..37d7c25c72 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-name-prop-string.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/generator-name-prop-symbol.js b/test/language/expressions/object/method-definition/generator-name-prop-symbol.js new file mode 100644 index 0000000000..df23c9c80c --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-name-prop-symbol.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/generator-param-id-yield.js b/test/language/expressions/object/method-definition/generator-param-id-yield.js new file mode 100644 index 0000000000..ac5e678698 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-param-id-yield.js @@ -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) {} +}); diff --git a/test/language/expressions/object/method-definition/generator-param-init-yield.js b/test/language/expressions/object/method-definition/generator-param-init-yield.js new file mode 100644 index 0000000000..2576f6d258 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-param-init-yield.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/generator-params.js b/test/language/expressions/object/method-definition/generator-params.js new file mode 100644 index 0000000000..ca6f694691 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-params.js @@ -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); diff --git a/test/language/expressions/object/method-definition/generator-prop-name-eval-error.js b/test/language/expressions/object/method-definition/generator-prop-name-eval-error.js new file mode 100644 index 0000000000..87c1397391 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-prop-name-eval-error.js @@ -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(); }())]() {} + }); +}); diff --git a/test/language/expressions/object/method-definition/generator-prop-name-yield-expr.js b/test/language/expressions/object/method-definition/generator-prop-name-yield-expr.js new file mode 100644 index 0000000000..2ccf6b43f1 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-prop-name-yield-expr.js @@ -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 +); diff --git a/test/language/expressions/object/method-definition/generator-prop-name-yield-id.js b/test/language/expressions/object/method-definition/generator-prop-name-yield-id.js new file mode 100644 index 0000000000..a844383dae --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-prop-name-yield-id.js @@ -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); diff --git a/test/language/expressions/object/method-definition/generator-property-desc.js b/test/language/expressions/object/method-definition/generator-property-desc.js new file mode 100644 index 0000000000..ae4b4310f9 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-property-desc.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/generator-prototype-prop.js b/test/language/expressions/object/method-definition/generator-prototype-prop.js new file mode 100644 index 0000000000..4eb0c0e437 --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-prototype-prop.js @@ -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 +); diff --git a/test/language/expressions/object/method-definition/generator-prototype.js b/test/language/expressions/object/method-definition/generator-prototype.js new file mode 100644 index 0000000000..245a0a199b --- /dev/null +++ b/test/language/expressions/object/method-definition/generator-prototype.js @@ -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*() {}) +); diff --git a/test/language/expressions/object/method-definition/name-invoke-ctor.js b/test/language/expressions/object/method-definition/name-invoke-ctor.js new file mode 100644 index 0000000000..b4b29b086d --- /dev/null +++ b/test/language/expressions/object/method-definition/name-invoke-ctor.js @@ -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(); +}); diff --git a/test/language/expressions/object/method-definition/name-invoke-fn-no-strict.js b/test/language/expressions/object/method-definition/name-invoke-fn-no-strict.js new file mode 100644 index 0000000000..a393b0d051 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-invoke-fn-no-strict.js @@ -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); diff --git a/test/language/expressions/object/method-definition/name-invoke-fn-strict.js b/test/language/expressions/object/method-definition/name-invoke-fn-strict.js new file mode 100644 index 0000000000..94c59b5a95 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-invoke-fn-strict.js @@ -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); diff --git a/test/language/expressions/object/method-definition/name-length.js b/test/language/expressions/object/method-definition/name-length.js new file mode 100644 index 0000000000..dc0178eb6f --- /dev/null +++ b/test/language/expressions/object/method-definition/name-length.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/name-name-prop-string.js b/test/language/expressions/object/method-definition/name-name-prop-string.js new file mode 100644 index 0000000000..6a56c27d8c --- /dev/null +++ b/test/language/expressions/object/method-definition/name-name-prop-string.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/name-name-prop-symbol.js b/test/language/expressions/object/method-definition/name-name-prop-symbol.js new file mode 100644 index 0000000000..338bfb2190 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-name-prop-symbol.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/name-param-id-yield.js b/test/language/expressions/object/method-definition/name-param-id-yield.js new file mode 100644 index 0000000000..a2ed2c273b --- /dev/null +++ b/test/language/expressions/object/method-definition/name-param-id-yield.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/name-param-init-yield.js b/test/language/expressions/object/method-definition/name-param-init-yield.js new file mode 100644 index 0000000000..9763575baf --- /dev/null +++ b/test/language/expressions/object/method-definition/name-param-init-yield.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/name-param-redecl.js b/test/language/expressions/object/method-definition/name-param-redecl.js new file mode 100644 index 0000000000..d435a450b5 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-param-redecl.js @@ -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; + } +}; diff --git a/test/language/expressions/object/method-definition/name-params.js b/test/language/expressions/object/method-definition/name-params.js new file mode 100644 index 0000000000..5e6b2a4c13 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-params.js @@ -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); diff --git a/test/language/expressions/object/method-definition/name-prop-name-eval-error.js b/test/language/expressions/object/method-definition/name-prop-name-eval-error.js new file mode 100644 index 0000000000..895e00ddf9 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-prop-name-eval-error.js @@ -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(); }())]() {} + }); +}); diff --git a/test/language/expressions/object/method-definition/name-prop-name-yield-expr.js b/test/language/expressions/object/method-definition/name-prop-name-yield-expr.js new file mode 100644 index 0000000000..85591f3cdc --- /dev/null +++ b/test/language/expressions/object/method-definition/name-prop-name-yield-expr.js @@ -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 +); diff --git a/test/language/expressions/object/method-definition/name-prop-name-yield-id.js b/test/language/expressions/object/method-definition/name-prop-name-yield-id.js new file mode 100644 index 0000000000..d511c3b092 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-prop-name-yield-id.js @@ -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); diff --git a/test/language/expressions/object/method-definition/name-property-desc.js b/test/language/expressions/object/method-definition/name-property-desc.js new file mode 100644 index 0000000000..d69301b4e2 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-property-desc.js @@ -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'); diff --git a/test/language/expressions/object/method-definition/name-prototype-prop.js b/test/language/expressions/object/method-definition/name-prototype-prop.js new file mode 100644 index 0000000000..fbb862b6b7 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-prototype-prop.js @@ -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); diff --git a/test/language/expressions/object/method-definition/name-prototype.js b/test/language/expressions/object/method-definition/name-prototype.js new file mode 100644 index 0000000000..8c55bb146b --- /dev/null +++ b/test/language/expressions/object/method-definition/name-prototype.js @@ -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); diff --git a/test/language/expressions/object/method-definition/name-super-call-body.js b/test/language/expressions/object/method-definition/name-super-call-body.js new file mode 100644 index 0000000000..5334201b91 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-super-call-body.js @@ -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; + } +}); diff --git a/test/language/expressions/object/method-definition/name-super-call-param.js b/test/language/expressions/object/method-definition/name-super-call-param.js new file mode 100644 index 0000000000..cf96e2f4b0 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-super-call-param.js @@ -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) {} +}); diff --git a/test/language/expressions/object/method-definition/name-super-prop-body.js b/test/language/expressions/object/method-definition/name-super-prop-body.js new file mode 100644 index 0000000000..0fbfbb5d01 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-super-prop-body.js @@ -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; +} diff --git a/test/language/expressions/object/method-definition/name-super-prop-param.js b/test/language/expressions/object/method-definition/name-super-prop-param.js new file mode 100644 index 0000000000..28f35f3e77 --- /dev/null +++ b/test/language/expressions/object/method-definition/name-super-prop-param.js @@ -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; +}