diff options
author | 2023-07-11 19:00:24 -0700 | |
---|---|---|
committer | 2023-07-11 19:00:51 -0700 | |
commit | a686b3bfc13a53bc324c09d7bae37f1249330481 (patch) | |
tree | 76c468a96953e274539e09aa695bdeaef7420ee6 | |
parent | a1fb289c96ca41fc3fc50ccb76f6e63e70b6a772 (diff) | |
download | bun-a686b3bfc13a53bc324c09d7bae37f1249330481.tar.gz bun-a686b3bfc13a53bc324c09d7bae37f1249330481.tar.zst bun-a686b3bfc13a53bc324c09d7bae37f1249330481.zip |
Fixes #3595
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 3291b204e..af0dad4da 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -336,12 +336,22 @@ extern "C" void JSCInitialize(const char* envp[], size_t envc, void (*onCrash)(c extern "C" void* Bun__getVM(); extern "C" JSGlobalObject* Bun__getDefaultGlobal(); +// Error.captureStackTrace may cause computeErrorInfo to be called twice +// Rather than figure out the plumbing in JSC, we just skip the next call +// TODO: thread_local for workers +static bool skipNextComputeErrorInfo = false; + +// error.stack calls this function static String computeErrorInfoWithoutPrepareStackTrace(JSC::VM& vm, Vector<StackFrame>& stackTrace, unsigned& line, unsigned& column, String& sourceURL, JSObject* errorInstance) { if (!errorInstance) { return String(); } + if (skipNextComputeErrorInfo) { + return String(); + } + Zig::GlobalObject* globalObject = jsDynamicCast<Zig::GlobalObject*>(errorInstance->globalObject()); if (!globalObject) { // Happens in node:vm @@ -414,6 +424,9 @@ static String computeErrorInfoWithoutPrepareStackTrace(JSC::VM& vm, Vector<Stack if (!sourceURLForFrame.isEmpty()) { remappedFrames[i].source_url = Bun::toString(sourceURLForFrame); + } else { + // https://github.com/oven-sh/bun/issues/3595 + remappedFrames[i].source_url = BunStringEmpty; } // This ensures the lifetime of the sourceURL is accounted for correctly @@ -423,7 +436,7 @@ static String computeErrorInfoWithoutPrepareStackTrace(JSC::VM& vm, Vector<Stack hasSet = true; line = thisLine; column = thisColumn; - sourceURL = frame.sourceURL(vm); + sourceURL = sourceURLForFrame; if (errorInstance) { if (remappedFrames[i].remapped) { @@ -2867,9 +2880,14 @@ JSC_DEFINE_HOST_FUNCTION(errorConstructorFuncCaptureStackTrace, (JSC::JSGlobalOb JSC::JSValue formattedStackTrace = globalObject->formatStackTrace(vm, lexicalGlobalObject, errorObject, callSites); RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode({})); + bool orignialSkipNextComputeErrorInfo = skipNextComputeErrorInfo; + skipNextComputeErrorInfo = true; if (errorObject->hasProperty(lexicalGlobalObject, vm.propertyNames->stack)) { + skipNextComputeErrorInfo = true; errorObject->deleteProperty(lexicalGlobalObject, vm.propertyNames->stack); } + skipNextComputeErrorInfo = orignialSkipNextComputeErrorInfo; + if (formattedStackTrace.isUndefinedOrNull()) { formattedStackTrace = JSC::jsUndefined(); } |