From 2fe074134a31fa0762faccbc4b90668d2197dfaf Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Wed, 8 Jul 2015 16:09:57 -0400 Subject: [PATCH] Add tests for function `name` attribute This change set includes tests for most invocations of the SetFunctionName abstract operation in the ES2015 specification. Practical testing considerations preclude the introduction of tests for certain invocations: - The project is still vetting methods to sustainably test the semantics of the Destructuring Binding pattern across all valid productions. - 13.3.3.6 Runtime Semantics: IteratorBindingInitialization - 13.3.3.7 Runtime Semantics: KeyedBindingInitialization - Without a loader, there is no way to access a function object declared in an ExportDeclaration, so `name` assignment cannot be tested in these cases - 14.1.19 Runtime Semantics: InstantiateFunctionObject - 14.4.12 Runtime Semantics: InstantiateFunctionObject - 14.5.15 Runtime Semantics: BindingClassDeclarationEvaluation - 15.2.3.11 Runtime Semantics: Evaluation --- test/annexB/__proto__/fn-name.js | 27 ++++++++ test/built-ins/Function/instance-name.js | 22 +++++++ .../prototype/bind/instance-name-chained.js | 21 ++++++ .../prototype/bind/instance-name-error.js | 20 ++++++ .../bind/instance-name-non-string.js | 58 +++++++++++++++++ .../Function/prototype/bind/instance-name.js | 20 ++++++ test/built-ins/Function/prototype/name.js | 22 +++++++ .../GeneratorFunction/instance-name.js | 24 +++++++ .../array-elem-init-fn-name-arrow.js | 28 ++++++++ .../array-elem-init-fn-name-class.js | 32 ++++++++++ .../array-elem-init-fn-name-cover.js | 32 ++++++++++ .../array-elem-init-fn-name-fn.js | 32 ++++++++++ .../array-elem-init-fn-name-gen.js | 32 ++++++++++ .../obj-id-init-fn-name-arrow.js | 27 ++++++++ .../obj-id-init-fn-name-class.js | 31 +++++++++ .../obj-id-init-fn-name-cover.js | 31 +++++++++ .../destructuring/obj-id-init-fn-name-fn.js | 30 +++++++++ .../destructuring/obj-id-init-fn-name-gen.js | 31 +++++++++ .../obj-prop-elem-init-fn-name-arrow.js | 28 ++++++++ .../obj-prop-elem-init-fn-name-class.js | 32 ++++++++++ .../obj-prop-elem-init-fn-name-cover.js | 32 ++++++++++ .../obj-prop-elem-init-fn-name-fn.js | 31 +++++++++ .../obj-prop-elem-init-fn-name-gen.js | 32 ++++++++++ .../expressions/assignment/fn-name-arrow.js | 31 +++++++++ .../expressions/assignment/fn-name-class.js | 35 ++++++++++ .../expressions/assignment/fn-name-cover.js | 35 ++++++++++ .../expressions/assignment/fn-name-fn.js | 34 ++++++++++ .../expressions/assignment/fn-name-gen.js | 35 ++++++++++ .../assignment/fn-name-lhs-cover.js | 27 ++++++++ .../assignment/fn-name-lhs-member.js | 27 ++++++++ test/language/expressions/class/name.js | 32 ++++++++++ test/language/expressions/function/name.js | 33 ++++++++++ test/language/expressions/generators/name.js | 38 +++++++---- .../object/fn-name-accessor-get.js | 42 ++++++++++++ .../object/fn-name-accessor-set.js | 43 +++++++++++++ .../expressions/object/fn-name-arrow.js | 40 ++++++++++++ .../expressions/object/fn-name-class.js | 43 +++++++++++++ .../expressions/object/fn-name-cover.js | 44 +++++++++++++ .../language/expressions/object/fn-name-fn.js | 43 +++++++++++++ .../expressions/object/fn-name-gen.js | 44 +++++++++++++ .../object/method-definition/fn-name-fn.js | 40 ++++++++++++ .../object/method-definition/fn-name-gen.js | 41 ++++++++++++ .../class/definition/fn-name-accessor-get.js | 63 ++++++++++++++++++ .../class/definition/fn-name-accessor-set.js | 64 +++++++++++++++++++ .../class/definition/fn-name-gen-method.js | 58 +++++++++++++++++ .../class/definition/fn-name-method.js | 57 +++++++++++++++++ .../definition/fn-name-static-precedence.js | 63 ++++++++++++++++++ test/language/statements/class/name.js | 21 ++++++ .../statements/const/fn-name-arrow.js | 24 +++++++ .../statements/const/fn-name-class.js | 28 ++++++++ .../statements/const/fn-name-cover.js | 28 ++++++++ test/language/statements/const/fn-name-fn.js | 27 ++++++++ test/language/statements/const/fn-name-gen.js | 28 ++++++++ test/language/statements/function/name.js | 24 +++++++ .../generators/name-property-descriptor.js | 16 ----- .../generators/name.js} | 13 ++-- test/language/statements/let/fn-name-arrow.js | 24 +++++++ test/language/statements/let/fn-name-class.js | 28 ++++++++ test/language/statements/let/fn-name-cover.js | 28 ++++++++ test/language/statements/let/fn-name-fn.js | 27 ++++++++ test/language/statements/let/fn-name-gen.js | 28 ++++++++ .../statements/variable/fn-name-arrow.js | 24 +++++++ .../statements/variable/fn-name-class.js | 28 ++++++++ .../statements/variable/fn-name-cover.js | 28 ++++++++ .../statements/variable/fn-name-fn.js | 27 ++++++++ .../statements/variable/fn-name-gen.js | 28 ++++++++ 66 files changed, 2133 insertions(+), 33 deletions(-) create mode 100644 test/annexB/__proto__/fn-name.js create mode 100644 test/built-ins/Function/instance-name.js create mode 100644 test/built-ins/Function/prototype/bind/instance-name-chained.js create mode 100644 test/built-ins/Function/prototype/bind/instance-name-error.js create mode 100644 test/built-ins/Function/prototype/bind/instance-name-non-string.js create mode 100644 test/built-ins/Function/prototype/bind/instance-name.js create mode 100644 test/built-ins/Function/prototype/name.js create mode 100644 test/built-ins/GeneratorFunction/instance-name.js create mode 100644 test/language/expressions/assignment/destructuring/array-elem-init-fn-name-arrow.js create mode 100644 test/language/expressions/assignment/destructuring/array-elem-init-fn-name-class.js create mode 100644 test/language/expressions/assignment/destructuring/array-elem-init-fn-name-cover.js create mode 100644 test/language/expressions/assignment/destructuring/array-elem-init-fn-name-fn.js create mode 100644 test/language/expressions/assignment/destructuring/array-elem-init-fn-name-gen.js create mode 100644 test/language/expressions/assignment/destructuring/obj-id-init-fn-name-arrow.js create mode 100644 test/language/expressions/assignment/destructuring/obj-id-init-fn-name-class.js create mode 100644 test/language/expressions/assignment/destructuring/obj-id-init-fn-name-cover.js create mode 100644 test/language/expressions/assignment/destructuring/obj-id-init-fn-name-fn.js create mode 100644 test/language/expressions/assignment/destructuring/obj-id-init-fn-name-gen.js create mode 100644 test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-arrow.js create mode 100644 test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-class.js create mode 100644 test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-cover.js create mode 100644 test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-fn.js create mode 100644 test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-gen.js create mode 100644 test/language/expressions/assignment/fn-name-arrow.js create mode 100644 test/language/expressions/assignment/fn-name-class.js create mode 100644 test/language/expressions/assignment/fn-name-cover.js create mode 100644 test/language/expressions/assignment/fn-name-fn.js create mode 100644 test/language/expressions/assignment/fn-name-gen.js create mode 100644 test/language/expressions/assignment/fn-name-lhs-cover.js create mode 100644 test/language/expressions/assignment/fn-name-lhs-member.js create mode 100644 test/language/expressions/class/name.js create mode 100644 test/language/expressions/function/name.js create mode 100644 test/language/expressions/object/fn-name-accessor-get.js create mode 100644 test/language/expressions/object/fn-name-accessor-set.js create mode 100644 test/language/expressions/object/fn-name-arrow.js create mode 100644 test/language/expressions/object/fn-name-class.js create mode 100644 test/language/expressions/object/fn-name-cover.js create mode 100644 test/language/expressions/object/fn-name-fn.js create mode 100644 test/language/expressions/object/fn-name-gen.js create mode 100644 test/language/expressions/object/method-definition/fn-name-fn.js create mode 100644 test/language/expressions/object/method-definition/fn-name-gen.js create mode 100644 test/language/statements/class/definition/fn-name-accessor-get.js create mode 100644 test/language/statements/class/definition/fn-name-accessor-set.js create mode 100644 test/language/statements/class/definition/fn-name-gen-method.js create mode 100644 test/language/statements/class/definition/fn-name-method.js create mode 100644 test/language/statements/class/definition/fn-name-static-precedence.js create mode 100644 test/language/statements/class/name.js create mode 100644 test/language/statements/const/fn-name-arrow.js create mode 100644 test/language/statements/const/fn-name-class.js create mode 100644 test/language/statements/const/fn-name-cover.js create mode 100644 test/language/statements/const/fn-name-fn.js create mode 100644 test/language/statements/const/fn-name-gen.js create mode 100644 test/language/statements/function/name.js delete mode 100644 test/language/statements/generators/name-property-descriptor.js rename test/language/{expressions/generators/name-property-descriptor.js => statements/generators/name.js} (55%) create mode 100644 test/language/statements/let/fn-name-arrow.js create mode 100644 test/language/statements/let/fn-name-class.js create mode 100644 test/language/statements/let/fn-name-cover.js create mode 100644 test/language/statements/let/fn-name-fn.js create mode 100644 test/language/statements/let/fn-name-gen.js create mode 100644 test/language/statements/variable/fn-name-arrow.js create mode 100644 test/language/statements/variable/fn-name-class.js create mode 100644 test/language/statements/variable/fn-name-cover.js create mode 100644 test/language/statements/variable/fn-name-fn.js create mode 100644 test/language/statements/variable/fn-name-gen.js diff --git a/test/annexB/__proto__/fn-name.js b/test/annexB/__proto__/fn-name.js new file mode 100644 index 0000000000..41e0816fb6 --- /dev/null +++ b/test/annexB/__proto__/fn-name.js @@ -0,0 +1,27 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: B.3.1 +description: Function name is not assigned based on the property name +info: > + [...] + 6. If propKey is the String value "__proto__" and if + IsComputedPropertyKey(propKey) is false, then + a. If Type(propValue) is either Object or Null, then + i. Return object.[[SetPrototypeOf]](propValue). + b. Return NormalCompletion(empty). + 7. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then + a. Let hasNameProperty be HasOwnProperty(propValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(propValue, propKey). +includes: [propertyHelper.js] +---*/ + +var o; + +o = { + __proto__: function() {} +}; + +assert(o.__proto__.name !== '__proto__'); diff --git a/test/built-ins/Function/instance-name.js b/test/built-ins/Function/instance-name.js new file mode 100644 index 0000000000..1748b3bc6b --- /dev/null +++ b/test/built-ins/Function/instance-name.js @@ -0,0 +1,22 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.2.1.1 +description: Assignment of function `name` attribute +info: > + [...] + 3. Return CreateDynamicFunction(C, NewTarget, "normal", args). + + ES6 19.2.1.1.1 + RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args) + + [...] + 29. Perform SetFunctionName(F, "anonymous"). +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Function().name, 'anonymous'); +verifyNotEnumerable(Function(), 'name'); +verifyNotWritable(Function(), 'name'); +verifyConfigurable(Function(), 'name'); diff --git a/test/built-ins/Function/prototype/bind/instance-name-chained.js b/test/built-ins/Function/prototype/bind/instance-name-chained.js new file mode 100644 index 0000000000..6014848231 --- /dev/null +++ b/test/built-ins/Function/prototype/bind/instance-name-chained.js @@ -0,0 +1,21 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.2.3.2 +description: > + Assignment of function `name` attribute (previously-bound function) +info: > + 12. Let targetName be Get(Target, "name"). + 13. ReturnIfAbrupt(targetName). + 14. If Type(targetName) is not String, let targetName be the empty string. + 15. Perform SetFunctionName(F, targetName, "bound"). +includes: [propertyHelper.js] +---*/ + +var target = Object.defineProperty(function() {}, 'name', { value: 'target' }); + +assert.sameValue(target.bind().bind().name, 'bound bound target'); +verifyNotEnumerable(target.bind().bind(), 'name'); +verifyNotWritable(target.bind().bind(), 'name'); +verifyConfigurable(target.bind().bind(), 'name'); diff --git a/test/built-ins/Function/prototype/bind/instance-name-error.js b/test/built-ins/Function/prototype/bind/instance-name-error.js new file mode 100644 index 0000000000..29135ab061 --- /dev/null +++ b/test/built-ins/Function/prototype/bind/instance-name-error.js @@ -0,0 +1,20 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.2.3.2 +description: Error thrown when accessing target's `name` property +info: > + 12. Let targetName be Get(Target, "name"). + 13. ReturnIfAbrupt(targetName). +---*/ + +var target = Object.defineProperty(function() {}, 'name', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + target.bind(); +}); diff --git a/test/built-ins/Function/prototype/bind/instance-name-non-string.js b/test/built-ins/Function/prototype/bind/instance-name-non-string.js new file mode 100644 index 0000000000..e6686134cb --- /dev/null +++ b/test/built-ins/Function/prototype/bind/instance-name-non-string.js @@ -0,0 +1,58 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.2.3.2 +description: > + Assignment of function `name` attribute (target has non-string name) +info: > + 12. Let targetName be Get(Target, "name"). + 13. ReturnIfAbrupt(targetName). + 14. If Type(targetName) is not String, let targetName be the empty string. + 15. Perform SetFunctionName(F, targetName, "bound"). +includes: [propertyHelper.js] +---*/ + +var target; + +target = Object.defineProperty(function() {}, 'name', { value: undefined }); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { value: null }); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { value: true }); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { value: Symbol('s') }); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { value: 23 }); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); + +target = Object.defineProperty(function() {}, 'name', { value: {} }); + +assert.sameValue(target.bind().name, 'bound '); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); diff --git a/test/built-ins/Function/prototype/bind/instance-name.js b/test/built-ins/Function/prototype/bind/instance-name.js new file mode 100644 index 0000000000..57b20ef203 --- /dev/null +++ b/test/built-ins/Function/prototype/bind/instance-name.js @@ -0,0 +1,20 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.2.3.2 +description: Assignment of function `name` attribute +info: > + 12. Let targetName be Get(Target, "name"). + 13. ReturnIfAbrupt(targetName). + 14. If Type(targetName) is not String, let targetName be the empty string. + 15. Perform SetFunctionName(F, targetName, "bound"). +includes: [propertyHelper.js] +---*/ + +var target = Object.defineProperty(function() {}, 'name', { value: 'target' }); + +assert.sameValue(target.bind().name, 'bound target'); +verifyNotEnumerable(target.bind(), 'name'); +verifyNotWritable(target.bind(), 'name'); +verifyConfigurable(target.bind(), 'name'); diff --git a/test/built-ins/Function/prototype/name.js b/test/built-ins/Function/prototype/name.js new file mode 100644 index 0000000000..2ceb0feb75 --- /dev/null +++ b/test/built-ins/Function/prototype/name.js @@ -0,0 +1,22 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 19.2.3 +description: FunctionPrototype `name` property +info: > + The value of the name property of the Function prototype object is the + empty String. + + ES6 Section 17: + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Function.prototype.name, ''); +verifyNotEnumerable(Function.prototype, 'name'); +verifyNotWritable(Function.prototype, 'name'); +verifyConfigurable(Function.prototype, 'name'); diff --git a/test/built-ins/GeneratorFunction/instance-name.js b/test/built-ins/GeneratorFunction/instance-name.js new file mode 100644 index 0000000000..5400645ccd --- /dev/null +++ b/test/built-ins/GeneratorFunction/instance-name.js @@ -0,0 +1,24 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 25.2.1.1 +description: Assignment of function `name` attribute +info: > + [...] + 3. Return CreateDynamicFunction(C, NewTarget, "generator", args). + + ES6 19.2.1.1.1 + RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args) + + [...] + 29. Perform SetFunctionName(F, "anonymous"). +includes: [propertyHelper.js] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; + +assert.sameValue(GeneratorFunction().name, 'anonymous'); +verifyNotEnumerable(GeneratorFunction(), 'name'); +verifyNotWritable(GeneratorFunction(), 'name'); +verifyConfigurable(GeneratorFunction(), 'name'); diff --git a/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-arrow.js b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-arrow.js new file mode 100644 index 0000000000..d729c2a895 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-arrow.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: Assignment of function `name` attribute (ArrowFunction) +es6id: 12.14.5.3 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +var arrow; + +[ arrow = () => {} ] = []; + +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); diff --git a/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-class.js b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-class.js new file mode 100644 index 0000000000..d781dd593c --- /dev/null +++ b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-class.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (ClassExpression) +es6id: 12.14.5.3 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [class] +---*/ + +var xCls, cls; + +[ xCls = class x {} ] = [];; +[ cls = class {} ] = []; + +assert(xCls.name !== 'xCls'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); diff --git a/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-cover.js b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-cover.js new file mode 100644 index 0000000000..4e4b393516 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-cover.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +es6id: 12.14.5.3 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +var xCover, cover; + +[ xCover = (0, function() {}) ] = []; +[ cover = (function() {}) ] = []; + +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); diff --git a/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-fn.js b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-fn.js new file mode 100644 index 0000000000..70e29b56ab --- /dev/null +++ b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-fn.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (FunctionExpression) +es6id: 12.14.5.3 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [class] +---*/ + +var xFn, fn; + +[ xFn = function x() {} ] = [];; +[ fn = function() {} ] = []; + +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); diff --git a/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-gen.js b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-gen.js new file mode 100644 index 0000000000..0d17fc6490 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/array-elem-init-fn-name-gen.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (GeneratorExpression) +es6id: 12.14.5.3 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and value is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(v, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(v, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [generators] +---*/ + +var xGen, gen; + +[ xGen = function* x() {} ] = []; +[ gen = function*() {} ] = [];; + +assert(xGen.name !== 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-arrow.js b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-arrow.js new file mode 100644 index 0000000000..53075d76e6 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-arrow.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (ArrowFunction) +es6id: 12.14.5.2 +info: > + AssignmentProperty : IdentifierReference Initializeropt + + [...] + 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). +includes: [propertyHelper.js] +---*/ + +var arrow; + +({ arrow = () => {} } = {}); + +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-class.js b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-class.js new file mode 100644 index 0000000000..3c20598cb5 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-class.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (ClassExpression) +es6id: 12.14.5.2 +info: > + AssignmentProperty : IdentifierReference Initializeropt + + [...] + 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). +includes: [propertyHelper.js] +features: [class] +---*/ + +var xCls, cls; + +({ xCls = class x {} } = {}); +({ cls = class {} } = {}); + +assert(xCls.name !== 'xCls'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-cover.js b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-cover.js new file mode 100644 index 0000000000..c220f37408 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-cover.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +es6id: 12.14.5.2 +info: > + AssignmentProperty : IdentifierReference Initializeropt + + [...] + 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). +includes: [propertyHelper.js] +---*/ + +var xCover, cover; + +({ xCover = (0, function() {}) } = {}); +({ cover = (function() {}) } = {}); + +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-fn.js b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-fn.js new file mode 100644 index 0000000000..269960e3bb --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-fn.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (FunctionExpression) +es6id: 12.14.5.2 +info: > + AssignmentProperty : IdentifierReference Initializeropt + + [...] + 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). +includes: [propertyHelper.js] +---*/ + +var xFn, fn; + +({ xFn = function x() {} } = {}); +({ fn = function() {} } = {}); + +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-gen.js b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-gen.js new file mode 100644 index 0000000000..9ae0f31a76 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-id-init-fn-name-gen.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (GeneratorExpression) +es6id: 12.14.5.2 +info: > + AssignmentProperty : IdentifierReference Initializeropt + + [...] + 6. If Initializeropt is present and v is undefined, then + [...] + d. If IsAnonymousFunctionDefinition(Initializer) is true, then + i. Let hasNameProperty be HasOwnProperty(v, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(v, P). +includes: [propertyHelper.js] +features: [generators] +---*/ + +var xGen, gen; + +({ xGen = function* x() {} } = {}); +({ gen = function*() {} } = {}); + +assert(xGen.name !== 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-arrow.js b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-arrow.js new file mode 100644 index 0000000000..a089de2b73 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-arrow.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: Assignment of function `name` attribute (ArrowFunction) +es6id: 12.14.5.4 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +var arrow; + +({ x: arrow = () => {} } = {}); + +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-class.js b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-class.js new file mode 100644 index 0000000000..43b0ddafb7 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-class.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (ClassExpression) +es6id: 12.14.5.4 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [class] +---*/ + +var xCls, cls; + +({ x: xCls = class x {} } = {}); +({ x: cls = class {} } = {}); + +assert(xCls.name !== 'xCls'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-cover.js b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-cover.js new file mode 100644 index 0000000000..5e4f473426 --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-cover.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +es6id: 12.14.5.4 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +var xCover, cover; + +({ x: xCover = (0, function() {}) } = {}); +({ x: cover = (function() {}) } = {}); + +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-fn.js b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-fn.js new file mode 100644 index 0000000000..79111de8ca --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-fn.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (FunctionExpression) +es6id: 12.14.5.4 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +var xFn, fn; + +({ x: xFn = function x() {} } = {}); +({ x: fn = function() {} } = {}); + +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); diff --git a/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-gen.js b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-gen.js new file mode 100644 index 0000000000..c65a81683c --- /dev/null +++ b/test/language/expressions/assignment/destructuring/obj-prop-elem-init-fn-name-gen.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Assignment of function `name` attribute (GeneratorExpression) +es6id: 12.14.5.4 +info: > + AssignmentElement[Yield] : DestructuringAssignmentTarget Initializeropt + + [...] + 7. If Initializer is present and v is undefined and + IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of + DestructuringAssignmentTarget are both true, then + a. Let hasNameProperty be HasOwnProperty(rhsValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(rhsValue, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [generators] +---*/ + +var xGen, gen; + +({ x: xGen = function* x() {} } = {}); +({ x: gen = function*() {} } = {}); + +assert(xGen.name !== 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name'); diff --git a/test/language/expressions/assignment/fn-name-arrow.js b/test/language/expressions/assignment/fn-name-arrow.js new file mode 100644 index 0000000000..31e3f9fc73 --- /dev/null +++ b/test/language/expressions/assignment/fn-name-arrow.js @@ -0,0 +1,31 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.14.4 +description: Assignment of function `name` attribute (ArrowFunction) +info: > + AssignmentExpression[In, Yield] : + LeftHandSideExpression[?Yield] = AssignmentExpression[?In, ?Yield] + + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an + ArrayLiteral, then + [...] + e. If IsAnonymousFunctionDefinition(AssignmentExpression) and + IsIdentifierRef of LeftHandSideExpression are both true, then + + i. Let hasNameProperty be HasOwnProperty(rval, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(rval, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +var arrow; + +arrow = () => {}; + +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); diff --git a/test/language/expressions/assignment/fn-name-class.js b/test/language/expressions/assignment/fn-name-class.js new file mode 100644 index 0000000000..5295daf260 --- /dev/null +++ b/test/language/expressions/assignment/fn-name-class.js @@ -0,0 +1,35 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.14.4 +description: Assignment of function `name` attribute (ClassExpression) +info: > + AssignmentExpression[In, Yield] : + LeftHandSideExpression[?Yield] = AssignmentExpression[?In, ?Yield] + + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an + ArrayLiteral, then + [...] + e. If IsAnonymousFunctionDefinition(AssignmentExpression) and + IsIdentifierRef of LeftHandSideExpression are both true, then + + i. Let hasNameProperty be HasOwnProperty(rval, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(rval, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [class] +---*/ + +var xCls, cls; + +xCls = class x {}; +cls = class {}; + +assert(xCls.name !== 'xCls'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); diff --git a/test/language/expressions/assignment/fn-name-cover.js b/test/language/expressions/assignment/fn-name-cover.js new file mode 100644 index 0000000000..6c71bbe2e7 --- /dev/null +++ b/test/language/expressions/assignment/fn-name-cover.js @@ -0,0 +1,35 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.14.4 +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +info: > + AssignmentExpression[In, Yield] : + LeftHandSideExpression[?Yield] = AssignmentExpression[?In, ?Yield] + + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an + ArrayLiteral, then + [...] + e. If IsAnonymousFunctionDefinition(AssignmentExpression) and + IsIdentifierRef of LeftHandSideExpression are both true, then + + i. Let hasNameProperty be HasOwnProperty(rval, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(rval, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +var xCover, cover; + +xCover = (0, function() {}); +cover = (function() {}); + +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); diff --git a/test/language/expressions/assignment/fn-name-fn.js b/test/language/expressions/assignment/fn-name-fn.js new file mode 100644 index 0000000000..10b81cda4f --- /dev/null +++ b/test/language/expressions/assignment/fn-name-fn.js @@ -0,0 +1,34 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.14.4 +description: Assignment of function `name` attribute (FunctionExpression) +info: > + AssignmentExpression[In, Yield] : + LeftHandSideExpression[?Yield] = AssignmentExpression[?In, ?Yield] + + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an + ArrayLiteral, then + [...] + e. If IsAnonymousFunctionDefinition(AssignmentExpression) and + IsIdentifierRef of LeftHandSideExpression are both true, then + + i. Let hasNameProperty be HasOwnProperty(rval, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(rval, + GetReferencedName(lref)). +includes: [propertyHelper.js] +---*/ + +var xFn, fn; + +xFn = function x() {}; +fn = function() {}; + +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); diff --git a/test/language/expressions/assignment/fn-name-gen.js b/test/language/expressions/assignment/fn-name-gen.js new file mode 100644 index 0000000000..e549f07e71 --- /dev/null +++ b/test/language/expressions/assignment/fn-name-gen.js @@ -0,0 +1,35 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.14.4 +description: Assignment of function `name` attribute (GeneratorExpression) +info: > + AssignmentExpression[In, Yield] : + LeftHandSideExpression[?Yield] = AssignmentExpression[?In, ?Yield] + + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an + ArrayLiteral, then + [...] + e. If IsAnonymousFunctionDefinition(AssignmentExpression) and + IsIdentifierRef of LeftHandSideExpression are both true, then + + i. Let hasNameProperty be HasOwnProperty(rval, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(rval, + GetReferencedName(lref)). +includes: [propertyHelper.js] +features: [generators] +---*/ + +var xGen, gen; + +xGen = function* x() {}; +gen = function*() {}; + +assert(xGen.name !== 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name'); diff --git a/test/language/expressions/assignment/fn-name-lhs-cover.js b/test/language/expressions/assignment/fn-name-lhs-cover.js new file mode 100644 index 0000000000..08db5d3684 --- /dev/null +++ b/test/language/expressions/assignment/fn-name-lhs-cover.js @@ -0,0 +1,27 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.14.4 +description: Left-hand side as a CoverParenthesizedExpression +info: > + AssignmentExpression[In, Yield] : + LeftHandSideExpression[?Yield] = AssignmentExpression[?In, ?Yield] + + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an + ArrayLiteral, then + [...] + e. If IsAnonymousFunctionDefinition(AssignmentExpression) and + IsIdentifierRef of LeftHandSideExpression are both true, then + + i. Let hasNameProperty be HasOwnProperty(rval, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(rval, + GetReferencedName(lref)). +---*/ + +var fn; + +(fn) = function() {}; + +assert.sameValue(Object.hasOwnProperty.call(fn, 'name'), false); diff --git a/test/language/expressions/assignment/fn-name-lhs-member.js b/test/language/expressions/assignment/fn-name-lhs-member.js new file mode 100644 index 0000000000..c76fbd9320 --- /dev/null +++ b/test/language/expressions/assignment/fn-name-lhs-member.js @@ -0,0 +1,27 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.14.4 +description: Left-hand side as a MemberExpression +info: > + AssignmentExpression[In, Yield] : + LeftHandSideExpression[?Yield] = AssignmentExpression[?In, ?Yield] + + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an + ArrayLiteral, then + [...] + e. If IsAnonymousFunctionDefinition(AssignmentExpression) and + IsIdentifierRef of LeftHandSideExpression are both true, then + + i. Let hasNameProperty be HasOwnProperty(rval, "name"). + ii. ReturnIfAbrupt(hasNameProperty). + iii. If hasNameProperty is false, perform SetFunctionName(rval, + GetReferencedName(lref)). +---*/ + +var o = {}; + +o.attr = function() {}; + +assert.sameValue(Object.hasOwnProperty.call(o.attr, 'name'), false); diff --git a/test/language/expressions/class/name.js b/test/language/expressions/class/name.js new file mode 100644 index 0000000000..70a1995301 --- /dev/null +++ b/test/language/expressions/class/name.js @@ -0,0 +1,32 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.5.16 +description: Assignment of function `name` attribute +info: > + ClassExpression : class BindingIdentifieropt ClassTail + + 5. If className is not undefined, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, then + i. Perform SetFunctionName(value, className). +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Object.hasOwnProperty.call(class {}, 'name'), false); + +assert.sameValue(class cls {}.name, 'cls'); +verifyNotEnumerable(class cls {}, 'name'); +verifyNotWritable(class cls {}, 'name'); +verifyConfigurable(class cls {}, 'name'); + +assert.sameValue( + Object.hasOwnProperty.call(class { constructor() {} }, 'name'), false +); + +assert.sameValue(class cls { constructor() {} }.name, 'cls'); +verifyNotEnumerable(class cls { constructor() {} }, 'name'); +verifyNotWritable(class cls { constructor() {} }, 'name'); +verifyConfigurable(class cls { constructor() {} }, 'name'); diff --git a/test/language/expressions/function/name.js b/test/language/expressions/function/name.js new file mode 100644 index 0000000000..543cc28d6e --- /dev/null +++ b/test/language/expressions/function/name.js @@ -0,0 +1,33 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.1.20 +description: Assignment of function `name` attribute +info: > + FunctionExpression : function ( FormalParameters ) { FunctionBody } + + 1. If the function code for FunctionExpression is strict mode code, let + strict be true. Otherwise let strict be false. + 2. Let scope be the LexicalEnvironment of the running execution context. + 3. Let closure be FunctionCreate(Normal, FormalParameters, FunctionBody, + scope, strict). + 4. Perform MakeConstructor(closure). + 5. Return closure. + + FunctionExpression : + function BindingIdentifier ( FormalParameters ) { FunctionBody } + + [...] + 5. Let name be StringValue of BindingIdentifier. + [...] + 9. Perform SetFunctionName(closure, name). +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Object.hasOwnProperty.call(function() {}, 'name'), false); + +assert.sameValue(function func() {}.name, 'func'); +verifyNotEnumerable(function func() {}, 'name'); +verifyNotWritable(function func() {}, 'name'); +verifyConfigurable(function func() {}, 'name'); diff --git a/test/language/expressions/generators/name.js b/test/language/expressions/generators/name.js index b732a6f5dd..ec43d6342b 100644 --- a/test/language/expressions/generators/name.js +++ b/test/language/expressions/generators/name.js @@ -1,19 +1,31 @@ -// Copyright 2015 Cubane Canada, Inc. All rights reserved. -// See LICENSE for details. +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. /*--- +es6id: 14.4.1 +description: Assignment of function `name` attribute info: > - Generator can be declared with GeneratorExpression syntax -es6id: 14.4 -author: Sam Mikes -description: can create generator function expressions (with name) + GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } + + 1. If the function code for this GeneratorExpression is strict mode code, + let strict be true. Otherwise let strict be false. + 2. Let scope be the LexicalEnvironment of the running execution context. + 3. Let closure be GeneratorFunctionCreate(Normal, FormalParameters, + GeneratorBody, scope, strict). + 4. Let prototype be ObjectCreate(%GeneratorPrototype%). + 5. Perform MakeConstructor(closure, true, prototype). + 6. Return closure. + + GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + + [...] + 10. Perform SetFunctionName(closure, name). +includes: [propertyHelper.js] ---*/ -var f = function *foo(a) { yield a+1; return; }; +assert.sameValue(Object.hasOwnProperty.call(function*() {}, 'name'), false); -assert.sameValue(f.name, 'foo'); - -var g = f(3); - -assert.sameValue(g.next().value, 4); -assert.sameValue(g.next().done, true); +assert.sameValue(function* func() {}.name, 'func'); +verifyNotEnumerable(function* func() {}, 'name'); +verifyNotWritable(function* func() {}, 'name'); +verifyConfigurable(function* func() {}, 'name'); diff --git a/test/language/expressions/object/fn-name-accessor-get.js b/test/language/expressions/object/fn-name-accessor-get.js new file mode 100644 index 0000000000..10cca6931f --- /dev/null +++ b/test/language/expressions/object/fn-name-accessor-get.js @@ -0,0 +1,42 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.3.9 +description: Assignment of function `name` attribute ("get" accessor) +info: > + MethodDefinition : get PropertyName ( ) { FunctionBody } + + [...] + 8. Perform SetFunctionName(closure, propKey, "get"). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var o, getter; + +o = { + get id() {}, + get [anonSym]() {}, + get [namedSym]() {} +}; + +getter = Object.getOwnPropertyDescriptor(o, 'id').get; +assert.sameValue(getter.name, 'get id'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(o, anonSym).get; +assert.sameValue(getter.name, 'get '); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(o, namedSym).get; +assert.sameValue(getter.name, 'get [test262]'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); diff --git a/test/language/expressions/object/fn-name-accessor-set.js b/test/language/expressions/object/fn-name-accessor-set.js new file mode 100644 index 0000000000..3ba3646228 --- /dev/null +++ b/test/language/expressions/object/fn-name-accessor-set.js @@ -0,0 +1,43 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.3.9 +description: Assignment of function `name` attribute ("set" accessor) +info: > + MethodDefinition : + set PropertyName ( PropertySetParameterList ) { FunctionBody } + + [...] + 7. Perform SetFunctionName(closure, propKey, "set"). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var o, setter; + +o = { + set id(_) {}, + set [anonSym](_) {}, + set [namedSym](_) {} +}; + +setter = Object.getOwnPropertyDescriptor(o, 'id').set; +assert.sameValue(setter.name, 'set id'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(o, anonSym).set; +assert.sameValue(setter.name, 'set '); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(o, namedSym).set; +assert.sameValue(setter.name, 'set [test262]'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); diff --git a/test/language/expressions/object/fn-name-arrow.js b/test/language/expressions/object/fn-name-arrow.js new file mode 100644 index 0000000000..134fdb9586 --- /dev/null +++ b/test/language/expressions/object/fn-name-arrow.js @@ -0,0 +1,40 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.2.6.9 +description: Assignment of function `name` attribute (ArrowFunction) +info: > + 6. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then + a. Let hasNameProperty be HasOwnProperty(propValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(propValue, + propKey). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var o; + +o = { + id: () => {}, + [anonSym]: () => {}, + [namedSym]: () => {} +}; + +assert.sameValue(o.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(o.id, 'name'); +verifyNotWritable(o.id, 'name'); +verifyConfigurable(o.id, 'name'); + +assert.sameValue(o[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(o[anonSym], 'name'); +verifyNotWritable(o[anonSym], 'name'); +verifyConfigurable(o[anonSym], 'name'); + +assert.sameValue(o[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(o[namedSym], 'name'); +verifyNotWritable(o[namedSym], 'name'); +verifyConfigurable(o[namedSym], 'name'); diff --git a/test/language/expressions/object/fn-name-class.js b/test/language/expressions/object/fn-name-class.js new file mode 100644 index 0000000000..e8ee409b64 --- /dev/null +++ b/test/language/expressions/object/fn-name-class.js @@ -0,0 +1,43 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.2.6.9 +description: Assignment of function `name` attribute (ClassExpression) +info: > + 6. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then + a. Let hasNameProperty be HasOwnProperty(propValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(propValue, + propKey). +includes: [propertyHelper.js] +features: [class, Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var o; + +o = { + xId: class x {}, + id: class {}, + [anonSym]: class {}, + [namedSym]: class {} +}; + +assert(o.xId.name !== 'xId'); + +assert.sameValue(o.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(o.id, 'name'); +verifyNotWritable(o.id, 'name'); +verifyConfigurable(o.id, 'name'); + +assert.sameValue(o[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(o[anonSym], 'name'); +verifyNotWritable(o[anonSym], 'name'); +verifyConfigurable(o[anonSym], 'name'); + +assert.sameValue(o[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(o[namedSym], 'name'); +verifyNotWritable(o[namedSym], 'name'); +verifyConfigurable(o[namedSym], 'name'); diff --git a/test/language/expressions/object/fn-name-cover.js b/test/language/expressions/object/fn-name-cover.js new file mode 100644 index 0000000000..e3068f9424 --- /dev/null +++ b/test/language/expressions/object/fn-name-cover.js @@ -0,0 +1,44 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.2.6.9 +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +info: > + 6. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then + a. Let hasNameProperty be HasOwnProperty(propValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(propValue, + propKey). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var o; + +o = { + xId: (0, function() {}), + id: (function() {}), + [anonSym]: (function() {}), + [namedSym]: (function() {}) +}; + +assert(o.xId.name !== 'xId'); + +assert.sameValue(o.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(o.id, 'name'); +verifyNotWritable(o.id, 'name'); +verifyConfigurable(o.id, 'name'); + +assert.sameValue(o[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(o[anonSym], 'name'); +verifyNotWritable(o[anonSym], 'name'); +verifyConfigurable(o[anonSym], 'name'); + +assert.sameValue(o[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(o[namedSym], 'name'); +verifyNotWritable(o[namedSym], 'name'); +verifyConfigurable(o[namedSym], 'name'); diff --git a/test/language/expressions/object/fn-name-fn.js b/test/language/expressions/object/fn-name-fn.js new file mode 100644 index 0000000000..84a5635caa --- /dev/null +++ b/test/language/expressions/object/fn-name-fn.js @@ -0,0 +1,43 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.2.6.9 +description: Assignment of function `name` attribute (FunctionExpression) +info: > + 6. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then + a. Let hasNameProperty be HasOwnProperty(propValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(propValue, + propKey). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var o; + +o = { + xId: function x() {}, + id: function() {}, + [anonSym]: function() {}, + [namedSym]: function() {} +}; + +assert(o.xId.name !== 'xId'); + +assert.sameValue(o.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(o.id, 'name'); +verifyNotWritable(o.id, 'name'); +verifyConfigurable(o.id, 'name'); + +assert.sameValue(o[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(o[anonSym], 'name'); +verifyNotWritable(o[anonSym], 'name'); +verifyConfigurable(o[anonSym], 'name'); + +assert.sameValue(o[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(o[namedSym], 'name'); +verifyNotWritable(o[namedSym], 'name'); +verifyConfigurable(o[namedSym], 'name'); diff --git a/test/language/expressions/object/fn-name-gen.js b/test/language/expressions/object/fn-name-gen.js new file mode 100644 index 0000000000..d35e730532 --- /dev/null +++ b/test/language/expressions/object/fn-name-gen.js @@ -0,0 +1,44 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.2.6.9 +description: > + Assignment of function `name` attribute (GeneratorExpression) +info: > + 6. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then + a. Let hasNameProperty be HasOwnProperty(propValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(propValue, + propKey). +includes: [propertyHelper.js] +features: [generators, Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var o; + +o = { + xId: function* x() {}, + id: function*() {}, + [anonSym]: function*() {}, + [namedSym]: function*() {} +}; + +assert(o.xId.name !== 'xId'); + +assert.sameValue(o.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(o.id, 'name'); +verifyNotWritable(o.id, 'name'); +verifyConfigurable(o.id, 'name'); + +assert.sameValue(o[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(o[anonSym], 'name'); +verifyNotWritable(o[anonSym], 'name'); +verifyConfigurable(o[anonSym], 'name'); + +assert.sameValue(o[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(o[namedSym], 'name'); +verifyNotWritable(o[namedSym], 'name'); +verifyConfigurable(o[namedSym], 'name'); diff --git a/test/language/expressions/object/method-definition/fn-name-fn.js b/test/language/expressions/object/method-definition/fn-name-fn.js new file mode 100644 index 0000000000..0f323f50a1 --- /dev/null +++ b/test/language/expressions/object/method-definition/fn-name-fn.js @@ -0,0 +1,40 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.2.6.9 +description: Assignment of function `name` attribute (MethodDefinition) +info: > + 6. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then + a. Let hasNameProperty be HasOwnProperty(propValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(propValue, + propKey). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var o; + +o = { + id() {}, + [anonSym]() {}, + [namedSym]() {} +}; + +assert.sameValue(o.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(o.id, 'name'); +verifyNotWritable(o.id, 'name'); +verifyConfigurable(o.id, 'name'); + +assert.sameValue(o[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(o[anonSym], 'name'); +verifyNotWritable(o[anonSym], 'name'); +verifyConfigurable(o[anonSym], 'name'); + +assert.sameValue(o[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(o[namedSym], 'name'); +verifyNotWritable(o[namedSym], 'name'); +verifyConfigurable(o[namedSym], 'name'); diff --git a/test/language/expressions/object/method-definition/fn-name-gen.js b/test/language/expressions/object/method-definition/fn-name-gen.js new file mode 100644 index 0000000000..448fa6b99b --- /dev/null +++ b/test/language/expressions/object/method-definition/fn-name-gen.js @@ -0,0 +1,41 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.4.13 +description: > + Assignment of function `name` attribute (GeneratorMethod) +info: > + GeneratorMethod : + * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + [...] + 9. Perform SetFunctionName(closure, propKey). +includes: [propertyHelper.js] +features: [generators, Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var o; + +o = { + *id() {}, + *[anonSym]() {}, + *[namedSym]() {} +}; + +assert.sameValue(o.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(o.id, 'name'); +verifyNotWritable(o.id, 'name'); +verifyConfigurable(o.id, 'name'); + +assert.sameValue(o[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(o[anonSym], 'name'); +verifyNotWritable(o[anonSym], 'name'); +verifyConfigurable(o[anonSym], 'name'); + +assert.sameValue(o[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(o[namedSym], 'name'); +verifyNotWritable(o[namedSym], 'name'); +verifyConfigurable(o[namedSym], 'name'); diff --git a/test/language/statements/class/definition/fn-name-accessor-get.js b/test/language/statements/class/definition/fn-name-accessor-get.js new file mode 100644 index 0000000000..5dfd13915f --- /dev/null +++ b/test/language/statements/class/definition/fn-name-accessor-get.js @@ -0,0 +1,63 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.3.9 +description: Assignment of function `name` attribute ("get" accessor) +info: > + MethodDefinition : get PropertyName ( ) { FunctionBody } + + [...] + 8. Perform SetFunctionName(closure, propKey, "get"). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var getter; + +class A { + get id() {} + get [anonSym]() {} + get [namedSym]() {} + static get id() {} + static get [anonSym]() {} + static get [namedSym]() {} +} + +getter = Object.getOwnPropertyDescriptor(A.prototype, 'id').get; +assert.sameValue(getter.name, 'get id'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A.prototype, anonSym).get; +assert.sameValue(getter.name, 'get '); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A.prototype, namedSym).get; +assert.sameValue(getter.name, 'get [test262]'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A, 'id').get; +assert.sameValue(getter.name, 'get id'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A, anonSym).get; +assert.sameValue(getter.name, 'get '); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A, namedSym).get; +assert.sameValue(getter.name, 'get [test262]'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); diff --git a/test/language/statements/class/definition/fn-name-accessor-set.js b/test/language/statements/class/definition/fn-name-accessor-set.js new file mode 100644 index 0000000000..f5c329625f --- /dev/null +++ b/test/language/statements/class/definition/fn-name-accessor-set.js @@ -0,0 +1,64 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.3.9 +description: Assignment of function `name` attribute ("set" accessor) +info: > + MethodDefinition : + set PropertyName ( PropertySetParameterList ) { FunctionBody } + + [...] + 7. Perform SetFunctionName(closure, propKey, "set"). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var setter; + +class A { + set id(_) {} + set [anonSym](_) {} + set [namedSym](_) {} + static set id(_) {} + static set [anonSym](_) {} + static set [namedSym](_) {} +} + +setter = Object.getOwnPropertyDescriptor(A.prototype, 'id').set; +assert.sameValue(setter.name, 'set id'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A.prototype, anonSym).set; +assert.sameValue(setter.name, 'set '); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A.prototype, namedSym).set; +assert.sameValue(setter.name, 'set [test262]'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A, 'id').set; +assert.sameValue(setter.name, 'set id'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A, anonSym).set; +assert.sameValue(setter.name, 'set '); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A, namedSym).set; +assert.sameValue(setter.name, 'set [test262]'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); diff --git a/test/language/statements/class/definition/fn-name-gen-method.js b/test/language/statements/class/definition/fn-name-gen-method.js new file mode 100644 index 0000000000..ed09ddf3e6 --- /dev/null +++ b/test/language/statements/class/definition/fn-name-gen-method.js @@ -0,0 +1,58 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.4.13 +description: > + Assignment of function `name` attribute (GeneratorMethod) +info: > + GeneratorMethod : + * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + [...] + 9. Perform SetFunctionName(closure, propKey). +includes: [propertyHelper.js] +features: [generators, Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); + +class A { + *id() {} + *[anonSym]() {} + *[namedSym]() {} + static *id() {} + static *[anonSym]() {} + static *[namedSym]() {} +} + +assert.sameValue(A.prototype.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(A.prototype.id, 'name'); +verifyNotWritable(A.prototype.id, 'name'); +verifyConfigurable(A.prototype.id, 'name'); + +assert.sameValue(A.prototype[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(A.prototype[anonSym], 'name'); +verifyNotWritable(A.prototype[anonSym], 'name'); +verifyConfigurable(A.prototype[anonSym], 'name'); + +assert.sameValue(A.prototype[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(A.prototype[namedSym], 'name'); +verifyNotWritable(A.prototype[namedSym], 'name'); +verifyConfigurable(A.prototype[namedSym], 'name'); + +assert.sameValue(A.id.name, 'id', 'static via IdentifierName'); +verifyNotEnumerable(A.id, 'name'); +verifyNotWritable(A.id, 'name'); +verifyConfigurable(A.id, 'name'); + +assert.sameValue(A[anonSym].name, '', 'static via anonymous Symbol'); +verifyNotEnumerable(A[anonSym], 'name'); +verifyNotWritable(A[anonSym], 'name'); +verifyConfigurable(A[anonSym], 'name'); + +assert.sameValue(A[namedSym].name, '[test262]', 'static via Symbol'); +verifyNotEnumerable(A[namedSym], 'name'); +verifyNotWritable(A[namedSym], 'name'); +verifyConfigurable(A[namedSym], 'name'); diff --git a/test/language/statements/class/definition/fn-name-method.js b/test/language/statements/class/definition/fn-name-method.js new file mode 100644 index 0000000000..e6842abc22 --- /dev/null +++ b/test/language/statements/class/definition/fn-name-method.js @@ -0,0 +1,57 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.2.6.9 +description: Assignment of function `name` attribute (MethodDefinition) +info: > + 6. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then + a. Let hasNameProperty be HasOwnProperty(propValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(propValue, + propKey). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); + +class A { + id() {} + [anonSym]() {} + [namedSym]() {} + static id() {} + static [anonSym]() {} + static [namedSym]() {} +} + +assert.sameValue(A.prototype.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(A.prototype.id, 'name'); +verifyNotWritable(A.prototype.id, 'name'); +verifyConfigurable(A.prototype.id, 'name'); + +assert.sameValue(A.prototype[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(A.prototype[anonSym], 'name'); +verifyNotWritable(A.prototype[anonSym], 'name'); +verifyConfigurable(A.prototype[anonSym], 'name'); + +assert.sameValue(A.prototype[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(A.prototype[namedSym], 'name'); +verifyNotWritable(A.prototype[namedSym], 'name'); +verifyConfigurable(A.prototype[namedSym], 'name'); + +assert.sameValue(A.id.name, 'id', 'static via IdentifierName'); +verifyNotEnumerable(A.id, 'name'); +verifyNotWritable(A.id, 'name'); +verifyConfigurable(A.id, 'name'); + +assert.sameValue(A[anonSym].name, '', 'static via anonymous Symbol'); +verifyNotEnumerable(A[anonSym], 'name'); +verifyNotWritable(A[anonSym], 'name'); +verifyConfigurable(A[anonSym], 'name'); + +assert.sameValue(A[namedSym].name, '[test262]', 'static via Symbol'); +verifyNotEnumerable(A[namedSym], 'name'); +verifyNotWritable(A[namedSym], 'name'); +verifyConfigurable(A[namedSym], 'name'); diff --git a/test/language/statements/class/definition/fn-name-static-precedence.js b/test/language/statements/class/definition/fn-name-static-precedence.js new file mode 100644 index 0000000000..7afcda8870 --- /dev/null +++ b/test/language/statements/class/definition/fn-name-static-precedence.js @@ -0,0 +1,63 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.5.15 +description: > + Function `name` attribute not inferred in presence of static `name` method +info: > + ClassDeclaration : class BindingIdentifier ClassTail + + [...] + 4. Let hasNameProperty be HasOwnProperty(value, "name"). + 5. ReturnIfAbrupt(hasNameProperty). + 6. If hasNameProperty is false, then perform SetFunctionName(value, + className). +includes: [propertyHelper.js] +---*/ + +class A { + static name() { + $ERROR('Static method should not be executed during definition'); + } +} + +assert.sameValue(typeof A.name, 'function'); + +var attr = 'name'; +class B { + static [attr]() { + $ERROR( + 'Static method defined via computed property should not be executed ' + + 'during definition' + ); + } +} + +assert.sameValue(typeof B.name, 'function'); + +class C { + static get name() { + $ERROR('Static `get` accessor should not be executed during definition'); + } +} + +assert.throws(Test262Error, function() { + C.name; +}); + +class D { + static set name(_) { + $ERROR('Static `set` accessor should not be executed during definition'); + } +} + +assert.sameValue(D.name, undefined); + +class E { + static *name() { + $ERROR('Static GeneratorMethod should not be executed during definition'); + } +} + +assert.sameValue(typeof E.name, 'function'); diff --git a/test/language/statements/class/name.js b/test/language/statements/class/name.js new file mode 100644 index 0000000000..b74ede2161 --- /dev/null +++ b/test/language/statements/class/name.js @@ -0,0 +1,21 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.5.15 +description: Assignment of function `name` attribute +info: > + ClassDeclaration : class BindingIdentifier ClassTail + + [...] + 6. If hasNameProperty is false, then perform SetFunctionName(value, + className). +includes: [propertyHelper.js] +---*/ + +class Test262 {} + +assert.sameValue(Test262.name, 'Test262'); +verifyNotEnumerable(Test262, 'name'); +verifyNotWritable(Test262, 'name'); +verifyConfigurable(Test262, 'name'); diff --git a/test/language/statements/const/fn-name-arrow.js b/test/language/statements/const/fn-name-arrow.js new file mode 100644 index 0000000000..d68cbc4bc5 --- /dev/null +++ b/test/language/statements/const/fn-name-arrow.js @@ -0,0 +1,24 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (ArrowFunction) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +const arrow = () => {}; + +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); diff --git a/test/language/statements/const/fn-name-class.js b/test/language/statements/const/fn-name-class.js new file mode 100644 index 0000000000..f48a7aa2de --- /dev/null +++ b/test/language/statements/const/fn-name-class.js @@ -0,0 +1,28 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (ClassExpression) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [class] +---*/ + +const xCls = class x {}; +const cls = class {}; + +assert(xCls.name !== 'xCls'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); diff --git a/test/language/statements/const/fn-name-cover.js b/test/language/statements/const/fn-name-cover.js new file mode 100644 index 0000000000..822b543daf --- /dev/null +++ b/test/language/statements/const/fn-name-cover.js @@ -0,0 +1,28 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +const xCover = (0, function() {}); +const cover = (function() {}); + +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); diff --git a/test/language/statements/const/fn-name-fn.js b/test/language/statements/const/fn-name-fn.js new file mode 100644 index 0000000000..03f9ce73ec --- /dev/null +++ b/test/language/statements/const/fn-name-fn.js @@ -0,0 +1,27 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (FunctionExpression) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +const xFn = function x() {}; +const fn = function() {}; + +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); diff --git a/test/language/statements/const/fn-name-gen.js b/test/language/statements/const/fn-name-gen.js new file mode 100644 index 0000000000..227615cd39 --- /dev/null +++ b/test/language/statements/const/fn-name-gen.js @@ -0,0 +1,28 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (GeneratorExpression) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [generators] +---*/ + +const xGen = function* x() {}; +const gen = function*() {}; + +assert(xGen.name !== 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name'); diff --git a/test/language/statements/function/name.js b/test/language/statements/function/name.js new file mode 100644 index 0000000000..b9a8142671 --- /dev/null +++ b/test/language/statements/function/name.js @@ -0,0 +1,24 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.1.19 +description: Assignment of function `name` attribute +info: > + FunctionDeclaration : + function BindingIdentifier ( FormalParameters ) { FunctionBody } + + 1. Let name be StringValue of BindingIdentifier. + 2. Let F be FunctionCreate(Normal, FormalParameters, FunctionBody, scope, strict). + 3. Perform MakeConstructor(F). + 4. Perform SetFunctionName(F, name). + 5. Return F. +includes: [propertyHelper.js] +---*/ + +function func() {} + +assert.sameValue(func.name, 'func'); +verifyNotEnumerable(func, 'name'); +verifyNotWritable(func, 'name'); +verifyConfigurable(func, 'name'); diff --git a/test/language/statements/generators/name-property-descriptor.js b/test/language/statements/generators/name-property-descriptor.js deleted file mode 100644 index f3e8007c8f..0000000000 --- a/test/language/statements/generators/name-property-descriptor.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2013 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: > - Generator functions should define a `name` property. -includes: [propertyHelper.js] -es6id: 25.2.4 ----*/ - -function* g() {} - -assert.sameValue(g.name, 'g'); -verifyNotEnumerable(g, 'name'); -verifyNotWritable(g, 'name'); -verifyConfigurable(g, 'name'); diff --git a/test/language/expressions/generators/name-property-descriptor.js b/test/language/statements/generators/name.js similarity index 55% rename from test/language/expressions/generators/name-property-descriptor.js rename to test/language/statements/generators/name.js index 02828c7b63..c6b931652f 100644 --- a/test/language/expressions/generators/name-property-descriptor.js +++ b/test/language/statements/generators/name.js @@ -2,13 +2,18 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -description: > - Generator functions should define a `name` property. +description: Assignment of function `name` attribute +es6id: 14.4.12 +info: > + GeneratorDeclaration : + function * BindingIdentifier ( FormalParameters ) { GeneratorBody } + + [...] + 6. Perform SetFunctionName(F, name). includes: [propertyHelper.js] -es6id: 25.2.4 ---*/ -var g = function*() {}; +function* g() {} assert.sameValue(g.name, 'g'); verifyNotEnumerable(g, 'name'); diff --git a/test/language/statements/let/fn-name-arrow.js b/test/language/statements/let/fn-name-arrow.js new file mode 100644 index 0000000000..7a82ece3f2 --- /dev/null +++ b/test/language/statements/let/fn-name-arrow.js @@ -0,0 +1,24 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (ArrowFunction) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +let arrow = () => {}; + +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); diff --git a/test/language/statements/let/fn-name-class.js b/test/language/statements/let/fn-name-class.js new file mode 100644 index 0000000000..85be2ac429 --- /dev/null +++ b/test/language/statements/let/fn-name-class.js @@ -0,0 +1,28 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (ClassExpression) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [class] +---*/ + +let xCls = class x {}; +let cls = class {}; + +assert(xCls.name !== 'xCls'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); diff --git a/test/language/statements/let/fn-name-cover.js b/test/language/statements/let/fn-name-cover.js new file mode 100644 index 0000000000..49de023520 --- /dev/null +++ b/test/language/statements/let/fn-name-cover.js @@ -0,0 +1,28 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +let xCover = (0, function() {}); +let cover = (function() {}); + +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); diff --git a/test/language/statements/let/fn-name-fn.js b/test/language/statements/let/fn-name-fn.js new file mode 100644 index 0000000000..749a9519f2 --- /dev/null +++ b/test/language/statements/let/fn-name-fn.js @@ -0,0 +1,27 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (FunctionExpression) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +let xFn = function x() {}; +let fn = function() {}; + +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); diff --git a/test/language/statements/let/fn-name-gen.js b/test/language/statements/let/fn-name-gen.js new file mode 100644 index 0000000000..857e19943c --- /dev/null +++ b/test/language/statements/let/fn-name-gen.js @@ -0,0 +1,28 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.1.4 +description: Assignment of function `name` attribute (GeneratorExpression) +info: > + LexicalBinding : BindingIdentifier Initializer + + [...] + 6. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [generators] +---*/ + +let xGen = function* x() {}; +let gen = function*() {}; + +assert(xGen.name !== 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name'); diff --git a/test/language/statements/variable/fn-name-arrow.js b/test/language/statements/variable/fn-name-arrow.js new file mode 100644 index 0000000000..885c848c04 --- /dev/null +++ b/test/language/statements/variable/fn-name-arrow.js @@ -0,0 +1,24 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: Assignment of function `name` attribute (ArrowFunction) +info: > + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +var arrow = () => {}; + +assert.sameValue(arrow.name, 'arrow'); +verifyNotEnumerable(arrow, 'name'); +verifyNotWritable(arrow, 'name'); +verifyConfigurable(arrow, 'name'); diff --git a/test/language/statements/variable/fn-name-class.js b/test/language/statements/variable/fn-name-class.js new file mode 100644 index 0000000000..0d095fc922 --- /dev/null +++ b/test/language/statements/variable/fn-name-class.js @@ -0,0 +1,28 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: Assignment of function `name` attribute (ClassExpression) +info: > + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [class] +---*/ + +var xCls = class x {}; +var cls = class {}; + +assert(xCls.name !== 'xCls'); + +assert.sameValue(cls.name, 'cls'); +verifyNotEnumerable(cls, 'name'); +verifyNotWritable(cls, 'name'); +verifyConfigurable(cls, 'name'); diff --git a/test/language/statements/variable/fn-name-cover.js b/test/language/statements/variable/fn-name-cover.js new file mode 100644 index 0000000000..875726ed7e --- /dev/null +++ b/test/language/statements/variable/fn-name-cover.js @@ -0,0 +1,28 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: > + Assignment of function `name` attribute (CoverParenthesizedExpression) +info: > + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +var xCover = (0, function() {}); +var cover = (function() {}); + +assert(xCover.name !== 'xCover'); + +assert.sameValue(cover.name, 'cover'); +verifyNotEnumerable(cover, 'name'); +verifyNotWritable(cover, 'name'); +verifyConfigurable(cover, 'name'); diff --git a/test/language/statements/variable/fn-name-fn.js b/test/language/statements/variable/fn-name-fn.js new file mode 100644 index 0000000000..1f02115737 --- /dev/null +++ b/test/language/statements/variable/fn-name-fn.js @@ -0,0 +1,27 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: Assignment of function `name` attribute (FunctionExpression) +info: > + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +---*/ + +var xFn = function x() {}; +var fn = function() {}; + +assert(xFn.name !== 'xFn'); + +assert.sameValue(fn.name, 'fn'); +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); diff --git a/test/language/statements/variable/fn-name-gen.js b/test/language/statements/variable/fn-name-gen.js new file mode 100644 index 0000000000..73dee4795b --- /dev/null +++ b/test/language/statements/variable/fn-name-gen.js @@ -0,0 +1,28 @@ +// Copyright (C) Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 13.3.2.4 +description: Assignment of function `name` attribute (GeneratorExpression) +info: > + VariableDeclaration : BindingIdentifier Initializer + + [...] + 7. If IsAnonymousFunctionDefinition(Initializer) is true, then + a. Let hasNameProperty be HasOwnProperty(value, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(value, + bindingId). +includes: [propertyHelper.js] +features: [generators] +---*/ + +var xGen = function* x() {}; +var gen = function*() {}; + +assert(xGen.name !== 'xGen'); + +assert.sameValue(gen.name, 'gen'); +verifyNotEnumerable(gen, 'name'); +verifyNotWritable(gen, 'name'); +verifyConfigurable(gen, 'name');