-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: regression for "in" operator on global between 22.4.1 and 22.5.0; breaks jsdom #54436
Comments
Can you strip your example to just the basics? Something very small that will reproduce this? |
I've already done so. It's 30 lines with no external dependencies. The issue is specifically about class hierarchies, inherited methods, and subclassing so it's not like it can get any smaller. Maybe I could remove |
You are correct, I was trying to oversimplify the code, but that's not needed. Sorry for the mistake. When I get a chance I'll check this for |
FWIW the only vm subsystem PR for that version is #53517 |
Maybe c0962dc @legendecas ? |
I can confirm the issue. Will prepare a fix soon. |
Due to a Node.js v22 vm issue (nodejs/node#54436), some subtests are failing that should pass, and some passing that should fail. Instead of trying to add per-subtest per-Node-version disable/enable functionality, let's just mark the whole test as failing for now, leaving the intended subtests in commented out.
I think the best course of this issue would be setting the prototype of the inner
If I understand correctly, the expected class hierarchy should be:
With the fix in #53517, the inner To fix the issue and preserving the correct
Since "use strict";
const vm = require("vm");
class EventTarget {
addEventListener() {}
}
const windowConstructor = function () {};
Object.setPrototypeOf(windowConstructor, EventTarget);
const windowPrototype = Object.create(EventTarget.prototype);
function Window() {
vm.createContext(this);
this._globalProxy = vm.runInContext("this", this);
// Set up the inner global prototype
Object.setPrototypeOf(this._globalProxy, windowPrototype);
const window = this;
Object.defineProperty(this, "window", {
get() {
return window._globalProxy;
},
enumerable: true,
configurable: true
});
}
const window = new Window();
console.log(vm.runInContext(`"addEventListener" in window`, window)); In this way, the following snippet will output the expected results: const jsdom = require('jsdom');
const vm = require('vm');
const { JSDOM } = jsdom;
const dom = new JSDOM(``, {
runScripts: 'outside-only',
});
const vmContext = dom.getInternalVMContext();
// Uncomment the following line to see the difference.
// vm.runInContext(`Object.setPrototypeOf(window, Window.prototype)`, vmContext);
console.log(vm.runInContext(`window instanceof Object`, vmContext)); // => always `false` because the window was created outside the context
console.log(vm.runInContext(`window instanceof EventTarget`, vmContext));
console.log(vm.runInContext(`'addEventListener' in window`, vmContext));
console.log(vm.runInContext(`Object.hasOwn(window, 'addEventListener')`, vmContext));
console.log(vm.runInContext(`Object.getOwnPropertyDescriptor(window, 'addEventListener')`, vmContext)); The output should be in Node.js
|
I can try such things, but from past experience anything other than our current (admittedly convoluted) setup has caused lots of tests to break. I would expect that anything that causes a regression like this to be reverted... |
Given how many other things this appears to fix, I'm happy to close this. In fact, I would wonder if it's possible to back-port c0962dc to v20, so that I could land jsdom/jsdom#3765 without having to wait for v22 to become the earliest LTS... |
I removed https://github.com/nodejs/node/labels/dont-land-on-v20.x on the original PR and it can be backported in the next release. |
Add more test coverage on vm prototype properties lookup with `in` operator and property access. PR-URL: nodejs#54606 Refs: nodejs#54436 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Add more test coverage on vm prototype properties lookup with `in` operator and property access. PR-URL: nodejs#54606 Refs: nodejs#54436 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Version
v22.5.0
Platform
Subsystem
vm
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Every time
What is the expected behavior? Why is that the expected behavior?
Outputs true. (That occurs on v22.4.1.)
What do you see instead?
Outputs false
Additional information
No response
The text was updated successfully, but these errors were encountered: