aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/CallSite.cpp2
-rw-r--r--test/js/node/v8/capture-stack-trace.test.js15
2 files changed, 16 insertions, 1 deletions
diff --git a/src/bun.js/bindings/CallSite.cpp b/src/bun.js/bindings/CallSite.cpp
index 48fe82275..7667d9606 100644
--- a/src/bun.js/bindings/CallSite.cpp
+++ b/src/bun.js/bindings/CallSite.cpp
@@ -45,7 +45,7 @@ void CallSite::finishCreation(VM& vm, JSC::JSGlobalObject* globalObject, JSCStac
m_function.set(vm, this, JSC::jsUndefined());
m_flags |= static_cast<unsigned int>(Flags::IsStrict);
} else {
- if (callFrame) {
+ if (callFrame && callFrame->thisValue()) {
// We know that we're not in strict mode
m_thisValue.set(vm, this, callFrame->thisValue().toThis(globalObject, JSC::ECMAMode::sloppy()));
} else {
diff --git a/test/js/node/v8/capture-stack-trace.test.js b/test/js/node/v8/capture-stack-trace.test.js
index 2a4d92d95..5e9492955 100644
--- a/test/js/node/v8/capture-stack-trace.test.js
+++ b/test/js/node/v8/capture-stack-trace.test.js
@@ -517,3 +517,18 @@ test("Error.prepareStackTrace inside a node:vm works", () => {
expect(result).toBe("custom stack trace");
expect(Error.prepareStackTrace).toBeNull();
});
+
+test("Error.captureStackTrace inside error constructor works", () => {
+ class ExtendedError extends Error {
+ constructor() {
+ super();
+ Error.captureStackTrace(this, ExtendedError);
+ }
+ }
+
+ class AnotherError extends ExtendedError {}
+
+ expect(() => {
+ throw new AnotherError();
+ }).toThrow();
+});