Class TopLevel
- All Implemented Interfaces:
Serializable
,ConstProperties
,DebuggableObject
,IdFunctionCall
,Scriptable
- Direct Known Subclasses:
ImporterTopLevel
,ModuleScope
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 proptotypes
(e.g. with dynamic scopes) embeddings should explicitly call
cacheBuiltins()
to initialize the class cache for each top-level
scope.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
An enumeration of built-in ECMAScript objects. -
Field Summary
Fields inherited from class org.mozilla.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Cache the built-in ECMAScript objects to protect them against modifications by the script.static Function
getBuiltinCtor
(Context cx, Scriptable scope, TopLevel.Builtins type) Static helper method to get a built-in object constructor with the giventype
from the givenscope
.Get the cached built-in object constructor from this scope with the giventype
.static Scriptable
getBuiltinPrototype
(Scriptable scope, TopLevel.Builtins type) Static helper method to get a built-in object prototype with the giventype
from the givenscope
.Get the cached built-in object prototype from this scope with the giventype
.Return the name of the class.Methods inherited from class org.mozilla.javascript.IdScriptableObject
activatePrototypeMap, defineOwnProperty, delete, execIdCall, exportAsJSClass, get, getAttributes, has, hasPrototypeMap, initPrototypeConstructor, initPrototypeMethod, initPrototypeValue, put, setAttributes
Methods inherited from class org.mozilla.javascript.ScriptableObject
associateValue, avoidObjectDetection, callMethod, callMethod, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineProperty, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, hasInstance, hasProperty, hasProperty, isConst, isEmpty, isExtensible, isSealed, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sealObject, setAttributes, setAttributes, setAttributes, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size
-
Constructor Details
-
TopLevel
public TopLevel()
-
-
Method Details
-
getClassName
Description copied from class:ScriptableObject
Return the name of the class. This is typically the same name as the constructor. Classes extending ScriptableObject must implement this abstract method.- Specified by:
getClassName
in interfaceScriptable
- Specified by:
getClassName
in classScriptableObject
-
cacheBuiltins
public void cacheBuiltins()Cache the built-in ECMAScript objects to protect them against modifications by the script. This method is called automatically byScriptRuntime.initStandardObjects
if 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()
. -
getBuiltinCtor
Static helper method to get a built-in object constructor with the giventype
from 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 giventype
from 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()
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()
has not been called on this object.- Parameters:
type
- the built-in type- Returns:
- the built-in prototype
-