mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-21 15:04:33 -05:00
Change signature of FunctionTemplate::build_fast (#1197)
Changes signature of "FunctionTemplate::build_fast" to allow to pass "CFunctionInfo" explicitly. If it's not passed explicitly, it's still autogenerated.
This commit is contained in:
parent
c58f4c08d9
commit
b1884eb1f5
4 changed files with 59 additions and 34 deletions
|
@ -87,7 +87,7 @@ fn main() {
|
||||||
rv.set(v8::Integer::new(scope, 42).into());
|
rv.set(v8::Integer::new(scope, 42).into());
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.build_fast(scope, &FastCall, None);
|
.build_fast(scope, &FastCall, None, None, None);
|
||||||
let name = v8::String::new(scope, "new_fast").unwrap();
|
let name = v8::String::new(scope, "new_fast").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub struct CFunction(Opaque);
|
||||||
|
|
||||||
impl CFunctionInfo {
|
impl CFunctionInfo {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) unsafe fn new(
|
pub unsafe fn new(
|
||||||
args: *const CTypeInfo,
|
args: *const CTypeInfo,
|
||||||
args_len: usize,
|
args_len: usize,
|
||||||
return_type: *const CTypeInfo,
|
return_type: *const CTypeInfo,
|
||||||
|
@ -45,11 +45,11 @@ pub struct CTypeInfo(Opaque);
|
||||||
|
|
||||||
impl CTypeInfo {
|
impl CTypeInfo {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub(crate) fn new(ty: CType) -> NonNull<CTypeInfo> {
|
pub fn new(ty: CType) -> NonNull<CTypeInfo> {
|
||||||
unsafe { NonNull::new_unchecked(v8__CTypeInfo__New(ty)) }
|
unsafe { NonNull::new_unchecked(v8__CTypeInfo__New(ty)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_from_slice(types: &[Type]) -> NonNull<CTypeInfo> {
|
pub fn new_from_slice(types: &[Type]) -> NonNull<CTypeInfo> {
|
||||||
let mut structs = vec![];
|
let mut structs = vec![];
|
||||||
|
|
||||||
for type_ in types.iter() {
|
for type_ in types.iter() {
|
||||||
|
|
|
@ -372,27 +372,50 @@ impl<'s> FunctionBuilder<'s, FunctionTemplate> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// It's not required to provide `CFunctionInfo` for the overloads - if they
|
||||||
|
/// are omitted, then they will be automatically created. In some cases it is
|
||||||
|
/// useful to pass them explicitly - eg. when you are snapshotting you'd provide
|
||||||
|
/// the overloads and `CFunctionInfo` that would be placed in the external
|
||||||
|
/// references array.
|
||||||
pub fn build_fast(
|
pub fn build_fast(
|
||||||
self,
|
self,
|
||||||
scope: &mut HandleScope<'s, ()>,
|
scope: &mut HandleScope<'s, ()>,
|
||||||
overload1: &dyn FastFunction,
|
overload1: &dyn FastFunction,
|
||||||
|
c_fn_info1: Option<*const CFunctionInfo>,
|
||||||
overload2: Option<&dyn FastFunction>,
|
overload2: Option<&dyn FastFunction>,
|
||||||
|
c_fn_info2: Option<*const CFunctionInfo>,
|
||||||
) -> Local<'s, FunctionTemplate> {
|
) -> Local<'s, FunctionTemplate> {
|
||||||
unsafe {
|
let c_fn1 = if let Some(fn_info) = c_fn_info1 {
|
||||||
|
fn_info
|
||||||
|
} else {
|
||||||
let args = CTypeInfo::new_from_slice(overload1.args());
|
let args = CTypeInfo::new_from_slice(overload1.args());
|
||||||
let ret = CTypeInfo::new(overload1.return_type());
|
let ret = CTypeInfo::new(overload1.return_type());
|
||||||
let c_fn1 =
|
let fn_info = unsafe {
|
||||||
CFunctionInfo::new(args.as_ptr(), overload1.args().len(), ret.as_ptr());
|
CFunctionInfo::new(args.as_ptr(), overload1.args().len(), ret.as_ptr())
|
||||||
|
|
||||||
let c_fn2 = match overload2 {
|
|
||||||
Some(overload) => {
|
|
||||||
let args = CTypeInfo::new_from_slice(overload.args());
|
|
||||||
let ret = CTypeInfo::new(overload.return_type());
|
|
||||||
CFunctionInfo::new(args.as_ptr(), overload.args().len(), ret.as_ptr())
|
|
||||||
.as_ptr()
|
|
||||||
}
|
|
||||||
None => null(),
|
|
||||||
};
|
};
|
||||||
|
fn_info.as_ptr()
|
||||||
|
};
|
||||||
|
|
||||||
|
let c_fn2 = if let Some(overload2) = overload2 {
|
||||||
|
if let Some(fn_info) = c_fn_info2 {
|
||||||
|
fn_info
|
||||||
|
} else {
|
||||||
|
let args = CTypeInfo::new_from_slice(overload2.args());
|
||||||
|
let ret = CTypeInfo::new(overload2.return_type());
|
||||||
|
let fn_info = unsafe {
|
||||||
|
CFunctionInfo::new(
|
||||||
|
args.as_ptr(),
|
||||||
|
overload2.args().len(),
|
||||||
|
ret.as_ptr(),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
fn_info.as_ptr()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null()
|
||||||
|
};
|
||||||
|
|
||||||
|
unsafe {
|
||||||
scope.cast_local(|sd| {
|
scope.cast_local(|sd| {
|
||||||
v8__FunctionTemplate__New(
|
v8__FunctionTemplate__New(
|
||||||
sd.get_isolate_ptr(),
|
sd.get_isolate_ptr(),
|
||||||
|
@ -403,7 +426,7 @@ impl<'s> FunctionBuilder<'s, FunctionTemplate> {
|
||||||
ConstructorBehavior::Throw,
|
ConstructorBehavior::Throw,
|
||||||
self.side_effect_type,
|
self.side_effect_type,
|
||||||
overload1.function(),
|
overload1.function(),
|
||||||
c_fn1.as_ptr(),
|
c_fn1,
|
||||||
overload2.map_or(null(), |f| f.function()),
|
overload2.map_or(null(), |f| f.function()),
|
||||||
c_fn2,
|
c_fn2,
|
||||||
)
|
)
|
||||||
|
|
|
@ -8268,8 +8268,8 @@ fn test_fast_calls() {
|
||||||
|
|
||||||
let global = context.global(scope);
|
let global = context.global(scope);
|
||||||
|
|
||||||
let template =
|
let template = v8::FunctionTemplate::builder(slow_fn)
|
||||||
v8::FunctionTemplate::builder(slow_fn).build_fast(scope, &FastTest, None);
|
.build_fast(scope, &FastTest, None, None, None);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "func").unwrap();
|
let name = v8::String::new(scope, "func").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
@ -8341,8 +8341,8 @@ fn test_fast_calls_sequence() {
|
||||||
|
|
||||||
let global = context.global(scope);
|
let global = context.global(scope);
|
||||||
|
|
||||||
let template =
|
let template = v8::FunctionTemplate::builder(slow_fn)
|
||||||
v8::FunctionTemplate::builder(slow_fn).build_fast(scope, &FastTest, None);
|
.build_fast(scope, &FastTest, None, None, None);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "func").unwrap();
|
let name = v8::String::new(scope, "func").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
@ -8414,8 +8414,8 @@ fn test_fast_calls_arraybuffer() {
|
||||||
|
|
||||||
let global = context.global(scope);
|
let global = context.global(scope);
|
||||||
|
|
||||||
let template =
|
let template = v8::FunctionTemplate::builder(slow_fn)
|
||||||
v8::FunctionTemplate::builder(slow_fn).build_fast(scope, &FastTest, None);
|
.build_fast(scope, &FastTest, None, None, None);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "func").unwrap();
|
let name = v8::String::new(scope, "func").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
@ -8490,8 +8490,8 @@ fn test_fast_calls_typedarray() {
|
||||||
|
|
||||||
let global = context.global(scope);
|
let global = context.global(scope);
|
||||||
|
|
||||||
let template =
|
let template = v8::FunctionTemplate::builder(slow_fn)
|
||||||
v8::FunctionTemplate::builder(slow_fn).build_fast(scope, &FastTest, None);
|
.build_fast(scope, &FastTest, None, None, None);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "func").unwrap();
|
let name = v8::String::new(scope, "func").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
@ -8580,8 +8580,8 @@ fn test_fast_calls_reciever() {
|
||||||
embedder_obj as _,
|
embedder_obj as _,
|
||||||
);
|
);
|
||||||
|
|
||||||
let template =
|
let template = v8::FunctionTemplate::builder(slow_fn)
|
||||||
v8::FunctionTemplate::builder(slow_fn).build_fast(scope, &FastTest, None);
|
.build_fast(scope, &FastTest, None, None, None);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "method").unwrap();
|
let name = v8::String::new(scope, "method").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
@ -8674,7 +8674,9 @@ fn test_fast_calls_overload() {
|
||||||
let template = v8::FunctionTemplate::builder(slow_fn).build_fast(
|
let template = v8::FunctionTemplate::builder(slow_fn).build_fast(
|
||||||
scope,
|
scope,
|
||||||
&FastTest,
|
&FastTest,
|
||||||
|
None,
|
||||||
Some(&FastTest2),
|
Some(&FastTest2),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "func").unwrap();
|
let name = v8::String::new(scope, "func").unwrap();
|
||||||
|
@ -8748,8 +8750,8 @@ fn test_fast_calls_callback_options_fallback() {
|
||||||
|
|
||||||
let global = context.global(scope);
|
let global = context.global(scope);
|
||||||
|
|
||||||
let template =
|
let template = v8::FunctionTemplate::builder(slow_fn)
|
||||||
v8::FunctionTemplate::builder(slow_fn).build_fast(scope, &FastTest, None);
|
.build_fast(scope, &FastTest, None, None, None);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "func").unwrap();
|
let name = v8::String::new(scope, "func").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
@ -8824,7 +8826,7 @@ fn test_fast_calls_callback_options_data() {
|
||||||
|
|
||||||
let template = v8::FunctionTemplate::builder(slow_fn)
|
let template = v8::FunctionTemplate::builder(slow_fn)
|
||||||
.data(external.into())
|
.data(external.into())
|
||||||
.build_fast(scope, &FastTest, None);
|
.build_fast(scope, &FastTest, None, None, None);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "func").unwrap();
|
let name = v8::String::new(scope, "func").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
@ -8936,8 +8938,8 @@ fn test_fast_calls_onebytestring() {
|
||||||
|
|
||||||
let global = context.global(scope);
|
let global = context.global(scope);
|
||||||
|
|
||||||
let template =
|
let template = v8::FunctionTemplate::builder(slow_fn)
|
||||||
v8::FunctionTemplate::builder(slow_fn).build_fast(scope, &FastTest, None);
|
.build_fast(scope, &FastTest, None, None, None);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "func").unwrap();
|
let name = v8::String::new(scope, "func").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
@ -9076,8 +9078,8 @@ fn test_fast_calls_pointer() {
|
||||||
|
|
||||||
let global = context.global(scope);
|
let global = context.global(scope);
|
||||||
|
|
||||||
let template =
|
let template = v8::FunctionTemplate::builder(slow_fn)
|
||||||
v8::FunctionTemplate::builder(slow_fn).build_fast(scope, &FastTest, None);
|
.build_fast(scope, &FastTest, None, None, None);
|
||||||
|
|
||||||
let name = v8::String::new(scope, "func").unwrap();
|
let name = v8::String::new(scope, "func").unwrap();
|
||||||
let value = template.get_function(scope).unwrap();
|
let value = template.get_function(scope).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue