We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

Une Liaison de langage XPCOM est une passerelle entre un langage donné et XPCOM en vue d'atteindre deux objectifs :  

  • Permettre l'accès aux objets XPCOM depuis ce langage (où l'accès signifie la lecture/écriture/création d'objets XPCOM, ainsi que l'appel de leurs méthodes).
  • Présenter les modules écrits dans le langage de liaison comme des objets XPCOM, et de ce fait permettre à tout autre langage pour lequel une liaison XPCOM existe d'accéder à ces modules.

Puisque la couche XPCOM est écrite en C/C++, son API peut être employée sans intermédiaire avec les langages C et C++. Pour tous les autres langages désirant accéder à l'API XPCOM, l'utilisation d'une passerelle est nécessaire.

 De telles passerelles existent pour différents langages :

Components.classes est un objet en lecture seule dont les propriétés sont des classes indexées par ContractID. Sespropriétés mettre en œuvre l'interface nsIJSCID. Chaque objet représente l'une des classes de XPCOM qui peuvent être construits ou accessibles en tant que service XPCOM.
Crée une fonction JavaScript qui peut être utilisé pour construire de nouvelles instances de composants XPCOM.
Components.Exception est un constructeur JavaScript pour créer des objets nsIXPCException. Ces objets exceptions peuvent être émis lors de l'implémentation des interfaces XPCOM en JavaScript, et ils peuvent fournir de meilleurs diagnostics dans la console d'erreur que la simplement valeur nsresult.
Components.ID est un constructeur qui crée des objets natifs qui sont conformes à l'interface {{ Interface("nsIJSID") }}.
Objet Components
L'objet Components est l'objet au travers duquel les fonctionnalités XPConnect sont reflétées en JavaScript. Il s'agit en réalité d'une instance native de l'interface nsIXPCComponents qui est reflétée en JavaScript comme un objet de niveau global à l'aide d'XPConnect.
Objet Components
L'objet Components est l'objet au travers duquel les fonctionnalités XPConnect sont reflétées en JavaScript. Il s'agit en réalité d'une instance native de l'interface nsIXPCComponents qui est reflétée en JavaScript comme un objet de niveau global à l'aide d'XPConnect.
PyXPCOM permet la communication entre Python et XPCOM de telle façon qu'une application Python puisse accéder à des objets XPCOM, et que XPCOM puisse accéder à des classes Python qui implémentent une interface XPCOM. PyXPCOM est utilisé dans ActiveState Komodo, par exemple.

Components.classesByID is a read-only object whose properties are classes indexed by CID.
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 true or false respectively.
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 nsIStackFrame (IDL definition) that represents a snapshot of the current JavaScript callstack. This can be used for various diagnostic purposes.
Components.utils is a collection of various useful XPConnect features. Its interface is defined at js/xpconnect/idl/xpccomponents.idl.
Components.utils.Sandbox is used to create a sandbox object for use with evalInSandbox().
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:
Components.utils.createObjectIn creates a new JavaScript object in the scope of the specified object's compartment.
The evalInSandbox() function enables you to evaluate JavaScript code inside a sandbox you've previously created using the Components.utils.Sandbox constructor.
This function enables code running in a more-privileged JavaScript context to evaluate a string in a less-privileged JavaScript context. The result is structured cloned back to the original context, unless it is native (for example, if it returns a DOM node, this is not structured cloned, because the original context will see that through an XrayWrapper already), so it's guaranteed to behave predictably.

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. In this way privileged code, such as an add-on, can share code with less-privileged code like a normal web page script. A function exported from privileged to less-privileged code can be called from the less privileged code's context.
Components.utils.forceGC lets scripts force a garbage collection cycle. The Mozilla JavaScript engine will perform garbage collection automatically when the JavaScript heap grows beyond a certain size. This mechanism doesn't account for any native (C++) XPCOM objects hanging off JavaScript objects though. In many cases a JavaScript application will have internal knowledge of JavaScript objects referencing large (trees of) XPCOM objects and know when they are no longer reachable. In this case it can be important to be able to force a garbage collection cycle from JavaScript.
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.
When privileged JavaScript in Gecko accesses objects belonging to less-privileged code (such as untrusted web content), it does so, by default, with "Xray vision": a mechanism that filters out certain changes to the objects that could cause them to behave in unexpected ways. For example, privileged code using an Xray to a DOM object sees only  the original, native version of the DOM object. Any expando properties are not visible, and if any native properties have been redefined, this has no effect.
Ensures that the specified object's methods are all in the object's scope, and aren't cross-component wrappers.
Components.utils.reportError reports a JavaScript Error object to the Error Console, and returns. It is meant for use by extension developers who have exception handler blocks which want to "eat" an exception, but still want to report it to the console.
This method lets scripts schedule a garbage collection cycle. The garbage collection cycle will occur sometime in the future, when no JavaScript code is executing. This is useful particularly when testing for memory leaks, because normal garbage collection is conservative when JavaScript code is running to ensure that in-use memory isn't inadvertently collected.
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:
Components.utils.unload was introduced in Firefox 7 and is used to unload JavaScript code modules. This can be particularly handy with restartless (boostrapped) extensions, so that you can unload an old version of a code module when a new version of your add-on is installed.
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.
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.
XPConnect is a bridge between JavaScript and XPCOM. With XPConnect, you can use XPCOM components from JavaScript code, and interact with JavaScript objects from within XPCOM components. XPConnect is part of Firefox and is actively used in XUL applications.

Étiquettes et contributeurs liés au document

Contributeurs à cette page : jmh, Planche, Chbok
Dernière mise à jour par : jmh,