- All Implemented Interfaces:
Serializable,ConstProperties<VarScope>,PropHolder<VarScope>,VarScope
- Direct Known Subclasses:
ImporterTopLevel
ECMA 262 requires that most constructors used internally construct objects with the original prototype object as value of their [[Prototype]] internal property. Since built-in global constructors are defined as writable and deletable, this means they should be cached to protect against redefinition at runtime.
In order to implement this efficiently, this class provides a mechanism to access the original
built-in global constructors and their prototypes via numeric class-ids. To make use of this, the
new ScriptRuntime.newBuiltinObject and ScriptRuntime.setBuiltinProtoAndParent methods should be
used to create and initialize objects of built-in classes instead of their generic counterparts.
Calling Context.initStandardObjects() with an instance of this
class as argument will automatically cache built-in classes after initialization. For other
setups involving top-level scopes that inherit global properties from their prototypes (e.g. with
dynamic scopes) embeddings should explicitly call cacheBuiltins(boolean) to initialize
the class cache for each top-level scope.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAn enumeration of built-in ECMAScript objects.static class -
Field Summary
Fields inherited from class org.htmlunit.corejs.javascript.SlotMapOwner
isSealed -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcacheBuiltins(boolean sealed) voidcacheBuiltins(TopLevel scope, boolean sealed) Deprecated.voidcopyBuiltins(TopLevel other, boolean sealed) static TopLevelcreateIsolate(TopLevel parent) static TopLevelcreateIsolate(TopLevel parent, ScriptableObject customGlobal) static TopLevelcreateIsolateCustomPrototypeChain(TopLevel parent, ScriptableObject customGlobal) Only use this function if you have already set the customGlobal's prototype chain to point to this top level's global object.voiddefineConst(Context cx, String name, VarScope start) Reserves a definition spot for a const.voiddefineFunctionProperties(VarScope scope, String[] names, Class<?> clazz, int attributes) voiddefineProperty(String propertyName, Object value, int attributes) Define a JavaScript property.voidReturns the value of the named property or NOT_FOUND.intgetAttributes(String name) Get the attributes of a named property.static FunctiongetBuiltinCtor(Context cx, VarScope scope, TopLevel.Builtins type) Static helper method to get a built-in object constructor with the giventypefrom the givenscope.Get the cached built-in object constructor from this scope with the giventype.Get the cached built-in object prototype from this scope with the giventype.getBuiltinPrototype(org.htmlunit.corejs.javascript.TopLevel.NativeErrors type) Get the cached built-in object prototype from this scope with the giventype.static ScriptablegetBuiltinPrototype(TopLevel scope, TopLevel.Builtins type) Static helper method to get a built-in object prototype with the giventypefrom the givenscope.booleanReturns true if the named property is defined.booleanReturns true if the named property is defined as a const on this object.voidSets the value of the named property, creating it if need be.voidSets the value of the named const property, creating it if need be.voidvoidsetAttributes(String name, int attributes) Set the attributes of a named property.Methods inherited from class org.htmlunit.corejs.javascript.ScopeObject
defineProperty, delete, delete, get, get, getParentScope, getThis, has, has, put, put, putOwnProperty, putOwnProperty, putOwnProperty, setAttributesMethods inherited from class org.htmlunit.corejs.javascript.SlotMapOwner
associateValue, checkNotSealed, copyAssociatedValue, createSlotMap, createSlotMap, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getIds, isSealed, readMaps, setAttributes, setAttributes, setAttributes, writeMapsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.htmlunit.corejs.javascript.PropHolder
getIdsMethods inherited from interface org.htmlunit.corejs.javascript.VarScope
copyScope, getAncestor, isNestedScope
-
Constructor Details
-
TopLevel
public TopLevel() -
TopLevel
-
-
Method Details
-
createIsolate
-
createIsolate
-
createIsolateCustomPrototypeChain
public static TopLevel createIsolateCustomPrototypeChain(TopLevel parent, ScriptableObject customGlobal) Only use this function if you have already set the customGlobal's prototype chain to point to this top level's global object. This should only be done if you know for certain that no other use will be made of this prototype chain. -
cacheBuiltins
Deprecated.Cache the built-in ECMAScript objects to protect them against modifications by the script. This method is called automatically byScriptRuntime.initStandardObjectsif the scope argument is an instance of this class. It only has to be called by the embedding if a top-level scope is not initialized throughinitStandardObjects().This method is deprecated and kept for compatibility. Please use either
cacheBuiltins(boolean)orcopyBuiltins(org.htmlunit.corejs.javascript.TopLevel,boolean)instead. -
cacheBuiltins
public void cacheBuiltins(boolean sealed) -
copyBuiltins
-
getBuiltinCtor
Static helper method to get a built-in object constructor with the giventypefrom the givenscope. If the scope is not an instance of this class or does have a cache of built-ins, the constructor is looked up via normal property lookup.- Parameters:
cx- the current Contextscope- the top-level scopetype- the built-in type- Returns:
- the built-in constructor
-
getBuiltinPrototype
Static helper method to get a built-in object prototype with the giventypefrom the givenscope. If the scope is not an instance of this class or does have a cache of built-ins, the prototype is looked up via normal property lookup.- Parameters:
scope- the top-level scopetype- the built-in type- Returns:
- the built-in prototype
-
getBuiltinCtor
Get the cached built-in object constructor from this scope with the giventype. Returns null ifcacheBuiltins(boolean)has not been called on this object.- Parameters:
type- the built-in type- Returns:
- the built-in constructor
-
getBuiltinPrototype
Get the cached built-in object prototype from this scope with the giventype. Returns null ifcacheBuiltins(boolean)has not been called on this object.- Parameters:
type- the built-in type- Returns:
- the built-in prototype
-
getBuiltinPrototype
Get the cached built-in object prototype from this scope with the giventype. Returns null ifcacheBuiltins(boolean)has not been called on this object.- Parameters:
type- the built-in type- Returns:
- the built-in prototype
-
getGlobalThis
-
get
Description copied from class:ScopeObjectReturns the value of the named property or NOT_FOUND.If the property was created using defineProperty, the appropriate getter method is called.
- Specified by:
getin interfacePropHolder<VarScope>- Overrides:
getin classScopeObject- Parameters:
name- the name of the propertystart- the object in which the lookup began- Returns:
- the value of the property (may be null), or NOT_FOUND
-
put
Description copied from class:ScopeObjectSets the value of the named property, creating it if need be.If the property was created using defineProperty, the appropriate setter method is called.
If the property's attributes include READONLY, no action is taken. This method will actually set the property in the start object.
- Specified by:
putin interfacePropHolder<VarScope>- Overrides:
putin classScopeObject- Parameters:
name- the name of the propertystart- the object whose property is being setvalue- value to set the property to
-
has
Description copied from class:ScopeObjectReturns true if the named property is defined.- Specified by:
hasin interfacePropHolder<VarScope>- Overrides:
hasin classScopeObject- Parameters:
name- the name of the propertystart- the object in which the lookup began- Returns:
- true if and only if the property was found in the object
-
delete
- Specified by:
deletein interfacePropHolder<VarScope>- Overrides:
deletein classScopeObject
-
sealObject
public void sealObject()- Overrides:
sealObjectin classSlotMapOwner<VarScope>
-
defineProperty
Description copied from class:ScopeObjectDefine a JavaScript property.Creates the property with an initial value and sets its attributes.
- Overrides:
definePropertyin classScopeObject- Parameters:
propertyName- the name of the property to define.value- the initial value of the propertyattributes- the attributes of the JavaScript property- See Also:
-
setAttributes
Description copied from class:ScopeObjectSet the attributes of a named property.The property is specified by
nameas defined forhas.The possible attributes are READONLY, DONTENUM, and PERMANENT. Combinations of attributes are expressed by the bitwise OR of attributes. EMPTY is the state of no attributes set. Any unused bits are reserved for future use.
- Overrides:
setAttributesin classScopeObject- Parameters:
name- the name of the propertyattributes- the bitset of attributes- See Also:
-
getAttributes
Description copied from class:SlotMapOwnerGet the attributes of a named property.The property is specified by
nameas defined forhas.- Overrides:
getAttributesin classSlotMapOwner<VarScope>- Parameters:
name- the identifier for the property- Returns:
- the bitset of attributes
- See Also:
-
isConst
Description copied from class:ScopeObjectReturns true if the named property is defined as a const on this object.- Specified by:
isConstin interfaceConstProperties<VarScope>- Overrides:
isConstin classScopeObjectname- the name of the property- Returns:
- true if the named property is defined as a const, false otherwise.
-
putConst
Description copied from class:ScopeObjectSets the value of the named const property, creating it if need be.If the property was created using defineProperty, the appropriate setter method is called.
If the property's attributes include READONLY, no action is taken. This method will actually set the property in the start object.
- Specified by:
putConstin interfaceConstProperties<VarScope>- Overrides:
putConstin classScopeObjectname- the name of the propertystart- the object whose property is being setvalue- value to set the property to- See Also:
-
defineConst
Description copied from interface:ConstPropertiesReserves a definition spot for a const. This will set up a definition of the const property, but set its value to undefined. The semantics of the start parameter is the same as for putConst.- Specified by:
defineConstin interfaceConstProperties<VarScope>- Overrides:
defineConstin classScopeObjectname- The name of the property.start- The object whose property is being reserved.
-
defineFunctionProperties
-