Documentation
¶
Overview ¶
Package javascriptcore provides Go bindings for the JavaScriptCore framework.
Evaluate JavaScript programs from within an app, and support JavaScript scripting of your app.
The JavaScriptCore framework provides the ability to evaluate JavaScript programs from within Swift, Objective-C, and C-based apps. You can use also use JavaScriptCore to insert custom objects into the JavaScript environment.
Execution Environment ¶
- JSVirtualMachine: A self-contained environment for JavaScript execution.
- JSContext: A JavaScript execution environment.
JavaScript Code ¶
- JSValue: A JavaScript value. (JSValueProperty)
- JSManagedValue: A JavaScript value with conditional retain behavior to provide automatic memory management.
Native Code ¶
- JSExport: The protocol for exporting Objective-C objects to JavaScript.
C API ¶
- C JavaScriptCore API: Browse the alternative C-based APIs for JavaScriptCore. (JSContextGroupRef, JSContextRef, JSGlobalContextRef, JSStringRef, JSClassRef)
Functions ¶
- JSBigIntCreateWithDouble
- JSBigIntCreateWithInt64
- JSBigIntCreateWithString
- JSBigIntCreateWithUInt64
- JSValueCompare
- JSValueCompareDouble
- JSValueCompareInt64
- JSValueCompareUInt64
- JSValueIsBigInt
- JSValueToInt32
- JSValueToInt64
- JSValueToUInt32
- JSValueToUInt64
Macros ¶
- JSC_ASSUME_NONNULL_BEGIN
- JSC_ASSUME_NONNULL_END
- JSC_CF_ENUM
- JSC_NONNULL
- JSC_NULLABLE
- JSC_NULL_UNSPECIFIED
Enumerations ¶
Key Types ¶
- JSValue - A JavaScript value.
- JSContext - A JavaScript execution environment.
- JSManagedValue - A JavaScript value with conditional retain behavior to provide automatic memory management.
- JSVirtualMachine - A self-contained environment for JavaScript execution.
Code generated from Apple documentation. DO NOT EDIT.
Index ¶
- Variables
- func JSCheckScriptSyntax(ctx JSContextRef, script JSStringRef, sourceURL JSStringRef, ...) bool
- func JSClassRelease(jsClass JSClassRef)
- func JSContextGroupRelease(group JSContextGroupRef)
- func JSGarbageCollect(ctx JSContextRef)
- func JSGlobalContextIsInspectable(ctx JSGlobalContextRef) bool
- func JSGlobalContextRelease(ctx JSGlobalContextRef)
- func JSGlobalContextSetInspectable(ctx JSGlobalContextRef, inspectable bool)
- func JSGlobalContextSetName(ctx JSGlobalContextRef, name JSStringRef)
- func JSObjectDeleteProperty(ctx JSContextRef, object JSObjectRef, propertyName JSStringRef, ...) bool
- func JSObjectDeletePropertyForKey(ctx JSContextRef, object JSObjectRef, propertyKey JSValueRef, ...) bool
- func JSObjectGetArrayBufferByteLength(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) uintptr
- func JSObjectGetArrayBufferBytesPtr(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) unsafe.Pointer
- func JSObjectGetPrivate(object JSObjectRef) unsafe.Pointer
- func JSObjectGetTypedArrayByteLength(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) uintptr
- func JSObjectGetTypedArrayByteOffset(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) uintptr
- func JSObjectGetTypedArrayBytesPtr(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) unsafe.Pointer
- func JSObjectGetTypedArrayLength(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) uintptr
- func JSObjectHasProperty(ctx JSContextRef, object JSObjectRef, propertyName JSStringRef) bool
- func JSObjectHasPropertyForKey(ctx JSContextRef, object JSObjectRef, propertyKey JSValueRef, ...) bool
- func JSObjectIsConstructor(ctx JSContextRef, object JSObjectRef) bool
- func JSObjectIsFunction(ctx JSContextRef, object JSObjectRef) bool
- func JSObjectSetPrivate(object JSObjectRef, data unsafe.Pointer) bool
- func JSObjectSetProperty(ctx JSContextRef, object JSObjectRef, propertyName JSStringRef, ...)
- func JSObjectSetPropertyAtIndex(ctx JSContextRef, object JSObjectRef, propertyIndex uint, value JSValueRef, ...)
- func JSObjectSetPropertyForKey(ctx JSContextRef, object JSObjectRef, propertyKey JSValueRef, value JSValueRef, ...)
- func JSObjectSetPrototype(ctx JSContextRef, object JSObjectRef, value JSValueRef)
- func JSPropertyNameAccumulatorAddName(accumulator JSPropertyNameAccumulatorRef, propertyName JSStringRef)
- func JSPropertyNameArrayGetCount(array JSPropertyNameArrayRef) uintptr
- func JSPropertyNameArrayRelease(array JSPropertyNameArrayRef)
- func JSStringCopyCFString(alloc corefoundation.CFAllocatorRef, string_ JSStringRef) corefoundation.CFStringRef
- func JSStringGetLength(string_ JSStringRef) uintptr
- func JSStringGetMaximumUTF8CStringSize(string_ JSStringRef) uintptr
- func JSStringGetUTF8CString(string_ JSStringRef, buffer *byte, bufferSize uintptr) uintptr
- func JSStringIsEqual(a JSStringRef, b JSStringRef) bool
- func JSStringIsEqualToUTF8CString(a JSStringRef, b string) bool
- func JSStringRelease(string_ JSStringRef)
- func JSValueIsArray(ctx JSContextRef, value JSValueRef) bool
- func JSValueIsBigInt(ctx JSContextRef, value JSValueRef) bool
- func JSValueIsBoolean(ctx JSContextRef, value JSValueRef) bool
- func JSValueIsDate(ctx JSContextRef, value JSValueRef) bool
- func JSValueIsEqual(ctx JSContextRef, a JSValueRef, b JSValueRef, exception *JSValueRef) bool
- func JSValueIsInstanceOfConstructor(ctx JSContextRef, value JSValueRef, constructor JSObjectRef, ...) bool
- func JSValueIsNull(ctx JSContextRef, value JSValueRef) bool
- func JSValueIsNumber(ctx JSContextRef, value JSValueRef) bool
- func JSValueIsObject(ctx JSContextRef, value JSValueRef) bool
- func JSValueIsObjectOfClass(ctx JSContextRef, value JSValueRef, jsClass JSClassRef) bool
- func JSValueIsStrictEqual(ctx JSContextRef, a JSValueRef, b JSValueRef) bool
- func JSValueIsString(ctx JSContextRef, value JSValueRef) bool
- func JSValueIsSymbol(ctx JSContextRef, value JSValueRef) bool
- func JSValueIsUndefined(ctx JSContextRef, value JSValueRef) bool
- func JSValueProtect(ctx JSContextRef, value JSValueRef)
- func JSValueToBoolean(ctx JSContextRef, value JSValueRef) bool
- func JSValueToInt32(ctx JSContextRef, value JSValueRef, exception *JSValueRef) int32
- func JSValueToInt64(ctx JSContextRef, value JSValueRef, exception *JSValueRef) int64
- func JSValueToNumber(ctx JSContextRef, value JSValueRef, exception *JSValueRef) float64
- func JSValueToUInt32(ctx JSContextRef, value JSValueRef, exception *JSValueRef) uint32
- func JSValueToUInt64(ctx JSContextRef, value JSValueRef, exception *JSValueRef) uint64
- func JSValueUnprotect(ctx JSContextRef, value JSValueRef)
- func NewJSContextJSValueBlock(handler JSContextJSValueHandler) (objc.ID, func())
- func NewJSValueJSValueBlock(handler JSValueJSValueHandler) (objc.ID, func())
- type IJSContext
- type IJSManagedValue
- type IJSValue
- type IJSVirtualMachine
- type JSChar
- type JSClassAttributes
- type JSClassDefinition
- type JSClassRef
- type JSContext
- func (j JSContext) Autorelease() JSContext
- func (j JSContext) EvaluateScript(script string) IJSValue
- func (j JSContext) EvaluateScriptWithSourceURL(script string, sourceURL foundation.NSURL) IJSValue
- func (j JSContext) Exception() IJSValue
- func (j JSContext) ExceptionHandler() JSContextJSValueHandler
- func (j JSContext) GlobalObject() IJSValue
- func (j JSContext) Init() JSContext
- func (j JSContext) InitWithVirtualMachine(virtualMachine IJSVirtualMachine) JSContext
- func (j JSContext) IsInspectable() bool
- func (j JSContext) JSGlobalContextRef() JSGlobalContextRef
- func (j JSContext) Name() string
- func (j JSContext) ObjectForKeyedSubscript(key objectivec.IObject) IJSValue
- func (j JSContext) SetException(value IJSValue)
- func (j JSContext) SetExceptionHandler(value JSContextJSValueHandler)
- func (j JSContext) SetInspectable(value bool)
- func (j JSContext) SetName(value string)
- func (j JSContext) SetObjectForKeyedSubscript(object objectivec.IObject, key objectivec.NSObject)
- func (j JSContext) VirtualMachine() IJSVirtualMachine
- type JSContextClass
- func (jc JSContextClass) Alloc() JSContext
- func (jc JSContextClass) Class() objc.Class
- func (_JSContextClass JSContextClass) CurrentArguments() foundation.INSArray
- func (_JSContextClass JSContextClass) CurrentCallee() JSValue
- func (_JSContextClass JSContextClass) CurrentContext() JSContext
- func (_JSContextClass JSContextClass) CurrentThis() JSValue
- type JSContextGroupRef
- type JSContextJSValueHandler
- type JSContextRef
- type JSExport
- type JSExportObject
- type JSGlobalContextRef
- func JSContextGetGlobalContext(ctx JSContextRef) JSGlobalContextRef
- func JSGlobalContextCreate(globalObjectClass JSClassRef) JSGlobalContextRef
- func JSGlobalContextCreateInGroup(group JSContextGroupRef, globalObjectClass JSClassRef) JSGlobalContextRef
- func JSGlobalContextRetain(ctx JSGlobalContextRef) JSGlobalContextRef
- type JSManagedValue
- type JSManagedValueClass
- type JSObjectCallAsConstructorCallback
- type JSObjectCallAsFunctionCallback
- type JSObjectConvertToTypeCallback
- type JSObjectDeletePropertyCallback
- type JSObjectFinalizeCallback
- type JSObjectGetPropertyCallback
- type JSObjectGetPropertyNamesCallback
- type JSObjectHasInstanceCallback
- type JSObjectHasPropertyCallback
- type JSObjectInitializeCallback
- type JSObjectRef
- func JSContextGetGlobalObject(ctx JSContextRef) JSObjectRef
- func JSObjectCallAsConstructor(ctx JSContextRef, object JSObjectRef, argumentCount uintptr, ...) JSObjectRef
- func JSObjectGetTypedArrayBuffer(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) JSObjectRef
- func JSObjectMake(ctx JSContextRef, jsClass JSClassRef, data unsafe.Pointer) JSObjectRef
- func JSObjectMakeArray(ctx JSContextRef, argumentCount uintptr, arguments JSValueRef, ...) JSObjectRef
- func JSObjectMakeArrayBufferWithBytesNoCopy(ctx JSContextRef, bytes unsafe.Pointer, byteLength uintptr, ...) JSObjectRef
- func JSObjectMakeConstructor(ctx JSContextRef, jsClass JSClassRef, ...) JSObjectRef
- func JSObjectMakeDate(ctx JSContextRef, argumentCount uintptr, arguments JSValueRef, ...) JSObjectRef
- func JSObjectMakeDeferredPromise(ctx JSContextRef, resolve *JSObjectRef, reject *JSObjectRef, ...) JSObjectRef
- func JSObjectMakeError(ctx JSContextRef, argumentCount uintptr, arguments JSValueRef, ...) JSObjectRef
- func JSObjectMakeFunction(ctx JSContextRef, name JSStringRef, parameterCount uint, ...) JSObjectRef
- func JSObjectMakeFunctionWithCallback(ctx JSContextRef, name JSStringRef, ...) JSObjectRef
- func JSObjectMakeRegExp(ctx JSContextRef, argumentCount uintptr, arguments JSValueRef, ...) JSObjectRef
- func JSObjectMakeTypedArray(ctx JSContextRef, arrayType JSTypedArrayType, length uintptr, ...) JSObjectRef
- func JSObjectMakeTypedArrayWithArrayBuffer(ctx JSContextRef, arrayType JSTypedArrayType, buffer JSObjectRef, ...) JSObjectRef
- func JSObjectMakeTypedArrayWithArrayBufferAndOffset(ctx JSContextRef, arrayType JSTypedArrayType, buffer JSObjectRef, ...) JSObjectRef
- func JSObjectMakeTypedArrayWithBytesNoCopy(ctx JSContextRef, arrayType JSTypedArrayType, bytes unsafe.Pointer, ...) JSObjectRef
- func JSValueToObject(ctx JSContextRef, value JSValueRef, exception *JSValueRef) JSObjectRef
- type JSObjectSetPropertyCallback
- type JSPropertyAttributes
- type JSPropertyNameAccumulatorRef
- type JSPropertyNameArrayRef
- type JSRelationCondition
- func JSValueCompare(ctx JSContextRef, left JSValueRef, right JSValueRef, exception *JSValueRef) JSRelationCondition
- func JSValueCompareDouble(ctx JSContextRef, left JSValueRef, right float64, exception *JSValueRef) JSRelationCondition
- func JSValueCompareInt64(ctx JSContextRef, left JSValueRef, right int64, exception *JSValueRef) JSRelationCondition
- func JSValueCompareUInt64(ctx JSContextRef, left JSValueRef, right uint64, exception *JSValueRef) JSRelationCondition
- type JSStaticFunction
- type JSStaticValue
- type JSStringRef
- func JSGlobalContextCopyName(ctx JSGlobalContextRef) JSStringRef
- func JSPropertyNameArrayGetNameAtIndex(array JSPropertyNameArrayRef, index uintptr) JSStringRef
- func JSStringCreateWithCFString(string_ corefoundation.CFStringRef) JSStringRef
- func JSStringCreateWithCharacters(chars *JSChar, numChars uintptr) JSStringRef
- func JSStringCreateWithUTF8CString(string_ string) JSStringRef
- func JSStringRetain(string_ JSStringRef) JSStringRef
- func JSValueCreateJSONString(ctx JSContextRef, value JSValueRef, indent uint, exception *JSValueRef) JSStringRef
- func JSValueToStringCopy(ctx JSContextRef, value JSValueRef, exception *JSValueRef) JSStringRef
- type JSType
- type JSTypedArrayBytesDeallocator
- type JSTypedArrayType
- type JSValue
- func JSValueFromID(id objc.ID) JSValue
- func NewJSValue() JSValue
- func NewJSValueWithBoolInContext(value bool, context IJSContext) JSValue
- func NewJSValueWithDoubleInContext(value float64, context IJSContext) JSValue
- func NewJSValueWithInt32InContext(value int32, context IJSContext) JSValue
- func NewJSValueWithJSValueRefInContext(value JSValueRef, context IJSContext) JSValue
- func NewJSValueWithNewArrayInContext(context IJSContext) JSValue
- func NewJSValueWithNewBigIntFromDoubleInContext(value float64, context IJSContext) JSValue
- func NewJSValueWithNewBigIntFromInt64InContext(int64_ int64, context IJSContext) JSValue
- func NewJSValueWithNewBigIntFromStringInContext(string_ string, context IJSContext) JSValue
- func NewJSValueWithNewBigIntFromUInt64InContext(uint64_ uint64, context IJSContext) JSValue
- func NewJSValueWithNewErrorFromMessageInContext(message string, context IJSContext) JSValue
- func NewJSValueWithNewObjectInContext(context IJSContext) JSValue
- func NewJSValueWithNewPromiseRejectedWithReasonInContext(reason objectivec.IObject, context IJSContext) JSValue
- func NewJSValueWithNewPromiseResolvedWithResultInContext(result objectivec.IObject, context IJSContext) JSValue
- func NewJSValueWithNewRegularExpressionFromPatternFlagsInContext(pattern string, flags string, context IJSContext) JSValue
- func NewJSValueWithNewSymbolFromDescriptionInContext(description string, context IJSContext) JSValue
- func NewJSValueWithNullInContext(context IJSContext) JSValue
- func NewJSValueWithObjectInContext(value objectivec.IObject, context IJSContext) JSValue
- func NewJSValueWithPointInContext(point corefoundation.CGPoint, context IJSContext) JSValue
- func NewJSValueWithRangeInContext(range_ foundation.NSRange, context IJSContext) JSValue
- func NewJSValueWithRectInContext(rect corefoundation.CGRect, context IJSContext) JSValue
- func NewJSValueWithSizeInContext(size corefoundation.CGSize, context IJSContext) JSValue
- func NewJSValueWithUInt32InContext(value uint32, context IJSContext) JSValue
- func NewJSValueWithUndefinedInContext(context IJSContext) JSValue
- func (j JSValue) Autorelease() JSValue
- func (j JSValue) CallWithArguments(arguments foundation.INSArray) IJSValue
- func (j JSValue) CompareDouble(other float64) JSRelationCondition
- func (j JSValue) CompareInt64(other int64) JSRelationCondition
- func (j JSValue) CompareJSValue(other IJSValue) JSRelationCondition
- func (j JSValue) CompareUInt64(other uint64) JSRelationCondition
- func (j JSValue) ConstructWithArguments(arguments foundation.INSArray) IJSValue
- func (j JSValue) Context() IJSContext
- func (j JSValue) DefinePropertyDescriptor(property JSValueProperty, descriptor objectivec.IObject)
- func (j JSValue) DeleteProperty(property JSValueProperty) bool
- func (j JSValue) HasProperty(property JSValueProperty) bool
- func (j JSValue) Init() JSValue
- func (j JSValue) InvokeMethodWithArguments(method string, arguments foundation.INSArray) IJSValue
- func (j JSValue) IsArray() bool
- func (j JSValue) IsBigInt() bool
- func (j JSValue) IsBoolean() bool
- func (j JSValue) IsDate() bool
- func (j JSValue) IsEqualToObject(value objectivec.IObject) bool
- func (j JSValue) IsEqualWithTypeCoercionToObject(value objectivec.IObject) bool
- func (j JSValue) IsInstanceOf(value objectivec.IObject) bool
- func (j JSValue) IsNull() bool
- func (j JSValue) IsNumber() bool
- func (j JSValue) IsObject() bool
- func (j JSValue) IsString() bool
- func (j JSValue) IsSymbol() bool
- func (j JSValue) IsUndefined() bool
- func (j JSValue) JSValueRef() JSValueRef
- func (j JSValue) ObjectAtIndexedSubscript(index uint) IJSValue
- func (j JSValue) ObjectForKeyedSubscript(key objectivec.IObject) IJSValue
- func (j JSValue) SetObjectAtIndexedSubscript(object objectivec.IObject, index uint)
- func (j JSValue) SetObjectForKeyedSubscript(object objectivec.IObject, key objectivec.IObject)
- func (j JSValue) SetValueAtIndex(value objectivec.IObject, index uint)
- func (j JSValue) SetValueForProperty(value objectivec.IObject, property JSValueProperty)
- func (j JSValue) ToArray() foundation.INSArray
- func (j JSValue) ToBool() bool
- func (j JSValue) ToDate() foundation.NSDate
- func (j JSValue) ToDictionary() foundation.INSDictionary
- func (j JSValue) ToDouble() float64
- func (j JSValue) ToInt32() int32
- func (j JSValue) ToInt64() int64
- func (j JSValue) ToNumber() foundation.NSNumber
- func (j JSValue) ToObject() objectivec.IObject
- func (j JSValue) ToObjectOfClass(expectedClass objectivec.Class) objectivec.IObject
- func (j JSValue) ToPoint() corefoundation.CGPoint
- func (j JSValue) ToRange() foundation.NSRange
- func (j JSValue) ToRect() corefoundation.CGRect
- func (j JSValue) ToSize() corefoundation.CGSize
- func (j JSValue) ToString() string
- func (j JSValue) ToUInt32() uint32
- func (j JSValue) ToUInt64() uint64
- func (j JSValue) ValueAtIndex(index uint) IJSValue
- func (j JSValue) ValueForProperty(property JSValueProperty) IJSValue
- type JSValueClass
- type JSValueJSValueHandler
- type JSValueProperty
- type JSValueRef
- func JSBigIntCreateWithDouble(ctx JSContextRef, value float64, exception *JSValueRef) JSValueRef
- func JSBigIntCreateWithInt64(ctx JSContextRef, integer int64, exception *JSValueRef) JSValueRef
- func JSBigIntCreateWithString(ctx JSContextRef, string_ JSStringRef, exception *JSValueRef) JSValueRef
- func JSBigIntCreateWithUInt64(ctx JSContextRef, integer uint64, exception *JSValueRef) JSValueRef
- func JSEvaluateScript(ctx JSContextRef, script JSStringRef, thisObject JSObjectRef, ...) JSValueRef
- func JSObjectCallAsFunction(ctx JSContextRef, object JSObjectRef, thisObject JSObjectRef, ...) JSValueRef
- func JSObjectGetProperty(ctx JSContextRef, object JSObjectRef, propertyName JSStringRef, ...) JSValueRef
- func JSObjectGetPropertyAtIndex(ctx JSContextRef, object JSObjectRef, propertyIndex uint, ...) JSValueRef
- func JSObjectGetPropertyForKey(ctx JSContextRef, object JSObjectRef, propertyKey JSValueRef, ...) JSValueRef
- func JSObjectGetPrototype(ctx JSContextRef, object JSObjectRef) JSValueRef
- func JSValueMakeBoolean(ctx JSContextRef, boolean bool) JSValueRef
- func JSValueMakeFromJSONString(ctx JSContextRef, string_ JSStringRef) JSValueRef
- func JSValueMakeNull(ctx JSContextRef) JSValueRef
- func JSValueMakeNumber(ctx JSContextRef, number float64) JSValueRef
- func JSValueMakeString(ctx JSContextRef, string_ JSStringRef) JSValueRef
- func JSValueMakeSymbol(ctx JSContextRef, description JSStringRef) JSValueRef
- func JSValueMakeUndefined(ctx JSContextRef) JSValueRef
- type JSVirtualMachine
- func (j JSVirtualMachine) AddManagedReferenceWithOwner(object objectivec.IObject, owner objectivec.IObject)
- func (j JSVirtualMachine) Autorelease() JSVirtualMachine
- func (j JSVirtualMachine) Init() JSVirtualMachine
- func (j JSVirtualMachine) RemoveManagedReferenceWithOwner(object objectivec.IObject, owner objectivec.IObject)
- type JSVirtualMachineClass
- type KJSClassAttribute
- type KJSPropertyAttribute
- type KJSType
- type KJSTypedArrayType
Constants ¶
This section is empty.
Variables ¶
var ( // JSPropertyDescriptorConfigurableKey is the Boolean value for this key determines whether the property deleted from its JavaScript object or its descriptor changed. // // See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyDescriptorConfigurableKey JSPropertyDescriptorConfigurableKey string // JSPropertyDescriptorEnumerableKey is the Boolean value for this key determines whether the property appears when enumerating the JavaScript object’s properties. // // See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyDescriptorEnumerableKey JSPropertyDescriptorEnumerableKey string // JSPropertyDescriptorGetKey is the JavaScript function to be invoked when reading the property. // // See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyDescriptorGetKey JSPropertyDescriptorGetKey string // JSPropertyDescriptorSetKey is the JavaScript function to be invoked when writing to the property. // // See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyDescriptorSetKey JSPropertyDescriptorSetKey string // JSPropertyDescriptorValueKey is the value for the property on the JavaScript object. // // See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyDescriptorValueKey JSPropertyDescriptorValueKey string // JSPropertyDescriptorWritableKey is the Boolean value for this key determines whether the property permits assignment with the JavaScript `=` operator. // // See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyDescriptorWritableKey JSPropertyDescriptorWritableKey string )
Functions ¶
func JSCheckScriptSyntax ¶
func JSCheckScriptSyntax(ctx JSContextRef, script JSStringRef, sourceURL JSStringRef, startingLineNumber int, exception *JSValueRef) bool
JSCheckScriptSyntax checks for syntax errors in a string of JavaScript.
See: https://developer.apple.com/documentation/JavaScriptCore/JSCheckScriptSyntax(_:_:_:_:_:)
func JSClassRelease ¶
func JSClassRelease(jsClass JSClassRef)
JSClassRelease releases a JavaScript class.
See: https://developer.apple.com/documentation/JavaScriptCore/JSClassRelease(_:)
func JSContextGroupRelease ¶
func JSContextGroupRelease(group JSContextGroupRef)
JSContextGroupRelease releases a JavaScript context group.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContextGroupRelease(_:)
func JSGarbageCollect ¶
func JSGarbageCollect(ctx JSContextRef)
JSGarbageCollect performs a JavaScript garbage collection.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGarbageCollect(_:)
func JSGlobalContextIsInspectable ¶
func JSGlobalContextIsInspectable(ctx JSGlobalContextRef) bool
JSGlobalContextIsInspectable returns a Boolean value that indicates whether the JavaScript context is inspectable.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGlobalContextIsInspectable(_:)
func JSGlobalContextRelease ¶
func JSGlobalContextRelease(ctx JSGlobalContextRef)
JSGlobalContextRelease releases a global JavaScript execution context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGlobalContextRelease(_:)
func JSGlobalContextSetInspectable ¶
func JSGlobalContextSetInspectable(ctx JSGlobalContextRef, inspectable bool)
JSGlobalContextSetInspectable sets a JavaScript context to be either inspectable or not inspectable.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGlobalContextSetInspectable(_:_:)
func JSGlobalContextSetName ¶
func JSGlobalContextSetName(ctx JSGlobalContextRef, name JSStringRef)
JSGlobalContextSetName sets the remote debugging name for a context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGlobalContextSetName(_:_:)
func JSObjectDeleteProperty ¶
func JSObjectDeleteProperty(ctx JSContextRef, object JSObjectRef, propertyName JSStringRef, exception *JSValueRef) bool
JSObjectDeleteProperty deletes a property from an object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectDeleteProperty(_:_:_:_:)
func JSObjectDeletePropertyForKey ¶
func JSObjectDeletePropertyForKey(ctx JSContextRef, object JSObjectRef, propertyKey JSValueRef, exception *JSValueRef) bool
JSObjectDeletePropertyForKey deletes a property from an object using a JavaScript value as the property key.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectDeletePropertyForKey(_:_:_:_:)
func JSObjectGetArrayBufferByteLength ¶
func JSObjectGetArrayBufferByteLength(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) uintptr
JSObjectGetArrayBufferByteLength returns the number of bytes in a JavaScript data object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetArrayBufferByteLength(_:_:_:)
func JSObjectGetArrayBufferBytesPtr ¶
func JSObjectGetArrayBufferBytesPtr(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) unsafe.Pointer
JSObjectGetArrayBufferBytesPtr returns a pointer to the data buffer that serves as the backing store for a JavaScript typed array object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetArrayBufferBytesPtr(_:_:_:)
func JSObjectGetPrivate ¶
func JSObjectGetPrivate(object JSObjectRef) unsafe.Pointer
JSObjectGetPrivate gets an object’s private data.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetPrivate(_:)
func JSObjectGetTypedArrayByteLength ¶
func JSObjectGetTypedArrayByteLength(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) uintptr
JSObjectGetTypedArrayByteLength returns the byte length of a JavaScript typed array object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetTypedArrayByteLength(_:_:_:)
func JSObjectGetTypedArrayByteOffset ¶
func JSObjectGetTypedArrayByteOffset(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) uintptr
JSObjectGetTypedArrayByteOffset returns the byte offset of a JavaScript typed array object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetTypedArrayByteOffset(_:_:_:)
func JSObjectGetTypedArrayBytesPtr ¶
func JSObjectGetTypedArrayBytesPtr(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) unsafe.Pointer
JSObjectGetTypedArrayBytesPtr returns a temporary pointer to the backing store of a JavaScript typed array object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetTypedArrayBytesPtr(_:_:_:)
func JSObjectGetTypedArrayLength ¶
func JSObjectGetTypedArrayLength(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) uintptr
JSObjectGetTypedArrayLength returns the length of a JavaScript typed array object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetTypedArrayLength(_:_:_:)
func JSObjectHasProperty ¶
func JSObjectHasProperty(ctx JSContextRef, object JSObjectRef, propertyName JSStringRef) bool
JSObjectHasProperty tests whether an object has a specified property.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectHasProperty(_:_:_:)
func JSObjectHasPropertyForKey ¶
func JSObjectHasPropertyForKey(ctx JSContextRef, object JSObjectRef, propertyKey JSValueRef, exception *JSValueRef) bool
JSObjectHasPropertyForKey tests whether an object has the specified property using a JavaScript value as the property key.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectHasPropertyForKey(_:_:_:_:)
func JSObjectIsConstructor ¶
func JSObjectIsConstructor(ctx JSContextRef, object JSObjectRef) bool
JSObjectIsConstructor tests whether you can call an object as a constructor.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectIsConstructor(_:_:)
func JSObjectIsFunction ¶
func JSObjectIsFunction(ctx JSContextRef, object JSObjectRef) bool
JSObjectIsFunction tests whether you can call an object as a function.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectIsFunction(_:_:)
func JSObjectSetPrivate ¶
func JSObjectSetPrivate(object JSObjectRef, data unsafe.Pointer) bool
JSObjectSetPrivate sets a pointer to private data on an object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectSetPrivate(_:_:)
func JSObjectSetProperty ¶
func JSObjectSetProperty(ctx JSContextRef, object JSObjectRef, propertyName JSStringRef, value JSValueRef, attributes JSPropertyAttributes, exception *JSValueRef)
JSObjectSetProperty sets a property on an object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectSetProperty(_:_:_:_:_:_:)
func JSObjectSetPropertyAtIndex ¶
func JSObjectSetPropertyAtIndex(ctx JSContextRef, object JSObjectRef, propertyIndex uint, value JSValueRef, exception *JSValueRef)
JSObjectSetPropertyAtIndex sets a property on an object by numeric index.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectSetPropertyAtIndex(_:_:_:_:_:)
func JSObjectSetPropertyForKey ¶
func JSObjectSetPropertyForKey(ctx JSContextRef, object JSObjectRef, propertyKey JSValueRef, value JSValueRef, attributes JSPropertyAttributes, exception *JSValueRef)
JSObjectSetPropertyForKey sets a property on an object using a JavaScript value as the property key.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectSetPropertyForKey(_:_:_:_:_:_:)
func JSObjectSetPrototype ¶
func JSObjectSetPrototype(ctx JSContextRef, object JSObjectRef, value JSValueRef)
JSObjectSetPrototype sets an object’s prototype.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectSetPrototype(_:_:_:)
func JSPropertyNameAccumulatorAddName ¶
func JSPropertyNameAccumulatorAddName(accumulator JSPropertyNameAccumulatorRef, propertyName JSStringRef)
JSPropertyNameAccumulatorAddName adds a property name to a JavaScript property name accumulator.
See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyNameAccumulatorAddName(_:_:)
func JSPropertyNameArrayGetCount ¶
func JSPropertyNameArrayGetCount(array JSPropertyNameArrayRef) uintptr
JSPropertyNameArrayGetCount gets a count of the number of items in a JavaScript property name array.
See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyNameArrayGetCount(_:)
func JSPropertyNameArrayRelease ¶
func JSPropertyNameArrayRelease(array JSPropertyNameArrayRef)
JSPropertyNameArrayRelease releases a JavaScript property name array.
See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyNameArrayRelease(_:)
func JSStringCopyCFString ¶
func JSStringCopyCFString(alloc corefoundation.CFAllocatorRef, string_ JSStringRef) corefoundation.CFStringRef
JSStringCopyCFString creates a Core Foundation string from a JavaScript string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringCopyCFString(_:_:)
func JSStringGetLength ¶
func JSStringGetLength(string_ JSStringRef) uintptr
JSStringGetLength returns the number of Unicode characters in a JavaScript string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringGetLength(_:)
func JSStringGetMaximumUTF8CStringSize ¶
func JSStringGetMaximumUTF8CStringSize(string_ JSStringRef) uintptr
JSStringGetMaximumUTF8CStringSize returns the maximum number of bytes a JavaScript string uses when you convert it into a null-terminated UTF-8 string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringGetMaximumUTF8CStringSize(_:)
func JSStringGetUTF8CString ¶
func JSStringGetUTF8CString(string_ JSStringRef, buffer *byte, bufferSize uintptr) uintptr
JSStringGetUTF8CString converts a JavaScript string into a null-terminated UTF-8 string, and copies the result into an external byte buffer.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringGetUTF8CString(_:_:_:)
func JSStringIsEqual ¶
func JSStringIsEqual(a JSStringRef, b JSStringRef) bool
JSStringIsEqual tests whether two JavaScript strings match.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringIsEqual(_:_:)
func JSStringIsEqualToUTF8CString ¶
func JSStringIsEqualToUTF8CString(a JSStringRef, b string) bool
JSStringIsEqualToUTF8CString tests whether a JavaScript string matches a null-terminated UTF-8 string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringIsEqualToUTF8CString(_:_:)
func JSStringRelease ¶
func JSStringRelease(string_ JSStringRef)
JSStringRelease releases a JavaScript string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringRelease(_:)
func JSValueIsArray ¶
func JSValueIsArray(ctx JSContextRef, value JSValueRef) bool
JSValueIsArray tests whether a JavaScript value is an array.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsArray(_:_:)
func JSValueIsBigInt ¶
func JSValueIsBigInt(ctx JSContextRef, value JSValueRef) bool
JSValueIsBigInt.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsBigInt(_:_:)
func JSValueIsBoolean ¶
func JSValueIsBoolean(ctx JSContextRef, value JSValueRef) bool
JSValueIsBoolean tests whether a JavaScript value is Boolean.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsBoolean(_:_:)
func JSValueIsDate ¶
func JSValueIsDate(ctx JSContextRef, value JSValueRef) bool
JSValueIsDate tests whether a JavaScript value is a date.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsDate(_:_:)
func JSValueIsEqual ¶
func JSValueIsEqual(ctx JSContextRef, a JSValueRef, b JSValueRef, exception *JSValueRef) bool
JSValueIsEqual tests whether two JavaScript values are equal.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsEqual(_:_:_:_:)
func JSValueIsInstanceOfConstructor ¶
func JSValueIsInstanceOfConstructor(ctx JSContextRef, value JSValueRef, constructor JSObjectRef, exception *JSValueRef) bool
JSValueIsInstanceOfConstructor tests whether a JavaScript value is an object that the specified constructor creates.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsInstanceOfConstructor(_:_:_:_:)
func JSValueIsNull ¶
func JSValueIsNull(ctx JSContextRef, value JSValueRef) bool
JSValueIsNull tests whether a JavaScript value’s type is the null type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsNull(_:_:)
func JSValueIsNumber ¶
func JSValueIsNumber(ctx JSContextRef, value JSValueRef) bool
JSValueIsNumber tests whether a JavaScript value’s type is the number type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsNumber(_:_:)
func JSValueIsObject ¶
func JSValueIsObject(ctx JSContextRef, value JSValueRef) bool
JSValueIsObject tests whether a JavaScript value’s type is the object type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsObject(_:_:)
func JSValueIsObjectOfClass ¶
func JSValueIsObjectOfClass(ctx JSContextRef, value JSValueRef, jsClass JSClassRef) bool
JSValueIsObjectOfClass tests whether a JavaScript value is an object with a specified class in its class chain.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsObjectOfClass(_:_:_:)
func JSValueIsStrictEqual ¶
func JSValueIsStrictEqual(ctx JSContextRef, a JSValueRef, b JSValueRef) bool
JSValueIsStrictEqual tests whether two JavaScript values are strict equal.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsStrictEqual(_:_:_:)
func JSValueIsString ¶
func JSValueIsString(ctx JSContextRef, value JSValueRef) bool
JSValueIsString tests whether a JavaScript value’s type is the string type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsString(_:_:)
func JSValueIsSymbol ¶
func JSValueIsSymbol(ctx JSContextRef, value JSValueRef) bool
JSValueIsSymbol tests whether a JavaScript value’s type is the symbol type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsSymbol(_:_:)
func JSValueIsUndefined ¶
func JSValueIsUndefined(ctx JSContextRef, value JSValueRef) bool
JSValueIsUndefined tests whether a JavaScript value’s type is the undefined type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueIsUndefined(_:_:)
func JSValueProtect ¶
func JSValueProtect(ctx JSContextRef, value JSValueRef)
JSValueProtect protects a JavaScript value from garbage collection.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueProtect(_:_:)
func JSValueToBoolean ¶
func JSValueToBoolean(ctx JSContextRef, value JSValueRef) bool
JSValueToBoolean converts a JavaScript value to a Boolean and returns the resulting Boolean.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueToBoolean(_:_:)
func JSValueToInt32 ¶
func JSValueToInt32(ctx JSContextRef, value JSValueRef, exception *JSValueRef) int32
JSValueToInt32.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueToInt32(_:_:_:)
func JSValueToInt64 ¶
func JSValueToInt64(ctx JSContextRef, value JSValueRef, exception *JSValueRef) int64
JSValueToInt64.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueToInt64(_:_:_:)
func JSValueToNumber ¶
func JSValueToNumber(ctx JSContextRef, value JSValueRef, exception *JSValueRef) float64
JSValueToNumber converts a JavaScript value to a number and returns the resulting number.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueToNumber(_:_:_:)
func JSValueToUInt32 ¶
func JSValueToUInt32(ctx JSContextRef, value JSValueRef, exception *JSValueRef) uint32
JSValueToUInt32.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueToUInt32(_:_:_:)
func JSValueToUInt64 ¶
func JSValueToUInt64(ctx JSContextRef, value JSValueRef, exception *JSValueRef) uint64
JSValueToUInt64.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueToUInt64(_:_:_:)
func JSValueUnprotect ¶
func JSValueUnprotect(ctx JSContextRef, value JSValueRef)
JSValueUnprotect unprotects a JavaScript value from garbage collection.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueUnprotect(_:_:)
func NewJSContextJSValueBlock ¶
func NewJSContextJSValueBlock(handler JSContextJSValueHandler) (objc.ID, func())
NewJSContextJSValueBlock wraps a Go JSContextJSValueHandler as an Objective-C block. The caller must defer the returned cleanup function.
func NewJSValueJSValueBlock ¶
func NewJSValueJSValueBlock(handler JSValueJSValueHandler) (objc.ID, func())
NewJSValueJSValueBlock wraps a Go JSValueJSValueHandler as an Objective-C block. The caller must defer the returned cleanup function.
Used by:
- [JSValue.ValueWithNewPromiseInContextFromExecutor]
Types ¶
type IJSContext ¶
type IJSContext interface {
objectivec.IObject
// Creates a new JavaScript context associated with a specific virtual machine.
InitWithVirtualMachine(virtualMachine IJSVirtualMachine) JSContext
// A Boolean value that indicates whether you can inspect the JavaScript context with Safari Web Inspector.
IsInspectable() bool
SetInspectable(value bool)
// Executes the specified JavaScript code.
EvaluateScript(script string) IJSValue
// Executes the specified JavaScript code, treating the specified URL as its source location.
EvaluateScriptWithSourceURL(script string, sourceURL foundation.NSURL) IJSValue
// The JavaScript global object associated with the context.
GlobalObject() IJSValue
// A JavaScript exception to be thrown in evaluation of the script.
Exception() IJSValue
SetException(value IJSValue)
// A block to be invoked should evaluating a script result in a JavaScript exception being thrown.
ExceptionHandler() JSContextJSValueHandler
SetExceptionHandler(value JSContextJSValueHandler)
// The JavaScript virtual machine to which the context belongs.
VirtualMachine() IJSVirtualMachine
// A descriptive name for the context.
Name() string
SetName(value string)
// Returns the value of the specified JavaScript property in the context’s global object, allowing subscript getter syntax.
ObjectForKeyedSubscript(key objectivec.IObject) IJSValue
// Sets the specified JavaScript property of the context’s global object, allowing subscript setter syntax.
SetObjectForKeyedSubscript(object objectivec.IObject, key objectivec.NSObject)
// Returns the C representation of the JavaScript context.
JSGlobalContextRef() JSGlobalContextRef
}
An interface definition for the JSContext class.
Creating JavaScript contexts ¶
- [IJSContext.InitWithVirtualMachine]: Creates a new JavaScript context associated with a specific virtual machine.
Making JavaScript context inspectable ¶
- [IJSContext.IsInspectable]: A Boolean value that indicates whether you can inspect the JavaScript context with Safari Web Inspector.
- [IJSContext.SetInspectable]
Evaluating scripts ¶
- [IJSContext.EvaluateScript]: Executes the specified JavaScript code.
- [IJSContext.EvaluateScriptWithSourceURL]: Executes the specified JavaScript code, treating the specified URL as its source location.
Working with JavaScript global state ¶
- [IJSContext.GlobalObject]: The JavaScript global object associated with the context.
- [IJSContext.Exception]: A JavaScript exception to be thrown in evaluation of the script.
- [IJSContext.SetException]
- [IJSContext.ExceptionHandler]: A block to be invoked should evaluating a script result in a JavaScript exception being thrown.
- [IJSContext.SetExceptionHandler]
- [IJSContext.VirtualMachine]: The JavaScript virtual machine to which the context belongs.
- [IJSContext.Name]: A descriptive name for the context.
- [IJSContext.SetName]
Accessing JavaScript global state with subscripts ¶
- [IJSContext.ObjectForKeyedSubscript]: Returns the value of the specified JavaScript property in the context’s global object, allowing subscript getter syntax.
- [IJSContext.SetObjectForKeyedSubscript]: Sets the specified JavaScript property of the context’s global object, allowing subscript setter syntax.
Working with the C JavaScriptCore API ¶
- [IJSContext.JSGlobalContextRef]: Returns the C representation of the JavaScript context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext
type IJSManagedValue ¶
type IJSManagedValue interface {
objectivec.IObject
// Initializes a managed value with the specified JavaScript value.
InitWithValue(value IJSValue) JSManagedValue
// The managed value’s underlying JavaScript value.
Value() IJSValue
}
An interface definition for the JSManagedValue class.
Creating a Managed Value ¶
- [IJSManagedValue.InitWithValue]: Initializes a managed value with the specified JavaScript value.
Accessing the Managed Value ¶
- [IJSManagedValue.Value]: The managed value’s underlying JavaScript value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSManagedValue
type IJSValue ¶
type IJSValue interface {
objectivec.IObject
// Converts the JavaScript value to a native object.
ToObject() objectivec.IObject
// Converts the JavaScript value to a native object of the specified class.
ToObjectOfClass(expectedClass objectivec.Class) objectivec.IObject
// Converts the JavaScript value to a native Boolean value.
ToBool() bool
// Converts the JavaScript value to a native floating-point value.
ToDouble() float64
// Converts the JavaScript value to a native signed integer value.
ToInt32() int32
// Converts the JavaScript value to a native unsigned integer value.
ToUInt32() uint32
// Converts the JavaScript value to a [NSNumber](<doc://com.apple.documentation/documentation/Foundation/NSNumber>) object.
ToNumber() foundation.NSNumber
// Converts the JavaScript value to a native string.
ToString() string
// Converts the JavaScript value to a date object.
ToDate() foundation.NSDate
// Converts the JavaScript value to an array.
ToArray() foundation.INSArray
// Converts the JavaScript value to a dictionary.
ToDictionary() foundation.INSDictionary
// Converts the value to a point structure.
ToPoint() corefoundation.CGPoint
// Converts the value to a range.
ToRange() foundation.NSRange
// Converts the value to a rectangle structure.
ToRect() corefoundation.CGRect
// Converts the value to a size.
ToSize() corefoundation.CGSize
// A Boolean value that indicates whether the instance corresponds to the JavaScript `undefined` value.
IsUndefined() bool
// A Boolean value that indicates whether the instance corresponds to the JavaScript `null` value.
IsNull() bool
// A Boolean value that indicates whether the instance is a JavaScript Boolean value.
IsBoolean() bool
// A Boolean value that indicates whether the instance is a JavaScript numeric value.
IsNumber() bool
// A Boolean value that indicates whether the instance is a JavaScript [String] object.
IsString() bool
// A Boolean value that indicates whether the instance is a JavaScript object.
IsObject() bool
// A Boolean value that indicates whether the instance is a JavaScript array value.
IsArray() bool
// A Boolean value that indicates whether the instance is a JavaScript [Date] object.
IsDate() bool
// A Boolean value that indicates whether the instance is a symbol.
IsSymbol() bool
// Compares the value to another for strict equality.
IsEqualToObject(value objectivec.IObject) bool
// Compares the value to another for equivalence, allowing type conversion.
IsEqualWithTypeCoercionToObject(value objectivec.IObject) bool
// Returns a Boolean value indicating whether the value is an instance of another JavaScript object value.
IsInstanceOf(value objectivec.IObject) bool
// Invokes the value as a JavaScript function.
CallWithArguments(arguments foundation.INSArray) IJSValue
// Invokes the value as a JavaScript constructor.
ConstructWithArguments(arguments foundation.INSArray) IJSValue
// Calls the named JavaScript method on the value.
InvokeMethodWithArguments(method string, arguments foundation.INSArray) IJSValue
// Defines a property on the JavaScript object value or modifies a property’s definition.
DefinePropertyDescriptor(property JSValueProperty, descriptor objectivec.IObject)
// Returns a Boolean value indicating whether the JavaScript value has a defined property with the specified name.
HasProperty(property JSValueProperty) bool
// Deletes the named property from the JavaScript object value.
DeleteProperty(property JSValueProperty) bool
// Returns the value at the specified numeric index in the JavaScript object value.
ValueAtIndex(index uint) IJSValue
// Sets the value at the specified numeric index in the JavaScript object value.
SetValueAtIndex(value objectivec.IObject, index uint)
// Returns the value of the named property in the JavaScript object value.
ValueForProperty(property JSValueProperty) IJSValue
// Sets the value of the named property in the JavaScript object value.
SetValueForProperty(value objectivec.IObject, property JSValueProperty)
// The JavaScript context hosting this value.
Context() IJSContext
// Returns the value’s JavaScript property at the specified index, allowing subscript syntax.
ObjectAtIndexedSubscript(index uint) IJSValue
// Sets the value’s JavaScript property at the specified index, allowing subscript syntax.
SetObjectAtIndexedSubscript(object objectivec.IObject, index uint)
// Returns the value’s JavaScript property named with the specified key, allowing subscript syntax.
ObjectForKeyedSubscript(key objectivec.IObject) IJSValue
// Sets the value’s JavaScript property named with the specified key, allowing subscript syntax.
SetObjectForKeyedSubscript(object objectivec.IObject, key objectivec.IObject)
// Returns the C representation of the JavaScript value.
JSValueRef() JSValueRef
IsBigInt() bool
CompareDouble(other float64) JSRelationCondition
CompareJSValue(other IJSValue) JSRelationCondition
CompareUInt64(other uint64) JSRelationCondition
CompareInt64(other int64) JSRelationCondition
ToInt64() int64
ToUInt64() uint64
}
An interface definition for the JSValue class.
Reading and Converting JavaScript Values ¶
- [IJSValue.ToObject]: Converts the JavaScript value to a native object.
- [IJSValue.ToObjectOfClass]: Converts the JavaScript value to a native object of the specified class.
- [IJSValue.ToBool]: Converts the JavaScript value to a native Boolean value.
- [IJSValue.ToDouble]: Converts the JavaScript value to a native floating-point value.
- [IJSValue.ToInt32]: Converts the JavaScript value to a native signed integer value.
- [IJSValue.ToUInt32]: Converts the JavaScript value to a native unsigned integer value.
- [IJSValue.ToNumber]: Converts the JavaScript value to a [NSNumber](<doc://com.apple.documentation/documentation/Foundation/NSNumber>) object.
- [IJSValue.ToString]: Converts the JavaScript value to a native string.
- [IJSValue.ToDate]: Converts the JavaScript value to a date object.
- [IJSValue.ToArray]: Converts the JavaScript value to an array.
- [IJSValue.ToDictionary]: Converts the JavaScript value to a dictionary.
- [IJSValue.ToPoint]: Converts the value to a point structure.
- [IJSValue.ToRange]: Converts the value to a range.
- [IJSValue.ToRect]: Converts the value to a rectangle structure.
- [IJSValue.ToSize]: Converts the value to a size.
Determining the Type of a JavaScript Value ¶
- [IJSValue.IsUndefined]: A Boolean value that indicates whether the instance corresponds to the JavaScript `undefined` value.
- [IJSValue.IsNull]: A Boolean value that indicates whether the instance corresponds to the JavaScript `null` value.
- [IJSValue.IsBoolean]: A Boolean value that indicates whether the instance is a JavaScript Boolean value.
- [IJSValue.IsNumber]: A Boolean value that indicates whether the instance is a JavaScript numeric value.
- [IJSValue.IsString]: A Boolean value that indicates whether the instance is a JavaScript [String] object.
- [IJSValue.IsObject]: A Boolean value that indicates whether the instance is a JavaScript object.
- [IJSValue.IsArray]: A Boolean value that indicates whether the instance is a JavaScript array value.
- [IJSValue.IsDate]: A Boolean value that indicates whether the instance is a JavaScript [Date] object.
- [IJSValue.IsSymbol]: A Boolean value that indicates whether the instance is a symbol.
Comparing JavaScript Values ¶
- [IJSValue.IsEqualToObject]: Compares the value to another for strict equality.
- [IJSValue.IsEqualWithTypeCoercionToObject]: Compares the value to another for equivalence, allowing type conversion.
- [IJSValue.IsInstanceOf]: Returns a Boolean value indicating whether the value is an instance of another JavaScript object value.
Working with Function and Constructor Values ¶
- [IJSValue.CallWithArguments]: Invokes the value as a JavaScript function.
- [IJSValue.ConstructWithArguments]: Invokes the value as a JavaScript constructor.
- [IJSValue.InvokeMethodWithArguments]: Calls the named JavaScript method on the value.
Working with Container Values ¶
- [IJSValue.DefinePropertyDescriptor]: Defines a property on the JavaScript object value or modifies a property’s definition.
- [IJSValue.HasProperty]: Returns a Boolean value indicating whether the JavaScript value has a defined property with the specified name.
- [IJSValue.DeleteProperty]: Deletes the named property from the JavaScript object value.
- [IJSValue.ValueAtIndex]: Returns the value at the specified numeric index in the JavaScript object value.
- [IJSValue.SetValueAtIndex]: Sets the value at the specified numeric index in the JavaScript object value.
- [IJSValue.ValueForProperty]: Returns the value of the named property in the JavaScript object value.
- [IJSValue.SetValueForProperty]: Sets the value of the named property in the JavaScript object value.
Accessing a Value’s JavaScript Context ¶
- [IJSValue.Context]: The JavaScript context hosting this value.
Accessing Values with Subscript Syntax ¶
- [IJSValue.ObjectAtIndexedSubscript]: Returns the value’s JavaScript property at the specified index, allowing subscript syntax.
- [IJSValue.SetObjectAtIndexedSubscript]: Sets the value’s JavaScript property at the specified index, allowing subscript syntax.
- [IJSValue.ObjectForKeyedSubscript]: Returns the value’s JavaScript property named with the specified key, allowing subscript syntax.
- [IJSValue.SetObjectForKeyedSubscript]: Sets the value’s JavaScript property named with the specified key, allowing subscript syntax.
Working with the C JavaScriptCore API ¶
- [IJSValue.JSValueRef]: Returns the C representation of the JavaScript value.
Instance Properties ¶
- [IJSValue.IsBigInt]
Instance Methods ¶
- [IJSValue.CompareDouble]
- [IJSValue.CompareJSValue]
- [IJSValue.CompareUInt64]
- [IJSValue.CompareInt64]
- [IJSValue.ToInt64]
- [IJSValue.ToUInt64]
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue
type IJSVirtualMachine ¶
type IJSVirtualMachine interface {
objectivec.IObject
// Notifies the JavaScriptCore virtual machine of an external object relationship.
AddManagedReferenceWithOwner(object objectivec.IObject, owner objectivec.IObject)
// Notifies the JavaScriptCore virtual machine that a previously registered object relationship no longer exists.
RemoveManagedReferenceWithOwner(object objectivec.IObject, owner objectivec.IObject)
}
An interface definition for the JSVirtualMachine class.
Managing Memory for Bridged Values ¶
- [IJSVirtualMachine.AddManagedReferenceWithOwner]: Notifies the JavaScriptCore virtual machine of an external object relationship.
- [IJSVirtualMachine.RemoveManagedReferenceWithOwner]: Notifies the JavaScriptCore virtual machine that a previously registered object relationship no longer exists.
See: https://developer.apple.com/documentation/JavaScriptCore/JSVirtualMachine
type JSChar ¶
type JSChar = uint16
JSChar is a Unicode character.
See: https://developer.apple.com/documentation/JavaScriptCore/JSChar
func JSStringGetCharactersPtr ¶
func JSStringGetCharactersPtr(string_ JSStringRef) *JSChar
JSStringGetCharactersPtr returns a pointer to the Unicode character buffer that serves as the backing store for a JavaScript string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringGetCharactersPtr(_:)
type JSClassAttributes ¶
type JSClassAttributes = uint
JSClassAttributes is a set of JavaScript class attributes.
See: https://developer.apple.com/documentation/JavaScriptCore/JSClassAttributes
type JSClassDefinition ¶
type JSClassDefinition struct {
Version int // The version of the class definition structure.
Attributes JSClassAttributes // A set of class attributes to give to the class.
ClassName *byte // A null-terminated UTF-8 string that contains the class’s name.
ParentClass JSClassRef // A JavaScript class to set as the class’s parent class.
StaticValues *JSStaticValue // An array that contains the class’s statically declared value properties.
StaticFunctions *JSStaticFunction // An array that contains the class’s statically declared function properties.
Initialize JSObjectInitializeCallback // The callback for creating the object.
Finalize JSObjectFinalizeCallback // The callback for preparing the object for garbage collection.
HasProperty JSObjectHasPropertyCallback // The callback for determining whether an object has a property.
GetProperty JSObjectGetPropertyCallback // The callback for getting a property’s value.
SetProperty JSObjectSetPropertyCallback // The callback for setting a property’s value.
DeleteProperty JSObjectDeletePropertyCallback // The callback for deleting a property.
GetPropertyNames JSObjectGetPropertyNamesCallback // The callback for collecting the names of an object’s properties.
CallAsFunction JSObjectCallAsFunctionCallback // The callback for calling an object as a function.
CallAsConstructor JSObjectCallAsConstructorCallback // The callback for using an object as a constructor.
HasInstance JSObjectHasInstanceCallback // The callback for checking whether an object is an instance of a particular type.
ConvertToType JSObjectConvertToTypeCallback // The callback for converting an object to a particular JavaScript type.
}
JSClassDefinition - A structure that contains properties and callbacks that define a type of object.
[Full Topic] [Full Topic]: https://developer.apple.com/documentation/JavaScriptCore/JSClassDefinition
var ( // KJSClassDefinitionEmpty is a class definition structure of the current version that contains null pointers and has no attributes. // // See: https://developer.apple.com/documentation/JavaScriptCore/kJSClassDefinitionEmpty KJSClassDefinitionEmpty JSClassDefinition )
type JSClassRef ¶
type JSClassRef uintptr
JSClassRef is a JavaScript class.
See: https://developer.apple.com/documentation/JavaScriptCore/JSClassRef
func JSClassCreate ¶
func JSClassCreate(definition *JSClassDefinition) JSClassRef
JSClassCreate creates a JavaScript class.
See: https://developer.apple.com/documentation/JavaScriptCore/JSClassCreate(_:)
func JSClassRetain ¶
func JSClassRetain(jsClass JSClassRef) JSClassRef
JSClassRetain retains a JavaScript class.
See: https://developer.apple.com/documentation/JavaScriptCore/JSClassRetain(_:)
type JSContext ¶
type JSContext struct {
objectivec.Object
}
A JavaScript execution environment.
Overview ¶
You create and use JavaScript contexts to evaluate JavaScript scripts from Objective-C or Swift code; to access values that JavaScript defines or calculates; and to make native objects, methods, or functions accessible to JavaScript.
Creating JavaScript contexts ¶
- JSContext.InitWithVirtualMachine: Creates a new JavaScript context associated with a specific virtual machine.
Making JavaScript context inspectable ¶
- JSContext.IsInspectable: A Boolean value that indicates whether you can inspect the JavaScript context with Safari Web Inspector.
- JSContext.SetInspectable
Evaluating scripts ¶
- JSContext.EvaluateScript: Executes the specified JavaScript code.
- JSContext.EvaluateScriptWithSourceURL: Executes the specified JavaScript code, treating the specified URL as its source location.
Working with JavaScript global state ¶
- JSContext.GlobalObject: The JavaScript global object associated with the context.
- JSContext.Exception: A JavaScript exception to be thrown in evaluation of the script.
- JSContext.SetException
- JSContext.ExceptionHandler: A block to be invoked should evaluating a script result in a JavaScript exception being thrown.
- JSContext.SetExceptionHandler
- JSContext.VirtualMachine: The JavaScript virtual machine to which the context belongs.
- JSContext.Name: A descriptive name for the context.
- JSContext.SetName
Accessing JavaScript global state with subscripts ¶
- JSContext.ObjectForKeyedSubscript: Returns the value of the specified JavaScript property in the context’s global object, allowing subscript getter syntax.
- JSContext.SetObjectForKeyedSubscript: Sets the specified JavaScript property of the context’s global object, allowing subscript setter syntax.
Working with the C JavaScriptCore API ¶
- JSContext.JSGlobalContextRef: Returns the C representation of the JavaScript context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext
func JSContextFromID ¶
JSContextFromID constructs a JSContext from an objc.ID.
A JavaScript execution environment.
func NewJSContextWithJSGlobalContextRef ¶
func NewJSContextWithJSGlobalContextRef(jsGlobalContextRef JSGlobalContextRef) JSContext
Creates a JavaScript context object from the equivalent C representation.
jsGlobalContextRef: A C JavaScript context reference.
Return Value ¶
A JavaScript context object representing the same context.
Discussion ¶
See JSContextRef for the C JavaScriptCore API.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/init(JSGlobalContextRef:)-9m51
func NewJSContextWithVirtualMachine ¶
func NewJSContextWithVirtualMachine(virtualMachine IJSVirtualMachine) JSContext
Creates a new JavaScript context associated with a specific virtual machine.
virtualMachine: The virtual machine with which to associate the new context.
Return Value ¶
A new JavaScript context.
Discussion ¶
By default, each context has an independent virtual machine (a JSVirtualMachine object). You cannot pass JavaScript values between contexts in different virtual machines. Use this initializer to create a context that shares its virtual machine with other JavaScript contexts to allow passing JSValue objects between those contexts.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/init(virtualMachine:)
func (JSContext) Autorelease ¶
Autorelease adds the receiver to the current autorelease pool.
func (JSContext) EvaluateScript ¶
Executes the specified JavaScript code.
script: The JavaScript source code to evaluate.
Return Value ¶
The last value generated by the script. Note that a script can result in the JavaScript value `undefined`.
Discussion ¶
Evaluating a script runs any top-level code and adds function and object definitions to the context’s global object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/evaluateScript(_:)
func (JSContext) EvaluateScriptWithSourceURL ¶
func (j JSContext) EvaluateScriptWithSourceURL(script string, sourceURL foundation.NSURL) IJSValue
Executes the specified JavaScript code, treating the specified URL as its source location.
script: The JavaScript source code to evaluate.
sourceURL: A URL to be considered as the script’s origin.
Return Value ¶
The last value generated by the script. Note that a script can result in the JavaScript value `undefined`.
Discussion ¶
Evaluating a script runs any top-level code and adds function or object definitions to the context’s global object.
The `sourceURL` parameter is informative only; debuggers may use this URL when reporting exceptions.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/evaluateScript(_:withSourceURL:)
func (JSContext) Exception ¶
A JavaScript exception to be thrown in evaluation of the script.
Discussion ¶
Before performing a callback from JavaScript to an Objective-C or Swift block or method, the context preserves the prior value of this property and then sets its value to `nil`. After the callback has completed, the context reads the new value of the JSContext.Exception property—if this value is not nil, the context treats the value as an exception to be thrown in JavaScript as a result of the callback. After reading the property (and possibly throwing a JavaScript exception), the context restores the prior value of this property.
By default, JavaScriptCore assigns any uncaught exception to this property, so you can check this property’s value to find uncaught exceptions arising from JavaScript function calls. To change the exception handling behavior, use the JSContext.ExceptionHandler property.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/exception
func (JSContext) ExceptionHandler ¶
func (j JSContext) ExceptionHandler() JSContextJSValueHandler
A block to be invoked should evaluating a script result in a JavaScript exception being thrown.
Discussion ¶
The block takes the following parameters:
context: The context in which the exception originates. exception: The JavaScript exception thrown.
The default value exception handler block stores its `exception` parameter value into the context’s JSContext.Exception property. As a consequence, the default behavior is that unhandled exceptions occurring within a callback from JavaScript to native code are thrown again upon return. Setting this value to `nil` results in all uncaught exceptions being silently consumed.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/exceptionHandler
func (JSContext) GlobalObject ¶
The JavaScript global object associated with the context.
Discussion ¶
In a web browser, the global object of a JavaScript context is the browser window (the `window` object in JavaScript). Outside of web-browser use, a context’s global object serves a similar role, separating the JavaScript namespaces of different contexts. Global variables within a script appear as fields or subscripts in the global object—you can access them either through this JSValue object or through the methods listed in the Accessing JavaScript global state with subscripts section in JSContext.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/globalObject
func (JSContext) InitWithVirtualMachine ¶
func (j JSContext) InitWithVirtualMachine(virtualMachine IJSVirtualMachine) JSContext
Creates a new JavaScript context associated with a specific virtual machine.
virtualMachine: The virtual machine with which to associate the new context.
Return Value ¶
A new JavaScript context.
Discussion ¶
By default, each context has an independent virtual machine (a JSVirtualMachine object). You cannot pass JavaScript values between contexts in different virtual machines. Use this initializer to create a context that shares its virtual machine with other JavaScript contexts to allow passing JSValue objects between those contexts.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/init(virtualMachine:)
func (JSContext) IsInspectable ¶
A Boolean value that indicates whether you can inspect the JavaScript context with Safari Web Inspector.
Discussion ¶
Defaults to `false`.
Set to `true` at any point in the context’s lifetime to allow Safari Web Inspector access to inspect the context. Then, select your context in Safari’s Develop menu for either your computer or an attached device to inspect it.
If you set this value to `false` during inspection, the system immediately closes Safari Web Inspector and does not provide any further information about the context.
For more information, see Enabling the Inspection of Web Content in Apps.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/isInspectable
func (JSContext) JSGlobalContextRef ¶
func (j JSContext) JSGlobalContextRef() JSGlobalContextRef
Returns the C representation of the JavaScript context.
Discussion ¶
See JSContextRef for the C JavaScriptCore API.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/jsGlobalContextRef
func (JSContext) Name ¶
A descriptive name for the context.
Discussion ¶
This name appears when using remote debugging to examine the context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/name
func (JSContext) ObjectForKeyedSubscript ¶
func (j JSContext) ObjectForKeyedSubscript(key objectivec.IObject) IJSValue
Returns the value of the specified JavaScript property in the context’s global object, allowing subscript getter syntax.
key: The name of a JavaScript property in the context’s global JavaScript object.
Return Value ¶
The JavaScript property named by `key`, or `nil` if no such field or function exists.
Discussion ¶
This method first constructs a JSValue object from the `key` parameter, then uses that value in JavaScript to look up the name of a property in the context’s global object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/objectForKeyedSubscript(_:)
func (JSContext) SetException ¶
func (JSContext) SetExceptionHandler ¶
func (j JSContext) SetExceptionHandler(value JSContextJSValueHandler)
func (JSContext) SetInspectable ¶
func (JSContext) SetObjectForKeyedSubscript ¶
func (j JSContext) SetObjectForKeyedSubscript(object objectivec.IObject, key objectivec.NSObject)
Sets the specified JavaScript property of the context’s global object, allowing subscript setter syntax.
object: The value to set for the JavaScript property.
key: The JavaScript property name to use in the context’s global JavaScript object.
Discussion ¶
This method first constructs a JSValue object from the `key` parameter, then uses that value in JavaScript to set the property in the context’s global object.
Use this method (or Objective-C subscript syntax) to bridge native objects or functions for use in JavaScript. For example, the following code creates a JavaScript function whose implementation is an Objective-C block:
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/setObject(_:forKeyedSubscript:)
func (JSContext) VirtualMachine ¶
func (j JSContext) VirtualMachine() IJSVirtualMachine
The JavaScript virtual machine to which the context belongs.
Discussion ¶
To create a context associated with a specific virtual machine, allowing JavaScript values to be passed between contexts that share the same virtual machine, use the JSContext.InitWithVirtualMachine initializer.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/virtualMachine
type JSContextClass ¶
type JSContextClass struct {
// contains filtered or unexported fields
}
func GetJSContextClass ¶
func GetJSContextClass() JSContextClass
GetJSContextClass returns the class object for JSContext.
func (JSContextClass) Alloc ¶
func (jc JSContextClass) Alloc() JSContext
Alloc allocates memory for a new instance of the class.
func (JSContextClass) Class ¶
func (jc JSContextClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
func (JSContextClass) CurrentArguments ¶
func (_JSContextClass JSContextClass) CurrentArguments() foundation.INSArray
Returns the arguments to the current native callback from JavaScript code.
Return Value ¶
The current callback arguments, or `nil` if not within native code called from JavaScript.
Discussion ¶
Call this method within an Objective-C or Swift block or method invoked from within JavaScript to obtain an array of JSValue objects representing the arguments to the JavaScript function responsible for that callback.
If not currently in code invoked as a callback from JavaScript, this method returns `nil`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/currentArguments()
func (JSContextClass) CurrentCallee ¶
func (_JSContextClass JSContextClass) CurrentCallee() JSValue
Returns the currently executing JavaScript function.
Return Value ¶
The currently executing JavaScript function, or `nil` if not within native code called from JavaScript.
Discussion ¶
Call this method within an Objective-C or Swift block or method invoked from within JavaScript to obtain a JSValue object representing the JavaScript function responsible for executing that code.
If not currently in code invoked as a callback from JavaScript, this method returns `nil`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/currentCallee()
func (JSContextClass) CurrentContext ¶
func (_JSContextClass JSContextClass) CurrentContext() JSContext
Returns the context currently executing JavaScript code.
Return Value ¶
The currently executing context, or `nil` if not within native code called from JavaScript.
Discussion ¶
Call this method within an Objective-C or Swift block or method invoked from within JavaScript to obtain the JSContext object responsible for executing that Javascript code.
If not currently in code invoked as a callback from JavaScript, this method returns `nil`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/current()
func (JSContextClass) CurrentThis ¶
func (_JSContextClass JSContextClass) CurrentThis() JSValue
Returns the value of the `this` keyword in currently executing JavaScript code.
Return Value ¶
The current value of the JavaScript `this` keyword, or `nil` if not within native code called from JavaScript.
Discussion ¶
Call this method within an Objective-C or Swift block or method invoked from within JavaScript to obtain a JSValue object representing the current value of the `this` keyword in that JavaScript code.
If not currently in code invoked as a callback from JavaScript, this method returns `nil`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContext/currentThis()
type JSContextGroupRef ¶
type JSContextGroupRef uintptr
JSContextGroupRef is a group that associates JavaScript contexts with one another.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContextGroupRef
func JSContextGetGroup ¶
func JSContextGetGroup(ctx JSContextRef) JSContextGroupRef
JSContextGetGroup gets the context group that a JavaScript execution context belongs to.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContextGetGroup(_:)
func JSContextGroupCreate ¶
func JSContextGroupCreate() JSContextGroupRef
JSContextGroupCreate creates a JavaScript context group.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContextGroupCreate()
func JSContextGroupRetain ¶
func JSContextGroupRetain(group JSContextGroupRef) JSContextGroupRef
JSContextGroupRetain retains a JavaScript context group.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContextGroupRetain(_:)
type JSContextJSValueHandler ¶
JSContextJSValueHandler is the signature for a completion handler block.
type JSContextRef ¶
type JSContextRef uintptr
JSContextRef is a JavaScript execution context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContextRef
type JSExport ¶
type JSExport interface {
objectivec.IObject
}
The protocol for exporting Objective-C objects to JavaScript.
See: https://developer.apple.com/documentation/JavaScriptCore/JSExport
type JSExportObject ¶
type JSExportObject struct {
objectivec.Object
}
JSExportObject wraps an existing Objective-C object that conforms to the JSExport protocol.
func JSExportObjectFromID ¶
func JSExportObjectFromID(id objc.ID) JSExportObject
JSExportObjectFromID constructs a JSExportObject from an objc.ID. The object is determined to conform to the protocol at runtime.
func (JSExportObject) BaseObject ¶
func (o JSExportObject) BaseObject() objectivec.Object
type JSGlobalContextRef ¶
type JSGlobalContextRef uintptr
JSGlobalContextRef is a global JavaScript execution context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGlobalContextRef
func JSContextGetGlobalContext ¶
func JSContextGetGlobalContext(ctx JSContextRef) JSGlobalContextRef
JSContextGetGlobalContext gets the global context of a JavaScript execution context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContextGetGlobalContext(_:)
func JSGlobalContextCreate ¶
func JSGlobalContextCreate(globalObjectClass JSClassRef) JSGlobalContextRef
JSGlobalContextCreate creates a global JavaScript execution context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGlobalContextCreate(_:)
func JSGlobalContextCreateInGroup ¶
func JSGlobalContextCreateInGroup(group JSContextGroupRef, globalObjectClass JSClassRef) JSGlobalContextRef
JSGlobalContextCreateInGroup creates a global JavaScript execution context in the provided context group.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGlobalContextCreateInGroup(_:_:)
func JSGlobalContextRetain ¶
func JSGlobalContextRetain(ctx JSGlobalContextRef) JSGlobalContextRef
JSGlobalContextRetain retains a global JavaScript execution context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGlobalContextRetain(_:)
type JSManagedValue ¶
type JSManagedValue struct {
objectivec.Object
}
A JavaScript value with conditional retain behavior to provide automatic memory management.
Overview ¶
The primary use case for a managed value is to store a JavaScript value in an Objective-C or Swift object that exports to JavaScript.
A managed value’s behavior ensures retention of its underlying JavaScript value as long as either of the following conditions is true:
- The JavaScript value is reachable through the JavaScript object graph (that is, not subject to JavaScript garbage collection). - The JSManagedValue object is reachable through the Objective-C or Swift object graph, as you report to the JavaScriptCore virtual machine using the JSVirtualMachine.AddManagedReferenceWithOwner method.
However, if neither of these conditions is true, the managed value sets its JSManagedValue.Value property to `nil`, releasing the underlying JSValue object.
Creating a Managed Value ¶
- JSManagedValue.InitWithValue: Initializes a managed value with the specified JavaScript value.
Accessing the Managed Value ¶
- JSManagedValue.Value: The managed value’s underlying JavaScript value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSManagedValue
func JSManagedValueFromID ¶
func JSManagedValueFromID(id objc.ID) JSManagedValue
JSManagedValueFromID constructs a JSManagedValue from an objc.ID.
A JavaScript value with conditional retain behavior to provide automatic memory management.
func NewJSManagedValue ¶
func NewJSManagedValue() JSManagedValue
NewJSManagedValue creates a new JSManagedValue instance.
func NewJSManagedValueWithValue ¶
func NewJSManagedValueWithValue(value IJSValue) JSManagedValue
Initializes a managed value with the specified JavaScript value.
value: A JavaScript value.
Return Value ¶
A new managed value.
Discussion ¶
To ensure that the underlying JavaScript value is retained as long as the managed value remains in use in the Objective-C or Swift runtime, report the managed value’s owner to the JavaScriptCore virtual machine using the JSVirtualMachine.AddManagedReferenceWithOwner method.
See: https://developer.apple.com/documentation/JavaScriptCore/JSManagedValue/init(value:)
func NewJSManagedValueWithValueAndOwner ¶
func NewJSManagedValueWithValueAndOwner(value IJSValue, owner objectivec.IObject) JSManagedValue
Creates a managed value and associates it with an owner.
value: A JavaScript value.
owner: The Objective-C or Swift object responsible for
Return Value ¶
A new managed value.
Discussion ¶
Calling this method is equivalent to creating a managed value and then reporting it to the JavaScriptCore virtual machine using the JSVirtualMachine.AddManagedReferenceWithOwner method.
See: https://developer.apple.com/documentation/JavaScriptCore/JSManagedValue/init(value:andOwner:)
func (JSManagedValue) Autorelease ¶
func (j JSManagedValue) Autorelease() JSManagedValue
Autorelease adds the receiver to the current autorelease pool.
func (JSManagedValue) Init ¶
func (j JSManagedValue) Init() JSManagedValue
Init initializes the instance.
func (JSManagedValue) InitWithValue ¶
func (j JSManagedValue) InitWithValue(value IJSValue) JSManagedValue
Initializes a managed value with the specified JavaScript value.
value: A JavaScript value.
Return Value ¶
A new managed value.
Discussion ¶
To ensure that the underlying JavaScript value is retained as long as the managed value remains in use in the Objective-C or Swift runtime, report the managed value’s owner to the JavaScriptCore virtual machine using the JSVirtualMachine.AddManagedReferenceWithOwner method.
See: https://developer.apple.com/documentation/JavaScriptCore/JSManagedValue/init(value:)
func (JSManagedValue) Value ¶
func (j JSManagedValue) Value() IJSValue
The managed value’s underlying JavaScript value.
Discussion ¶
If the JavaScript garbage collector removes the underlying value, this property becomes `nil`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSManagedValue/value
type JSManagedValueClass ¶
type JSManagedValueClass struct {
// contains filtered or unexported fields
}
func GetJSManagedValueClass ¶
func GetJSManagedValueClass() JSManagedValueClass
GetJSManagedValueClass returns the class object for JSManagedValue.
func (JSManagedValueClass) Alloc ¶
func (jc JSManagedValueClass) Alloc() JSManagedValue
Alloc allocates memory for a new instance of the class.
func (JSManagedValueClass) Class ¶
func (jc JSManagedValueClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type JSObjectCallAsConstructorCallback ¶
JSObjectCallAsConstructorCallback is the callback type for using an object as a constructor.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectCallAsConstructorCallback
type JSObjectCallAsFunctionCallback ¶
type JSObjectCallAsFunctionCallback = func(uintptr, uintptr, uintptr, uint, uintptr, uintptr) uintptr
JSObjectCallAsFunctionCallback is the callback type for calling an object as a function.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectCallAsFunctionCallback
type JSObjectConvertToTypeCallback ¶
JSObjectConvertToTypeCallback is the callback type for converting an object to a particular JavaScript type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectConvertToTypeCallback
type JSObjectDeletePropertyCallback ¶
JSObjectDeletePropertyCallback is the callback type for deleting a property.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectDeletePropertyCallback
type JSObjectFinalizeCallback ¶
type JSObjectFinalizeCallback = func(uintptr)
JSObjectFinalizeCallback is the callback type for finalizing an object (preparing it for garbage collection).
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectFinalizeCallback
type JSObjectGetPropertyCallback ¶
JSObjectGetPropertyCallback is the callback type for getting a property’s value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetPropertyCallback
type JSObjectGetPropertyNamesCallback ¶
JSObjectGetPropertyNamesCallback is the callback type for collecting the names of an object’s properties.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetPropertyNamesCallback
type JSObjectHasInstanceCallback ¶
JSObjectHasInstanceCallback is the callback type for checking whether an object is an instance of a particular type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectHasInstanceCallback
type JSObjectHasPropertyCallback ¶
JSObjectHasPropertyCallback is the callback type for determining whether an object has a property.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectHasPropertyCallback
type JSObjectInitializeCallback ¶
JSObjectInitializeCallback is the callback type for first creating an object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectInitializeCallback
type JSObjectRef ¶
type JSObjectRef uintptr
JSObjectRef is a JavaScript object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectRef
func JSContextGetGlobalObject ¶
func JSContextGetGlobalObject(ctx JSContextRef) JSObjectRef
JSContextGetGlobalObject gets the global object of a JavaScript execution context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSContextGetGlobalObject(_:)
func JSObjectCallAsConstructor ¶
func JSObjectCallAsConstructor(ctx JSContextRef, object JSObjectRef, argumentCount uintptr, arguments JSValueRef, exception *JSValueRef) JSObjectRef
JSObjectCallAsConstructor calls an object as a constructor.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectCallAsConstructor(_:_:_:_:_:)
func JSObjectGetTypedArrayBuffer ¶
func JSObjectGetTypedArrayBuffer(ctx JSContextRef, object JSObjectRef, exception *JSValueRef) JSObjectRef
JSObjectGetTypedArrayBuffer returns the JavaScript array buffer object to use as the backing of a JavaScript typed array object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetTypedArrayBuffer(_:_:_:)
func JSObjectMake ¶
func JSObjectMake(ctx JSContextRef, jsClass JSClassRef, data unsafe.Pointer) JSObjectRef
JSObjectMake creates a JavaScript object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMake(_:_:_:)
func JSObjectMakeArray ¶
func JSObjectMakeArray(ctx JSContextRef, argumentCount uintptr, arguments JSValueRef, exception *JSValueRef) JSObjectRef
JSObjectMakeArray creates a JavaScript array object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMakeArray(_:_:_:_:)
func JSObjectMakeArrayBufferWithBytesNoCopy ¶
func JSObjectMakeArrayBufferWithBytesNoCopy(ctx JSContextRef, bytes unsafe.Pointer, byteLength uintptr, bytesDeallocator JSTypedArrayBytesDeallocator, deallocatorContext unsafe.Pointer, exception *JSValueRef) JSObjectRef
JSObjectMakeArrayBufferWithBytesNoCopy creates a JavaScript array buffer object from an existing pointer.
func JSObjectMakeConstructor ¶
func JSObjectMakeConstructor(ctx JSContextRef, jsClass JSClassRef, callAsConstructor JSObjectCallAsConstructorCallback) JSObjectRef
JSObjectMakeConstructor creates a JavaScript constructor.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMakeConstructor(_:_:_:)
func JSObjectMakeDate ¶
func JSObjectMakeDate(ctx JSContextRef, argumentCount uintptr, arguments JSValueRef, exception *JSValueRef) JSObjectRef
JSObjectMakeDate creates a JavaScript date object as though invoking the built-in date constructor.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMakeDate(_:_:_:_:)
func JSObjectMakeDeferredPromise ¶
func JSObjectMakeDeferredPromise(ctx JSContextRef, resolve *JSObjectRef, reject *JSObjectRef, exception *JSValueRef) JSObjectRef
JSObjectMakeDeferredPromise creates a JavaScript promise object by invoking the provided executor.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMakeDeferredPromise(_:_:_:_:)
func JSObjectMakeError ¶
func JSObjectMakeError(ctx JSContextRef, argumentCount uintptr, arguments JSValueRef, exception *JSValueRef) JSObjectRef
JSObjectMakeError creates a JavaScript error object as though invoking the built-in error constructor.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMakeError(_:_:_:_:)
func JSObjectMakeFunction ¶
func JSObjectMakeFunction(ctx JSContextRef, name JSStringRef, parameterCount uint, parameterNames JSStringRef, body JSStringRef, sourceURL JSStringRef, startingLineNumber int, exception *JSValueRef) JSObjectRef
JSObjectMakeFunction creates a function with a specified script as its body.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMakeFunction(_:_:_:_:_:_:_:_:)
func JSObjectMakeFunctionWithCallback ¶
func JSObjectMakeFunctionWithCallback(ctx JSContextRef, name JSStringRef, callAsFunction JSObjectCallAsFunctionCallback) JSObjectRef
JSObjectMakeFunctionWithCallback creates a JavaScript function with a specified callback as its implementation.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMakeFunctionWithCallback(_:_:_:)
func JSObjectMakeRegExp ¶
func JSObjectMakeRegExp(ctx JSContextRef, argumentCount uintptr, arguments JSValueRef, exception *JSValueRef) JSObjectRef
JSObjectMakeRegExp creates a JavaScript regular expression object as though invoking the built-in regular expression constructor.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMakeRegExp(_:_:_:_:)
func JSObjectMakeTypedArray ¶
func JSObjectMakeTypedArray(ctx JSContextRef, arrayType JSTypedArrayType, length uintptr, exception *JSValueRef) JSObjectRef
JSObjectMakeTypedArray creates a JavaScript typed array object with the specified number of elements.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectMakeTypedArray(_:_:_:_:)
func JSObjectMakeTypedArrayWithArrayBuffer ¶
func JSObjectMakeTypedArrayWithArrayBuffer(ctx JSContextRef, arrayType JSTypedArrayType, buffer JSObjectRef, exception *JSValueRef) JSObjectRef
JSObjectMakeTypedArrayWithArrayBuffer creates a JavaScript typed array object from an existing JavaScript array buffer object.
func JSObjectMakeTypedArrayWithArrayBufferAndOffset ¶
func JSObjectMakeTypedArrayWithArrayBufferAndOffset(ctx JSContextRef, arrayType JSTypedArrayType, buffer JSObjectRef, byteOffset uintptr, length uintptr, exception *JSValueRef) JSObjectRef
JSObjectMakeTypedArrayWithArrayBufferAndOffset creates a JavaScript typed array object from an existing JavaScript array buffer object with the specified offset and length.
func JSObjectMakeTypedArrayWithBytesNoCopy ¶
func JSObjectMakeTypedArrayWithBytesNoCopy(ctx JSContextRef, arrayType JSTypedArrayType, bytes unsafe.Pointer, byteLength uintptr, bytesDeallocator JSTypedArrayBytesDeallocator, deallocatorContext unsafe.Pointer, exception *JSValueRef) JSObjectRef
JSObjectMakeTypedArrayWithBytesNoCopy creates a JavaScript typed array object from an existing pointer.
func JSValueToObject ¶
func JSValueToObject(ctx JSContextRef, value JSValueRef, exception *JSValueRef) JSObjectRef
JSValueToObject converts a JavaScript value to an object and returns the resulting object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueToObject(_:_:_:)
type JSObjectSetPropertyCallback ¶
JSObjectSetPropertyCallback is the callback type for setting a property’s value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectSetPropertyCallback
type JSPropertyAttributes ¶
type JSPropertyAttributes = uint
JSPropertyAttributes is a set of JavaScript property attributes.
See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyAttributes
type JSPropertyNameAccumulatorRef ¶
type JSPropertyNameAccumulatorRef uintptr
JSPropertyNameAccumulatorRef is an ordered set of the names of a JavaScript object’s properties.
See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyNameAccumulatorRef
type JSPropertyNameArrayRef ¶
type JSPropertyNameArrayRef uintptr
JSPropertyNameArrayRef is an array of JavaScript property names.
See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyNameArrayRef
func JSObjectCopyPropertyNames ¶
func JSObjectCopyPropertyNames(ctx JSContextRef, object JSObjectRef) JSPropertyNameArrayRef
JSObjectCopyPropertyNames gets the names of an object’s enumerable properties.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectCopyPropertyNames(_:_:)
func JSPropertyNameArrayRetain ¶
func JSPropertyNameArrayRetain(array JSPropertyNameArrayRef) JSPropertyNameArrayRef
JSPropertyNameArrayRetain retains a JavaScript property name array.
See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyNameArrayRetain(_:)
type JSRelationCondition ¶
type JSRelationCondition uint32
See: https://developer.apple.com/documentation/JavaScriptCore/JSRelationCondition
func JSValueCompare ¶
func JSValueCompare(ctx JSContextRef, left JSValueRef, right JSValueRef, exception *JSValueRef) JSRelationCondition
JSValueCompare.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueCompare(_:_:_:_:)
func JSValueCompareDouble ¶
func JSValueCompareDouble(ctx JSContextRef, left JSValueRef, right float64, exception *JSValueRef) JSRelationCondition
JSValueCompareDouble.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueCompareDouble(_:_:_:_:)
func JSValueCompareInt64 ¶
func JSValueCompareInt64(ctx JSContextRef, left JSValueRef, right int64, exception *JSValueRef) JSRelationCondition
JSValueCompareInt64.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueCompareInt64(_:_:_:_:)
func JSValueCompareUInt64 ¶
func JSValueCompareUInt64(ctx JSContextRef, left JSValueRef, right uint64, exception *JSValueRef) JSRelationCondition
JSValueCompareUInt64.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueCompareUInt64(_:_:_:_:)
type JSStaticFunction ¶
type JSStaticFunction struct {
Name *byte // A null-terminated UTF-8 string that contains the property’s name.
CallAsFunction JSObjectCallAsFunctionCallback // A callback to invoke when calling the property as a function.
Attributes JSPropertyAttributes // A set of property attributes to give to the property.
}
JSStaticFunction - A statically declared function property.
[Full Topic] [Full Topic]: https://developer.apple.com/documentation/JavaScriptCore/JSStaticFunction
type JSStaticValue ¶
type JSStaticValue struct {
Name *byte // A null-terminated UTF-8 string that contains the property’s name.
GetProperty JSObjectGetPropertyCallback // A callback to invoke when getting the property’s value.
SetProperty JSObjectSetPropertyCallback // A callback to invoke when setting the property’s value.
Attributes JSPropertyAttributes // A set of property attributes to give to the property.
}
JSStaticValue - A statically declared value property.
[Full Topic] [Full Topic]: https://developer.apple.com/documentation/JavaScriptCore/JSStaticValue
type JSStringRef ¶
type JSStringRef uintptr
JSStringRef is a UTF-16 character buffer.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringRef
func JSGlobalContextCopyName ¶
func JSGlobalContextCopyName(ctx JSGlobalContextRef) JSStringRef
JSGlobalContextCopyName gets a copy of the name of a context.
See: https://developer.apple.com/documentation/JavaScriptCore/JSGlobalContextCopyName(_:)
func JSPropertyNameArrayGetNameAtIndex ¶
func JSPropertyNameArrayGetNameAtIndex(array JSPropertyNameArrayRef, index uintptr) JSStringRef
JSPropertyNameArrayGetNameAtIndex gets a property name at a specified index in a JavaScript property name array.
See: https://developer.apple.com/documentation/JavaScriptCore/JSPropertyNameArrayGetNameAtIndex(_:_:)
func JSStringCreateWithCFString ¶
func JSStringCreateWithCFString(string_ corefoundation.CFStringRef) JSStringRef
JSStringCreateWithCFString creates a JavaScript string from a Core Foundation string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringCreateWithCFString(_:)
func JSStringCreateWithCharacters ¶
func JSStringCreateWithCharacters(chars *JSChar, numChars uintptr) JSStringRef
JSStringCreateWithCharacters creates a JavaScript string from a buffer of Unicode characters.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringCreateWithCharacters(_:_:)
func JSStringCreateWithUTF8CString ¶
func JSStringCreateWithUTF8CString(string_ string) JSStringRef
JSStringCreateWithUTF8CString creates a JavaScript string from a null-terminated UTF-8 string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringCreateWithUTF8CString(_:)
func JSStringRetain ¶
func JSStringRetain(string_ JSStringRef) JSStringRef
JSStringRetain retains a JavaScript string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSStringRetain(_:)
func JSValueCreateJSONString ¶
func JSValueCreateJSONString(ctx JSContextRef, value JSValueRef, indent uint, exception *JSValueRef) JSStringRef
JSValueCreateJSONString creates a JavaScript string that contains the JSON-serialized representation of a JavaScript value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueCreateJSONString(_:_:_:_:)
func JSValueToStringCopy ¶
func JSValueToStringCopy(ctx JSContextRef, value JSValueRef, exception *JSValueRef) JSStringRef
JSValueToStringCopy converts a JavaScript value to a string and copies the result into a JavaScript string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueToStringCopy(_:_:_:)
type JSType ¶
type JSType = KJSType
JSType is an alias for referenced enum type KJSType.
func JSValueGetType ¶
func JSValueGetType(ctx JSContextRef, value JSValueRef) JSType
JSValueGetType returns a JavaScript value’s type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueGetType(_:_:)
type JSTypedArrayBytesDeallocator ¶
JSTypedArrayBytesDeallocator is a function that deallocates bytes that pass to a typed array constructor.
See: https://developer.apple.com/documentation/JavaScriptCore/JSTypedArrayBytesDeallocator
type JSTypedArrayType ¶
type JSTypedArrayType = KJSTypedArrayType
JSTypedArrayType is an alias for referenced enum type KJSTypedArrayType.
func JSValueGetTypedArrayType ¶
func JSValueGetTypedArrayType(ctx JSContextRef, value JSValueRef, exception *JSValueRef) JSTypedArrayType
JSValueGetTypedArrayType returns a JavaScript value’s typed array type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueGetTypedArrayType(_:_:_:)
type JSValue ¶
type JSValue struct {
objectivec.Object
}
A JavaScript value.
Overview ¶
You use the JSValue class to convert basic values, such as numbers and strings, between JavaScript and Objective-C or Swift representations to pass data between native code and JavaScript code. You can also use this class to create JavaScript objects that wrap native objects of custom classes or JavaScript functions with implementations that native methods or blocks provide.
Each JSValue instance originates from a JSContext object that represents the JavaScript execution environment containing that value. The value holds a strong reference to its JSValue.Context object — as long as it retains any value for a particular JSContext instance, that context remains alive. When you invoke an instance method on a JSValue object, and that method returns another JSValue object, the returned value belongs to the same context as the original value.
Each JavaScript value also has an association (indirectly via the JSValue.Context property) with a specific JSVirtualMachine object that represents the underlying set of execution resources for its context. You can pass JSValue instances only to methods on JSValue and JSContext instances on the same virtual machine — attempting to pass a value to a different virtual machine raises an Objective-C exception.
Convert Between JavaScript and Native Types ¶
When you use the JSValue methods for creating, reading, and converting JavaScript values, JavaScriptCore automatically converts native values to JavaScript values and vice versa, using the rules below.
- NSDictionary objects or Swift dictionaries and the keys they contain become JavaScript objects with matching named properties and vice versa. JavaScriptCore recursively copies and converts the values for keys. - NSArray objects or Swift arrays become JavaScript arrays and vice versa, with elements that JavaScriptCore recursively copies and converts. - Objective-C blocks (or Swift closures with the `@convention(block)` attribute) become JavaScript [Function] objects, with parameter and return types that JavaScriptCore converts using the same rules as values. Converting a JavaScript function with a backing from a native block or method returns that block or method; all other JavaScript functions convert as empty dictionaries. - For all other native object types (and class types or metatypes), JavaScriptCore creates a JavaScript wrapper object with a constructor prototype chain that reflects the native class hierarchy. By default, the JavaScript wrapper for a native object doesn’t make that object’s properties and methods available in JavaScript. To choose properties and methods for export to JavaScript, see JSExport.
When you convert an object, method, or block, JavaScriptCore implicitly converts the types and values of object properties and method parameters using the rules below:
[Table data omitted]
Reading and Converting JavaScript Values ¶
- JSValue.ToObject: Converts the JavaScript value to a native object.
- JSValue.ToObjectOfClass: Converts the JavaScript value to a native object of the specified class.
- JSValue.ToBool: Converts the JavaScript value to a native Boolean value.
- JSValue.ToDouble: Converts the JavaScript value to a native floating-point value.
- JSValue.ToInt32: Converts the JavaScript value to a native signed integer value.
- JSValue.ToUInt32: Converts the JavaScript value to a native unsigned integer value.
- JSValue.ToNumber: Converts the JavaScript value to a [NSNumber](<doc://com.apple.documentation/documentation/Foundation/NSNumber>) object.
- JSValue.ToString: Converts the JavaScript value to a native string.
- JSValue.ToDate: Converts the JavaScript value to a date object.
- JSValue.ToArray: Converts the JavaScript value to an array.
- JSValue.ToDictionary: Converts the JavaScript value to a dictionary.
- JSValue.ToPoint: Converts the value to a point structure.
- JSValue.ToRange: Converts the value to a range.
- JSValue.ToRect: Converts the value to a rectangle structure.
- JSValue.ToSize: Converts the value to a size.
Determining the Type of a JavaScript Value ¶
- JSValue.IsUndefined: A Boolean value that indicates whether the instance corresponds to the JavaScript `undefined` value.
- JSValue.IsNull: A Boolean value that indicates whether the instance corresponds to the JavaScript `null` value.
- JSValue.IsBoolean: A Boolean value that indicates whether the instance is a JavaScript Boolean value.
- JSValue.IsNumber: A Boolean value that indicates whether the instance is a JavaScript numeric value.
- JSValue.IsString: A Boolean value that indicates whether the instance is a JavaScript [String] object.
- JSValue.IsObject: A Boolean value that indicates whether the instance is a JavaScript object.
- JSValue.IsArray: A Boolean value that indicates whether the instance is a JavaScript array value.
- JSValue.IsDate: A Boolean value that indicates whether the instance is a JavaScript [Date] object.
- JSValue.IsSymbol: A Boolean value that indicates whether the instance is a symbol.
Comparing JavaScript Values ¶
- JSValue.IsEqualToObject: Compares the value to another for strict equality.
- JSValue.IsEqualWithTypeCoercionToObject: Compares the value to another for equivalence, allowing type conversion.
- JSValue.IsInstanceOf: Returns a Boolean value indicating whether the value is an instance of another JavaScript object value.
Working with Function and Constructor Values ¶
- JSValue.CallWithArguments: Invokes the value as a JavaScript function.
- JSValue.ConstructWithArguments: Invokes the value as a JavaScript constructor.
- JSValue.InvokeMethodWithArguments: Calls the named JavaScript method on the value.
Working with Container Values ¶
- JSValue.DefinePropertyDescriptor: Defines a property on the JavaScript object value or modifies a property’s definition.
- JSValue.HasProperty: Returns a Boolean value indicating whether the JavaScript value has a defined property with the specified name.
- JSValue.DeleteProperty: Deletes the named property from the JavaScript object value.
- JSValue.ValueAtIndex: Returns the value at the specified numeric index in the JavaScript object value.
- JSValue.SetValueAtIndex: Sets the value at the specified numeric index in the JavaScript object value.
- JSValue.ValueForProperty: Returns the value of the named property in the JavaScript object value.
- JSValue.SetValueForProperty: Sets the value of the named property in the JavaScript object value.
Accessing a Value’s JavaScript Context ¶
- JSValue.Context: The JavaScript context hosting this value.
Accessing Values with Subscript Syntax ¶
- JSValue.ObjectAtIndexedSubscript: Returns the value’s JavaScript property at the specified index, allowing subscript syntax.
- JSValue.SetObjectAtIndexedSubscript: Sets the value’s JavaScript property at the specified index, allowing subscript syntax.
- JSValue.ObjectForKeyedSubscript: Returns the value’s JavaScript property named with the specified key, allowing subscript syntax.
- JSValue.SetObjectForKeyedSubscript: Sets the value’s JavaScript property named with the specified key, allowing subscript syntax.
Working with the C JavaScriptCore API ¶
- JSValue.JSValueRef: Returns the C representation of the JavaScript value.
Instance Properties ¶
Instance Methods ¶
- JSValue.CompareDouble
- JSValue.CompareJSValue
- JSValue.CompareUInt64
- JSValue.CompareInt64
- JSValue.ToInt64
- JSValue.ToUInt64
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue
func NewJSValueWithBoolInContext ¶
func NewJSValueWithBoolInContext(value bool, context IJSContext) JSValue
Creates a JavaScript representation of the specified Boolean value.
value: A native Boolean value.
context: The JavaScript context in which to create the value.
Return Value ¶
A JavaScript Boolean value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(bool:in:)
func NewJSValueWithDoubleInContext ¶
func NewJSValueWithDoubleInContext(value float64, context IJSContext) JSValue
Creates a JavaScript representation of the specified floating-point value.
value: A native double-precision floating-point value.
context: The JavaScript context in which to create the value.
Return Value ¶
A JavaScript numeric value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(double:in:)
func NewJSValueWithInt32InContext ¶
func NewJSValueWithInt32InContext(value int32, context IJSContext) JSValue
Creates a JavaScript representation of the specified signed integer value.
value: A native 32-bit signed integer value.
context: The JavaScript context in which to create the value.
Return Value ¶
A JavaScript numeric value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(int32:in:)
func NewJSValueWithJSValueRefInContext ¶
func NewJSValueWithJSValueRefInContext(value JSValueRef, context IJSContext) JSValue
Creates a JavaScript value object from the equivalent C representation.
value: A C JavaScript value reference.
context: The JavaScript context in which to create the value.
Return Value ¶
A JavaScript value object representing the same value.
Discussion ¶
See JSValueRef for the C JavaScriptCore API.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(JSValueRef:inContext:)
func NewJSValueWithNewArrayInContext ¶
func NewJSValueWithNewArrayInContext(context IJSContext) JSValue
Creates a new, empty JavaScript array value.
context: The JavaScript context in which to create the value.
Return Value ¶
An empty JavaScript array value.
Discussion ¶
Calling this method is equivalent to declaring an empty array literal `[]` or using the `new Array()` syntax in JavaScript.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(newArrayIn:)
func NewJSValueWithNewBigIntFromDoubleInContext ¶
func NewJSValueWithNewBigIntFromDoubleInContext(value float64, context IJSContext) JSValue
value: The value of the BigInt JavaScript value being created.
context: The JSContext to which the resulting JSValue belongs.
Return Value ¶
The JSValue representing a JavaScript value with type BigInt.
Discussion ¶
Create a new BigInt value from a double.
If the value is not an integer, an exception is thrown.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(newBigIntFrom:in:)-r38z
func NewJSValueWithNewBigIntFromInt64InContext ¶
func NewJSValueWithNewBigIntFromInt64InContext(int64_ int64, context IJSContext) JSValue
int64: The signed 64-bit integer of the BigInt JavaScript value being created.
context: The JSContext to which the resulting JSValue belongs.
Return Value ¶
The JSValue representing a JavaScript value with type BigInt.
Discussion ¶
Create a new BigInt value from a int64_t.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(newBigIntFrom:in:)-8l9iv
func NewJSValueWithNewBigIntFromStringInContext ¶
func NewJSValueWithNewBigIntFromStringInContext(string_ string, context IJSContext) JSValue
string: The string representation of the BigInt JavaScript value being created.
context: The JSContext to which the resulting JSValue belongs.
Return Value ¶
The JSValue representing a JavaScript value with type BigInt.
Discussion ¶
Create a new BigInt value from a numeric string.
This is equivalent to calling the BigInt constructor from JavaScript with a string argument.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(newBigIntFrom:in:)-1f0xs
func NewJSValueWithNewBigIntFromUInt64InContext ¶
func NewJSValueWithNewBigIntFromUInt64InContext(uint64_ uint64, context IJSContext) JSValue
uint64: The unsigned 64-bit integer of the BigInt JavaScript value being created.
context: The JSContext to which the resulting JSValue belongs.
Return Value ¶
The JSValue representing a JavaScript value with type BigInt.
Discussion ¶
Create a new BigInt value from a uint64_t.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(newBigIntFrom:in:)-7worq
func NewJSValueWithNewErrorFromMessageInContext ¶
func NewJSValueWithNewErrorFromMessageInContext(message string, context IJSContext) JSValue
Creates a JavaScript error value with the specified error message.
message: The error message for the error object.
context: The JavaScript context in which to create the value.
Return Value ¶
A new JavaScript error value.
Discussion ¶
Calling this method creates a JavaScript [Error] object, and is equivalent to calling the [Error] constructor (for example, `new Error("message")`) in JavaScript.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(newErrorFromMessage:in:)
func NewJSValueWithNewObjectInContext ¶
func NewJSValueWithNewObjectInContext(context IJSContext) JSValue
Creates a new, empty JavaScript object value.
context: The JavaScript context in which to create the value.
Return Value ¶
An empty JavaScript object value.
Discussion ¶
Calling this method is equivalent to declaring an empty object literal `{}` or using the `new Object()` syntax in JavaScript.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(newObjectIn:)
func NewJSValueWithNewPromiseRejectedWithReasonInContext ¶
func NewJSValueWithNewPromiseRejectedWithReasonInContext(reason objectivec.IObject, context IJSContext) JSValue
Creates a rejected promise object with the specified value.
reason: The result value to pass to any reactions.
context: The JSContext the resulting JSValue belongs to.
Return Value ¶
A JSValue that represents a new promise JavaScript object.
Discussion ¶
This method is equivalent to calling the following:
func NewJSValueWithNewPromiseResolvedWithResultInContext ¶
func NewJSValueWithNewPromiseResolvedWithResultInContext(result objectivec.IObject, context IJSContext) JSValue
Creates a resolved promise object with the specified value.
result: The result value to pass to any reactions.
context: The JSContext the resulting JSValue belongs to.
Return Value ¶
A JSValue that represents a new promise JavaScript object.
Discussion ¶
This method is equivalent to calling the following:
func NewJSValueWithNewRegularExpressionFromPatternFlagsInContext ¶
func NewJSValueWithNewRegularExpressionFromPatternFlagsInContext(pattern string, flags string, context IJSContext) JSValue
Creates a JavaScript regular expression value from the specified pattern.
pattern: A string to be interpreted as a regular expression pattern.
flags: A combination of zero or more single-letter flags specifying search options.
context: The JavaScript context in which to create the value.
Return Value ¶
A new JavaScript regular expression object.
Discussion ¶
Calling this method creates a JavaScript [RegExp] object, and is equivalent to declaring a regular expression literal (such as `/ab+c/i`) or calling the [RegExp] constructor (for example, `new RegExp("ab+c", "i")`) in JavaScript.
The `flags` parameter can include any of the following options:
- `g` (global match): match all occurrences of the pattern in a string, not just the first. - `i` (ignore case): perform case-insensitive search. - `m` (multiline): treat the `^` and `$` regular expression tokens as matching the start or end of any line in a string (as delimited by newline or return characters), not just the start or end of the entire string.
func NewJSValueWithNewSymbolFromDescriptionInContext ¶
func NewJSValueWithNewSymbolFromDescriptionInContext(description string, context IJSContext) JSValue
Creates a unique symbol object.
description: The description of the symbol object to create.
context: The JSContext the resulting JSValue belongs to.
Return Value ¶
A JSValue that represents a new, unique JavaScript symbol object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(newSymbolFromDescription:in:)
func NewJSValueWithNullInContext ¶
func NewJSValueWithNullInContext(context IJSContext) JSValue
Creates a JavaScript `null` value.
context: The JavaScript context in which to create the value.
Return Value ¶
The JavaScript `null` value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(nullIn:)
func NewJSValueWithObjectInContext ¶
func NewJSValueWithObjectInContext(value objectivec.IObject, context IJSContext) JSValue
Creates a JavaScript value by converting the specified native object.
value: The Objective-C or Swift object to be made available to JavaScript.
context: The JavaScript context in which to create the value.
Return Value ¶
A new JavaScript value representing the object.
Discussion ¶
Converting a native object creates a JavaScript object, including a constructor and prototype chain that reflects the object’s inheritance in the Objective-C or Swift type hierarchy. By default, properties and methods on the converted object are not exposed to JavaScript: to choose which properties and methods should be visible to JavaScript, see JSExport.
Creating a JSValue instance that wraps a native object retains the underlying Objective-C or Swift object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(object:in:)
func NewJSValueWithPointInContext ¶
func NewJSValueWithPointInContext(point corefoundation.CGPoint, context IJSContext) JSValue
Creates a JavaScript representation of the specified point.
point: A CoreGraphics point structure.
context: The JavaScript context in which to create the value.
Return Value ¶
A JavaScript object representing the specified point.
Discussion ¶
Converting a point creates a JavaScript object value with fields named `x` and `y`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(point:inContext:)
func NewJSValueWithRangeInContext ¶
func NewJSValueWithRangeInContext(range_ foundation.NSRange, context IJSContext) JSValue
Creates a JavaScript representation of the specified range.
range: A range.
context: The JavaScript context in which to create the value.
Return Value ¶
A JavaScript object representing the specified range.
Discussion ¶
Converting a range creates a JavaScript object value with fields named `location` and `length`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(range:inContext:)
func NewJSValueWithRectInContext ¶
func NewJSValueWithRectInContext(rect corefoundation.CGRect, context IJSContext) JSValue
Creates a JavaScript representation of the specified rectangle.
rect: A CoreGraphics rectangle structure.
context: The JavaScript context in which to create the value.
Return Value ¶
A JavaScript object representing the specified rectangle.
Discussion ¶
Converting a rectangle creates a JavaScript object value with fields named `x`, `y`, `width`, and `height`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(rect:inContext:)
func NewJSValueWithSizeInContext ¶
func NewJSValueWithSizeInContext(size corefoundation.CGSize, context IJSContext) JSValue
Creates a JavaScript representation of the specified width and height.
size: A CoreGraphics size structure.
context: The JavaScript context in which to create the value.
Return Value ¶
A JavaScript object representing the specified size.
Discussion ¶
Converting a rectangle creates a JavaScript object value with fields named `width` and `height`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(size:inContext:)
func NewJSValueWithUInt32InContext ¶
func NewJSValueWithUInt32InContext(value uint32, context IJSContext) JSValue
Creates a JavaScript representation of the specified unsigned integer value.
value: A native 32-bit unsigned integer value.
context: The JavaScript context in which to create the value.
Return Value ¶
A JavaScript numeric value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(uInt32:in:)
func NewJSValueWithUndefinedInContext ¶
func NewJSValueWithUndefinedInContext(context IJSContext) JSValue
Creates a JavaScript `undefined` value.
context: The JavaScript context in which to create the value.
Return Value ¶
The JavaScript `undefined` value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(undefinedIn:)
func (JSValue) Autorelease ¶
Autorelease adds the receiver to the current autorelease pool.
func (JSValue) CallWithArguments ¶
func (j JSValue) CallWithArguments(arguments foundation.INSArray) IJSValue
Invokes the value as a JavaScript function.
arguments: The parameters to pass to the function. The objects in this array must be other JSValue objects or objects that can be converted to JavaScript values using the methods listed in the Creating JavaScript Values section in JSValue.
Return Value ¶
The result of calling the value as a function, or `nil` if the value cannot be treated as a JavaScript function.
Discussion ¶
In JavaScript, if a function does not explicitly return a value, it implicitly returns the value `undefined`—use the JSValue.IsUndefined property to test for this result.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/call(withArguments:)
func (JSValue) CompareDouble ¶
func (j JSValue) CompareDouble(other float64) JSRelationCondition
Return Value ¶
A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.
Discussion ¶
Compare a JSValue with a double.
The JSValue is converted to a double according to the rules specified by the JavaScript language then compared with other.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/compare(_:)-35b2t
func (JSValue) CompareInt64 ¶
func (j JSValue) CompareInt64(other int64) JSRelationCondition
Return Value ¶
A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.
Discussion ¶
Compare a JSValue with a int64_t.
The JSValue is converted to an integer according to the rules specified by the JavaScript language then compared with other.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/compare(_:)-9d4zq
func (JSValue) CompareJSValue ¶
func (j JSValue) CompareJSValue(other IJSValue) JSRelationCondition
Return Value ¶
A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.
Discussion ¶
Compare two JSValues.
The result is computed by comparing the results of JavaScript’s ==, operators. If either self or other is (or would coerce to) NaN in JavaScript, then the result is kJSRelationConditionUndefined.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/compare(_:)-5w184
func (JSValue) CompareUInt64 ¶
func (j JSValue) CompareUInt64(other uint64) JSRelationCondition
Return Value ¶
A value of JSRelationCondition, a kJSRelationConditionUndefined is returned if an exception is thrown.
Discussion ¶
Compare a JSValue with a uint64_t.
The JSValue is converted to an integer according to the rules specified by the JavaScript language then compared with other.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/compare(_:)-64n3k
func (JSValue) ConstructWithArguments ¶
func (j JSValue) ConstructWithArguments(arguments foundation.INSArray) IJSValue
Invokes the value as a JavaScript constructor.
arguments: The parameters to pass to the constructor. The objects in this array must be other JSValue objects or objects that can be converted to JavaScript values using the methods listed in Creating JavaScript Values.
Return Value ¶
The result of calling the value as a constructor, or `nil` if the value cannot be treated as a JavaScript constructor.
Discussion ¶
Calling a constructor is equivalent to using the `new` keyword in JavaScript.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/construct(withArguments:)
func (JSValue) Context ¶
func (j JSValue) Context() IJSContext
The JavaScript context hosting this value.
Discussion ¶
A value maintains a strong reference to its enclosing JavaScript environment (a JSContext object). As such, you should not store JavaScript values inside objects that are owned by the same JSContext object, as this action creates a retain cycle. To properly manage memory when storing JSValue instances, use the JSManagedValue class.
You can pass a value to other JavaScript contexts with the same virtual machine, but not to contexts with other virtual machines. Use the JSContext.VirtualMachine property of a value’s context to determine which other contexts can use the value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/context
func (JSValue) DefinePropertyDescriptor ¶
func (j JSValue) DefinePropertyDescriptor(property JSValueProperty, descriptor objectivec.IObject)
Defines a property on the JavaScript object value or modifies a property’s definition.
property: The name of the property to define or modify.
descriptor: A JavaScript object whose keys and values define the property’s behavior.
Discussion ¶
Calling this method is equivalent to using the `Object.DefineProperty()` method in JavaScript. The `descriptor` parameter has the same format required by that JavaScript method; for convenience when calling from Objective-C or Swift, you can also construct it as a dictionary with the keys listed in Property Descriptor Keys.
The descriptor determines the behavior of the JavaScript property, and must fit one of three cases:
- Data Descriptor: Contains one or both of the keys `value` and `writable`, and optionally also contains the keys `enumerable` or `configurable`. Cannot contain the keys `get` or `set`. Use a data descriptor to create or modify the attributes of a data property on an object (replacing any existing accessor property). - Accessor Descriptor: Contains one or both of the keys `get` or `set`, and optionally also contains the keys `enumerable` or `configurable`. Cannot contain the keys `value` and `writable`. Use an accessor descriptor to create or modify the attributes of an accessor property on an object (replacing any existing data property). - Generic Descriptor: Contains one or both of the keys `enumerable` or `configurable`, and cannot contain any other keys. Use a genetic descriptor to modify the attributes of an existing data or accessor property, or to create a new data property.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/defineProperty(_:descriptor:)
func (JSValue) DeleteProperty ¶
func (j JSValue) DeleteProperty(property JSValueProperty) bool
Deletes the named property from the JavaScript object value.
property: The name of a property in the JavaScript object value.
Return Value ¶
true if property deletion was successful; otherwise, false.
Discussion ¶
Calling this method is equivalent to using the JavaScript `delete` operator on an object (for example, `delete object.Property()`). After deletion, attempting to retrieve the property’s value results in the undefined value, and any descriptor information that defines the property’s behavior (see the JSValue.DefinePropertyDescriptor method or the JavaScript `defineProperty` function) is lost.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/deleteProperty(_:)
func (JSValue) HasProperty ¶
func (j JSValue) HasProperty(property JSValueProperty) bool
Returns a Boolean value indicating whether the JavaScript value has a defined property with the specified name.
property: The name of a property to query for in the JavaScript object value.
Return Value ¶
true if the JavaScript object has a defined property by that name; otherwise, false.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/hasProperty(_:)
func (JSValue) InvokeMethodWithArguments ¶
func (j JSValue) InvokeMethodWithArguments(method string, arguments foundation.INSArray) IJSValue
Calls the named JavaScript method on the value.
method: The name of a method on the value; that is, of a field whose contents are a function value.
arguments: The parameters to pass to the method. The objects in this array must be other JSValue objects or objects that can be converted to JavaScript values using the methods listed in the Creating JavaScript Values section in JSValue.
Return Value ¶
The result of calling the value as a constructor, or `nil` if the value cannot be treated as a JavaScript constructor.
Discussion ¶
Calling this Objective-C method first uses the JSValue.ValueForProperty method to look up the named field of the JavaScript value. Then, JavaScriptCore treats that field’s contents as a JavaScript function and sets the JavaScript `this` keyword to refer to this JSValue instance.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/invokeMethod(_:withArguments:)
func (JSValue) IsArray ¶
A Boolean value that indicates whether the instance is a JavaScript array value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isArray
func (JSValue) IsBigInt ¶
Discussion ¶
Check if a JSValue is a BigInt.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isBigInt
func (JSValue) IsBoolean ¶
A Boolean value that indicates whether the instance is a JavaScript Boolean value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isBoolean
func (JSValue) IsDate ¶
A Boolean value that indicates whether the instance is a JavaScript [Date] object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isDate
func (JSValue) IsEqualToObject ¶
func (j JSValue) IsEqualToObject(value objectivec.IObject) bool
Compares the value to another for strict equality.
value: The value to be compared against.
Return Value ¶
true if the values are strictly equal; otherwise, false.
Discussion ¶
This method is analogous to the identity or strict equality operator `===` in JavaScript.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isEqual(to:)
func (JSValue) IsEqualWithTypeCoercionToObject ¶
func (j JSValue) IsEqualWithTypeCoercionToObject(value objectivec.IObject) bool
Compares the value to another for equivalence, allowing type conversion.
value: The value to be compared against.
Return Value ¶
true if the values are equivalent; otherwise, false.
Discussion ¶
This method is analogous to the equality operator `==` in JavaScript: it first converts its operands to the same type (if they are not already of the same type), then applies a strict equality comparison to the result. JavaScript object values are equal if and only if they refer to the same object instance.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isEqualWithTypeCoercion(to:)
func (JSValue) IsInstanceOf ¶
func (j JSValue) IsInstanceOf(value objectivec.IObject) bool
Returns a Boolean value indicating whether the value is an instance of another JavaScript object value.
value: The value to be compared against.
Return Value ¶
true if this value inherits from `value`; otherwise, false.
Discussion ¶
This method is analogous to the `instanceof` operator in JavaScript: it tests for the presence of the specified value’s constructor prototype in this value’s prototype chain.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isInstance(of:)
func (JSValue) IsNull ¶
A Boolean value that indicates whether the instance corresponds to the JavaScript `null` value.
Discussion ¶
The JavaScript `null` value is used only in cases where an actual value is expected but none is applicable. Note that `null` is not the same as `undefined`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isNull
func (JSValue) IsNumber ¶
A Boolean value that indicates whether the instance is a JavaScript numeric value.
Discussion ¶
In JavaScript, there is no differentiation between types of numbers. Semantically, all numbers behave as double-precision floating-point types, except in special cases like bit operations.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isNumber
func (JSValue) IsObject ¶
A Boolean value that indicates whether the instance is a JavaScript object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isObject
func (JSValue) IsString ¶
A Boolean value that indicates whether the instance is a JavaScript [String] object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isString
func (JSValue) IsSymbol ¶
A Boolean value that indicates whether the instance is a symbol.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isSymbol
func (JSValue) IsUndefined ¶
A Boolean value that indicates whether the instance corresponds to the JavaScript `undefined` value.
Discussion ¶
The JavaScript `undefined` value is used for variables that have not yet been assigned a value, for formal parameters in functions for which no actual parameter has been passed, and as the result of expressions or function calls that do not explicitly return a value. Note that `undefined` is not the same as `null`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/isUndefined
func (JSValue) JSValueRef ¶
func (j JSValue) JSValueRef() JSValueRef
Returns the C representation of the JavaScript value.
Discussion ¶
See JSValueRef for the C JavaScriptCore API.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/jsValueRef
func (JSValue) ObjectAtIndexedSubscript ¶
Returns the value’s JavaScript property at the specified index, allowing subscript syntax.
index: An index in the JavaScript object.
Return Value ¶
The value at the specified index, or the JavaScript `undefined` value if no property exists at that index.
Discussion ¶
This method is equivalent to the JSValue.ValueAtIndex method, but provides Objective-C subscripting support.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/objectAtIndexedSubscript(_:)
func (JSValue) ObjectForKeyedSubscript ¶
func (j JSValue) ObjectForKeyedSubscript(key objectivec.IObject) IJSValue
Returns the value’s JavaScript property named with the specified key, allowing subscript syntax.
key: The name of a property in the JavaScript object.
Return Value ¶
The value of the named property, or the JavaScript `undefined` value if no property exists by that name.
Discussion ¶
This method is equivalent to the JSValue.ValueForProperty method, but provides Objective-C subscripting support.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/objectForKeyedSubscript(_:)
func (JSValue) SetObjectAtIndexedSubscript ¶
func (j JSValue) SetObjectAtIndexedSubscript(object objectivec.IObject, index uint)
Sets the value’s JavaScript property at the specified index, allowing subscript syntax.
object: The value to set at the specified index.
index: An index in the JavaScript object.
Discussion ¶
This method is equivalent to the JSValue.SetValueAtIndex method, but provides Objective-C subscripting support.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/setObject(_:atIndexedSubscript:)
func (JSValue) SetObjectForKeyedSubscript ¶
func (j JSValue) SetObjectForKeyedSubscript(object objectivec.IObject, key objectivec.IObject)
Sets the value’s JavaScript property named with the specified key, allowing subscript syntax.
object: The value to set for the named JavaScript property.
key: The name of a property in the JavaScript object.
Discussion ¶
This method is equivalent to the JSValue.SetValueForProperty method, but provides Objective-C subscripting support.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/setObject(_:forKeyedSubscript:)
func (JSValue) SetValueAtIndex ¶
func (j JSValue) SetValueAtIndex(value objectivec.IObject, index uint)
Sets the value at the specified numeric index in the JavaScript object value.
value: The value to set at the specified index.
index: An index in the JavaScript object.
Discussion ¶
Calling this method is equivalent to using the subscript operator with a numeric subscript in JavaScript. Use it to access elements of JavaScript arrays or of objects with numerically-indexed properties.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/setValue(_:at:)
func (JSValue) SetValueForProperty ¶
func (j JSValue) SetValueForProperty(value objectivec.IObject, property JSValueProperty)
Sets the value of the named property in the JavaScript object value.
value: The value to set for the named property.
property: The name of a property in the JavaScript object.
Discussion ¶
Calling this method is equivalent to using the subscript operator with a string subscript in JavaScript. Use it to set or create fields or properties in JavaScript objects.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/setValue(_:forProperty:)
func (JSValue) ToArray ¶
func (j JSValue) ToArray() foundation.INSArray
Converts the JavaScript value to an array.
Return Value ¶
The array representation of the value.
Discussion ¶
If the value is a JavaScript object, this method reads the object’s `length` property as an unsigned integer, creates an NSArray object of the corresponding size, and recursively copies and converts any properties corresponding to indices within the array bounds. JavaScript converts each element to a native object using the rules listed in JSValue.
This method returns `nil` if the JavaScript value is `null` or `undefined`, and throws a JavaScript [TypeError] if the value is not a JavaScript object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toArray()
func (JSValue) ToBool ¶
Converts the JavaScript value to a native Boolean value.
Return Value ¶
The native Boolean value.
Discussion ¶
This method uses JavaScript type coercion to convert the value to a JavaScript Boolean value, then returns the native representation of the result. Thus, this method can return true even when the JSValue.IsBoolean property does not.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toBool()
func (JSValue) ToDate ¶
func (j JSValue) ToDate() foundation.NSDate
Converts the JavaScript value to a date object.
Return Value ¶
The date representation of the value.
Discussion ¶
If the value contains a JavaScript [Date] object, this method returns an equivalent NSDate representation. Otherwise, this method uses JavaScript type coercion to interpret the value as a number of seconds and creates an NSDate object with the doc://com.apple.documentation/documentation/foundation/nsdate/1591576-datewithtimeintervalsince1970 method.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toDate()
func (JSValue) ToDictionary ¶
func (j JSValue) ToDictionary() foundation.INSDictionary
Converts the JavaScript value to a dictionary.
Return Value ¶
The dictionary representation of the value.
Discussion ¶
If the value is a JavaScript object, this method creates an NSDictionary object of the corresponding size, and recursively copies and converts all enumerable properties of the object into the dictionary with correspondingly named keys. JavaScript converts each element to a native object using the rules listed in JSValue.
This method returns `nil` if the JavaScript value is `null` or `undefined`, and throws a JavaScript [TypeError] if the value is not a JavaScript object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toDictionary()
func (JSValue) ToDouble ¶
Converts the JavaScript value to a native floating-point value.
Return Value ¶
The native double-precision floating-point value.
Discussion ¶
This method uses JavaScript type coercion to convert the value to a JavaScript numeric value, then returns a native representation of the result. In JavaScript, all numeric values are treated as double-precision floating-point numbers except for certain operations such as bit shifts.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toDouble()
func (JSValue) ToInt32 ¶
Converts the JavaScript value to a native signed integer value.
Return Value ¶
The native signed 32-bit integer value.
Discussion ¶
This method uses JavaScript type coercion to convert the value to a JavaScript integer value, then returns a native representation of the result. In JavaScript, all numeric values are treated as double-precision floating-point numbers except for certain operations such as bit shifts.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toInt32()
func (JSValue) ToInt64 ¶
Discussion ¶
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.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toInt64()
func (JSValue) ToNumber ¶
func (j JSValue) ToNumber() foundation.NSNumber
Converts the JavaScript value to a NSNumber object.
Return Value ¶
A NSNumber object encapsulating the native representation of the value.
Discussion ¶
If the value represents a Boolean value, the resulting NSNumber object is created as with the doc://com.apple.documentation/documentation/foundation/nsnumber/1551475-numberwithbool method. Otherwise, this method uses JavaScript type coercion to convert the value to a JavaScript numeric value and creates a NSNumber object wrapping the result.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toNumber()
func (JSValue) ToObject ¶
func (j JSValue) ToObject() objectivec.IObject
Converts the JavaScript value to a native object.
Return Value ¶
An Objective-C or Swift object representing the JavaScript value.
Discussion ¶
The type of the resulting object depends on the contents of the JavaScript value. For conversion rules, see JSValue.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toObject()
func (JSValue) ToObjectOfClass ¶
func (j JSValue) ToObjectOfClass(expectedClass objectivec.Class) objectivec.IObject
Converts the JavaScript value to a native object of the specified class.
expectedClass: The Objective-C or Swift class type to convert the value to.
Return Value ¶
An Objective-C or Swift object representing the JavaScript value, or `nil` if the value cannot be converted to the expected class.
Discussion ¶
Use this method to enforce a specific type conversion from JavaScript, or to retrieve Objective-C or Swift objects of custom classes that were bridged into JavaScript using the JSExport protocol.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toObjectOf(_:)
func (JSValue) ToPoint ¶
func (j JSValue) ToPoint() corefoundation.CGPoint
Converts the value to a point structure.
Return Value ¶
A CoreGraphics point representation of the value.
Discussion ¶
This method treats the value as a JavaScript object, reading the values of its `x` and `y` properties using the JSValue.ToDouble method and creating a CGPoint structure from the result. If the value is not a JavaScript object or does not have the appropriate properties, each of the resulting point’s coordinates is not a number (NaN).
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toPoint()
func (JSValue) ToRange ¶
func (j JSValue) ToRange() foundation.NSRange
Converts the value to a range.
Return Value ¶
A range representation of the value.
Discussion ¶
This method treats the value as a JavaScript object, reading the values of its `location` and `length` properties using the JSValue.ToDouble method and creating a NSRange structure from the result. If the value is not a JavaScript object or does not have the appropriate properties, the resulting range is invalid.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toRange()
func (JSValue) ToRect ¶
func (j JSValue) ToRect() corefoundation.CGRect
Converts the value to a rectangle structure.
Return Value ¶
A CoreGraphics point representation of the value.
Discussion ¶
This method treats the value as a JavaScript object, reading the values of its `x`, `y`, `width`, and `height` properties using the JSValue.ToDouble method and creating a CGRect structure from the result. If the value is not a JavaScript object or does not have the appropriate properties, each of the resulting rectangle’s coordinates is not a number (NaN).
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toRect()
func (JSValue) ToSize ¶
func (j JSValue) ToSize() corefoundation.CGSize
Converts the value to a size.
Return Value ¶
A CoreGraphics size representation of the value.
Discussion ¶
This method treats the value as a JavaScript object, reading the values of its `width` and `height` properties using the JSValue.ToDouble method and creating a CGSize structure from the result. If the value is not a JavaScript object or does not have the appropriate properties, the size’s width and height are each not a number (NaN).
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toSize()
func (JSValue) ToString ¶
Converts the JavaScript value to a native string.
Return Value ¶
The string representation of the value.
Discussion ¶
This method uses JavaScript type coercion rules to convert the value to a JavaScript string, then creates a native string from the result. Thus, this method can return a string even when the JSValue.IsString property is false; for example, an empty object becomes the string `"[object Object]"`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toString()
func (JSValue) ToUInt32 ¶
Converts the JavaScript value to a native unsigned integer value.
Return Value ¶
The native unsigned 32-bit integer value.
Discussion ¶
This method uses JavaScript type coercion to convert the value to a JavaScript integer value, then returns a native representation of the result. In JavaScript, all numeric values are treated as double-precision floating-point numbers except for certain operations such as bit shifts.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toUInt32()
func (JSValue) ToUInt64 ¶
Discussion ¶
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.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/toUInt64()
func (JSValue) ValueAtIndex ¶
Returns the value at the specified numeric index in the JavaScript object value.
index: An index in the JavaScript object.
Return Value ¶
The value at the specified index, or the JavaScript `undefined` value if no property exists at that index.
Discussion ¶
Calling this method is equivalent to using the subscript operator with a numeric subscript in JavaScript. Use it to access elements of JavaScript arrays or of objects with numerically-indexed properties.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/atIndex(_:)
func (JSValue) ValueForProperty ¶
func (j JSValue) ValueForProperty(property JSValueProperty) IJSValue
Returns the value of the named property in the JavaScript object value.
property: The name of a property in the JavaScript object.
Return Value ¶
The value of the named property, or the JavaScript `undefined` value if no property exists by that name.
Discussion ¶
Calling this method is equivalent to using the subscript operator with a string subscript in JavaScript. Use it to access fields or properties in JavaScript objects.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/forProperty(_:)
type JSValueClass ¶
type JSValueClass struct {
// contains filtered or unexported fields
}
func GetJSValueClass ¶
func GetJSValueClass() JSValueClass
GetJSValueClass returns the class object for JSValue.
func (JSValueClass) Alloc ¶
func (jc JSValueClass) Alloc() JSValue
Alloc allocates memory for a new instance of the class.
func (JSValueClass) Class ¶
func (jc JSValueClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
func (JSValueClass) ValueWithNewPromiseInContextFromExecutor ¶
func (_JSValueClass JSValueClass) ValueWithNewPromiseInContextFromExecutor(context IJSContext, callback JSValueJSValueHandler) JSValue
Creates a promise object using the specified executor callback.
context: The JSContext the resulting JSValue belongs to.
callback: A callback block to invoke during initialization of the promise object. The `resolve` and `reject` parameters are functions that you can call to notify any pending reactions about the state of the new promise object.
Return Value ¶
A JSValue that represents a new promise JavaScript object.
Discussion ¶
This method is equivalent to calling the `Promise()` constructor in JavaScript.
The `resolve` and `reject` callbacks each typically take a single value, which they forward to all relevant pending reactions. While inside the executor callback, `context` acts as if it is in any other callback, except `calleeFunction` is `nil`. This also means you can access the new promise object using `[context thisValue]`.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValue/init(newPromiseIn:fromExecutor:)
type JSValueJSValueHandler ¶
JSValueJSValueHandler handles A callback block to invoke during initialization of the promise object.
Used by:
- [JSValue.ValueWithNewPromiseInContextFromExecutor]
type JSValueProperty ¶
type JSValueProperty = objectivec.Object
JSValueProperty is a type that identifies a property of a JavaScript value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueProperty
type JSValueRef ¶
type JSValueRef uintptr
JSValueRef is a JavaScript value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueRef
func JSBigIntCreateWithDouble ¶
func JSBigIntCreateWithDouble(ctx JSContextRef, value float64, exception *JSValueRef) JSValueRef
JSBigIntCreateWithDouble.
See: https://developer.apple.com/documentation/JavaScriptCore/JSBigIntCreateWithDouble(_:_:_:)
func JSBigIntCreateWithInt64 ¶
func JSBigIntCreateWithInt64(ctx JSContextRef, integer int64, exception *JSValueRef) JSValueRef
JSBigIntCreateWithInt64.
See: https://developer.apple.com/documentation/JavaScriptCore/JSBigIntCreateWithInt64(_:_:_:)
func JSBigIntCreateWithString ¶
func JSBigIntCreateWithString(ctx JSContextRef, string_ JSStringRef, exception *JSValueRef) JSValueRef
JSBigIntCreateWithString.
See: https://developer.apple.com/documentation/JavaScriptCore/JSBigIntCreateWithString(_:_:_:)
func JSBigIntCreateWithUInt64 ¶
func JSBigIntCreateWithUInt64(ctx JSContextRef, integer uint64, exception *JSValueRef) JSValueRef
JSBigIntCreateWithUInt64.
See: https://developer.apple.com/documentation/JavaScriptCore/JSBigIntCreateWithUInt64(_:_:_:)
func JSEvaluateScript ¶
func JSEvaluateScript(ctx JSContextRef, script JSStringRef, thisObject JSObjectRef, sourceURL JSStringRef, startingLineNumber int, exception *JSValueRef) JSValueRef
JSEvaluateScript evaluates a string of JavaScript.
See: https://developer.apple.com/documentation/JavaScriptCore/JSEvaluateScript(_:_:_:_:_:_:)
func JSObjectCallAsFunction ¶
func JSObjectCallAsFunction(ctx JSContextRef, object JSObjectRef, thisObject JSObjectRef, argumentCount uintptr, arguments JSValueRef, exception *JSValueRef) JSValueRef
JSObjectCallAsFunction calls an object as a function.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectCallAsFunction(_:_:_:_:_:_:)
func JSObjectGetProperty ¶
func JSObjectGetProperty(ctx JSContextRef, object JSObjectRef, propertyName JSStringRef, exception *JSValueRef) JSValueRef
JSObjectGetProperty gets a property from an object.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetProperty(_:_:_:_:)
func JSObjectGetPropertyAtIndex ¶
func JSObjectGetPropertyAtIndex(ctx JSContextRef, object JSObjectRef, propertyIndex uint, exception *JSValueRef) JSValueRef
JSObjectGetPropertyAtIndex gets a property from an object by numeric index.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetPropertyAtIndex(_:_:_:_:)
func JSObjectGetPropertyForKey ¶
func JSObjectGetPropertyForKey(ctx JSContextRef, object JSObjectRef, propertyKey JSValueRef, exception *JSValueRef) JSValueRef
JSObjectGetPropertyForKey gets a property from an object using a JavaScript value as the property key.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetPropertyForKey(_:_:_:_:)
func JSObjectGetPrototype ¶
func JSObjectGetPrototype(ctx JSContextRef, object JSObjectRef) JSValueRef
JSObjectGetPrototype gets an object’s prototype.
See: https://developer.apple.com/documentation/JavaScriptCore/JSObjectGetPrototype(_:_:)
func JSValueMakeBoolean ¶
func JSValueMakeBoolean(ctx JSContextRef, boolean bool) JSValueRef
JSValueMakeBoolean creates a JavaScript Boolean value.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueMakeBoolean(_:_:)
func JSValueMakeFromJSONString ¶
func JSValueMakeFromJSONString(ctx JSContextRef, string_ JSStringRef) JSValueRef
JSValueMakeFromJSONString creates a JavaScript value from a JSON-formatted string.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueMakeFromJSONString(_:_:)
func JSValueMakeNull ¶
func JSValueMakeNull(ctx JSContextRef) JSValueRef
JSValueMakeNull creates a JavaScript value of the null type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueMakeNull(_:)
func JSValueMakeNumber ¶
func JSValueMakeNumber(ctx JSContextRef, number float64) JSValueRef
JSValueMakeNumber creates a JavaScript value of the number type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueMakeNumber(_:_:)
func JSValueMakeString ¶
func JSValueMakeString(ctx JSContextRef, string_ JSStringRef) JSValueRef
JSValueMakeString creates a JavaScript value of the string type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueMakeString(_:_:)
func JSValueMakeSymbol ¶
func JSValueMakeSymbol(ctx JSContextRef, description JSStringRef) JSValueRef
JSValueMakeSymbol creates a JavaScript value of the symbol type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueMakeSymbol(_:_:)
func JSValueMakeUndefined ¶
func JSValueMakeUndefined(ctx JSContextRef) JSValueRef
JSValueMakeUndefined creates a JavaScript value of the undefined type.
See: https://developer.apple.com/documentation/JavaScriptCore/JSValueMakeUndefined(_:)
type JSVirtualMachine ¶
type JSVirtualMachine struct {
objectivec.Object
}
A self-contained environment for JavaScript execution.
Overview ¶
You use this class for two main purposes: to support concurrent JavaScript execution, and to manage memory for objects that bridge between JavaScript and Objective-C or Swift.
Support Threading and Concurrent JavaScript Execution ¶
Each JavaScript context (a JSContext object) belongs to a virtual machine. Each virtual machine can encompass multiple contexts, allowing values (JSValue objects) to pass between contexts. However, each virtual machine is distinct—you can’t pass a value that you create in one virtual machine to a context in another virtual machine.
The JavaScriptCore API is thread-safe—for example, you can create JSValue objects or evaluate scripts from any thread—however, all other threads attempting to use the same virtual machine must wait. To run JavaScript concurrently on multiple threads, use a separate JSVirtualMachine instance for each thread.
Manage Memory for Exported Objects ¶
When you export an Objective-C or Swift object to JavaScript, you must not to store JavaScript values in that object. This action creates a retain cycle—JSValue objects hold strong references to their enclosing JavaScript contexts, and JSContext objects hold strong references to the native objects you export to JavaScript. Instead, use the JSManagedValue class to conditionally retain a JavaScript value, and report the native ownership chain for that managed value to the JavaScriptCore virtual machine. Use the JSVirtualMachine.AddManagedReferenceWithOwner and JSVirtualMachine.RemoveManagedReferenceWithOwner methods to describe your native object graph to JavaScriptCore. After you remove the last managed reference for an object, the JavaScript garbage collector can safely destroy that object.
Managing Memory for Bridged Values ¶
- JSVirtualMachine.AddManagedReferenceWithOwner: Notifies the JavaScriptCore virtual machine of an external object relationship.
- JSVirtualMachine.RemoveManagedReferenceWithOwner: Notifies the JavaScriptCore virtual machine that a previously registered object relationship no longer exists.
See: https://developer.apple.com/documentation/JavaScriptCore/JSVirtualMachine
func JSVirtualMachineFromID ¶
func JSVirtualMachineFromID(id objc.ID) JSVirtualMachine
JSVirtualMachineFromID constructs a JSVirtualMachine from an objc.ID.
A self-contained environment for JavaScript execution.
func NewJSVirtualMachine ¶
func NewJSVirtualMachine() JSVirtualMachine
NewJSVirtualMachine creates a new JSVirtualMachine instance.
func (JSVirtualMachine) AddManagedReferenceWithOwner ¶
func (j JSVirtualMachine) AddManagedReferenceWithOwner(object objectivec.IObject, owner objectivec.IObject)
Notifies the JavaScriptCore virtual machine of an external object relationship.
object: The object to be referenced by the JavaScript memory management graph.
owner: The other object responsible for the lifetime of the reference.
Discussion ¶
Use this method to make the JavaScript runtime aware of arbitrary external Objective-C or Swift object graphs. The runtime can then use this information to retain any JavaScript values that are referenced from somewhere in said object graph.
For correct behavior, clients must make their external object graphs reachable from within the JavaScript runtime. If an Objective-C or Swift object is reachable from within the JavaScript runtime, all managed references transitively reachable from it as recorded using the JSVirtualMachine.AddManagedReferenceWithOwner method are scanned by the garbage collector.
func (JSVirtualMachine) Autorelease ¶
func (j JSVirtualMachine) Autorelease() JSVirtualMachine
Autorelease adds the receiver to the current autorelease pool.
func (JSVirtualMachine) Init ¶
func (j JSVirtualMachine) Init() JSVirtualMachine
Init initializes the instance.
func (JSVirtualMachine) RemoveManagedReferenceWithOwner ¶
func (j JSVirtualMachine) RemoveManagedReferenceWithOwner(object objectivec.IObject, owner objectivec.IObject)
Notifies the JavaScriptCore virtual machine that a previously registered object relationship no longer exists.
object: The object formerly referenced by the JavaScript memory management graph.
owner: The other object responsible for the lifetime of the reference.
Discussion ¶
Use this method to deregister object relationships recorded using the JSVirtualMachine.AddManagedReferenceWithOwner method.
The JavaScript garbage collector continues to scan any references that were reported to it until you use this method to remove those references.
type JSVirtualMachineClass ¶
type JSVirtualMachineClass struct {
// contains filtered or unexported fields
}
func GetJSVirtualMachineClass ¶
func GetJSVirtualMachineClass() JSVirtualMachineClass
GetJSVirtualMachineClass returns the class object for JSVirtualMachine.
func (JSVirtualMachineClass) Alloc ¶
func (jc JSVirtualMachineClass) Alloc() JSVirtualMachine
Alloc allocates memory for a new instance of the class.
func (JSVirtualMachineClass) Class ¶
func (jc JSVirtualMachineClass) Class() objc.Class
Class returns the underlying Objective-C class pointer.
type KJSClassAttribute ¶
type KJSClassAttribute uint
const ( // KJSClassAttributeNoAutomaticPrototype: An attribute that specifies that a class doesn’t automatically generate a shared prototype for its instance objects. KJSClassAttributeNoAutomaticPrototype KJSClassAttribute = 2 // KJSClassAttributeNone: An attribute that specifies that a class has no special attributes. KJSClassAttributeNone KJSClassAttribute = 0 )
func (KJSClassAttribute) String ¶
func (e KJSClassAttribute) String() string
type KJSPropertyAttribute ¶
type KJSPropertyAttribute uint
const ( // KJSPropertyAttributeDontDelete: An attribute that specifies that the delete operation fails on a property. KJSPropertyAttributeDontDelete KJSPropertyAttribute = 8 // KJSPropertyAttributeDontEnum: An attribute that specifies that property enumerators and JavaScript for-in loops don’t enumerate a property. KJSPropertyAttributeDontEnum KJSPropertyAttribute = 4 // KJSPropertyAttributeNone: An attribute that specifies that a property has no special attributes. KJSPropertyAttributeNone KJSPropertyAttribute = 0 // KJSPropertyAttributeReadOnly: An attribute that specifies that a property is read-only. KJSPropertyAttributeReadOnly KJSPropertyAttribute = 2 )
func (KJSPropertyAttribute) String ¶
func (e KJSPropertyAttribute) String() string
type KJSType ¶
type KJSType uint
const ( KJSTypeBigInt KJSType = 7 // KJSTypeBoolean: A primitive Boolean value. KJSTypeBoolean KJSType = 2 // KJSTypeNull: The unique null value. KJSTypeNull KJSType = 1 // KJSTypeNumber: A primitive number value. KJSTypeNumber KJSType = 3 // KJSTypeObject: An object value. KJSTypeObject KJSType = 5 // KJSTypeString: A primitive string value. KJSTypeString KJSType = 4 // KJSTypeSymbol: A primitive symbol value. KJSTypeSymbol KJSType = 6 // KJSTypeUndefined: The unique undefined value. KJSTypeUndefined KJSType = 0 )
type KJSTypedArrayType ¶
type KJSTypedArrayType uint
const ( // KJSTypedArrayTypeArrayBuffer: An array buffer type. KJSTypedArrayTypeArrayBuffer KJSTypedArrayType = 9 KJSTypedArrayTypeBigInt64Array KJSTypedArrayType = 11 KJSTypedArrayTypeBigUint64Array KJSTypedArrayType = 12 // KJSTypedArrayTypeFloat32Array: A 32-bit floating point array type. KJSTypedArrayTypeFloat32Array KJSTypedArrayType = 7 // KJSTypedArrayTypeFloat64Array: A 64-bit floating point array type. KJSTypedArrayTypeFloat64Array KJSTypedArrayType = 8 // KJSTypedArrayTypeInt16Array: A 16-bit integer array type. KJSTypedArrayTypeInt16Array KJSTypedArrayType = 1 // KJSTypedArrayTypeInt32Array: A 32-bit integer array type. KJSTypedArrayTypeInt32Array KJSTypedArrayType = 2 // KJSTypedArrayTypeInt8Array: An 8-bit integer array type. KJSTypedArrayTypeInt8Array KJSTypedArrayType = 0 // KJSTypedArrayTypeNone: Not a typed array. KJSTypedArrayTypeNone KJSTypedArrayType = 10 // KJSTypedArrayTypeUint16Array: A 16-bit unsigned integer array type. KJSTypedArrayTypeUint16Array KJSTypedArrayType = 5 // KJSTypedArrayTypeUint32Array: A 32-bit unsigned integer array type. KJSTypedArrayTypeUint32Array KJSTypedArrayType = 6 // KJSTypedArrayTypeUint8Array: An 8-bit unsigned integer array type. KJSTypedArrayTypeUint8Array KJSTypedArrayType = 3 // KJSTypedArrayTypeUint8ClampedArray: An 8-bit unsigned integer clamped array type. KJSTypedArrayTypeUint8ClampedArray KJSTypedArrayType = 4 )
func (KJSTypedArrayType) String ¶
func (e KJSTypedArrayType) String() string