Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

deps,src: workaround vm.runInContext issue with top level "var" #542

Merged
merged 1 commit into from
May 22, 2018

Conversation

MSLaguana
Copy link
Contributor

addresses #420

ChakraCore doesn't handle global objects in the same way as v8, and
in particular ChakraCore doesn't support all proxy interceptors there.
We attempted to work around this via interceptors in the prototype
chain, but that was an imperfect solution, and a top-level "var"
declaration would end up adding a property to the global object in
a context without going through the interceptors.

To work around this in simple cases, we now take a snapshot of
properties on the global before running in a context, and diff the
changes at the end to patch up changes in the sandbox.

This is NOT a complete solution, and in particular will not work if
there is any sort of asynchronous operation that changes the state
of the global object. It also has behavioral differences if the
global object is writable but the sandbox object is not; in node-v8
this will result in the variable silently not being set in the
context and instead the value from the sandbox being used, while
here we discover the mismatch too late and the new value has been
set on the global.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@MSLaguana MSLaguana requested review from kfarnung and jackhorton May 21, 2018 21:45
@MSLaguana
Copy link
Contributor Author

@MSLaguana
Copy link
Contributor Author

Looks like OSX failed due to running out of disk.

Copy link
Contributor

@sethbrenith sethbrenith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@MSLaguana
Copy link
Contributor Author

Looks like there is a node test test-vm-proxy-failure-CP which explicitly forbids us to call getOwnPropertyDescriptors on the sandbox. I'm inclined to just ignore that test for now.

@MSLaguana
Copy link
Contributor Author

void CacheGlobalProperties();
void ResolveGlobalChanges(JsValueRef sandbox);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return true;
}
utils.afterContext = function (beforeDescriptors, contextGlobal, sandbox) {
try{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing around braces. I think the linter on Windows should have caught it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@MSLaguana MSLaguana force-pushed the vmContextWorkaround branch from e610a21 to e772faf Compare May 21, 2018 23:08
MSLaguana added a commit to MSLaguana/node-chakracore that referenced this pull request May 21, 2018
addresses nodejs#420

ChakraCore doesn't handle global objects in the same way as v8, and
in particular ChakraCore doesn't support all proxy interceptors there.
We attempted to work around this via interceptors in the prototype
chain, but that was an imperfect solution, and a top-level "var"
declaration would end up adding a property to the global object in
a context without going through the interceptors.

To work around this in simple cases, we now take a snapshot of
properties on the global before running in a context, and diff the
changes at the end to patch up changes in the sandbox.

This is NOT a complete solution, and in particular will not work if
there is any sort of asynchronous operation that changes the state
of the global object. It also has behavioral differences if the
global object is writable but the sandbox object is not; in node-v8
this will result in the variable silently not being set in the
context and instead the value from the sandbox being used, while
here we discover the mismatch too late and the new value has been
set on the global.

PR-URL: nodejs#542
Reviewed-By: Seth Brenith <sethb@microsoft.com>
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
addresses nodejs#420

ChakraCore doesn't handle global objects in the same way as v8, and
in particular ChakraCore doesn't support all proxy interceptors there.
We attempted to work around this via interceptors in the prototype
chain, but that was an imperfect solution, and a top-level "var"
declaration would end up adding a property to the global object in
a context without going through the interceptors.

To work around this in simple cases, we now take a snapshot of
properties on the global before running in a context, and diff the
changes at the end to patch up changes in the sandbox.

This is NOT a complete solution, and in particular will not work if
there is any sort of asynchronous operation that changes the state
of the global object. It also has behavioral differences if the
global object is writable but the sandbox object is not; in node-v8
this will result in the variable silently not being set in the
context and instead the value from the sandbox being used, while
here we discover the mismatch too late and the new value has been
set on the global.

PR-URL: nodejs#542
Reviewed-By: Seth Brenith <sethb@microsoft.com>
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
@MSLaguana MSLaguana force-pushed the vmContextWorkaround branch from e772faf to e7643d2 Compare May 21, 2018 23:13
@MSLaguana MSLaguana merged commit e7643d2 into nodejs:master May 22, 2018
@MSLaguana MSLaguana deleted the vmContextWorkaround branch May 22, 2018 00:19
kfarnung pushed a commit to kfarnung/node-chakracore that referenced this pull request May 22, 2018
addresses nodejs#420

ChakraCore doesn't handle global objects in the same way as v8, and
in particular ChakraCore doesn't support all proxy interceptors there.
We attempted to work around this via interceptors in the prototype
chain, but that was an imperfect solution, and a top-level "var"
declaration would end up adding a property to the global object in
a context without going through the interceptors.

To work around this in simple cases, we now take a snapshot of
properties on the global before running in a context, and diff the
changes at the end to patch up changes in the sandbox.

This is NOT a complete solution, and in particular will not work if
there is any sort of asynchronous operation that changes the state
of the global object. It also has behavioral differences if the
global object is writable but the sandbox object is not; in node-v8
this will result in the variable silently not being set in the
context and instead the value from the sandbox being used, while
here we discover the mismatch too late and the new value has been
set on the global.

PR-URL: nodejs#542
Reviewed-By: Seth Brenith <sethb@microsoft.com>
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
kfarnung pushed a commit to kfarnung/node-chakracore that referenced this pull request May 22, 2018
addresses nodejs#420

ChakraCore doesn't handle global objects in the same way as v8, and
in particular ChakraCore doesn't support all proxy interceptors there.
We attempted to work around this via interceptors in the prototype
chain, but that was an imperfect solution, and a top-level "var"
declaration would end up adding a property to the global object in
a context without going through the interceptors.

To work around this in simple cases, we now take a snapshot of
properties on the global before running in a context, and diff the
changes at the end to patch up changes in the sandbox.

This is NOT a complete solution, and in particular will not work if
there is any sort of asynchronous operation that changes the state
of the global object. It also has behavioral differences if the
global object is writable but the sandbox object is not; in node-v8
this will result in the variable silently not being set in the
context and instead the value from the sandbox being used, while
here we discover the mismatch too late and the new value has been
set on the global.

PR-URL: nodejs#542
Reviewed-By: Seth Brenith <sethb@microsoft.com>
Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
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.

4 participants