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