From c7358d29280021cb49f397fe953831948a145f04 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Wed, 15 Apr 2020 13:24:27 -0500 Subject: [PATCH] Normative: fix Function toString on builtins --- spec.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec.html b/spec.html index 9d624459ebd..5a5ff34270e 100644 --- a/spec.html +++ b/spec.html @@ -8572,6 +8572,9 @@

SetFunctionName ( _F_, _name_ [ , _prefix_ ] )

1. Let _description_ be _name_'s [[Description]] value. 1. If _description_ is *undefined*, set _name_ to the empty String. 1. Else, set _name_ to the string-concatenation of *"["*, _description_, and *"]"*. + 1. If _F_ has an [[InitialName]] internal slot, and _F_.[[InitialName]] is *null*, + 1. Set _F_.[[InitialName]] to _name_. + 1. NOTE: The [[InitialName]] internal slot does not contain _prefix_ so that it matches the |PropertyName| in |NativeFunction|. 1. If _prefix_ is present, then 1. Set _name_ to the string-concatenation of _prefix_, the code unit 0x0020 (SPACE), and _name_. 1. Return ! DefinePropertyOrThrow(_F_, *"name"*, PropertyDescriptor { [[Value]]: _name_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }). @@ -8731,6 +8734,7 @@

Built-in Function Objects

The behaviour specified for each built-in function via algorithm steps or other means is the specification of the function body behaviour for both [[Call]] and [[Construct]] invocations of the function. However, [[Construct]] invocation is not supported by all built-in functions. For each built-in function, when invoked with [[Call]], the [[Call]] _thisArgument_ provides the *this* value, the [[Call]] _argumentsList_ provides the named parameters, and the NewTarget value is *undefined*. When invoked with [[Construct]], the *this* value is uninitialized, the [[Construct]] _argumentsList_ provides the named parameters, and the [[Construct]] _newTarget_ parameter provides the NewTarget value. If the built-in function is implemented as an ECMAScript function object then this specified behaviour must be implemented by the ECMAScript code that is the body of the function. Built-in functions that are ECMAScript function objects must be strict functions. If a built-in constructor has any [[Call]] behaviour other than throwing a *TypeError* exception, an ECMAScript implementation of the function must be done in a manner that does not cause the function's [[IsClassConstructor]] internal slot to have the value *true*.

Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function. When a built-in constructor is called as part of a `new` expression the _argumentsList_ parameter of the invoked [[Construct]] internal method provides the values for the built-in constructor's named parameters.

Built-in functions that are not constructors do not have a *"prototype"* property unless otherwise specified in the description of a particular function.

+

Built-in functions have an [[InitialName]] internal slot.

If a built-in function object is not implemented as an ECMAScript function it must provide [[Call]] and [[Construct]] internal methods that conform to the following definitions:

@@ -8776,6 +8780,7 @@

CreateBuiltinFunction ( _steps_, _internalSlotsList_ [ , _realm_ [ , _protot 1. Set _func_.[[Prototype]] to _prototype_. 1. Set _func_.[[Extensible]] to *true*. 1. Set _func_.[[ScriptOrModule]] to *null*. + 1. Set _func_.[[InitialName]] to *null*. 1. Return _func_.

Each built-in function defined in this specification is created by calling the CreateBuiltinFunction abstract operation.

@@ -26447,7 +26452,7 @@

Function.prototype.toString ( )

When the `toString` method is called, the following steps are taken:

1. Let _func_ be the *this* value. - 1. If _func_ is a bound function exotic object or a built-in function object, then return an implementation-dependent String source code representation of _func_. The representation must have the syntax of a |NativeFunction|. Additionally, if _func_ is a Well-known Intrinsic Object and is not identified as an anonymous function, the portion of the returned String that would be matched by |PropertyName| must be the initial value of the *"name"* property of _func_. + 1. If _func_ is a bound function exotic object or a built-in function object, then return an implementation-dependent String source code representation of _func_. The representation must have the syntax of a |NativeFunction|. Additionaly, if _func_ has an [[InitialName]] internal slot, the portion of the returned String that would be matched by |PropertyName| must be the value of _func_.[[InitialName]]. 1. If Type(_func_) is Object and _func_ has a [[SourceText]] internal slot and _func_.[[SourceText]] is a sequence of Unicode code points and ! HostHasSourceTextAvailable(_func_) is *true*, then 1. Return ! UTF16Encode(_func_.[[SourceText]]). 1. If Type(_func_) is Object and IsCallable(_func_) is *true*, then return an implementation-dependent String source code representation of _func_. The representation must have the syntax of a |NativeFunction|.