@@ -91,6 +91,10 @@ derived class (the parent class) first, and the most derived class last.
9191typedef void
9292(* JSObjectInitializeCallback ) (JSContextRef ctx , JSObjectRef object );
9393
94+ /* Extension of the above callback with the class that the method is being invoked for. */
95+ typedef void
96+ (* JSObjectInitializeCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSObjectRef object );
97+
9498/*!
9599@typedef JSObjectFinalizeCallback
96100@abstract The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
@@ -109,6 +113,10 @@ all functions that have a JSContextRef parameter.
109113typedef void
110114(* JSObjectFinalizeCallback ) (JSObjectRef object );
111115
116+ /* Extension of the above callback with the class that the method is being invoked for. */
117+ typedef void
118+ (* JSObjectFinalizeCallbackEx ) (JSClassRef jsClass , JSObjectRef object );
119+
112120/*!
113121@typedef JSObjectHasPropertyCallback
114122@abstract The callback invoked when determining whether an object has a property.
@@ -129,6 +137,10 @@ If this callback is NULL, the getProperty callback will be used to service hasPr
129137typedef bool
130138(* JSObjectHasPropertyCallback ) (JSContextRef ctx , JSObjectRef object , JSStringRef propertyName );
131139
140+ /* Extension of the above callback with the class that the method is being invoked for. */
141+ typedef bool
142+ (* JSObjectHasPropertyCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSObjectRef object , JSStringRef propertyName );
143+
132144/*!
133145@typedef JSObjectGetPropertyCallback
134146@abstract The callback invoked when getting a property's value.
@@ -146,6 +158,10 @@ If this function returns NULL, the get request forwards to object's statically d
146158typedef JSValueRef
147159(* JSObjectGetPropertyCallback ) (JSContextRef ctx , JSObjectRef object , JSStringRef propertyName , JSValueRef * exception );
148160
161+ /* Extension of the above callback with the class that the method is being invoked for. */
162+ typedef JSValueRef
163+ (* JSObjectGetPropertyCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSObjectRef object , JSStringRef propertyName , JSValueRef * exception );
164+
149165/*!
150166@typedef JSObjectSetPropertyCallback
151167@abstract The callback invoked when setting a property's value.
@@ -164,6 +180,10 @@ If this function returns false, the set request forwards to object's statically
164180typedef bool
165181(* JSObjectSetPropertyCallback ) (JSContextRef ctx , JSObjectRef object , JSStringRef propertyName , JSValueRef value , JSValueRef * exception );
166182
183+ /* Extension of the above callback with the class that the method is being invoked for. */
184+ typedef bool
185+ (* JSObjectSetPropertyCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSObjectRef object , JSStringRef propertyName , JSValueRef value , JSValueRef * exception );
186+
167187/*!
168188@typedef JSObjectDeletePropertyCallback
169189@abstract The callback invoked when deleting a property.
@@ -181,6 +201,10 @@ If this function returns false, the delete request forwards to object's statical
181201typedef bool
182202(* JSObjectDeletePropertyCallback ) (JSContextRef ctx , JSObjectRef object , JSStringRef propertyName , JSValueRef * exception );
183203
204+ /* Extension of the above callback with the class that the method is being invoked for. */
205+ typedef bool
206+ (* JSObjectDeletePropertyCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSObjectRef object , JSStringRef propertyName , JSValueRef * exception );
207+
184208/*!
185209@typedef JSObjectGetPropertyNamesCallback
186210@abstract The callback invoked when collecting the names of an object's properties.
@@ -198,6 +222,10 @@ Use JSPropertyNameAccumulatorAddName to add property names to accumulator. A cla
198222typedef void
199223(* JSObjectGetPropertyNamesCallback ) (JSContextRef ctx , JSObjectRef object , JSPropertyNameAccumulatorRef propertyNames );
200224
225+ /* Extension of the above callback with the class that the method is being invoked for. */
226+ typedef void
227+ (* JSObjectGetPropertyNamesCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSObjectRef object , JSPropertyNameAccumulatorRef propertyNames );
228+
201229/*!
202230@typedef JSObjectCallAsFunctionCallback
203231@abstract The callback invoked when an object is called as a function.
@@ -219,6 +247,12 @@ If this callback is NULL, calling your object as a function will throw an except
219247typedef JSValueRef
220248(* JSObjectCallAsFunctionCallback ) (JSContextRef ctx , JSObjectRef function , JSObjectRef thisObject , size_t argumentCount , const JSValueRef arguments [], JSValueRef * exception );
221249
250+ /* Extension of the above callback with the class and class name of the object being called as a function.
251+ @discussion If this is a JSStaticFunctionEx, className will actually be the name of the function.
252+ */
253+ typedef JSValueRef
254+ (* JSObjectCallAsFunctionCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSStringRef className , JSObjectRef function , JSObjectRef thisObject , size_t argumentCount , const JSValueRef arguments [], JSValueRef * exception );
255+
222256/*!
223257@typedef JSObjectCallAsConstructorCallback
224258@abstract The callback invoked when an object is used as a constructor in a 'new' expression.
@@ -239,6 +273,10 @@ If this callback is NULL, using your object as a constructor in a 'new' expressi
239273typedef JSObjectRef
240274(* JSObjectCallAsConstructorCallback ) (JSContextRef ctx , JSObjectRef constructor , size_t argumentCount , const JSValueRef arguments [], JSValueRef * exception );
241275
276+ /* Extension of the above callback with the class that the method is being invoked for. */
277+ typedef JSObjectRef
278+ (* JSObjectCallAsConstructorCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSObjectRef constructor , size_t argumentCount , const JSValueRef arguments [], JSValueRef * exception );
279+
242280/*!
243281@typedef JSObjectHasInstanceCallback
244282@abstract hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
@@ -260,6 +298,10 @@ Standard JavaScript practice calls for objects that implement the callAsConstruc
260298typedef bool
261299(* JSObjectHasInstanceCallback ) (JSContextRef ctx , JSObjectRef constructor , JSValueRef possibleInstance , JSValueRef * exception );
262300
301+ /* Extension of the above callback with the class that the method is being invoked for. */
302+ typedef bool
303+ (* JSObjectHasInstanceCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSObjectRef constructor , JSValueRef possibleInstance , JSValueRef * exception );
304+
263305/*!
264306@typedef JSObjectConvertToTypeCallback
265307@abstract The callback invoked when converting an object to a particular JavaScript type.
@@ -279,6 +321,10 @@ This function is only invoked when converting an object to number or string. An
279321typedef JSValueRef
280322(* JSObjectConvertToTypeCallback ) (JSContextRef ctx , JSObjectRef object , JSType type , JSValueRef * exception );
281323
324+ /* Extension of the above callback with the class that the method is being invoked for. */
325+ typedef JSValueRef
326+ (* JSObjectConvertToTypeCallbackEx ) (JSContextRef ctx , JSClassRef jsClass , JSObjectRef object , JSType type , JSValueRef * exception );
327+
282328/*!
283329@struct JSStaticValue
284330@abstract This structure describes a statically declared value property.
@@ -294,6 +340,14 @@ typedef struct {
294340 JSPropertyAttributes attributes ;
295341} JSStaticValue ;
296342
343+ /* Extension of the above structure for use with class version 1000 */
344+ typedef struct {
345+ const char * name ;
346+ JSObjectGetPropertyCallbackEx getPropertyEx ;
347+ JSObjectSetPropertyCallbackEx setPropertyEx ;
348+ JSPropertyAttributes attributes ;
349+ } JSStaticValueEx ;
350+
297351/*!
298352@struct JSStaticFunction
299353@abstract This structure describes a statically declared function property.
@@ -307,6 +361,13 @@ typedef struct {
307361 JSPropertyAttributes attributes ;
308362} JSStaticFunction ;
309363
364+ /* Extension of the above structure for use with class version 1000 */
365+ typedef struct {
366+ const char * name ;
367+ JSObjectCallAsFunctionCallbackEx callAsFunctionEx ;
368+ JSPropertyAttributes attributes ;
369+ } JSStaticFunctionEx ;
370+
310371/*!
311372@struct JSClassDefinition
312373@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.
@@ -341,26 +402,49 @@ Standard JavaScript practice calls for storing function objects in prototypes, s
341402A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
342403*/
343404typedef struct {
344- int version ; /* current (and only) version is 0 */
405+ int version ; /* default version is 0, use version 1000 for callbacks with extended class information */
345406 JSClassAttributes attributes ;
346407
347408 const char * className ;
348409 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 ;
410+
411+ union {
412+ /* version 0 */
413+ struct {
414+ const JSStaticValue * staticValues ;
415+ const JSStaticFunction * staticFunctions ;
416+ JSObjectInitializeCallback initialize ;
417+ JSObjectFinalizeCallback finalize ;
418+ JSObjectHasPropertyCallback hasProperty ;
419+ JSObjectGetPropertyCallback getProperty ;
420+ JSObjectSetPropertyCallback setProperty ;
421+ JSObjectDeletePropertyCallback deleteProperty ;
422+ JSObjectGetPropertyNamesCallback getPropertyNames ;
423+ JSObjectCallAsFunctionCallback callAsFunction ;
424+ JSObjectCallAsConstructorCallback callAsConstructor ;
425+ JSObjectHasInstanceCallback hasInstance ;
426+ JSObjectConvertToTypeCallback convertToType ;
427+ };
428+
429+ /* version 1000 */
430+ struct {
431+ const JSStaticValueEx * staticValuesEx ;
432+ const JSStaticFunctionEx * staticFunctionsEx ;
433+ JSObjectInitializeCallbackEx initializeEx ;
434+ JSObjectFinalizeCallbackEx finalizeEx ;
435+ JSObjectHasPropertyCallbackEx hasPropertyEx ;
436+ JSObjectGetPropertyCallbackEx getPropertyEx ;
437+ JSObjectSetPropertyCallbackEx setPropertyEx ;
438+ JSObjectDeletePropertyCallbackEx deletePropertyEx ;
439+ JSObjectGetPropertyNamesCallbackEx getPropertyNamesEx ;
440+ JSObjectCallAsFunctionCallbackEx callAsFunctionEx ;
441+ JSObjectCallAsConstructorCallbackEx callAsConstructorEx ;
442+ JSObjectHasInstanceCallbackEx hasInstanceEx ;
443+ JSObjectConvertToTypeCallbackEx convertToTypeEx ;
444+ };
445+ };
446+
447+ void * privateData ; /* version 1000 only */
364448} JSClassDefinition ;
365449
366450/*!
@@ -396,6 +480,25 @@ JS_EXPORT JSClassRef JSClassRetain(JSClassRef jsClass);
396480*/
397481JS_EXPORT void JSClassRelease (JSClassRef jsClass );
398482
483+ /*!
484+ @function
485+ @abstract Retrieves the private data from a class reference, only possible with classes created with version 1000 (extended callbacks).
486+ @param jsClass The class to get the data from
487+ @result The private data on the class, or NULL, if not set
488+ @discussion Only classes with version 1000 (extended callbacks) can store private data, for other classes always NULL will always be returned.
489+ */
490+ JS_EXPORT void * JSClassGetPrivate (JSClassRef jsClass );
491+
492+ /*!
493+ @function
494+ @abstract Sets the private data on a class, only possible with classes created with version 1000 (extended callbacks).
495+ @param jsClass The class to set the data on
496+ @param data A void* to set as the private data for the class
497+ @result true if the data has been set on the class, false if the class has not been created with version 1000 (extended callbacks)
498+ @discussion Only classes with version 1000 (extended callbacks) can store private data, for other classes the function always fails. The set pointer is not touched by the engine.
499+ */
500+ JS_EXPORT bool JSClassSetPrivate (JSClassRef jsClass , void * data );
501+
399502/*!
400503@function
401504@abstract Creates a JavaScript object.
0 commit comments