mozilla

Components

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Warning: This object is only intended for code running with chrome privileges. Exposing the object to regular web code was a mistake. If you use this object on your web page, your site might break at any time! In current versions of Firefox only a few interfaces required for compatibility are still accessible. Don't use Components!

The Components object is the object through which XPConnect functionality is reflected into JavaScript. The Components object is actually a native instance of the nsIXPCComponents interface which is reflected into JavaScript as a top level object using XPConnect.

Some properties of Components require advanced privileges and may not work in web pages.

The Components object has the following members:

classes
array of classes by ContractID
classesByID
array of classes by CID
Constructor
constructor for constructor of components
Exception
constructor for XPConnect exceptions
ID
constructor for XPCOM nsIDs
interfaces
array of interfaces by interface name
interfacesByID
array of interfaces by IID
isSuccessCode
function to determine if a given result code is a success code
lastResult
result code of most recent XPConnect call
manager
the global XPCOM component manager
results
array of known result codes by name
returnCode
pending result for current call
stack
current JavaScript call stack
utils
provides access to several useful features
 
utils.atline
Provides access to the value of the atline property in the JavaScript environment.
utils.createObjectIn
Creates a new object in the scope of the specified object's compartment. May only be called from JavaScript code.
utils.evalInSandbox
Runs JavaScript code in a sandbox, usually used to run code with restricted privileges.
utils.forceGC
Forces a garbage collection cycle.
utils.getGlobalForObject 
Returns the global object with which a given object is associated (through its prototype chain at birth, for example).
utils.getWeakReference 
Gets a weak reference for the object passed in.
utils.import 
Loads a JavaScript module into the current script, without sharing a scope.
utils.lookupMethod
Looks up a native (i.e. declared in the interface) method or property of an XPCOM object. Serves the same purpose as XPCNativeWrapper.
utils.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.
utils.methodjit Obsolete since Gecko 24.0
Provides access to the value of the methodjit property in the JavaScript environment.
utils.methodjit_always Obsolete since Gecko 24.0
Provides access to the value of the methodjit_always property in the JavaScript environment.
utils.relimit
Provides access to the value of the relimit property in the JavaScript environment.
utils.reportError
Reports a JavaScript Error object to the Error Console.
utils.schedulePreciseGC
Requests that garbage collection occur sometime in the future when no JavaScript code is running; accepts a callback function to receive notification once collection is complete.
utils.setGCZeal()
Sets the GC zeal level for the context.
utils.strict
Provides access to the value of the strict property in the JavaScript environment.
utils.werror
Provides access to the value of the werror property in the JavaScript environment.
utils.Sandbox
Creates sandbox objects for use with evalInSandbox.
utils.xml
Provides access to the value of the xml property in the JavaScript environment.

Document Tags and Contributors

Contributors to this page: Sheppy, Nickolay, Mgjbot, CN
Last updated by: Sheppy,