Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bun.js/bindings/ZigStackFrame.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub const ZigStackFrame = extern struct {
/// This informs formatters whether to display as a blob URL or not
remapped: bool = false,

/// -1 means not set.
jsc_stack_frame_index: i32 = -1,

pub fn deinit(this: *ZigStackFrame) void {
this.function_name.deref();
this.source_url.deref();
Expand Down Expand Up @@ -213,6 +216,7 @@ pub const ZigStackFrame = extern struct {
.source_url = .empty,
.position = .invalid,
.is_async = false,
.jsc_stack_frame_index = -1,
};

pub fn nameFormatter(this: *const ZigStackFrame, comptime enable_color: bool) NameFormatter {
Expand Down
44 changes: 28 additions & 16 deletions src/bun.js/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4772,25 +4772,37 @@ class V8StackTraceIterator {

static void populateStackTrace(JSC::VM& vm, const WTF::Vector<JSC::StackFrame>& frames, ZigStackTrace& trace, JSC::JSGlobalObject* globalObject, PopulateStackTraceFlags flags)
{
uint8_t frame_i = 0;
size_t stack_frame_i = 0;
const size_t total_frame_count = frames.size();
const uint8_t frame_count = total_frame_count < trace.frames_cap ? total_frame_count : trace.frames_cap;

while (frame_i < frame_count && stack_frame_i < total_frame_count) {
// Skip native frames
while (stack_frame_i < total_frame_count && !(frames.at(stack_frame_i).hasLineAndColumnInfo()) && !(frames.at(stack_frame_i).isWasmFrame())) {
if (flags == PopulateStackTraceFlags::OnlyPosition) {
uint8_t frame_i = 0;
size_t stack_frame_i = 0;
const size_t total_frame_count = frames.size();
const uint8_t frame_count = total_frame_count < trace.frames_cap ? total_frame_count : trace.frames_cap;

while (frame_i < frame_count && stack_frame_i < total_frame_count) {
// Skip native frames
while (stack_frame_i < total_frame_count && !(frames.at(stack_frame_i).hasLineAndColumnInfo()) && !(frames.at(stack_frame_i).isWasmFrame())) {
stack_frame_i++;
}
if (stack_frame_i >= total_frame_count)
break;

ZigStackFrame& frame = trace.frames_ptr[frame_i];
frame.jsc_stack_frame_index = static_cast<int32_t>(stack_frame_i);
populateStackFrame(vm, trace, frames[stack_frame_i], frame, frame_i == 0, &trace.referenced_source_provider, globalObject, flags);
stack_frame_i++;
frame_i++;
}
trace.frames_len = frame_i;
} else if (flags == PopulateStackTraceFlags::OnlySourceLines) {
for (uint8_t i = 0; i < trace.frames_len; i++) {
ZigStackFrame& frame = trace.frames_ptr[i];
// A call with flags set to OnlySourceLines always follows a call with flags set to OnlyPosition,
// so jsc_stack_frame_index is always a valid value here.
ASSERT(frame.jsc_stack_frame_index >= 0);
ASSERT(static_cast<size_t>(frame.jsc_stack_frame_index) < frames.size());
populateStackFrame(vm, trace, frames[frame.jsc_stack_frame_index], frame, i == 0, &trace.referenced_source_provider, globalObject, flags);
}
if (stack_frame_i >= total_frame_count)
break;

ZigStackFrame& frame = trace.frames_ptr[frame_i];
populateStackFrame(vm, trace, frames[stack_frame_i], frame, frame_i == 0, &trace.referenced_source_provider, globalObject, flags);
stack_frame_i++;
frame_i++;
}
trace.frames_len = frame_i;
}

static JSC::JSValue getNonObservable(JSC::VM& vm, JSC::JSGlobalObject* global, JSC::JSObject* obj, const JSC::PropertyName& propertyName)
Expand Down
12 changes: 12 additions & 0 deletions src/bun.js/bindings/headers-handwritten.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ typedef struct ZigStackFrame {
ZigStackFrameCode code_type;
bool is_async;
bool remapped;
int32_t jsc_stack_frame_index;

ZigStackFrame()
: function_name {}
, source_url {}
, position {}
, code_type {}
, is_async(false)
, remapped(false)
, jsc_stack_frame_index(-1)
{
}
} ZigStackFrame;

typedef struct ZigStackTrace {
Expand Down
10 changes: 0 additions & 10 deletions src/logger.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1335,15 +1335,6 @@ pub const Log = struct {

if (needs_newline) _ = try to.write("\n");
}

pub fn toZigException(this: *const Log, allocator: std.mem.Allocator) *js.ZigException.Holder {
var holder = try allocator.create(js.ZigException.Holder);
holder.* = js.ZigException.Holder.init();
var zig_exception: *js.ZigException = holder.zigException();
zig_exception.exception = this;
zig_exception.code = js.JSErrorCode.BundlerError;
return holder;
}
};

pub inline fn usize2Loc(loc: usize) Loc {
Expand Down Expand Up @@ -1617,7 +1608,6 @@ const Output = bun.Output;
const StringBuilder = bun.StringBuilder;
const assert = bun.assert;
const default_allocator = bun.default_allocator;
const js = bun.jsc;
const jsc = bun.jsc;
const strings = bun.strings;
const Index = bun.ast.Index;
Expand Down