]> git.saurik.com Git - apple/javascriptcore.git/blame - API/JSObjectRef.h
JavaScriptCore-461.tar.gz
[apple/javascriptcore.git] / API / JSObjectRef.h
CommitLineData
b37bf2e1
A
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * Copyright (C) 2006, 2007 Apple 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@enum JSClassAttribute
62@constant kJSClassAttributeNone Specifies that a class has no special attributes.
63@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.
64*/
65enum {
66 kJSClassAttributeNone = 0,
67 kJSClassAttributeNoAutomaticPrototype = 1 << 1
68};
69
70/*!
71@typedef JSClassAttributes
72@abstract A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
73*/
74typedef unsigned JSClassAttributes;
75
76/*!
77@typedef JSObjectInitializeCallback
78@abstract The callback invoked when an object is first created.
79@param ctx The execution context to use.
80@param object The JSObject being created.
81@discussion If you named your function Initialize, you would declare it like this:
82
83void Initialize(JSContextRef ctx, JSObjectRef object);
84
85Unlike the other object callbacks, the initialize callback is called on the least
86derived class (the parent class) first, and the most derived class last.
87*/
88typedef void
89(*JSObjectInitializeCallback) (JSContextRef ctx, JSObjectRef object);
90
91/*!
92@typedef JSObjectFinalizeCallback
93@abstract The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
94@param object The JSObject being finalized.
95@discussion If you named your function Finalize, you would declare it like this:
96
97void Finalize(JSObjectRef object);
98
99The finalize callback is called on the most derived class first, and the least
100derived class (the parent class) last.
101
102You must not call any function that may cause a garbage collection or an allocation
103of a garbage collected object from within a JSObjectFinalizeCallback. This includes
104all functions that have a JSContextRef parameter.
105*/
106typedef void
107(*JSObjectFinalizeCallback) (JSObjectRef object);
108
109/*!
110@typedef JSObjectHasPropertyCallback
111@abstract The callback invoked when determining whether an object has a property.
112@param ctx The execution context to use.
113@param object The JSObject to search for the property.
114@param propertyName A JSString containing the name of the property look up.
115@result true if object has the property, otherwise false.
116@discussion If you named your function HasProperty, you would declare it like this:
117
118bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
119
120If 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.
121
122This 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.
123
124If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
125*/
126typedef bool
127(*JSObjectHasPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
128
129/*!
130@typedef JSObjectGetPropertyCallback
131@abstract The callback invoked when getting a property's value.
132@param ctx The execution context to use.
133@param object The JSObject to search for the property.
134@param propertyName A JSString containing the name of the property to get.
135@param exception A pointer to a JSValueRef in which to return an exception, if any.
136@result The property's value if object has the property, otherwise NULL.
137@discussion If you named your function GetProperty, you would declare it like this:
138
139JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
140
141If 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.
142*/
143typedef JSValueRef
144(*JSObjectGetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
145
146/*!
147@typedef JSObjectSetPropertyCallback
148@abstract The callback invoked when setting a property's value.
149@param ctx The execution context to use.
150@param object The JSObject on which to set the property's value.
151@param propertyName A JSString containing the name of the property to set.
152@param value A JSValue to use as the property's value.
153@param exception A pointer to a JSValueRef in which to return an exception, if any.
154@result true if the property was set, otherwise false.
155@discussion If you named your function SetProperty, you would declare it like this:
156
157bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
158
159If 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).
160*/
161typedef bool
162(*JSObjectSetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
163
164/*!
165@typedef JSObjectDeletePropertyCallback
166@abstract The callback invoked when deleting a property.
167@param ctx The execution context to use.
168@param object The JSObject in which to delete the property.
169@param propertyName A JSString containing the name of the property to delete.
170@param exception A pointer to a JSValueRef in which to return an exception, if any.
171@result true if propertyName was successfully deleted, otherwise false.
172@discussion If you named your function DeleteProperty, you would declare it like this:
173
174bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
175
176If 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).
177*/
178typedef bool
179(*JSObjectDeletePropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
180
181/*!
182@typedef JSObjectGetPropertyNamesCallback
183@abstract The callback invoked when collecting the names of an object's properties.
184@param ctx The execution context to use.
185@param object The JSObject whose property names are being collected.
186@param accumulator A JavaScript property name accumulator in which to accumulate the names of object's properties.
187@discussion If you named your function GetPropertyNames, you would declare it like this:
188
189void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
190
191Property name accumulators are used by JSObjectCopyPropertyNames and JavaScript for...in loops.
192
193Use 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.
194*/
195typedef void
196(*JSObjectGetPropertyNamesCallback) (JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
197
198/*!
199@typedef JSObjectCallAsFunctionCallback
200@abstract The callback invoked when an object is called as a function.
201@param ctx The execution context to use.
202@param function A JSObject that is the function being called.
203@param thisObject A JSObject that is the 'this' variable in the function's scope.
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 JSValue that is the function's return value.
208@discussion If you named your function CallAsFunction, you would declare it like this:
209
210JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
211
212If your callback were invoked by the JavaScript expression 'myObject.myFunction()', function would be set to myFunction, and thisObject would be set to myObject.
213
214If this callback is NULL, calling your object as a function will throw an exception.
215*/
216typedef JSValueRef
217(*JSObjectCallAsFunctionCallback) (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
218
219/*!
220@typedef JSObjectCallAsConstructorCallback
221@abstract The callback invoked when an object is used as a constructor in a 'new' expression.
222@param ctx The execution context to use.
223@param constructor A JSObject that is the constructor being called.
224@param argumentCount An integer count of the number of arguments in arguments.
225@param arguments A JSValue array of the arguments passed to the function.
226@param exception A pointer to a JSValueRef in which to return an exception, if any.
227@result A JSObject that is the constructor's return value.
228@discussion If you named your function CallAsConstructor, you would declare it like this:
229
230JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
231
232If your callback were invoked by the JavaScript expression 'new myConstructor()', constructor would be set to myConstructor.
233
234If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
235*/
236typedef JSObjectRef
237(*JSObjectCallAsConstructorCallback) (JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
238
239/*!
240@typedef JSObjectHasInstanceCallback
241@abstract hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
242@param ctx The execution context to use.
243@param constructor The JSObject that is the target of the 'instanceof' expression.
244@param possibleInstance The JSValue being tested to determine if it is an instance of constructor.
245@param exception A pointer to a JSValueRef in which to return an exception, if any.
246@result true if possibleInstance is an instance of constructor, otherwise false.
247@discussion If you named your function HasInstance, you would declare it like this:
248
249bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
250
251If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue.
252
253If this callback is NULL, 'instanceof' expressions that target your object will return false.
254
255Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
256*/
257typedef bool
258(*JSObjectHasInstanceCallback) (JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
259
260/*!
261@typedef JSObjectConvertToTypeCallback
262@abstract The callback invoked when converting an object to a particular JavaScript type.
263@param ctx The execution context to use.
264@param object The JSObject to convert.
265@param type A JSType specifying the JavaScript type to convert to.
266@param exception A pointer to a JSValueRef in which to return an exception, if any.
267@result The objects's converted value, or NULL if the object was not converted.
268@discussion If you named your function ConvertToType, you would declare it like this:
269
270JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
271
272If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
273
274This 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.
275*/
276typedef JSValueRef
277(*JSObjectConvertToTypeCallback) (JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
278
279/*!
280@struct JSStaticValue
281@abstract This structure describes a statically declared value property.
282@field name A null-terminated UTF8 string containing the property's name.
283@field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
284@field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. May be NULL if the ReadOnly attribute is set.
285@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
286*/
287typedef struct {
288 const char* const name;
289 JSObjectGetPropertyCallback getProperty;
290 JSObjectSetPropertyCallback setProperty;
291 JSPropertyAttributes attributes;
292} JSStaticValue;
293
294/*!
295@struct JSStaticFunction
296@abstract This structure describes a statically declared function property.
297@field name A null-terminated UTF8 string containing the property's name.
298@field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
299@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
300*/
301typedef struct {
302 const char* const name;
303 JSObjectCallAsFunctionCallback callAsFunction;
304 JSPropertyAttributes attributes;
305} JSStaticFunction;
306
307/*!
308@struct JSClassDefinition
309@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.
310@field version The version number of this structure. The current version is 0.
311@field attributes A logically ORed set of JSClassAttributes to give to the class.
312@field className A null-terminated UTF8 string containing the class's name.
313@field parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
314@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.
315@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.
316@field initialize The callback invoked when an object is first created. Use this callback to initialize the object.
317@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.
318@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.
319@field getProperty The callback invoked when getting a property's value.
320@field setProperty The callback invoked when setting a property's value.
321@field deleteProperty The callback invoked when deleting a property.
322@field getPropertyNames The callback invoked when collecting the names of an object's properties.
323@field callAsFunction The callback invoked when an object is called as a function.
324@field hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
325@field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.
326@field convertToType The callback invoked when converting an object to a particular JavaScript type.
327@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.
328
329If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:
330
331JSStaticValue StaticValueArray[] = {
332 { "X", GetX, SetX, kJSPropertyAttributeNone },
333 { 0, 0, 0, 0 }
334};
335
336Standard 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.
337
338A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
339*/
340typedef struct {
341 int version; // current (and only) version is 0
342 JSClassAttributes attributes;
343
344 const char* className;
345 JSClassRef parentClass;
346
347 const JSStaticValue* staticValues;
348 const JSStaticFunction* staticFunctions;
349
350 JSObjectInitializeCallback initialize;
351 JSObjectFinalizeCallback finalize;
352 JSObjectHasPropertyCallback hasProperty;
353 JSObjectGetPropertyCallback getProperty;
354 JSObjectSetPropertyCallback setProperty;
355 JSObjectDeletePropertyCallback deleteProperty;
356 JSObjectGetPropertyNamesCallback getPropertyNames;
357 JSObjectCallAsFunctionCallback callAsFunction;
358 JSObjectCallAsConstructorCallback callAsConstructor;
359 JSObjectHasInstanceCallback hasInstance;
360 JSObjectConvertToTypeCallback convertToType;
361} JSClassDefinition;
362
363/*!
364@const kJSClassDefinitionEmpty
365@abstract A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.
366@discussion Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:
367
368JSClassDefinition definition = kJSClassDefinitionEmpty;
369definition.finalize = Finalize;
370*/
371JS_EXPORT extern const JSClassDefinition kJSClassDefinitionEmpty;
372
373/*!
374@function
375@abstract Creates a JavaScript class suitable for use with JSObjectMake.
376@param definition A JSClassDefinition that defines the class.
377@result A JSClass with the given definition. Ownership follows the Create Rule.
378*/
379JS_EXPORT JSClassRef JSClassCreate(const JSClassDefinition* definition);
380
381/*!
382@function
383@abstract Retains a JavaScript class.
384@param jsClass The JSClass to retain.
385@result A JSClass that is the same as jsClass.
386*/
387JS_EXPORT JSClassRef JSClassRetain(JSClassRef jsClass);
388
389/*!
390@function
391@abstract Releases a JavaScript class.
392@param jsClass The JSClass to release.
393*/
394JS_EXPORT void JSClassRelease(JSClassRef jsClass);
395
396/*!
397@function
398@abstract Creates a JavaScript object.
399@param ctx The execution context to use.
400@param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
401@param data A void* to set as the object's private data. Pass NULL to specify no private data.
402@result A JSObject with the given class and private data.
403@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.
404
405data 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.
406*/
407JS_EXPORT JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data);
408
409/*!
410@function
411@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
412@param ctx The execution context to use.
413@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.
414@param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.
415@result A JSObject that is a function. The object's prototype will be the default function prototype.
416*/
417JS_EXPORT JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction);
418
419/*!
420@function
421@abstract Convenience method for creating a JavaScript constructor.
422@param ctx The execution context to use.
423@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.
424@param callAsConstructor A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.
425@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
426@discussion The default object constructor takes no arguments and constructs an object of class jsClass with no private data.
427*/
428JS_EXPORT JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor);
429
430/*!
431@function
432@abstract Creates a function with a given script as its body.
433@param ctx The execution context to use.
434@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.
435@param parameterCount An integer count of the number of parameter names in parameterNames.
436@param parameterNames A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
437@param body A JSString containing the script to use as the function's body.
438@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.
439@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.
440@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.
441@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.
442@discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
443*/
444JS_EXPORT JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
445
446/*!
447@function
448@abstract Gets an object's prototype.
449@param ctx The execution context to use.
450@param object A JSObject whose prototype you want to get.
451@result A JSValue that is the object's prototype.
452*/
453JS_EXPORT JSValueRef JSObjectGetPrototype(JSContextRef ctx, JSObjectRef object);
454
455/*!
456@function
457@abstract Sets an object's prototype.
458@param ctx The execution context to use.
459@param object The JSObject whose prototype you want to set.
460@param value A JSValue to set as the object's prototype.
461*/
462JS_EXPORT void JSObjectSetPrototype(JSContextRef ctx, JSObjectRef object, JSValueRef value);
463
464/*!
465@function
466@abstract Tests whether an object has a given property.
467@param object The JSObject to test.
468@param propertyName A JSString containing the property's name.
469@result true if the object has a property whose name matches propertyName, otherwise false.
470*/
471JS_EXPORT bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
472
473/*!
474@function
475@abstract Gets a property from an object.
476@param ctx The execution context to use.
477@param object The JSObject whose property you want to get.
478@param propertyName A JSString containing the property's name.
479@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.
480@result The property's value if object has the property, otherwise the undefined value.
481*/
482JS_EXPORT JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
483
484/*!
485@function
486@abstract Sets a property on an object.
487@param ctx The execution context to use.
488@param object The JSObject whose property you want to set.
489@param propertyName A JSString containing the property's name.
490@param value A JSValue to use as the property's value.
491@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.
492@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
493*/
494JS_EXPORT void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception);
495
496/*!
497@function
498@abstract Deletes a property from an object.
499@param ctx The execution context to use.
500@param object The JSObject whose property you want to delete.
501@param propertyName A JSString containing the property's name.
502@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.
503@result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
504*/
505JS_EXPORT bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
506
507/*!
508@function
509@abstract Gets a property from an object by numeric index.
510@param ctx The execution context to use.
511@param object The JSObject whose property you want to get.
512@param propertyIndex An integer value that is the property's name.
513@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.
514@result The property's value if object has the property, otherwise the undefined value.
515@discussion Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.
516*/
517JS_EXPORT JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception);
518
519/*!
520@function
521@abstract Sets a property on an object by numeric index.
522@param ctx The execution context to use.
523@param object The JSObject whose property you want to set.
524@param propertyIndex The property's name as a number.
525@param value A JSValue to use as the property's value.
526@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.
527@discussion Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.
528*/
529JS_EXPORT void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception);
530
531/*!
532@function
533@abstract Gets an object's private data.
534@param object A JSObject whose private data you want to get.
535@result A void* that is the object's private data, if the object has private data, otherwise NULL.
536*/
537JS_EXPORT void* JSObjectGetPrivate(JSObjectRef object);
538
539/*!
540@function
541@abstract Sets a pointer to private data on an object.
542@param object The JSObject whose private data you want to set.
543@param data A void* to set as the object's private data.
544@result true if object can store private data, otherwise false.
545@discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
546*/
547JS_EXPORT bool JSObjectSetPrivate(JSObjectRef object, void* data);
548
549/*!
550@function
551@abstract Tests whether an object can be called as a function.
552@param ctx The execution context to use.
553@param object The JSObject to test.
554@result true if the object can be called as a function, otherwise false.
555*/
556JS_EXPORT bool JSObjectIsFunction(JSContextRef ctx, JSObjectRef object);
557
558/*!
559@function
560@abstract Calls an object as a function.
561@param ctx The execution context to use.
562@param object The JSObject to call as a function.
563@param thisObject The object to use as "this," or NULL to use the global object as "this."
564@param argumentCount An integer count of the number of arguments in arguments.
565@param arguments A JSValue array of arguments to pass to the function. Pass NULL if argumentCount is 0.
566@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.
567@result The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
568*/
569JS_EXPORT JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
570
571/*!
572@function
573@abstract Tests whether an object can be called as a constructor.
574@param ctx The execution context to use.
575@param object The JSObject to test.
576@result true if the object can be called as a constructor, otherwise false.
577*/
578JS_EXPORT bool JSObjectIsConstructor(JSContextRef ctx, JSObjectRef object);
579
580/*!
581@function
582@abstract Calls an object as a constructor.
583@param ctx The execution context to use.
584@param object The JSObject to call as a constructor.
585@param argumentCount An integer count of the number of arguments in arguments.
586@param arguments A JSValue array of arguments to pass to the constructor. Pass NULL if argumentCount is 0.
587@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.
588@result The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
589*/
590JS_EXPORT JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
591
592/*!
593@function
594@abstract Gets the names of an object's enumerable properties.
595@param ctx The execution context to use.
596@param object The object whose property names you want to get.
597@result A JSPropertyNameArray containing the names object's enumerable properties. Ownership follows the Create Rule.
598*/
599JS_EXPORT JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object);
600
601/*!
602@function
603@abstract Retains a JavaScript property name array.
604@param array The JSPropertyNameArray to retain.
605@result A JSPropertyNameArray that is the same as array.
606*/
607JS_EXPORT JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array);
608
609/*!
610@function
611@abstract Releases a JavaScript property name array.
612@param array The JSPropetyNameArray to release.
613*/
614JS_EXPORT void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array);
615
616/*!
617@function
618@abstract Gets a count of the number of items in a JavaScript property name array.
619@param array The array from which to retrieve the count.
620@result An integer count of the number of names in array.
621*/
622JS_EXPORT size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array);
623
624/*!
625@function
626@abstract Gets a property name at a given index in a JavaScript property name array.
627@param array The array from which to retrieve the property name.
628@param index The index of the property name to retrieve.
629@result A JSStringRef containing the property name.
630*/
631JS_EXPORT JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index);
632
633/*!
634@function
635@abstract Adds a property name to a JavaScript property name accumulator.
636@param accumulator The accumulator object to which to add the property name.
637@param propertyName The property name to add.
638*/
639JS_EXPORT void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName);
640
641#ifdef __cplusplus
642}
643#endif
644
645#endif // JSObjectRef_h