V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
|
#include <v8.h>
Public Member Functions | |
V8_DEPRECATED ("Use maybe version", Local< Function > GetFunction()) | |
V8_WARN_UNUSED_RESULT MaybeLocal< Function > | GetFunction (Local< Context > context) |
V8_WARN_UNUSED_RESULT MaybeLocal< Object > | NewRemoteInstance () |
void | SetCallHandler (FunctionCallback callback, Local< Value > data=Local< Value >(), SideEffectType side_effect_type=SideEffectType::kHasSideEffect) |
void | SetLength (int length) |
Local< ObjectTemplate > | InstanceTemplate () |
void | Inherit (Local< FunctionTemplate > parent) |
Local< ObjectTemplate > | PrototypeTemplate () |
void | SetPrototypeProviderTemplate (Local< FunctionTemplate > prototype_provider) |
void | SetClassName (Local< String > name) |
void | SetAcceptAnyReceiver (bool value) |
void | SetHiddenPrototype (bool value) |
void | ReadOnlyPrototype () |
void | RemovePrototype () |
bool | HasInstance (Local< Value > object) |
Public Member Functions inherited from v8::Template | |
void | Set (Local< Name > name, Local< Data > value, PropertyAttribute attributes=None) |
void | SetPrivate (Local< Private > name, Local< Data > value, PropertyAttribute attributes=None) |
V8_INLINE void | Set (Isolate *isolate, const char *name, Local< Data > value) |
void | SetAccessorProperty (Local< Name > name, Local< FunctionTemplate > getter=Local< FunctionTemplate >(), Local< FunctionTemplate > setter=Local< FunctionTemplate >(), PropertyAttribute attribute=None, AccessControl settings=DEFAULT) |
void | SetNativeDataProperty (Local< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), PropertyAttribute attribute=None, Local< AccessorSignature > signature=Local< AccessorSignature >(), AccessControl settings=DEFAULT, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect) |
void | SetNativeDataProperty (Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=nullptr, Local< Value > data=Local< Value >(), PropertyAttribute attribute=None, Local< AccessorSignature > signature=Local< AccessorSignature >(), AccessControl settings=DEFAULT, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect) |
void | SetLazyDataProperty (Local< Name > name, AccessorNameGetterCallback getter, Local< Value > data=Local< Value >(), PropertyAttribute attribute=None, SideEffectType getter_side_effect_type=SideEffectType::kHasSideEffect, SideEffectType setter_side_effect_type=SideEffectType::kHasSideEffect) |
void | SetIntrinsicDataProperty (Local< Name > name, Intrinsic intrinsic, PropertyAttribute attribute=None) |
Static Public Member Functions | |
static Local< FunctionTemplate > | New (Isolate *isolate, FunctionCallback callback=nullptr, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect) |
static MaybeLocal< FunctionTemplate > | FromSnapshot (Isolate *isolate, size_t index) |
static Local< FunctionTemplate > | NewWithCache (Isolate *isolate, FunctionCallback callback, Local< Private > cache_property, Local< Value > data=Local< Value >(), Local< Signature > signature=Local< Signature >(), int length=0, SideEffectType side_effect_type=SideEffectType::kHasSideEffect) |
static V8_INLINE FunctionTemplate * | Cast (Data *data) |
Friends | |
class | Context |
class | ObjectTemplate |
A FunctionTemplate is used to create functions at runtime. There can only be one function created from a FunctionTemplate in a context. The lifetime of the created function is equal to the lifetime of the context. So in case the embedder needs to create temporary functions that can be collected using Scripts is preferred.
Any modification of a FunctionTemplate after first instantiation will trigger a crash.
A FunctionTemplate can have properties, these properties are added to the function object when it is created.
A FunctionTemplate has a corresponding instance template which is used to create object instances when the function is used as a constructor. Properties added to the instance template are added to each object instance.
A FunctionTemplate can have a prototype template. The prototype template is used to create the prototype object of the function.
The following example shows how to use a FunctionTemplate:
Let's use "function" as the JS variable name of the function object and "instance" for the instance object created above. The function and the instance will have the following properties:
A FunctionTemplate can inherit from another one by calling the FunctionTemplate::Inherit method. The following graph illustrates the semantics of inheritance:
A FunctionTemplate 'Child' inherits from 'Parent', the prototype object of the Child() function has proto pointing to the Parent() function's prototype object. An instance of the Child function has all properties on Parent's instance templates.
Let Parent be the FunctionTemplate initialized in the previous section and create a Child FunctionTemplate by:
The Child function and Child instance will have the following properties:
|
static |
void v8::FunctionTemplate::Inherit | ( | v8::Local< FunctionTemplate > | value | ) |
Local< ObjectTemplate > v8::FunctionTemplate::InstanceTemplate | ( | ) |
|
static |
MaybeLocal< v8::Object > v8::FunctionTemplate::NewRemoteInstance | ( | ) |
Similar to Context::NewRemoteContext, this creates an instance that isn't backed by an actual object.
The InstanceTemplate of this FunctionTemplate must have access checks with handlers installed.
|
static |
Local< ObjectTemplate > v8::FunctionTemplate::PrototypeTemplate | ( | ) |
void v8::FunctionTemplate::ReadOnlyPrototype | ( | ) |
Sets the ReadOnly flag in the attributes of the 'prototype' property of functions created from this FunctionTemplate to true.
void v8::FunctionTemplate::RemovePrototype | ( | ) |
Removes the prototype property from functions created from this FunctionTemplate.
void v8::FunctionTemplate::SetAcceptAnyReceiver | ( | bool | value | ) |
void v8::FunctionTemplate::SetCallHandler | ( | FunctionCallback | callback, |
v8::Local< Value > | data = Local<Value>() , |
||
SideEffectType | side_effect_type = SideEffectType::kHasSideEffect |
||
) |
Set the call-handler callback for a FunctionTemplate. This callback is called whenever the function created from this FunctionTemplate is called.
Set the class name of the FunctionTemplate. This is used for printing objects created with the function created from the FunctionTemplate as its constructor.
void v8::FunctionTemplate::SetHiddenPrototype | ( | bool | value | ) |
Determines whether the proto accessor ignores instances of the function template. If instances of the function template are ignored, proto skips all instances and instead returns the next object in the prototype chain.
Call with a value of true to make the proto accessor ignore instances of the function template. Call with a value of false to make the proto accessor not ignore instances of the function template. By default, instances of a function template are not ignored.
void v8::FunctionTemplate::SetLength | ( | int | length | ) |
Set the predefined length property for the FunctionTemplate.
void v8::FunctionTemplate::SetPrototypeProviderTemplate | ( | Local< FunctionTemplate > | prototype_provider | ) |
A PrototypeProviderTemplate is another function template whose prototype property is used for this template. This is mutually exclusive with setting a prototype template indirectly by calling PrototypeTemplate() or using Inherit().
Returns the unique function instance in the current execution context.