From 5f90045ad086457f6fdab80a9564f8cefed57d29 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Tue, 24 May 2022 21:57:35 +0800 Subject: [PATCH] feat: add Context::get_extras_binding_object (#975) --- src/binding.cc | 4 ++++ src/context.rs | 10 ++++++++++ tests/test_api.rs | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/binding.cc b/src/binding.cc index 292e0fc0..46f9c7ba 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -1602,6 +1602,10 @@ const v8::Data* v8__Context__GetDataFromSnapshotOnce(v8::Context& self, ptr_to_local(&self)->GetDataFromSnapshotOnce(index)); } +const v8::Object* v8__Context__GetExtrasBindingObject(v8::Context& self) { + return local_to_ptr(ptr_to_local(&self)->GetExtrasBindingObject()); +} + void v8__Context__SetPromiseHooks(v8::Context& self, v8::Function& init_hook, v8::Function& before_hook, v8::Function& after_hook, diff --git a/src/context.rs b/src/context.rs index 9376ed7a..4140df60 100644 --- a/src/context.rs +++ b/src/context.rs @@ -25,6 +25,8 @@ extern "C" { ) -> *const Context; fn v8__Context__GetIsolate(this: *const Context) -> *mut Isolate; fn v8__Context__Global(this: *const Context) -> *const Object; + fn v8__Context__GetExtrasBindingObject(this: *const Context) + -> *const Object; fn v8__Context__SetPromiseHooks( this: *const Context, init_hook: *const Function, @@ -71,6 +73,14 @@ impl Context { .unwrap() } + pub fn get_extras_binding_object<'s>( + &self, + scope: &mut HandleScope<'s, ()>, + ) -> Local<'s, Object> { + unsafe { scope.cast_local(|_| v8__Context__GetExtrasBindingObject(self)) } + .unwrap() + } + /// Returns the global proxy object. /// /// Global proxy object is a thin wrapper whose prototype points to actual diff --git a/tests/test_api.rs b/tests/test_api.rs index 70daccac..fd35747a 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -2582,6 +2582,19 @@ fn promise_hook() { } } +#[test] +fn context_get_extras_binding_object() { + let _setup_guard = setup(); + let isolate = &mut v8::Isolate::new(Default::default()); + { + let scope = &mut v8::HandleScope::new(isolate); + let context = v8::Context::new(scope); + let scope = &mut v8::ContextScope::new(scope, context); + let extras_binding = context.get_extras_binding_object(scope); + assert!(extras_binding.is_object()); + } +} + #[test] fn context_promise_hooks() { let _setup_guard = setup();