-
Notifications
You must be signed in to change notification settings - Fork 851
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
Bound functions leak global scope into strict functions #442
Comments
This looks like an important fix. We have integration with test262 in the test suite now via a git submodule -- could you take a quick look and see if there are any tests in there that we could enable (by editing testsrc/test262.properties)? It'd be nice to have an independent test to verify this behavior. |
This is an important fix and the issue isn't (just) tied to BoundFunction imho. Been looking on whether I can fix this issue, and this is where things stand: in interpreted mode, I've got something that improves the implementation. I changed the Token.THIS case in Intepreter.interpretLoop to the following:
What this does is:
I'm wondering what is thought off this approach? I have also tried the approach to intervene at the moment when the topLevel scope is fetched to send it into a
Other that that, there are a lot of different calls to Callable/function.call() throughout the code (and potentially to custom implementations of those interfaces outside the Rhino codebase), so wasn't sure whether going this route could handle things properly in all scenario's. If the basic gist of this approach seems feasible, then any thoughts on how to tackle the issues in the breaking tests? For the breaking For the tests breaking because the returned Undefined.SCRIPTABLE_UNDEFINED isn't a fully implemented Scriptable interface I could add the missing bits, but not sure of the impact of that And then there's the non-interpreted implementation. Haven't wrapped my head around how the whole byteCode generation works, but I did find https://github.com/mozilla/rhino/compare/strict-bind-null which has some, so I might be able to take inspiration from there :-) |
Have also spend some time on this over the last weekend but only with frustrating results. Will focus on #909 for now, maybe this helps also to fix some strict-mode problems. |
Which pitfalls/challenges did you ran into? What's your take on the approach I've taken? |
Just a quick note to thank you @p-bakker for taking a stab at this. I myself have stopped working on this specifically because I didn't have more time to spend on it at the time, and what I thought will be a relatively small and contained fix turned out to cause a lot of breakage (as you yourself have noticed.) I'm willing to provide advice on this if you get stuck, but can't commit to seeing it through myself. I'll circle back to try to understand your changes sometime later. |
Tnx @szegedi I'll report back here if I get stuck or get somewhere. Thought I was close earlier today, but the spec bit me :-) Anyway, I'll fiddle some more and if I get close, I'll create a draft PR If I get things working in interpreted mode, I think I could use your help with the CodeGen part for the non-interpreted implementation. |
My plan was to try to enhance the PR from szegedi - but from the spec i saw that the this handling is something that has to be done in the function before the start. Followed this way and made some progress. But (again) this breaks some tests that are already passing. From my point of view these test are passing at the moment because we use this == null as detection if we are calling the ctor or new. So far i had no idea how to solve this. And yes, i also found it really hard to match the interpreter code to the steps done by the optimizer. |
So, I've been playing around with 2 different approaches. Can share 2 different branches with implementation prototypes, but I want to ask everyone some questions first. basic gist of how the this value is to be handled in strict mode (see The Strict model of JavaScript, bullit 11)
implementation challengesWith that high level overview in mind, below the basic challenges with implementing the non-scriptable
|
I'm not sure if this has anything to do with this issue.
|
That is one of the places where the value for The exact mechanism to resolve the |
@gbrail @rbri @szegedi Any thoughts on #442 (comment)? I'd like to proceed, but don't wanna go down a path that isn't likely to get accepted |
While investigating #238 I noticed that our BoundFunction is replacing null "this" with global too early; it shouldn't be doing that at all (see #238 for relevant ES5 specification citations).
This expression needs to evaluate to true as strict functions aren't allowed to see global scope as their "this" (you can verify with either Nashorn or V8):
Unfortunately, in Rhino it evaluates to false.
The text was updated successfully, but these errors were encountered: