Struct JSClassDefinition

Source
#[repr(C)]
pub struct JSClassDefinition {
Show 17 fields pub version: c_int, pub attributes: JSClassAttributes, pub className: *const c_char, pub parentClass: JSClassRef, pub staticValues: *const JSStaticValue, pub staticFunctions: *const JSStaticFunction, pub initialize: JSObjectInitializeCallback, pub finalize: JSObjectFinalizeCallback, pub hasProperty: JSObjectHasPropertyCallback, pub getProperty: JSObjectGetPropertyCallback, pub setProperty: JSObjectSetPropertyCallback, pub deleteProperty: JSObjectDeletePropertyCallback, pub getPropertyNames: JSObjectGetPropertyNamesCallback, pub callAsFunction: JSObjectCallAsFunctionCallback, pub callAsConstructor: JSObjectCallAsConstructorCallback, pub hasInstance: JSObjectHasInstanceCallback, pub convertToType: JSObjectConvertToTypeCallback,
}
Available on crate features JSBase and JSObjectRef and JSValueRef only.
Expand description

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. Field: version The version number of this structure. The current version is 0. Field: attributes A logically ORed set of JSClassAttributes to give to the class. Field: className A null-terminated UTF8 string containing the class’s name. Field: parentClass A JSClass to set as the class’s parent class. Pass NULL use the default object class. Field: staticValues A JSStaticValue array containing the class’s statically declared value properties. Pass NULL to specify no statically declared value properties. The array must be terminated by a JSStaticValue whose name field is NULL. Field: staticFunctions A JSStaticFunction array containing the class’s statically declared function properties. Pass NULL to specify no statically declared function properties. The array must be terminated by a JSStaticFunction whose name field is NULL. Field: initialize The callback invoked when an object is first created. Use this callback to initialize the object. Field: finalize The callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for the object, and perform other cleanup. Field: hasProperty The callback invoked when determining whether an object has a property. If this field is NULL, getProperty is called instead. The hasProperty callback enables optimization in cases where only a property’s existence needs to be known, not its value, and computing its value is expensive. Field: getProperty The callback invoked when getting a property’s value. Field: setProperty The callback invoked when setting a property’s value. Field: deleteProperty The callback invoked when deleting a property. Field: getPropertyNames The callback invoked when collecting the names of an object’s properties. Field: callAsFunction The callback invoked when an object is called as a function. Field: hasInstance The callback invoked when an object is used as the target of an ‘instanceof’ expression. Field: callAsConstructor The callback invoked when an object is used as a constructor in a ‘new’ expression. Field: convertToType The callback invoked when converting an object to a particular JavaScript type.

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.

It 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.

See also Apple’s documentation

Fields§

§version: c_int§attributes: JSClassAttributes§className: *const c_char§parentClass: JSClassRef§staticValues: *const JSStaticValue§staticFunctions: *const JSStaticFunction§initialize: JSObjectInitializeCallback§finalize: JSObjectFinalizeCallback§hasProperty: JSObjectHasPropertyCallback§getProperty: JSObjectGetPropertyCallback§setProperty: JSObjectSetPropertyCallback§deleteProperty: JSObjectDeletePropertyCallback§getPropertyNames: JSObjectGetPropertyNamesCallback§callAsFunction: JSObjectCallAsFunctionCallback§callAsConstructor: JSObjectCallAsConstructorCallback§hasInstance: JSObjectHasInstanceCallback§convertToType: JSObjectConvertToTypeCallback

Trait Implementations§

Source§

impl Clone for JSClassDefinition

Source§

fn clone(&self) -> JSClassDefinition

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JSClassDefinition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Encode for JSClassDefinition

Available on crate feature objc2 only.
Source§

const ENCODING: Encoding

The Objective-C type-encoding for this type.
Source§

impl PartialEq for JSClassDefinition

Source§

fn eq(&self, other: &JSClassDefinition) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RefEncode for JSClassDefinition

Available on crate feature objc2 only.
Source§

const ENCODING_REF: Encoding

The Objective-C type-encoding for a reference of this type. Read more
Source§

impl Copy for JSClassDefinition

Source§

impl StructuralPartialEq for JSClassDefinition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> EncodeArgument for T
where T: Encode,

Source§

const ENCODING_ARGUMENT: Encoding = T::ENCODING

The Objective-C type-encoding for this type.
Source§

impl<T> EncodeReturn for T
where T: Encode,

Source§

const ENCODING_RETURN: Encoding = T::ENCODING

The Objective-C type-encoding for this type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,