0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-21 15:04:33 -05:00

feat: add Context::get_extras_binding_object (#975)

This commit is contained in:
Chengzhong Wu 2022-05-24 21:57:35 +08:00 committed by GitHub
parent 9b1bb41d86
commit 5f90045ad0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View file

@ -1602,6 +1602,10 @@ const v8::Data* v8__Context__GetDataFromSnapshotOnce(v8::Context& self,
ptr_to_local(&self)->GetDataFromSnapshotOnce<v8::Data>(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,

View file

@ -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

View file

@ -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();