On Oct 3, 5:09*am, RobG <robg...@gmail.com> wrote:
> On Oct 3, 2:28*pm, George <y...@virginia.edu> wrote:
>
> > Hi,
>
> > I am wondering what is the grace way to determine whether an object
> > exists in the current function Call object or not.
>
> Where "exists" has some special meaning to you that you don't explain.
>
> > Namely, how to
> > determine if an object is locally defined or not. For example, in the
> > following script, how to implement the function IsDefinedLocally?
>
> > var x = {a:1};
>
> Here, x is declared globally. Then, when that line of code is
> executed, it is assigned a reference to an object.
>
> > function f() {
> > * var ref;
>
> Here ref is declared as a local variable of the function f.
>
>
>
> > * ref = x;
>
> When f is called, ref is assigned a reference to the same object that
> as was assigned to x.
>
> > * IsDefinedLocally(ref); *//should return false
>
> ref was *declared* locally. Whether the object that it now references
> was fist assigned to a global variable (or one defined in any other
> scope) is impossible to determine. You haven't explained why you want
> to know that.
>
>
>
> > * var loc_obj = {a:1};
> > * ref = loc_obj;
> > * IsDefinedLocally(ref); *//should return true
>
> As above, replacing global with local.
>
>
>
> > }
>
> It would be best to explain what you are trying to do, then it might
> be possible to suggest a solution.
>
> --
> Rob
I'd like to decide the set of live-out objects for a function. An
object is said to be live-out with respect to a function if its value
can be affected by the computation of the function, i.e., the
execution of the function drops side effects to the live-out object.
Certainly, there is another way side effects appear:
var x = 1;
function f() {
var loc_x = 100;
x++; // I would only worry about this update.
loc_x++; // I would not worry about effects confined within the
current Call Object.
}
It seem that what I really need to take care with is the *base* of
every reference (the reference type defined internally for JS in
ECMAScript specs).
Thanks,
Yan Huang
|