Think of a scope as just a bucket of variables and objects. When a script is
executing any reference to a variable, or any function that is called is
looked up in this bucket, aka "the scope".
A visual example:
MyScope contains:
var a
object b
Etc...
If a script is executing and has the statement:
a=5;
The variable a is looked up in the scope that the script is currently
executing against. In this case the script above is executing against the
scope "MyScope".
Keep in mind that a context does the work of executing the script, but the
context has no state by its self, all of the state is stored in the scope.
You are able to run multiple scripts in the same scope, thus the script
share the same variables. Presumably many applications will execute one
script at a time within a scope, and perhaps only one script will ever run
in one scope, making this point irrelevant for many applications. But it is
perfectly legal to execute two script simultaneously using the same scope.
This would mean that all variables are shared by both scripts.
Thus the statement really has the same meaning as it would have in the
context of concurrent java programming in which two threads sharing
variables must consider synchronization when accessing shared data. If two
script are executing concurrently using a shared scope (aka a shared set of
variables), and both might perform, for example, a read-then-update
operation on a shared variable, you are responsible for dealing with the
proper synchronization of that operation.
Hope that helps.
David
-----Original Message-----
From:
dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozilla.org
[mailto:dev-tech-js-engine-rhino-bounces+davidparks21=yahoo....@lists.mozill
a.org] On Behalf Of Caesar You
Sent: Sunday, March 15, 2009 7:15 AM
To: [email protected]
Subject: a question of contexts and scopes
Hi, everybody.
i am a newer of Rhino.
today i am learning an article "Contexts and
Scopes"(https://developer.mozilla.org/En/Rhino_documentation/Scopes_and_Cont
exts),
and i am not very sure about a sentence, it says:
"Rhino guarantees that accesses to properties of JavaScript objects are
atomic across threads, but doesn't make any more guarantees for scripts
executing in the same scope at the same time. If two scripts use the same
scope simultaneously, the scripts are responsible for coordinating any
accesses to shared variables."
can anybody explain it for me?
thanks!
[email protected]
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino