mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-26 09:13:46 -05:00
refactor: Move set_promise_hooks API to HandleScope (#1186)
This commit is contained in:
parent
3b6d79c0e6
commit
36cf16b594
3 changed files with 30 additions and 37 deletions
|
@ -5,7 +5,6 @@ use crate::isolate::Isolate;
|
|||
use crate::isolate::RawSlot;
|
||||
use crate::support::int;
|
||||
use crate::Context;
|
||||
use crate::Function;
|
||||
use crate::HandleScope;
|
||||
use crate::Local;
|
||||
use crate::Object;
|
||||
|
@ -27,13 +26,6 @@ extern "C" {
|
|||
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,
|
||||
before_hook: *const Function,
|
||||
after_hook: *const Function,
|
||||
resolve_hook: *const Function,
|
||||
);
|
||||
fn v8__Context__GetNumberOfEmbedderDataFields(this: *const Context) -> u32;
|
||||
fn v8__Context__GetAlignedPointerFromEmbedderData(
|
||||
this: *const Context,
|
||||
|
@ -107,26 +99,6 @@ impl Context {
|
|||
unsafe { scope.cast_local(|_| v8__Context__Global(self)) }.unwrap()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn set_promise_hooks<'s>(
|
||||
&self,
|
||||
_scope: &mut HandleScope<'s, ()>,
|
||||
init_hook: Option<Local<Function>>,
|
||||
before_hook: Option<Local<Function>>,
|
||||
after_hook: Option<Local<Function>>,
|
||||
resolve_hook: Option<Local<Function>>,
|
||||
) {
|
||||
unsafe {
|
||||
v8__Context__SetPromiseHooks(
|
||||
self,
|
||||
init_hook.map_or_else(null, |v| &*v),
|
||||
before_hook.map_or_else(null, |v| &*v),
|
||||
after_hook.map_or_else(null, |v| &*v),
|
||||
resolve_hook.map_or_else(null, |v| &*v),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_annex_mut<'a>(
|
||||
&'a self,
|
||||
|
|
28
src/scope.rs
28
src/scope.rs
|
@ -96,6 +96,7 @@ use crate::function::PropertyCallbackInfo;
|
|||
use crate::Context;
|
||||
use crate::Data;
|
||||
use crate::DataError;
|
||||
use crate::Function;
|
||||
use crate::Handle;
|
||||
use crate::Isolate;
|
||||
use crate::Local;
|
||||
|
@ -287,6 +288,26 @@ impl<'s> HandleScope<'s> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn set_promise_hooks(
|
||||
&mut self,
|
||||
init_hook: Option<Local<Function>>,
|
||||
before_hook: Option<Local<Function>>,
|
||||
after_hook: Option<Local<Function>>,
|
||||
resolve_hook: Option<Local<Function>>,
|
||||
) {
|
||||
unsafe {
|
||||
let sd = data::ScopeData::get_mut(self);
|
||||
raw::v8__Context__SetPromiseHooks(
|
||||
sd.get_current_context(),
|
||||
init_hook.map_or_else(std::ptr::null, |v| &*v),
|
||||
before_hook.map_or_else(std::ptr::null, |v| &*v),
|
||||
after_hook.map_or_else(std::ptr::null, |v| &*v),
|
||||
resolve_hook.map_or_else(std::ptr::null, |v| &*v),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn set_continuation_preserved_embedder_data(
|
||||
&mut self,
|
||||
|
@ -1719,6 +1740,13 @@ mod raw {
|
|||
this: *const Context,
|
||||
index: usize,
|
||||
) -> *const Data;
|
||||
pub(super) fn v8__Context__SetPromiseHooks(
|
||||
this: *const Context,
|
||||
init_hook: *const Function,
|
||||
before_hook: *const Function,
|
||||
after_hook: *const Function,
|
||||
resolve_hook: *const Function,
|
||||
);
|
||||
pub(super) fn v8__Context__SetContinuationPreservedEmbedderData(
|
||||
this: *const Context,
|
||||
value: *const Value,
|
||||
|
|
|
@ -3269,8 +3269,7 @@ fn context_promise_hooks() {
|
|||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
context.set_promise_hooks(
|
||||
scope,
|
||||
scope.set_promise_hooks(
|
||||
Some(init_hook),
|
||||
Some(before_hook),
|
||||
Some(after_hook),
|
||||
|
@ -3349,13 +3348,7 @@ fn context_promise_hooks_partial() {
|
|||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
context.set_promise_hooks(
|
||||
scope,
|
||||
Some(init_hook),
|
||||
Some(before_hook),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
scope.set_promise_hooks(Some(init_hook), Some(before_hook), None, None);
|
||||
|
||||
let source = r#"
|
||||
function expect(expected, actual = promises.size) {
|
||||
|
|
Loading…
Reference in a new issue