diff options
author | 2023-09-25 23:27:55 -0700 | |
---|---|---|
committer | 2023-09-25 23:27:55 -0700 | |
commit | aec0d35f9b90083b93299859822ac67f3389a6d1 (patch) | |
tree | a4310b05be13ad44ef08b826e5dd84b52c36e504 | |
parent | b5c80d947630b0d73ca114c1c6c47b4f7845e398 (diff) | |
download | bun-aec0d35f9b90083b93299859822ac67f3389a6d1.tar.gz bun-aec0d35f9b90083b93299859822ac67f3389a6d1.tar.zst bun-aec0d35f9b90083b93299859822ac67f3389a6d1.zip |
no this value (#6063)
-rw-r--r-- | src/bun.js/bindings/CallSite.cpp | 2 | ||||
-rw-r--r-- | test/js/node/v8/capture-stack-trace.test.js | 15 |
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(); +}); |