docs
Loading...
Searching...
No Matches
JSObjectRef.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2019 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Kelvin W Sherlock ([email protected])
4 * Copyright (C) 2020 Janrupf ([email protected])
5 * Copyright (C) 2025 Ultralight, Inc. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef JSObjectRef_h
30#define JSObjectRef_h
31
35
36#ifndef __cplusplus
37#include <stdbool.h>
38#endif
39#include <stddef.h> /* for size_t */
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/*!
46@enum JSPropertyAttribute
47@constant kJSPropertyAttributeNone Specifies that a property has no special attributes.
48@constant kJSPropertyAttributeReadOnly Specifies that a property is read-only.
49@constant kJSPropertyAttributeDontEnum Specifies that a property should not be enumerated by JSPropertyEnumerators and JavaScript for...in loops.
50@constant kJSPropertyAttributeDontDelete Specifies that the delete operation should fail on a property.
51*/
52enum {
57};
58
59/*!
60@typedef JSPropertyAttributes
61@abstract A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
62*/
63typedef unsigned JSPropertyAttributes;
64
65/*!
66@enum JSClassAttribute
67@constant kJSClassAttributeNone Specifies that a class has no special attributes.
68@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.
69*/
70enum {
73};
74
75/*!
76@typedef JSClassAttributes
77@abstract A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
78*/
79typedef unsigned JSClassAttributes;
80
81/*!
82@typedef JSObjectInitializeCallback
83@abstract The callback invoked when an object is first created.
84@param ctx The execution context to use.
85@param object The JSObject being created.
86@discussion If you named your function Initialize, you would declare it like this:
87
88void Initialize(JSContextRef ctx, JSObjectRef object);
89
90Unlike the other object callbacks, the initialize callback is called on the least
91derived class (the parent class) first, and the most derived class last.
92*/
93typedef void
95
96/* Extension of the above callback with the class that the method is being invoked for. */
97typedef void
99
100/*!
101@typedef JSObjectFinalizeCallback
102@abstract The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
103@param object The JSObject being finalized.
104@discussion If you named your function Finalize, you would declare it like this:
105
106void Finalize(JSObjectRef object);
107
108The finalize callback is called on the most derived class first, and the least
109derived class (the parent class) last.
110
111You must not call any function that may cause a garbage collection or an allocation
112of a garbage collected object from within a JSObjectFinalizeCallback. This includes
113all functions that have a JSContextRef parameter.
114*/
115typedef void
117
118/* Extension of the above callback with the class that the method is being invoked for. */
119typedef void
121
122/*!
123@typedef JSObjectHasPropertyCallback
124@abstract The callback invoked when determining whether an object has a property.
125@param ctx The execution context to use.
126@param object The JSObject to search for the property.
127@param propertyName A JSString containing the name of the property look up.
128@result true if object has the property, otherwise false.
129@discussion If you named your function HasProperty, you would declare it like this:
130
131bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
132
133If 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.
134
135This 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.
136
137If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
138*/
139typedef bool
141
142/* Extension of the above callback with the class that the method is being invoked for. */
143typedef bool
144(*JSObjectHasPropertyCallbackEx) (JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName);
145
146/*!
147@typedef JSObjectGetPropertyCallback
148@abstract The callback invoked when getting a property's value.
149@param ctx The execution context to use.
150@param object The JSObject to search for the property.
151@param propertyName A JSString containing the name of the property to get.
152@param exception A pointer to a JSValueRef in which to return an exception, if any.
153@result The property's value if object has the property, otherwise NULL.
154@discussion If you named your function GetProperty, you would declare it like this:
155
156JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
157
158If 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.
159*/
161(*JSObjectGetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
162
163/* Extension of the above callback with the class that the method is being invoked for. */
165(*JSObjectGetPropertyCallbackEx) (JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
166
167/*!
168@typedef JSObjectSetPropertyCallback
169@abstract The callback invoked when setting a property's value.
170@param ctx The execution context to use.
171@param object The JSObject on which to set the property's value.
172@param propertyName A JSString containing the name of the property to set.
173@param value A JSValue to use as the property's value.
174@param exception A pointer to a JSValueRef in which to return an exception, if any.
175@result true if the property was set, otherwise false.
176@discussion If you named your function SetProperty, you would declare it like this:
177
178bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
179
180If 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).
181*/
182typedef bool
183(*JSObjectSetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
184
185/* Extension of the above callback with the class that the method is being invoked for. */
186typedef bool
187(*JSObjectSetPropertyCallbackEx) (JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
188
189/*!
190@typedef JSObjectDeletePropertyCallback
191@abstract The callback invoked when deleting a property.
192@param ctx The execution context to use.
193@param object The JSObject in which to delete the property.
194@param propertyName A JSString containing the name of the property to delete.
195@param exception A pointer to a JSValueRef in which to return an exception, if any.
196@result true if propertyName was successfully deleted, otherwise false.
197@discussion If you named your function DeleteProperty, you would declare it like this:
198
199bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
200
201If 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).
202*/
203typedef bool
204(*JSObjectDeletePropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
205
206/* Extension of the above callback with the class that the method is being invoked for. */
207typedef bool
208(*JSObjectDeletePropertyCallbackEx) (JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
209
210/*!
211@typedef JSObjectGetPropertyNamesCallback
212@abstract The callback invoked when collecting the names of an object's properties.
213@param ctx The execution context to use.
214@param object The JSObject whose property names are being collected.
215@param propertyNames A JavaScript property name accumulator in which to accumulate the names of object's properties.
216@discussion If you named your function GetPropertyNames, you would declare it like this:
217
218void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
219
220Property name accumulators are used by JSObjectCopyPropertyNames and JavaScript for...in loops.
221
222Use 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.
223*/
224typedef void
226
227/* Extension of the above callback with the class that the method is being invoked for. */
228typedef void
230
231/*!
232@typedef JSObjectCallAsFunctionCallback
233@abstract The callback invoked when an object is called as a function.
234@param ctx The execution context to use.
235@param function A JSObject that is the function being called.
236@param thisObject A JSObject that is the 'this' variable in the function's scope.
237@param argumentCount An integer count of the number of arguments in arguments.
238@param arguments A JSValue array of the arguments passed to the function.
239@param exception A pointer to a JSValueRef in which to return an exception, if any.
240@result A JSValue that is the function's return value.
241@discussion If you named your function CallAsFunction, you would declare it like this:
242
243JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
244
245If your callback were invoked by the JavaScript expression 'myObject.myFunction()', function would be set to myFunction, and thisObject would be set to myObject.
246
247If this callback is NULL, calling your object as a function will throw an exception.
248*/
250(*JSObjectCallAsFunctionCallback) (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
251
252/* Extension of the above callback with the class that the method is being invoked for. */
254(*JSObjectCallAsFunctionCallbackEx) (JSContextRef ctx, JSClassRef jsClass, JSStringRef className, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
255
256/*!
257@typedef JSObjectCallAsFunctionDataCallback
258@abstract The callback invoked when a function created with JSObjectMakeFunctionWithData is called.
259@param ctx The execution context to use.
260@param userData The user data pointer the function was created with.
261@param function A JSObject that is the function being called.
262@param thisObject A JSObject that is the 'this' variable in the function's scope.
263@param argumentCount An integer count of the number of arguments in arguments.
264@param arguments A JSValue array of the arguments passed to the function.
265@param exception A pointer to a JSValueRef in which to return an exception, if any.
266@result A JSValue that is the function's return value.
267*/
269(*JSObjectCallAsFunctionDataCallback) (JSContextRef ctx, void* userData, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
270
271/*!
272@typedef JSFunctionDataFinalizeCallback
273@abstract The callback invoked when a function created with JSObjectMakeFunctionWithData is garbage collected.
274@param userData The user data pointer the function was created with.
275@discussion Called exactly once, either when the function object is garbage collected or when its
276 context group is destroyed. It runs with the context group's internal lock held: you must not call
277 any function that may cause a garbage collection or an allocation of a garbage collected object
278 from within a JSFunctionDataFinalizeCallback. This includes all functions that have a JSContextRef
279 parameter.
280*/
281typedef void
282(*JSFunctionDataFinalizeCallback) (void* userData);
283
284/*!
285@typedef JSObjectCallAsConstructorCallback
286@abstract The callback invoked when an object is used as a constructor in a 'new' expression.
287@param ctx The execution context to use.
288@param constructor A JSObject that is the constructor being called.
289@param argumentCount An integer count of the number of arguments in arguments.
290@param arguments A JSValue array of the arguments passed to the function.
291@param exception A pointer to a JSValueRef in which to return an exception, if any.
292@result A JSObject that is the constructor's return value.
293@discussion If you named your function CallAsConstructor, you would declare it like this:
294
295JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
296
297If your callback were invoked by the JavaScript expression 'new myConstructor()', constructor would be set to myConstructor.
298
299If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
300*/
302(*JSObjectCallAsConstructorCallback) (JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
303
304/* Extension of the above callback with the class that the method is being invoked for. */
306(*JSObjectCallAsConstructorCallbackEx) (JSContextRef ctx, JSClassRef jsClass, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
307
308/*!
309@typedef JSObjectHasInstanceCallback
310@abstract hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
311@param ctx The execution context to use.
312@param constructor The JSObject that is the target of the 'instanceof' expression.
313@param possibleInstance The JSValue being tested to determine if it is an instance of constructor.
314@param exception A pointer to a JSValueRef in which to return an exception, if any.
315@result true if possibleInstance is an instance of constructor, otherwise false.
316@discussion If you named your function HasInstance, you would declare it like this:
317
318bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
319
320If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue.
321
322If this callback is NULL, 'instanceof' expressions that target your object will return false.
323
324Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
325*/
326typedef bool
327(*JSObjectHasInstanceCallback) (JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
328
329/* Extension of the above callback with the class that the method is being invoked for. */
330typedef bool
331(*JSObjectHasInstanceCallbackEx) (JSContextRef ctx, JSClassRef jsClass, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
332
333/*!
334@typedef JSObjectConvertToTypeCallback
335@abstract The callback invoked when converting an object to a particular JavaScript type.
336@param ctx The execution context to use.
337@param object The JSObject to convert.
338@param type A JSType specifying the JavaScript type to convert to.
339@param exception A pointer to a JSValueRef in which to return an exception, if any.
340@result The objects's converted value, or NULL if the object was not converted.
341@discussion If you named your function ConvertToType, you would declare it like this:
342
343JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
344
345If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
346
347This 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.
348*/
351
352/* Extension of the above callback with the class that the method is being invoked for. */
354(*JSObjectConvertToTypeCallbackEx) (JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSType type, JSValueRef* exception);
355
356/*!
357@struct JSStaticValue
358@abstract This structure describes a statically declared value property.
359@field name A null-terminated UTF8 string containing the property's name.
360@field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
361@field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. May be NULL if the ReadOnly attribute is set.
362@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
363*/
370
371/* Extended static value structure for version 1000 classes */
378
379/*!
380@struct JSStaticFunction
381@abstract This structure describes a statically declared function property.
382@field name A null-terminated UTF8 string containing the property's name.
383@field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
384@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
385*/
391
392/* Extended static function structure for version 1000 classes */
398
399/*!
400@struct JSClassDefinition
401@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.
402@field version The version number of this structure. Use 0 for standard callbacks or 1000 for extended callbacks.
403@field attributes A logically ORed set of JSClassAttributes to give to the class.
404@field className A null-terminated UTF8 string containing the class's name.
405@field parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
406@field staticValues (Version 0) 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.
407@field staticFunctions (Version 0) 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.
408@field staticValuesEx (Version 1000) A JSStaticValueEx array for extended static values that receive JSClassRef in callbacks.
409@field staticFunctionsEx (Version 1000) A JSStaticFunctionEx array for extended static functions that receive JSClassRef in callbacks.
410@field initialize/initializeEx The callback invoked when an object is first created. Use version 0 'initialize' or version 1000 'initializeEx'.
411@field finalize/finalizeEx The callback invoked when an object is finalized (prepared for garbage collection). Use version 0 'finalize' or version 1000 'finalizeEx'.
412@field hasProperty/hasPropertyEx The callback invoked when determining whether an object has a property. If this field is NULL, getProperty is called instead. Use version 0 'hasProperty' or version 1000 'hasPropertyEx'.
413@field getProperty/getPropertyEx The callback invoked when getting a property's value. Use version 0 'getProperty' or version 1000 'getPropertyEx'.
414@field setProperty/setPropertyEx The callback invoked when setting a property's value. Use version 0 'setProperty' or version 1000 'setPropertyEx'.
415@field deleteProperty/deletePropertyEx The callback invoked when deleting a property. Use version 0 'deleteProperty' or version 1000 'deletePropertyEx'.
416@field getPropertyNames/getPropertyNamesEx The callback invoked when collecting the names of an object's properties. Use version 0 'getPropertyNames' or version 1000 'getPropertyNamesEx'.
417@field callAsFunction/callAsFunctionEx The callback invoked when an object is called as a function. Use version 0 'callAsFunction' or version 1000 'callAsFunctionEx'.
418@field hasInstance/hasInstanceEx The callback invoked when an object is used as the target of an 'instanceof' expression. Use version 0 'hasInstance' or version 1000 'hasInstanceEx'.
419@field callAsConstructor/callAsConstructorEx The callback invoked when an object is used as a constructor in a 'new' expression. Use version 0 'callAsConstructor' or version 1000 'callAsConstructorEx'.
420@field convertToType/convertToTypeEx The callback invoked when converting an object to a particular JavaScript type. Use version 0 'convertToType' or version 1000 'convertToTypeEx'.
421@field privateData Private data storage for the JSClass itself (version 1000 only). This allows you to associate arbitrary data with the class definition.
422
423@discussion Version System and Callback Types:
424
425The JSClassDefinition structure supports two versions of callbacks through a union with anonymous structs:
426
427Version 0 (Standard Callbacks):
428- Original JSC API callbacks that receive standard parameters
429- Callbacks do not receive the JSClassRef, limiting context awareness
430- Use this version for simple cases or backward compatibility
431- Access callbacks directly: definition.initialize, definition.getProperty, etc.
432- Example callback: void Initialize(JSContextRef ctx, JSObjectRef object)
433
434Version 1000 (Extended Callbacks):
435- Enhanced callbacks that receive JSClassRef as an additional first parameter after JSContextRef
436- Enables callbacks to know which class they belong to, useful for:
437 * Implementing class hierarchies with shared callback implementations
438 * Storing per-class data via the privateData field
439 * Creating more object-oriented bindings
440- Access callbacks with 'Ex' suffix: definition.initializeEx, definition.getPropertyEx, etc.
441- Example callback: void InitializeEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object)
442- The privateData field is ONLY available for version 1000 classes
443
444The union structure allows both callback sets to share the same memory space, with anonymous structs
445enabling direct field access based on version (e.g., definition.initialize for v0 or definition.initializeEx for v1000).
446
447Example Usage:
448
449Version 0 (Standard):
450JSClassDefinition definition = kJSClassDefinitionEmpty;
451definition.version = 0; // or omit since 0 is default
452definition.className = "MyClass";
453definition.initialize = MyInitialize; // Direct access
454definition.finalize = MyFinalize;
455
456Version 1000 (Extended):
457JSClassDefinition definition = kJSClassDefinitionEmpty;
458definition.version = 1000;
459definition.className = "MyClass";
460definition.initializeEx = MyInitializeEx; // Direct access with Ex suffix
461definition.finalizeEx = MyFinalizeEx;
462definition.privateData = myClassData; // Store class-specific data
463
464JSClassRef jsClass = JSClassCreate(&definition);
465// Later retrieve private data in callbacks:
466void* data = JSClassGetPrivate(jsClass);
467
468@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.
469
470If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:
471
472JSStaticValue StaticValueArray[] = {
473 { "X", GetX, SetX, kJSPropertyAttributeNone },
474 { 0, 0, 0, 0 }
475};
476
477Standard 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.
478
479A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
480
481It is not possible to use JS subclassing with objects created from a class definition that sets callAsConstructor by default. Subclassing is supported via the JSObjectMakeConstructor function, however.
482*/
483typedef struct {
484 int version; /* version is 0 for standard callbacks or 1000 for extended callbacks */
486
487 const char* className;
489
525
526 void* privateData; /* Private data for version 1000 classes */
528
529/*!
530@const kJSClassDefinitionEmpty
531@abstract A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.
532@discussion Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:
533
534JSClassDefinition definition = kJSClassDefinitionEmpty;
535definition.finalize = Finalize;
536*/
538
539/*!
540@function
541@abstract Creates a JavaScript class suitable for use with JSObjectMake.
542@param definition A JSClassDefinition that defines the class.
543@result A JSClass with the given definition. Ownership follows the Create Rule.
544*/
546
547/*!
548@function
549@abstract Retains a JavaScript class.
550@param jsClass The JSClass to retain.
551@result A JSClass that is the same as jsClass.
552*/
554
555/*!
556@function
557@abstract Releases a JavaScript class.
558@param jsClass The JSClass to release.
559*/
561
562/*!
563@function
564@abstract Creates a JavaScript object.
565@param ctx The execution context to use.
566@param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
567@param data A void* to set as the object's private data. Pass NULL to specify no private data.
568@result A JSObject with the given class and private data.
569@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.
570
571data 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.
572*/
574
575/*!
576@function
577@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
578@param ctx The execution context to use.
579@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.
580@param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.
581@result A JSObject that is a function. The object's prototype will be the default function prototype.
582*/
584
585/*!
586@function
587@abstract Convenience method for creating a JavaScript constructor.
588@param ctx The execution context to use.
589@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.
590@param callAsConstructor A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.
591@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
592@discussion The default object constructor takes no arguments and constructs an object of class jsClass with no private data. If the constructor is inherited via JS subclassing and the value returned from callAsConstructor was created with jsClass, then the returned object will have it's prototype overridden to the derived class's prototype.
593*/
595
596/*!
597 @function
598 @abstract Creates a JavaScript Array object.
599 @param ctx The execution context to use.
600 @param argumentCount An integer count of the number of arguments in arguments.
601 @param arguments A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0.
602 @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.
603 @result A JSObject that is an Array.
604 @discussion The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument
605 is supplied, this function returns an array with one element.
606 */
607JS_EXPORT JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) JSC_API_AVAILABLE(macos(10.6), ios(7.0));
608
609/*!
610 @function
611 @abstract Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
612 @param ctx The execution context to use.
613 @param argumentCount An integer count of the number of arguments in arguments.
614 @param arguments A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0.
615 @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.
616 @result A JSObject that is a Date.
617 */
618JS_EXPORT JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) JSC_API_AVAILABLE(macos(10.6), ios(7.0));
619
620/*!
621 @function
622 @abstract Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
623 @param ctx The execution context to use.
624 @param argumentCount An integer count of the number of arguments in arguments.
625 @param arguments A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0.
626 @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.
627 @result A JSObject that is an Error.
628 */
629JS_EXPORT JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) JSC_API_AVAILABLE(macos(10.6), ios(7.0));
630
631/*!
632 @function
633 @abstract Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
634 @param ctx The execution context to use.
635 @param argumentCount An integer count of the number of arguments in arguments.
636 @param arguments A JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0.
637 @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.
638 @result A JSObject that is a RegExp.
639 */
640JS_EXPORT JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) JSC_API_AVAILABLE(macos(10.6), ios(7.0));
641
642/*!
643 @function
644 @abstract Creates a JavaScript promise object by invoking the provided executor.
645 @param ctx The execution context to use.
646 @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.
647 @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.
648 @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.
649 @result A JSObject that is a promise or NULL if an exception occurred.
650 */
652
653/*!
654@function
655@abstract Creates a function with a given script as its body.
656@param ctx The execution context to use.
657@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.
658@param parameterCount An integer count of the number of parameter names in parameterNames.
659@param parameterNames A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
660@param body A JSString containing the script to use as the function's body.
661@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.
662@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.
663@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.
664@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.
665@discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
666*/
667JS_EXPORT JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
668
669/*!
670@function
671@abstract Gets an object's prototype.
672@param ctx The execution context to use.
673@param object A JSObject whose prototype you want to get.
674@result A JSValue that is the object's prototype.
675*/
677
678/*!
679@function
680@abstract Sets an object's prototype.
681@param ctx The execution context to use.
682@param object The JSObject whose prototype you want to set.
683@param value A JSValue to set as the object's prototype.
684*/
686
687/*!
688@function
689@abstract Tests whether an object has a given property.
690@param object The JSObject to test.
691@param propertyName A JSString containing the property's name.
692@result true if the object has a property whose name matches propertyName, otherwise false.
693*/
695
696/*!
697@function
698@abstract Gets a property from an object.
699@param ctx The execution context to use.
700@param object The JSObject whose property you want to get.
701@param propertyName A JSString containing the property's name.
702@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.
703@result The property's value if object has the property, otherwise the undefined value.
704*/
706
707/*!
708@function
709@abstract Sets a property on an object.
710@param ctx The execution context to use.
711@param object The JSObject whose property you want to set.
712@param propertyName A JSString containing the property's name.
713@param value A JSValueRef to use as the property's value.
714@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
715@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.
716*/
717JS_EXPORT void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception);
718
719/*!
720@function
721@abstract Deletes a property from an object.
722@param ctx The execution context to use.
723@param object The JSObject whose property you want to delete.
724@param propertyName A JSString containing the property's name.
725@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.
726@result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
727*/
729
730/*!
731 @function
732 @abstract Tests whether an object has a given property using a JSValueRef as the property key.
733 @param object The JSObject to test.
734 @param propertyKey A JSValueRef containing the property key to use when looking up the property.
735 @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.
736 @result true if the object has a property whose name matches propertyKey, otherwise false.
737 @discussion This function is the same as performing "propertyKey in object" from JavaScript.
738 */
739JS_EXPORT bool JSObjectHasPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macos(10.15), ios(13.0));
740
741/*!
742 @function
743 @abstract Gets a property from an object using a JSValueRef as the property key.
744 @param ctx The execution context to use.
745 @param object The JSObject whose property you want to get.
746 @param propertyKey A JSValueRef containing the property key to use when looking up the property.
747 @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.
748 @result The property's value if object has the property key, otherwise the undefined value.
749 @discussion This function is the same as performing "object[propertyKey]" from JavaScript.
750 */
752
753/*!
754 @function
755 @abstract Sets a property on an object using a JSValueRef as the property key.
756 @param ctx The execution context to use.
757 @param object The JSObject whose property you want to set.
758 @param propertyKey A JSValueRef containing the property key to use when looking up the property.
759 @param value A JSValueRef to use as the property's value.
760 @param attributes A logically ORed set of JSPropertyAttributes to give to the property.
761 @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.
762 @discussion This function is the same as performing "object[propertyKey] = value" from JavaScript.
763 */
764JS_EXPORT void JSObjectSetPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception) JSC_API_AVAILABLE(macos(10.15), ios(13.0));
765
766/*!
767 @function
768 @abstract Deletes a property from an object using a JSValueRef as the property key.
769 @param ctx The execution context to use.
770 @param object The JSObject whose property you want to delete.
771 @param propertyKey A JSValueRef containing the property key to use when looking up the property.
772 @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.
773 @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
774 @discussion This function is the same as performing "delete object[propertyKey]" from JavaScript.
775 */
776JS_EXPORT bool JSObjectDeletePropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef* exception) JSC_API_AVAILABLE(macos(10.15), ios(13.0));
777
778/*!
779@function
780@abstract Gets a property from an object by numeric index.
781@param ctx The execution context to use.
782@param object The JSObject whose property you want to get.
783@param propertyIndex An integer value that is the property's name.
784@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.
785@result The property's value if object has the property, otherwise the undefined value.
786@discussion Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.
787*/
788JS_EXPORT JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception);
789
790/*!
791@function
792@abstract Sets a property on an object by numeric index.
793@param ctx The execution context to use.
794@param object The JSObject whose property you want to set.
795@param propertyIndex The property's name as a number.
796@param value A JSValue to use as the property's value.
797@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.
798@discussion Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.
799*/
800JS_EXPORT void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception);
801
802/*!
803@function
804@abstract Gets an object's private data.
805@param object A JSObject whose private data you want to get.
806@result A void* that is the object's private data, if the object has private data, otherwise NULL.
807*/
809
810/*!
811@function
812@abstract Sets a pointer to private data on an object.
813@param object The JSObject whose private data you want to set.
814@param data A void* to set as the object's private data.
815@result true if object can store private data, otherwise false.
816@discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
817*/
818JS_EXPORT bool JSObjectSetPrivate(JSObjectRef object, void* data);
819
820/*!
821@function
822@abstract Tests whether an object can be called as a function.
823@param ctx The execution context to use.
824@param object The JSObject to test.
825@result true if the object can be called as a function, otherwise false.
826*/
828
829/*!
830@function
831@abstract Calls an object as a function.
832@param ctx The execution context to use.
833@param object The JSObject to call as a function.
834@param thisObject The object to use as "this," or NULL to use the global object as "this."
835@param argumentCount An integer count of the number of arguments in arguments.
836@param arguments A JSValue array of arguments to pass to the function. Pass NULL if argumentCount is 0.
837@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.
838@result The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
839*/
840JS_EXPORT JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
841
842/*!
843@function
844@abstract Tests whether an object can be called as a constructor.
845@param ctx The execution context to use.
846@param object The JSObject to test.
847@result true if the object can be called as a constructor, otherwise false.
848*/
850
851/*!
852@function
853@abstract Calls an object as a constructor.
854@param ctx The execution context to use.
855@param object The JSObject to call as a constructor.
856@param argumentCount An integer count of the number of arguments in arguments.
857@param arguments A JSValue array of arguments to pass to the constructor. Pass NULL if argumentCount is 0.
858@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.
859@result The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
860*/
861JS_EXPORT JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
862
863/*!
864@function
865@abstract Gets the names of an object's enumerable properties.
866@param ctx The execution context to use.
867@param object The object whose property names you want to get.
868@result A JSPropertyNameArray containing the names object's enumerable properties. Ownership follows the Create Rule.
869*/
871
872/*!
873@function
874@abstract Retains a JavaScript property name array.
875@param array The JSPropertyNameArray to retain.
876@result A JSPropertyNameArray that is the same as array.
877*/
879
880/*!
881@function
882@abstract Releases a JavaScript property name array.
883@param array The JSPropetyNameArray to release.
884*/
886
887/*!
888@function
889@abstract Gets a count of the number of items in a JavaScript property name array.
890@param array The array from which to retrieve the count.
891@result An integer count of the number of names in array.
892*/
894
895/*!
896@function
897@abstract Gets a property name at a given index in a JavaScript property name array.
898@param array The array from which to retrieve the property name.
899@param index The index of the property name to retrieve.
900@result A JSStringRef containing the property name.
901*/
903
904/*!
905@function
906@abstract Adds a property name to a JavaScript property name accumulator.
907@param accumulator The accumulator object to which to add the property name.
908@param propertyName The property name to add.
909*/
911
912/*!
913@function
914@abstract Gets the private data from a JSClass (version 1000 only).
915@param jsClass The JSClass whose private data you want to get.
916@result The private data for the class, or NULL if the class is not version 1000.
917*/
919
920/*!
921@function
922@abstract Sets the private data for a JSClass (version 1000 only).
923@param jsClass The JSClass whose private data you want to set.
924@param data The private data to set.
925@result true if the private data was set (class is version 1000), false otherwise.
926*/
927JS_EXPORT bool JSClassSetPrivate(JSClassRef jsClass, void* data);
928
929/*!
930@function
931@abstract Creates a JavaScript function with a callback, a user data pointer, and an optional finalizer.
932@param ctx The execution context to use.
933@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.
934@param callAsFunction The JSObjectCallAsFunctionDataCallback to invoke when the function is called. The userData pointer is passed to every invocation.
935@param userData A pointer to user data associated with the function. May be NULL.
936@param finalize A JSFunctionDataFinalizeCallback invoked exactly once when the function is garbage collected or its context group is destroyed. Pass NULL if no cleanup is needed.
937@result A JSObject that is a function. The object's prototype will be the default function prototype.
938@discussion Unlike objects faked as callable through a JSClass, the returned object is a real
939 function: it inherits from Function.prototype, so bind, call, and apply work on it from script.
940*/
942
943/*!
944@function
945@abstract Gets multiple properties of an object in one call, using UTF-8 property names.
946@param ctx The execution context to use.
947@param object The JSObject whose properties you want to get.
948@param names An array of count null-terminated UTF-8 property names.
949@param count The number of properties to get.
950@param outValues An array of count JSValueRefs that receives the property values. A property that does not exist yields the undefined value.
951@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.
952@result true if all properties were read; false if an exception was thrown, in which case the contents of outValues are unspecified.
953*/
954JS_EXPORT bool JSObjectGetPropertiesUTF8(JSContextRef ctx, JSObjectRef object, const char* const* names, size_t count, JSValueRef* outValues, JSValueRef* exception);
955
956/*!
957@function
958@abstract Sets multiple properties of an object in one call, using UTF-8 property names.
959@param ctx The execution context to use.
960@param object The JSObject whose properties you want to set.
961@param names An array of count null-terminated UTF-8 property names.
962@param values An array of count JSValueRefs that are the property values to set.
963@param count The number of properties to set.
964@param attributes A logically ORed set of JSPropertyAttributes to give to each property.
965@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.
966@result true if all properties were set; false if an exception was thrown. Properties before the failing one remain set.
967*/
968JS_EXPORT bool JSObjectSetPropertiesUTF8(JSContextRef ctx, JSObjectRef object, const char* const* names, const JSValueRef* values, size_t count, unsigned attributes, JSValueRef* exception);
969
970/*!
971@function
972@abstract Creates a JavaScript object initialized with a set of properties, using UTF-8 property names.
973@param ctx The execution context to use.
974@param names An array of count null-terminated UTF-8 property names.
975@param values An array of count JSValueRefs that are the property values.
976@param count The number of properties.
977@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.
978@result A JSObject with the given properties, or NULL if an exception was thrown.
979*/
980JS_EXPORT JSObjectRef JSObjectMakeWithPropertiesUTF8(JSContextRef ctx, const char* const* names, const JSValueRef* values, size_t count, JSValueRef* exception);
981
982/*!
983@function
984@abstract Gets an object's own enumerable string-keyed properties (names and values) in one call.
985@param ctx The execution context to use.
986@param object The JSObject whose entries you want to get.
987@param start The enumeration-order position to start reading entries from (0 reads from the beginning). Positions at or beyond the property count read nothing.
988@param outNames An array that receives up to capacity JSStringRefs, one per property name. May be NULL if capacity is 0. Each returned string is owned by the caller, who is responsible for releasing it with JSStringRelease.
989@param outValues An array that receives up to capacity property values. May be NULL if capacity is 0.
990@param capacity The number of entries the out arrays can hold.
991@param outCount On success, receives the total number of own enumerable string-keyed properties, which may exceed start + capacity. Pass a capacity of 0 to query the count without reading entries.
992@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.
993@result true on success; false if an exception was thrown, in which case the contents of the out arrays are unspecified.
994@discussion Entries are returned in the standard property enumeration order, matching Object.entries. Values are read with the object's ordinary get behavior, so getters run. The property set is re-enumerated per call, so a caller reading a large object in windows should expect skipped or repeated entries if a getter mutates the object between calls.
995*/
996JS_EXPORT bool JSObjectGetOwnEntriesUTF8(JSContextRef ctx, JSObjectRef object, size_t start, JSStringRef* outNames, JSValueRef* outValues, size_t capacity, size_t* outCount, JSValueRef* exception);
997
998/*!
999@function
1000@abstract Defines an accessor (getter/setter) property on an object, using a UTF-8 property name.
1001@param ctx The execution context to use.
1002@param object The JSObject on which to define the accessor.
1003@param name A null-terminated UTF-8 string containing the property name.
1004@param getter A JSObject that is a function to invoke on property reads. May be NULL to define a write-only accessor.
1005@param setter A JSObject that is a function to invoke on property writes. May be NULL to define a read-only accessor.
1006@param attributes A logically ORed set of JSPropertyAttributes to give to the property. kJSPropertyAttributeReadOnly is ignored for accessors.
1007@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.
1008@result true if the accessor was defined; false if an exception was thrown (for example, redefining a non-configurable property, or passing a non-callable getter or setter).
1009@discussion At least one of getter and setter must be non-NULL.
1010*/
1011JS_EXPORT bool JSObjectDefineAccessorUTF8(JSContextRef ctx, JSObjectRef object, const char* name, JSObjectRef getter, JSObjectRef setter, unsigned attributes, JSValueRef* exception);
1012
1013/*!
1014@function
1015@abstract Defines an own data property on an object with the given attributes, equivalent to Object.defineProperty.
1016@param ctx The execution context to use.
1017@param object The JSObject on which to define the property.
1018@param name A null-terminated UTF-8 string containing the property name.
1019@param value A JSValueRef that is the property value. Pass NULL for the undefined value.
1020@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
1021@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.
1022@result true if the property was defined; false if the object refused it (for example, redefining a non-configurable property or adding a property to a frozen object).
1023@discussion Unlike JSObjectSetProperty, this never falls back to ordinary assignment when a
1024 same-named property exists on the prototype chain: the attributes always apply, and setters
1025 never run.
1026*/
1027JS_EXPORT bool JSObjectDefinePropertyUTF8(JSContextRef ctx, JSObjectRef object, const char* name, JSValueRef value, unsigned attributes, JSValueRef* exception);
1028
1029/*!
1030@function
1031@abstract Freezes an object, equivalent to Object.freeze.
1032@param ctx The execution context to use.
1033@param object The JSObject to freeze.
1034@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.
1035@result true if the object was frozen; false if an exception was thrown (for example, a Proxy that refuses to prevent extensions).
1036*/
1038
1039/*!
1040@function
1041@abstract Creates a JavaScript error object of a given type.
1042@param ctx The execution context to use.
1043@param type The JSTypedErrorType of error to create, for example kJSTypedError_TypeError.
1044@param message A JSString containing the error message. May be NULL to create an error with no message.
1045@result A JSObject that is an error object of the given type, or NULL if creation failed.
1046*/
1048
1049/*!
1050@enum JSPromiseStatus
1051@abstract The possible states of a JavaScript Promise.
1052@constant kJSPromiseStatus_Pending The promise has not been settled yet.
1053@constant kJSPromiseStatus_Fulfilled The promise has been resolved with a value.
1054@constant kJSPromiseStatus_Rejected The promise has been rejected with a reason.
1055*/
1061
1062/*!
1063@function
1064@abstract Gets the state of a JavaScript Promise without scheduling any reaction.
1065@param ctx The execution context to use.
1066@param promise The JSObject to inspect.
1067@param outStatus On success, receives the promise's JSPromiseStatus.
1068@result true if promise is a Promise and outStatus was written; false if promise is not a Promise.
1069*/
1071
1072/*!
1073@function
1074@abstract Gets the settled result of a JavaScript Promise: its value if fulfilled, or its rejection reason if rejected.
1075@param ctx The execution context to use.
1076@param promise The JSObject to inspect.
1077@result The promise's result, or NULL if promise is not a Promise. A pending promise yields the undefined value, which is indistinguishable from a promise fulfilled with undefined: consult JSPromiseGetStatus first.
1078*/
1080
1081/*!
1082@function
1083@abstract Marks a JavaScript Promise as handled for unhandled-rejection reporting.
1084@param ctx The execution context to use.
1085@param promise The JSObject to mark.
1086@result true if promise is a Promise and was marked; false if promise is not a Promise.
1087@discussion Use this when native code observes a promise's rejection through the inspection
1088 functions above instead of attaching a JavaScript reaction, so the page does not report an
1089 unhandled promise rejection for a rejection that native code in fact handles. Like attaching
1090 a catch handler, marking only suppresses reports made after it happens.
1091*/
1093
1094/*!
1095@function
1096@abstract Reports the amount of non-JavaScript memory kept alive by an object, to guide garbage collection.
1097@param ctx The execution context to use.
1098@param object The JSObject the memory is attributed to.
1099@param bytes The number of bytes of external memory the object keeps alive. Replaces any previously set hint. Pass 0 to clear the hint.
1100@result true if the hint was stored; false if the object cannot carry a hint, in which case nothing was reported.
1101@discussion Use this when a small JavaScript wrapper pins a large native allocation, so that the
1102 collector can account for the true memory cost of the wrapper. The hint is attributed to the
1103 object for as long as it is alive and is dropped automatically when the object is collected.
1104 Only objects created with a non-NULL JSClass (for example via JSObjectMake) can carry a hint.
1105 The hint influences collection scheduling; it is not an exact accounting ledger.
1106*/
1108
1109#ifdef __cplusplus
1110}
1111#endif
1112
1113#endif /* JSObjectRef_h */
struct OpaqueJSClass * JSClassRef
Definition JSBase.h:52
struct OpaqueJSString * JSStringRef
Definition JSBase.h:49
struct OpaqueJSValue * JSObjectRef
Definition JSBase.h:69
const struct OpaqueJSValue * JSValueRef
Definition JSBase.h:66
struct OpaqueJSPropertyNameArray * JSPropertyNameArrayRef
Definition JSBase.h:55
struct OpaqueJSPropertyNameAccumulator * JSPropertyNameAccumulatorRef
Definition JSBase.h:58
#define JS_EXPORT
Definition JSBase.h:93
const struct OpaqueJSContext * JSContextRef
Definition JSBase.h:43
JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array)
Retains a JavaScript property name array.
bool(*) JSObjectDeletePropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
The callback invoked when deleting a property.
Definition JSObjectRef.h:204
JSValueRef JSPromiseGetResult(JSContextRef ctx, JSObjectRef promise)
Gets the settled result of a JavaScript Promise: its value if fulfilled, or its rejection reason if r...
JSObjectRef(*) JSObjectCallAsConstructorCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Definition JSObjectRef.h:306
const JSClassDefinition kJSClassDefinitionEmpty
A JSClassDefinition structure of the current version, filled with NULL pointers and having no attribu...
JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
Gets a property from an object.
JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor)
Convenience method for creating a JavaScript constructor.
bool JSClassSetPrivate(JSClassRef jsClass, void *data)
Sets the private data for a JSClass (version 1000 only).
JSValueRef JSObjectGetPrototype(JSContextRef ctx, JSObjectRef object)
Gets an object's prototype.
JSValueRef(*) JSObjectConvertToTypeCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSType type, JSValueRef *exception)
Definition JSObjectRef.h:354
void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array)
Releases a JavaScript property name array.
JSValueRef(*) JSObjectGetPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
The callback invoked when getting a property's value.
Definition JSObjectRef.h:161
void * JSClassGetPrivate(JSClassRef jsClass)
Gets the private data from a JSClass (version 1000 only).
void(*) JSObjectFinalizeCallback(JSObjectRef object)
The callback invoked when an object is finalized (prepared for garbage collection)....
Definition JSObjectRef.h:116
void(*) JSObjectInitializeCallback(JSContextRef ctx, JSObjectRef object)
The callback invoked when an object is first created.
Definition JSObjectRef.h:94
JSValueRef JSObjectGetPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
Gets a property from an object using a JSValueRef as the property key.
bool JSObjectDefinePropertyUTF8(JSContextRef ctx, JSObjectRef object, const char *name, JSValueRef value, unsigned attributes, JSValueRef *exception)
Defines an own data property on an object with the given attributes, equivalent to Object....
JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Calls an object as a function.
JSObjectRef(*) JSObjectCallAsConstructorCallback(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
The callback invoked when an object is used as a constructor in a 'new' expression.
Definition JSObjectRef.h:302
JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) JSC_API_AVAILABLE(macos(10.6)
Creates a JavaScript Array object.
void * JSObjectGetPrivate(JSObjectRef object)
Gets an object's private data.
bool JSObjectDeletePropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
Deletes a property from an object using a JSValueRef as the property key.
JSPromiseStatus
The possible states of a JavaScript Promise.
Definition JSObjectRef.h:1056
@ kJSPromiseStatus_Rejected
Definition JSObjectRef.h:1059
@ kJSPromiseStatus_Fulfilled
Definition JSObjectRef.h:1058
@ kJSPromiseStatus_Pending
Definition JSObjectRef.h:1057
void(*) JSObjectGetPropertyNamesCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
Definition JSObjectRef.h:229
bool(*) JSObjectHasInstanceCallback(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef *exception)
hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
Definition JSObjectRef.h:327
JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef *exception)
Creates a function with a given script as its body.
JSValueRef(*) JSObjectGetPropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
Definition JSObjectRef.h:165
bool(*) JSObjectHasPropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName)
Definition JSObjectRef.h:144
bool(*) JSObjectHasInstanceCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef *exception)
Definition JSObjectRef.h:331
void(*) JSFunctionDataFinalizeCallback(void *userData)
The callback invoked when a function created with JSObjectMakeFunctionWithData is garbage collected.
Definition JSObjectRef.h:282
void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef *exception)
Sets a property on an object.
bool JSPromiseGetStatus(JSContextRef ctx, JSObjectRef promise, JSPromiseStatus *outStatus)
Gets the state of a JavaScript Promise without scheduling any reaction.
bool JSObjectSetExternalMemoryHint(JSContextRef ctx, JSObjectRef object, size_t bytes)
Reports the amount of non-JavaScript memory kept alive by an object, to guide garbage collection.
bool(*) JSObjectHasPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
The callback invoked when determining whether an object has a property.
Definition JSObjectRef.h:140
void JSObjectSetPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef value, JSPropertyAttributes attributes, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
Sets a property on an object using a JSValueRef as the property key.
bool JSPromiseMarkAsHandled(JSContextRef ctx, JSObjectRef promise)
Marks a JavaScript Promise as handled for unhandled-rejection reporting.
size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array)
Gets a count of the number of items in a JavaScript property name array.
void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef *exception)
Sets a property on an object by numeric index.
unsigned JSPropertyAttributes
A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
Definition JSObjectRef.h:63
JSValueRef(*) JSObjectCallAsFunctionDataCallback(JSContextRef ctx, void *userData, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
The callback invoked when a function created with JSObjectMakeFunctionWithData is called.
Definition JSObjectRef.h:269
bool JSObjectGetPropertiesUTF8(JSContextRef ctx, JSObjectRef object, const char *const *names, size_t count, JSValueRef *outValues, JSValueRef *exception)
Gets multiple properties of an object in one call, using UTF-8 property names.
bool JSObjectHasPropertyForKey(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
Tests whether an object has a given property using a JSValueRef as the property key.
JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) JSC_API_AVAILABLE(macos(10.6)
Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
JSClassRef JSClassCreate(const JSClassDefinition *definition)
Creates a JavaScript class suitable for use with JSObjectMake.
JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void *data)
Creates a JavaScript object.
bool(*) JSObjectDeletePropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
Definition JSObjectRef.h:208
bool JSObjectIsConstructor(JSContextRef ctx, JSObjectRef object)
Tests whether an object can be called as a constructor.
void(*) JSObjectFinalizeCallbackEx(JSClassRef jsClass, JSObjectRef object)
Definition JSObjectRef.h:120
void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName)
Adds a property name to a JavaScript property name accumulator.
JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index)
Gets a property name at a given index in a JavaScript property name array.
void JSClassRelease(JSClassRef jsClass)
Releases a JavaScript class.
JSValueRef(*) JSObjectCallAsFunctionCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
The callback invoked when an object is called as a function.
Definition JSObjectRef.h:250
JSValueRef(*) JSObjectCallAsFunctionCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSStringRef className, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Definition JSObjectRef.h:254
bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
Deletes a property from an object.
@ kJSClassAttributeNone
Definition JSObjectRef.h:71
@ kJSClassAttributeNoAutomaticPrototype
Definition JSObjectRef.h:72
void JSObjectSetPrototype(JSContextRef ctx, JSObjectRef object, JSValueRef value)
Sets an object's prototype.
bool JSObjectGetOwnEntriesUTF8(JSContextRef ctx, JSObjectRef object, size_t start, JSStringRef *outNames, JSValueRef *outValues, size_t capacity, size_t *outCount, JSValueRef *exception)
Gets an object's own enumerable string-keyed properties (names and values) in one call.
bool JSObjectDefineAccessorUTF8(JSContextRef ctx, JSObjectRef object, const char *name, JSObjectRef getter, JSObjectRef setter, unsigned attributes, JSValueRef *exception)
Defines an accessor (getter/setter) property on an object, using a UTF-8 property name.
JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
Calls an object as a constructor.
bool JSObjectIsFunction(JSContextRef ctx, JSObjectRef object)
Tests whether an object can be called as a function.
JSObjectRef JSObjectMakeWithPropertiesUTF8(JSContextRef ctx, const char *const *names, const JSValueRef *values, size_t count, JSValueRef *exception)
Creates a JavaScript object initialized with a set of properties, using UTF-8 property names.
JSObjectRef JSObjectMakeFunctionWithData(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionDataCallback callAsFunction, void *userData, JSFunctionDataFinalizeCallback finalize)
Creates a JavaScript function with a callback, a user data pointer, and an optional finalizer.
JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object)
Gets the names of an object's enumerable properties.
void(*) JSObjectGetPropertyNamesCallback(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
The callback invoked when collecting the names of an object's properties.
Definition JSObjectRef.h:225
JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef *exception)
Gets a property from an object by numeric index.
unsigned JSClassAttributes
A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
Definition JSObjectRef.h:79
JSObjectRef JSObjectMakeDeferredPromise(JSContextRef ctx, JSObjectRef *resolve, JSObjectRef *reject, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
Creates a JavaScript promise object by invoking the provided executor.
void(*) JSObjectInitializeCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object)
Definition JSObjectRef.h:98
bool JSObjectSetPrivate(JSObjectRef object, void *data)
Sets a pointer to private data on an object.
JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) JSC_API_AVAILABLE(macos(10.6)
Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
@ kJSPropertyAttributeReadOnly
Definition JSObjectRef.h:54
@ kJSPropertyAttributeNone
Definition JSObjectRef.h:53
@ kJSPropertyAttributeDontDelete
Definition JSObjectRef.h:56
@ kJSPropertyAttributeDontEnum
Definition JSObjectRef.h:55
bool JSObjectSetPropertiesUTF8(JSContextRef ctx, JSObjectRef object, const char *const *names, const JSValueRef *values, size_t count, unsigned attributes, JSValueRef *exception)
Sets multiple properties of an object in one call, using UTF-8 property names.
bool(*) JSObjectSetPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
The callback invoked when setting a property's value.
Definition JSObjectRef.h:183
JSValueRef(*) JSObjectConvertToTypeCallback(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef *exception)
The callback invoked when converting an object to a particular JavaScript type.
Definition JSObjectRef.h:350
JSClassRef JSClassRetain(JSClassRef jsClass)
Retains a JavaScript class.
bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
Tests whether an object has a given property.
bool JSObjectFreeze(JSContextRef ctx, JSObjectRef object, JSValueRef *exception)
Freezes an object, equivalent to Object.freeze.
JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) JSC_API_AVAILABLE(macos(10.6)
Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction)
Convenience method for creating a JavaScript function with a given callback as its implementation.
JSObjectRef JSObjectMakeTypedError(JSContextRef ctx, JSTypedErrorType type, JSStringRef message)
Creates a JavaScript error object of a given type.
bool(*) JSObjectSetPropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
Definition JSObjectRef.h:187
enum JSTypedArrayType ios
JSType
A constant identifying the type of a JSValue.
Definition JSValueRef.h:48
JSTypedErrorType
A constant identifying the type of a JavaScript error object.
Definition JSValueRef.h:392
#define JSC_API_AVAILABLE(...)
Definition WebKitAvailability.h:46
This structure contains properties and callbacks that define a type of object. All fields other than ...
Definition JSObjectRef.h:483
JSClassAttributes attributes
Definition JSObjectRef.h:485
const char * className
Definition JSObjectRef.h:487
int version
Definition JSObjectRef.h:484
void * privateData
Definition JSObjectRef.h:526
JSClassRef parentClass
Definition JSObjectRef.h:488
Definition JSObjectRef.h:393
const char * name
Definition JSObjectRef.h:394
JSPropertyAttributes attributes
Definition JSObjectRef.h:396
JSObjectCallAsFunctionCallbackEx callAsFunctionEx
Definition JSObjectRef.h:395
This structure describes a statically declared function property.
Definition JSObjectRef.h:386
const char * name
Definition JSObjectRef.h:387
JSObjectCallAsFunctionCallback callAsFunction
Definition JSObjectRef.h:388
JSPropertyAttributes attributes
Definition JSObjectRef.h:389
Definition JSObjectRef.h:372
JSObjectGetPropertyCallbackEx getPropertyEx
Definition JSObjectRef.h:374
JSObjectSetPropertyCallbackEx setPropertyEx
Definition JSObjectRef.h:375
const char * name
Definition JSObjectRef.h:373
JSPropertyAttributes attributes
Definition JSObjectRef.h:376
This structure describes a statically declared value property.
Definition JSObjectRef.h:364
JSObjectGetPropertyCallback getProperty
Definition JSObjectRef.h:366
const char * name
Definition JSObjectRef.h:365
JSObjectSetPropertyCallback setProperty
Definition JSObjectRef.h:367
JSPropertyAttributes attributes
Definition JSObjectRef.h:368