aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-09-25 23:27:55 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-25 23:27:55 -0700
commitaec0d35f9b90083b93299859822ac67f3389a6d1 (patch)
treea4310b05be13ad44ef08b826e5dd84b52c36e504
parentb5c80d947630b0d73ca114c1c6c47b4f7845e398 (diff)
downloadbun-aec0d35f9b90083b93299859822ac67f3389a6d1.tar.gz
bun-aec0d35f9b90083b93299859822ac67f3389a6d1.tar.zst
bun-aec0d35f9b90083b93299859822ac67f3389a6d1.zip
no this value (#6063)
-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();
+});