From a043407ae8d5ea65ecc60a04da0508802a76ff41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Mon, 8 Nov 2021 19:51:53 -0100 Subject: [PATCH] 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. --- src/function.rs | 5 +++-- tests/test_api.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/function.rs b/src/function.rs index 3f6b6e6f..8c1d10cb 100644 --- a/src/function.rs +++ b/src/function.rs @@ -273,9 +273,10 @@ impl<'s> PropertyCallbackArguments<'s> { pub type FunctionCallback = extern "C" fn(*const FunctionCallbackInfo); -impl MapFnFrom for FunctionCallback +impl<'a, F> MapFnFrom 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| { diff --git a/tests/test_api.rs b/tests/test_api.rs index 390d1a19..72f6eceb 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -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 = 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