0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-11 08:34:01 -05:00

Simplify Function::new_with_data() (#510)

It's not necessary to have a separate C++ glue function, it can be
shared with Function::new().
This commit is contained in:
Ben Noordhuis 2020-10-27 15:15:00 +01:00 committed by GitHub
parent fb049cb934
commit 315e9a83e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 15 deletions

View file

@ -1264,16 +1264,11 @@ const v8::StackTrace* v8__Exception__GetStackTrace(const v8::Value& exception) {
}
const v8::Function* v8__Function__New(const v8::Context& context,
v8::FunctionCallback callback) {
return maybe_local_to_ptr(
v8::Function::New(ptr_to_local(&context), callback));
}
const v8::Function* v8__Function__NewWithData(const v8::Context& context,
v8::FunctionCallback callback,
const v8::Value& data) {
const v8::Value* maybe_data) {
return maybe_local_to_ptr(
v8::Function::New(ptr_to_local(&context), callback, ptr_to_local(&data)));
v8::Function::New(ptr_to_local(&context), callback,
ptr_to_local(maybe_data)));
}
const v8::Value* v8__Function__Call(const v8::Function& self,

View file

@ -1,5 +1,6 @@
use std::convert::TryFrom;
use std::marker::PhantomData;
use std::ptr::null;
use crate::scope::CallbackScope;
use crate::support::MapFnFrom;
@ -19,10 +20,6 @@ extern "C" {
fn v8__Function__New(
context: *const Context,
callback: FunctionCallback,
) -> *const Function;
fn v8__Function__NewWithData(
context: *const Context,
callback: FunctionCallback,
data: *const Value,
) -> *const Function;
fn v8__Function__Call(
@ -294,7 +291,11 @@ impl Function {
) -> Option<Local<'s, Function>> {
unsafe {
scope.cast_local(|sd| {
v8__Function__New(sd.get_current_context(), callback.map_fn_to())
v8__Function__New(
sd.get_current_context(),
callback.map_fn_to(),
null(),
)
})
}
}
@ -308,7 +309,7 @@ impl Function {
) -> Option<Local<'s, Function>> {
unsafe {
scope.cast_local(|sd| {
v8__Function__NewWithData(
v8__Function__New(
sd.get_current_context(),
callback.map_fn_to(),
&*data,