Skip to content

Commit

Permalink
Fix scope usage in #[stack_trace] (#958)
Browse files Browse the repository at this point in the history
Fixes #957
  • Loading branch information
littledivy authored Nov 7, 2024
1 parent 41e7c3d commit 1bcb645
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 18 deletions.
20 changes: 10 additions & 10 deletions ops/op2/dispatch_slow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ pub(crate) fn generate_dispatch_slow(
|s| V8SignatureMappingError::NoRetValMapping(s, signature.ret_val.clone()),
)?);

let with_stack_trace = if generator_state.needs_stack_trace {
with_stack_trace(generator_state)
} else {
quote!()
};

// We only generate the isolate if we need it but don't need a scope. We call it `scope`.
let with_isolate =
if generator_state.needs_isolate && !generator_state.needs_scope {
Expand Down Expand Up @@ -125,12 +131,6 @@ pub(crate) fn generate_dispatch_slow(
quote!()
};

let with_stack_trace = if generator_state.needs_stack_trace {
with_stack_trace(generator_state)
} else {
quote!()
};

Ok(
gs_quote!(generator_state(opctx, info, slow_function, slow_function_metrics) => {
#[inline(always)]
Expand Down Expand Up @@ -196,12 +196,12 @@ pub(crate) fn with_stack_trace(
generator_state: &mut GeneratorState,
) -> TokenStream {
generator_state.needs_opctx = true;
generator_state.needs_scope = true;
gs_quote!(generator_state(stack_trace, opctx, scope) =>
(let #stack_trace = if #opctx.enable_stack_trace_arg {
let hs = &mut deno_core::v8::HandleScope::new(&mut #scope);
let stack_trace_msg = deno_core::v8::String::empty(hs);
let stack_trace_error = deno_core::v8::Exception::error(hs, stack_trace_msg.into());
let js_error = deno_core::error::JsError::from_v8_exception(hs, stack_trace_error);
let stack_trace_msg = deno_core::v8::String::empty(&mut #scope);
let stack_trace_error = deno_core::v8::Exception::error(&mut #scope, stack_trace_msg.into());
let js_error = deno_core::error::JsError::from_v8_exception(&mut #scope, stack_trace_error);
Some(js_error.frames)
} else { None };)
)
Expand Down
7 changes: 3 additions & 4 deletions ops/op2/test_cases/async/async_stack_trace.out

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ops/op2/test_cases/compiler_pass/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
deno_ops_compile_test_runner::prelude!();

use deno_core::v8;
use deno_core::error::JsStackFrame;

// Collect a few examples that we'll smoke test when not running on the CI.

Expand Down Expand Up @@ -58,3 +59,9 @@ fn op_smi_signed_return(
) -> Int32 {
a as Int32 + b as Int32 + c as Int32 + d as Int32
}

#[op2]
fn op_stack_trace(
#[string] _: String,
#[stack_trace] _: Option<Vec<JsStackFrame>>,
) {}
7 changes: 3 additions & 4 deletions ops/op2/test_cases/sync/stack_trace.out

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 110 additions & 0 deletions ops/op2/test_cases/sync/stack_trace_scope.out

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions ops/op2/test_cases/sync/stack_trace_scope.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
#![deny(warnings)]
deno_ops_compile_test_runner::prelude!();

use deno_core::error::JsStackFrame;

#[op2]
fn op_stack_trace(
#[string] _: String,
#[stack_trace] _: Option<Vec<JsStackFrame>>,
) {}

0 comments on commit 1bcb645

Please sign in to comment.