public class JSValue extends NSObject
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.
| Modifier and Type | Class and Description |
|---|---|
static interface |
JSValue.Block_valueWithNewPromiseInContextFromExecutor |
NSObject.Function_instanceMethodForSelector_ret, NSObject.Function_methodForSelector_ret| Modifier | Constructor and Description |
|---|---|
protected |
JSValue(org.moe.natj.general.Pointer peer) |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
accessInstanceVariablesDirectly() |
static JSValue |
alloc() |
static JSValue |
allocWithZone(org.moe.natj.general.ptr.VoidPtr zone) |
static boolean |
automaticallyNotifiesObserversForKey(java.lang.String key) |
JSValue |
callWithArguments(NSArray<?> arguments)
[@methodgroup] Calling Functions and Constructors
|
static void |
cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget) |
static void |
cancelPreviousPerformRequestsWithTargetSelectorObject(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.Class |
classForKeyedUnarchiver() |
JSValue |
constructWithArguments(NSArray<?> arguments)
Invoke a JSValue as a constructor.
|
JSContext |
context()
[@property]
|
static java.lang.String |
debugDescription_static() |
void |
definePropertyDescriptor(java.lang.String property,
java.lang.Object descriptor)
Define properties with custom descriptors on JSValues.
|
boolean |
deleteProperty(java.lang.String property)
Delete a property from a JSValue.
|
static java.lang.String |
description_static() |
static long |
hash_static() |
boolean |
hasProperty(java.lang.String property)
Check if a JSValue has a property.
|
JSValue |
init() |
static NSObject.Function_instanceMethodForSelector_ret |
instanceMethodForSelector(org.moe.natj.objc.SEL aSelector) |
static NSMethodSignature |
instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector) |
static boolean |
instancesRespondToSelector(org.moe.natj.objc.SEL aSelector) |
JSValue |
invokeMethodWithArguments(java.lang.String method,
NSArray<?> arguments)
Invoke a method on a JSValue.
|
boolean |
isArray()
[@property]
|
boolean |
isBoolean()
[@property]
|
boolean |
isDate()
[@property]
|
boolean |
isEqualToObject(java.lang.Object value)
Compare two JSValues using JavaScript's
=== operator. |
boolean |
isEqualWithTypeCoercionToObject(java.lang.Object value)
Compare two JSValues using JavaScript's
== operator. |
boolean |
isInstanceOf(java.lang.Object value)
Check if a JSValue is an instance of another object.
|
boolean |
isNull()
[@property]
|
boolean |
isNumber()
[@property]
|
boolean |
isObject()
[@property]
|
boolean |
isString()
[@property]
|
static boolean |
isSubclassOfClass(org.moe.natj.objc.Class aClass) |
boolean |
isSymbol()
[@property]
|
boolean |
isUndefined()
[@property]
|
JSValueRef |
JSValueRef()
[@property]
|
static NSSet<java.lang.String> |
keyPathsForValuesAffectingValueForKey(java.lang.String key) |
static JSValue |
new_objc() |
JSValue |
objectAtIndexedSubscript(long index) |
JSValue |
objectForKeyedSubscript(java.lang.Object key) |
static boolean |
resolveClassMethod(org.moe.natj.objc.SEL sel) |
static boolean |
resolveInstanceMethod(org.moe.natj.objc.SEL sel) |
void |
setObjectAtIndexedSubscript(java.lang.Object object,
long index) |
void |
setObjectForKeyedSubscript(java.lang.Object object,
java.lang.Object key) |
void |
setValueAtIndex(java.lang.Object value,
long index)
Set an indexed (numerical) property on a JSValue.
|
void |
setValueForProperty(java.lang.Object value,
java.lang.String property)
Set a property on a JSValue.
|
static void |
setVersion_static(long aVersion) |
static org.moe.natj.objc.Class |
superclass_static() |
NSArray<?> |
toArray()
Convert a JSValue to a NSArray.
|
boolean |
toBool()
Convert a JSValue to a boolean.
|
NSDate |
toDate()
Convert a JSValue to a NSDate.
|
NSDictionary<?,?> |
toDictionary()
Convert a JSValue to a NSDictionary.
|
double |
toDouble()
Convert a JSValue to a double.
|
int |
toInt32()
Convert a JSValue to an
int32_t. |
NSNumber |
toNumber()
Convert a JSValue to a NSNumber.
|
java.lang.Object |
toObject()
[@methodgroup] Converting to Objective-C Types
|
java.lang.Object |
toObjectOfClass(org.moe.natj.objc.Class expectedClass)
Convert a JSValue to an Objective-C object of a specific class.
|
CGPoint |
toPoint()
Convert a JSValue to a CGPoint.
|
NSRange |
toRange()
Convert a JSValue to an NSRange.
|
CGRect |
toRect()
Convert a JSValue to a CGRect.
|
CGSize |
toSize()
Convert a JSValue to a CGSize.
|
java.lang.String |
toString()
Convert a JSValue to a NSString.
|
int |
toUInt32()
Convert a JSValue to a
uint32_t. |
JSValue |
valueAtIndex(long index)
Access an indexed (numerical) property on a JSValue.
|
JSValue |
valueForProperty(java.lang.String property)
Access a property of a JSValue.
|
static JSValue |
valueWithBoolInContext(boolean value,
JSContext context)
Create a JavaScript value from a BOOL primitive.
|
static JSValue |
valueWithDoubleInContext(double value,
JSContext context)
Create a JavaScript value from a double primitive.
|
static JSValue |
valueWithInt32InContext(int value,
JSContext context)
Create a JavaScript value from an
int32_t primitive. |
static JSValue |
valueWithJSValueRefInContext(JSValueRef value,
JSContext context)
Creates a JSValue, wrapping its C API counterpart.
|
static JSValue |
valueWithNewArrayInContext(JSContext context)
Create a new, empty JavaScript array.
|
static JSValue |
valueWithNewErrorFromMessageInContext(java.lang.String message,
JSContext context)
Create a new JavaScript error object.
|
static JSValue |
valueWithNewObjectInContext(JSContext context)
Create a new, empty JavaScript object.
|
static JSValue |
valueWithNewPromiseInContextFromExecutor(JSContext context,
JSValue.Block_valueWithNewPromiseInContextFromExecutor callback)
Create a new promise object using the provided executor callback.
|
static JSValue |
valueWithNewPromiseRejectedWithReasonInContext(java.lang.Object reason,
JSContext context)
Create a new rejected promise object with the provided value.
|
static JSValue |
valueWithNewPromiseResolvedWithResultInContext(java.lang.Object result,
JSContext context)
Create a new resolved promise object with the provided value.
|
static JSValue |
valueWithNewRegularExpressionFromPatternFlagsInContext(java.lang.String pattern,
java.lang.String flags,
JSContext context)
Create a new JavaScript regular expression object.
|
static JSValue |
valueWithNewSymbolFromDescriptionInContext(java.lang.String description,
JSContext context)
Create a new, unique, symbol object.
|
static JSValue |
valueWithNullInContext(JSContext context)
Create the JavaScript value
null. |
static JSValue |
valueWithObjectInContext(java.lang.Object value,
JSContext context)
[@methodgroup] Creating JavaScript Values
|
static JSValue |
valueWithPointInContext(CGPoint point,
JSContext context)
Create a JSValue from a CGPoint.
|
static JSValue |
valueWithRangeInContext(NSRange range,
JSContext context)
Create a JSValue from a NSRange.
|
static JSValue |
valueWithRectInContext(CGRect rect,
JSContext context)
Create a JSValue from a CGRect.
|
static JSValue |
valueWithSizeInContext(CGSize size,
JSContext context)
Create a JSValue from a CGSize.
|
static JSValue |
valueWithUInt32InContext(int value,
JSContext context)
Create a JavaScript value from a
uint32_t primitive. |
static JSValue |
valueWithUndefinedInContext(JSContext context)
Create the JavaScript value
undefined. |
static long |
version_static() |
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, willChangeValuesAtIndexesForKeypublic static boolean accessInstanceVariablesDirectly()
public static JSValue alloc()
public static JSValue allocWithZone(org.moe.natj.general.ptr.VoidPtr zone)
public static boolean automaticallyNotifiesObserversForKey(java.lang.String key)
public static void cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget)
public static void cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument)
public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
public static org.moe.natj.objc.Class classForKeyedUnarchiver()
public static java.lang.String debugDescription_static()
public static java.lang.String description_static()
public static long hash_static()
public static NSObject.Function_instanceMethodForSelector_ret instanceMethodForSelector(org.moe.natj.objc.SEL aSelector)
public static NSMethodSignature instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector)
public static boolean instancesRespondToSelector(org.moe.natj.objc.SEL aSelector)
public static boolean isSubclassOfClass(org.moe.natj.objc.Class aClass)
public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey(java.lang.String key)
public static JSValue new_objc()
public static boolean resolveClassMethod(org.moe.natj.objc.SEL sel)
public static boolean resolveInstanceMethod(org.moe.natj.objc.SEL sel)
public static void setVersion_static(long aVersion)
public static org.moe.natj.objc.Class superclass_static()
public static JSValue valueWithBoolInContext(boolean value, JSContext context)
context - The JSContext in which the resulting JSValue will be created.public static JSValue valueWithDoubleInContext(double value, JSContext context)
context - The JSContext in which the resulting JSValue will be created.public static JSValue valueWithInt32InContext(int value, JSContext context)
int32_t primitive.context - The JSContext in which the resulting JSValue will be created.public static JSValue valueWithJSValueRefInContext(JSValueRef value, JSContext context)
public static JSValue valueWithNewArrayInContext(JSContext context)
context - The JSContext in which the resulting array will be created.public static JSValue valueWithNewErrorFromMessageInContext(java.lang.String message, JSContext context)
message - The error message.context - The JSContext in which the resulting error object will be created.public static JSValue valueWithNewObjectInContext(JSContext context)
context - The JSContext in which the resulting object will be created.public static JSValue valueWithNewRegularExpressionFromPatternFlagsInContext(java.lang.String pattern, java.lang.String flags, JSContext context)
pattern - The regular expression pattern.flags - The regular expression flags.context - The JSContext in which the resulting regular expression object will be created.public static JSValue valueWithNullInContext(JSContext context)
null.context - The JSContext to which the resulting JSValue belongs.null.public static JSValue valueWithObjectInContext(java.lang.Object value, JSContext context)
Create a JSValue by converting an Objective-C object.
The resulting JSValue retains the provided Objective-C object.
value - The Objective-C object to be converted.public static JSValue valueWithPointInContext(CGPoint point, JSContext context)
x and y, with values from the CGPoint.public static JSValue valueWithRangeInContext(NSRange range, JSContext context)
location and length, with values from the NSRange.public static JSValue valueWithRectInContext(CGRect rect, JSContext context)
x, y, width, and height, with values from the CGRect.public static JSValue valueWithSizeInContext(CGSize size, JSContext context)
width and height, with values from the CGSize.public static JSValue valueWithUInt32InContext(int value, JSContext context)
uint32_t primitive.context - The JSContext in which the resulting JSValue will be created.public static JSValue valueWithUndefinedInContext(JSContext context)
undefined.context - The JSContext to which the resulting JSValue belongs.undefined.public static long version_static()
public JSValueRef JSValueRef()
Returns the C API counterpart wrapped by a JSContext.
public JSValue callWithArguments(NSArray<?> arguments)
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.
arguments - The arguments to pass to the function.public JSValue constructWithArguments(NSArray<?> arguments)
This is equivalent to using the new syntax in JavaScript.
arguments - The arguments to pass to the constructor.public JSContext context()
The JSContext that this value originates from.
public void definePropertyDescriptor(java.lang.String property,
java.lang.Object descriptor)
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 *.
public boolean deleteProperty(java.lang.String property)
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 *.
public boolean hasProperty(java.lang.String property)
This method has the same function as the JavaScript operator in.
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 *.
public JSValue invokeMethodWithArguments(java.lang.String method, NSArray<?> arguments)
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.
method - The name of the method to be invoked.arguments - The arguments to pass to the method.public boolean isArray()
Check if a JSValue is an array.
public boolean isBoolean()
Check if a JSValue is a boolean.
public boolean isDate()
Check if a JSValue is a date.
public boolean isEqualToObject(java.lang.Object value)
=== operator.public boolean isEqualWithTypeCoercionToObject(java.lang.Object value)
== operator.public boolean isInstanceOf(java.lang.Object value)
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.
public boolean isNull()
Check if a JSValue corresponds to the JavaScript value null.
public boolean isNumber()
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.
public boolean isObject()
Check if a JSValue is an object.
public boolean isString()
Check if a JSValue is a string.
public boolean isUndefined()
Check if a JSValue corresponds to the JavaScript value undefined.
public JSValue objectAtIndexedSubscript(long index)
public JSValue objectForKeyedSubscript(java.lang.Object key)
public void setObjectAtIndexedSubscript(java.lang.Object object,
long index)
public void setObjectForKeyedSubscript(java.lang.Object object,
java.lang.Object key)
public void setValueAtIndex(java.lang.Object value,
long index)
For JSValues that are JavaScript arrays, indices greater than UINT_MAX - 1 will not affect the length of the array.
public void setValueForProperty(java.lang.Object value,
java.lang.String property)
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 *.
public NSArray<?> toArray()
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 indicies within the array bounds will be copied to the array, with
JSValues converted to equivalent Objective-C objects as specified.
public boolean toBool()
The JSValue is converted to a boolean according to the rules specified by the JavaScript language.
public NSDate toDate()
The value is converted to a number representing a time interval since 1970 which is then used to create a new NSDate instance.
public NSDictionary<?,?> toDictionary()
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.
public double toDouble()
The JSValue is converted to a number according to the rules specified by the JavaScript language.
public int toInt32()
int32_t.
The JSValue is converted to an integer according to the rules specified by the JavaScript language.
int32_t result of the conversion.public NSNumber toNumber()
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.
public java.lang.Object toObject()
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.
public java.lang.Object toObjectOfClass(org.moe.natj.objc.Class expectedClass)
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.
nil.public CGPoint toPoint()
Reads the properties named x and y from
this JSValue, and converts the results to double.
public NSRange toRange()
Reads the properties named location and
length from this JSValue and converts the results to double.
public CGRect toRect()
Reads the properties named x, y,
width, and height from this JSValue and converts the results to double.
public CGSize toSize()
Reads the properties named width and
height from this JSValue and converts the results to double.
public java.lang.String toString()
The JSValue is converted to a string according to the rules specified by the JavaScript language.
toString in class org.moe.natj.objc.ObjCObjectpublic int toUInt32()
uint32_t.
The JSValue is converted to an integer according to the rules specified by the JavaScript language.
uint32_t result of the conversion.public JSValue valueAtIndex(long index)
undefined if no property exists at that index.public JSValue valueForProperty(java.lang.String property)
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 *.
undefined
if the property does not exist.public boolean isSymbol()
Check if a JSValue is a symbol.
public static JSValue valueWithNewPromiseInContextFromExecutor(JSContext context, JSValue.Block_valueWithNewPromiseInContextFromExecutor 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 be nil. This also means means the new promise object may be accessed via [context thisValue].
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.public static JSValue valueWithNewPromiseRejectedWithReasonInContext(java.lang.Object reason, JSContext context)
This method is equivalent to calling [JSValue valueWithNewPromiseFromExecutor:^(JSValue *resolve, JSValue *reject) { [reject callWithArguments:@[reason]]; } inContext:context]
reason - The result value to be passed to any reactions.context - The JSContext to which the resulting JSValue belongs.public static JSValue valueWithNewPromiseResolvedWithResultInContext(java.lang.Object result, JSContext context)
This method is equivalent to calling [JSValue valueWithNewPromiseFromExecutor:^(JSValue *resolve, JSValue *reject) { [resolve callWithArguments:@[result]]; } inContext:context]
result - The result value to be passed to any reactions.context - The JSContext to which the resulting JSValue belongs.public static JSValue valueWithNewSymbolFromDescriptionInContext(java.lang.String description, JSContext context)
description - The description of the symbol object being created.context - The JSContext to which the resulting JSValue belongs.