Struct JSValue

Source
#[repr(C)]
pub struct JSValue { /* private fields */ }
Available on crate features JSValue and objc2 only.
Expand description

A JSValue is a reference to a JavaScript value. Every JSValue originates from a JSContext and holds a strong reference to it. When a JSValue instance method creates a new JSValue, the new value originates from the same JSContext.

All JSValues values also originate from a JSVirtualMachine (available indirectly via the context property). It is an error to pass a JSValue to a method or property of a JSValue or JSContext originating from a different JSVirtualMachine. Doing so will raise an Objective-C exception.

See also Apple’s documentation

Implementations§

Source§

impl JSValue

Source

pub unsafe fn context(&self) -> Option<Retained<JSContext>>

Available on crate feature JSContext only.

The JSContext that this value originates from.

Source

pub unsafe fn valueWithObject_inContext( value: Option<&AnyObject>, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a JSValue by converting an Objective-C object.

The resulting JSValue retains the provided Objective-C object.

Parameter value: The Objective-C object to be converted.

Returns: The new JSValue.

Source

pub unsafe fn valueWithBool_inContext( value: bool, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a JavaScript value from a BOOL primitive.

Parameter context: The JSContext in which the resulting JSValue will be created.

Returns: The new JSValue representing the equivalent boolean value.

Source

pub unsafe fn valueWithDouble_inContext( value: c_double, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a JavaScript value from a double primitive.

Parameter context: The JSContext in which the resulting JSValue will be created.

Returns: The new JSValue representing the equivalent boolean value.

Source

pub unsafe fn valueWithInt32_inContext( value: i32, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a JavaScript value from an int32_t primitive.

Parameter context: The JSContext in which the resulting JSValue will be created.

Returns: The new JSValue representing the equivalent boolean value.

Source

pub unsafe fn valueWithUInt32_inContext( value: u32, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a JavaScript value from a uint32_t primitive.

Parameter context: The JSContext in which the resulting JSValue will be created.

Returns: The new JSValue representing the equivalent boolean value.

Source

pub unsafe fn valueWithNewObjectInContext( context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a new, empty JavaScript object.

Parameter context: The JSContext in which the resulting object will be created.

Returns: The new JavaScript object.

Source

pub unsafe fn valueWithNewArrayInContext( context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a new, empty JavaScript array.

Parameter context: The JSContext in which the resulting array will be created.

Returns: The new JavaScript array.

Source

pub unsafe fn valueWithNewRegularExpressionFromPattern_flags_inContext( pattern: Option<&NSString>, flags: Option<&NSString>, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate features JSContext and objc2-foundation only.

Create a new JavaScript regular expression object.

Parameter pattern: The regular expression pattern.

Parameter flags: The regular expression flags.

Parameter context: The JSContext in which the resulting regular expression object will be created.

Returns: The new JavaScript regular expression object.

Source

pub unsafe fn valueWithNewErrorFromMessage_inContext( message: Option<&NSString>, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate features JSContext and objc2-foundation only.

Create a new JavaScript error object.

Parameter message: The error message.

Parameter context: The JSContext in which the resulting error object will be created.

Returns: The new JavaScript error object.

Source

pub unsafe fn valueWithNewPromiseInContext_fromExecutor( context: Option<&JSContext>, callback: Option<&DynBlock<dyn Fn(*mut JSValue, *mut JSValue)>>, ) -> Option<Retained<JSValue>>

Available on crate features JSContext and block2 only.

Create a new promise object using the provided executor callback.

Parameter callback: A callback block invoked while the promise object is being initialized. The resolve and reject parameters are functions that can be called to notify any pending reactions about the state of the new promise object.

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing a new promise JavaScript object.

This method is equivalent to calling the Promise constructor in JavaScript. the resolve and reject callbacks each normally take a single value, which they forward to all relevent pending reactions. While inside the executor callback context will act as if it were in any other callback, except calleeFunction will be nil . This also means means the new promise object may be accessed via [context thisValue] .

Source

pub unsafe fn valueWithNewPromiseResolvedWithResult_inContext( result: Option<&AnyObject>, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a new resolved promise object with the provided value.

Parameter result: The result value to be passed to any reactions.

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing a new promise JavaScript object.

This method is equivalent to calling [JSValue valueWithNewPromiseFromExecutor:^(JSValue *resolve, JSValue *reject) { [resolve callWithArguments: @ [result]]; } inContext:context]

Source

pub unsafe fn valueWithNewPromiseRejectedWithReason_inContext( reason: Option<&AnyObject>, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a new rejected promise object with the provided value.

Parameter reason: The result value to be passed to any reactions.

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing a new promise JavaScript object.

This method is equivalent to calling [JSValue valueWithNewPromiseFromExecutor:^(JSValue *resolve, JSValue *reject) { [reject callWithArguments: @ [reason]]; } inContext:context]

Source

pub unsafe fn valueWithNewSymbolFromDescription_inContext( description: Option<&NSString>, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate features JSContext and objc2-foundation only.

Create a new, unique, symbol object.

Parameter description: The description of the symbol object being created.

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing a unique JavaScript value with type symbol.

Source

pub unsafe fn valueWithNewBigIntFromString_inContext( string: &NSString, context: &JSContext, ) -> Option<Retained<JSValue>>

Available on crate features JSContext and objc2-foundation only.

Create a new BigInt value from a numeric string.

Parameter string: The string representation of the BigInt JavaScript value being created.

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing a JavaScript value with type BigInt.

This is equivalent to calling the BigInt constructor from JavaScript with a string argument.

Source

pub unsafe fn valueWithNewBigIntFromInt64_inContext( int64: i64, context: &JSContext, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a new BigInt value from a int64_t .

Parameter int64: The signed 64-bit integer of the BigInt JavaScript value being created.

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing a JavaScript value with type BigInt.

Source

pub unsafe fn valueWithNewBigIntFromUInt64_inContext( uint64: u64, context: &JSContext, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a new BigInt value from a uint64_t .

Parameter uint64: The unsigned 64-bit integer of the BigInt JavaScript value being created.

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing a JavaScript value with type BigInt.

Source

pub unsafe fn valueWithNewBigIntFromDouble_inContext( value: c_double, context: &JSContext, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create a new BigInt value from a double.

Parameter value: The value of the BigInt JavaScript value being created.

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing a JavaScript value with type BigInt.

If the value is not an integer, an exception is thrown.

Source

pub unsafe fn valueWithNullInContext( context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create the JavaScript value null .

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing the JavaScript value null .

Source

pub unsafe fn valueWithUndefinedInContext( context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate feature JSContext only.

Create the JavaScript value undefined .

Parameter context: The JSContext to which the resulting JSValue belongs.

Returns: The JSValue representing the JavaScript value undefined .

Source

pub unsafe fn toObject(&self) -> Option<Retained<AnyObject>>

When converting between JavaScript values and Objective-C objects a copy is performed. Values of types listed below are copied to the corresponding types on conversion in each direction. For NSDictionaries, entries in the dictionary that are keyed by strings are copied onto a JavaScript object. For dictionaries and arrays, conversion is recursive, with the same object conversion being applied to all entries in the collection.


```text
   Objective-C type  |   JavaScript type
 --------------------+---------------------
         nil         |     undefined
        NSNull       |        null
       NSString      |       string
       NSNumber      |   number, boolean
     NSDictionary    |   Object object
       NSArray       |    Array object
        NSDate       |     Date object
       NSBlock (1)   |   Function object (1)
          id (2)     |   Wrapper object (2)
        Class (3)    | Constructor object (3)
```

(1) Instances of NSBlock with supported arguments types will be presented to JavaScript as a callable Function object. For more information on supported argument types see JSExport.h. If a JavaScript Function originating from an Objective-C block is converted back to an Objective-C object the block will be returned. All other JavaScript functions will be converted in the same manner as a JavaScript object of type Object.

(2) For Objective-C instances that do not derive from the set of types listed above, a wrapper object to provide a retaining handle to the Objective-C instance from JavaScript. For more information on these wrapper objects, see JSExport.h. When a JavaScript wrapper object is converted back to Objective-C the Objective-C instance being retained by the wrapper is returned.

(3) For Objective-C Class objects a constructor object containing exported class methods will be returned. See JSExport.h for more information on constructor objects.

For all methods taking arguments of type id, arguments will be converted into a JavaScript value according to the above conversion.

Convert this JSValue to an Objective-C object.

The JSValue is converted to an Objective-C object according to the conversion rules specified above.

Returns: The Objective-C representation of this JSValue.

Source

pub unsafe fn toObjectOfClass( &self, expected_class: Option<&AnyClass>, ) -> Option<Retained<AnyObject>>

Convert a JSValue to an Objective-C object of a specific class.

The JSValue is converted to an Objective-C object of the specified Class. If the result is not of the specified Class then nil will be returned.

Returns: An Objective-C object of the specified Class or nil .

Source

pub unsafe fn toBool(&self) -> bool

Convert a JSValue to a boolean.

The JSValue is converted to a boolean according to the rules specified by the JavaScript language.

Returns: The boolean result of the conversion.

Source

pub unsafe fn toDouble(&self) -> c_double

Convert a JSValue to a double.

Returns: The double result of the conversion.

Convert the JSValue to a number according to the rules specified by the JavaScript language. Unless the JSValue is a BigInt then this is equivalent to Number(value) in JavaScript.

Source

pub unsafe fn toInt32(&self) -> i32

Convert a JSValue to an int32_t .

The JSValue is converted to an integer according to the rules specified by the JavaScript language. If the JSValue is a BigInt, then the value is truncated to an int32_t .

Returns: The int32_t result of the conversion.

Source

pub unsafe fn toUInt32(&self) -> u32

Convert a JSValue to a uint32_t .

The JSValue is converted to an integer according to the rules specified by the JavaScript language. If the JSValue is a BigInt, then the value is truncated to a uint32_t .

Returns: The uint32_t result of the conversion.

Source

pub unsafe fn toInt64(&self) -> i64

Convert a JSValue to a int64_t .

The JSValue is converted to an integer according to the rules specified by the JavaScript language. If the value is a BigInt, then the value is truncated to an int64_t .

Source

pub unsafe fn toUInt64(&self) -> u64

Convert a JSValue to a uint64_t .

The JSValue is converted to an integer according to the rules specified by the JavaScript language. If the value is a BigInt, then the value is truncated to a uint64_t .

Source

pub unsafe fn toNumber(&self) -> Option<Retained<NSNumber>>

Available on crate feature objc2-foundation only.

Convert a JSValue to a NSNumber.

If the JSValue represents a boolean, a NSNumber value of YES or NO will be returned. For all other types, the result is equivalent to Number(value) in JavaScript.

Returns: The NSNumber result of the conversion.

Source

pub unsafe fn toString(&self) -> Option<Retained<NSString>>

Available on crate feature objc2-foundation only.

Convert a JSValue to a NSString.

The JSValue is converted to a string according to the rules specified by the JavaScript language.

Returns: The NSString containing the result of the conversion.

Source

pub unsafe fn toDate(&self) -> Option<Retained<NSDate>>

Available on crate feature objc2-foundation only.

Convert a JSValue to a NSDate.

The value is converted to a number representing a time interval since 1970 which is then used to create a new NSDate instance.

Returns: The NSDate created using the converted time interval.

Source

pub unsafe fn toArray(&self) -> Option<Retained<NSArray>>

Available on crate feature objc2-foundation only.

Convert a JSValue to a NSArray.

If the value is null or undefined then nil is returned. If the value is not an object then a JavaScript TypeError will be thrown. The property length is read from the object, converted to an unsigned integer, and an NSArray of this size is allocated. Properties corresponding to indices within the array bounds will be copied to the array, with JSValues converted to equivalent Objective-C objects as specified.

Returns: The NSArray containing the recursively converted contents of the converted JavaScript array.

Source

pub unsafe fn toDictionary(&self) -> Option<Retained<NSDictionary>>

Available on crate feature objc2-foundation only.

Convert a JSValue to a NSDictionary.

If the value is null or undefined then nil is returned. If the value is not an object then a JavaScript TypeError will be thrown. All enumerable properties of the object are copied to the dictionary, with JSValues converted to equivalent Objective-C objects as specified.

Returns: The NSDictionary containing the recursively converted contents of the converted JavaScript object.

Source

pub unsafe fn isUndefined(&self) -> bool

Check if a JSValue corresponds to the JavaScript value undefined .

Source

pub unsafe fn isNull(&self) -> bool

Check if a JSValue corresponds to the JavaScript value null .

Source

pub unsafe fn isBoolean(&self) -> bool

Check if a JSValue is a boolean.

Source

pub unsafe fn isNumber(&self) -> bool

Check if a JSValue is a number.

In JavaScript, there is no differentiation between types of numbers. Semantically all numbers behave like doubles except in special cases like bit operations.

Source

pub unsafe fn isString(&self) -> bool

Check if a JSValue is a string.

Source

pub unsafe fn isObject(&self) -> bool

Check if a JSValue is an object.

Source

pub unsafe fn isArray(&self) -> bool

Check if a JSValue is an array.

Source

pub unsafe fn isDate(&self) -> bool

Check if a JSValue is a date.

Source

pub unsafe fn isSymbol(&self) -> bool

Check if a JSValue is a symbol.

Source

pub unsafe fn isBigInt(&self) -> bool

Check if a JSValue is a BigInt.

Source

pub unsafe fn isInstanceOf(&self, value: Option<&AnyObject>) -> bool

Check if a JSValue is an instance of another object.

This method has the same function as the JavaScript operator instanceof . If an object other than a JSValue is passed, it will first be converted according to the aforementioned rules.

Source

pub unsafe fn isEqualToObject(&self, value: Option<&AnyObject>) -> bool

§Compare two JSValues using JavaScript’s
operator.
Source

pub unsafe fn isEqualWithTypeCoercionToObject( &self, value: Option<&AnyObject>, ) -> bool

§Compare two JSValues using JavaScript’s
operator.
Source

pub unsafe fn compareJSValue(&self, other: &JSValue) -> JSRelationCondition

Available on crate feature JSValueRef only.

Compare two JSValues. The JSValue to compare with.

Returns: A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.

§The result is computed by comparing the results of JavaScript’s
, < , and > operators. If either self or other is (or would coerce to) NaN in JavaScript, then the result is kJSRelationConditionUndefined.
Source

pub unsafe fn compareInt64(&self, other: i64) -> JSRelationCondition

Available on crate feature JSValueRef only.

Compare a JSValue with a int64_t . The int64_t to compare with.

Returns: A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.

The JSValue is converted to an integer according to the rules specified by the JavaScript language then compared with other .

Source

pub unsafe fn compareUInt64(&self, other: u64) -> JSRelationCondition

Available on crate feature JSValueRef only.

Compare a JSValue with a uint64_t . The uint64_t to compare with.

Returns: A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.

The JSValue is converted to an integer according to the rules specified by the JavaScript language then compared with other .

Source

pub unsafe fn compareDouble(&self, other: c_double) -> JSRelationCondition

Available on crate feature JSValueRef only.

Compare a JSValue with a double. The double to compare with.

Returns: A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.

The JSValue is converted to a double according to the rules specified by the JavaScript language then compared with other .

Source

pub unsafe fn callWithArguments( &self, arguments: Option<&NSArray>, ) -> Option<Retained<JSValue>>

Available on crate feature objc2-foundation only.

Invoke a JSValue as a function.

In JavaScript, if a function doesn’t explicitly return a value then it implicitly returns the JavaScript value undefined .

Parameter arguments: The arguments to pass to the function.

Returns: The return value of the function call.

Source

pub unsafe fn constructWithArguments( &self, arguments: Option<&NSArray>, ) -> Option<Retained<JSValue>>

Available on crate feature objc2-foundation only.

Invoke a JSValue as a constructor.

This is equivalent to using the new syntax in JavaScript.

Parameter arguments: The arguments to pass to the constructor.

Returns: The return value of the constructor call.

Source

pub unsafe fn invokeMethod_withArguments( &self, method: Option<&NSString>, arguments: Option<&NSArray>, ) -> Option<Retained<JSValue>>

Available on crate feature objc2-foundation only.

Invoke a method on a JSValue.

Accesses the property named method from this value and calls the resulting value as a function, passing this JSValue as the this value along with the specified arguments.

Parameter method: The name of the method to be invoked.

Parameter arguments: The arguments to pass to the method.

Returns: The return value of the method call.

Source§

impl JSValue

Methods declared on superclass NSObject.

Source

pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>

Source

pub unsafe fn new() -> Retained<Self>

Source§

impl JSValue

StructSupport. Objective-C methods exported to JavaScript may have argument and/or return values of struct types, provided that conversion to and from the struct is supported by JSValue. Support is provided for any types where JSValue contains both a class method valueWith <Type

:inContext: , and and instance method to <Type

- where the string in these selector names match, with the first argument to the former being of the same struct type as the return type of the latter. Support is provided for structs of type CGPoint, NSRange, CGRect and CGSize.
Source

pub unsafe fn valueWithPoint_inContext( point: CGPoint, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate features JSContext and objc2-core-foundation only.

Create a JSValue from a CGPoint.

Returns: A newly allocated JavaScript object containing properties named x and y , with values from the CGPoint.

Source

pub unsafe fn valueWithRange_inContext( range: NSRange, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate features JSContext and objc2-foundation only.

Create a JSValue from a NSRange.

Returns: A newly allocated JavaScript object containing properties named location and length , with values from the NSRange.

Source

pub unsafe fn valueWithRect_inContext( rect: CGRect, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate features JSContext and objc2-core-foundation only.

Create a JSValue from a CGRect.

Returns: A newly allocated JavaScript object containing properties named x , y , width , and height , with values from the CGRect.

Source

pub unsafe fn valueWithSize_inContext( size: CGSize, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate features JSContext and objc2-core-foundation only.

Create a JSValue from a CGSize.

Returns: A newly allocated JavaScript object containing properties named width and height , with values from the CGSize.

Source

pub unsafe fn toPoint(&self) -> CGPoint

Available on crate feature objc2-core-foundation only.

Convert a JSValue to a CGPoint.

Reads the properties named x and y from this JSValue, and converts the results to double.

Returns: The new CGPoint.

Source

pub unsafe fn toRange(&self) -> NSRange

Available on crate feature objc2-foundation only.

Convert a JSValue to an NSRange.

Reads the properties named location and length from this JSValue and converts the results to double.

Returns: The new NSRange.

Source

pub unsafe fn toRect(&self) -> CGRect

Available on crate feature objc2-core-foundation only.

Convert a JSValue to a CGRect.

Reads the properties named x , y , width , and height from this JSValue and converts the results to double.

Returns: The new CGRect.

Source

pub unsafe fn toSize(&self) -> CGSize

Available on crate feature objc2-core-foundation only.

Convert a JSValue to a CGSize.

Reads the properties named width and height from this JSValue and converts the results to double.

Returns: The new CGSize.

Source§

impl JSValue

PropertyAccess. These methods enable querying properties on a JSValue.

Source

pub unsafe fn valueForProperty( &self, property: Option<&JSValueProperty>, ) -> Option<Retained<JSValue>>

Available on crate feature objc2-foundation only.

Access a property of a JSValue.

Returns: The JSValue for the requested property or the JSValue undefined if the property does not exist.

Corresponds to the JavaScript operation object[property] . Starting with macOS 10.15 and iOS 13, ‘property’ can be any ‘id’ and will be converted to a JSValue using the conversion rules of valueWithObject:inContext: . Prior to macOS 10.15 and iOS 13, ‘property’ was expected to be an NSString *.

Source

pub unsafe fn setValue_forProperty( &self, value: Option<&AnyObject>, property: Option<&JSValueProperty>, )

Available on crate feature objc2-foundation only.

Set a property on a JSValue.

Corresponds to the JavaScript operation object[property] = value . Starting with macOS 10.15 and iOS 13, ‘property’ can be any ‘id’ and will be converted to a JSValue using the conversion rules of valueWithObject:inContext: . Prior to macOS 10.15 and iOS 13, ‘property’ was expected to be an NSString *.

Source

pub unsafe fn deleteProperty(&self, property: Option<&JSValueProperty>) -> bool

Available on crate feature objc2-foundation only.

Delete a property from a JSValue.

Returns: YES if deletion is successful, NO otherwise.

Corresponds to the JavaScript operation delete object[property] . Starting with macOS 10.15 and iOS 13, ‘property’ can be any ‘id’ and will be converted to a JSValue using the conversion rules of valueWithObject:inContext: . Prior to macOS 10.15 and iOS 13, ‘property’ was expected to be an NSString *.

Source

pub unsafe fn hasProperty(&self, property: Option<&JSValueProperty>) -> bool

Available on crate feature objc2-foundation only.

Check if a JSValue has a property.

This method has the same function as the JavaScript operator in .

Returns: Returns YES if property is present on the value.

Corresponds to the JavaScript operation property in object . Starting with macOS 10.15 and iOS 13, ‘property’ can be any ‘id’ and will be converted to a JSValue using the conversion rules of valueWithObject:inContext: . Prior to macOS 10.15 and iOS 13, ‘property’ was expected to be an NSString *.

Source

pub unsafe fn defineProperty_descriptor( &self, property: Option<&JSValueProperty>, descriptor: Option<&AnyObject>, )

Available on crate feature objc2-foundation only.

Define properties with custom descriptors on JSValues.

This method may be used to create a data or accessor property on an object. This method operates in accordance with the Object.defineProperty method in the JavaScript language. Starting with macOS 10.15 and iOS 13, ‘property’ can be any ‘id’ and will be converted to a JSValue using the conversion rules of valueWithObject:inContext: . Prior to macOS 10.15 and iOS 13, ‘property’ was expected to be an NSString *.

Source

pub unsafe fn valueAtIndex( &self, index: NSUInteger, ) -> Option<Retained<JSValue>>

Access an indexed (numerical) property on a JSValue.

Returns: The JSValue for the property at the specified index. Returns the JavaScript value undefined if no property exists at that index.

Source

pub unsafe fn setValue_atIndex( &self, value: Option<&AnyObject>, index: NSUInteger, )

Set an indexed (numerical) property on a JSValue.

For JSValues that are JavaScript arrays, indices greater than UINT_MAX - 1 will not affect the length of the array.

Source§

impl JSValue

SubscriptSupport. Instances of JSValue implement the following methods in order to enable support for subscript access by key and index, for example:

    JSValue *objectA, *objectB;
    JSValue *v1 = object[@"X"]; // Get value for property "X" from 'object'.
    JSValue *v2 = object[42];   // Get value for index 42 from 'object'.
    object[@"Y"] = v1;          // Assign 'v1' to property "Y" of 'object'.
    object[101] = v2;           // Assign 'v2' to index 101 of 'object'.

An object key passed as a subscript will be converted to a JavaScript value, and then the value using the same rules as valueWithObject:inContext: . In macOS 10.14 and iOS 12 and below, the key argument of setObject:object forKeyedSubscript:key was restricted to an NSObject <NSCopying

but that restriction was never used internally.
Source

pub unsafe fn objectForKeyedSubscript( &self, key: Option<&AnyObject>, ) -> Option<Retained<JSValue>>

Source

pub unsafe fn objectAtIndexedSubscript( &self, index: NSUInteger, ) -> Option<Retained<JSValue>>

Source

pub unsafe fn setObject_forKeyedSubscript( &self, object: Option<&AnyObject>, key: Option<&AnyObject>, )

Source

pub unsafe fn setObject_atIndexedSubscript( &self, object: Option<&AnyObject>, index: NSUInteger, )

Source§

impl JSValue

JSValueRefSupport. These functions are for bridging between the C API and the Objective-C API.

Source

pub unsafe fn valueWithJSValueRef_inContext( value: JSValueRef, context: Option<&JSContext>, ) -> Option<Retained<JSValue>>

Available on crate features JSBase and JSContext only.

Creates a JSValue, wrapping its C API counterpart.

Returns: The Objective-C API equivalent of the specified JSValueRef.

Source

pub unsafe fn JSValueRef(&self) -> JSValueRef

Available on crate feature JSBase only.

Returns the C API counterpart wrapped by a JSContext.

Returns: The C API equivalent of this JSValue.

Source§

impl JSValue

Source

pub unsafe fn type(ctx: JSContextRef, value: JSValueRef) -> JSType

Available on crate features JSValueRef and JSBase only.

Returns a JavaScript value’s type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue whose type you want to obtain.

Returns: A value of type JSType that identifies value’s type.

Source

pub unsafe fn is_undefined(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value’s type is the undefined type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value’s type is the undefined type, otherwise false.

Source

pub unsafe fn is_null(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value’s type is the null type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value’s type is the null type, otherwise false.

Source

pub unsafe fn is_boolean(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value’s type is the boolean type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value’s type is the boolean type, otherwise false.

Source

pub unsafe fn is_number(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value’s type is the number type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value’s type is the number type, otherwise false.

Source

pub unsafe fn is_string(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value’s type is the string type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value’s type is the string type, otherwise false.

Source

pub unsafe fn is_symbol(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value’s type is the symbol type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value’s type is the symbol type, otherwise false.

Source

pub unsafe fn is_big_int(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value’s type is the BigInt type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value’s type is the BigInt type, otherwise false.

Source

pub unsafe fn is_object(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value’s type is the object type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value’s type is the object type, otherwise false.

Source

pub unsafe fn is_object_of_class( ctx: JSContextRef, value: JSValueRef, js_class: JSClassRef, ) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value is an object with a given class in its class chain.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Parameter jsClass: The JSClass to test against.

Returns: true if value is an object and has jsClass in its class chain, otherwise false.

Source

pub unsafe fn is_array(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value is an array.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value is an array, otherwise false.

Source

pub unsafe fn is_date(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value is a date.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Returns: true if value is a date, otherwise false.

Source

pub unsafe fn typed_array_type( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> JSTypedArrayType

Available on crate features JSValueRef and JSBase only.

Returns a JavaScript value’s Typed Array type.

Parameter ctx: The execution context to use.

Parameter value: The JSValue whose Typed Array type to return.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: A value of type JSTypedArrayType that identifies value’s Typed Array type, or kJSTypedArrayTypeNone if the value is not a Typed Array object.

Source

pub unsafe fn is_equal( ctx: JSContextRef, a: JSValueRef, b: JSValueRef, exception: *mut JSValueRef, ) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether two JavaScript values are equal, as compared by the JS == operator.

Parameter ctx: The execution context to use.

Parameter a: The first value to test.

Parameter b: The second value to test.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: true if the two values are equal, false if they are not equal or an exception is thrown.

Source

pub unsafe fn is_strict_equal( ctx: JSContextRef, a: JSValueRef, b: JSValueRef, ) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether two JavaScript values are strict equal, as compared by the JS === operator.

Parameter ctx: The execution context to use.

Parameter a: The first value to test.

Parameter b: The second value to test.

Returns: true if the two values are strict equal, otherwise false.

Source

pub unsafe fn is_instance_of_constructor( ctx: JSContextRef, value: JSValueRef, constructor: JSObjectRef, exception: *mut JSValueRef, ) -> bool

Available on crate features JSValueRef and JSBase only.

Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to test.

Parameter constructor: The constructor to test against.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: true if value is an object constructed by constructor, as compared by the JS instanceof operator, otherwise false.

Source

pub unsafe fn compare( ctx: JSContextRef, left: JSValueRef, right: JSValueRef, exception: *mut JSValueRef, ) -> JSRelationCondition

Available on crate features JSValueRef and JSBase only.

Compares two JSValues.

Parameter ctx: The execution context to use.

Parameter left: The JSValue as the left operand.

Parameter right: The JSValue as the right operand.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.

The result is computed by comparing the results of JavaScript’s ==, <, and > operators. If either left or right is (or would coerce to) NaN in JavaScript, then the result is kJSRelationConditionUndefined.

Source

pub unsafe fn compare_int64( ctx: JSContextRef, left: JSValueRef, right: i64, exception: *mut JSValueRef, ) -> JSRelationCondition

Available on crate features JSValueRef and JSBase only.

Compares a JSValue with a signed 64-bit integer.

Parameter ctx: The execution context to use.

Parameter left: The JSValue as the left operand.

Parameter right: The int64_t as the right operand.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.

left is converted to an integer according to the rules specified by the JavaScript language then compared with right.

Source

pub unsafe fn compare_u_int64( ctx: JSContextRef, left: JSValueRef, right: u64, exception: *mut JSValueRef, ) -> JSRelationCondition

Available on crate features JSValueRef and JSBase only.

Compares a JSValue with an unsigned 64-bit integer.

Parameter ctx: The execution context to use.

Parameter left: The JSValue as the left operand.

Parameter right: The uint64_t as the right operand.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.

left is converted to an integer according to the rules specified by the JavaScript language then compared with right.

Source

pub unsafe fn compare_double( ctx: JSContextRef, left: JSValueRef, right: c_double, exception: *mut JSValueRef, ) -> JSRelationCondition

Available on crate features JSValueRef and JSBase only.

Compares a JSValue with a double.

Parameter ctx: The execution context to use.

Parameter left: The JSValue as the left operand.

Parameter right: The double as the right operand.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.

left is converted to a double according to the rules specified by the JavaScript language then compared with right.

Source

pub unsafe fn new_undefined(ctx: JSContextRef) -> JSValueRef

Available on crate features JSValueRef and JSBase only.

Creates a JavaScript value of the undefined type.

Parameter ctx: The execution context to use.

Returns: The unique undefined value.

Source

pub unsafe fn new_null(ctx: JSContextRef) -> JSValueRef

Available on crate features JSValueRef and JSBase only.

Creates a JavaScript value of the null type.

Parameter ctx: The execution context to use.

Returns: The unique null value.

Source

pub unsafe fn new_boolean(ctx: JSContextRef, boolean: bool) -> JSValueRef

Available on crate features JSValueRef and JSBase only.

Creates a JavaScript value of the boolean type.

Parameter ctx: The execution context to use.

Parameter boolean: The bool to assign to the newly created JSValue.

Returns: A JSValue of the boolean type, representing the value of boolean.

Source

pub unsafe fn new_number(ctx: JSContextRef, number: c_double) -> JSValueRef

Available on crate features JSValueRef and JSBase only.

Creates a JavaScript value of the number type.

Parameter ctx: The execution context to use.

Parameter number: The double to assign to the newly created JSValue.

Returns: A JSValue of the number type, representing the value of number.

Source

pub unsafe fn new_string(ctx: JSContextRef, string: JSStringRef) -> JSValueRef

Available on crate features JSValueRef and JSBase only.

Creates a JavaScript value of the string type.

Parameter ctx: The execution context to use.

Parameter string: The JSString to assign to the newly created JSValue. The newly created JSValue retains string, and releases it upon garbage collection.

Returns: A JSValue of the string type, representing the value of string.

Source

pub unsafe fn new_symbol( ctx: JSContextRef, description: JSStringRef, ) -> JSValueRef

Available on crate features JSValueRef and JSBase only.

Creates a JavaScript value of the symbol type.

Parameter ctx: The execution context to use.

Parameter description: A description of the newly created symbol value.

Returns: A unique JSValue of the symbol type, whose description matches the one provided.

Source§

impl JSValue

Source

pub unsafe fn from_json_string( ctx: JSContextRef, string: JSStringRef, ) -> JSValueRef

Available on crate features JSValueRef and JSBase only.

Creates a JavaScript value from a JSON formatted string.

Parameter ctx: The execution context to use.

Parameter string: The JSString containing the JSON string to be parsed.

Returns: A JSValue containing the parsed value, or NULL if the input is invalid.

Source

pub unsafe fn create_json_string( ctx: JSContextRef, value: JSValueRef, indent: c_uint, exception: *mut JSValueRef, ) -> JSStringRef

Available on crate features JSValueRef and JSBase only.

Creates a JavaScript string containing the JSON serialized representation of a JS value.

Parameter ctx: The execution context to use.

Parameter value: The value to serialize.

Parameter indent: The number of spaces to indent when nesting. If 0, the resulting JSON will not contains newlines. The size of the indent is clamped to 10 spaces.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: A JSString with the result of serialization, or NULL if an exception is thrown.

Source

pub unsafe fn to_boolean(ctx: JSContextRef, value: JSValueRef) -> bool

Available on crate features JSValueRef and JSBase only.

Converts a JavaScript value to boolean and returns the resulting boolean.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to convert.

Returns: The boolean result of conversion.

Source

pub unsafe fn to_number( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> c_double

Available on crate features JSValueRef and JSBase only.

Converts a JavaScript value to number and returns the resulting number.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to convert.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: The numeric result of conversion, or NaN if an exception is thrown.

The result is equivalent to Number(value) in JavaScript.

Source

pub unsafe fn to_int32( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> i32

Available on crate features JSValueRef and JSBase only.

Converts a JSValue to a singed 32-bit integer and returns the resulting integer.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to convert.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: An int32_t with the result of conversion, or 0 if an exception is thrown. Since 0 is valid value, exception must be checked after the call.

The JSValue is converted to an integer according to the rules specified by the JavaScript language. If the value is a BigInt, then the JSValue is truncated to an int32_t.

Source

pub unsafe fn to_u_int32( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> u32

Available on crate features JSValueRef and JSBase only.

Converts a JSValue to an unsigned 32-bit integer and returns the resulting integer.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to convert.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: A uint32_t with the result of conversion, or 0 if an exception is thrown. Since 0 is valid value, exception must be checked after the call.

The JSValue is converted to an integer according to the rules specified by the JavaScript language. If the value is a BigInt, then the JSValue is truncated to a uint32_t.

Source

pub unsafe fn to_int64( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> i64

Available on crate features JSValueRef and JSBase only.

Converts a JSValue to a singed 64-bit integer and returns the resulting integer.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to convert.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: An int64_t with the result of conversion, or 0 if an exception is thrown. Since 0 is valid value, exception must be checked after the call.

The JSValue is converted to an integer according to the rules specified by the JavaScript language. If the value is a BigInt, then the JSValue is truncated to an int64_t.

Source

pub unsafe fn to_u_int64( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> u64

Available on crate features JSValueRef and JSBase only.

Converts a JSValue to an unsigned 64-bit integer and returns the resulting integer.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to convert.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: A uint64_t with the result of conversion, or 0 if an exception is thrown. Since 0 is valid value, exception must be checked after the call.

The JSValue is converted to an integer according to the rules specified by the JavaScript language. If the value is a BigInt, then the JSValue is truncated to a uint64_t.

Source

pub unsafe fn to_string_copy( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> JSStringRef

Available on crate features JSValueRef and JSBase only.

Converts a JavaScript value to string and copies the result into a JavaScript string.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to convert.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: A JSString with the result of conversion, or NULL if an exception is thrown. Ownership follows the Create Rule.

Source

pub unsafe fn to_object( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> JSObjectRef

Available on crate features JSValueRef and JSBase only.

Converts a JavaScript value to object and returns the resulting object.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to convert.

Parameter exception: A pointer to a JSValueRef in which to store an exception, if any. To reliable detect exception, initialize this to null before the call. Pass NULL if you do not care to store an exception.

Returns: The JSObject result of conversion, or NULL if an exception is thrown.

Source

pub unsafe fn protect(ctx: JSContextRef, value: JSValueRef)

Available on crate features JSValueRef and JSBase only.

Protects a JavaScript value from garbage collection.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to protect.

Use this method when you want to store a JSValue in a global or on the heap, where the garbage collector will not be able to discover your reference to it.

A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection.

Source

pub unsafe fn unprotect(ctx: JSContextRef, value: JSValueRef)

Available on crate features JSValueRef and JSBase only.

Unprotects a JavaScript value from garbage collection.

Parameter ctx: The execution context to use.

Parameter value: The JSValue to unprotect.

A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection.

Methods from Deref<Target = NSObject>§

Source

pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !

Handle messages the object doesn’t recognize.

See Apple’s documentation for details.

Methods from Deref<Target = AnyObject>§

Source

pub fn class(&self) -> &'static AnyClass

Dynamically find the class of this object.

§Panics

May panic if the object is invalid (which may be the case for objects returned from unavailable init/new methods).

§Example

Check that an instance of NSObject has the precise class NSObject.

use objc2::ClassType;
use objc2::runtime::NSObject;

let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Source

pub unsafe fn get_ivar<T>(&self, name: &str) -> &T
where T: Encode,

👎Deprecated: this is difficult to use correctly, use Ivar::load instead.

Use Ivar::load instead.

§Safety

The object must have an instance variable with the given name, and it must be of type T.

See Ivar::load_ptr for details surrounding this.

Source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: DowncastTarget,

Attempt to downcast the object to a class of type T.

This is the reference-variant. Use Retained::downcast if you want to convert a retained object to another type.

§Mutable classes

Some classes have immutable and mutable variants, such as NSString and NSMutableString.

When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.

So using this method to convert a NSString to a NSMutableString, while not unsound, is generally frowned upon unless you created the string yourself, or the API explicitly documents the string to be mutable.

See Apple’s documentation on mutability and on isKindOfClass: for more details.

§Generic classes

Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.

You can, however, safely downcast to generic collections where all the type-parameters are AnyObject.

§Panics

This works internally by calling isKindOfClass:. That means that the object must have the instance method of that name, and an exception will be thrown (if CoreFoundation is linked) or the process will abort if that is not the case. In the vast majority of cases, you don’t need to worry about this, since both root objects NSObject and NSProxy implement this method.

§Examples

Cast an NSString back and forth from NSObject.

use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};

let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();

Try (and fail) to cast an NSObject to an NSString.

use objc2_foundation::{NSObject, NSString};

let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());

Try to cast to an array of strings.

use objc2_foundation::{NSArray, NSObject, NSString};

let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();

This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.

Downcast when processing each element instead.

use objc2_foundation::{NSArray, NSObject, NSString};

let arr = NSArray::from_retained_slice(&[NSObject::new()]);

for elem in arr {
    if let Some(data) = elem.downcast_ref::<NSString>() {
        // handle `data`
    }
}

Trait Implementations§

Source§

impl AsRef<AnyObject> for JSValue

Source§

fn as_ref(&self) -> &AnyObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<JSValue> for JSValue

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<NSObject> for JSValue

Source§

fn as_ref(&self) -> &NSObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Borrow<AnyObject> for JSValue

Source§

fn borrow(&self) -> &AnyObject

Immutably borrows from an owned value. Read more
Source§

impl Borrow<NSObject> for JSValue

Source§

fn borrow(&self) -> &NSObject

Immutably borrows from an owned value. Read more
Source§

impl ClassType for JSValue

Source§

const NAME: &'static str = "JSValue"

The name of the Objective-C class that this type represents. Read more
Source§

type Super = NSObject

The superclass of this class. Read more
Source§

type ThreadKind = <<JSValue as ClassType>::Super as ClassType>::ThreadKind

Whether the type can be used from any thread, or from only the main thread. Read more
Source§

fn class() -> &'static AnyClass

Get a reference to the Objective-C class that this type represents. Read more
Source§

fn as_super(&self) -> &Self::Super

Get an immutable reference to the superclass.
Source§

impl Debug for JSValue

Source§

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

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

impl Deref for JSValue

Source§

type Target = NSObject

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Hash for JSValue

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Message for JSValue

Source§

fn retain(&self) -> Retained<Self>
where Self: Sized,

Increment the reference count of the receiver. Read more
Source§

impl NSObjectProtocol for JSValue

Source§

fn isEqual(&self, other: Option<&AnyObject>) -> bool
where Self: Sized + Message,

Check whether the object is equal to an arbitrary other object. Read more
Source§

fn hash(&self) -> usize
where Self: Sized + Message,

An integer that can be used as a table address in a hash table structure. Read more
Source§

fn isKindOfClass(&self, cls: &AnyClass) -> bool
where Self: Sized + Message,

Check if the object is an instance of the class, or one of its subclasses. Read more
Source§

fn is_kind_of<T>(&self) -> bool
where T: ClassType, Self: Sized + Message,

👎Deprecated: use isKindOfClass directly, or cast your objects with AnyObject::downcast_ref
Check if the object is an instance of the class type, or one of its subclasses. Read more
Source§

fn isMemberOfClass(&self, cls: &AnyClass) -> bool
where Self: Sized + Message,

Check if the object is an instance of a specific class, without checking subclasses. Read more
Source§

fn respondsToSelector(&self, aSelector: Sel) -> bool
where Self: Sized + Message,

Check whether the object implements or inherits a method with the given selector. Read more
Source§

fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
where Self: Sized + Message,

Check whether the object conforms to a given protocol. Read more
Source§

fn description(&self) -> Retained<NSObject>
where Self: Sized + Message,

A textual representation of the object. Read more
Source§

fn debugDescription(&self) -> Retained<NSObject>
where Self: Sized + Message,

A textual representation of the object to use when debugging. Read more
Source§

fn isProxy(&self) -> bool
where Self: Sized + Message,

Check whether the receiver is a subclass of the NSProxy root class instead of the usual NSObject. Read more
Source§

fn retainCount(&self) -> usize
where Self: Sized + Message,

The reference count of the object. Read more
Source§

impl PartialEq for JSValue

Source§

fn eq(&self, other: &Self) -> 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 JSValue

Source§

const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF

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

impl DowncastTarget for JSValue

Source§

impl Eq for JSValue

Auto Trait Implementations§

§

impl !Freeze for JSValue

§

impl !RefUnwindSafe for JSValue

§

impl !Send for JSValue

§

impl !Sync for JSValue

§

impl !Unpin for JSValue

§

impl !UnwindSafe for JSValue

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<'a, T> AnyThread for T
where T: ClassType<ThreadKind = dyn AnyThread + 'a> + ?Sized,

Source§

fn alloc() -> Allocated<Self>
where Self: Sized + ClassType,

Allocate a new instance of the class. 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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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,