Components.utils

Components.utils is a collection of various useful XPConnect features. Its interface is defined at js/xpconnect/idl/xpccomponents.idl.

The object currently has the following members:

EDITORS! please keep this list in sync with the Components object page

Methods

Method Description
cloneInto()

Create a structured clone of an object in a different JavaScript context.

Requires Gecko 29

createArrayIn() Returns an array created in specified compartment.
createObjectIn() Creates a new object, created in the scope of the specified object's compartment.
dispatch() Dispatches a runnable to the current/main thread. If the parameter is passed, the runnable will be dispatch in the compartment of the parameter, which affects which error reporter gets called.
evalInSandbox() Runs JavaScript code in a sandbox, usually used to run code with restricted privileges.
evalInWindow()

Evaluate JavaScript code in a less-privileged JavaScript context.

Requires Gecko 29

exportFunction()

Export a JavaScript function from a more-privileged to a less-privileged scope, allowing it to be called in the less-privileged scope.

Requires Gecko 29

forceGC() Forces a garbage collection cycle.
forceCC() Forces a cycle collection cycle.
forceShrinkingGC() Forces a shrinking garbage collection cycle.
getComponentsForScope() This seemingly-paradoxical API allows privileged code to explicitly give unprivileged code a reference to its own Components object (whereas it's normally hidden away on a scope chain visible only to XBL methods). See also SpecialPowers.getComponents.
getGlobalForObject() Returns the global object with which a given object is associated (through its prototype chain at birth, for example).
getJSTestingFunctions()
getWeakReference() Gets a weak reference for the object passed in.
import() Loads a JS module into the current script, without sharing a scope.
unload() Unloads a JS module loaded with import().
isDeadWrapper() Determines whether this object is backed by a DeadObjectProxy.
lookupMethod()

Looks up a native (i.e. declared in the interface) method or property of an XPCOM object. Serves the same purpose as XPCNativeWrapper.

makeObjectPropsNormal() Ensures that all functions come from the specified object's scope, and aren't cross-compartment wrappers. May only be called from JavaScript code.
nondeterministicGetWeakMapKeys() Return the keys in a weak map. This operation is non-deterministic because it is affected by the scheduling of the garbage collector and the cycle collector. This should only be used to write tests of the interaction of the GC and CC with weak maps.
nukeSandbox()
recomputeWrappers() To be called from JS only. This is for Gecko internal use only, and may disappear at any moment.
reportError() Reports a JavaScript Error object to the Error Console.
setWantXrays() Requires Gecko 20 To be called from JS only. This is for Gecko internal use only, and may disappear at any moment.
schedulePreciseGC() Schedules a garbage collection cycle for some time in the future at which no JavaScript code is running. This lets you specify a callback so you can be notified once the garbage collection cycle has been performed.
setGCZeal() Sets the level of garbage collection level for full garbage collection. See JS_SetGCZeal for details; this method calls through to that with the specified value as the zeal value.

Properties

 

Property Type Description
Sandbox nsIXPCComponents_utils_Sandbox Creates sandbox objects for use with evalInSandbox().
atline Boolean When atline is enabled, comments of the form //@line num set the number of the following line to num. This reflects the value of the JavaScript environment's option by the same name. Read only.
ion Boolean Read only.
methodjit Boolean This reflects the value of the JavaScript environment's option by the same name. Read only.
methodjit_always Boolean This reflects the value of the JavaScript environment's option by the same name. Read only.
relimit Boolean This reflects the value of the JavaScript environment's option by the same name. Read only.
strict Boolean Strict mode is enabled. This reflects the value of the JavaScript environment's option by the same name. Read only.
strict_mode Boolean Read only.
werror Boolean Warnings should be treated as errors. This reflects the value of the JavaScript environment's option by the same name. Read only.
xml Boolean XML mode is enabled. This reflects the value of the JavaScript environment's option by the same name. Read only.

 

Document Tags and Contributors

Last updated by: wbamberg,