V8 Project
|
A FunctionTemplate is used to create functions at runtime. More...
#include <v8.h>
Public Member Functions | |
Local< Function > | GetFunction () |
Returns the unique function instance in the current execution context. More... | |
void | SetCallHandler (FunctionCallback callback, Handle< Value > data=Handle< Value >()) |
Set the call-handler callback for a FunctionTemplate. More... | |
void | SetLength (int length) |
Set the predefined length property for the FunctionTemplate. More... | |
Local< ObjectTemplate > | InstanceTemplate () |
Get the InstanceTemplate. More... | |
void | Inherit (Handle< FunctionTemplate > parent) |
Causes the function template to inherit from a parent function template. More... | |
Local< ObjectTemplate > | PrototypeTemplate () |
A PrototypeTemplate is the template used to create the prototype object of the function created by this template. More... | |
void | SetClassName (Handle< String > name) |
Set the class name of the FunctionTemplate. More... | |
void | SetHiddenPrototype (bool value) |
Determines whether the proto accessor ignores instances of the function template. More... | |
void | ReadOnlyPrototype () |
Sets the ReadOnly flag in the attributes of the 'prototype' property of functions created from this FunctionTemplate to true. More... | |
void | RemovePrototype () |
Removes the prototype property from functions created from this FunctionTemplate. More... | |
bool | HasInstance (Handle< Value > object) |
Returns true if the given object is an instance of this function template. More... | |
![]() | |
void | Set (Handle< Name > name, Handle< Data > value, PropertyAttribute attributes=None) |
Adds a property to each instance created by this template. More... | |
void | Set (Isolate *isolate, const char *name, Handle< 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=0, Handle< Value > data=Handle< Value >(), PropertyAttribute attribute=None, Local< AccessorSignature > signature=Local< AccessorSignature >(), AccessControl settings=DEFAULT) |
Whenever the property with the given name is accessed on objects created from this Template the getter and setter callbacks are called instead of getting and setting the property directly on the JavaScript object. More... | |
void | SetNativeDataProperty (Local< Name > name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter=0, Handle< Value > data=Handle< Value >(), PropertyAttribute attribute=None, Local< AccessorSignature > signature=Local< AccessorSignature >(), AccessControl settings=DEFAULT) |
bool | SetDeclaredAccessor (Local< Name > name, Local< DeclaredAccessorDescriptor > descriptor, PropertyAttribute attribute=None, Local< AccessorSignature > signature=Local< AccessorSignature >(), AccessControl settings=DEFAULT) |
Static Public Member Functions | |
static Local< FunctionTemplate > | New (Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0) |
Creates a function template. More... | |
Private Member Functions | |
FunctionTemplate () | |
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.
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:
|
private |
Local< v8::Function > v8::FunctionTemplate::GetFunction | ( | ) |
Returns the unique function instance in the current execution context.
Definition at line 5327 of file api.cc.
References ENTER_V8, EXCEPTION_BAILOUT_CHECK, EXCEPTION_PREAMBLE, LOG_API, ON_BAILOUT, v8::Utils::OpenHandle(), and v8::Utils::ToLocal().
Returns true if the given object is an instance of this function template.
Definition at line 5342 of file api.cc.
References ON_BAILOUT, and v8::Utils::OpenHandle().
void v8::FunctionTemplate::Inherit | ( | v8::Handle< FunctionTemplate > | value | ) |
Causes the function template to inherit from a parent function template.
Definition at line 864 of file api.cc.
References ENTER_V8, and v8::Utils::OpenHandle().
Local< ObjectTemplate > v8::FunctionTemplate::InstanceTemplate | ( | ) |
Get the InstanceTemplate.
Definition at line 1181 of file api.cc.
References v8::Utils::ApiCheck(), ENTER_V8, v8::internal::handle(), v8::ObjectTemplate::New(), v8::Utils::OpenHandle(), and v8::Utils::ToLocal().
|
static |
Creates a function template.
Definition at line 904 of file api.cc.
References ENTER_V8, v8::FunctionTemplateNew(), and LOG_API.
Referenced by v8::Shell::AddOSMethods(), v8::Shell::CreateGlobalTemplate(), v8::EnsureConstructor(), v8::internal::ExternalizeStringExtension::GetNativeFunctionTemplate(), v8::internal::FreeBufferExtension::GetNativeFunctionTemplate(), v8::internal::GCExtension::GetNativeFunctionTemplate(), v8::internal::StatisticsExtension::GetNativeFunctionTemplate(), and v8::internal::TriggerFailureExtension::GetNativeFunctionTemplate().
Local< ObjectTemplate > v8::FunctionTemplate::PrototypeTemplate | ( | ) |
A PrototypeTemplate is the template used to create the prototype object of the function created by this template.
Definition at line 850 of file api.cc.
References ENTER_V8, v8::ObjectTemplate::New(), v8::Utils::OpenHandle(), and v8::internal::prototype_template.
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 1222 of file api.cc.
References ENTER_V8, and v8::Utils::OpenHandle().
void v8::FunctionTemplate::RemovePrototype | ( | ) |
Removes the prototype property from functions created from this FunctionTemplate.
Definition at line 1229 of file api.cc.
References ENTER_V8, and v8::Utils::OpenHandle().
void v8::FunctionTemplate::SetCallHandler | ( | FunctionCallback | callback, |
v8::Handle< Value > | data = Handle<Value>() |
||
) |
Set the call-handler callback for a FunctionTemplate.
This callback is called whenever the function created from this FunctionTemplate is called.
Definition at line 1107 of file api.cc.
References v8::internal::CALL_HANDLER_INFO_TYPE, v8::internal::Handle< T >::cast(), ENTER_V8, v8::internal::Isolate::factory(), v8::Handle< T >::IsEmpty(), v8::Utils::OpenHandle(), SET_FIELD_WRAPPED, and v8::Undefined().
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 1208 of file api.cc.
References ENTER_V8, name, and v8::Utils::OpenHandle().
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.
Definition at line 1215 of file api.cc.
References ENTER_V8, and v8::Utils::OpenHandle().
void v8::FunctionTemplate::SetLength | ( | int | length | ) |
Set the predefined length property for the FunctionTemplate.
Definition at line 1201 of file api.cc.
References ENTER_V8, and v8::Utils::OpenHandle().
|
friend |