Labs/Jetpack/JEP/28: Difference between revisions

→‎Modules: Added docs on Loader.runScript().
(→‎Modules: documented securable-module.Loader)
(→‎Modules: Added docs on Loader.runScript().)
Line 141: Line 141:


The implementation of this module is actually the same implementation underlying Cuddlefish itself; for more information, see [[Labs/Jetpack/JEP/25|JEP 25]].
The implementation of this module is actually the same implementation underlying Cuddlefish itself; for more information, see [[Labs/Jetpack/JEP/25|JEP 25]].
==== Loader Objects ====
Loader objects encapsulate the sandboxed loading of SecurableModules and the execution of code that relies upon them.
<tt>Loader.'''runScript'''(''options'')</tt>
Runs JavaScript code in the context of the Loader.  ''options'' is an object with the following keys:
{|cellpadding="5" cellspacing="0" border="1" width="100%"
|<tt>contents</tt>
|A string of JavaScript code.
|-
|<tt>filename</tt>
|An absolute URL naming the file from which the code originates; useful for error reporting and debugging. If omitted, this option defaults to <tt>"&lt;string&gt;"</tt>.
|-
|<tt>lineNo</tt>
|An integer representing the line from the file which the beginning of the code corresponds to. If ommitted, this option defaults to <tt>1</tt>.
|-
|<tt>jsVersion</tt>
|A string representing the JavaScript version that the code should be interpreted under. If omitted, this options defaults to the latest version of JavaScript supported by the platform.
|}
This method returns the most recent value evaluated by the given code.
<tt>Loader.'''runScript'''(''code'')</tt>
If ''code'' is a string of JavaScript code, this is a convenient shorthand for <tt>Loader.runScript({contents: code}}</tt>.
==== Functions ====


<tt>securable-module.'''Loader'''(''options'')</tt>
<tt>securable-module.'''Loader'''(''options'')</tt>


Creates a new SecurableModule loader. ''options'' is an object with any of the following keys:
Creates a new SecurableModule Loader. ''options'' is an object with the following keys:


{|cellpadding="5" cellspacing="0" border="1" width="100%"
{|cellpadding="5" cellspacing="0" border="1" width="100%"
|<tt>rootPaths</tt>
|<tt>rootPaths</tt>
|A list of absolute URLs that will be searched, in order, for SecurableModules when <tt>require()</tt> is called by any code executing within the context of the loader.
|A list of absolute URLs that will be searched, in order, for SecurableModules when <tt>require()</tt> is called by any code executing within the context of the Loader.
|-
|-
|<tt>rootPath</tt>
|<tt>rootPath</tt>
Line 154: Line 184:
|-
|-
|<tt>defaultPrincipal</tt>
|<tt>defaultPrincipal</tt>
|A string representing the default principal given to any code that is executed by the loader. This can be <tt>"system"</tt>, in which case code executed has full chrome access (including access to the <tt>Components</tt> object which allows it to access the Mozilla platform unrestricted). Alternatively, it can be a URL, such as <tt><nowiki>"http://www.foo.com"</nowiki></tt>, in which case it is treated like web content. If left unspecified, the default value of this option is <tt><nowiki>"http://www.mozilla.org"</nowiki></tt>.
|A string representing the default principal given to any code that is executed by the Loader. This can be <tt>"system"</tt>, in which case code executed has full chrome access (including access to the <tt>Components</tt> object which allows it to access the Mozilla platform unrestricted). Alternatively, it can be a URL, such as <tt><nowiki>"http://www.foo.com"</nowiki></tt>, in which case it is treated like web content. If left unspecified, the default value of this option is <tt><nowiki>"http://www.mozilla.org"</nowiki></tt>.
|-
|-
|<tt>globals</tt>
|<tt>globals</tt>
|An object containing the names and values of all variables that will be injected into the global scope of all code executed by the loader.
|An object containing the names and values of all variables that will be injected into the global scope of all code executed by the Loader.
|}
|}


874

edits