10.3 Built-in Function Objects
The built-in function objects defined in this specification may be implemented as either ECMAScript function objects (
If a built-in
Unless otherwise specified every built-in
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
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 new
expression the argumentsList parameter of the invoked [[Construct]] internal method provides the values for the built-in
Built-in functions that are not constructors do not have a
Built-in functions have an [[InitialName]] internal slot.
If a built-in
10.3.1 [[Call]] ( thisArgument, argumentsList )
The [[Call]] internal method of a built-in
- Let callerContext be the
running execution context . - If callerContext is not already suspended, suspend callerContext.
- Let calleeContext be a new
execution context . - Set the Function of calleeContext to F.
- Let calleeRealm be F.[[Realm]].
- Set the
Realm of calleeContext to calleeRealm. - Set the ScriptOrModule of calleeContext to
null . - Perform any necessary
implementation-defined initialization of calleeContext. - Push calleeContext onto the
execution context stack ; calleeContext is now therunning execution context . - 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 thethis value, argumentsList provides the named parameters, and the NewTarget value isundefined . - Remove calleeContext from the
execution context stack and restore callerContext as therunning execution context . - Return result.
When calleeContext is removed from the
10.3.2 [[Construct]] ( argumentsList, newTarget )
The [[Construct]] internal method of a built-in
- Let result be the
Completion Record that is the result of evaluating F in a manner that conforms to the specification of F. Thethis value is uninitialized, argumentsList provides the named parameters, and newTarget provides the NewTarget value.
10.3.3 CreateBuiltinFunction ( steps, length, name, internalSlotsList [ , realm [ , prototype [ , prefix ] ] ] )
The abstract operation CreateBuiltinFunction takes arguments steps, length, name, and internalSlotsList (a
Assert : steps is either a set of algorithm steps or other definition of a function's behaviour provided in this specification.- If realm is not present, set realm to
the current Realm Record . Assert : realm is aRealm Record .- If prototype is not present, set prototype to realm.[[Intrinsics]].[[
%Function.prototype% ]]. - Let func be a new built-in
function object that when called performs the action described by steps. The newfunction object has internal slots whose names are the elements of internalSlotsList, and an [[InitialName]] internal slot. - Set func.[[Realm]] to realm.
- Set func.[[Prototype]] to prototype.
- Set func.[[Extensible]] to
true . - Set func.[[InitialName]] to
null . - Perform !
SetFunctionLength (func, length). - If prefix is not present, then
- Perform !
SetFunctionName (func, name).
- Perform !
- Else,
- Perform !
SetFunctionName (func, name, prefix).
- Perform !
- Return func.
Each built-in function defined in this specification is created by calling the CreateBuiltinFunction abstract operation.