Skip to content

Commit 8596923

Browse files
authored
Fix mutliple isolate borrows with #[stack_trace] (#1044)
1 parent 2ba615a commit 8596923

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

ops/op2/dispatch_fast.rs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -468,17 +468,6 @@ pub(crate) fn generate_dispatch_fast(
468468
quote!()
469469
};
470470

471-
let with_isolate = if generator_state.needs_fast_isolate
472-
&& !generator_state.needs_fast_scope
473-
{
474-
generator_state.needs_opctx = true;
475-
gs_quote!(generator_state(opctx, scope) =>
476-
(let mut #scope = unsafe { &mut *#opctx.isolate };)
477-
)
478-
} else {
479-
quote!()
480-
};
481-
482471
let with_opctx = if generator_state.needs_opctx {
483472
generator_state.needs_fast_api_callback_options = true;
484473
gs_quote!(generator_state(opctx, fast_api_callback_options) => {
@@ -492,15 +481,13 @@ pub(crate) fn generate_dispatch_fast(
492481
};
493482

494483
let with_self = if generator_state.needs_self {
495-
generator_state.needs_fast_api_callback_options = true;
484+
generator_state.needs_fast_isolate = true;
496485
let throw_exception = throw_type_error(
497486
generator_state,
498487
format!("expected {}", &generator_state.self_ty),
499488
);
500-
gs_quote!(generator_state(self_ty, fast_api_callback_options) => {
501-
// SAFETY: Isolate is valid if this function is being called.
502-
let isolate = unsafe { &mut *#fast_api_callback_options.isolate };
503-
let Some(self_) = deno_core::_ops::try_unwrap_cppgc_object::<#self_ty>(isolate, this.into()) else {
489+
gs_quote!(generator_state(self_ty, scope) => {
490+
let Some(self_) = deno_core::_ops::try_unwrap_cppgc_object::<#self_ty>(&mut #scope, this.into()) else {
504491
#throw_exception
505492
};
506493
let self_ = &*self_;
@@ -509,6 +496,17 @@ pub(crate) fn generate_dispatch_fast(
509496
quote!()
510497
};
511498

499+
let with_isolate = if generator_state.needs_fast_isolate
500+
&& !generator_state.needs_fast_scope
501+
&& !generator_state.needs_stack_trace
502+
{
503+
generator_state.needs_fast_api_callback_options = true;
504+
gs_quote!(generator_state(scope, fast_api_callback_options) =>
505+
(let mut #scope = unsafe { &mut *#fast_api_callback_options.isolate };)
506+
)
507+
} else {
508+
quote!()
509+
};
512510
let with_scope = if generator_state.needs_scope {
513511
let create_scope = create_scope(generator_state);
514512
gs_quote!(generator_state(scope) => {
@@ -591,8 +589,8 @@ pub(crate) fn generate_dispatch_fast(
591589
#with_opstate;
592590
#with_stack_trace
593591
#with_js_runtime_state
594-
#with_self
595592
#with_isolate
593+
#with_self
596594
let #result = {
597595
#(#call_args)*
598596
#call (#(#call_names),*)
@@ -632,6 +630,7 @@ fn map_v8_fastcall_arg_to_arg(
632630
needs_scope,
633631
needs_opctx,
634632
needs_fast_api_callback_options,
633+
needs_fast_isolate,
635634
needs_js_runtime_state,
636635
..
637636
} = generator_state;
@@ -799,13 +798,11 @@ fn map_v8_fastcall_arg_to_arg(
799798
let ty =
800799
syn::parse_str::<syn::Path>(ty).expect("Failed to reparse state type");
801800

802-
*needs_fast_api_callback_options = true;
801+
*needs_fast_isolate = true;
803802
let throw_exception =
804803
throw_type_error(generator_state, format!("expected {ty:?}"));
805-
gs_quote!(generator_state(fast_api_callback_options) => {
806-
// SAFETY: Isolate is valid if this function is being called.
807-
let isolate = unsafe { &mut *#fast_api_callback_options.isolate };
808-
let Some(#arg_ident) = deno_core::_ops::try_unwrap_cppgc_object::<#ty>(isolate, #arg_ident) else {
804+
gs_quote!(generator_state(scope) => {
805+
let Some(#arg_ident) = deno_core::_ops::try_unwrap_cppgc_object::<#ty>(&mut #scope, #arg_ident) else {
809806
#throw_exception
810807
};
811808
let #arg_ident = &*#arg_ident;
@@ -815,15 +812,13 @@ fn map_v8_fastcall_arg_to_arg(
815812
let ty =
816813
syn::parse_str::<syn::Path>(ty).expect("Failed to reparse state type");
817814

818-
*needs_fast_api_callback_options = true;
815+
*needs_fast_isolate = true;
819816
let throw_exception =
820817
throw_type_error(generator_state, format!("expected {ty:?}"));
821-
gs_quote!(generator_state(fast_api_callback_options) => {
822-
// SAFETY: Isolate is valid if this function is being called.
823-
let isolate = unsafe { &mut *#fast_api_callback_options.isolate };
818+
gs_quote!(generator_state(scope) => {
824819
let #arg_ident = if #arg_ident.is_null_or_undefined() {
825820
None
826-
} else if let Some(#arg_ident) = deno_core::_ops::try_unwrap_cppgc_object::<#ty>(isolate, #arg_ident) {
821+
} else if let Some(#arg_ident) = deno_core::_ops::try_unwrap_cppgc_object::<#ty>(&mut #scope, #arg_ident) {
827822
Some(#arg_ident)
828823
} else {
829824
#throw_exception

ops/op2/test_cases/sync/cppgc_resource.out

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ops/op2/test_cases/sync/object_wrap.out

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/checkin/runner/ops.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ impl DOMPoint {
212212
#[fast]
213213
#[symbol("symbolMethod")]
214214
fn with_symbol(&self) {}
215+
216+
#[fast]
217+
#[stack_trace]
218+
fn with_stack_trace(&self) {}
215219
}
216220

217221
#[repr(u8)]

0 commit comments

Comments
 (0)