0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-03-09 21:47:00 -04:00

add Isolate::get_current_context() (#155)

This commit is contained in:
Bartek Iwańczuk 2019-12-31 14:07:42 +01:00 committed by Bert Belder
parent d31960342f
commit 23a49d0fd1
3 changed files with 12 additions and 2 deletions

View file

@ -104,6 +104,10 @@ void v8__Isolate__Enter(v8::Isolate* isolate) { isolate->Enter(); }
void v8__Isolate__Exit(v8::Isolate* isolate) { isolate->Exit(); } void v8__Isolate__Exit(v8::Isolate* isolate) { isolate->Exit(); }
v8::Context* v8__Isolate__GetCurrentContext(v8::Isolate* isolate) {
return local_to_ptr(isolate->GetCurrentContext());
}
void v8__Isolate__SetData(v8::Isolate* isolate, uint32_t slot, void* data) { void v8__Isolate__SetData(v8::Isolate* isolate, uint32_t slot, void* data) {
isolate->SetData(slot, data); isolate->SetData(slot, data);
} }

View file

@ -68,6 +68,7 @@ extern "C" {
fn v8__Isolate__GetNumberOfDataSlots(this: *const Isolate) -> u32; fn v8__Isolate__GetNumberOfDataSlots(this: *const Isolate) -> u32;
fn v8__Isolate__Enter(this: *mut Isolate); fn v8__Isolate__Enter(this: *mut Isolate);
fn v8__Isolate__Exit(this: *mut Isolate); fn v8__Isolate__Exit(this: *mut Isolate);
fn v8__Isolate__GetCurrentContext(this: *mut Isolate) -> *mut Context;
fn v8__Isolate__SetCaptureStackTraceForUncaughtExceptions( fn v8__Isolate__SetCaptureStackTraceForUncaughtExceptions(
this: *mut Isolate, this: *mut Isolate,
caputre: bool, caputre: bool,
@ -177,6 +178,12 @@ impl Isolate {
unsafe { v8__Isolate__Exit(self) } unsafe { v8__Isolate__Exit(self) }
} }
/// Returns the context of the currently running JavaScript, or the context
/// on the top of the stack if no JavaScript is running.
pub fn get_current_context<'sc>(&mut self) -> Local<'sc, Context> {
unsafe { Local::from_raw(v8__Isolate__GetCurrentContext(self)).unwrap() }
}
/// Tells V8 to capture current stack trace when uncaught exception occurs /// Tells V8 to capture current stack trace when uncaught exception occurs
/// and report it to the message listeners. The option is off by default. /// and report it to the message listeners. The option is off by default.
pub fn set_capture_stack_trace_for_uncaught_exceptions( pub fn set_capture_stack_trace_for_uncaught_exceptions(

View file

@ -922,14 +922,13 @@ extern "C" fn fn_callback2(info: &FunctionCallbackInfo) {
assert_eq!(info.length(), 2); assert_eq!(info.length(), 2);
let isolate = info.get_isolate(); let isolate = info.get_isolate();
let mut locker = v8::Locker::new(&isolate); let mut locker = v8::Locker::new(&isolate);
let mut context = isolate.get_current_context();
let arg1 = info.get_argument(0); let arg1 = info.get_argument(0);
let arg2 = info.get_argument(1); let arg2 = info.get_argument(1);
let rv = &mut info.get_return_value(); let rv = &mut info.get_return_value();
{ {
let mut hs = v8::HandleScope::new(&mut locker); let mut hs = v8::HandleScope::new(&mut locker);
let scope = hs.enter(); let scope = hs.enter();
let mut context = v8::Context::new(scope);
context.enter(); context.enter();
let arg1_val = v8::String::new(scope, "arg1").unwrap(); let arg1_val = v8::String::new(scope, "arg1").unwrap();