Skip to content

Commit

Permalink
Assign "name" property to all anonymous functions (#2299)
Browse files Browse the repository at this point in the history
Implements the changes from <tc39/ecma262#1490>.
  • Loading branch information
anba authored and leobalter committed Aug 15, 2019
1 parent 40dca6e commit 59a1a01
Show file tree
Hide file tree
Showing 23 changed files with 373 additions and 145 deletions.
16 changes: 11 additions & 5 deletions test/built-ins/Promise/all/resolve-element-function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ info: |
A promise resolve function is an anonymous built-in function.
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
---*/

var resolveElementFunction;
Expand All @@ -28,5 +33,6 @@ NotPromise.resolve = function(v) {
};
Promise.all.call(NotPromise, [thenable]);

assert.sameValue(Object.prototype.hasOwnProperty.call(resolveElementFunction, "name"), false);
assert.sameValue(resolveElementFunction.name, "");
verifyProperty(resolveElementFunction, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
16 changes: 11 additions & 5 deletions test/built-ins/Promise/allSettled/reject-element-function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ info: |
A promise resolve function is an anonymous built-in function.
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
features: [Promise.allSettled]
---*/

Expand All @@ -29,5 +34,6 @@ NotPromise.resolve = function(v) {
};
Promise.allSettled.call(NotPromise, [thenable]);

assert.sameValue(Object.prototype.hasOwnProperty.call(rejectElementFunction, 'name'), false);
assert.sameValue(rejectElementFunction.name, '');
verifyProperty(rejectElementFunction, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
19 changes: 11 additions & 8 deletions test/built-ins/Promise/allSettled/resolve-element-function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ info: |
A promise resolve function is an anonymous built-in function.
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
features: [Promise.allSettled]
---*/

Expand All @@ -29,8 +34,6 @@ NotPromise.resolve = function(v) {
};
Promise.allSettled.call(NotPromise, [thenable]);

assert.sameValue(
Object.prototype.hasOwnProperty.call(resolveElementFunction, 'name'),
false
);
assert.sameValue(resolveElementFunction.name, '');
verifyProperty(resolveElementFunction, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
16 changes: 11 additions & 5 deletions test/built-ins/Promise/executor-function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ info: |
A GetCapabilitiesExecutor function is an anonymous built-in function.
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
---*/

var executorFunction;
Expand All @@ -21,5 +26,6 @@ function NotPromise(executor) {
}
Promise.resolve.call(NotPromise);

assert.sameValue(Object.prototype.hasOwnProperty.call(executorFunction, "name"), false);
assert.sameValue(executorFunction.name, "");
verifyProperty(executorFunction, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
16 changes: 11 additions & 5 deletions test/built-ins/Promise/reject-function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ info: |
A promise reject function is an anonymous built-in function.
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
---*/

var rejectFunction;
new Promise(function(resolve, reject) {
rejectFunction = reject;
});

assert.sameValue(Object.prototype.hasOwnProperty.call(rejectFunction, "name"), false);
assert.sameValue(rejectFunction.name, "");
verifyProperty(rejectFunction, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
16 changes: 11 additions & 5 deletions test/built-ins/Promise/resolve-function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ info: |
A promise resolve function is an anonymous built-in function.
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
---*/

var resolveFunction;
new Promise(function(resolve, reject) {
resolveFunction = resolve;
});

assert.sameValue(Object.prototype.hasOwnProperty.call(resolveFunction, "name"), false);
assert.sameValue(resolveFunction.name, "");
verifyProperty(resolveFunction, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
15 changes: 11 additions & 4 deletions test/built-ins/Proxy/revocable/revocation-function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ info: |
A Proxy revocation function is an anonymous function.
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
features: [Proxy]
---*/

var revocationFunction = Proxy.revocable({}, {}).revoke;

assert.sameValue(Object.prototype.hasOwnProperty.call(revocationFunction, "name"), false);
verifyProperty(revocationFunction, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
21 changes: 18 additions & 3 deletions test/built-ins/ThrowTypeError/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@ description: >
info: |
%ThrowTypeError% ( )
The %ThrowTypeError% intrinsic is an anonymous built-in function
object that is defined once for each Realm.
9.2.9.1 %ThrowTypeError% ( )
The %ThrowTypeError% intrinsic is an anonymous built-in function
object that is defined once for each Realm. The `name` property of a
%ThrowTypeError% function has the attributes { [[Writable]]: *false*,
[[Enumerable]]: *false*, [[Configurable]]: *false* }.
17 ECMAScript Standard Built-in Objects:
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
---*/

var ThrowTypeError = Object.getOwnPropertyDescriptor(function() {
"use strict";
return arguments;
}(), "callee").get;

assert.sameValue(Object.prototype.hasOwnProperty.call(ThrowTypeError, "name"), false);
verifyProperty(ThrowTypeError, "name", {
value: "", writable: false, enumerable: false, configurable: false
});
20 changes: 12 additions & 8 deletions test/intl402/Collator/prototype/compare/compare-function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ description: >
info: |
10.3.3 get Intl.Collator.prototype.compare
...
4. If collator.[[boundCompare]] is undefined, then
a. Let F be a new built-in function object as defined in 10.3.4.
b. Let bc be BoundFunctionCreate(F, collator, « »).
c. Perform ! DefinePropertyOrThrow(bc, "length", PropertyDescriptor {[[Value]]: 2, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true}).
d. Set collator.[[boundCompare]] to bc.
...
17 ECMAScript Standard Built-in Objects:
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
---*/

var compareFn = new Intl.Collator().compare;

assert.sameValue(Object.prototype.hasOwnProperty.call(compareFn, "name"), false);
verifyProperty(compareFn, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ description: >
info: |
12.4.3 get Intl.DateTimeFormat.prototype.compare
...
4. If the [[boundFormat]] internal slot of dtf is undefined, then
a. Let F be a new built-in function object as defined in DateTime Format Functions (12.1.5).
b. Let bf be BoundFunctionCreate(F, dft, « »).
c. Perform ! DefinePropertyOrThrow(bf, "length", PropertyDescriptor {[[Value]]: 1, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true}).
d. Set dtf.[[boundFormat]] to bf.
...
17 ECMAScript Standard Built-in Objects:
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
---*/

var formatFn = new Intl.DateTimeFormat().format;

assert.sameValue(Object.prototype.hasOwnProperty.call(formatFn, "name"), false);
verifyProperty(formatFn, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
20 changes: 12 additions & 8 deletions test/intl402/NumberFormat/prototype/format/format-function-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ description: >
info: |
11.4.3 get Intl.NumberFormat.prototype.compare
...
4. If nf.[[boundFormat]] is undefined, then
a. Let F be a new built-in function object as defined in Number Format Functions (11.1.3).
b. Let bf be BoundFunctionCreate(F, nf, « »).
c. Perform ! DefinePropertyOrThrow(bf, "length", PropertyDescriptor {[[Value]]: 1, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true}).
d. Set nf.[[boundFormat]] to bf.
...
17 ECMAScript Standard Built-in Objects:
Every built-in function object, including constructors, has a `name`
property whose value is a String. Functions that are identified as
anonymous functions use the empty string as the value of the `name`
property.
Unless otherwise specified, the `name` property of a built-in function
object has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*,
[[Configurable]]: *true* }.
includes: [propertyHelper.js]
---*/

var formatFn = new Intl.NumberFormat().format;

assert.sameValue(Object.prototype.hasOwnProperty.call(formatFn, "name"), false);
verifyProperty(formatFn, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.5
esid: sec-object-initializer
description: >
In a class, static computed property method names can be a number
includes: [compareArray.js]
Expand All @@ -21,6 +21,6 @@ assert(
"`compareArray(Object.keys(C), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'prototype', 'name', 'a', 'c']),
"`compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'prototype', 'name', 'a', 'c'])` returns `true`"
compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'name', 'prototype', 'a', 'c']),
"`compareArray(Object.getOwnPropertyNames(C), ['1', '2', 'length', 'name', 'prototype', 'a', 'c'])` returns `true`"
);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.5
esid: sec-object-initializer
description: >
In a class, static computed property method names can be a string
includes: [compareArray.js]
Expand All @@ -21,6 +21,6 @@ assert(
"`compareArray(Object.keys(C), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'b', 'c', 'd']),
"`compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'b', 'c', 'd'])` returns `true`"
compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype', 'a', 'b', 'c', 'd']),
"`compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype', 'a', 'b', 'c', 'd'])` returns `true`"
);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2014 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 12.2.5
esid: sec-object-initializer
description: >
In a class, static computed property method names can be a symbol
includes: [compareArray.js]
Expand All @@ -24,8 +24,8 @@ assert(
"`compareArray(Object.keys(C), [])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'c']),
"`compareArray(Object.getOwnPropertyNames(C), ['length', 'prototype', 'name', 'a', 'c'])` returns `true`"
compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype', 'a', 'c']),
"`compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype', 'a', 'c'])` returns `true`"
);
assert(
compareArray(Object.getOwnPropertySymbols(C), [sym1, sym2]),
Expand Down
24 changes: 24 additions & 0 deletions test/language/expressions/arrow-function/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2019 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-arrow-function-definitions-runtime-semantics-evaluation
description: Assignment of function `name` attribute
info: |
ArrowFunction : ArrowParameters => ConciseBody
1. Let scope be the LexicalEnvironment of the running execution context.
2. Let parameters be CoveredFormalsList of ArrowParameters.
3. Let closure be FunctionCreate(Arrow, parameters, ConciseBody, scope, "").
...
5. Return closure.
includes: [propertyHelper.js]
---*/

verifyProperty(x => {}, "name", {
value: "", writable: false, enumerable: false, configurable: true
});

verifyProperty(() => {}, "name", {
value: "", writable: false, enumerable: false, configurable: true
});
Loading

0 comments on commit 59a1a01

Please sign in to comment.