Skip to main content

FunctionBuilder

Struct FunctionBuilder 

Source
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>

Source

pub fn new( callback: impl MapFnTo<unsafe extern "C" fn(*const FunctionCallbackInfo)>, ) -> FunctionBuilder<'s, T>

Create a new FunctionBuilder.

Source

pub fn new_raw( callback: unsafe extern "C" fn(*const FunctionCallbackInfo), ) -> FunctionBuilder<'s, T>

Source

pub fn data(self, data: Local<'s, Value>) -> FunctionBuilder<'s, T>

Set the associated data. The default is no associated data.

Source

pub fn length(self, length: i32) -> FunctionBuilder<'s, T>

Set the function length. The default is 0.

Source

pub fn constructor_behavior( self, constructor_behavior: ConstructorBehavior, ) -> FunctionBuilder<'s, T>

Set the constructor behavior. The default is ConstructorBehavior::Allow.

Source

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>

Source

pub fn build<'i>( self, scope: &PinnedRef<'s, HandleScope<'i>>, ) -> Option<Local<'s, Function>>

Create the function in the current execution context.

Source§

impl<'s> FunctionBuilder<'s, FunctionTemplate>

Source

pub fn signature( self, signature: Local<'s, Signature>, ) -> FunctionBuilder<'s, FunctionTemplate>

Set the function call signature. The default is no signature.

Source

pub fn build<'i>( self, scope: &PinnedRef<'s, HandleScope<'i, ()>>, ) -> Local<'s, FunctionTemplate>

Creates the function template.

Source

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.

Auto Trait Implementations§

§

impl<'s, T> !Send for FunctionBuilder<'s, T>

§

impl<'s, T> !Sync for FunctionBuilder<'s, T>

§

impl<'s, T> Freeze for FunctionBuilder<'s, T>
where PhantomData<T>: Freeze,

§

impl<'s, T> RefUnwindSafe for FunctionBuilder<'s, T>

§

impl<'s, T> Unpin for FunctionBuilder<'s, T>
where PhantomData<T>: Unpin,

§

impl<'s, T> UnsafeUnpin for FunctionBuilder<'s, T>

§

impl<'s, T> UnwindSafe for FunctionBuilder<'s, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.