зеркало из https://github.com/mozilla/gecko-dev.git
Adjusting examples not to assume that Context.initStandardObjects(ScriptableObject) returns ScriptableObject since that was changed back to Scriptable for compatibility.
This commit is contained in:
Родитель
4c338669a9
Коммит
4da147d828
|
@ -145,8 +145,8 @@ can be used concurrently. <br>
|
|||
<h2>Sealed shared scopes</h2>
|
||||
<p>The ECMAScript standard defines that scripts can add properties to all standard library objects and in many cases it is also possible to change or delete their properties as well. Such behavior may not be suitable with shared scopes since if a script by mistake adds a property to a library object from the shared scope, that object would not be garbage collected until there re active references to the shared scope potentially leading to memory leaks. In addition if a script alters some of the standard objects, the library may not work properly for other scripts. Such bugs are hard to debug and to remove a possibility for them to occur one can use seal the shared scope and all its objects.
|
||||
<p>
|
||||
A notion of a sealed object is a JavaScript extension supported by Rhino and it means that properties can not be added/deleted to the object and the existing object properties can not be changed. Any attempt to modify sealed object throws an exception. To seal all objects in the standard library pass <tt>true</tt> for the sealed argument when calling <tt>Context.initStandardObjects(boolean)</tt>:
|
||||
<pre> ScriptableObject sealedSharedScope = cx.initStandardObjects(true);</pre>
|
||||
A notion of a sealed object is a JavaScript extension supported by Rhino and it means that properties can not be added/deleted to the object and the existing object properties can not be changed. Any attempt to modify sealed object throws an exception. To seal all objects in the standard library pass <tt>true</tt> for the sealed argument when calling <tt>Context.initStandardObjects(ScriptableObject, boolean)</tt>:
|
||||
<pre> ScriptableObject sealedSharedScope = cx.initStandardObjects(null, true);</pre>
|
||||
This seals only all standard library objects, it does not seal the shared scope itself thus after calling <tt>initStandardObjects</tt>, <tt>sealedSharedScope</tt> cab be farther populated with application-specific objects and functions. Then after a custom initialization is done, one can seal the shared scope by calling <tt>ScriptableObject.sealObject()</tt>:
|
||||
<pre> sealedSharedScope.sealObject();</pre>
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public class DynamicScopes {
|
|||
// Initialize the standard objects (Object, Function, etc.)
|
||||
// This must be done before scripts can be executed. The call
|
||||
// returns a new scope that we will share.
|
||||
ScriptableObject scope = cx.initStandardObjects(true);
|
||||
ScriptableObject scope = cx.initStandardObjects(null, true);
|
||||
|
||||
// Now we can evaluate a script and functions will be compiled to
|
||||
// use dynamic scope if the Context is so initialized.
|
||||
|
|
Загрузка…
Ссылка в новой задаче