Thin ergonomic helpers over the raw bindings.
The per-header modules stay verbatim C. This module adds the four things almost every caller needs: UTF-8 string conversion both ways, one-shot script evaluation, and scoped context lifetime.
Procs
proc `$`(str: JSStringRef): string {....raises: [], tags: [], forbids: [].}
- Converts a JSString to a Nim UTF-8 string. Never fails; nil gives "".
proc evalScript(ctx: JSContextRef; script: string; thisObject: JSObjectRef = nil; sourceURL: string = ""; line: int = 1; exception: var JSValueRef): JSValueRef {. ...raises: [], tags: [], forbids: [].}
- Evaluates script and returns the result (nil on exception, with exception[] set). exception must be initialized to nil by the caller.
proc newJSString(s: string): JSStringRef {....raises: [], tags: [], forbids: [].}
- Wraps s in a JSString. Owned: release with JSStringRelease.
Templates
template withGlobalContext(ctx: untyped; body: untyped)
- Creates a global context, runs body, releases it. Usage: withGlobalContext(ctx): ....
Exports
-
JSCheckScriptSyntax, JSClassRef, JSContextGroupRef, JSContextRef, JSEvaluateScript, JSGarbageCollect, JSGlobalContextRef, JSObjectRef, JSPropertyNameAccumulatorRef, JSPropertyNameArrayRef, JSStringRef, JSTypedArrayBytesDeallocator, JSValueRef, OpaqueJSClass, OpaqueJSContext, OpaqueJSContextGroup, OpaqueJSPropertyNameAccumulator, OpaqueJSPropertyNameArray, OpaqueJSString, OpaqueJSValue, jscHeader, JSChar, JSCheckScriptSyntax, JSClassRef, JSContextGroupRef, JSContextRef, JSEvaluateScript, JSGarbageCollect, JSGlobalContextRef, JSObjectRef, JSPropertyNameAccumulatorRef, JSPropertyNameArrayRef, JSStringCreateWithCharacters, JSStringCreateWithUTF8CString, JSStringGetCharactersPtr, JSStringGetLength, JSStringGetMaximumUTF8CStringSize, JSStringGetUTF8CString, JSStringIsEqual, JSStringIsEqualToUTF8CString, JSStringRef, JSStringRelease, JSStringRetain, JSTypedArrayBytesDeallocator, JSValueRef, OpaqueJSClass, OpaqueJSContext, OpaqueJSContextGroup, OpaqueJSPropertyNameAccumulator, OpaqueJSPropertyNameArray, OpaqueJSString, OpaqueJSValue, jscHeader, JSCheckScriptSyntax, JSClassRef, JSContextGetGlobalContext, JSContextGetGlobalObject, JSContextGetGroup, JSContextGroupCreate, JSContextGroupRef, JSContextGroupRelease, JSContextGroupRetain, JSContextRef, JSEvaluateScript, JSGarbageCollect, JSGlobalContextCopyName, JSGlobalContextCreate, JSGlobalContextCreateInGroup, JSGlobalContextIsInspectable, JSGlobalContextRef, JSGlobalContextRelease, JSGlobalContextRetain, JSGlobalContextSetInspectable, JSGlobalContextSetName, 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, JSBigIntCreateWithDouble, JSBigIntCreateWithInt64, JSBigIntCreateWithString, JSBigIntCreateWithUInt64, JSCheckScriptSyntax, JSClassAttributes, JSClassCreate, JSClassDefinition, JSClassRef, JSClassRelease, JSClassRetain, JSContextGroupRef, JSContextRef, JSEvaluateScript, JSGarbageCollect, JSGlobalContextRef, JSObjectCallAsConstructor, JSObjectCallAsConstructorCallback, JSObjectCallAsFunction, JSObjectCallAsFunctionCallback, JSObjectConvertToTypeCallback, JSObjectCopyPropertyNames, JSObjectDeleteProperty, JSObjectDeletePropertyCallback, JSObjectDeletePropertyForKey, JSObjectFinalizeCallback, JSObjectGetPrivate, JSObjectGetProperty, JSObjectGetPropertyAtIndex, JSObjectGetPropertyCallback, JSObjectGetPropertyForKey, JSObjectGetPropertyNamesCallback, JSObjectGetPrototype, JSObjectHasInstanceCallback, JSObjectHasProperty, JSObjectHasPropertyCallback, JSObjectHasPropertyForKey, JSObjectInitializeCallback, JSObjectIsConstructor, JSObjectIsFunction, JSObjectMake, JSObjectMakeArray, JSObjectMakeConstructor, JSObjectMakeDate, JSObjectMakeDeferredPromise, JSObjectMakeError, JSObjectMakeFunction, JSObjectMakeFunctionWithCallback, JSObjectMakeRegExp, JSObjectRef, JSObjectSetPrivate, JSObjectSetProperty, JSObjectSetPropertyAtIndex, JSObjectSetPropertyCallback, JSObjectSetPropertyForKey, JSObjectSetPrototype, JSPropertyAttributes, JSPropertyNameAccumulatorAddName, JSPropertyNameAccumulatorRef, JSPropertyNameArrayGetCount, JSPropertyNameArrayGetNameAtIndex, JSPropertyNameArrayRef, JSPropertyNameArrayRelease, JSPropertyNameArrayRetain, JSRelationCondition, JSStaticFunction, JSStaticValue, 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, kJSClassAttributeNoAutomaticPrototype, kJSClassAttributeNone, kJSClassDefinitionEmpty, kJSPropertyAttributeDontDelete, kJSPropertyAttributeDontEnum, kJSPropertyAttributeNone, kJSPropertyAttributeReadOnly