Skip to content

Commit

Permalink
Fixes #3554 (#15870)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Dec 19, 2024
1 parent 42f23f0 commit 10990f5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions scripts/check-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
i=0
j=0

export BUN_DEBUG_QUIET_LOGS=1
export NO_COLOR=1

for x in $(git ls-files test/js/node/test/parallel --exclude-standard --others | grep test-$1)
do
i=$((i+1))
Expand Down
3 changes: 2 additions & 1 deletion src/bun.js/bindings/NodeVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ NodeVMGlobalObject* NodeVMGlobalObject::create(JSC::VM& vm, JSC::Structure* stru

Structure* NodeVMGlobalObject::createStructure(JSC::VM& vm, JSC::JSValue prototype)
{
return JSC::Structure::create(vm, nullptr, prototype, JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags), info());
// ~IsImmutablePrototypeExoticObject is necessary for JSDOM to work (it relies on __proto__ = on the GlobalObject).
return JSC::Structure::create(vm, nullptr, prototype, JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags & ~IsImmutablePrototypeExoticObject), info());
}

void NodeVMGlobalObject::finishCreation(JSC::VM&)
Expand Down
Binary file modified test/bun.lockb
Binary file not shown.
14 changes: 14 additions & 0 deletions test/integration/jsdom/jsdom.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test, expect, describe } from "bun:test";
import { JSDOM } from "jsdom";

describe("jsdom", () => {
for (const runScripts of ["dangerously", "outside-only", undefined]) {
test(`runScripts: ${runScripts}`, () => {
const dom = new JSDOM(`<!DOCTYPE html><html><body><h1>Hello World!</h1></body></html>`, {
url: "https://example.com",
runScripts,
});
expect(dom.window.document.querySelector("h1").textContent).toBe("Hello World!");
});
}
});
13 changes: 13 additions & 0 deletions test/js/node/test/parallel/test-vm-set-proto-null-on-globalthis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
require('../common');

// Setting __proto__ on vm context's globalThis should not cause a crash
// Regression test for https://github.com/nodejs/node/issues/47798

const vm = require('vm');
const context = vm.createContext();

const contextGlobalThis = vm.runInContext('this', context);

// Should not crash.
contextGlobalThis.__proto__ = null; // eslint-disable-line no-proto
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"isbot": "5.1.13",
"jest-extended": "4.0.0",
"jimp": "1.6.0",
"jsdom": "25.0.1",
"jsonwebtoken": "9.0.2",
"jws": "4.0.0",
"lodash": "4.17.21",
Expand Down

0 comments on commit 10990f5

Please sign in to comment.