9.3 Realms
Before it is evaluated, all ECMAScript code must be associated with a realm. Conceptually, a
A
Field Name | Value | Meaning |
---|---|---|
[[AgentSignifier]] |
an |
The |
[[Intrinsics]] |
a |
The intrinsic values used by code associated with this |
[[GlobalObject]] |
an Object or |
The |
[[GlobalEnv]] |
a |
The global environment for this |
[[TemplateMap]] |
a |
Template objects are canonicalized separately for each Once a |
[[LoadedModules]] |
a |
A map from the specifier strings imported by this
As mentioned in import() expression in a context where there is no |
[[HostDefined]] |
anything (default value is |
Field reserved for use by |
9.3.1 CreateRealm ( )
The abstract operation CreateRealm takes no arguments and returns a
- Let realmRec be a new
Realm Record . - Perform
CreateIntrinsics (realmRec). - Set realmRec.[[AgentSignifier]] to
AgentSignifier (). - Set realmRec.[[GlobalObject]] to
undefined . - Set realmRec.[[GlobalEnv]] to
undefined . - Set realmRec.[[TemplateMap]] to a new empty
List . - Return realmRec.
9.3.2 CreateIntrinsics ( realmRec )
The abstract operation CreateIntrinsics takes argument realmRec (a
- Set realmRec.[[Intrinsics]] to a new
Record . - Set fields of realmRec.[[Intrinsics]] with the values listed in
Table 6 . The field names are the names listed in column one of the table. The value of each field is a new object value fully and recursively populated with property values as defined by the specification of each object in clauses19 through28 . All object property values are newly created object values. All values that are built-infunction objects are created by performingCreateBuiltinFunction (steps, length, name, slots, realmRec, prototype) where steps is the definition of that function provided by this specification, name is the initial value of the function's"name" property, length is the initial value of the function's"length" property, slots is a list of the names, if any, of the function's specified internal slots, and prototype is the specified value of the function's [[Prototype]] internal slot. The creation of the intrinsics and their properties must be ordered to avoid any dependencies upon objects that have not yet been created. - Perform
AddRestrictedFunctionProperties (realmRec.[[Intrinsics]].[[%Function.prototype% ]], realmRec). - Return
unused .
9.3.3 SetRealmGlobalObject ( realmRec, globalObj, thisValue )
The abstract operation SetRealmGlobalObject takes arguments realmRec (a
- If globalObj is
undefined , then- Let intrinsics be realmRec.[[Intrinsics]].
- Set globalObj to
OrdinaryObjectCreate (intrinsics.[[%Object.prototype% ]]).
Assert : globalObjis an Object .- If thisValue is
undefined , set thisValue to globalObj. - Set realmRec.[[GlobalObject]] to globalObj.
- Let newGlobalEnv be
NewGlobalEnvironment (globalObj, thisValue). - Set realmRec.[[GlobalEnv]] to newGlobalEnv.
- Return
unused .
9.3.4 SetDefaultGlobalBindings ( realmRec )
The abstract operation SetDefaultGlobalBindings takes argument realmRec (a
- Let global be realmRec.[[GlobalObject]].
- For each property of the Global Object specified in clause
19 , do- Let name be the String value of the
property name . - Let desc be the fully populated data
Property Descriptor for the property, containing the specified attributes for the property. For properties listed in19.2 ,19.3 , or19.4 the value of the [[Value]] attribute is the corresponding intrinsic object from realmRec. - Perform ?
DefinePropertyOrThrow (global, name, desc).
- Let name be the String value of the
- Return global.