Declared global variables treated as undefined #11

Merged
merged 2 commits into from Dec 13, 2011

Projects

None yet

2 participants

@assaf
Contributor
assaf commented Dec 13, 2011

In JavaScript, this results in an ReferenceError: y is not defined:

x = y

OTOH a variable declared with no value is set to undefined, and so this sets x to undefined:

var y
x = y

This pull requests provides two tests, one with a sandbox property (x) set to undefined and one with a global variable (z) declared as undefined.

This seems to fix the first test, by returning the sandbox property if defined, regardless of value:

Local<Value> rv = sandbox->Get(property);
if (sandbox->HasRealNamedProperty(property))
    return scope.Close(rv);

// Next, check the global object (things like Object, Array, etc).
// This needs to call GetRealNamedProperty or else we'll get stuck in
// an infinite loop here.
rv = info->global->GetRealNamedProperty(property);

I am not sure if this is correct, or how to go about fixing the second test.

@brianmcd brianmcd added a commit that referenced this pull request Dec 13, 2011
@brianmcd Updated test for #11. c6e9785
@brianmcd brianmcd added a commit that referenced this pull request Dec 13, 2011
@brianmcd Fix for #11 - Declared global variables treated as undefined
2 parts to this fix:
    1. Needed a proper NamedPropertyQuery interceptor, which must return
       an empty handle if the queried property is not intercepted.
    2. In Getter, when checking sandbox, we must call
       HasRealNamedProperty to make sure we don't miss properties that
       have been declared but not defined.
d497b61
@brianmcd brianmcd added a commit that referenced this pull request Dec 13, 2011
@brianmcd Follow up fix for #11.
HasRealNamedProperty doesn't check the prototype chain, so we have to
traverse it manually when looking for sandbox properties.
6f1d52c
@brianmcd brianmcd added a commit that referenced this pull request Dec 13, 2011
@brianmcd Follow up fix for #11
Actually, we can just use GetRealNamedProperty, which does check the
prototype chain.  It returns an empty handle if the property wasn't
found.
4abc7b3
@brianmcd brianmcd merged commit ca986f9 into brianmcd:master Dec 13, 2011
@brianmcd
Owner

Thanks for the tests and the detailed report. I merged the tests in and I think I fixed the issue. If it looks good to you, I'll push a new release to npm. I tried running the Zombie (with the pending test activated) and JSDOM test suites with these fixes, and everything seems normal.

Thanks again for digging into this.

@assaf
Contributor
assaf commented Dec 13, 2011

Sweet. Works like a charm!

@brianmcd
Owner

I just pushed version 0.0.7 to npm. Thanks for your help on this!

@assaf
Contributor
assaf commented Dec 13, 2011

And Zombie 0.12.3 is out. Thank you so much for making that possible.

On Tuesday, December 13, 2011 at 10:47 AM, Brian McDaniel wrote:

I just pushed version 0.0.7 to npm. Thanks for your help on this!


Reply to this email directly or view it on GitHub:
#11 (comment)

@brianmcd
Owner

Glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment