Bindings for JSObjectRef.h.
Classes, callbacks, properties, functions, constructors and promises. Availability floors from the SDK headers are noted per item.
Struct layout mirrors JSClassDefinition exactly (version first, convertToType last); completeStruct keeps it honest.
Types
JSClassAttributes = cuint
- Bitmask of kJSClassAttribute* flags.
JSClassDefinition {.bycopy, completeStruct.} = object version*: cint attributes*: JSClassAttributes className*: cstring parentClass*: JSClassRef staticValues*: ptr JSStaticValue staticFunctions*: ptr JSStaticFunction initialize*: JSObjectInitializeCallback finalize*: JSObjectFinalizeCallback hasProperty*: JSObjectHasPropertyCallback getProperty*: JSObjectGetPropertyCallback setProperty*: JSObjectSetPropertyCallback deleteProperty*: JSObjectDeletePropertyCallback getPropertyNames*: JSObjectGetPropertyNamesCallback callAsFunction*: JSObjectCallAsFunctionCallback callAsConstructor*: JSObjectCallAsConstructorCallback hasInstance*: JSObjectHasInstanceCallback convertToType*: JSObjectConvertToTypeCallback
JSObjectCallAsConstructorCallback = proc (ctx: JSContextRef; constructor: JSObjectRef; argumentCount: csize_t; arguments: ptr JSValueRef; exception: ptr JSValueRef): JSObjectRef {.cdecl.}
JSObjectCallAsFunctionCallback = proc (ctx: JSContextRef; function: JSObjectRef; thisObject: JSObjectRef; argumentCount: csize_t; arguments: ptr JSValueRef; exception: ptr JSValueRef): JSValueRef {. cdecl.}
JSObjectConvertToTypeCallback = proc (ctx: JSContextRef; obj: JSObjectRef; kind: JSType; exception: ptr JSValueRef): JSValueRef {. cdecl.}
JSObjectDeletePropertyCallback = proc (ctx: JSContextRef; obj: JSObjectRef; propertyName: JSStringRef; exception: ptr JSValueRef): bool {.cdecl.}
JSObjectFinalizeCallback = proc (obj: JSObjectRef) {.cdecl.}
- No JS API calls allowed inside (any thread, GC-unsafe).
JSObjectGetPropertyCallback = proc (ctx: JSContextRef; obj: JSObjectRef; propertyName: JSStringRef; exception: ptr JSValueRef): JSValueRef {. cdecl.}
JSObjectGetPropertyNamesCallback = proc (ctx: JSContextRef; obj: JSObjectRef; propertyNames: JSPropertyNameAccumulatorRef) {.cdecl.}
JSObjectHasInstanceCallback = proc (ctx: JSContextRef; constructor: JSObjectRef; possibleInstance: JSValueRef; exception: ptr JSValueRef): bool {.cdecl.}
JSObjectHasPropertyCallback = proc (ctx: JSContextRef; obj: JSObjectRef; propertyName: JSStringRef): bool {.cdecl.}
JSObjectInitializeCallback = proc (ctx: JSContextRef; obj: JSObjectRef) {.cdecl.}
JSObjectSetPropertyCallback = proc (ctx: JSContextRef; obj: JSObjectRef; propertyName: JSStringRef; value: JSValueRef; exception: ptr JSValueRef): bool {. cdecl.}
JSPropertyAttributes = cuint
- Bitmask of kJSPropertyAttribute* flags.
JSStaticFunction {.bycopy, completeStruct.} = object name*: cstring callAsFunction*: JSObjectCallAsFunctionCallback attributes*: JSPropertyAttributes
JSStaticValue {.bycopy, completeStruct.} = object name*: cstring getProperty*: JSObjectGetPropertyCallback setProperty*: JSObjectSetPropertyCallback attributes*: JSPropertyAttributes
Consts
kJSClassAttributeNone = 0'u
kJSClassDefinitionEmpty = (version: 0'i32, attributes: 0'u32, className: nil, parentClass: nil, staticValues: nil, staticFunctions: nil, initialize: nil, finalize: nil, hasProperty: nil, getProperty: nil, setProperty: nil, deleteProperty: nil, getPropertyNames: nil, callAsFunction: nil, callAsConstructor: nil, hasInstance: nil, convertToType: nil)
- Zero definition, version 0. Copy before filling in. (C also exports this as an extern const; this Nim const is its zero value.)
kJSPropertyAttributeNone = 0'u
Procs
proc JSClassCreate(definition: ptr JSClassDefinition): JSClassRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- Create Rule.
proc JSClassRelease(jsClass: JSClassRef) {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSClassRetain(jsClass: JSClassRef): JSClassRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectCallAsConstructor(ctx: JSContextRef; obj: JSObjectRef; argumentCount: csize_t; arguments: ptr JSValueRef; exception: ptr JSValueRef): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectCallAsFunction(ctx: JSContextRef; obj: JSObjectRef; thisObject: JSObjectRef; argumentCount: csize_t; arguments: ptr JSValueRef; exception: ptr JSValueRef): JSValueRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- Nil thisObject uses the global object. Nil on exception/not-a-function.
proc JSObjectCopyPropertyNames(ctx: JSContextRef; obj: JSObjectRef): JSPropertyNameArrayRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- Create Rule.
proc JSObjectDeleteProperty(ctx: JSContextRef; obj: JSObjectRef; propertyName: JSStringRef; exception: ptr JSValueRef): bool {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectDeletePropertyForKey(ctx: JSContextRef; obj: JSObjectRef; propertyKey: JSValueRef; exception: ptr JSValueRef): bool {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- macOS 10.15+.
proc JSObjectGetPrivate(obj: JSObjectRef): pointer {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- Borrowed private data, or nil.
proc JSObjectGetProperty(ctx: JSContextRef; obj: JSObjectRef; propertyName: JSStringRef; exception: ptr JSValueRef): JSValueRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectGetPropertyAtIndex(ctx: JSContextRef; obj: JSObjectRef; propertyIndex: cuint; exception: ptr JSValueRef): JSValueRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectGetPropertyForKey(ctx: JSContextRef; obj: JSObjectRef; propertyKey: JSValueRef; exception: ptr JSValueRef): JSValueRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- object[propertyKey]. macOS 10.15+.
proc JSObjectGetPrototype(ctx: JSContextRef; obj: JSObjectRef): JSValueRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectHasProperty(ctx: JSContextRef; obj: JSObjectRef; propertyName: JSStringRef): bool {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectHasPropertyForKey(ctx: JSContextRef; obj: JSObjectRef; propertyKey: JSValueRef; exception: ptr JSValueRef): bool {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- propertyKey in object. macOS 10.15+.
proc JSObjectIsConstructor(ctx: JSContextRef; obj: JSObjectRef): bool {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectIsFunction(ctx: JSContextRef; obj: JSObjectRef): bool {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectMake(ctx: JSContextRef; jsClass: JSClassRef; data: pointer): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- Nil class uses the default object class. data needs a non-nil class to be stored; readable via GetPrivate.
proc JSObjectMakeArray(ctx: JSContextRef; argumentCount: csize_t; arguments: ptr JSValueRef; exception: ptr JSValueRef): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- macOS 10.6+. One argument makes a one-element array (unlike new Array).
proc JSObjectMakeConstructor(ctx: JSContextRef; jsClass: JSClassRef; callAsConstructor: JSObjectCallAsConstructorCallback): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectMakeDate(ctx: JSContextRef; argumentCount: csize_t; arguments: ptr JSValueRef; exception: ptr JSValueRef): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- macOS 10.6+.
proc JSObjectMakeDeferredPromise(ctx: JSContextRef; resolve: ptr JSObjectRef; reject: ptr JSObjectRef; exception: ptr JSValueRef): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- resolve/reject may each be nil if unneeded. macOS 10.15+.
proc JSObjectMakeError(ctx: JSContextRef; argumentCount: csize_t; arguments: ptr JSValueRef; exception: ptr JSValueRef): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- macOS 10.6+.
proc JSObjectMakeFunction(ctx: JSContextRef; name: JSStringRef; parameterCount: cuint; parameterNames: ptr JSStringRef; body: JSStringRef; sourceURL: JSStringRef; startingLineNumber: cint; exception: ptr JSValueRef): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- Builds a function from source. Nil on syntax error.
proc JSObjectMakeFunctionWithCallback(ctx: JSContextRef; name: JSStringRef; callAsFunction: JSObjectCallAsFunctionCallback): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- Nil name makes an anonymous function.
proc JSObjectMakeRegExp(ctx: JSContextRef; argumentCount: csize_t; arguments: ptr JSValueRef; exception: ptr JSValueRef): JSObjectRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- macOS 10.6+.
proc JSObjectSetPrivate(obj: JSObjectRef; data: pointer): bool {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- False when the class stores no private data.
proc JSObjectSetProperty(ctx: JSContextRef; obj: JSObjectRef; propertyName: JSStringRef; value: JSValueRef; attributes: JSPropertyAttributes; exception: ptr JSValueRef) {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectSetPropertyAtIndex(ctx: JSContextRef; obj: JSObjectRef; propertyIndex: cuint; value: JSValueRef; exception: ptr JSValueRef) {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSObjectSetPropertyForKey(ctx: JSContextRef; obj: JSObjectRef; propertyKey: JSValueRef; value: JSValueRef; attributes: JSPropertyAttributes; exception: ptr JSValueRef) {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- object[propertyKey] = value. macOS 10.15+.
proc JSObjectSetPrototype(ctx: JSContextRef; obj: JSObjectRef; value: JSValueRef) {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSPropertyNameAccumulatorAddName(accumulator: JSPropertyNameAccumulatorRef; propertyName: JSStringRef) {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- For use inside getPropertyNames callbacks.
proc JSPropertyNameArrayGetCount(array: JSPropertyNameArrayRef): csize_t {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSPropertyNameArrayGetNameAtIndex(array: JSPropertyNameArrayRef; index: csize_t): JSStringRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
- Borrowed: valid while array lives. Do not release.
proc JSPropertyNameArrayRelease(array: JSPropertyNameArrayRef) {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
proc JSPropertyNameArrayRetain(array: JSPropertyNameArrayRef): JSPropertyNameArrayRef {. header: "<JavaScriptCore/JavaScript.h>", importc, cdecl, ...raises: [], tags: [], forbids: [].}
Exports
-
JSCheckScriptSyntax, JSClassRef, JSContextGroupRef, JSContextRef, JSEvaluateScript, JSGarbageCollect, JSGlobalContextRef, JSObjectRef, JSPropertyNameAccumulatorRef, JSPropertyNameArrayRef, JSStringRef, JSTypedArrayBytesDeallocator, JSValueRef, OpaqueJSClass, OpaqueJSContext, OpaqueJSContextGroup, OpaqueJSPropertyNameAccumulator, OpaqueJSPropertyNameArray, OpaqueJSString, OpaqueJSValue, jscHeader, JSBigIntCreateWithDouble, JSBigIntCreateWithInt64, JSBigIntCreateWithString, JSBigIntCreateWithUInt64, JSCheckScriptSyntax, JSClassRef, JSContextGroupRef, JSContextRef, JSEvaluateScript, JSGarbageCollect, JSGlobalContextRef, JSObjectRef, JSPropertyNameAccumulatorRef, JSPropertyNameArrayRef, JSRelationCondition, JSStringRef, JSType, JSTypedArrayBytesDeallocator, JSTypedArrayType, JSValueCompare, JSValueCompareDouble, JSValueCompareInt64, JSValueCompareUInt64, JSValueCreateJSONString, JSValueGetType, JSValueGetTypedArrayType, JSValueIsArray, JSValueIsBigInt, JSValueIsBoolean, JSValueIsDate, JSValueIsEqual, JSValueIsInstanceOfConstructor, JSValueIsNull, JSValueIsNumber, JSValueIsObject, JSValueIsObjectOfClass, JSValueIsStrictEqual, JSValueIsString, JSValueIsSymbol, JSValueIsUndefined, JSValueMakeBoolean, JSValueMakeFromJSONString, JSValueMakeNull, JSValueMakeNumber, JSValueMakeString, JSValueMakeSymbol, JSValueMakeUndefined, JSValueProtect, JSValueRef, JSValueToBoolean, JSValueToInt32, JSValueToInt64, JSValueToNumber, JSValueToObject, JSValueToStringCopy, JSValueToUInt32, JSValueToUInt64, JSValueUnprotect, OpaqueJSClass, OpaqueJSContext, OpaqueJSContextGroup, OpaqueJSPropertyNameAccumulator, OpaqueJSPropertyNameArray, OpaqueJSString, OpaqueJSValue, jscHeader