Skip to content

Commit

Permalink
Setup Window prototype in vm context
Browse files Browse the repository at this point in the history
This includes a revert of commit 98c38d3. The new version works on both the latest Node versions and the older ones.

This also introduces the intermediate WindowProperties object, although we don't properly put the named properties there yet.
  • Loading branch information
legendecas authored Aug 24, 2024
1 parent 98c38d3 commit 439a43e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 31 deletions.
14 changes: 13 additions & 1 deletion lib/jsdom/browser/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ function setupWindow(windowInstance, { runScripts }) {
value: windowConstructor
});

const windowPrototype = Object.create(EventTargetConstructor.prototype);
const windowProperties = Object.create(EventTargetConstructor.prototype);
Object.defineProperties(windowProperties, {
[Symbol.toStringTag]: {
value: "WindowProperties",
configurable: true
}
});

const windowPrototype = Object.create(windowProperties);
Object.defineProperties(windowPrototype, {
constructor: {
value: windowConstructor,
Expand All @@ -148,6 +156,10 @@ function setupWindow(windowInstance, { runScripts }) {

windowConstructor.prototype = windowPrototype;
Object.setPrototypeOf(windowInstance, windowPrototype);
if (runScripts === "outside-only" || runScripts === "dangerously") {
const global = vm.runInContext("this", windowInstance);
Object.setPrototypeOf(global, windowPrototype);
}

EventTarget.setup(windowInstance, windowInstance);
mixin(windowInstance, WindowEventHandlersImpl.prototype);
Expand Down
3 changes: 2 additions & 1 deletion test/web-platform-tests/run-wpts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const { resolveReason, killSubprocess } = require("./utils.js");

const validInnerReasons = new Set([
"fail",
"fail-with-canvas"
"fail-with-canvas",
"fail-lt-node22"
]);

const validReasons = new Set([
Expand Down
52 changes: 25 additions & 27 deletions test/web-platform-tests/to-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -750,40 +750,38 @@ window-open-noreferrer.html: [fail, Depends on BroadcastChannel]
window-open-popup-behavior.html: [fail, Depends on BroadcastChannel]
window-open-windowfeatures-values.html: [fail, Depends on BroadcastChannel]
window-opener-unconfigurable.window.html: [fail, Not implemented]
window-properties.https.html: [fail, Incorrectly implemented or not implemented]
#"Window attribute: name": [fail, Incorrectly implemented as a data property]
#"Window attribute: onmousewheel": [fail, Not implemented]
#"Window attribute: onmove": [fail, Unknown]
#"Window attribute: opener": [fail, Not implemented]
#"Window attribute: status": [fail, Incorrectly implemented as a data property]
#"Window method: createImageBitmap": [fail, Not implemented]
#"Window method: matchMedia": [fail, Not implemented]
#"Window readonly attribute: applicationCache": [fail, Not implemented]
#"Window replaceable attribute: devicePixelRatio": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: innerHeight": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: innerWidth": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: outerHeight": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: outerWidth": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: pageXOffset": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: pageYOffset": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: screenLeft": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: screenTop": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: screenX": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: screenY": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: scrollX": [fail, Incorrectly implemented as a data property]
#"Window replaceable attribute: scrollY": [fail, Incorrectly implemented as a data property]
#"constructor": [fail, Unknown]
window-properties.https.html:
"Window attribute: name": [fail, Incorrectly implemented as a data property]
"Window attribute: onmousewheel": [fail, Not implemented]
"Window attribute: onmove": [fail, Unknown]
"Window attribute: opener": [fail, Not implemented]
"Window attribute: status": [fail, Incorrectly implemented as a data property]
"Window method: createImageBitmap": [fail, Not implemented]
"Window method: matchMedia": [fail, Not implemented]
"Window readonly attribute: applicationCache": [fail, Not implemented]
"Window replaceable attribute: devicePixelRatio": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: innerHeight": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: innerWidth": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: outerHeight": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: outerWidth": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: pageXOffset": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: pageYOffset": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: screenLeft": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: screenTop": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: screenX": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: screenY": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: scrollX": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: scrollY": [fail, Incorrectly implemented as a data property]
"constructor": [fail-lt-node22, Incorrectly implemented VM global prototype properties]
window-prototype-chain.html:
"Window.prototype": [fail, Unknown]
"Global scope polluter": [fail, Depends on the named properties object]
"EventTarget.prototype": [fail, Depends on the named properties object]
"Object.prototype": [fail, Depends on the named properties object]
"Object.prototype": [fail, Tests Object.prototype which jsdom has trouble with due to VM globals]
window-reuse-in-nested-browsing-contexts.tentative.html:
"synchronously navigate iframe with no initial src.": [fail, Unknown]
"after the first iframe load event, navigate iframe with no initial src.": [fail, Unknown]
'synchronously navigate iframe with initial src == "".': [fail, Unknown]
'synchronously navigate iframe with initial src == "about:blank".': [fail, Unknown]


---

DIR: html/browsers/the-windowproxy-exotic-object
Expand Down
8 changes: 6 additions & 2 deletions test/web-platform-tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { Canvas } = require("../../lib/jsdom/utils.js");

const hasCanvas = Boolean(Canvas);

const nodeMajorVersion = process.versions.node.split(".")[0];
const nodeMajorVersion = Number.parseInt(process.versions.node.split(".")[0]);

exports.resolveReason = reason => {
if (["fail-slow", "timeout", "flaky"].includes(reason)) {
Expand All @@ -18,10 +18,14 @@ exports.resolveReason = reason => {
return "skip";
}

if (reason === "fail-node18" && nodeMajorVersion === "18") {
if (reason === "fail-node18" && nodeMajorVersion === 18) {
return "skip";
}

if (reason === "fail-lt-node22" && nodeMajorVersion < 22) {
return "expect-fail";
}

if (reason === "fail" ||
(reason === "fail-with-canvas" && hasCanvas)) {
return "expect-fail";
Expand Down

0 comments on commit 439a43e

Please sign in to comment.