1 | // -*- mode: c++; c-basic-offset: 4 -*-
|
---|
2 | /*
|
---|
3 | * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | * 1. Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer in the
|
---|
12 | * documentation and/or other materials provided with the distribution.
|
---|
13 | *
|
---|
14 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
---|
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
---|
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
---|
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef JSObjectRef_h
|
---|
28 | #define JSObjectRef_h
|
---|
29 |
|
---|
30 | #include <JavaScriptCore/JSBase.h>
|
---|
31 | #include <JavaScriptCore/JSValueRef.h>
|
---|
32 |
|
---|
33 | #include <stdbool.h>
|
---|
34 | #include <stddef.h> // for size_t
|
---|
35 |
|
---|
36 | #ifdef __cplusplus
|
---|
37 | extern "C" {
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | /*!
|
---|
41 | @enum JSPropertyAttribute
|
---|
42 | @constant kJSPropertyAttributeNone Specifies that a property has no special attributes.
|
---|
43 | @constant kJSPropertyAttributeReadOnly Specifies that a property is read-only.
|
---|
44 | @constant kJSPropertyAttributeDontEnum Specifies that a property should not be enumerated by JSPropertyEnumerators and JavaScript for...in loops.
|
---|
45 | @constant kJSPropertyAttributeDontDelete Specifies that the delete operation should fail on a property.
|
---|
46 | */
|
---|
47 | enum {
|
---|
48 | kJSPropertyAttributeNone = 0,
|
---|
49 | kJSPropertyAttributeReadOnly = 1 << 1,
|
---|
50 | kJSPropertyAttributeDontEnum = 1 << 2,
|
---|
51 | kJSPropertyAttributeDontDelete = 1 << 3
|
---|
52 | };
|
---|
53 |
|
---|
54 | /*!
|
---|
55 | @typedef JSPropertyAttributes
|
---|
56 | @abstract A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
|
---|
57 | */
|
---|
58 | typedef unsigned JSPropertyAttributes;
|
---|
59 |
|
---|
60 | /*!
|
---|
61 | @typedef JSObjectInitializeCallback
|
---|
62 | @abstract The callback invoked when an object is first created.
|
---|
63 | @param context The execution context to use.
|
---|
64 | @param object The JSObject being created.
|
---|
65 | @param exception A pointer to a JSValueRef in which to return an exception, if any.
|
---|
66 | @discussion If you named your function Initialize, you would declare it like this:
|
---|
67 |
|
---|
68 | void Initialize(JSContextRef context, JSObjectRef object, JSValueRef* exception);
|
---|
69 | */
|
---|
70 | typedef void
|
---|
71 | (*JSObjectInitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception);
|
---|
72 |
|
---|
73 | /*!
|
---|
74 | @typedef JSObjectFinalizeCallback
|
---|
75 | @abstract The callback invoked when an object is finalized (prepared for garbage collection).
|
---|
76 | @param object The JSObject being finalized.
|
---|
77 | @discussion If you named your function Finalize, you would declare it like this:
|
---|
78 |
|
---|
79 | void Finalize(JSObjectRef object);
|
---|
80 | */
|
---|
81 | typedef void
|
---|
82 | (*JSObjectFinalizeCallback) (JSObjectRef object);
|
---|
83 |
|
---|
84 | /*!
|
---|
85 | @typedef JSObjectHasPropertyCallback
|
---|
86 | @abstract The callback invoked when determining whether an object has a given property.
|
---|
87 | @param context The current execution context.
|
---|
88 | @param object The JSObject to search for the property.
|
---|
89 | @param propertyName A JSString containing the name of the property look up.
|
---|
90 | @param exception A pointer to a JSValueRef in which to return an exception, if any.
|
---|
91 | @result true if object has the property, otherwise false.
|
---|
92 | @discussion If you named your function HasProperty, you would declare it like this:
|
---|
93 |
|
---|
94 | bool HasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
|
---|
95 |
|
---|
96 | If this function returns false, the hasProperty request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain.
|
---|
97 |
|
---|
98 | 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.
|
---|
99 | */
|
---|
100 | typedef bool
|
---|
101 | (*JSObjectHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
|
---|
102 |
|
---|
103 | /*!
|
---|
104 | @typedef JSObjectGetPropertyCallback
|
---|
105 | @abstract The callback invoked when getting a property from an object.
|
---|
106 | @param context The current execution context.
|
---|
107 | @param object The JSObject to search for the property.
|
---|
108 | @param propertyName A JSString containing the name of the property to get.
|
---|
109 | @param exception A pointer to a JSValueRef in which to return an exception, if any.
|
---|
110 | @result The property's value if object has the property, otherwise NULL.
|
---|
111 | @discussion If you named your function GetProperty, you would declare it like this:
|
---|
112 |
|
---|
113 | JSValueRef GetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
|
---|
114 |
|
---|
115 | If this function returns NULL, the get request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain.
|
---|
116 | */
|
---|
117 | typedef JSValueRef
|
---|
118 | (*JSObjectGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
|
---|
119 |
|
---|
120 | /*!
|
---|
121 | @typedef JSObjectSetPropertyCallback
|
---|
122 | @abstract The callback invoked when setting the value of a given property.
|
---|
123 | @param context The current execution context.
|
---|
124 | @param object The JSObject on which to set the property's value.
|
---|
125 | @param propertyName A JSString containing the name of the property to set.
|
---|
126 | @param value A JSValue to use as the property's value.
|
---|
127 | @param exception A pointer to a JSValueRef in which to return an exception, if any.
|
---|
128 | @result true if the property was set, otherwise false.
|
---|
129 | @discussion If you named your function SetProperty, you would declare it like this:
|
---|
130 |
|
---|
131 | bool SetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
|
---|
132 |
|
---|
133 | If this function returns false, the set request forwards to object's static property table, then its parent class chain (which includes the default object class).
|
---|
134 | */
|
---|
135 | typedef bool
|
---|
136 | (*JSObjectSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
|
---|
137 |
|
---|
138 | /*!
|
---|
139 | @typedef JSObjectDeletePropertyCallback
|
---|
140 | @abstract The callback invoked when deleting a given property.
|
---|
141 | @param context The current execution context.
|
---|
142 | @param object The JSObject in which to delete the property.
|
---|
143 | @param propertyName A JSString containing the name of the property to delete.
|
---|
144 | @param exception A pointer to a JSValueRef in which to return an exception, if any.
|
---|
145 | @result true if propertyName was successfully deleted, otherwise false.
|
---|
146 | @discussion If you named your function DeleteProperty, you would declare it like this:
|
---|
147 |
|
---|
148 | bool DeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
|
---|
149 |
|
---|
150 | If this function returns false, the delete request forwards to object's static property table, then its parent class chain (which includes the default object class).
|
---|
151 | */
|
---|
152 | typedef bool
|
---|
153 | (*JSObjectDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
|
---|
154 |
|
---|
155 | /*!
|
---|
156 | @typedef JSObjectAddPropertiesToListCallback
|
---|
157 | @abstract The callback invoked when adding an object's properties to a property list.
|
---|
158 | @param object The JSObject whose properties need to be added to propertyList.
|
---|
159 | @param propertyList A JavaScript property list that will be used to enumerate object's properties.
|
---|
160 | @discussion If you named your function GetPropertyList, you would declare it like this:
|
---|
161 |
|
---|
162 | void AddPropertiesToList(JSObjectRef object, JSPropertyListRef propertyList);
|
---|
163 |
|
---|
164 | Use JSPropertyListAdd to add properties to propertyList.
|
---|
165 |
|
---|
166 | Property lists are used by JSPropertyEnumerators and JavaScript for...in loops.
|
---|
167 | */
|
---|
168 | typedef void
|
---|
169 | (*JSObjectAddPropertiesToListCallback) (JSObjectRef object, JSPropertyListRef propertyList);
|
---|
170 |
|
---|
171 | /*!
|
---|
172 | @typedef JSObjectCallAsFunctionCallback
|
---|
173 | @abstract The callback invoked when an object is called as a function.
|
---|
174 | @param context The current execution context.
|
---|
175 | @param function A JSObject that is the function being called.
|
---|
176 | @param thisObject A JSObject that is the 'this' variable in the function's scope.
|
---|
177 | @param argc An integer count of the number of arguments in argv.
|
---|
178 | @param argv A JSValue array of the arguments passed to the function.
|
---|
179 | @param exception A pointer to a JSValueRef in which to return an exception, if any.
|
---|
180 | @result A JSValue that is the function's return value.
|
---|
181 | @discussion If you named your function CallAsFunction, you would declare it like this:
|
---|
182 |
|
---|
183 | JSValueRef CallAsFunction(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);
|
---|
184 |
|
---|
185 | If your callback were invoked by the JavaScript expression 'myObject.myMemberFunction()', function would be set to myMemberFunction, and thisObject would be set to myObject.
|
---|
186 |
|
---|
187 | If this callback is NULL, calling your object as a function will throw an exception.
|
---|
188 | */
|
---|
189 | typedef JSValueRef
|
---|
190 | (*JSObjectCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);
|
---|
191 |
|
---|
192 | /*!
|
---|
193 | @typedef JSObjectCallAsConstructorCallback
|
---|
194 | @abstract The callback invoked when an object is used as a constructor in a 'new' expression.
|
---|
195 | @param context The current execution context.
|
---|
196 | @param constructor A JSObject that is the constructor being called.
|
---|
197 | @param argc An integer count of the number of arguments in argv.
|
---|
198 | @param argv A JSValue array of the arguments passed to the function.
|
---|
199 | @param exception A pointer to a JSValueRef in which to return an exception, if any.
|
---|
200 | @result A JSObject that is the constructor's return value.
|
---|
201 | @discussion If you named your function CallAsConstructor, you would declare it like this:
|
---|
202 |
|
---|
203 | JSObjectRef CallAsConstructor(JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception);
|
---|
204 |
|
---|
205 | If your callback were invoked by the JavaScript expression 'new myConstructorFunction()', constructor would be set to myConstructorFunction.
|
---|
206 |
|
---|
207 | If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
|
---|
208 | */
|
---|
209 | typedef JSObjectRef
|
---|
210 | (*JSObjectCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception);
|
---|
211 |
|
---|
212 | /*!
|
---|
213 | @typedef JSObjectHasInstanceCallback
|
---|
214 | @abstract The callback invoked when an object is used in an 'instanceof' expression.
|
---|
215 | @param context The current execution context.
|
---|
216 | @param constructor The JSObject receiving the hasInstance request
|
---|
217 | @param possibleInstance The JSValue being tested to determine if it is an instance of constructor.
|
---|
218 | @param exception A pointer to a JSValueRef in which to return an exception, if any.
|
---|
219 | @result true if possibleInstance is an instance of constructor, otherwise false
|
---|
220 |
|
---|
221 | @discussion If you named your function HasInstance, you would declare it like this:
|
---|
222 |
|
---|
223 | bool HasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
|
---|
224 |
|
---|
225 | 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..
|
---|
226 |
|
---|
227 | If this callback is NULL, using your object in an 'instanceof' will always return false.
|
---|
228 |
|
---|
229 | Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
|
---|
230 | */
|
---|
231 | typedef bool
|
---|
232 | (*JSObjectHasInstanceCallback) (JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
|
---|
233 |
|
---|
234 | /*!
|
---|
235 | @typedef JSObjectConvertToTypeCallback
|
---|
236 | @abstract The callback invoked when converting an object to a particular JavaScript type.
|
---|
237 | @param context The current execution context.
|
---|
238 | @param object The JSObject to convert.
|
---|
239 | @param type A JSType specifying the JavaScript type to convert to.
|
---|
240 | @param exception A pointer to a JSValueRef in which to return an exception, if any.
|
---|
241 | @result The objects's converted value, or NULL if the object was not converted.
|
---|
242 | @discussion If you named your function ConvertToType, you would declare it like this:
|
---|
243 |
|
---|
244 | JSValueRef ConvertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
|
---|
245 |
|
---|
246 | If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
|
---|
247 | */
|
---|
248 | typedef JSValueRef
|
---|
249 | (*JSObjectConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
|
---|
250 |
|
---|
251 | /*!
|
---|
252 | @struct JSObjectCallbacks
|
---|
253 | @abstract This structure contains optional callbacks for supplementing default object behavior. Any callback field can be NULL.
|
---|
254 | @field version The version number of this structure. The current version is 0.
|
---|
255 | @field initialize The callback invoked when an object is first created. Use this callback in conjunction with JSObjectSetPrivate to initialize private data in your object.
|
---|
256 | @field finalize The callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for your object, and perform other cleanup.
|
---|
257 | @field hasProperty The callback invoked when determining whether an object has a given property. If this field is NULL, getProperty will be 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 would be expensive.
|
---|
258 | @field getProperty The callback invoked when getting the value of a given property.
|
---|
259 | @field setProperty The callback invoked when setting the value of a given property.
|
---|
260 | @field deleteProperty The callback invoked when deleting a given property.
|
---|
261 | @field addPropertiesToList The callback invoked when adding an object's properties to a property list.
|
---|
262 | @field callAsFunction The callback invoked when an object is called as a function.
|
---|
263 | @field hasInstance The callback invoked when an object is used in an 'instanceof' expression.
|
---|
264 | @field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.
|
---|
265 | @field convertToType The callback invoked when converting an object to a particular JavaScript type.
|
---|
266 | */
|
---|
267 | typedef struct {
|
---|
268 | int version; // current (and only) version is 0
|
---|
269 | JSObjectInitializeCallback initialize;
|
---|
270 | JSObjectFinalizeCallback finalize;
|
---|
271 | JSObjectHasPropertyCallback hasProperty;
|
---|
272 | JSObjectGetPropertyCallback getProperty;
|
---|
273 | JSObjectSetPropertyCallback setProperty;
|
---|
274 | JSObjectDeletePropertyCallback deleteProperty;
|
---|
275 | JSObjectAddPropertiesToListCallback addPropertiesToList;
|
---|
276 | JSObjectCallAsFunctionCallback callAsFunction;
|
---|
277 | JSObjectCallAsConstructorCallback callAsConstructor;
|
---|
278 | JSObjectHasInstanceCallback hasInstance;
|
---|
279 | JSObjectConvertToTypeCallback convertToType;
|
---|
280 | } JSObjectCallbacks;
|
---|
281 |
|
---|
282 | /*!
|
---|
283 | @const kJSObjectCallbacksNone
|
---|
284 | @abstract A JSObjectCallbacks structure of the current version, filled with NULL callbacks.
|
---|
285 | @discussion Use this constant as a convenience when creating callback structures. For example, to create a callback structure that has only a finalize method:
|
---|
286 |
|
---|
287 | JSObjectCallbacks callbacks = kJSObjectCallbacksNone;
|
---|
288 |
|
---|
289 | callbacks.finalize = Finalize;
|
---|
290 | */
|
---|
291 | extern const JSObjectCallbacks kJSObjectCallbacksNone;
|
---|
292 |
|
---|
293 | /*!
|
---|
294 | @struct JSStaticValue
|
---|
295 | @abstract This structure describes a static value property.
|
---|
296 | @field name A null-terminated UTF8 string containing the property's name.
|
---|
297 | @field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
|
---|
298 | @field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value.
|
---|
299 | @field attributes A logically ORed set of JSPropertyAttributes to give to the property.
|
---|
300 | */
|
---|
301 | typedef struct {
|
---|
302 | const char* const name; // FIXME: convert UTF8
|
---|
303 | JSObjectGetPropertyCallback getProperty;
|
---|
304 | JSObjectSetPropertyCallback setProperty;
|
---|
305 | JSPropertyAttributes attributes;
|
---|
306 | } JSStaticValue;
|
---|
307 |
|
---|
308 | /*!
|
---|
309 | @struct JSStaticFunction
|
---|
310 | @abstract This structure describes a static function property.
|
---|
311 | @field name A null-terminated UTF8 string containing the property's name.
|
---|
312 | @field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
|
---|
313 | @field attributes A logically ORed set of JSPropertyAttributes to give to the property.
|
---|
314 | */
|
---|
315 | typedef struct {
|
---|
316 | const char* const name; // FIXME: convert UTF8
|
---|
317 | JSObjectCallAsFunctionCallback callAsFunction;
|
---|
318 | JSPropertyAttributes attributes;
|
---|
319 | } JSStaticFunction;
|
---|
320 |
|
---|
321 | /*!
|
---|
322 | @function
|
---|
323 | @abstract Creates a JavaScript class suitable for use with JSObjectMake
|
---|
324 | @param staticValues A JSStaticValue array representing the class's static value properties. Pass NULL to specify no static value properties. The array must be terminated by a JSStaticValue whose name field is NULL.
|
---|
325 | @param staticFunctions A JSStaticFunction array representing the class's static function properties. Pass NULL to specify no static function properties. The array must be terminated by a JSStaticFunction whose name field is NULL.
|
---|
326 | @param callbacks A pointer to a JSObjectCallbacks structure holding custom callbacks for supplementing default object behavior. Pass NULL to specify no custom behavior.
|
---|
327 | @param parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
|
---|
328 | @result A JSClass with the given properties, callbacks, and parent class. Ownership follows the Create Rule.
|
---|
329 | @discussion The simplest and most efficient way to add custom properties to a class is by specifying static values and functions. Standard JavaScript practice calls for functions to be placed in prototype objects, so that they can be shared among objects.
|
---|
330 | */
|
---|
331 | JSClassRef JSClassCreate(JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass);
|
---|
332 | /*!
|
---|
333 | @function
|
---|
334 | @abstract Retains a JavaScript class.
|
---|
335 | @param jsClass The JSClass to retain.
|
---|
336 | @result A JSClass that is the same as jsClass.
|
---|
337 | */
|
---|
338 | JSClassRef JSClassRetain(JSClassRef jsClass);
|
---|
339 | /*!
|
---|
340 | @function
|
---|
341 | @abstract Releases a JavaScript class.
|
---|
342 | @param jsClass The JSClass to release.
|
---|
343 | */
|
---|
344 | void JSClassRelease(JSClassRef jsClass);
|
---|
345 |
|
---|
346 | /*!
|
---|
347 | @function
|
---|
348 | @abstract Creates a JavaScript object with a given class and prototype.
|
---|
349 | @param context The execution context to use.
|
---|
350 | @param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
|
---|
351 | @param prototype The prototype to assign to the object. Pass NULL to use the default object prototype.
|
---|
352 | @result A JSObject with the given class and prototype.
|
---|
353 | */
|
---|
354 | JSObjectRef JSObjectMake(JSContextRef context, JSClassRef jsClass, JSValueRef prototype);
|
---|
355 |
|
---|
356 | /*!
|
---|
357 | @function
|
---|
358 | @abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
|
---|
359 | @param context The execution context to use.
|
---|
360 | @param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.
|
---|
361 | @result A JSObject that is an anonymous function. The object's prototype will be the default function prototype.
|
---|
362 | */
|
---|
363 | JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction);
|
---|
364 | /*!
|
---|
365 | @function
|
---|
366 | @abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation.
|
---|
367 | @param context The execution context to use.
|
---|
368 | @param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' expression.
|
---|
369 | @result A JSObject that is a constructor. The object's prototype will be the default object prototype.
|
---|
370 | */
|
---|
371 | JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor);
|
---|
372 |
|
---|
373 | /*!
|
---|
374 | @function
|
---|
375 | @abstract Creates a function with a given script as its body.
|
---|
376 | @param context The execution context to use.
|
---|
377 | @param body A JSString containing the script to use as the function's body.
|
---|
378 | @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
|
---|
379 | @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
|
---|
380 | @param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
|
---|
381 | @result A JSObject that is an anonymous function, or NULL if body contains a syntax error. The returned object's prototype will be the default function prototype.
|
---|
382 | @discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
|
---|
383 | */
|
---|
384 | JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
|
---|
385 |
|
---|
386 | /*!
|
---|
387 | @function
|
---|
388 | @abstract Gets an object's prototype.
|
---|
389 | @param object A JSObject whose prototype you want to get.
|
---|
390 | @result A JSValue containing the object's prototype.
|
---|
391 | */
|
---|
392 | JSValueRef JSObjectGetPrototype(JSObjectRef object);
|
---|
393 | /*!
|
---|
394 | @function
|
---|
395 | @abstract Sets an object's prototype.
|
---|
396 | @param object The JSObject whose prototype you want to set.
|
---|
397 | @param value A JSValue to set as the object's prototype.
|
---|
398 | */
|
---|
399 | void JSObjectSetPrototype(JSObjectRef object, JSValueRef value);
|
---|
400 |
|
---|
401 | /*!
|
---|
402 | @function
|
---|
403 | @abstract Tests whether an object has a certain property.
|
---|
404 | @param object The JSObject to test.
|
---|
405 | @param propertyName A JSString containing the property's name.
|
---|
406 | @result true if the object has a property whose name matches propertyName, otherwise false.
|
---|
407 | */
|
---|
408 | bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
|
---|
409 |
|
---|
410 | /*!
|
---|
411 | @function
|
---|
412 | @abstract Gets a property from an object.
|
---|
413 | @param context The execution context to use.
|
---|
414 | @param object The JSObject whose property you want to get.
|
---|
415 | @param propertyName A JSString containing the property's name.
|
---|
416 | @result The property's value if object has the property, otherwise NULL.
|
---|
417 | */
|
---|
418 | JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
|
---|
419 |
|
---|
420 | /*!
|
---|
421 | @function
|
---|
422 | @abstract Sets a property on an object.
|
---|
423 | @param context The execution context to use.
|
---|
424 | @param object The JSObject whose property you want to set.
|
---|
425 | @param propertyName A JSString containing the property's name.
|
---|
426 | @param value A JSValue to use as the property's value.
|
---|
427 | @param attributes A logically ORed set of JSPropertyAttributes to give to the property.
|
---|
428 | */
|
---|
429 | void JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes);
|
---|
430 |
|
---|
431 | /*!
|
---|
432 | @function
|
---|
433 | @abstract Deletes a property from an object.
|
---|
434 | @param context The execution context to use.
|
---|
435 | @param object The JSObject whose property you want to delete.
|
---|
436 | @param propertyName A JSString containing the property's name.
|
---|
437 | @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
|
---|
438 | */
|
---|
439 | bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
|
---|
440 |
|
---|
441 | /*!
|
---|
442 | @function
|
---|
443 | @abstract Gets a property from an object by numeric index.
|
---|
444 | @param context The execution context to use.
|
---|
445 | @param object The JSObject whose property you want to get.
|
---|
446 | @param propertyIndex The property's name as a number
|
---|
447 | @result The property's value if object has the property, otherwise NULL.
|
---|
448 | @discussion This is equivalent to getting a property by a string name containing the number, but allows faster access to JS arrays.
|
---|
449 | */
|
---|
450 | JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex);
|
---|
451 |
|
---|
452 | /*!
|
---|
453 | @function
|
---|
454 | @abstract Sets a property on an object by numeric index.
|
---|
455 | @param context The execution context to use.
|
---|
456 | @param object The JSObject whose property you want to set.
|
---|
457 | @param propertyIndex The property's name as a number
|
---|
458 | @param value A JSValue to use as the property's value.
|
---|
459 | @param attributes A logically ORed set of JSPropertyAttributes to give to the property.
|
---|
460 | @discussion This is equivalent to setting a property by a string name containing the number, but allows faster access to JS arrays.
|
---|
461 | */
|
---|
462 | void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSPropertyAttributes attributes);
|
---|
463 |
|
---|
464 | /*!
|
---|
465 | @function
|
---|
466 | @abstract Gets a pointer to private data from an object.
|
---|
467 | @param object A JSObject whose private data you want to get.
|
---|
468 | @result A void* that points to the object's private data, if the object has private data, otherwise NULL.
|
---|
469 | @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.
|
---|
470 | */
|
---|
471 | void* JSObjectGetPrivate(JSObjectRef object);
|
---|
472 |
|
---|
473 | /*!
|
---|
474 | @function
|
---|
475 | @abstract Sets a pointer to private data on an object.
|
---|
476 | @param object A JSObject whose private data you want to set.
|
---|
477 | @param data A void* that points to the object's private data.
|
---|
478 | @result true if the set operation succeeds, otherwise false.
|
---|
479 | @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.
|
---|
480 | */
|
---|
481 | bool JSObjectSetPrivate(JSObjectRef object, void* data);
|
---|
482 |
|
---|
483 | /*!
|
---|
484 | @function
|
---|
485 | @abstract Tests whether an object can be called as a function.
|
---|
486 | @param object The JSObject to test.
|
---|
487 | @result true if the object can be called as a function, otherwise false.
|
---|
488 | */
|
---|
489 | bool JSObjectIsFunction(JSObjectRef object);
|
---|
490 | /*!
|
---|
491 | @function
|
---|
492 | @abstract Calls an object as a function.
|
---|
493 | @param context The execution context to use.
|
---|
494 | @param object The JSObject to call as a function.
|
---|
495 | @param thisObject The object to use as "this," or NULL to use the global object as "this."
|
---|
496 | @param argc An integer count of the number of arguments in argv.
|
---|
497 | @param argv A JSValue array of the arguments to pass to the function.
|
---|
498 | @param exception A pointer to a JSValueRef in which to store an uncaught exception, if any. Pass NULL if you do not care to store an uncaught exception.
|
---|
499 | @result The JSValue that results from calling object as a function, or NULL if an uncaught exception is thrown or object is not a function.
|
---|
500 | */
|
---|
501 | JSValueRef JSObjectCallAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);
|
---|
502 | /*!
|
---|
503 | @function
|
---|
504 | @abstract Tests whether an object can be called as a constructor.
|
---|
505 | @param object The JSObject to test.
|
---|
506 | @result true if the object can be called as a constructor, otherwise false.
|
---|
507 | */
|
---|
508 | bool JSObjectIsConstructor(JSObjectRef object);
|
---|
509 | /*!
|
---|
510 | @function
|
---|
511 | @abstract Calls an object as a constructor.
|
---|
512 | @param context The execution context to use.
|
---|
513 | @param object The JSObject to call as a constructor.
|
---|
514 | @param argc An integer count of the number of arguments in argv.
|
---|
515 | @param argv A JSValue array of the arguments to pass to the function.
|
---|
516 | @param exception A pointer to a JSValueRef in which to store an uncaught exception, if any. Pass NULL if you do not care to store an uncaught exception.
|
---|
517 | @result The JSObject that results from calling object as a constructor, or NULL if an uncaught exception is thrown or object is not a constructor.
|
---|
518 | */
|
---|
519 | JSObjectRef JSObjectCallAsConstructor(JSContextRef context, JSObjectRef object, size_t argc, JSValueRef argv[], JSValueRef* exception);
|
---|
520 |
|
---|
521 | /*!
|
---|
522 | @function
|
---|
523 | @abstract Creates an enumerator for an object's properties.
|
---|
524 | @param object The object whose properties you want to enumerate.
|
---|
525 | @result A JSPropertyEnumerator with a list of object's properties. Ownership follows the Create Rule.
|
---|
526 | */
|
---|
527 | JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSObjectRef object);
|
---|
528 | /*!
|
---|
529 | @function
|
---|
530 | @abstract Retains a property enumerator.
|
---|
531 | @param enumerator The JSPropertyEnumerator to retain.
|
---|
532 | @result A JSPropertyEnumerator that is the same as enumerator.
|
---|
533 | */
|
---|
534 | JSPropertyEnumeratorRef JSPropertyEnumeratorRetain(JSPropertyEnumeratorRef enumerator);
|
---|
535 | /*!
|
---|
536 | @function
|
---|
537 | @abstract Releases a property enumerator.
|
---|
538 | @param enumerator The JSPropertyEnumerator to release.
|
---|
539 | */
|
---|
540 | void JSPropertyEnumeratorRelease(JSPropertyEnumeratorRef enumerator);
|
---|
541 | /*!
|
---|
542 | @function
|
---|
543 | @abstract Gets a property enumerator's next property.
|
---|
544 | @param enumerator The JSPropertyEnumerator whose next property you want to get.
|
---|
545 | @result A JSString containing the property's name, or NULL if all properties have been enumerated.
|
---|
546 | */
|
---|
547 | JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator);
|
---|
548 |
|
---|
549 | /*!
|
---|
550 | @function
|
---|
551 | @abstract Adds a property to a property list.
|
---|
552 | @discussion Use this method inside a JSObjectAddPropertiesToListCallback to add a custom property to an object's property list.
|
---|
553 | @param propertyList The JSPropertyList to which you want to add a property.
|
---|
554 | @param thisObject The JSObject to which the property belongs.
|
---|
555 | @param propertyName A JSString specifying the property's name.
|
---|
556 | */
|
---|
557 | void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName);
|
---|
558 |
|
---|
559 | #ifdef __cplusplus
|
---|
560 | }
|
---|
561 | #endif
|
---|
562 |
|
---|
563 | #endif // JSObjectRef_h
|
---|