mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-11 16:42:32 -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:
parent
fb049cb934
commit
315e9a83e0
2 changed files with 11 additions and 15 deletions
|
@ -1264,16 +1264,11 @@ const v8::StackTrace* v8__Exception__GetStackTrace(const v8::Value& exception) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const v8::Function* v8__Function__New(const v8::Context& context,
|
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,
|
v8::FunctionCallback callback,
|
||||||
const v8::Value& data) {
|
const v8::Value* maybe_data) {
|
||||||
return maybe_local_to_ptr(
|
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,
|
const v8::Value* v8__Function__Call(const v8::Function& self,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use std::ptr::null;
|
||||||
|
|
||||||
use crate::scope::CallbackScope;
|
use crate::scope::CallbackScope;
|
||||||
use crate::support::MapFnFrom;
|
use crate::support::MapFnFrom;
|
||||||
|
@ -19,10 +20,6 @@ extern "C" {
|
||||||
fn v8__Function__New(
|
fn v8__Function__New(
|
||||||
context: *const Context,
|
context: *const Context,
|
||||||
callback: FunctionCallback,
|
callback: FunctionCallback,
|
||||||
) -> *const Function;
|
|
||||||
fn v8__Function__NewWithData(
|
|
||||||
context: *const Context,
|
|
||||||
callback: FunctionCallback,
|
|
||||||
data: *const Value,
|
data: *const Value,
|
||||||
) -> *const Function;
|
) -> *const Function;
|
||||||
fn v8__Function__Call(
|
fn v8__Function__Call(
|
||||||
|
@ -294,7 +291,11 @@ impl Function {
|
||||||
) -> Option<Local<'s, Function>> {
|
) -> Option<Local<'s, Function>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
scope.cast_local(|sd| {
|
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>> {
|
) -> Option<Local<'s, Function>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
scope.cast_local(|sd| {
|
scope.cast_local(|sd| {
|
||||||
v8__Function__NewWithData(
|
v8__Function__New(
|
||||||
sd.get_current_context(),
|
sd.get_current_context(),
|
||||||
callback.map_fn_to(),
|
callback.map_fn_to(),
|
||||||
&*data,
|
&*data,
|
||||||
|
|
Loading…
Reference in a new issue