An XPCOM Language Binding is a bridge between a particular language and XPCOM to provide access to XPCOM objects from that language, and to let modules written in that language be used as XPCOM objects by all other languages for which there are XPCOM bindings.
More specifically, an XPCOM language binding:
- Enables access to XPCOM objects from that language (where access means reading/writing/creating XPCOM objects as well as calling methods on them).
- Exposes modules written in the bound language as XPCOM objects, thereby enabling all other languages for which XPCOM bindings exist to access these modules.
Since the XPCOM layer itself is written in C/C++, its API can be accessed out-of-the-box using C or C++. In order to allow any other language to use the XPCOM API, a bridging layer is required.
The following bridging layers are currently available:
- Components object
Components.classes is a read-only object whose properties are classes indexed by ContractID.
Components.classesByID is a read-only object whose properties are classes indexed by CID.
nsresult's value will.
Components.ID is a constructor that creates native objects that conform to the
Components.interfaces is a read-only object whose properties are interfaces indexed by their names.
Components.interfacesByID is a read-only array of classes indexed by IID.
- Determines whether a given XPCOM return code (that is, an
nsresult value) indicates the success or failure of an operation, returning
Components.manager is a convenience reflection of the global native component manager service. The scriptable methods on the
nsIComponentManager interface can be called directly on this object.
Components.results is a read-only object whose properties are the names listed as the first parameters of the macros in
js/xpconnect/src/xpc.msg (also at Table Of Errors), with the value of each corresponding to that constant's value.
Components.stack is a read only property of type
Components.utils is a collection of various useful XPConnect features. Its interface is defined at
- This function provides a safe way to take an object defined in a privileged scope and create a structured clone of it in a less-privileged scope. It returns a reference to the clone:
This is useful for privileged code, such as add-on code, to access variables and APIs defined in web content.
- This function provides a safe way to expose a function from a privileged scope to a less-privileged scope.
- This method is used to determine the global object with which an object is associated. This is the global object in place at the time the object was created, which is to say the global object used when executing the script that created the object.
- This method was introduced in Firefox 3 and is used for obtaining a weak reference for an object. To obtain the object reference, you have to call
get() on the resulting object.
Components.utils.import was introduced in Firefox 3 and is used for sharing code between different scopes easily. For example, you can import XPCOMUtils.jsm to avoid copy/pasting long XPCOM component registration boilerplate in your component files.
- Imports various objects into a system scope.
- Ensures that the specified object's methods are all in the object's scope, and aren't cross-component wrappers.
Components.utils.Sandbox is used to create a sandbox object for use with
- This method lets scripts set the zeal level for garbage collection. You can get details on what this method does in
JS_SetGCZeal. This method calls through to that thusly:
- Undo a previous call to
Components.utils.waiveXrays(), restoring Xray vision for the caller.
- Waives Xray vision for an object, giving the caller a transparent wrapper to the underlying object.
- JavaXPCOM allows for communication between Java and XPCOM, such that a Java application can access XPCOM objects, and XPCOM can access any Java class that implements an XPCOM interface. JavaXPCOM is not actively maintained.
- plXPCOM (Perl XPCOM) provides language bindings letting you use XPCOM from Perl code. The resources here provide information about this language binding and how to use it.
- PyXPCOM allows for communication between Python and XPCOM, such that a Python application can access XPCOM objects, and XPCOM can access any Python class that implements an XPCOM interface. PyXPCOM is actively used in ActiveState Komodo products, for example.
- RbXPCOM (Ruby Cross-Platform COM) provides bindings between the popular Ruby programming language and XPCOM. You can find additional information using the resource links below.