Components
对象是 XPConnect 功能被映射到 JavaScript 上的对象。Components
对象的 native 实现位置在 nsIXPCComponents , 这个接口会被映射成JavaScript 作为使用 XPConnect 的最高层级的对象。
Components 的一些属性需要高级的全写,可能在 web 页面中不能正常工作。
Components 对象包含下面的成员:
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
已废弃 Gecko 24.0- Provides access to the value of the
methodjit
property in the JavaScript environment.
utils.methodjit_always
已废弃 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.