📄 jsobjectref.h
字号:
JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);If your callback were invoked by the JavaScript expression 'new myConstructor()', constructor would be set to myConstructor.If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.*/typedef JSObjectRef (*JSObjectCallAsConstructorCallback) (JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);/*! @typedef JSObjectHasInstanceCallback@abstract hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.@param ctx The execution context to use.@param constructor The JSObject that is the target of the 'instanceof' expression.@param possibleInstance The JSValue being tested to determine if it is an instance of constructor.@param exception A pointer to a JSValueRef in which to return an exception, if any.@result true if possibleInstance is an instance of constructor, otherwise false.@discussion If you named your function HasInstance, you would declare it like this:bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue.If this callback is NULL, 'instanceof' expressions that target your object will return false.Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.*/typedef bool (*JSObjectHasInstanceCallback) (JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);/*! @typedef JSObjectConvertToTypeCallback@abstract The callback invoked when converting an object to a particular JavaScript type.@param ctx The execution context to use.@param object The JSObject to convert.@param type A JSType specifying the JavaScript type to convert to.@param exception A pointer to a JSValueRef in which to return an exception, if any.@result The objects's converted value, or NULL if the object was not converted.@discussion If you named your function ConvertToType, you would declare it like this:JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).This function is only invoked when converting an object to number or string. An object converted to boolean is 'true.' An object converted to object is itself.*/typedef JSValueRef(*JSObjectConvertToTypeCallback) (JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);/*! @struct JSStaticValue@abstract This structure describes a statically declared value property.@field name A null-terminated UTF8 string containing the property's name.@field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.@field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. May be NULL if the ReadOnly attribute is set.@field attributes A logically ORed set of JSPropertyAttributes to give to the property.*/typedef struct { const char* const name; JSObjectGetPropertyCallback getProperty; JSObjectSetPropertyCallback setProperty; JSPropertyAttributes attributes;} JSStaticValue;/*! @struct JSStaticFunction@abstract This structure describes a statically declared function property.@field name A null-terminated UTF8 string containing the property's name.@field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.@field attributes A logically ORed set of JSPropertyAttributes to give to the property.*/typedef struct { const char* const name; JSObjectCallAsFunctionCallback callAsFunction; JSPropertyAttributes attributes;} JSStaticFunction;/*!@struct JSClassDefinition@abstract This structure contains properties and callbacks that define a type of object. All fields other than the version field are optional. Any pointer may be NULL.@field version The version number of this structure. The current version is 0.@field attributes A logically ORed set of JSClassAttributes to give to the class.@field className A null-terminated UTF8 string containing the class's name.@field parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.@field staticValues A JSStaticValue array containing the class's statically declared value properties. Pass NULL to specify no statically declared value properties. The array must be terminated by a JSStaticValue whose name field is NULL.@field staticFunctions A JSStaticFunction array containing the class's statically declared function properties. Pass NULL to specify no statically declared function properties. The array must be terminated by a JSStaticFunction whose name field is NULL.@field initialize The callback invoked when an object is first created. Use this callback to initialize the object.@field finalize The callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for the object, and perform other cleanup.@field hasProperty The callback invoked when determining whether an object has a property. If this field is NULL, getProperty is called instead. The hasProperty callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value is expensive. @field getProperty The callback invoked when getting a property's value.@field setProperty The callback invoked when setting a property's value.@field deleteProperty The callback invoked when deleting a property.@field getPropertyNames The callback invoked when collecting the names of an object's properties.@field callAsFunction The callback invoked when an object is called as a function.@field hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.@field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.@field convertToType The callback invoked when converting an object to a particular JavaScript type.@discussion The staticValues and staticFunctions arrays are the simplest and most efficient means for vending custom properties. Statically declared properties autmatically service requests like getProperty, setProperty, and getPropertyNames. Property access callbacks are required only to implement unusual properties, like array indexes, whose names are not known at compile-time.If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:JSStaticValue StaticValueArray[] = { { "X", GetX, SetX, kJSPropertyAttributeNone }, { 0, 0, 0, 0 }};Standard JavaScript practice calls for storing function objects in prototypes, so they can be shared. The default JSClass created by JSClassCreate follows this idiom, instantiating objects with a shared, automatically generating prototype containing the class's function objects. The kJSClassAttributeNoAutomaticPrototype attribute specifies that a JSClass should not automatically generate such a prototype. The resulting JSClass instantiates objects with the default object prototype, and gives each instance object its own copy of the class's function objects.A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.*/typedef struct { int version; /* current (and only) version is 0 */ JSClassAttributes attributes; const char* className; JSClassRef parentClass; const JSStaticValue* staticValues; const JSStaticFunction* staticFunctions; JSObjectInitializeCallback initialize; JSObjectFinalizeCallback finalize; JSObjectHasPropertyCallback hasProperty; JSObjectGetPropertyCallback getProperty; JSObjectSetPropertyCallback setProperty; JSObjectDeletePropertyCallback deleteProperty; JSObjectGetPropertyNamesCallback getPropertyNames; JSObjectCallAsFunctionCallback callAsFunction; JSObjectCallAsConstructorCallback callAsConstructor; JSObjectHasInstanceCallback hasInstance; JSObjectConvertToTypeCallback convertToType;} JSClassDefinition;/*! @const kJSClassDefinitionEmpty @abstract A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.@discussion Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:JSClassDefinition definition = kJSClassDefinitionEmpty;definition.finalize = Finalize;*/JS_EXPORT extern const JSClassDefinition kJSClassDefinitionEmpty;/*!@function@abstract Creates a JavaScript class suitable for use with JSObjectMake.@param definition A JSClassDefinition that defines the class.@result A JSClass with the given definition. Ownership follows the Create Rule.*/JS_EXPORT JSClassRef JSClassCreate(const JSClassDefinition* definition);/*!@function@abstract Retains a JavaScript class.@param jsClass The JSClass to retain.@result A JSClass that is the same as jsClass.*/JS_EXPORT JSClassRef JSClassRetain(JSClassRef jsClass);/*!@function@abstract Releases a JavaScript class.@param jsClass The JSClass to release.*/JS_EXPORT void JSClassRelease(JSClassRef jsClass);/*!@function@abstract Creates a JavaScript object.@param ctx The execution context to use.@param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.@param data A void* to set as the object's private data. Pass NULL to specify no private data.@result A JSObject with the given class and private data.@discussion The default object class does not allocate storage for private data, so you must provide a non-NULL jsClass to JSObjectMake if you want your object to be able to store private data.data is set on the created object before the intialize methods in its class chain are called. This enables the initialize methods to retrieve and manipulate data through JSObjectGetPrivate.*/JS_EXPORT JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data);/*!@function@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.@param ctx The execution context to use.@param name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.@param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.@result A JSObject that is a function. The object's prototype will be the default function prototype.*/JS_EXPORT JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction);/*!@function@abstract Convenience method for creating a JavaScript constructor.@param ctx The execution context to use.@param jsClass A JSClass that is the class your constructor will assign to the objects its constructs. jsClass will be used to set the constructor's .prototype property, and to evaluate 'instanceof' expressions. Pass NULL to use the default object class.@param callAsConstructor A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.@result A JSObject that is a constructor. The object's prototype will be the default object prototype.@discussion The default object constructor takes no arguments and constructs an object of class jsClass with no private data.*/JS_EXPORT JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor);/*! @function @abstract Creates a JavaScript Array object. @param ctx The execution context to use. @param argumentCount An integer count of the number of arguments in arguments. @param arguments A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0. @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObject that is an Array. @discussion The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument is supplied, this function returns an array with one element. */JS_EXPORT JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;/*! @function @abstract Creates a JavaScript Date object, as if by invoking the built-in Date constructor. @param ctx The execution context to use. @param argumentCount An integer count of the number of arguments in arguments. @param arguments A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0. @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObject that is a Date. */JS_EXPORT JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;/*! @function @abstract Creates a JavaScript Error object, as if by invoking the built-in Error constructor. @param ctx The execution context to use. @param argumentCount An integer count of the number of arguments in arguments. @param arguments A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0. @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObject that is a Error.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -