Skip to content

Commit

Permalink
fix bad stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
zackradisic committed May 2, 2024
1 parent d66a4fc commit 1af10af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ WTF::String Bun::formatStackTrace(JSC::VM& vm, JSC::JSGlobalObject* globalObject
// "".test(/[a-0]/);
auto originalLine = WTF::OrdinalNumber::fromOneBasedInt(err->line());

ZigStackFrame remappedFrame;
ZigStackFrame remappedFrame = {};
memset(&remappedFrame, 0, sizeof(ZigStackFrame));

remappedFrame.position.line = originalLine.zeroBasedInt() + 1;
Expand Down Expand Up @@ -467,7 +467,7 @@ WTF::String Bun::formatStackTrace(JSC::VM& vm, JSC::JSGlobalObject* globalObject
LineColumn lineColumn = frame.computeLineAndColumn();
thisLine = lineColumn.line;
thisColumn = lineColumn.column;
ZigStackFrame remappedFrame;
ZigStackFrame remappedFrame = {};
remappedFrame.position.line = thisLine;
remappedFrame.position.column_start = thisColumn;

Expand Down Expand Up @@ -565,6 +565,7 @@ static String computeErrorInfoWithPrepareStackTrace(JSC::VM& vm, Zig::GlobalObje
size_t framesCount = stackTrace.size();
ZigStackFrame remappedFrames[framesCount];
for (int i = 0; i < framesCount; i++) {
remappedFrames[i] = {};
remappedFrames[i].source_url = Bun::toString(lexicalGlobalObject, stackTrace.at(i).sourceURL());
if (JSCStackFrame::SourcePositions* sourcePositions = stackTrace.at(i).getSourcePositions()) {
remappedFrames[i].position.line = sourcePositions->line.oneBasedInt();
Expand Down
9 changes: 5 additions & 4 deletions src/bun.js/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4326,14 +4326,15 @@ static void fromErrorInstance(ZigException* except, JSC::JSGlobalObject* global,
iterator.forEachFrame([&](const V8StackTraceIterator::StackFrame& frame, bool& stop) -> void {
ASSERT(except->stack.frames_len < frame_count);
auto& current = except->stack.frames_ptr[except->stack.frames_len];
current = {};

String functionName = frame.functionName.toString();
String sourceURL = frame.sourceURL.toString();
current.function_name = Bun::toStringRef(functionName);
current.source_url = Bun::toStringRef(sourceURL);
current.position.line = frame.lineNumber.zeroBasedInt();
current.position.column_start = frame.columnNumber.zeroBasedInt();
current.position.column_stop = frame.columnNumber.zeroBasedInt();
current.position.line = frame.lineNumber.oneBasedInt();
current.position.column_start = frame.columnNumber.oneBasedInt();
current.position.column_stop = frame.columnNumber.oneBasedInt();

current.remapped = true;

Expand Down Expand Up @@ -5535,4 +5536,4 @@ CPP_DECL bool JSC__CustomGetterSetter__isSetterNull(JSC__CustomGetterSetter* get
CPP_DECL JSC__JSValue Bun__ProxyObject__getInternalField(JSC__JSValue value, uint32_t id)
{
return JSValue::encode(jsCast<ProxyObject*>(JSValue::decode(value))->internalField((ProxyObject::Field)id).get());
}
}

0 comments on commit 1af10af

Please sign in to comment.