source: webkit/trunk/JavaScriptCore/API/JSObjectRef.h@ 15469

Last change on this file since 15469 was 15469, checked in by ggaren, 19 years ago

Reviewed by Maciej.


  • Added names to functions.


  • Removed GetPrivate/SetPrivate from callbackFunctions and callbackConstructors. The private data idiom is that a JS object stores its native implementation as private data. For functions and constructors, the native implementation is nothing more than the callback they already store, so supporting private data, too, confuses the idiom. If you *really* want, you can still create a custom function with private data.
  • API/JSCallbackConstructor.cpp:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp: (KJS::JSCallbackFunction::JSCallbackFunction):
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::staticFunctionGetter):
  • API/JSObjectRef.cpp: (JSObjectMakeFunction): (JSObjectMakeFunctionWithBody): (JSObjectGetPrivate): (JSObjectSetPrivate):
  • API/JSObjectRef.h:
  • API/minidom.c: (main):
  • API/testapi.c: (main):
File size: 31.1 KB
Line 
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
37extern "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*/
47enum {
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*/
58typedef 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
68void Initialize(JSContextRef context, JSObjectRef object, JSValueRef* exception);
69*/
70typedef 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
79void Finalize(JSObjectRef object);
80*/
81typedef void
82(*JSObjectFinalizeCallback) (JSObjectRef object);
83
84/*!
85@typedef JSObjectHasPropertyCallback
86@abstract The callback invoked when determining whether an object has a 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@result true if object has the property, otherwise false.
91@discussion If you named your function HasProperty, you would declare it like this:
92
93bool HasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
94
95If 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.
96
97This 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.
98
99If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
100*/
101typedef bool
102(*JSObjectHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName);
103
104/*!
105@typedef JSObjectGetPropertyCallback
106@abstract The callback invoked when getting a property's value.
107@param context The current execution context.
108@param object The JSObject to search for the property.
109@param propertyName A JSString containing the name of the property to get.
110@param exception A pointer to a JSValueRef in which to return an exception, if any.
111@result The property's value if object has the property, otherwise NULL.
112@discussion If you named your function GetProperty, you would declare it like this:
113
114JSValueRef GetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
115
116If 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.
117*/
118typedef JSValueRef
119(*JSObjectGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
120
121/*!
122@typedef JSObjectSetPropertyCallback
123@abstract The callback invoked when setting a property's value.
124@param context The current execution context.
125@param object The JSObject on which to set the property's value.
126@param propertyName A JSString containing the name of the property to set.
127@param value A JSValue to use as the property's value.
128@param exception A pointer to a JSValueRef in which to return an exception, if any.
129@result true if the property was set, otherwise false.
130@discussion If you named your function SetProperty, you would declare it like this:
131
132bool SetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
133
134If 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).
135*/
136typedef bool
137(*JSObjectSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
138
139/*!
140@typedef JSObjectDeletePropertyCallback
141@abstract The callback invoked when deleting a property.
142@param context The current execution context.
143@param object The JSObject in which to delete the property.
144@param propertyName A JSString containing the name of the property to delete.
145@param exception A pointer to a JSValueRef in which to return an exception, if any.
146@result true if propertyName was successfully deleted, otherwise false.
147@discussion If you named your function DeleteProperty, you would declare it like this:
148
149bool DeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
150
151If 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).
152*/
153typedef bool
154(*JSObjectDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
155
156/*!
157@typedef JSObjectGetPropertyNamesCallback
158@abstract The callback invoked to get the names of an object's properties.
159@param context The current execution context.
160@param object The JSObject whose property names need to be appended to propertyNames.
161@param accumulator A JavaScript property name accumulator, to which the object should add the names of its properties.
162@discussion If you named your function GetPropertyNames, you would declare it like this:
163
164void GetPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef accumulator);
165
166Use JSPropertyNameAccumulatorAddName to add property names to accumulator.
167
168Property lists are used by JSPropertyEnumerators and JavaScript for...in loops.
169
170It's only necessary to add names of properties that you handle
171specially in your own get / set callbacks. Static property names,
172names of standard JS properties, and properties from the prototype
173will be added automatically.
174*/
175typedef void
176(*JSObjectGetPropertyNamesCallback) (JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
177
178/*!
179@typedef JSObjectCallAsFunctionCallback
180@abstract The callback invoked when an object is called as a function.
181@param context The current execution context.
182@param function A JSObject that is the function being called.
183@param thisObject A JSObject that is the 'this' variable in the function's scope.
184@param argumentCount An integer count of the number of arguments in arguments.
185@param arguments A JSValue array of the arguments passed to the function.
186@param exception A pointer to a JSValueRef in which to return an exception, if any.
187@result A JSValue that is the function's return value.
188@discussion If you named your function CallAsFunction, you would declare it like this:
189
190JSValueRef CallAsFunction(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
191
192If your callback were invoked by the JavaScript expression 'myObject.myMemberFunction()', function would be set to myMemberFunction, and thisObject would be set to myObject.
193
194If this callback is NULL, calling your object as a function will throw an exception.
195*/
196typedef JSValueRef
197(*JSObjectCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
198
199/*!
200@typedef JSObjectCallAsConstructorCallback
201@abstract The callback invoked when an object is used as a constructor in a 'new' expression.
202@param context The current execution context.
203@param constructor A JSObject that is the constructor being called.
204@param argumentCount An integer count of the number of arguments in arguments.
205@param arguments A JSValue array of the arguments passed to the function.
206@param exception A pointer to a JSValueRef in which to return an exception, if any.
207@result A JSObject that is the constructor's return value.
208@discussion If you named your function CallAsConstructor, you would declare it like this:
209
210JSObjectRef CallAsConstructor(JSContextRef context, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
211
212If your callback were invoked by the JavaScript expression 'new myConstructorFunction()', constructor would be set to myConstructorFunction.
213
214If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
215*/
216typedef JSObjectRef
217(*JSObjectCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
218
219/*!
220@typedef JSObjectHasInstanceCallback
221@abstract hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
222@param context The current execution context.
223@param constructor The JSObject that is the target of the 'instanceof' expression.
224@param possibleInstance The JSValue being tested to determine if it is an instance of constructor.
225@param exception A pointer to a JSValueRef in which to return an exception, if any.
226@result true if possibleInstance is an instance of constructor, otherwise false.
227
228@discussion If you named your function HasInstance, you would declare it like this:
229
230bool HasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
231
232If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue.
233
234If this callback is NULL, 'instanceof' expressions that target your object will return false.
235
236Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
237*/
238typedef bool
239(*JSObjectHasInstanceCallback) (JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
240
241/*!
242@typedef JSObjectConvertToTypeCallback
243@abstract The callback invoked when converting an object to a particular JavaScript type.
244@param context The current execution context.
245@param object The JSObject to convert.
246@param type A JSType specifying the JavaScript type to convert to.
247@param exception A pointer to a JSValueRef in which to return an exception, if any.
248@result The objects's converted value, or NULL if the object was not converted.
249@discussion If you named your function ConvertToType, you would declare it like this:
250
251JSValueRef ConvertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
252
253If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
254
255This 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.
256*/
257typedef JSValueRef
258(*JSObjectConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception);
259
260/*!
261@struct JSStaticValue
262@abstract This structure describes a statically declared value property.
263@field name A null-terminated UTF8 string containing the property's name.
264@field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
265@field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value.
266@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
267*/
268typedef struct {
269 const char* const name; // FIXME: convert UTF8
270 JSObjectGetPropertyCallback getProperty;
271 JSObjectSetPropertyCallback setProperty;
272 JSPropertyAttributes attributes;
273} JSStaticValue;
274
275/*!
276@struct JSStaticFunction
277@abstract This structure describes a statically declared function property.
278@field name A null-terminated UTF8 string containing the property's name.
279@field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
280@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
281*/
282typedef struct {
283 const char* const name; // FIXME: convert UTF8
284 JSObjectCallAsFunctionCallback callAsFunction;
285 JSPropertyAttributes attributes;
286} JSStaticFunction;
287
288/*!
289@struct JSClassDefinition
290@abstract This structure contains properties and callbacks that define a type of object. All fields are optional. Any field may be NULL.
291@field version The version number of this structure. The current version is 0.
292@field className A null-terminated UTF8 string containing the class's name.
293@field parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
294@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.
295@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.
296@field initialize The callback invoked when an object is first created. Use this callback to initialize the object.
297@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.
298@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.
299@field getProperty The callback invoked when getting a property's value.
300@field setProperty The callback invoked when setting a property's value.
301@field deleteProperty The callback invoked when deleting a property.
302@field addPropertiesToList The callback invoked when adding an object's properties to a property list.
303@field callAsFunction The callback invoked when an object is called as a function.
304@field hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
305@field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.
306@field convertToType The callback invoked when converting an object to a particular JavaScript type.
307@discussion The staticValues and staticFunctions arrays are the simplest and most efficient means for vending custom properties. Statically declared properties autmatically service requests like get, set, and enumerate. Property access callbacks are required only to implement unusual properties, like array indexes, whose names are not known at compile-time.
308
309If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:
310
311JSStaticValue StaticValueArray[] = {
312 { "X", GetX, SetX, kJSPropertyAttributeNone },
313 { 0, 0, 0, 0 }
314};
315
316Standard JavaScript practice calls for storing functions in prototype objects, so derived objects can share them. Therefore, it is common for prototype classes to have function properties but no value properties, and for object classes to have value properties but no function properties.
317
318A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
319*/
320typedef struct {
321 int version; // current (and only) version is 0
322
323 const char* className;
324 JSClassRef parentClass;
325
326 JSStaticValue* staticValues;
327 JSStaticFunction* staticFunctions;
328
329 JSObjectInitializeCallback initialize;
330 JSObjectFinalizeCallback finalize;
331 JSObjectHasPropertyCallback hasProperty;
332 JSObjectGetPropertyCallback getProperty;
333 JSObjectSetPropertyCallback setProperty;
334 JSObjectDeletePropertyCallback deleteProperty;
335 JSObjectGetPropertyNamesCallback getPropertyNames;
336 JSObjectCallAsFunctionCallback callAsFunction;
337 JSObjectCallAsConstructorCallback callAsConstructor;
338 JSObjectHasInstanceCallback hasInstance;
339 JSObjectConvertToTypeCallback convertToType;
340} JSClassDefinition;
341
342/*!
343@const kJSClassDefinitionNull
344@abstract A JSClassDefinition structure of the current version, filled with NULL pointers.
345@discussion Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:
346
347JSClassDefinition definition = kJSClassDefinitionNull;
348
349definition.finalize = Finalize;
350*/
351extern const JSClassDefinition kJSClassDefinitionNull;
352
353/*!
354@function
355@abstract Creates a JavaScript class suitable for use with JSObjectMake.
356@param definition A JSClassDefinition that defines the class.
357@result A JSClass with the given definition's name, properties, callbacks, and parent class. Ownership follows the Create Rule.
358*/
359JSClassRef JSClassCreate(JSClassDefinition* definition);
360
361/*!
362@function
363@abstract Retains a JavaScript class.
364@param jsClass The JSClass to retain.
365@result A JSClass that is the same as jsClass.
366*/
367JSClassRef JSClassRetain(JSClassRef jsClass);
368/*!
369@function
370@abstract Releases a JavaScript class.
371@param jsClass The JSClass to release.
372*/
373void JSClassRelease(JSClassRef jsClass);
374
375/*!
376@function
377@abstract Creates a JavaScript object with a given class and prototype.
378@param context The execution context to use.
379@param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
380@param prototype The prototype to assign to the object. Pass NULL to use the default object prototype.
381@result A JSObject with the given class and prototype.
382*/
383JSObjectRef JSObjectMake(JSContextRef context, JSClassRef jsClass, JSValueRef prototype);
384
385/*!
386@function
387@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
388@param context The execution context to use.
389@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.
390@param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.
391@result A JSObject that is an anonymous function. The object's prototype will be the default function prototype.
392*/
393JSObjectRef JSObjectMakeFunction(JSContextRef context, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction);
394/*!
395@function
396@abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation.
397@param context The execution context to use.
398@param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' expression.
399@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
400*/
401JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor);
402
403/*!
404@function
405@abstract Creates a function with a given script as its body.
406@param context The execution context to use.
407@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.
408@param parameterCount An integer count of the number of parameter names in parameterNames.
409@param parameterNames A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
410@param body A JSString containing the script to use as the function's body.
411@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.
412@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.
413@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.
414@result A JSObject that is a function, or NULL if either body or parameterNames contains a syntax error. The object's prototype will be the default function prototype.
415@discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
416*/
417JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
418
419/*!
420@function
421@abstract Gets an object's prototype.
422@param object A JSObject whose prototype you want to get.
423@result A JSValue containing the object's prototype.
424*/
425JSValueRef JSObjectGetPrototype(JSObjectRef object);
426/*!
427@function
428@abstract Sets an object's prototype.
429@param object The JSObject whose prototype you want to set.
430@param value A JSValue to set as the object's prototype.
431*/
432void JSObjectSetPrototype(JSObjectRef object, JSValueRef value);
433
434/*!
435@function
436@abstract Tests whether an object has a given property.
437@param object The JSObject to test.
438@param propertyName A JSString containing the property's name.
439@result true if the object has a property whose name matches propertyName, otherwise false.
440*/
441bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
442
443/*!
444@function
445@abstract Gets a property from an object.
446@param context The execution context to use.
447@param object The JSObject whose property you want to get.
448@param propertyName A JSString containing the property's name.
449@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.
450@result The property's value if object has the property, otherwise NULL.
451*/
452JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
453
454/*!
455@function
456@abstract Sets a property on an object.
457@param context The execution context to use.
458@param object The JSObject whose property you want to set.
459@param propertyName A JSString containing the property's name.
460@param value A JSValue to use as the property's value.
461@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.
462@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
463*/
464void JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception);
465
466/*!
467@function
468@abstract Deletes a property from an object.
469@param context The execution context to use.
470@param object The JSObject whose property you want to delete.
471@param propertyName A JSString containing the property's name.
472@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.
473@result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
474*/
475bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
476
477/*!
478@function
479@abstract Gets a property from an object by numeric index.
480@param context The execution context to use.
481@param object The JSObject whose property you want to get.
482@param propertyIndex The property's name as a number
483@result The property's value if object has the property, otherwise NULL.
484@discussion This is equivalent to getting a property by a string name containing the number, but allows faster access to JS arrays.
485*/
486JSValueRef JSObjectGetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex);
487
488/*!
489@function
490@abstract Sets a property on an object by numeric index.
491@param context The execution context to use.
492@param object The JSObject whose property you want to set.
493@param propertyIndex The property's name as a number
494@param value A JSValue to use as the property's value.
495@discussion This is equivalent to setting a property by a string name containing the number, but allows faster access to JS arrays.
496*/
497void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value);
498
499/*!
500@function
501@abstract Gets a pointer to private data from an object.
502@param object A JSObject whose private data you want to get.
503@result A void* that points to the object's private data, if the object has private data, otherwise NULL.
504*/
505void* JSObjectGetPrivate(JSObjectRef object);
506
507/*!
508@function
509@abstract Sets a pointer to private data on an object.
510@param object A JSObject whose private data you want to set.
511@param data A void* that points to the object's private data.
512@result true if the object can store private data, otherwise false.
513@discussion Only custom objects created with a JSClass can store private data.
514*/
515bool JSObjectSetPrivate(JSObjectRef object, void* data);
516
517/*!
518@function
519@abstract Tests whether an object can be called as a function.
520@param object The JSObject to test.
521@result true if the object can be called as a function, otherwise false.
522*/
523bool JSObjectIsFunction(JSObjectRef object);
524/*!
525@function
526@abstract Calls an object as a function.
527@param context The execution context to use.
528@param object The JSObject to call as a function.
529@param thisObject The object to use as "this," or NULL to use the global object as "this."
530@param argumentCount An integer count of the number of arguments in arguments.
531@param arguments A JSValue array of the arguments to pass to the function. Pass NULL if argumentCount is 0.
532@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.
533@result The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
534*/
535JSValueRef JSObjectCallAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
536/*!
537@function
538@abstract Tests whether an object can be called as a constructor.
539@param object The JSObject to test.
540@result true if the object can be called as a constructor, otherwise false.
541*/
542bool JSObjectIsConstructor(JSObjectRef object);
543/*!
544@function
545@abstract Calls an object as a constructor.
546@param context The execution context to use.
547@param object The JSObject to call as a constructor.
548@param argumentCount An integer count of the number of arguments in arguments.
549@param arguments A JSValue array of the arguments to pass to the function. Pass NULL if argumentCount is 0.
550@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.
551@result The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
552*/
553JSObjectRef JSObjectCallAsConstructor(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
554
555/*!
556@function
557@abstract Get the names of all enumerable properties of an object.
558@param context The execution context to use.
559@param object The object from which to get property names.
560@result A JSPropertyNameArray containing the names of all the object's enumerable properties.
561*/
562JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef context, JSObjectRef object);
563
564/*!
565@function
566@abstract Retains a JavaScript property name array.
567@param array The JSPropertyNameArray to retain.
568@result A JSPropertyNameArray that is the same as array.
569*/
570JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array);
571
572/*!
573@function
574@abstract Releases a JavaScript property name array.
575@param array The JSPropetyNameArray to release.
576*/
577void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array);
578
579/*!
580@function
581@abstract Get the number of items in a JavaScript property name array.
582@param array The array from which to retrieve the count.
583@result The count of items in the array.
584*/
585size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array);
586
587/*!
588@function
589@abstract Get a single item from a JavaScript property name array.
590@param array The array from which to retrieve a property name.
591@param index The index of the property name to retrieve.
592@result A JSStringRef containing the name of the property.
593*/
594JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index);
595
596/*!
597@function
598@abstract Add a property name - useful while getting the property names for an object.
599@param accumulator The accumulator object to which to add the property.
600@param propertyName The new property to add.
601*/
602void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName);
603
604#ifdef __cplusplus
605}
606#endif
607
608#endif // JSObjectRef_h
Note: See TracBrowser for help on using the repository browser.