Class TopLevel
- java.lang.Object
- 
- org.mozilla.javascript.ScriptableObject
- 
- org.mozilla.javascript.IdScriptableObject
- 
- org.mozilla.javascript.TopLevel
 
 
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- ConstProperties,- DebuggableObject,- IdFunctionCall,- Scriptable,- SymbolScriptable
 - Direct Known Subclasses:
- ImporterTopLevel,- ModuleScope
 
 public class TopLevel extends IdScriptableObject A top-level scope object that provides special means to cache and preserve the initial values of the built-in constructor properties for better ECMAScript compliance.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.newBuiltinObjectandScriptRuntime.setBuiltinProtoAndParentmethods 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 callcacheBuiltins(Scriptable, boolean)to initialize the class cache for each top-level scope.- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classTopLevel.BuiltinsAn enumeration of built-in ECMAScript objects.- 
Nested classes/interfaces inherited from class org.mozilla.javascript.ScriptableObjectScriptableObject.KeyComparator
 
- 
 - 
Field Summary- 
Fields inherited from class org.mozilla.javascript.ScriptableObjectCONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 - 
Fields inherited from interface org.mozilla.javascript.ScriptableNOT_FOUND
 
- 
 - 
Constructor SummaryConstructors Constructor Description TopLevel()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcacheBuiltins(Scriptable scope, boolean sealed)Cache the built-in ECMAScript objects to protect them against modifications by the script.static FunctiongetBuiltinCtor(Context cx, Scriptable scope, TopLevel.Builtins type)Static helper method to get a built-in object constructor with the giventypefrom the givenscope.BaseFunctiongetBuiltinCtor(TopLevel.Builtins type)Get the cached built-in object constructor from this scope with the giventype.static ScriptablegetBuiltinPrototype(Scriptable scope, TopLevel.Builtins type)Static helper method to get a built-in object prototype with the giventypefrom the givenscope.ScriptablegetBuiltinPrototype(TopLevel.Builtins type)Get the cached built-in object prototype from this scope with the giventype.java.lang.StringgetClassName()Return the name of the class.- 
Methods inherited from class org.mozilla.javascript.IdScriptableObjectactivatePrototypeMap, addIdFunctionProperty, defaultGet, defaultHas, defaultPut, defineOwnProperty, delete, delete, ensureType, execIdCall, exportAsJSClass, fillConstructorProperties, findInstanceIdInfo, findInstanceIdInfo, findPrototypeId, findPrototypeId, get, get, getAttributes, getAttributes, getInstanceIdName, getInstanceIdValue, getMaxInstanceId, getOwnPropertyDescriptor, has, has, hasPrototypeMap, initPrototypeConstructor, initPrototypeId, initPrototypeMethod, initPrototypeMethod, initPrototypeMethod, initPrototypeValue, initPrototypeValue, instanceIdInfo, put, put, setAttributes, setInstanceIdAttributes, setInstanceIdValue
 - 
Methods inherited from class org.mozilla.javascript.ScriptableObjectapplyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, equivalentValues, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, hasInstance, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size
 
- 
 
- 
- 
- 
Method Detail- 
getClassNamepublic java.lang.String getClassName() Description copied from class:ScriptableObjectReturn the name of the class.This is typically the same name as the constructor. Classes extending ScriptableObject must implement this abstract method. - Specified by:
- getClassNamein interface- Scriptable
- Specified by:
- getClassNamein class- ScriptableObject
 
 - 
cacheBuiltinspublic void cacheBuiltins(Scriptable scope, boolean sealed) 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().
 - 
getBuiltinCtorpublic static Function getBuiltinCtor(Context cx, Scriptable scope, TopLevel.Builtins type) 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 Context
- scope- the top-level scope
- type- the built-in type
- Returns:
- the built-in constructor
 
 - 
getBuiltinPrototypepublic static Scriptable getBuiltinPrototype(Scriptable scope, TopLevel.Builtins type) 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 scope
- type- the built-in type
- Returns:
- the built-in prototype
 
 - 
getBuiltinCtorpublic BaseFunction getBuiltinCtor(TopLevel.Builtins type) Get the cached built-in object constructor from this scope with the giventype. Returns null ifcacheBuiltins(Scriptable, boolean)has not been called on this object.- Parameters:
- type- the built-in type
- Returns:
- the built-in constructor
 
 - 
getBuiltinPrototypepublic Scriptable getBuiltinPrototype(TopLevel.Builtins type) Get the cached built-in object prototype from this scope with the giventype. Returns null ifcacheBuiltins(Scriptable, boolean)has not been called on this object.- Parameters:
- type- the built-in type
- Returns:
- the built-in prototype
 
 
- 
 
-