![]() |
v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
|
#include <v8-template.h>
Private Member Functions | |
FunctionTemplate () | |
Static Private Member Functions | |
static void | CheckCast (Data *that) |
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.
Definition at line 584 of file v8-template.h.
|
private |
|
static |
|
staticprivate |
MaybeLocal< v8::Function > v8::FunctionTemplate::GetFunction | ( | Local< Context > | context | ) |
void v8::FunctionTemplate::Inherit | ( | v8::Local< FunctionTemplate > | value | ) |
Local< ObjectTemplate > v8::FunctionTemplate::InstanceTemplate | ( | ) |
Returns true if the given value is an API object that was constructed by an instance of this function template (without checking for inheriting function templates).
This is an experimental feature and may still change significantly.
Definition at line 7468 of file api.cc.
|
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.
Definition at line 7423 of file api.cc.
|
static |
|
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.
Definition at line 1358 of file api.cc.
void v8::FunctionTemplate::RemovePrototype | ( | ) |
Removes the prototype property from functions created from this FunctionTemplate.
Definition at line 1366 of file api.cc.
void v8::FunctionTemplate::SealAndPrepareForPromotionToReadOnly | ( | ) |
void v8::FunctionTemplate::SetAcceptAnyReceiver | ( | bool | value | ) |
void v8::FunctionTemplate::SetCallHandler | ( | FunctionCallback | callback, |
v8::Local< Value > | data = Local<Value>(), | ||
SideEffectType | side_effect_type = SideEffectType::kHasSideEffect, | ||
const MemorySpan< const CFunction > & | c_function_overloads = {} ) |
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.
Definition at line 1216 of file api.cc.
Set the class name of the FunctionTemplate. This is used for printing objects created with the function created from the FunctionTemplate as its constructor.
Definition at line 1326 of file api.cc.
void v8::FunctionTemplate::SetExceptionContext | ( | ExceptionContext | context | ) |
Provides information on the type of FunctionTemplate for embedder exception handling.
Definition at line 1342 of file api.cc.
Set the interface name of the FunctionTemplate. This is provided as contextual information in an ExceptionPropagationMessage to the embedder.
Definition at line 1334 of file api.cc.
void v8::FunctionTemplate::SetLength | ( | int | length | ) |
Set the predefined length property for the FunctionTemplate.
Definition at line 1318 of file api.cc.
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().
Definition at line 1032 of file api.cc.
|
friend |
Definition at line 732 of file v8-template.h.
|
friend |
Definition at line 733 of file v8-template.h.