-
Notifications
You must be signed in to change notification settings - Fork 30k
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: accessor properties get converted to data properties inside the vm #2734
Comments
I have an issue that may be related : function Window() {
this.Window = Window;
this.console = console;
}
var w = new Window();
var vm = require("vm");
vm.createContext(w);
vm.runInContext('console.log(this instanceof Window);', w); gives
|
This commit adds tests for several known issues. Refs: nodejs#1901 Refs: nodejs#728 Refs: nodejs#4778 Refs: nodejs#947 Refs: nodejs#2734 PR-URL: nodejs#5653 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
This commit adds tests for several known issues. Refs: #1901 Refs: #728 Refs: #4778 Refs: #947 Refs: #2734 PR-URL: #5653 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
This commit adds tests for several known issues. Refs: #1901 Refs: #728 Refs: #4778 Refs: #947 Refs: #2734 PR-URL: #5653 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
This commit adds tests for several known issues. Refs: #1901 Refs: #728 Refs: #4778 Refs: #947 Refs: #2734 PR-URL: #5653 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
This commit adds tests for several known issues. Refs: #1901 Refs: #728 Refs: #4778 Refs: #947 Refs: #2734 PR-URL: #5653 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
I don't know about other contexts, but the problem only appears to occur for me when the accessor is on the vm's global. This code (which adds an intervening 'use strict';
const vm = require('vm');
const x = {};
Object.defineProperty(x, 'prop', {
get() { return 'foo'; }
});
const o = vm.createContext({parent: x});
const code = 'Object.getOwnPropertyDescriptor(parent, "prop")';
const res = vm.runInContext(code, o, 'test');
console.log(res); which logs: { get: [Function: get],
set: undefined,
enumerable: false,
configurable: false } |
Should this remain open? (I'm guessing the answer is "yes" but I'd be happy to find out I'm wrong.) |
In fact, we should take another look at this issue now that v8/v8@b0a7738 has been committed. |
Fixes: nodejs#2734 Fixes: nodejs#5350 Fixes: nodejs#5679
Remove the CopyProperties() hack in the vm module, i.e., Contextify. Use different V8 API methods, that allow interception of DefineProperty() and do not flatten accessor descriptors to property descriptors. Move many known issues to test cases. Factor out the last test in test-vm-context.js for nodejs#10223 into its own file, test-vm-strict-assign.js. Part of this CL is taken from a stalled PR by https://github.com/AnnaMag nodejs#13265 This PR requires a backport of https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f Refs: nodejs#6283 Refs: nodejs#15114 Refs: nodejs#13265 Fixes: nodejs#2734 Fixes: nodejs#10223 Fixes: nodejs#11803 Fixes: nodejs#11902
Remove the CopyProperties() hack in the vm module, i.e., Contextify. Use different V8 API methods, that allow interception of DefineProperty() and do not flatten accessor descriptors to property descriptors. Move many known issues to test cases. Factor out the last test in test-vm-context.js for nodejs/node#10223 into its own file, test-vm-strict-assign.js. Part of this CL is taken from a stalled PR by https://github.com/AnnaMag nodejs/node#13265 This PR requires a backport of https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f PR-URL: nodejs/node#16293 Fixes: nodejs/node#2734 Fixes: nodejs/node#10223 Fixes: nodejs/node#11803 Fixes: nodejs/node#11902 Ref: nodejs/node#6283 Ref: nodejs/node#15114 Ref: nodejs/node#13265 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Remove the CopyProperties() hack in the vm module, i.e., Contextify. Use different V8 API methods, that allow interception of DefineProperty() and do not flatten accessor descriptors to property descriptors. Move many known issues to test cases. Factor out the last test in test-vm-context.js for nodejs/node#10223 into its own file, test-vm-strict-assign.js. Part of this CL is taken from a stalled PR by https://github.com/AnnaMag nodejs/node#13265 This PR requires a backport of https://chromium.googlesource.com/v8/v8/+/37a3a15c3e52e2146e45f41c427f24414e4d7f6f PR-URL: nodejs/node#16293 Fixes: nodejs/node#2734 Fixes: nodejs/node#10223 Fixes: nodejs/node#11803 Fixes: nodejs/node#11902 Ref: nodejs/node#6283 Ref: nodejs/node#15114 Ref: nodejs/node#13265 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Example:
gives
In 659dadd I fixed it to return the correct data descriptor. But it appears the accessor descriptor is just broken.
As far as I can tell this is a shortcoming of the V8 API. The named properties handler and the GlobalPropertyQueryCallback always returns data descriptors. This is probably because that is all that is required by Web IDL for the browser use case, where the named property handler is meant to be used for things like
window.idOrName
orwindow.forms.foo
, which are always data descriptors.I think Chrome also has this problem. Even for non-named properties, things like
window.top
are data descriptors. I'm asking related questions on blink-dev.Original discovery: jsdom/jsdom#1208, where this is affecting Facebook's use in jest.
/cc @nodejs/v8
The text was updated successfully, but these errors were encountered: