1 // -*- mode: c++; c-basic-offset: 4 -*-
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #include <JavaScriptCore/JSBase.h>
31 #include <JavaScriptCore/JSValueRef.h>
34 #include <stddef.h> // for size_t
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.
48 kJSPropertyAttributeNone
= 0,
49 kJSPropertyAttributeReadOnly
= 1 << 1,
50 kJSPropertyAttributeDontEnum
= 1 << 2,
51 kJSPropertyAttributeDontDelete
= 1 << 3
55 @typedef JSPropertyAttributes
56 @abstract A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
58 typedef unsigned JSPropertyAttributes
;
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.
66 kJSClassAttributeNone
= 0,
67 kJSClassAttributeNoAutomaticPrototype
= 1 << 1
71 @typedef JSClassAttributes
72 @abstract A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
74 typedef unsigned JSClassAttributes
;
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:
83 void Initialize(JSContextRef ctx, JSObjectRef object);
85 Unlike the other object callbacks, the initialize callback is called on the least
86 derived class (the parent class) first, and the most derived class last.
89 (*JSObjectInitializeCallback
) (JSContextRef ctx
, JSObjectRef object
);
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:
97 void Finalize(JSObjectRef object);
99 The finalize callback is called on the most derived class first, and the least
100 derived class (the parent class) last.
102 You must not call any function that may cause a garbage collection or an allocation
103 of a garbage collected object from within a JSObjectFinalizeCallback. This includes
104 all functions that have a JSContextRef parameter.
107 (*JSObjectFinalizeCallback
) (JSObjectRef object
);
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:
118 bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
120 If this function returns false, the hasProperty request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
122 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.
124 If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
127 (*JSObjectHasPropertyCallback
) (JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
);
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:
139 JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
141 If this function returns NULL, the get request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
144 (*JSObjectGetPropertyCallback
) (JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef
* exception
);
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:
157 bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
159 If this function returns false, the set request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
162 (*JSObjectSetPropertyCallback
) (JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef value
, JSValueRef
* exception
);
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:
174 bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
176 If this function returns false, the delete request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
179 (*JSObjectDeletePropertyCallback
) (JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef
* exception
);
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:
189 void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
191 Property name accumulators are used by JSObjectCopyPropertyNames and JavaScript for...in loops.
193 Use JSPropertyNameAccumulatorAddName to add property names to accumulator. A class's getPropertyNames callback only needs to provide the names of properties that the class vends through a custom getProperty or setProperty callback. Other properties, including statically declared properties, properties vended by other classes, and properties belonging to object's prototype, are added independently.
196 (*JSObjectGetPropertyNamesCallback
) (JSContextRef ctx
, JSObjectRef object
, JSPropertyNameAccumulatorRef propertyNames
);
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:
210 JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
212 If your callback were invoked by the JavaScript expression 'myObject.myFunction()', function would be set to myFunction, and thisObject would be set to myObject.
214 If this callback is NULL, calling your object as a function will throw an exception.
217 (*JSObjectCallAsFunctionCallback
) (JSContextRef ctx
, JSObjectRef function
, JSObjectRef thisObject
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
);
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:
230 JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
232 If your callback were invoked by the JavaScript expression 'new myConstructor()', constructor would be set to myConstructor.
234 If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
237 (*JSObjectCallAsConstructorCallback
) (JSContextRef ctx
, JSObjectRef constructor
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
);
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:
249 bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
251 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.
253 If this callback is NULL, 'instanceof' expressions that target your object will return false.
255 Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
258 (*JSObjectHasInstanceCallback
) (JSContextRef ctx
, JSObjectRef constructor
, JSValueRef possibleInstance
, JSValueRef
* exception
);
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:
270 JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
272 If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
274 This function is only invoked when converting an object to number or string. An object converted to boolean is 'true.' An object converted to object is itself.
277 (*JSObjectConvertToTypeCallback
) (JSContextRef ctx
, JSObjectRef object
, JSType type
, JSValueRef
* exception
);
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.
288 const char* const name
;
289 JSObjectGetPropertyCallback getProperty
;
290 JSObjectSetPropertyCallback setProperty
;
291 JSPropertyAttributes attributes
;
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.
302 const char* const name
;
303 JSObjectCallAsFunctionCallback callAsFunction
;
304 JSPropertyAttributes attributes
;
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.
329 If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:
331 JSStaticValue StaticValueArray[] = {
332 { "X", GetX, SetX, kJSPropertyAttributeNone },
336 Standard JavaScript practice calls for storing function objects in prototypes, so they can be shared. The default JSClass created by JSClassCreate follows this idiom, instantiating objects with a shared, automatically generating prototype containing the class's function objects. The kJSClassAttributeNoAutomaticPrototype attribute specifies that a JSClass should not automatically generate such a prototype. The resulting JSClass instantiates objects with the default object prototype, and gives each instance object its own copy of the class's function objects.
338 A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
341 int version
; // current (and only) version is 0
342 JSClassAttributes attributes
;
344 const char* className
;
345 JSClassRef parentClass
;
347 const JSStaticValue
* staticValues
;
348 const JSStaticFunction
* staticFunctions
;
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
;
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:
368 JSClassDefinition definition = kJSClassDefinitionEmpty;
369 definition.finalize = Finalize;
371 JS_EXPORT
extern const JSClassDefinition kJSClassDefinitionEmpty
;
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.
379 JS_EXPORT JSClassRef
JSClassCreate(const JSClassDefinition
* definition
);
383 @abstract Retains a JavaScript class.
384 @param jsClass The JSClass to retain.
385 @result A JSClass that is the same as jsClass.
387 JS_EXPORT JSClassRef
JSClassRetain(JSClassRef jsClass
);
391 @abstract Releases a JavaScript class.
392 @param jsClass The JSClass to release.
394 JS_EXPORT
void JSClassRelease(JSClassRef jsClass
);
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.
405 data is set on the created object before the intialize methods in its class chain are called. This enables the initialize methods to retrieve and manipulate data through JSObjectGetPrivate.
407 JS_EXPORT JSObjectRef
JSObjectMake(JSContextRef ctx
, JSClassRef jsClass
, void* data
);
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.
417 JS_EXPORT JSObjectRef
JSObjectMakeFunctionWithCallback(JSContextRef ctx
, JSStringRef name
, JSObjectCallAsFunctionCallback callAsFunction
);
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.
428 JS_EXPORT JSObjectRef
JSObjectMakeConstructor(JSContextRef ctx
, JSClassRef jsClass
, JSObjectCallAsConstructorCallback callAsConstructor
);
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.
444 JS_EXPORT JSObjectRef
JSObjectMakeFunction(JSContextRef ctx
, JSStringRef name
, unsigned parameterCount
, const JSStringRef parameterNames
[], JSStringRef body
, JSStringRef sourceURL
, int startingLineNumber
, JSValueRef
* exception
);
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.
453 JS_EXPORT JSValueRef
JSObjectGetPrototype(JSContextRef ctx
, JSObjectRef object
);
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.
462 JS_EXPORT
void JSObjectSetPrototype(JSContextRef ctx
, JSObjectRef object
, JSValueRef value
);
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.
471 JS_EXPORT
bool JSObjectHasProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
);
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.
482 JS_EXPORT JSValueRef
JSObjectGetProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef
* exception
);
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.
494 JS_EXPORT
void JSObjectSetProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef value
, JSPropertyAttributes attributes
, JSValueRef
* exception
);
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).
505 JS_EXPORT
bool JSObjectDeleteProperty(JSContextRef ctx
, JSObjectRef object
, JSStringRef propertyName
, JSValueRef
* exception
);
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.
517 JS_EXPORT JSValueRef
JSObjectGetPropertyAtIndex(JSContextRef ctx
, JSObjectRef object
, unsigned propertyIndex
, JSValueRef
* exception
);
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.
529 JS_EXPORT
void JSObjectSetPropertyAtIndex(JSContextRef ctx
, JSObjectRef object
, unsigned propertyIndex
, JSValueRef value
, JSValueRef
* exception
);
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.
537 JS_EXPORT
void* JSObjectGetPrivate(JSObjectRef object
);
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.
547 JS_EXPORT
bool JSObjectSetPrivate(JSObjectRef object
, void* data
);
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.
556 JS_EXPORT
bool JSObjectIsFunction(JSContextRef ctx
, JSObjectRef object
);
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.
569 JS_EXPORT JSValueRef
JSObjectCallAsFunction(JSContextRef ctx
, JSObjectRef object
, JSObjectRef thisObject
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
);
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.
578 JS_EXPORT
bool JSObjectIsConstructor(JSContextRef ctx
, JSObjectRef object
);
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.
590 JS_EXPORT JSObjectRef
JSObjectCallAsConstructor(JSContextRef ctx
, JSObjectRef object
, size_t argumentCount
, const JSValueRef arguments
[], JSValueRef
* exception
);
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.
599 JS_EXPORT JSPropertyNameArrayRef
JSObjectCopyPropertyNames(JSContextRef ctx
, JSObjectRef object
);
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.
607 JS_EXPORT JSPropertyNameArrayRef
JSPropertyNameArrayRetain(JSPropertyNameArrayRef array
);
611 @abstract Releases a JavaScript property name array.
612 @param array The JSPropetyNameArray to release.
614 JS_EXPORT
void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array
);
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.
622 JS_EXPORT
size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array
);
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.
631 JS_EXPORT JSStringRef
JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array
, size_t index
);
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.
639 JS_EXPORT
void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef accumulator
, JSStringRef propertyName
);
645 #endif // JSObjectRef_h