Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v8::Isolate::set_capture_stack_trace_for_uncaught_exceptions #77

Merged
merged 2 commits into from
Dec 18, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: google
7 changes: 7 additions & 0 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ void v8__Isolate__Enter(Isolate& isolate) { isolate.Enter(); }

void v8__Isolate__Exit(Isolate& isolate) { isolate.Exit(); }

void v8__Isolate__SetCaptureStackTraceForUncaughtExceptions(Isolate& isolate,
bool capture,
int frame_limit) {
// Note: StackTraceOptions are deprecated so we don't bother to bind to it.
isolate.SetCaptureStackTraceForUncaughtExceptions(capture, frame_limit);
}

Isolate::CreateParams* v8__Isolate__CreateParams__NEW() {
return new Isolate::CreateParams();
}
Expand Down
21 changes: 21 additions & 0 deletions src/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ extern "C" {
fn v8__Isolate__Dispose(this: &mut CxxIsolate) -> ();
fn v8__Isolate__Enter(this: &mut CxxIsolate) -> ();
fn v8__Isolate__Exit(this: &mut CxxIsolate) -> ();
fn v8__Isolate__SetCaptureStackTraceForUncaughtExceptions(
this: &mut CxxIsolate,
caputre: bool,
frame_limit: i32,
);

fn v8__Isolate__CreateParams__NEW() -> *mut CreateParams;
fn v8__Isolate__CreateParams__DELETE(this: &mut CreateParams);
Expand Down Expand Up @@ -64,6 +69,22 @@ impl Isolate {
pub fn exit(&mut self) {
unsafe { v8__Isolate__Exit(self.0) }
}

/// Tells V8 to capture current stack trace when uncaught exception occurs
/// and report it to the message listeners. The option is off by default.
pub fn set_capture_stack_trace_for_uncaught_exceptions(
&mut self,
capture: bool,
frame_limit: i32,
) {
unsafe {
v8__Isolate__SetCaptureStackTraceForUncaughtExceptions(
self.0,
capture,
frame_limit,
)
}
}
}

impl Drop for Isolate {
Expand Down
3 changes: 2 additions & 1 deletion tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ fn isolate_new() {
params.set_array_buffer_allocator(
v8::array_buffer::Allocator::new_default_allocator(),
);
v8::Isolate::new(params);
let mut isolate = v8::Isolate::new(params);
isolate.set_capture_stack_trace_for_uncaught_exceptions(true, 32);
drop(g);
}

Expand Down