v8
3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
|
#include <v8.h>
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) |
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:
Local< v8::Function > GetFunction | ( | ) |
Returns the unique function instance in the current execution context.
Definition at line 5299 of file api.cc.
References ENTER_V8, EXCEPTION_BAILOUT_CHECK, EXCEPTION_PREAMBLE, Execution::InstantiateFunction(), LOG_API, ON_BAILOUT, Utils::OpenHandle(), and Utils::ToLocal().
Referenced by CreateFramePointerGrabberConstructor(), TEST(), RequestInterruptTestWithMethodCall::TestBody(), RequestInterruptTestWithAccessor::TestBody(), RequestInterruptTestWithNativeAccessor::TestBody(), RequestInterruptTestWithMethodCallAndInterceptor::TestBody(), THREADED_PROFILED_TEST(), and THREADED_TEST().
Returns true if the given object is an instance of this function template.
Definition at line 5314 of file api.cc.
References ON_BAILOUT, and Utils::OpenHandle().
void Inherit | ( | v8::Handle< FunctionTemplate > | value | ) |
Causes the function template to inherit from a parent function template.
Definition at line 902 of file api.cc.
References ENTER_V8, and Utils::OpenHandle().
Referenced by THREADED_TEST().
Local< ObjectTemplate > InstanceTemplate | ( | ) |
Get the InstanceTemplate.
Definition at line 1223 of file api.cc.
References Utils::ApiCheck(), ObjectTemplateInfo::cast(), ENTER_V8, v8::internal::handle(), ObjectTemplate::New(), NULL, Utils::OpenHandle(), and Utils::ToLocal().
Referenced by TEST(), RequestInterruptTestWithNativeAccessor::TestBody(), RequestInterruptTestWithMethodCallAndInterceptor::TestBody(), THREADED_PROFILED_TEST(), and THREADED_TEST().
|
static |
Creates a function template.
Definition at line 942 of file api.cc.
References ENTER_V8, and LOG_API.
Referenced by Shell::AddOSMethods(), CreateFramePointerGrabberConstructor(), CreateGlobalTemplate(), CreateShellContext(), TriggerFailureExtension::GetNativeFunctionTemplate(), PrintExtension::GetNativeFunctionTemplate(), ExternalizeStringExtension::GetNativeFunctionTemplate(), TraceExtension::GetNativeFunctionTemplate(), StatisticsExtension::GetNativeFunctionTemplate(), FreeBufferExtension::GetNativeFunctionTemplate(), ProfilerExtension::GetNativeFunctionTemplate(), GCExtension::GetNativeFunctionTemplate(), NativeFunctionExtension::GetNativeFunctionTemplate(), FunctionExtension::GetNativeFunctionTemplate(), SetFunctionEntryHookTest::RunLoopInNewEnv(), RunMain(), TEST(), RequestInterruptTestWithMethodCall::TestBody(), RequestInterruptTestWithAccessor::TestBody(), RequestInterruptTestWithNativeAccessor::TestBody(), RequestInterruptTestWithMethodCallAndInterceptor::TestBody(), TestFastReturnValues(), THREADED_PROFILED_TEST(), and THREADED_TEST().
Local< ObjectTemplate > PrototypeTemplate | ( | ) |
A PrototypeTemplate is the template used to create the prototype object of the function created by this template.
Definition at line 888 of file api.cc.
References ENTER_V8, ObjectTemplate::New(), Utils::OpenHandle(), and v8::internal::prototype_template.
Referenced by TEST(), RequestInterruptTestWithMethodCall::TestBody(), RequestInterruptTestWithAccessor::TestBody(), RequestInterruptTestWithMethodCallAndInterceptor::TestBody(), THREADED_PROFILED_TEST(), and THREADED_TEST().
void ReadOnlyPrototype | ( | ) |
Sets the ReadOnly flag in the attributes of the 'prototype' property of functions created from this FunctionTemplate to true.
Definition at line 1264 of file api.cc.
References ENTER_V8, and Utils::OpenHandle().
void RemovePrototype | ( | ) |
Removes the prototype property from functions created from this FunctionTemplate.
Definition at line 1271 of file api.cc.
References ENTER_V8, and Utils::OpenHandle().
void 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 1148 of file api.cc.
References v8::internal::CALL_HANDLER_INFO_TYPE, Handle< T >::cast(), ENTER_V8, Isolate::factory(), Handle< T >::IsEmpty(), Factory::NewStruct(), 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 1250 of file api.cc.
References ENTER_V8, and Utils::OpenHandle().
Referenced by CreateFramePointerGrabberConstructor(), TEST(), and THREADED_TEST().
void 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 1257 of file api.cc.
References ENTER_V8, and Utils::OpenHandle().
Referenced by TEST(), and THREADED_PROFILED_TEST().
void SetLength | ( | int | length | ) |
Set the predefined length property for the FunctionTemplate.
Definition at line 1243 of file api.cc.
References ENTER_V8, and Utils::OpenHandle().
|
friend |