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

Last change on this file since 36016 was 34606, checked in by Simon Hausmann, 17 years ago

2008-06-16 Thiago Macieira <[email protected]>

Reviewed by Darin.

https://bugs.webkit.org/show_bug.cgi?id=19577

Fix compilation in C++ environments where C99 headers are not present

The stdbool.h header is a C99 feature, defining the "_Bool" type as well as the
"true" and "false" constants. But it's completely unnecessary in C++ as the
language already defines the "bool" type and its two values.

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