Labs/Jetpack/Binary Components: Difference between revisions

From MozillaWiki
< Labs‎ | Jetpack
Jump to navigation Jump to search
m (all hg links point to tip)
(added some docs for wrap().)
Line 18: Line 18:
The source code for this functionality is in [http://hg.mozilla.org/labs/jetpack/file/tip/components/src/wrapper.cpp wrapper.cpp].   
The source code for this functionality is in [http://hg.mozilla.org/labs/jetpack/file/tip/components/src/wrapper.cpp wrapper.cpp].   


=== wrap() ===
<code>nsJetpack.</code>'''wrap'''(''object'', ''membrane'')
 
This function wraps ''object'' with ''membrane'', meaning that ''membrane'' mediates all access to and from ''object''.
 
''membrane'' should be a JavaScript object with any of the following methods defined:
 
::<code>membrane.</code>'''resolve'''(''wrappee'', ''membrane'', ''name'')
 
::This is essentially a JavaScript wrapper for [https://developer.mozilla.org/en/SpiderMonkey/JSAPI_Reference/JSClass.resolve JSClass.resolve].  It's called when the property identified by ''name'' doesn't exist on ''wrappee''.  The membrane should either define ''name'' on ''wrappee'' and return ''wrappee'', or&mdash;if ''name'' doesn't exist&mdash;it should return <code>undefined</code>.


=== unwrap() ===
=== unwrap() ===

Revision as of 20:07, 28 July 2009

nsJetpack

nsJetpack is a binary component used to provide services to Jetpack that aren't otherwise available to scripted chrome code in the Mozilla platform.

Accessing the Component

Because the goal of nsJetpack is to provide functionality to scripted code, and because much of its functionality is concerned with providing access to SpiderMonkey internals, the XPCOM interface for the component is rather trivial. To obtain the component, simply do:

 var nsJetpack = Cc["@labs.mozilla.com/jetpackdi;1"]
                 .createInstance(Ci.nsIJetpack).get();

This will give you the nsJetpack native JavaScript object, which provides access to all the component's functionality.

Flexible Membrane Functionality

nsJetpack contains functionality that exposes many SpiderMonkey C API calls to JavaScript, allowing chrome code to create custom wrappers (aka membranes) that allow trusted and untrusted code to interoperate.

The source code for this functionality is in wrapper.cpp.

nsJetpack.wrap(object, membrane)

This function wraps object with membrane, meaning that membrane mediates all access to and from object.

membrane should be a JavaScript object with any of the following methods defined:

membrane.resolve(wrappee, membrane, name)
This is essentially a JavaScript wrapper for JSClass.resolve. It's called when the property identified by name doesn't exist on wrappee. The membrane should either define name on wrappee and return wrappee, or—if name doesn't exist—it should return undefined.

unwrap()

getWrapper()

Memory Profiling

nsJetpack contains functionality allowing chrome code to examine the JavaScript heap. The semantics of this are described at a high level in Atul's blog post entitled Fun with SpiderMonkey.

The source code for this functionality is in memory_profiler.cpp.

profileMemory()

Miscellaneous Functions

The source code for this functionality is in tcb.cpp.

functionInfo()

seal()