Skip to content

Commit

Permalink
Fixes #16277 (#16280)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Jan 9, 2025
1 parent 313bf86 commit 5e003dc
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/bun.js/bindings/ErrorStackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,18 +630,23 @@ String sourceURL(const JSC::SourceCode& sourceCode)
return sourceURL(sourceCode.provider());
}

String sourceURL(JSC::CodeBlock* codeBlock)
String sourceURL(JSC::CodeBlock& codeBlock)
{
if (UNLIKELY(!codeBlock)) {
if (!codeBlock.ownerExecutable()) {
return String();
}

if (!codeBlock->ownerExecutable()) {
const auto& source = codeBlock.source();
return sourceURL(source);
}

String sourceURL(JSC::CodeBlock* codeBlock)
{
if (UNLIKELY(!codeBlock)) {
return String();
}

const auto& source = codeBlock->source();
return sourceURL(source);
return Zig::sourceURL(*codeBlock);
}

String sourceURL(JSC::VM& vm, const JSC::StackFrame& frame)
Expand All @@ -650,7 +655,7 @@ String sourceURL(JSC::VM& vm, const JSC::StackFrame& frame)
return "[wasm code]"_s;
}

if (UNLIKELY(!frame.codeBlock())) {
if (UNLIKELY(!frame.hasLineAndColumnInfo())) {
return "[native code]"_s;
}

Expand Down Expand Up @@ -833,7 +838,8 @@ String functionName(JSC::VM& vm, JSC::JSGlobalObject* lexicalGlobalObject, const
return functionName;
}

if (auto codeblock = frame.codeBlock()) {
if (frame.hasLineAndColumnInfo()) {
auto* codeblock = frame.codeBlock();
if (codeblock->isConstructor()) {
isConstructor = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/ErrorStackTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ String sourceURL(const JSC::SourceOrigin& origin);
String sourceURL(JSC::SourceProvider* sourceProvider);
String sourceURL(const JSC::SourceCode& sourceCode);
String sourceURL(JSC::CodeBlock* codeBlock);
String sourceURL(JSC::CodeBlock& codeBlock);
String sourceURL(JSC::VM& vm, const JSC::StackFrame& frame);
String sourceURL(JSC::StackVisitor& visitor);
String sourceURL(JSC::VM& vm, JSC::JSFunction* function);
Expand Down
6 changes: 4 additions & 2 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,10 @@ WTF::String Bun::formatStackTrace(
JSC::JSGlobalObject* globalObjectForFrame = lexicalGlobalObject;
if (frame.hasLineAndColumnInfo()) {
auto* callee = frame.callee();
if (auto* object = callee->getObject()) {
globalObjectForFrame = object->globalObject();
if (callee) {
if (auto* object = callee->getObject()) {
globalObjectForFrame = object->globalObject();
}
}
}

Expand Down
Binary file modified test/bun.lockb
Binary file not shown.
27 changes: 27 additions & 0 deletions test/js/node/vm/happy-dom-vm-16277.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test, expect } from "bun:test";
import { Window } from "happy-dom";
test("reproduction", async (): Promise<undefined> => {
expect.assertions(1);
for (let i: number = 0; i < 2; ++i) {
// TODO: have a reproduction of this that doesn't depend on a 10 MB file.
const response: Response = new Response(`<!DOCTYPE html>
<html>
<head>
<script
id="base-js"
src="https://www.youtube.com/s/desktop/6ed1dd74/jsbin/desktop_polymer_legacy_browsers.vflset/desktop_polymer_legacy_browsers.js"
nonce="4oKS2biXokC0utrX4MKrsQ"></script>
</head>
</body>
</html>`);
const window: Window = new Window({ url: "http://youtube.com" });
const localStorage = window.localStorage;
global.window = window;
global.document = window.document;
localStorage.clear();
document.body.innerHTML = await response.text();
}

// This test passes by simply not crashing.
expect().pass();
});
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"express": "4.18.2",
"fast-glob": "3.3.1",
"filenamify": "6.0.0",
"happy-dom": "16.5.3",
"http2-wrapper": "2.2.1",
"https-proxy-agent": "7.0.5",
"iconv-lite": "0.6.3",
Expand Down

0 comments on commit 5e003dc

Please sign in to comment.