pub struct FunctionBuilder<'s, T> { /* private fields */ }Expand description
A builder to construct the properties of a Function or FunctionTemplate.
Implementations§
Source§impl<'s, T> FunctionBuilder<'s, T>
impl<'s, T> FunctionBuilder<'s, T>
Sourcepub fn new(
callback: impl MapFnTo<unsafe extern "C" fn(*const FunctionCallbackInfo)>,
) -> FunctionBuilder<'s, T>
pub fn new( callback: impl MapFnTo<unsafe extern "C" fn(*const FunctionCallbackInfo)>, ) -> FunctionBuilder<'s, T>
Create a new FunctionBuilder.
pub fn new_raw( callback: unsafe extern "C" fn(*const FunctionCallbackInfo), ) -> FunctionBuilder<'s, T>
Sourcepub fn data(self, data: Local<'s, Value>) -> FunctionBuilder<'s, T>
pub fn data(self, data: Local<'s, Value>) -> FunctionBuilder<'s, T>
Set the associated data. The default is no associated data.
Sourcepub fn length(self, length: i32) -> FunctionBuilder<'s, T>
pub fn length(self, length: i32) -> FunctionBuilder<'s, T>
Set the function length. The default is 0.
Sourcepub fn constructor_behavior(
self,
constructor_behavior: ConstructorBehavior,
) -> FunctionBuilder<'s, T>
pub fn constructor_behavior( self, constructor_behavior: ConstructorBehavior, ) -> FunctionBuilder<'s, T>
Set the constructor behavior. The default is ConstructorBehavior::Allow.
Sourcepub fn side_effect_type(
self,
side_effect_type: SideEffectType,
) -> FunctionBuilder<'s, T>
pub fn side_effect_type( self, side_effect_type: SideEffectType, ) -> FunctionBuilder<'s, T>
Set the side effect type. The default is SideEffectType::HasSideEffect.
Source§impl<'s> FunctionBuilder<'s, Function>
impl<'s> FunctionBuilder<'s, Function>
Source§impl<'s> FunctionBuilder<'s, FunctionTemplate>
impl<'s> FunctionBuilder<'s, FunctionTemplate>
Sourcepub fn signature(
self,
signature: Local<'s, Signature>,
) -> FunctionBuilder<'s, FunctionTemplate>
pub fn signature( self, signature: Local<'s, Signature>, ) -> FunctionBuilder<'s, FunctionTemplate>
Set the function call signature. The default is no signature.
Sourcepub fn build<'i>(
self,
scope: &PinnedRef<'s, HandleScope<'i, ()>>,
) -> Local<'s, FunctionTemplate>
pub fn build<'i>( self, scope: &PinnedRef<'s, HandleScope<'i, ()>>, ) -> Local<'s, FunctionTemplate>
Creates the function template.
Sourcepub fn build_fast<'i>(
self,
scope: &PinnedRef<'s, HandleScope<'i>>,
overloads: &'static [CFunction],
) -> Local<'s, FunctionTemplate>
pub fn build_fast<'i>( self, scope: &PinnedRef<'s, HandleScope<'i>>, overloads: &'static [CFunction], ) -> Local<'s, FunctionTemplate>
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.
§Lifetime invariant
overloads is &'static [CFunction] because, since
crrev.com/c/7828135, V8 stores the raw v8::CFunction pointers it
receives via NewWithCFunctionOverloads directly inside
FunctionTemplateInfo (rather than copying them into a managed heap
object). The pointed-to storage must therefore outlive every
FunctionTemplate that references it. A FunctionTemplate may live
until isolate disposal, so in practice this requires the slice (and its
elements, including the CFunctionInfos they reference) to have
'static storage. Use a const slice such as
const OVERLOADS: &[v8::fast_api::CFunction] = &[FAST_TEST];or a static item; do not synthesize the slice from stack-local
data.