Labs/Jetpack/JEP/25: Difference between revisions

→‎XULRunner extension, in a JS module: culled unnecessary comments
("securable-module.js" -> "booster.js")
(→‎XULRunner extension, in a JS module: culled unnecessary comments)
Line 75: Line 75:


<pre class="brush:js;">
<pre class="brush:js;">
// The same file we loaded in-page in the last example can actually be
// loaded as a JS module, too:
var SecurableModule = {};
var SecurableModule = {};
Components.utils.import("resource://some_extension/content/booster.js",
Components.utils.import("resource://some_extension/content/booster.js",
                         SecurableModule);
                         SecurableModule);


// Create a loader for SecurableModules that gives them chrome
// privileges by default and roots the filesystem at
// chrome://some_extension/content/lib/. We can't provide a
// relative directory name here because JS modules don't conventionally
// have a concept of relative directories (and we won't introduce such
// a concept here to reduce potential confusion).
var loader = SecurableModule.Loader({
var loader = SecurableModule.Loader({
   defaultPrincipal: "system",
   defaultPrincipal: "system",
Line 92: Line 84:
});
});


// Load the 'foo' SecurableModule and call its exported doSomething()
// function.
loader.require('blarg').doSomething();
loader.require('blarg').doSomething();
</pre>
</pre>


Note that while we could unload the module if we want, we don't really
Note that unlike the previous example, we can't provide a relative directory name for <tt>rootPath</tt> because JS modules don't conventionally have a concept of relative directories (and we won't introduce such a concept here to reduce potential confusion).
 
Note also that while we could unload the module if we want, we don't really
have any pressing reason to, since JS modules themselves are never
have any pressing reason to, since JS modules themselves are never
unloaded.
unloaded.
874

edits