📄 jsobjectref.h
字号:
/* * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. * Copyright (C) 2008 Kelvin W Sherlock (ksherlock@gmail.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#ifndef JSObjectRef_h#define JSObjectRef_h#include <JavaScriptCore/JSBase.h>#include <JavaScriptCore/JSValueRef.h>#include <JavaScriptCore/WebKitAvailability.h>#ifndef __cplusplus#include <stdbool.h>#endif#include <stddef.h> /* for size_t */#ifdef __cplusplusextern "C" {#endif/*!@enum JSPropertyAttribute@constant kJSPropertyAttributeNone Specifies that a property has no special attributes.@constant kJSPropertyAttributeReadOnly Specifies that a property is read-only.@constant kJSPropertyAttributeDontEnum Specifies that a property should not be enumerated by JSPropertyEnumerators and JavaScript for...in loops.@constant kJSPropertyAttributeDontDelete Specifies that the delete operation should fail on a property.*/enum { kJSPropertyAttributeNone = 0, kJSPropertyAttributeReadOnly = 1 << 1, kJSPropertyAttributeDontEnum = 1 << 2, kJSPropertyAttributeDontDelete = 1 << 3};/*! @typedef JSPropertyAttributes@abstract A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.*/typedef unsigned JSPropertyAttributes;/*!@enum JSClassAttribute@constant kJSClassAttributeNone Specifies that a class has no special attributes.@constant kJSClassAttributeNoAutomaticPrototype Specifies that a class should not automatically generate a shared prototype for its instance objects. Use kJSClassAttributeNoAutomaticPrototype in combination with JSObjectSetPrototype to manage prototypes manually.*/enum { kJSClassAttributeNone = 0, kJSClassAttributeNoAutomaticPrototype = 1 << 1};/*! @typedef JSClassAttributes@abstract A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.*/typedef unsigned JSClassAttributes;/*! @typedef JSObjectInitializeCallback@abstract The callback invoked when an object is first created.@param ctx The execution context to use.@param object The JSObject being created.@discussion If you named your function Initialize, you would declare it like this:void Initialize(JSContextRef ctx, JSObjectRef object);Unlike the other object callbacks, the initialize callback is called on the leastderived class (the parent class) first, and the most derived class last.*/typedef void(*JSObjectInitializeCallback) (JSContextRef ctx, JSObjectRef object);/*! @typedef JSObjectFinalizeCallback@abstract The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.@param object The JSObject being finalized.@discussion If you named your function Finalize, you would declare it like this:void Finalize(JSObjectRef object);The finalize callback is called on the most derived class first, and the least derived class (the parent class) last.You must not call any function that may cause a garbage collection or an allocationof a garbage collected object from within a JSObjectFinalizeCallback. This includesall functions that have a JSContextRef parameter.*/typedef void (*JSObjectFinalizeCallback) (JSObjectRef object);/*! @typedef JSObjectHasPropertyCallback@abstract The callback invoked when determining whether an object has a property.@param ctx The execution context to use.@param object The JSObject to search for the property.@param propertyName A JSString containing the name of the property look up.@result true if object has the property, otherwise false.@discussion If you named your function HasProperty, you would declare it like this:bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);If this function returns false, the hasProperty request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive.If this callback is NULL, the getProperty callback will be used to service hasProperty requests.*/typedef bool(*JSObjectHasPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);/*! @typedef JSObjectGetPropertyCallback@abstract The callback invoked when getting a property's value.@param ctx The execution context to use.@param object The JSObject to search for the property.@param propertyName A JSString containing the name of the property to get.@param exception A pointer to a JSValueRef in which to return an exception, if any.@result The property's value if object has the property, otherwise NULL.@discussion If you named your function GetProperty, you would declare it like this:JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);If this function returns NULL, the get request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.*/typedef JSValueRef(*JSObjectGetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);/*! @typedef JSObjectSetPropertyCallback@abstract The callback invoked when setting a property's value.@param ctx The execution context to use.@param object The JSObject on which to set the property's value.@param propertyName A JSString containing the name of the property to set.@param value A JSValue to use as the property's value.@param exception A pointer to a JSValueRef in which to return an exception, if any.@result true if the property was set, otherwise false.@discussion If you named your function SetProperty, you would declare it like this:bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);If this function returns false, the set request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).*/typedef bool(*JSObjectSetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);/*! @typedef JSObjectDeletePropertyCallback@abstract The callback invoked when deleting a property.@param ctx The execution context to use.@param object The JSObject in which to delete the property.@param propertyName A JSString containing the name of the property to delete.@param exception A pointer to a JSValueRef in which to return an exception, if any.@result true if propertyName was successfully deleted, otherwise false.@discussion If you named your function DeleteProperty, you would declare it like this:bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);If this function returns false, the delete request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).*/typedef bool(*JSObjectDeletePropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);/*! @typedef JSObjectGetPropertyNamesCallback@abstract The callback invoked when collecting the names of an object's properties.@param ctx The execution context to use.@param object The JSObject whose property names are being collected.@param accumulator A JavaScript property name accumulator in which to accumulate the names of object's properties.@discussion If you named your function GetPropertyNames, you would declare it like this:void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);Property name accumulators are used by JSObjectCopyPropertyNames and JavaScript for...in loops. Use JSPropertyNameAccumulatorAddName to add property names to accumulator. A class's getPropertyNames callback only needs to provide the names of properties that the class vends through a custom getProperty or setProperty callback. Other properties, including statically declared properties, properties vended by other classes, and properties belonging to object's prototype, are added independently.*/typedef void(*JSObjectGetPropertyNamesCallback) (JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);/*! @typedef JSObjectCallAsFunctionCallback@abstract The callback invoked when an object is called as a function.@param ctx The execution context to use.@param function A JSObject that is the function being called.@param thisObject A JSObject that is the 'this' variable in the function's scope.@param argumentCount An integer count of the number of arguments in arguments.@param arguments A JSValue array of the arguments passed to the function.@param exception A pointer to a JSValueRef in which to return an exception, if any.@result A JSValue that is the function's return value.@discussion If you named your function CallAsFunction, you would declare it like this:JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);If your callback were invoked by the JavaScript expression 'myObject.myFunction()', function would be set to myFunction, and thisObject would be set to myObject.If this callback is NULL, calling your object as a function will throw an exception.*/typedef JSValueRef (*JSObjectCallAsFunctionCallback) (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);/*! @typedef JSObjectCallAsConstructorCallback@abstract The callback invoked when an object is used as a constructor in a 'new' expression.@param ctx The execution context to use.@param constructor A JSObject that is the constructor being called.@param argumentCount An integer count of the number of arguments in arguments.@param arguments A JSValue array of the arguments passed to the function.@param exception A pointer to a JSValueRef in which to return an exception, if any.@result A JSObject that is the constructor's return value.@discussion If you named your function CallAsConstructor, you would declare it like this:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -