wrappedJSObject

If you implement an XPConnect interface in Javascript (e.g. nsITreeView if you don't want to use RDF to display data in a tree), you might need to access properties or methods inside your javascript object which are not part of the interface.

This can be easily achieved using a special object property.

This property is called wrappedJSObject and is part of every XPConnect interface. Here is an example.

// in the interface-implementing code, set the property to this

function my_interface() {
    this.wrappedJSObject = this;
}

// whatever you assigned to wrappedJSObject can be retrieved through the XPConnect wrapper

function get_obj(tree) {
    return tree.view
            ? tree.view.wrappedJSObject
            : null;
}


Why this is necessary is explained in nsIXPConnect.idl:

* When JavaScript code uses a component that is itself implemeted in
* JavaScript then XPConnect will build a wrapper rather than directly
* expose the JSObject of the component. This allows components implemented
* in JavaScript to 'look' just like any other xpcom component (from the
* perspective of the JavaScript caller). This insulates the component from
* the caller and hides any properties or methods that are not part of the
* interface as declared in xpidl. Usually this is a good thing.
*
* However, in some cases it is useful to allow the JS caller access to the
* JS component's underlying implementation. In order to facilitate this
* XPConnect supports the 'wrappedJSObject' property.

Trackbacks

    No Trackbacks

Comments

Display comments as (Linear | Threaded)

    No comments


Add Comment


Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA 1CAPTCHA 2CAPTCHA 3CAPTCHA 4CAPTCHA 5