From 5e55cc5a5cf3fcc0e8d1e6777e5d8f8251fd8fe5 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 22 Jan 2020 23:34:02 +0100 Subject: [PATCH] Add binding for Isolate::get_entered_or_microtask_context() (#245) A test will be added later. --- src/binding.cc | 4 ++++ src/isolate.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/binding.cc b/src/binding.cc index 69371cfb..5facaf7a 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -114,6 +114,10 @@ v8::Context* v8__Isolate__GetCurrentContext(v8::Isolate* isolate) { return local_to_ptr(isolate->GetCurrentContext()); } +v8::Context* v8__Isolate__GetEnteredOrMicrotaskContext(v8::Isolate* isolate) { + return local_to_ptr(isolate->GetEnteredOrMicrotaskContext()); +} + void v8__Isolate__SetData(v8::Isolate* isolate, uint32_t slot, void* data) { isolate->SetData(slot, data); } diff --git a/src/isolate.rs b/src/isolate.rs index 5bd42317..9ade32b6 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -73,6 +73,9 @@ extern "C" { fn v8__Isolate__Enter(this: *mut Isolate); fn v8__Isolate__Exit(this: *mut Isolate); fn v8__Isolate__GetCurrentContext(this: *mut Isolate) -> *mut Context; + fn v8__Isolate__GetEnteredOrMicrotaskContext( + this: *mut Isolate, + ) -> *mut Context; fn v8__Isolate__SetCaptureStackTraceForUncaughtExceptions( this: *mut Isolate, caputre: bool, @@ -197,6 +200,18 @@ impl Isolate { unsafe { Local::from_raw(v8__Isolate__GetCurrentContext(self)).unwrap() } } + /// Returns either the last context entered through V8's C++ API, or the + /// context of the currently running microtask while processing microtasks. + /// If a context is entered while executing a microtask, that context is + /// returned. + pub fn get_entered_or_microtask_context<'sc>( + &mut self, + ) -> Local<'sc, Context> { + unsafe { + Local::from_raw(v8__Isolate__GetEnteredOrMicrotaskContext(self)).unwrap() + } + } + /// 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(