Skip to content

Commit

Permalink
Editorial: Drop [[ScriptOrModule]] slot for exotic built-ins (#2190)
Browse files Browse the repository at this point in the history
A built-in function that is implemented as an exotic object
has no need for a [[ScriptOrModule]] internal slot.
It always has the value `*null*`,
and the only place it's used is in
[the [[Call]] and [[Construct]] methods for exotic built-ins](sec-built-in-function-objects-call-thisargument-argumentslist),
so we can just inline `*null*` there.

The remaining 3 appearances of [[ScriptOrModule]]
pertain only to ordinary functions.

(Setting [[ScriptOrModule]] for exotic built-ins
made more sense when the slot was introduced,
because of the way GetActiveScriptOrModule() was written,
but PR #556 changed it to basically the current situation.)
  • Loading branch information
jmdyck authored and ljharb committed Nov 3, 2020
1 parent 5657da4 commit 0b3a808
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -8548,7 +8548,7 @@ <h1>FunctionDeclarationInstantiation ( _func_, _argumentsList_ )</h1>
<emu-clause id="sec-built-in-function-objects">
<h1>Built-in Function Objects</h1>
<p>The built-in function objects defined in this specification may be implemented as either ECMAScript function objects (<emu-xref href="#sec-ecmascript-function-objects"></emu-xref>) whose behaviour is provided using ECMAScript code or as implementation provided function exotic objects whose behaviour is provided in some other manner. In either case, the effect of calling such functions must conform to their specifications. An implementation may also provide additional built-in function objects that are not defined in this specification.</p>
<p>If a built-in function object is implemented as an exotic object it must have the ordinary object behaviour specified in <emu-xref href="#sec-ordinary-object-internal-methods-and-internal-slots"></emu-xref>. All such function exotic objects also have [[Prototype]], [[Extensible]], [[Realm]], and [[ScriptOrModule]] internal slots.</p>
<p>If a built-in function object is implemented as an exotic object it must have the ordinary object behaviour specified in <emu-xref href="#sec-ordinary-object-internal-methods-and-internal-slots"></emu-xref>. All such function exotic objects also have [[Prototype]], [[Extensible]], and [[Realm]] internal slots.</p>
<p>Unless otherwise specified every built-in function object has the %Function.prototype% object as the initial value of its [[Prototype]] internal slot.</p>
<p>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*.</p>
<p>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.</p>
Expand All @@ -8566,7 +8566,7 @@ <h1>[[Call]] ( _thisArgument_, _argumentsList_ )</h1>
1. Set the Function of _calleeContext_ to _F_.
1. Let _calleeRealm_ be _F_.[[Realm]].
1. Set the Realm of _calleeContext_ to _calleeRealm_.
1. Set the ScriptOrModule of _calleeContext_ to _F_.[[ScriptOrModule]].
1. Set the ScriptOrModule of _calleeContext_ to *null*.
1. Perform any necessary implementation-defined initialization of _calleeContext_.
1. Push _calleeContext_ onto the execution context stack; _calleeContext_ is now the running execution context.
1. [id="step-call-builtin-function-result"] Let _result_ be the Completion Record that is the result of evaluating _F_ in a manner that conforms to the specification of _F_. _thisArgument_ is the *this* value, _argumentsList_ provides the named parameters, and the NewTarget value is *undefined*.
Expand Down Expand Up @@ -8598,7 +8598,6 @@ <h1>CreateBuiltinFunction ( _steps_, _internalSlotsList_ [ , _realm_ [ , _protot
1. Set _func_.[[Realm]] to _realm_.
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_.
</emu-alg>
Expand Down

0 comments on commit 0b3a808

Please sign in to comment.