-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
VM: weird behaviour in runInContext/runInThisContext #5344
Comments
I can confirm the bug but I suspect it's a V8 issue - it calls the global object's named property handlers (specifically the |
Still happens with V8 4.10.253 and 5.0.48. I'll see if I can put a standalone test case together for upstream to take a look at. |
I talked to my colleagues. V8 seems to be working as intended in this case. I assume that there is an interceptor on the global object installed by node. The interceptor probably stores the value onto the global object, but returns false, signalling that it did not intercept. V8 then attempts to store and throws due to strict mode. So the interceptor should either not store and return false, or throw if v8::PropertyCallbackInfo::ShouldThrowOnError() returns true. |
@hashseed Yang, thanks for chiming in. Is there anything we can do with 4.6 and 4.8? They don't have the The best I've been able to come up with is to sniff the script for a Local<Object> sandbox = /* ... */;
if (!strict() || sandbox->Has(property)) {
sandbox->Set(property, value);
info.GetReturnValue().Set(value);
} |
Would this work for you? Whenever the interceptor is going to do a normal store, it does not store and returns false. V8 will then do the store, unless strict mode causes an exception before that. |
@bnoordhuis If the property is newly created, neither the sandbox object nor the global object will have the property defined on them when |
the global object will fail because we are in strict mode. Function declarations should not throw, we expect that they are not set when we define them, so copy them over! Add test for setting variable in strict mode for issue nodejs#5344.
In vm, the setter interceptor should not copy a value onto the sandbox, if setting it on the global object will fail. It will fail if we are in strict mode and set a value without declaring it. Fixes nodejs#5344
In vm, the setter interceptor should not copy a value onto the sandbox, if setting it on the global object will fail. It will fail if we are in strict mode and set a value without declaring it. Fixes: #5344 PR-URL: #7908 Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
The possible bug behind this "#5344" seems to be fixed now. |
I'm still experiencing weirdness with a slightly modified version of this test case:
results in:
|
This does seem to be happening still, even on current master. Thoughts @nodejs/v8? |
Moved to #12300 so it has its own bug number. It's related but separate. |
While working on my electron based REPL application, I noticed a weird behaviour in
vm.runInContext
.Program
Output
Behaviour
vm.runInThisContext
/vm.runInContext
throws error. ✅var
orlet
binding ❌Versions
Tested versions:
v5.6.0
&v5.1.1
Platform
Subsystem
vm
repl
withstrict
is affected by this issue.The text was updated successfully, but these errors were encountered: