v8
9.0.257(node16.0.0)
V8 is Google's open source JavaScript engine
|
#include <v8.h>
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, const CFunction *c_function=nullptr) |
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:
The additional 'c_function' parameter refers to a fast API call, which must not trigger GC or JavaScript execution, or call into V8 in other ways. For more information how to define them, see include/v8-fast-api-calls.h. Please note that this feature is still experimental.
|
static |
V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction | ( | Local< Context > | context | ) |
Returns the unique function instance in the current execution context.
Returns true if the given object is an instance of this function template.
void Inherit | ( | Local< FunctionTemplate > | parent | ) |
Causes the function template to inherit from a parent function template. This means the function's prototype.__proto__ is set to the parent function's prototype.
Local<ObjectTemplate> InstanceTemplate | ( | ) |
Get the InstanceTemplate.
|
static |
Creates a function template.
V8_WARN_UNUSED_RESULT MaybeLocal<Object> 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 |
Creates a function template backed/cached by a private property.
Local<ObjectTemplate> PrototypeTemplate | ( | ) |
A PrototypeTemplate is the template used to create the prototype object of the function created by this template.
void ReadOnlyPrototype | ( | ) |
Sets the ReadOnly flag in the attributes of the 'prototype' property of functions created from this FunctionTemplate to true.
void RemovePrototype | ( | ) |
Removes the prototype property from functions created from this FunctionTemplate.
void SetAcceptAnyReceiver | ( | bool | value | ) |
When set to true, no access check will be performed on the receiver of a function call. Currently defaults to true, but this is subject to change.
void SetCallHandler | ( | FunctionCallback | callback, |
Local< Value > | data = Local< Value >() , |
||
SideEffectType | side_effect_type = SideEffectType::kHasSideEffect , |
||
const CFunction * | c_function = nullptr |
||
) |
Set the call-handler callback for a FunctionTemplate. This callback is called whenever the function created from this FunctionTemplate is called. The 'c_function' represents a fast API call, see the comment above the class declaration.
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 SetLength | ( | int | length | ) |
Set the predefined length property for the FunctionTemplate.
void 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().
|
friend |