-
Notifications
You must be signed in to change notification settings - Fork 857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix missing scope definition at some places #1227
Conversation
LGTM |
Thanks! Looking good for now. However, I felt that using var f = function() {};
f.prototype.__parent__; // null before fix, [object global] after
f.prototype.__parent__ = null;
Object.getOwnPropertyDescriptor(f.prototype, 'constructor').hasOwnProperty('value'); // TypeError This Pull Request is correct and necessary, but it may be better not to use |
@tuchida Not sure i got your point - do you talk about
inside setupDefaultPrototype()? |
This approach also seems to solve the problem. diff --git a/src/org/mozilla/javascript/ScriptableObject.java b/src/org/mozilla/javascript/ScriptableObject.java
index 46e5aaeb..f1f45a24 100644
--- a/src/org/mozilla/javascript/ScriptableObject.java
+++ b/src/org/mozilla/javascript/ScriptableObject.java
@@ -2651,8 +2651,7 @@ public abstract class ScriptableObject
protected ScriptableObject getOwnPropertyDescriptor(Context cx, Object id) {
Slot slot = querySlot(cx, id);
if (slot == null) return null;
- Scriptable scope = getParentScope();
- return slot.getPropertyDescriptor(cx, (scope == null ? this : scope));
+ return slot.getPropertyDescriptor(cx, cx.topCallScope);
}
protected Slot querySlot(Context cx, Object id) { |
@tuchida ok, is see, will test and add a commit |
If we're deriving the scope from the context, there's not much point in passing it into slot getPropertyas we're also passing in context, no? But are we 100% sure that it is always correct to read the top level scope from the context and not derive it from the Scriptable? |
Have seen this but i was not sure if we should stay with the signature for backward compatibility.
Had the same question in mind but as long we have no test case that proves this i think both solutions are correct - so i did the commit because the code is simpler (from my point of view). |
The testcases might be in test262, but not enabled/failing as we're missing part of the required testing infrastructure, see #1077 In the browser I can test the cross-realm scripting using iframes:
The above 'testcase' indicates (I think) that in EcmaScript the lookup of the instance of Object to use for creating for example property descriptors should be based not on the Object instance of the current realm, but on scope in which the object is created on which the getOwnPropertyDescriptor method is called. The following code with Rhino behaves differently when using cx.topCallScope vs. using the scriptable as scope:
|
Created a (draft) PR for adding the missing infr, see #1229 |
added test case from p-bakker
The codechange that @tuchida proposed in #1227 (comment) (using |
I think we really have to squash the commits for this pr :-> |
LGTM now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for me as well. Thanks for tracking this down!
next try to fix #934 (this replaces #1226)