Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Declared global variables treated as undefined #11

Merged
merged 2 commits into from
Dec 13, 2011
Merged

Declared global variables treated as undefined #11

merged 2 commits into from
Dec 13, 2011

Conversation

assaf
Copy link
Contributor

@assaf 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 added a commit that referenced this pull request Dec 13, 2011
brianmcd added a commit that referenced this pull request Dec 13, 2011
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.
brianmcd added a commit that referenced this pull request Dec 13, 2011
HasRealNamedProperty doesn't check the prototype chain, so we have to
traverse it manually when looking for sandbox properties.
brianmcd added a commit that referenced this pull request Dec 13, 2011
Actually, we can just use GetRealNamedProperty, which does check the
prototype chain.  It returns an empty handle if the property wasn't
found.
@brianmcd brianmcd merged commit ca986f9 into brianmcd:master Dec 13, 2011
@brianmcd
Copy link
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
Copy link
Contributor Author

assaf commented Dec 13, 2011

Sweet. Works like a charm!

@brianmcd
Copy link
Owner

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

@assaf
Copy link
Contributor Author

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
Copy link
Owner

Glad to help!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants