📄 v8.h.svn-base
字号:
* the kind of cross-context access that should be allowed. */enum AccessControl { DEFAULT = 0, ALL_CAN_READ = 1, ALL_CAN_WRITE = 2};/** * Access type specification. */enum AccessType { ACCESS_GET, ACCESS_SET, ACCESS_HAS, ACCESS_DELETE, ACCESS_KEYS};/** * Returns true if cross-context access should be allowed to the named * property with the given key on the global object. */typedef bool (*NamedSecurityCallback)(Local<Object> global, Local<Value> key, AccessType type, Local<Value> data);/** * Returns true if cross-context access should be allowed to the indexed * property with the given index on the global object. */typedef bool (*IndexedSecurityCallback)(Local<Object> global, uint32_t index, AccessType type, Local<Value> data);/** * A FunctionTemplate is used to create functions at runtime. There * can only be one function created from a FunctionTemplate in a * context. * * 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: * * \code * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); * t->Set("func_property", v8::Number::New(1)); * * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); * proto_t->Set("proto_const", v8::Number::New(2)); * * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); * instance_t->Set("instance_property", Number::New(3)); * * v8::Local<v8::Function> function = t->GetFunction(); * v8::Local<v8::Object> instance = function->NewInstance(); * \endcode * * 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: * * \code * func_property in function == true; * function.func_property == 1; * * function.prototype.proto_method() invokes 'InvokeCallback' * function.prototype.proto_const == 2; * * instance instanceof function == true; * instance.instance_accessor calls 'InstanceAccessorCallback' * instance.instance_property == 3; * \endcode * * A FunctionTemplate can inherit from another one by calling the * FunctionTemplate::Inherit method. The following graph illustrates * the semantics of inheritance: * * \code * FunctionTemplate Parent -> Parent() . prototype -> { } * ^ ^ * | Inherit(Parent) | .__proto__ * | | * FunctionTemplate Child -> Child() . prototype -> { } * \endcode * * 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: * * \code * Local<FunctionTemplate> parent = t; * Local<FunctionTemplate> child = FunctionTemplate::New(); * child->Inherit(parent); * * Local<Function> child_function = child->GetFunction(); * Local<Object> child_instance = child_function->NewInstance(); * \endcode * * The Child function and Child instance will have the following * properties: * * \code * child_func.prototype.__proto__ == function.prototype; * child_instance.instance_accessor calls 'InstanceAccessorCallback' * child_instance.instance_property == 3; * \endcode */class EXPORT FunctionTemplate : public Template { public: /** Creates a function template.*/ static Local<FunctionTemplate> New( InvocationCallback callback = 0, Handle<Value> data = Handle<Value>(), Handle<Signature> signature = Handle<Signature>()); /** Returns the unique function instance in the current execution context.*/ Local<Function> GetFunction(); /** * Set the call-handler callback for a FunctionTemplate. This * callback is called whenever the function created from this * FunctionTemplate is called. */ void SetCallHandler(InvocationCallback callback, Handle<Value> data = Handle<Value>()); /** Get the InstanceTemplate. */ Local<ObjectTemplate> InstanceTemplate(); /** Causes the function template to inherit from a parent function template.*/ void Inherit(Handle<FunctionTemplate> parent); /** * A PrototypeTemplate is the template used to create the prototype object * of the function created by this template. */ Local<ObjectTemplate> PrototypeTemplate(); /** * 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 SetClassName(Handle<String> name); /** * 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 SetHiddenPrototype(bool value); /** * Returns true if the given object is an instance of this function * template. */ bool HasInstance(Handle<Value> object); private: FunctionTemplate(); void AddInstancePropertyAccessor(Handle<String> name, AccessorGetter getter, AccessorSetter setter, Handle<Value> data, AccessControl settings, PropertyAttribute attributes); void SetNamedInstancePropertyHandler(NamedPropertyGetter getter, NamedPropertySetter setter, NamedPropertyQuery query, NamedPropertyDeleter remover, NamedPropertyEnumerator enumerator, Handle<Value> data); void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter, IndexedPropertySetter setter, IndexedPropertyQuery query, IndexedPropertyDeleter remover, IndexedPropertyEnumerator enumerator, Handle<Value> data); void SetInstanceCallAsFunctionHandler(InvocationCallback callback, Handle<Value> data); friend class Context; friend class ObjectTemplate;};/** * An ObjectTemplate is used to create objects at runtime. * * Properties added to an ObjectTemplate are added to each object * created from the ObjectTemplate. */class EXPORT ObjectTemplate : public Template { public: /** Creates an ObjectTemplate. */ static Local<ObjectTemplate> New(); /** Creates a new instance of this template.*/ Local<Object> NewInstance(); /** * Sets an accessor on the object template. * * Whenever the property with the given name is accessed on objects * created from this ObjectTemplate the getter and setter callbacks * are called instead of getting and setting the property directly * on the JavaScript object. * * \param name The name of the property for which an accessor is added. * \param getter The callback to invoke when getting the property. * \param setter The callback to invoke when setting the property. * \param data A piece of data that will be passed to the getter and setter * callbacks whenever they are invoked. * \param settings Access control settings for the accessor. This is a bit * field consisting of one of more of * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. * The default is to not allow cross-context access. * ALL_CAN_READ means that all cross-context reads are allowed. * ALL_CAN_WRITE means that all cross-context writes are allowed. * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all * cross-context access. * \param attribute The attributes of the property for which an accessor * is added. */ void SetAccessor(Handle<String> name, AccessorGetter getter, AccessorSetter setter = 0, Handle<Value> data = Handle<Value>(), AccessControl settings = DEFAULT, PropertyAttribute attribute = None); /** * Sets a named property handler on the object template. * * Whenever a named property is accessed on objects created from * this object template, the provided callback is invoked instead of * accessing the property directly on the JavaScript object. * * \param getter The callback to invoke when getting a property. * \param setter The callback to invoke when setting a property. * \param query The callback to invoke to check is an object has a property. * \param deleter The callback to invoke when deleting a property. * \param enumerator The callback to invoke to enumerate all the named * properties of an object. * \param data A piece of data that will be passed to the callbacks * whenever they are invoked. */ void SetNamedPropertyHandler(NamedPropertyGetter getter, NamedPropertySetter setter = 0, NamedPropertyQuery query = 0, NamedPropertyDeleter deleter = 0, NamedPropertyEnumerator enumerator = 0, Handle<Value> data = Handle<Value>()); /** * Sets an indexed property handler on the object template. * * Whenever an indexed property is accessed on objects created from * this object template, the provided callback is invoked instead of * accessing the property directly on the JavaScript object. * * \param getter The callback to invoke when getting a property. * \param setter The callback to invoke when setting a property. * \param query The callback to invoke to check is an object has a property. * \param deleter The callback to invoke when deleting a property. * \param enumerator The callback to invoke to enumerate all the indexed * properties of an object. * \param data A piece of data that will be passed to the callbacks * whenever they are invoked. */ void SetIndexedPropertyHandler(IndexedPropertyGetter getter, IndexedPropertySetter setter = 0, IndexedPropertyQuery query = 0, IndexedPropertyDeleter deleter = 0, IndexedPropertyEnumerator enumerator = 0, Handle<Value> data = Handle<Value>()); /** * Sets the callback to be used when calling instances created from * this template as a function. If no callback is set, instances * behave like normal JavaScript objects that cannot be called as a * function. */ void SetCallAsFunctionHandler(InvocationCallback callback, Handle<Value> data = Handle<Value>()); /** * Mark object instances of the template as undetectable. * * In many ways, undetectable objects behave as though they are not * there. They behave like 'undefined' in conditionals and when * printed. However, properties can be accessed and called as on * normal objects. */ void MarkAsUndetectable(); /** * Sets access check callbacks on the object template. * * When accessing properties on instances of this object template, * the access check callback will be called to determine whether or * not to allow cross-context access to the properties. */ void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, IndexedSecurityCallback indexed_handler, Handle<Value> data = Handle<Value>()); /** * Gets the number of internal fields for objects generated from * this template. */ int InternalFieldCount(); /** * Sets the number of internal fields for objects generated from * this template. */ void SetInternalFieldCount(int value); private: ObjectTemplate(); static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); friend class FunctionTemplate;};/** * A Signature specifies which receivers and arguments a function can * legally be called with. */class EXPORT Signature : public Data { public: static Local<Signature> New(Handle<FunctionTemplate> receiver = Handle<FunctionTemplate>(), int argc = 0, Handle<FunctionTemplate> argv[] = 0); private: Signature();};/** * A utility for determining the type of objects based on the template * they were constructed from. */class EXPORT TypeSwitch : public Data { public: static Local<TypeSwitch> New(Handle<FunctionTemplate> type); static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); int match(Handle<Value> value); private: TypeSwitch();};// --- E x t e n s i o n s ---/** * Ignore */class EXPORT Extension { // NOLINT public: Extension(const char* name, const char* source = 0, int dep_count = 0, const char** deps = 0); virtual ~Extension() { } virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(v8::Handle<v8::String> name) { return v8::Handle<v8::FunctionTemplate>(); } const char* name() { return name_; } const char* source() { return source_; } int dependency_count() { return dep_count_; } const char** dependencies() { return deps_; } void set_auto_enable(bool value) { auto_enable_ = value; } bool auto_enable() { return auto_enable_; } private: const char* name_; const char* source_; int dep_count_; const char** deps_; bool auto_enable_;};void EXPORT RegisterExtension(Extension* extension);/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -