Package apple.javascriptcore
Class JSValue
- java.lang.Object
-
- org.moe.natj.general.NativeObject
-
- org.moe.natj.objc.ObjCObject
-
- apple.NSObject
-
- apple.javascriptcore.JSValue
-
- All Implemented Interfaces:
NSObject
public class JSValue extends NSObject
[@interface] 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceJSValue.Block_valueWithNewPromiseInContextFromExecutor-
Nested classes/interfaces inherited from class apple.NSObject
NSObject.Function_instanceMethodForSelector_ret, NSObject.Function_methodForSelector_ret
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJSValue(org.moe.natj.general.Pointer peer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleanaccessInstanceVariablesDirectly()static JSValuealloc()static java.lang.ObjectallocWithZone(org.moe.natj.general.ptr.VoidPtr zone)static booleanautomaticallyNotifiesObserversForKey(java.lang.String key)JSValuecallWithArguments(NSArray<?> arguments)[@methodgroup] Calling Functions and Constructors Invoke a JSValue as a function.static voidcancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget)static voidcancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget, org.moe.natj.objc.SEL aSelector, java.lang.Object anArgument)static NSArray<java.lang.String>classFallbacksForKeyedArchiver()static org.moe.natj.objc.ClassclassForKeyedUnarchiver()JSValueconstructWithArguments(NSArray<?> arguments)Invoke a JSValue as a constructor.JSContextcontext()[@property] The JSContext that this value originates from.static java.lang.StringdebugDescription_static()voiddefinePropertyDescriptor(java.lang.String property, java.lang.Object descriptor)Define properties with custom descriptors on JSValues.booleandeleteProperty(java.lang.String property)Delete a property from a JSValue.static java.lang.Stringdescription_static()static longhash_static()booleanhasProperty(java.lang.String property)Check if a JSValue has a property.JSValueinit()static NSObject.Function_instanceMethodForSelector_retinstanceMethodForSelector(org.moe.natj.objc.SEL aSelector)static NSMethodSignatureinstanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector)static booleaninstancesRespondToSelector(org.moe.natj.objc.SEL aSelector)JSValueinvokeMethodWithArguments(java.lang.String method, NSArray<?> arguments)Invoke a method on a JSValue.booleanisArray()[@property] Check if a JSValue is an array.booleanisBoolean()[@property] Check if a JSValue is a boolean.booleanisDate()[@property] Check if a JSValue is a date.booleanisEqualToObject(java.lang.Object value)Compare two JSValues using JavaScript's===operator.booleanisEqualWithTypeCoercionToObject(java.lang.Object value)Compare two JSValues using JavaScript's==operator.booleanisInstanceOf(java.lang.Object value)Check if a JSValue is an instance of another object.booleanisNull()[@property] Check if a JSValue corresponds to the JavaScript valuenull.booleanisNumber()[@property] Check if a JSValue is a number.booleanisObject()[@property] Check if a JSValue is an object.booleanisString()[@property] Check if a JSValue is a string.static booleanisSubclassOfClass(org.moe.natj.objc.Class aClass)booleanisSymbol()[@property] Check if a JSValue is a symbol.booleanisUndefined()[@property] Check if a JSValue corresponds to the JavaScript valueundefined.JSValueRefJSValueRef()[@property] Returns the C API counterpart wrapped by a JSContext.static NSSet<java.lang.String>keyPathsForValuesAffectingValueForKey(java.lang.String key)static java.lang.Objectnew_objc()JSValueobjectAtIndexedSubscript(long index)JSValueobjectForKeyedSubscript(java.lang.Object key)static booleanresolveClassMethod(org.moe.natj.objc.SEL sel)static booleanresolveInstanceMethod(org.moe.natj.objc.SEL sel)voidsetObjectAtIndexedSubscript(java.lang.Object object, long index)voidsetObjectForKeyedSubscript(java.lang.Object object, java.lang.Object key)voidsetValueAtIndex(java.lang.Object value, long index)Set an indexed (numerical) property on a JSValue.voidsetValueForProperty(java.lang.Object value, java.lang.String property)Set a property on a JSValue.static voidsetVersion_static(long aVersion)static org.moe.natj.objc.Classsuperclass_static()NSArray<?>toArray()Convert a JSValue to a NSArray.booleantoBool()Convert a JSValue to a boolean.NSDatetoDate()Convert a JSValue to a NSDate.NSDictionary<?,?>toDictionary()Convert a JSValue to a NSDictionary.doubletoDouble()Convert a JSValue to a double.inttoInt32()Convert a JSValue to anint32_t.NSNumbertoNumber()Convert a JSValue to a NSNumber.java.lang.ObjecttoObject()[@methodgroup] Converting to Objective-C Types When converting between JavaScript values and Objective-C objects a copy is performed.java.lang.ObjecttoObjectOfClass(org.moe.natj.objc.Class expectedClass)Convert a JSValue to an Objective-C object of a specific class.CGPointtoPoint()Convert a JSValue to a CGPoint.NSRangetoRange()Convert a JSValue to an NSRange.CGRecttoRect()Convert a JSValue to a CGRect.CGSizetoSize()Convert a JSValue to a CGSize.java.lang.StringtoString()Convert a JSValue to a NSString.inttoUInt32()Convert a JSValue to auint32_t.JSValuevalueAtIndex(long index)Access an indexed (numerical) property on a JSValue.JSValuevalueForProperty(java.lang.String property)Access a property of a JSValue.static JSValuevalueWithBoolInContext(boolean value, JSContext context)Create a JavaScript value from a BOOL primitive.static JSValuevalueWithDoubleInContext(double value, JSContext context)Create a JavaScript value from a double primitive.static JSValuevalueWithInt32InContext(int value, JSContext context)Create a JavaScript value from anint32_tprimitive.static JSValuevalueWithJSValueRefInContext(JSValueRef value, JSContext context)Creates a JSValue, wrapping its C API counterpart.static JSValuevalueWithNewArrayInContext(JSContext context)Create a new, empty JavaScript array.static JSValuevalueWithNewErrorFromMessageInContext(java.lang.String message, JSContext context)Create a new JavaScript error object.static JSValuevalueWithNewObjectInContext(JSContext context)Create a new, empty JavaScript object.static JSValuevalueWithNewPromiseInContextFromExecutor(JSContext context, JSValue.Block_valueWithNewPromiseInContextFromExecutor callback)Create a new promise object using the provided executor callback.static JSValuevalueWithNewPromiseRejectedWithReasonInContext(java.lang.Object reason, JSContext context)Create a new rejected promise object with the provided value.static JSValuevalueWithNewPromiseResolvedWithResultInContext(java.lang.Object result, JSContext context)Create a new resolved promise object with the provided value.static JSValuevalueWithNewRegularExpressionFromPatternFlagsInContext(java.lang.String pattern, java.lang.String flags, JSContext context)Create a new JavaScript regular expression object.static JSValuevalueWithNewSymbolFromDescriptionInContext(java.lang.String description, JSContext context)Create a new, unique, symbol object.static JSValuevalueWithNullInContext(JSContext context)Create the JavaScript valuenull.static JSValuevalueWithObjectInContext(java.lang.Object value, JSContext context)[@methodgroup] Creating JavaScript Values Create a JSValue by converting an Objective-C object.static JSValuevalueWithPointInContext(CGPoint point, JSContext context)Create a JSValue from a CGPoint.static JSValuevalueWithRangeInContext(NSRange range, JSContext context)Create a JSValue from a NSRange.static JSValuevalueWithRectInContext(CGRect rect, JSContext context)Create a JSValue from a CGRect.static JSValuevalueWithSizeInContext(CGSize size, JSContext context)Create a JSValue from a CGSize.static JSValuevalueWithUInt32InContext(int value, JSContext context)Create a JavaScript value from auint32_tprimitive.static JSValuevalueWithUndefinedInContext(JSContext context)Create the JavaScript valueundefined.static longversion_static()-
Methods inherited from class apple.NSObject
accessibilityActivate, accessibilityActivationPoint, accessibilityAssistiveTechnologyFocusedIdentifiers, accessibilityAttributedHint, accessibilityAttributedLabel, accessibilityAttributedUserInputLabels, accessibilityAttributedValue, accessibilityContainerType, accessibilityCustomActions, accessibilityCustomRotors, accessibilityDecrement, accessibilityDragSourceDescriptors, accessibilityDropPointDescriptors, accessibilityElementAtIndex, accessibilityElementCount, accessibilityElementDidBecomeFocused, accessibilityElementDidLoseFocus, accessibilityElementIsFocused, accessibilityElements, accessibilityElementsHidden, accessibilityFrame, accessibilityHint, accessibilityIncrement, accessibilityLabel, accessibilityLanguage, accessibilityNavigationStyle, accessibilityPath, accessibilityPerformEscape, accessibilityPerformMagicTap, accessibilityRespondsToUserInteraction, accessibilityScroll, accessibilityTextualContext, accessibilityTraits, accessibilityUserInputLabels, accessibilityValue, accessibilityViewIsModal, addObserverForKeyPathOptionsContext, attemptRecoveryFromErrorOptionIndex, attemptRecoveryFromErrorOptionIndexDelegateDidRecoverSelectorContextInfo, autoContentAccessingProxy, awakeAfterUsingCoder, awakeFromNib, class_objc, classForCoder, classForKeyedArchiver, copy, dealloc, debugDescription, description, dictionaryWithValuesForKeys, didChangeValueForKey, didChangeValueForKeyWithSetMutationUsingObjects, didChangeValuesAtIndexesForKey, doesNotRecognizeSelector, fileManagerShouldProceedAfterError, fileManagerWillProcessPath, finalize_objc, forwardingTargetForSelector, forwardInvocation, hash, indexOfAccessibilityElement, isAccessibilityElement, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableArrayValueForKey, mutableArrayValueForKeyPath, mutableCopy, mutableOrderedSetValueForKey, mutableOrderedSetValueForKeyPath, mutableSetValueForKey, mutableSetValueForKeyPath, observationInfo, observeValueForKeyPathOfObjectChangeContext, performSelector, performSelectorInBackgroundWithObject, performSelectorOnMainThreadWithObjectWaitUntilDone, performSelectorOnMainThreadWithObjectWaitUntilDoneModes, performSelectorOnThreadWithObjectWaitUntilDone, performSelectorOnThreadWithObjectWaitUntilDoneModes, performSelectorWithObject, performSelectorWithObjectAfterDelay, performSelectorWithObjectAfterDelayInModes, performSelectorWithObjectWithObject, prepareForInterfaceBuilder, provideImageDataBytesPerRowOrigin_Size_UserInfo, removeObserverForKeyPath, removeObserverForKeyPathContext, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, self, setAccessibilityActivationPoint, setAccessibilityAttributedHint, setAccessibilityAttributedLabel, setAccessibilityAttributedUserInputLabels, setAccessibilityAttributedValue, setAccessibilityContainerType, setAccessibilityCustomActions, setAccessibilityCustomRotors, setAccessibilityDragSourceDescriptors, setAccessibilityDropPointDescriptors, setAccessibilityElements, setAccessibilityElementsHidden, setAccessibilityFrame, setAccessibilityHint, setAccessibilityLabel, setAccessibilityLanguage, setAccessibilityNavigationStyle, setAccessibilityPath, setAccessibilityRespondsToUserInteraction, setAccessibilityTextualContext, setAccessibilityTraits, setAccessibilityUserInputLabels, setAccessibilityValue, setAccessibilityViewIsModal, setIsAccessibilityElement, setNilValueForKey, setObservationInfo, setShouldGroupAccessibilityChildren, setValueForKey, setValueForKeyPath, setValueForUndefinedKey, setValuesForKeysWithDictionary, shouldGroupAccessibilityChildren, superclass, validateValueForKeyError, validateValueForKeyPathError, valueForKey, valueForKeyPath, valueForUndefinedKey, willChangeValueForKey, willChangeValueForKeyWithSetMutationUsingObjects, willChangeValuesAtIndexesForKey
-
-
-
-
Method Detail
-
accessInstanceVariablesDirectly
public static boolean accessInstanceVariablesDirectly()
-
alloc
public static JSValue alloc()
-
allocWithZone
public static java.lang.Object allocWithZone(org.moe.natj.general.ptr.VoidPtr zone)
-
automaticallyNotifiesObserversForKey
public static boolean automaticallyNotifiesObserversForKey(java.lang.String key)
-
cancelPreviousPerformRequestsWithTarget
public static void cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget)
-
cancelPreviousPerformRequestsWithTargetSelectorObject
public static void cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget, org.moe.natj.objc.SEL aSelector, java.lang.Object anArgument)
-
classFallbacksForKeyedArchiver
public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
-
classForKeyedUnarchiver
public static org.moe.natj.objc.Class classForKeyedUnarchiver()
-
debugDescription_static
public static java.lang.String debugDescription_static()
-
description_static
public static java.lang.String description_static()
-
hash_static
public static long hash_static()
-
instanceMethodForSelector
public static NSObject.Function_instanceMethodForSelector_ret instanceMethodForSelector(org.moe.natj.objc.SEL aSelector)
-
instanceMethodSignatureForSelector
public static NSMethodSignature instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector)
-
instancesRespondToSelector
public static boolean instancesRespondToSelector(org.moe.natj.objc.SEL aSelector)
-
isSubclassOfClass
public static boolean isSubclassOfClass(org.moe.natj.objc.Class aClass)
-
keyPathsForValuesAffectingValueForKey
public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey(java.lang.String key)
-
new_objc
public static java.lang.Object new_objc()
-
resolveClassMethod
public static boolean resolveClassMethod(org.moe.natj.objc.SEL sel)
-
resolveInstanceMethod
public static boolean resolveInstanceMethod(org.moe.natj.objc.SEL sel)
-
setVersion_static
public static void setVersion_static(long aVersion)
-
superclass_static
public static org.moe.natj.objc.Class superclass_static()
-
valueWithBoolInContext
public static JSValue valueWithBoolInContext(boolean value, JSContext context)
Create a JavaScript value from a BOOL primitive.- Parameters:
context- The JSContext in which the resulting JSValue will be created.- Returns:
- The new JSValue representing the equivalent boolean value.
-
valueWithDoubleInContext
public static JSValue valueWithDoubleInContext(double value, JSContext context)
Create a JavaScript value from a double primitive.- Parameters:
context- The JSContext in which the resulting JSValue will be created.- Returns:
- The new JSValue representing the equivalent boolean value.
-
valueWithInt32InContext
public static JSValue valueWithInt32InContext(int value, JSContext context)
Create a JavaScript value from anint32_tprimitive.- Parameters:
context- The JSContext in which the resulting JSValue will be created.- Returns:
- The new JSValue representing the equivalent boolean value.
-
valueWithJSValueRefInContext
public static JSValue valueWithJSValueRefInContext(JSValueRef value, JSContext context)
Creates a JSValue, wrapping its C API counterpart.- Returns:
- The Objective-C API equivalent of the specified JSValueRef.
-
valueWithNewArrayInContext
public static JSValue valueWithNewArrayInContext(JSContext context)
Create a new, empty JavaScript array.- Parameters:
context- The JSContext in which the resulting array will be created.- Returns:
- The new JavaScript array.
-
valueWithNewErrorFromMessageInContext
public static JSValue valueWithNewErrorFromMessageInContext(java.lang.String message, JSContext context)
Create a new JavaScript error object.- Parameters:
message- The error message.context- The JSContext in which the resulting error object will be created.- Returns:
- The new JavaScript error object.
-
valueWithNewObjectInContext
public static JSValue valueWithNewObjectInContext(JSContext context)
Create a new, empty JavaScript object.- Parameters:
context- The JSContext in which the resulting object will be created.- Returns:
- The new JavaScript object.
-
valueWithNewRegularExpressionFromPatternFlagsInContext
public static JSValue valueWithNewRegularExpressionFromPatternFlagsInContext(java.lang.String pattern, java.lang.String flags, JSContext context)
Create a new JavaScript regular expression object.- Parameters:
pattern- The regular expression pattern.flags- The regular expression flags.context- The JSContext in which the resulting regular expression object will be created.- Returns:
- The new JavaScript regular expression object.
-
valueWithNullInContext
public static JSValue valueWithNullInContext(JSContext context)
Create the JavaScript valuenull.- Parameters:
context- The JSContext to which the resulting JSValue belongs.- Returns:
- The JSValue representing the JavaScript value
null.
-
valueWithObjectInContext
public static JSValue valueWithObjectInContext(java.lang.Object value, JSContext context)
[@methodgroup] Creating JavaScript Values Create a JSValue by converting an Objective-C object. The resulting JSValue retains the provided Objective-C object.- Parameters:
value- The Objective-C object to be converted.- Returns:
- The new JSValue.
-
valueWithPointInContext
public static JSValue valueWithPointInContext(CGPoint point, JSContext context)
Create a JSValue from a CGPoint.- Returns:
- A newly allocated JavaScript object containing properties
named
xandy, with values from the CGPoint.
-
valueWithRangeInContext
public static JSValue valueWithRangeInContext(NSRange range, JSContext context)
Create a JSValue from a NSRange.- Returns:
- A newly allocated JavaScript object containing properties
named
locationandlength, with values from the NSRange.
-
valueWithRectInContext
public static JSValue valueWithRectInContext(CGRect rect, JSContext context)
Create a JSValue from a CGRect.- Returns:
- A newly allocated JavaScript object containing properties
named
x,y,width, andheight, with values from the CGRect.
-
valueWithSizeInContext
public static JSValue valueWithSizeInContext(CGSize size, JSContext context)
Create a JSValue from a CGSize.- Returns:
- A newly allocated JavaScript object containing properties
named
widthandheight, with values from the CGSize.
-
valueWithUInt32InContext
public static JSValue valueWithUInt32InContext(int value, JSContext context)
Create a JavaScript value from auint32_tprimitive.- Parameters:
context- The JSContext in which the resulting JSValue will be created.- Returns:
- The new JSValue representing the equivalent boolean value.
-
valueWithUndefinedInContext
public static JSValue valueWithUndefinedInContext(JSContext context)
Create the JavaScript valueundefined.- Parameters:
context- The JSContext to which the resulting JSValue belongs.- Returns:
- The JSValue representing the JavaScript value
undefined.
-
version_static
public static long version_static()
-
JSValueRef
public JSValueRef JSValueRef()
[@property] Returns the C API counterpart wrapped by a JSContext.- Returns:
- The C API equivalent of this JSValue.
-
callWithArguments
public JSValue callWithArguments(NSArray<?> arguments)
[@methodgroup] Calling Functions and Constructors Invoke a JSValue as a function. In JavaScript, if a function doesn't explicitly return a value then it implicitly returns the JavaScript valueundefined.- Parameters:
arguments- The arguments to pass to the function.- Returns:
- The return value of the function call.
-
constructWithArguments
public JSValue constructWithArguments(NSArray<?> arguments)
Invoke a JSValue as a constructor. This is equivalent to using thenewsyntax in JavaScript.- Parameters:
arguments- The arguments to pass to the constructor.- Returns:
- The return value of the constructor call.
-
context
public JSContext context()
[@property] The JSContext that this value originates from.
-
definePropertyDescriptor
public void definePropertyDescriptor(java.lang.String property, java.lang.Object descriptor)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 ofvalueWithObject:inContext:. Prior to macOS 10.15 and iOS 13, 'property' was expected to be an NSString *.
-
deleteProperty
public boolean deleteProperty(java.lang.String property)
Delete a property from a JSValue. Corresponds to the JavaScript operationdelete 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 ofvalueWithObject:inContext:. Prior to macOS 10.15 and iOS 13, 'property' was expected to be an NSString *.- Returns:
- YES if deletion is successful, NO otherwise.
-
hasProperty
public boolean hasProperty(java.lang.String property)
Check if a JSValue has a property. This method has the same function as the JavaScript operatorin. Corresponds to the JavaScript operationproperty 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 ofvalueWithObject:inContext:. Prior to macOS 10.15 and iOS 13, 'property' was expected to be an NSString *.- Returns:
- Returns YES if property is present on the value.
-
invokeMethodWithArguments
public JSValue invokeMethodWithArguments(java.lang.String method, NSArray<?> arguments)
Invoke a method on a JSValue. Accesses the property namedmethodfrom this value and calls the resulting value as a function, passing this JSValue as thethisvalue along with the specified arguments.- Parameters:
method- The name of the method to be invoked.arguments- The arguments to pass to the method.- Returns:
- The return value of the method call.
-
isArray
public boolean isArray()
[@property] Check if a JSValue is an array.
-
isBoolean
public boolean isBoolean()
[@property] Check if a JSValue is a boolean.
-
isDate
public boolean isDate()
[@property] Check if a JSValue is a date.
-
isEqualToObject
public boolean isEqualToObject(java.lang.Object value)
Compare two JSValues using JavaScript's===operator.
-
isEqualWithTypeCoercionToObject
public boolean isEqualWithTypeCoercionToObject(java.lang.Object value)
Compare two JSValues using JavaScript's==operator.
-
isInstanceOf
public boolean isInstanceOf(java.lang.Object value)
Check if a JSValue is an instance of another object. This method has the same function as the JavaScript operatorinstanceof. If an object other than a JSValue is passed, it will first be converted according to the aforementioned rules.
-
isNull
public boolean isNull()
[@property] Check if a JSValue corresponds to the JavaScript valuenull.
-
isNumber
public boolean isNumber()
[@property] 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.
-
isObject
public boolean isObject()
[@property] Check if a JSValue is an object.
-
isString
public boolean isString()
[@property] Check if a JSValue is a string.
-
isUndefined
public boolean isUndefined()
[@property] Check if a JSValue corresponds to the JavaScript valueundefined.
-
objectAtIndexedSubscript
public JSValue objectAtIndexedSubscript(long index)
-
objectForKeyedSubscript
public JSValue objectForKeyedSubscript(java.lang.Object key)
-
setObjectAtIndexedSubscript
public void setObjectAtIndexedSubscript(java.lang.Object object, long index)
-
setObjectForKeyedSubscript
public void setObjectForKeyedSubscript(java.lang.Object object, java.lang.Object key)
-
setValueAtIndex
public void setValueAtIndex(java.lang.Object value, long index)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.
-
setValueForProperty
public void setValueForProperty(java.lang.Object value, java.lang.String property)Set a property on a JSValue. Corresponds to the JavaScript operationobject[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 ofvalueWithObject:inContext:. Prior to macOS 10.15 and iOS 13, 'property' was expected to be an NSString *.
-
toArray
public NSArray<?> toArray()
Convert a JSValue to a NSArray. If the value isnullorundefinedthennilis returned. If the value is not an object then a JavaScript TypeError will be thrown. The propertylengthis read from the object, converted to an unsigned integer, and an NSArray of this size is allocated. Properties corresponding to indicies 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.
-
toBool
public boolean toBool()
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.
-
toDate
public NSDate toDate()
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.
-
toDictionary
public NSDictionary<?,?> toDictionary()
Convert a JSValue to a NSDictionary. If the value isnullorundefinedthennilis 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.
-
toDouble
public double toDouble()
Convert a JSValue to a double. The JSValue is converted to a number according to the rules specified by the JavaScript language.- Returns:
- The double result of the conversion.
-
toInt32
public int toInt32()
Convert a JSValue to anint32_t. The JSValue is converted to an integer according to the rules specified by the JavaScript language.- Returns:
- The
int32_tresult of the conversion.
-
toNumber
public NSNumber toNumber()
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 value will be converted to a number according to the rules specified by the JavaScript language.- Returns:
- The NSNumber result of the conversion.
-
toObject
public java.lang.Object toObject()
[@methodgroup] Converting to Objective-C Types 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.- Returns:
- The Objective-C representation of this JSValue.
-
toObjectOfClass
public java.lang.Object toObjectOfClass(org.moe.natj.objc.Class expectedClass)
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 thennilwill be returned.- Returns:
- An Objective-C object of the specified Class or
nil.
-
toPoint
public CGPoint toPoint()
Convert a JSValue to a CGPoint. Reads the properties namedxandyfrom this JSValue, and converts the results to double.- Returns:
- The new CGPoint.
-
toRange
public NSRange toRange()
Convert a JSValue to an NSRange. Reads the properties namedlocationandlengthfrom this JSValue and converts the results to double.- Returns:
- The new NSRange.
-
toRect
public CGRect toRect()
Convert a JSValue to a CGRect. Reads the properties namedx,y,width, andheightfrom this JSValue and converts the results to double.- Returns:
- The new CGRect.
-
toSize
public CGSize toSize()
Convert a JSValue to a CGSize. Reads the properties namedwidthandheightfrom this JSValue and converts the results to double.- Returns:
- The new CGSize.
-
toString
public java.lang.String toString()
Convert a JSValue to a NSString. The JSValue is converted to a string according to the rules specified by the JavaScript language.- Overrides:
toStringin classorg.moe.natj.objc.ObjCObject- Returns:
- The NSString containing the result of the conversion.
-
toUInt32
public int toUInt32()
Convert a JSValue to auint32_t. The JSValue is converted to an integer according to the rules specified by the JavaScript language.- Returns:
- The
uint32_tresult of the conversion.
-
valueAtIndex
public JSValue valueAtIndex(long index)
Access an indexed (numerical) property on a JSValue.- Returns:
- The JSValue for the property at the specified index.
Returns the JavaScript value
undefinedif no property exists at that index.
-
valueForProperty
public JSValue valueForProperty(java.lang.String property)
Access a property of a JSValue. Corresponds to the JavaScript operationobject[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 ofvalueWithObject:inContext:. Prior to macOS 10.15 and iOS 13, 'property' was expected to be an NSString *.- Returns:
- The JSValue for the requested property or the JSValue
undefinedif the property does not exist.
-
isSymbol
public boolean isSymbol()
[@property] Check if a JSValue is a symbol.
-
valueWithNewPromiseInContextFromExecutor
public static JSValue valueWithNewPromiseInContextFromExecutor(JSContext context, JSValue.Block_valueWithNewPromiseInContextFromExecutor callback)
Create a new promise object using the provided executor callback. 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 benil. This also means means the new promise object may be accessed via[context thisValue].- Parameters:
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.context- The JSContext to which the resulting JSValue belongs.- Returns:
- The JSValue representing a new promise JavaScript object.
-
valueWithNewPromiseRejectedWithReasonInContext
public static JSValue valueWithNewPromiseRejectedWithReasonInContext(java.lang.Object reason, JSContext context)
Create a new rejected promise object with the provided value. This method is equivalent to calling[JSValue valueWithNewPromiseFromExecutor:^(JSValue *resolve, JSValue *reject) { [reject callWithArguments:@[reason]]; } inContext:context]- Parameters:
reason- The result value to be passed to any reactions.context- The JSContext to which the resulting JSValue belongs.- Returns:
- The JSValue representing a new promise JavaScript object.
-
valueWithNewPromiseResolvedWithResultInContext
public static JSValue valueWithNewPromiseResolvedWithResultInContext(java.lang.Object result, JSContext context)
Create a new resolved promise object with the provided value. This method is equivalent to calling[JSValue valueWithNewPromiseFromExecutor:^(JSValue *resolve, JSValue *reject) { [resolve callWithArguments:@[result]]; } inContext:context]- Parameters:
result- The result value to be passed to any reactions.context- The JSContext to which the resulting JSValue belongs.- Returns:
- The JSValue representing a new promise JavaScript object.
-
valueWithNewSymbolFromDescriptionInContext
public static JSValue valueWithNewSymbolFromDescriptionInContext(java.lang.String description, JSContext context)
Create a new, unique, symbol object.- Parameters:
description- The description of the symbol object being created.context- The JSContext to which the resulting JSValue belongs.- Returns:
- The JSValue representing a unique JavaScript value with type symbol.
-
-