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

Make lifetime in FunctionCallback signature more restrictive (#822)

This makes the callbacks themselves less restrictive. A test is added
the would fail to compile before.
This commit is contained in:
Rafael Ávila de Espíndola 2021-11-08 19:51:53 -01:00 committed by GitHub
parent 6094410c8d
commit a043407ae8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View file

@ -273,9 +273,10 @@ impl<'s> PropertyCallbackArguments<'s> {
pub type FunctionCallback = extern "C" fn(*const FunctionCallbackInfo);
impl<F> MapFnFrom<F> for FunctionCallback
impl<'a, F> MapFnFrom<F> for FunctionCallback
where
F: UnitType + Fn(&mut HandleScope, FunctionCallbackArguments, ReturnValue),
F: UnitType
+ Fn(&mut HandleScope<'a>, FunctionCallbackArguments<'a>, ReturnValue),
{
fn mapping() -> Self {
let f = |info: *const FunctionCallbackInfo| {

View file

@ -1901,6 +1901,21 @@ fn data_is_true_callback(
assert!(data.is_true());
}
fn nested_builder<'a>(
scope: &mut v8::HandleScope<'a>,
args: v8::FunctionCallbackArguments<'a>,
_: v8::ReturnValue,
) {
let arg0 = args.get(0);
v8::Function::builder(
|_: &mut v8::HandleScope,
_: v8::FunctionCallbackArguments,
_: v8::ReturnValue| {},
)
.data(arg0)
.build(scope);
}
#[test]
fn function() {
let _setup_guard = setup();
@ -1913,6 +1928,9 @@ fn function() {
let global = context.global(scope);
let recv: v8::Local<v8::Value> = global.into();
// Just check that this compiles.
v8::Function::builder(nested_builder);
// create function using template
let fn_template = v8::FunctionTemplate::new(scope, fn_callback);
let function = fn_template