Ultralight C API 1.3.0
Loading...
Searching...
No Matches
JSClassDefinition Struct Reference

#include <JavaScriptCore/JSObjectRef.h>

Details

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.

  • version The version number of this structure. The current version is 0.
  • attributes A logically ORed set of JSClassAttributes to give to the class.
  • className A null-terminated UTF8 string containing the class's name.
  • parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
  • 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.
  • 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.
  • initialize The callback invoked when an object is first created. Use this callback to initialize the object.
  • 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.
  • 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.
  • getProperty The callback invoked when getting a property's value.
  • setProperty The callback invoked when setting a property's value.
  • deleteProperty The callback invoked when deleting a property.
  • getPropertyNames The callback invoked when collecting the names of an object's properties.
  • callAsFunction The callback invoked when an object is called as a function.
  • hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
  • callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.
  • convertToType The callback invoked when converting an object to a particular JavaScript type.
    Note

    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.

    If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:

    JSStaticValue StaticValueArray[] = { { "X", GetX, SetX, kJSPropertyAttributeNone }, { 0, 0, 0, 0 } };

    Standard JavaScript practice calls for storing function objects in prototypes, so they can be shared. The default JSClass created by JSClassCreate follows this idiom, instantiating objects with a shared, automatically generating prototype containing the class's function objects. The kJSClassAttributeNoAutomaticPrototype attribute specifies that a JSClass should not automatically generate such a prototype. The resulting JSClass instantiates objects with the default object prototype, and gives each instance object its own copy of the class's function objects.

    A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.

Data Fields

int version
 
JSClassAttributes attributes
 
const char * className
 
JSClassRef parentClass
 
union { 
 
   struct { 
 
      const JSStaticValue *   staticValues 
 
      const JSStaticFunction *   staticFunctions 
 
      JSObjectInitializeCallback   initialize 
 
      JSObjectFinalizeCallback   finalize 
 
      JSObjectHasPropertyCallback   hasProperty 
 
      JSObjectGetPropertyCallback   getProperty 
 
      JSObjectSetPropertyCallback   setProperty 
 
      JSObjectDeletePropertyCallback   deleteProperty 
 
      JSObjectGetPropertyNamesCallback   getPropertyNames 
 
      JSObjectCallAsFunctionCallback   callAsFunction 
 
      JSObjectCallAsConstructorCallback   callAsConstructor 
 
      JSObjectHasInstanceCallback   hasInstance 
 
      JSObjectConvertToTypeCallback   convertToType 
 
   }  
 
   struct { 
 
      const JSStaticValueEx *   staticValuesEx 
 
      const JSStaticFunctionEx *   staticFunctionsEx 
 
      JSObjectInitializeCallbackEx   initializeEx 
 
      JSObjectFinalizeCallbackEx   finalizeEx 
 
      JSObjectHasPropertyCallbackEx   hasPropertyEx 
 
      JSObjectGetPropertyCallbackEx   getPropertyEx 
 
      JSObjectSetPropertyCallbackEx   setPropertyEx 
 
      JSObjectDeletePropertyCallbackEx   deletePropertyEx 
 
      JSObjectGetPropertyNamesCallbackEx   getPropertyNamesEx 
 
      JSObjectCallAsFunctionCallbackEx   callAsFunctionEx 
 
      JSObjectCallAsConstructorCallbackEx   callAsConstructorEx 
 
      JSObjectHasInstanceCallbackEx   hasInstanceEx 
 
      JSObjectConvertToTypeCallbackEx   convertToTypeEx 
 
   }  
 
};  
 
void * privateData
 

Field Documentation

◆ [union]

union { ... } JSClassDefinition

◆ attributes

JSClassAttributes JSClassDefinition::attributes

◆ callAsConstructor

JSObjectCallAsConstructorCallback JSClassDefinition::callAsConstructor

◆ callAsConstructorEx

JSObjectCallAsConstructorCallbackEx JSClassDefinition::callAsConstructorEx

◆ callAsFunction

JSObjectCallAsFunctionCallback JSClassDefinition::callAsFunction

◆ callAsFunctionEx

JSObjectCallAsFunctionCallbackEx JSClassDefinition::callAsFunctionEx

◆ className

const char* JSClassDefinition::className

◆ convertToType

JSObjectConvertToTypeCallback JSClassDefinition::convertToType

◆ convertToTypeEx

JSObjectConvertToTypeCallbackEx JSClassDefinition::convertToTypeEx

◆ deleteProperty

JSObjectDeletePropertyCallback JSClassDefinition::deleteProperty

◆ deletePropertyEx

JSObjectDeletePropertyCallbackEx JSClassDefinition::deletePropertyEx

◆ finalize

JSObjectFinalizeCallback JSClassDefinition::finalize

◆ finalizeEx

JSObjectFinalizeCallbackEx JSClassDefinition::finalizeEx

◆ getProperty

JSObjectGetPropertyCallback JSClassDefinition::getProperty

◆ getPropertyEx

JSObjectGetPropertyCallbackEx JSClassDefinition::getPropertyEx

◆ getPropertyNames

JSObjectGetPropertyNamesCallback JSClassDefinition::getPropertyNames

◆ getPropertyNamesEx

JSObjectGetPropertyNamesCallbackEx JSClassDefinition::getPropertyNamesEx

◆ hasInstance

JSObjectHasInstanceCallback JSClassDefinition::hasInstance

◆ hasInstanceEx

JSObjectHasInstanceCallbackEx JSClassDefinition::hasInstanceEx

◆ hasProperty

JSObjectHasPropertyCallback JSClassDefinition::hasProperty

◆ hasPropertyEx

JSObjectHasPropertyCallbackEx JSClassDefinition::hasPropertyEx

◆ initialize

JSObjectInitializeCallback JSClassDefinition::initialize

◆ initializeEx

JSObjectInitializeCallbackEx JSClassDefinition::initializeEx

◆ parentClass

JSClassRef JSClassDefinition::parentClass

◆ privateData

void* JSClassDefinition::privateData

◆ setProperty

JSObjectSetPropertyCallback JSClassDefinition::setProperty

◆ setPropertyEx

JSObjectSetPropertyCallbackEx JSClassDefinition::setPropertyEx

◆ staticFunctions

const JSStaticFunction* JSClassDefinition::staticFunctions

◆ staticFunctionsEx

const JSStaticFunctionEx* JSClassDefinition::staticFunctionsEx

◆ staticValues

const JSStaticValue* JSClassDefinition::staticValues

◆ staticValuesEx

const JSStaticValueEx* JSClassDefinition::staticValuesEx

◆ version

int JSClassDefinition::version

The documentation for this struct was generated from the following file: