Last active
February 14, 2017 05:01
-
-
Save rosshadden/d2877ef77085c889d6e5f90e38b06650 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import | |
ChakraCommon, | |
ChakraCore | |
var | |
runtime: JsRuntimeHandle | |
context: JsContextRef | |
result: JsValueRef | |
currentSourceContext = 0.cuint | |
# var script = "(() => 'Hi, Mom!')()" | |
var script = "(()=>{return \'Hello World!\';})()" | |
discard JsCreateRuntime(JsRuntimeAttributeNone, nil, addr runtime) | |
discard JsCreateContext(runtime, addr context) | |
discard JsSetCurrentContext(context) | |
var fname : JsValueRef | |
discard JsCreateString("sample", len("sample"), addr fname) | |
var scriptSource : JsValueRef | |
discard JsCreateExternalArrayBuffer(addr script, script.len.cuint, nil, nil, addr scriptSource) | |
discard JsRun(scriptSource, currentSourceContext, fname, JsParseScriptAttributeNone, addr result) | |
inc(currentSourceContext) | |
var resultJsString : JsValueRef | |
discard JsConvertValueToString(result, addr resultJsString) | |
var | |
resultStr: cstring | |
stringLength: csize | |
discard JsCopyString(resultJsString, nil, 0, addr stringLength) | |
# stringLength is always 0, so nothing below works ^^^ | |
resultStr = cast[cstring](alloc(stringLength + 1)) | |
discard JsCopyString(resultJsString, resultStr, stringLength + 1, nil) | |
resultStr[stringLength] = cast[char](nil) | |
echo resultStr | |
dealloc(addr resultStr) | |
discard JsSetCurrentContext(nil) | |
discard JsDisposeRuntime(runtime) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ------------------------------------------------------------------------------------------------------- | |
## Copyright (C) Microsoft. All rights reserved. | |
## Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | |
## ------------------------------------------------------------------------------------------------------- | |
## / \mainpage Chakra Hosting API Reference | |
## / | |
## / Chakra is Microsoft's JavaScript engine. It is an integral part of Internet Explorer but can | |
## / also be hosted independently by other applications. This reference describes the APIs available | |
## / to applications to host Chakra. | |
## / | |
## / This file contains the common API set shared among all Chakra releases. For Windows-specific | |
## / releases, see chakrart.h. | |
## / \file | |
## / \brief The base Chakra hosting API. | |
## / | |
## / This file contains a flat C API layer. This is the API exported by chakra.dll. | |
{.deadCodeElim: on.} | |
const | |
chakraLib* = "./libChakraCore.so" | |
## #def CHAKRA_API extern "C" SET_API_VISIBILITY JsErrorCode | |
when not defined(CHAKRACOMMON_H): | |
const | |
CHAKRACOMMON_H* = true | |
type | |
ChakraCookie* = cuint | |
ChakraBytePtr* = ptr cuchar | |
## xplat-todo: try reduce usage of following types | |
type | |
UINT32* = uint32 | |
INT64* = int64 | |
HANDLE* = pointer | |
BYTE* = cuchar | |
byte* = BYTE | |
DWORD* = UINT32 | |
WCHAR* = cushort | |
## / <summary> | |
## / An error code returned from a Chakra hosting API. | |
## / </summary> | |
type ## / <summary> | |
## / Success error code. | |
## / </summary> | |
JsErrorCode* {.size: sizeof(cint).} = enum | |
JsNoError = 0, ## / <summary> | |
## / Category of errors that relates to incorrect usage of the API itself. | |
## / </summary> | |
JsErrorCategoryUsage = 0x00010000, ## / <summary> | |
## / An argument to a hosting API was invalid. | |
## / </summary> | |
JsErrorInvalidArgument, ## / <summary> | |
## / An argument to a hosting API was null in a context where null is not allowed. | |
## / </summary> | |
JsErrorNullArgument, ## / <summary> | |
## / The hosting API requires that a context be current, but there is no current context. | |
## / </summary> | |
JsErrorNoCurrentContext, ## / <summary> | |
## / The engine is in an exception state and no APIs can be called until the exception is | |
## / cleared. | |
## / </summary> | |
JsErrorInExceptionState, ## / <summary> | |
## / A hosting API is not yet implemented. | |
## / </summary> | |
JsErrorNotImplemented, ## / <summary> | |
## / A hosting API was called on the wrong thread. | |
## / </summary> | |
JsErrorWrongThread, ## / <summary> | |
## / A runtime that is still in use cannot be disposed. | |
## / </summary> | |
JsErrorRuntimeInUse, ## / <summary> | |
## / A bad serialized script was used, or the serialized script was serialized by a | |
## / different version of the Chakra engine. | |
## / </summary> | |
JsErrorBadSerializedScript, ## / <summary> | |
## / The runtime is in a disabled state. | |
## / </summary> | |
JsErrorInDisabledState, ## / <summary> | |
## / Runtime does not support reliable script interruption. | |
## / </summary> | |
JsErrorCannotDisableExecution, ## / <summary> | |
## / A heap enumeration is currently underway in the script context. | |
## / </summary> | |
JsErrorHeapEnumInProgress, ## / <summary> | |
## / A hosting API that operates on object values was called with a non-object value. | |
## / </summary> | |
JsErrorArgumentNotObject, ## / <summary> | |
## / A script context is in the middle of a profile callback. | |
## / </summary> | |
JsErrorInProfileCallback, ## / <summary> | |
## / A thread service callback is currently underway. | |
## / </summary> | |
JsErrorInThreadServiceCallback, ## / <summary> | |
## / Scripts cannot be serialized in debug contexts. | |
## / </summary> | |
JsErrorCannotSerializeDebugScript, ## / <summary> | |
## / The context cannot be put into a debug state because it is already in a debug state. | |
## / </summary> | |
JsErrorAlreadyDebuggingContext, ## / <summary> | |
## / The context cannot start profiling because it is already profiling. | |
## / </summary> | |
JsErrorAlreadyProfilingContext, ## / <summary> | |
## / Idle notification given when the host did not enable idle processing. | |
## / </summary> | |
JsErrorIdleNotEnabled, ## / <summary> | |
## / The context did not accept the enqueue callback. | |
## / </summary> | |
JsCannotSetProjectionEnqueueCallback, ## / <summary> | |
## / Failed to start projection. | |
## / </summary> | |
JsErrorCannotStartProjection, ## / <summary> | |
## / The operation is not supported in an object before collect callback. | |
## / </summary> | |
JsErrorInObjectBeforeCollectCallback, ## / <summary> | |
## / Object cannot be unwrapped to IInspectable pointer. | |
## / </summary> | |
JsErrorObjectNotInspectable, ## / <summary> | |
## / A hosting API that operates on symbol property ids but was called with a non-symbol property id. | |
## / The error code is returned by JsGetSymbolFromPropertyId if the function is called with non-symbol property id. | |
## / </summary> | |
JsErrorPropertyNotSymbol, ## / <summary> | |
## / A hosting API that operates on string property ids but was called with a non-string property id. | |
## / The error code is returned by existing JsGetPropertyNamefromId if the function is called with non-string property id. | |
## / </summary> | |
JsErrorPropertyNotString, ## / <summary> | |
## / Module evaulation is called in wrong context. | |
## / </summary> | |
JsErrorInvalidContext, ## / <summary> | |
## / Module evaulation is called in wrong context. | |
## / </summary> | |
JsInvalidModuleHostInfoKind, ## / <summary> | |
## / Module was parsed already when JsParseModuleSource is called. | |
## / </summary> | |
JsErrorModuleParsed, ## / <summary> | |
## / Module was evaluated already when JsModuleEvaluation is called. | |
## / </summary> | |
JsErrorModuleEvaluated, ## / <summary> | |
## / Category of errors that relates to errors occurring within the engine itself. | |
## / </summary> | |
JsErrorCategoryEngine = 0x00020000, ## / <summary> | |
## / The Chakra engine has run out of memory. | |
## / </summary> | |
JsErrorOutOfMemory, ## / <summary> | |
## / The Chakra engine failed to set the Floating Point Unit state. | |
## / </summary> | |
JsErrorBadFPUState, ## / <summary> | |
## / Category of errors that relates to errors in a script. | |
## / </summary> | |
JsErrorCategoryScript = 0x00030000, ## / <summary> | |
## / A JavaScript exception occurred while running a script. | |
## / </summary> | |
JsErrorScriptException, ## / <summary> | |
## / JavaScript failed to compile. | |
## / </summary> | |
JsErrorScriptCompile, ## / <summary> | |
## / A script was terminated due to a request to suspend a runtime. | |
## / </summary> | |
JsErrorScriptTerminated, ## / <summary> | |
## / A script was terminated because it tried to use <c>eval</c> or <c>function</c> and eval | |
## / was disabled. | |
## / </summary> | |
JsErrorScriptEvalDisabled, ## / <summary> | |
## / Category of errors that are fatal and signify failure of the engine. | |
## / </summary> | |
JsErrorCategoryFatal = 0x00040000, ## / <summary> | |
## / A fatal error in the engine has occurred. | |
## / </summary> | |
JsErrorFatal, ## / <summary> | |
## / A hosting API was called with object created on different javascript runtime. | |
## / </summary> | |
JsErrorWrongRuntime, ## / <summary> | |
## / Category of errors that are related to failures during diagnostic operations. | |
## / </summary> | |
JsErrorCategoryDiagError = 0x00050000, ## / <summary> | |
## / The object for which the debugging API was called was not found | |
## / </summary> | |
JsErrorDiagAlreadyInDebugMode, ## / <summary> | |
## / The debugging API can only be called when VM is in debug mode | |
## / </summary> | |
JsErrorDiagNotInDebugMode, ## / <summary> | |
## / The debugging API can only be called when VM is at a break | |
## / </summary> | |
JsErrorDiagNotAtBreak, ## / <summary> | |
## / Debugging API was called with an invalid handle. | |
## / </summary> | |
JsErrorDiagInvalidHandle, ## / <summary> | |
## / The object for which the debugging API was called was not found | |
## / </summary> | |
JsErrorDiagObjectNotFound, ## / <summary> | |
## / VM was unable to perfom the request action | |
## / </summary> | |
JsErrorDiagUnableToPerformAction | |
## / <summary> | |
## / A handle to a Chakra runtime. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Each Chakra runtime has its own independent execution engine, JIT compiler, and garbage | |
## / collected heap. As such, each runtime is completely isolated from other runtimes. | |
## / </para> | |
## / <para> | |
## / Runtimes can be used on any thread, but only one thread can call into a runtime at any | |
## / time. | |
## / </para> | |
## / <para> | |
## / NOTE: A <c>JsRuntimeHandle</c>, unlike other object references in the Chakra hosting API, | |
## / is not garbage collected since it contains the garbage collected heap itself. A runtime | |
## / will continue to exist until <c>JsDisposeRuntime</c> is called. | |
## / </para> | |
## / </remarks> | |
type | |
JsRuntimeHandle* = pointer | |
## / <summary> | |
## / An invalid runtime handle. | |
## / </summary> | |
## const JsRuntimeHandle JS_INVALID_RUNTIME_HANDLE = 0; | |
## / <summary> | |
## / A reference to an object owned by the Chakra garbage collector. | |
## / </summary> | |
## / <remarks> | |
## / A Chakra runtime will automatically track <c>JsRef</c> references as long as they are | |
## / stored in local variables or in parameters (i.e. on the stack). Storing a <c>JsRef</c> | |
## / somewhere other than on the stack requires calling <c>JsAddRef</c> and <c>JsRelease</c> to | |
## / manage the lifetime of the object, otherwise the garbage collector may free the object | |
## / while it is still in use. | |
## / </remarks> | |
type | |
JsRef* = pointer | |
## / <summary> | |
## / An invalid reference. | |
## / </summary> | |
## const JsRef JS_INVALID_REFERENCE = 0; | |
## / <summary> | |
## / A reference to a script context. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Each script context contains its own global object, distinct from the global object in | |
## / other script contexts. | |
## / </para> | |
## / <para> | |
## / Many Chakra hosting APIs require an "active" script context, which can be set using | |
## / <c>JsSetCurrentContext</c>. Chakra hosting APIs that require a current context to be set | |
## / will note that explicitly in their documentation. | |
## / </para> | |
## / </remarks> | |
type | |
JsContextRef* = JsRef | |
## / <summary> | |
## / A reference to a JavaScript value. | |
## / </summary> | |
## / <remarks> | |
## / A JavaScript value is one of the following types of values: undefined, null, Boolean, | |
## / string, number, or object. | |
## / </remarks> | |
type | |
JsValueRef* = JsRef | |
## / <summary> | |
## / A cookie that identifies a script for debugging purposes. | |
## / </summary> | |
type | |
JsSourceContext* = ChakraCookie | |
## / <summary> | |
## / An empty source context. | |
## / </summary> | |
## const JsSourceContext JS_SOURCE_CONTEXT_NONE = (JsSourceContext)-1; | |
## / <summary> | |
## / A property identifier. | |
## / </summary> | |
## / <remarks> | |
## / Property identifiers are used to refer to properties of JavaScript objects instead of using | |
## / strings. | |
## / </remarks> | |
type | |
JsPropertyIdRef* = JsRef | |
## / <summary> | |
## / Attributes of a runtime. | |
## / </summary> | |
type ## / <summary> | |
## / No special attributes. | |
## / </summary> | |
JsRuntimeAttributes* {.size: sizeof(cint).} = enum | |
JsRuntimeAttributeNone = 0x00000000, ## / <summary> | |
## / The runtime will not do any work (such as garbage collection) on background threads. | |
## / </summary> | |
JsRuntimeAttributeDisableBackgroundWork = 0x00000001, ## / <summary> | |
## / The runtime should support reliable script interruption. This increases the number of | |
## / places where the runtime will check for a script interrupt request at the cost of a | |
## / small amount of runtime performance. | |
## / </summary> | |
JsRuntimeAttributeAllowScriptInterrupt = 0x00000002, ## / <summary> | |
## / Host will call <c>JsIdle</c>, so enable idle processing. Otherwise, the runtime will | |
## / manage memory slightly more aggressively. | |
## / </summary> | |
JsRuntimeAttributeEnableIdleProcessing = 0x00000004, ## / <summary> | |
## / Runtime will not generate native code. | |
## / </summary> | |
JsRuntimeAttributeDisableNativeCodeGeneration = 0x00000008, ## / <summary> | |
## / Using <c>eval</c> or <c>function</c> constructor will throw an exception. | |
## / </summary> | |
JsRuntimeAttributeDisableEval = 0x00000010, ## / <summary> | |
## / Runtime will enable all experimental features. | |
## / </summary> | |
JsRuntimeAttributeEnableExperimentalFeatures = 0x00000020, ## / <summary> | |
## / Calling | |
## <c>JsSetException</c> will also dispatch the exception to the script debugger | |
## / (if any) giving the debugger a chance to break on the exception. | |
## / </summary> | |
JsRuntimeAttributeDispatchSetExceptionsToDebugger = 0x00000040 | |
## / <summary> | |
## / The type of a typed JavaScript array. | |
## / </summary> | |
type ## / <summary> | |
## / An int8 array. | |
## / </summary> | |
JsTypedArrayType* {.size: sizeof(cint).} = enum | |
JsArrayTypeInt8, ## / <summary> | |
## / An uint8 array. | |
## / </summary> | |
JsArrayTypeUint8, ## / <summary> | |
## / An uint8 clamped array. | |
## / </summary> | |
JsArrayTypeUint8Clamped, ## / <summary> | |
## / An int16 array. | |
## / </summary> | |
JsArrayTypeInt16, ## / <summary> | |
## / An uint16 array. | |
## / </summary> | |
JsArrayTypeUint16, ## / <summary> | |
## / An int32 array. | |
## / </summary> | |
JsArrayTypeInt32, ## / <summary> | |
## / An uint32 array. | |
## / </summary> | |
JsArrayTypeUint32, ## / <summary> | |
## / A float32 array. | |
## / </summary> | |
JsArrayTypeFloat32, ## / <summary> | |
## / A float64 array. | |
## / </summary> | |
JsArrayTypeFloat64 | |
## / <summary> | |
## / Allocation callback event type. | |
## / </summary> | |
type ## / <summary> | |
## / Indicates a request for memory allocation. | |
## / </summary> | |
JsMemoryEventType* {.size: sizeof(cint).} = enum | |
JsMemoryAllocate = 0, ## / <summary> | |
## / Indicates a memory freeing event. | |
## / </summary> | |
JsMemoryFree = 1, ## / <summary> | |
## / Indicates a failed allocation event. | |
## / </summary> | |
JsMemoryFailure = 2 | |
## / <summary> | |
## / Attribute mask for JsParseScriptWithAttributes | |
## / </summary> | |
type ## / <summary> | |
## / Default attribute | |
## / </summary> | |
JsParseScriptAttributes* {.size: sizeof(cint).} = enum | |
JsParseScriptAttributeNone = 0x00000000, ## / <summary> | |
## / Specified script is internal and non-user code. Hidden from debugger | |
## / </summary> | |
JsParseScriptAttributeLibraryCode = 0x00000001, ## / <summary> | |
## / ChakraCore assumes ExternalArrayBuffer is Utf8 by default. | |
## / This one needs to be set for Utf16 | |
## / </summary> | |
JsParseScriptAttributeArrayBufferIsUtf16Encoded = 0x00000002 | |
## / <summary> | |
## / Type enumeration of a JavaScript property | |
## / </summary> | |
type ## / <summary> | |
## / Type enumeration of a JavaScript string property | |
## / </summary> | |
JsPropertyIdType* {.size: sizeof(cint).} = enum | |
JsPropertyIdTypeString, ## / <summary> | |
## / Type enumeration of a JavaScript symbol property | |
## / </summary> | |
JsPropertyIdTypeSymbol | |
## / <summary> | |
## / The JavaScript type of a JsValueRef. | |
## / </summary> | |
type ## / <summary> | |
## / The value is the <c>undefined</c> value. | |
## / </summary> | |
JsValueType* {.size: sizeof(cint).} = enum | |
JsUndefined = 0, ## / <summary> | |
## / The value is the <c>null</c> value. | |
## / </summary> | |
JsNull = 1, ## / <summary> | |
## / The value is a JavaScript number value. | |
## / </summary> | |
JsNumber = 2, ## / <summary> | |
## / The value is a JavaScript string value. | |
## / </summary> | |
JsString = 3, ## / <summary> | |
## / The value is a JavaScript Boolean value. | |
## / </summary> | |
JsBoolean = 4, ## / <summary> | |
## / The value is a JavaScript object value. | |
## / </summary> | |
JsObject = 5, ## / <summary> | |
## / The value is a JavaScript function object value. | |
## / </summary> | |
JsFunction = 6, ## / <summary> | |
## / The value is a JavaScript error object value. | |
## / </summary> | |
JsError = 7, ## / <summary> | |
## / The value is a JavaScript array object value. | |
## / </summary> | |
JsArray = 8, ## / <summary> | |
## / The value is a JavaScript symbol value. | |
## / </summary> | |
JsSymbol = 9, ## / <summary> | |
## / The value is a JavaScript ArrayBuffer object value. | |
## / </summary> | |
JsArrayBuffer = 10, ## / <summary> | |
## / The value is a JavaScript typed array object value. | |
## / </summary> | |
JsTypedArray = 11, ## / <summary> | |
## / The value is a JavaScript DataView object value. | |
## / </summary> | |
JsDataView = 12 | |
## / <summary> | |
## / User implemented callback routine for memory allocation events | |
## / </summary> | |
## / <remarks> | |
## / Use <c>JsSetRuntimeMemoryAllocationCallback</c> to register this callback. | |
## / </remarks> | |
## / <param name="callbackState"> | |
## / The state passed to <c>JsSetRuntimeMemoryAllocationCallback</c>. | |
## / </param> | |
## / <param name="allocationEvent">The type of type allocation event.</param> | |
## / <param name="allocationSize">The size of the allocation.</param> | |
## / <returns> | |
## / For the <c>JsMemoryAllocate</c> event, returning <c>true</c> allows the runtime to continue | |
## / with the allocation. Returning false indicates the allocation request is rejected. The | |
## / return value is ignored for other allocation events. | |
## / </returns> | |
type | |
JsMemoryAllocationCallback* = proc (callbackState: pointer; | |
allocationEvent: JsMemoryEventType; | |
allocationSize: csize): bool {.cdecl.} | |
## / <summary> | |
## / A callback called before collection. | |
## / </summary> | |
## / <remarks> | |
## / Use <c>JsSetBeforeCollectCallback</c> to register this callback. | |
## / </remarks> | |
## / <param name="callbackState">The state passed to <c>JsSetBeforeCollectCallback</c>.</param> | |
type | |
JsBeforeCollectCallback* = proc (callbackState: pointer) {.cdecl.} | |
## / <summary> | |
## / A callback called before collecting an object. | |
## / </summary> | |
## / <remarks> | |
## / Use <c>JsSetObjectBeforeCollectCallback</c> to register this callback. | |
## / </remarks> | |
## / <param name="ref">The object to be collected.</param> | |
## / <param name="callbackState">The state passed to <c>JsSetObjectBeforeCollectCallback</c>.</param> | |
type | |
JsObjectBeforeCollectCallback* = proc (`ref`: JsRef; callbackState: pointer) {. | |
cdecl.} | |
## / <summary> | |
## / A background work item callback. | |
## / </summary> | |
## / <remarks> | |
## / This is passed to the host's thread service (if provided) to allow the host to | |
## / invoke the work item callback on the background thread of its choice. | |
## / </remarks> | |
## / <param name="callbackState">Data argument passed to the thread service.</param> | |
type | |
JsBackgroundWorkItemCallback* = proc (callbackState: pointer) {.cdecl.} | |
## / <summary> | |
## / A thread service callback. | |
## / </summary> | |
## / <remarks> | |
## / The host can specify a background thread service when calling <c>JsCreateRuntime</c>. If | |
## / specified, then background work items will be passed to the host using this callback. The | |
## / host is expected to either begin executing the background work item immediately and return | |
## / true or return false and the runtime will handle the work item in-thread. | |
## / </remarks> | |
## / <param name="callback">The callback for the background work item.</param> | |
## / <param name="callbackState">The data argument to be passed to the callback.</param> | |
type | |
JsThreadServiceCallback* = proc (callback: JsBackgroundWorkItemCallback; | |
callbackState: pointer): bool {.cdecl.} | |
## / <summary> | |
## / Called by the runtime when it is finished with all resources related to the script execution. | |
## / The caller should free the source if loaded, the byte code, and the context at this time. | |
## / </summary> | |
## / <param name="sourceContext">The context passed to Js[Parse|Run]SerializedScriptWithCallback</param> | |
type | |
JsSerializedScriptUnloadCallback* = proc (sourceContext: JsSourceContext) {.cdecl.} | |
## / <summary> | |
## / A finalizer callback. | |
## / </summary> | |
## / <param name="data"> | |
## / The external data that was passed in when creating the object being finalized. | |
## / </param> | |
type | |
JsFinalizeCallback* = proc (data: pointer) {.cdecl.} | |
## / <summary> | |
## / A function callback. | |
## / </summary> | |
## / <param name="callee"> | |
## / A function object that represents the function being invoked. | |
## / </param> | |
## / <param name="isConstructCall">Indicates whether this is a regular call or a 'new' call.</param> | |
## / <param name="arguments">The arguments to the call.</param> | |
## / <param name="argumentCount">The number of arguments.</param> | |
## / <param name="callbackState"> | |
## / The state passed to <c>JsCreateFunction</c>. | |
## / </param> | |
## / <returns>The result of the call, if any.</returns> | |
type | |
JsNativeFunction* = proc (callee: JsValueRef; isConstructCall: bool; | |
arguments: ptr JsValueRef; argumentCount: cushort; | |
callbackState: pointer): JsValueRef {.cdecl.} | |
## / <summary> | |
## / A promise continuation callback. | |
## / </summary> | |
## / <remarks> | |
## / The host can specify a promise continuation callback in <c>JsSetPromiseContinuationCallback</c>. If | |
## / a script creates a task to be run later, then the promise continuation callback will be called with | |
## / the task and the task should be put in a FIFO queue, to be run when the current script is | |
## / done executing. | |
## / </remarks> | |
## / <param name="task">The task, represented as a JavaScript function.</param> | |
## / <param name="callbackState">The data argument to be passed to the callback.</param> | |
type | |
JsPromiseContinuationCallback* = proc (task: JsValueRef; callbackState: pointer) {. | |
cdecl.} | |
## / <summary> | |
## / Creates a new runtime. | |
## / </summary> | |
## / <param name="attributes">The attributes of the runtime to be created.</param> | |
## / <param name="threadService">The thread service for the runtime. Can be null.</param> | |
## / <param name="runtime">The runtime created.</param> | |
## / <remarks>In the edge-mode binary, chakra.dll, this function lacks the <c>runtimeVersion</c> | |
## / parameter (compare to jsrt9.h).</remarks> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateRuntime*(attributes: JsRuntimeAttributes; | |
threadService: JsThreadServiceCallback; | |
runtime: ptr JsRuntimeHandle): JsErrorCode {.cdecl, | |
importc: "JsCreateRuntime", dynlib: chakraLib.} | |
## / <summary> | |
## / Performs a full garbage collection. | |
## / </summary> | |
## / <param name="runtime">The runtime in which the garbage collection will be performed.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCollectGarbage*(runtime: JsRuntimeHandle): JsErrorCode {.cdecl, | |
importc: "JsCollectGarbage", dynlib: chakraLib.} | |
## / <summary> | |
## / Disposes a runtime. | |
## / </summary> | |
## / <remarks> | |
## / Once a runtime has been disposed, all resources owned by it are invalid and cannot be used. | |
## / If the runtime is active (i.e. it is set to be current on a particular thread), it cannot | |
## / be disposed. | |
## / </remarks> | |
## / <param name="runtime">The runtime to dispose.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsDisposeRuntime*(runtime: JsRuntimeHandle): JsErrorCode {.cdecl, | |
importc: "JsDisposeRuntime", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the current memory usage for a runtime. | |
## / </summary> | |
## / <remarks> | |
## / Memory usage can be always be retrieved, regardless of whether or not the runtime is active | |
## / on another thread. | |
## / </remarks> | |
## / <param name="runtime">The runtime whose memory usage is to be retrieved.</param> | |
## / <param name="memoryUsage">The runtime's current memory usage, in bytes.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetRuntimeMemoryUsage*(runtime: JsRuntimeHandle; memoryUsage: ptr csize): JsErrorCode {. | |
cdecl, importc: "JsGetRuntimeMemoryUsage", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the current memory limit for a runtime. | |
## / </summary> | |
## / <remarks> | |
## / The memory limit of a runtime can be always be retrieved, regardless of whether or not the | |
## / runtime is active on another thread. | |
## / </remarks> | |
## / <param name="runtime">The runtime whose memory limit is to be retrieved.</param> | |
## / <param name="memoryLimit"> | |
## / The runtime's current memory limit, in bytes, or -1 if no limit has been set. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetRuntimeMemoryLimit*(runtime: JsRuntimeHandle; memoryLimit: ptr csize): JsErrorCode {. | |
cdecl, importc: "JsGetRuntimeMemoryLimit", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets the current memory limit for a runtime. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / A memory limit will cause any operation which exceeds the limit to fail with an "out of | |
## / memory" error. Setting a runtime's memory limit to -1 means that the runtime has no memory | |
## / limit. New runtimes default to having no memory limit. If the new memory limit exceeds | |
## / current usage, the call will succeed and any future allocations in this runtime will fail | |
## / until the runtime's memory usage drops below the limit. | |
## / </para> | |
## / <para> | |
## / A runtime's memory limit can be always be set, regardless of whether or not the runtime is | |
## / active on another thread. | |
## / </para> | |
## / </remarks> | |
## / <param name="runtime">The runtime whose memory limit is to be set.</param> | |
## / <param name="memoryLimit"> | |
## / The new runtime memory limit, in bytes, or -1 for no memory limit. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetRuntimeMemoryLimit*(runtime: JsRuntimeHandle; memoryLimit: csize): JsErrorCode {. | |
cdecl, importc: "JsSetRuntimeMemoryLimit", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets a memory allocation callback for specified runtime | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Registering a memory allocation callback will cause the runtime to call back to the host | |
## / whenever it acquires memory from, or releases memory to, the OS. The callback routine is | |
## / called before the runtime memory manager allocates a block of memory. The allocation will | |
## / be rejected if the callback returns false. The runtime memory manager will also invoke the | |
## / callback routine after freeing a block of memory, as well as after allocation failures. | |
## / </para> | |
## / <para> | |
## / The callback is invoked on the current runtime execution thread, therefore execution is | |
## / blocked until the callback completes. | |
## / </para> | |
## / <para> | |
## / The return value of the callback is not stored; previously rejected allocations will not | |
## / prevent the runtime from invoking the callback again later for new memory allocations. | |
## / </para> | |
## / </remarks> | |
## / <param name="runtime">The runtime for which to register the allocation callback.</param> | |
## / <param name="callbackState"> | |
## / User provided state that will be passed back to the callback. | |
## / </param> | |
## / <param name="allocationCallback"> | |
## / Memory allocation callback to be called for memory allocation events. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetRuntimeMemoryAllocationCallback*(runtime: JsRuntimeHandle; | |
callbackState: pointer; allocationCallback: JsMemoryAllocationCallback): JsErrorCode {. | |
cdecl, importc: "JsSetRuntimeMemoryAllocationCallback", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets a callback function that is called by the runtime before garbage collection. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / The callback is invoked on the current runtime execution thread, therefore execution is | |
## / blocked until the callback completes. | |
## / </para> | |
## / <para> | |
## / The callback can be used by hosts to prepare for garbage collection. For example, by | |
## / releasing unnecessary references on Chakra objects. | |
## / </para> | |
## / </remarks> | |
## / <param name="runtime">The runtime for which to register the allocation callback.</param> | |
## / <param name="callbackState"> | |
## / User provided state that will be passed back to the callback. | |
## / </param> | |
## / <param name="beforeCollectCallback">The callback function being set.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetRuntimeBeforeCollectCallback*(runtime: JsRuntimeHandle; | |
callbackState: pointer; beforeCollectCallback: JsBeforeCollectCallback): JsErrorCode {. | |
cdecl, importc: "JsSetRuntimeBeforeCollectCallback", dynlib: chakraLib.} | |
## / <summary> | |
## / Adds a reference to a garbage collected object. | |
## / </summary> | |
## / <remarks> | |
## / This only needs to be called on <c>JsRef</c> handles that are not going to be stored | |
## / somewhere on the stack. Calling <c>JsAddRef</c> ensures that the object the <c>JsRef</c> | |
## / refers to will not be freed until <c>JsRelease</c> is called. | |
## / </remarks> | |
## / <param name="ref">The object to add a reference to.</param> | |
## / <param name="count">The object's new reference count (can pass in null).</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsAddRef*(`ref`: JsRef; count: ptr cuint): JsErrorCode {.cdecl, | |
importc: "JsAddRef", dynlib: chakraLib.} | |
## / <summary> | |
## / Releases a reference to a garbage collected object. | |
## / </summary> | |
## / <remarks> | |
## / Removes a reference to a <c>JsRef</c> handle that was created by <c>JsAddRef</c>. | |
## / </remarks> | |
## / <param name="ref">The object to add a reference to.</param> | |
## / <param name="count">The object's new reference count (can pass in null).</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsRelease*(`ref`: JsRef; count: ptr cuint): JsErrorCode {.cdecl, | |
importc: "JsRelease", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets a callback function that is called by the runtime before garbage collection of | |
## / an object. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / The callback is invoked on the current runtime execution thread, therefore execution is | |
## / blocked until the callback completes. | |
## / </para> | |
## / </remarks> | |
## / <param name="ref">The object for which to register the callback.</param> | |
## / <param name="callbackState"> | |
## / User provided state that will be passed back to the callback. | |
## / </param> | |
## / <param name="objectBeforeCollectCallback">The callback function being set. Use null to clear | |
## / previously registered callback.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetObjectBeforeCollectCallback*(`ref`: JsRef; callbackState: pointer; | |
objectBeforeCollectCallback: JsObjectBeforeCollectCallback): JsErrorCode {. | |
cdecl, importc: "JsSetObjectBeforeCollectCallback", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a script context for running scripts. | |
## / </summary> | |
## / <remarks> | |
## / Each script context has its own global object that is isolated from all other script | |
## / contexts. | |
## / </remarks> | |
## / <param name="runtime">The runtime the script context is being created in.</param> | |
## / <param name="newContext">The created script context.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateContext*(runtime: JsRuntimeHandle; newContext: ptr JsContextRef): JsErrorCode {. | |
cdecl, importc: "JsCreateContext", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the current script context on the thread. | |
## / </summary> | |
## / <param name="currentContext"> | |
## / The current script context on the thread, null if there is no current script context. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetCurrentContext*(currentContext: ptr JsContextRef): JsErrorCode {.cdecl, | |
importc: "JsGetCurrentContext", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets the current script context on the thread. | |
## / </summary> | |
## / <param name="context">The script context to make current.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetCurrentContext*(context: JsContextRef): JsErrorCode {.cdecl, | |
importc: "JsSetCurrentContext", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the script context that the object belongs to. | |
## / </summary> | |
## / <param name="object">The object to get the context from.</param> | |
## / <param name="context">The context the object belongs to.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetContextOfObject*(`object`: JsValueRef; context: ptr JsContextRef): JsErrorCode {. | |
cdecl, importc: "JsGetContextOfObject", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the internal data set on JsrtContext. | |
## / </summary> | |
## / <param name="context">The context to get the data from.</param> | |
## / <param name="data">The pointer to the data where data will be returned.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetContextData*(context: JsContextRef; data: ptr pointer): JsErrorCode {. | |
cdecl, importc: "JsGetContextData", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets the internal data of JsrtContext. | |
## / </summary> | |
## / <param name="context">The context to set the data to.</param> | |
## / <param name="data">The pointer to the data to be set.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetContextData*(context: JsContextRef; data: pointer): JsErrorCode {.cdecl, | |
importc: "JsSetContextData", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the runtime that the context belongs to. | |
## / </summary> | |
## / <param name="context">The context to get the runtime from.</param> | |
## / <param name="runtime">The runtime the context belongs to.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetRuntime*(context: JsContextRef; runtime: ptr JsRuntimeHandle): JsErrorCode {. | |
cdecl, importc: "JsGetRuntime", dynlib: chakraLib.} | |
## / <summary> | |
## / Tells the runtime to do any idle processing it need to do. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / If idle processing has been enabled for the current runtime, calling <c>JsIdle</c> will | |
## / inform the current runtime that the host is idle and that the runtime can perform | |
## / memory cleanup tasks. | |
## / </para> | |
## / <para> | |
## / <c>JsIdle</c> can also return the number of system ticks until there will be more idle work | |
## / for the runtime to do. Calling <c>JsIdle</c> before this number of ticks has passed will do | |
## / no work. | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="nextIdleTick"> | |
## / The next system tick when there will be more idle work to do. Can be null. Returns the | |
## / maximum number of ticks if there no upcoming idle work to do. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsIdle*(nextIdleTick: ptr cuint): JsErrorCode {.cdecl, importc: "JsIdle", | |
dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the symbol associated with the property ID. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="propertyId">The property ID to get the symbol of.</param> | |
## / <param name="symbol">The symbol associated with the property ID.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetSymbolFromPropertyId*(propertyId: JsPropertyIdRef; | |
symbol: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsGetSymbolFromPropertyId", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the type of property | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="propertyId">The property ID to get the type of.</param> | |
## / <param name="propertyIdType">The JsPropertyIdType of the given property ID</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetPropertyIdType*(propertyId: JsPropertyIdRef; | |
propertyIdType: ptr JsPropertyIdType): JsErrorCode {. | |
cdecl, importc: "JsGetPropertyIdType", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the property ID associated with the symbol. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Property IDs are specific to a context and cannot be used across contexts. | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="symbol"> | |
## / The symbol whose property ID is being retrieved. | |
## / </param> | |
## / <param name="propertyId">The property ID for the given symbol.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetPropertyIdFromSymbol*(symbol: JsValueRef; | |
propertyId: ptr JsPropertyIdRef): JsErrorCode {. | |
cdecl, importc: "JsGetPropertyIdFromSymbol", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a Javascript symbol. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="description">The string description of the symbol. Can be null.</param> | |
## / <param name="result">The new symbol.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateSymbol*(description: JsValueRef; result: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateSymbol", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the list of all symbol properties on the object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object from which to get the property symbols.</param> | |
## / <param name="propertySymbols">An array of property symbols.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetOwnPropertySymbols*(`object`: JsValueRef; | |
propertySymbols: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsGetOwnPropertySymbols", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the value of <c>undefined</c> in the current script context. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="undefinedValue">The <c>undefined</c> value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetUndefinedValue*(undefinedValue: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsGetUndefinedValue", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the value of <c>null</c> in the current script context. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="nullValue">The <c>null</c> value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetNullValue*(nullValue: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsGetNullValue", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the value of <c>true</c> in the current script context. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="trueValue">The <c>true</c> value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetTrueValue*(trueValue: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsGetTrueValue", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the value of <c>false</c> in the current script context. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="falseValue">The <c>false</c> value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetFalseValue*(falseValue: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsGetFalseValue", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a Boolean value from a <c>bool</c> value. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="value">The value to be converted.</param> | |
## / <param name="booleanValue">The converted value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsBoolToBoolean*(value: bool; booleanValue: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsBoolToBoolean", dynlib: chakraLib.} | |
## / <summary> | |
## / Retrieves the <c>bool</c> value of a Boolean value. | |
## / </summary> | |
## / <param name="value">The value to be converted.</param> | |
## / <param name="boolValue">The converted value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsBooleanToBool*(value: JsValueRef; boolValue: ptr bool): JsErrorCode {.cdecl, | |
importc: "JsBooleanToBool", dynlib: chakraLib.} | |
## / <summary> | |
## / Converts the value to Boolean using standard JavaScript semantics. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="value">The value to be converted.</param> | |
## / <param name="booleanValue">The converted value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsConvertValueToBoolean*(value: JsValueRef; booleanValue: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsConvertValueToBoolean", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the JavaScript type of a JsValueRef. | |
## / </summary> | |
## / <param name="value">The value whose type is to be returned.</param> | |
## / <param name="type">The type of the value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetValueType*(value: JsValueRef; `type`: ptr JsValueType): JsErrorCode {. | |
cdecl, importc: "JsGetValueType", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a number value from a <c>double</c> value. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="doubleValue">The <c>double</c> to convert to a number value.</param> | |
## / <param name="value">The new number value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsDoubleToNumber*(doubleValue: cdouble; value: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsDoubleToNumber", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a number value from an <c>int</c> value. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="intValue">The <c>int</c> to convert to a number value.</param> | |
## / <param name="value">The new number value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsIntToNumber*(intValue: cint; value: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsIntToNumber", dynlib: chakraLib.} | |
## / <summary> | |
## / Retrieves the <c>double</c> value of a number value. | |
## / </summary> | |
## / <remarks> | |
## / This function retrieves the value of a number value. It will fail with | |
## / <c>JsErrorInvalidArgument</c> if the type of the value is not number. | |
## / </remarks> | |
## / <param name="value">The number value to convert to a <c>double</c> value.</param> | |
## / <param name="doubleValue">The <c>double</c> value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsNumberToDouble*(value: JsValueRef; doubleValue: ptr cdouble): JsErrorCode {. | |
cdecl, importc: "JsNumberToDouble", dynlib: chakraLib.} | |
## / <summary> | |
## / Retrieves the <c>int</c> value of a number value. | |
## / </summary> | |
## / <remarks> | |
## / This function retrieves the value of a number value and converts to an <c>int</c> value. | |
## / It will fail with <c>JsErrorInvalidArgument</c> if the type of the value is not number. | |
## / </remarks> | |
## / <param name="value">The number value to convert to an <c>int</c> value.</param> | |
## / <param name="intValue">The <c>int</c> value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsNumberToInt*(value: JsValueRef; intValue: ptr cint): JsErrorCode {.cdecl, | |
importc: "JsNumberToInt", dynlib: chakraLib.} | |
## / <summary> | |
## / Converts the value to number using standard JavaScript semantics. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="value">The value to be converted.</param> | |
## / <param name="numberValue">The converted value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsConvertValueToNumber*(value: JsValueRef; numberValue: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsConvertValueToNumber", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the length of a string value. | |
## / </summary> | |
## / <param name="stringValue">The string value to get the length of.</param> | |
## / <param name="length">The length of the string.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetStringLength*(stringValue: JsValueRef; length: ptr cint): JsErrorCode {. | |
cdecl, importc: "JsGetStringLength", dynlib: chakraLib.} | |
## / <summary> | |
## / Converts the value to string using standard JavaScript semantics. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="value">The value to be converted.</param> | |
## / <param name="stringValue">The converted value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsConvertValueToString*(value: JsValueRef; stringValue: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsConvertValueToString", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the global object in the current script context. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="globalObject">The global object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetGlobalObject*(globalObject: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsGetGlobalObject", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The new object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateObject*(`object`: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsCreateObject", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new object that stores some external data. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="data">External data that the object will represent. May be null.</param> | |
## / <param name="finalizeCallback"> | |
## / A callback for when the object is finalized. May be null. | |
## / </param> | |
## / <param name="object">The new object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateExternalObject*(data: pointer; finalizeCallback: JsFinalizeCallback; | |
`object`: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsCreateExternalObject", dynlib: chakraLib.} | |
## / <summary> | |
## / Converts the value to object using standard JavaScript semantics. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="value">The value to be converted.</param> | |
## / <param name="object">The converted value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsConvertValueToObject*(value: JsValueRef; `object`: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsConvertValueToObject", dynlib: chakraLib.} | |
## / <summary> | |
## / Returns the prototype of an object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object whose prototype is to be returned.</param> | |
## / <param name="prototypeObject">The object's prototype.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetPrototype*(`object`: JsValueRef; prototypeObject: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsGetPrototype", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets the prototype of an object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object whose prototype is to be changed.</param> | |
## / <param name="prototypeObject">The object's new prototype.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetPrototype*(`object`: JsValueRef; prototypeObject: JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsSetPrototype", dynlib: chakraLib.} | |
## / <summary> | |
## / Performs JavaScript "instanceof" operator test. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object to test.</param> | |
## / <param name="constructor">The constructor function to test against.</param> | |
## / <param name="result">Whether "object instanceof constructor" is true.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsInstanceOf*(`object`: JsValueRef; constructor: JsValueRef; result: ptr bool): JsErrorCode {. | |
cdecl, importc: "JsInstanceOf", dynlib: chakraLib.} | |
## / <summary> | |
## / Returns a value that indicates whether an object is extensible or not. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object to test.</param> | |
## / <param name="value">Whether the object is extensible or not.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetExtensionAllowed*(`object`: JsValueRef; value: ptr bool): JsErrorCode {. | |
cdecl, importc: "JsGetExtensionAllowed", dynlib: chakraLib.} | |
## / <summary> | |
## / Makes an object non-extensible. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object to make non-extensible.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsPreventExtension*(`object`: JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsPreventExtension", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets an object's property. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object that contains the property.</param> | |
## / <param name="propertyId">The ID of the property.</param> | |
## / <param name="value">The value of the property.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetProperty*(`object`: JsValueRef; propertyId: JsPropertyIdRef; | |
value: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsGetProperty", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets a property descriptor for an object's own property. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object that has the property.</param> | |
## / <param name="propertyId">The ID of the property.</param> | |
## / <param name="propertyDescriptor">The property descriptor.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetOwnPropertyDescriptor*(`object`: JsValueRef; | |
propertyId: JsPropertyIdRef; | |
propertyDescriptor: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsGetOwnPropertyDescriptor", dynlib: chakraLib.} | |
## / <summary> | |
## / Gets the list of all properties on the object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object from which to get the property names.</param> | |
## / <param name="propertyNames">An array of property names.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetOwnPropertyNames*(`object`: JsValueRef; propertyNames: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsGetOwnPropertyNames", dynlib: chakraLib.} | |
## / <summary> | |
## / Puts an object's property. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object that contains the property.</param> | |
## / <param name="propertyId">The ID of the property.</param> | |
## / <param name="value">The new value of the property.</param> | |
## / <param name="useStrictRules">The property set should follow strict mode rules.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetProperty*(`object`: JsValueRef; propertyId: JsPropertyIdRef; | |
value: JsValueRef; useStrictRules: bool): JsErrorCode {.cdecl, | |
importc: "JsSetProperty", dynlib: chakraLib.} | |
## / <summary> | |
## / Determines whether an object has a property. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object that may contain the property.</param> | |
## / <param name="propertyId">The ID of the property.</param> | |
## / <param name="hasProperty">Whether the object (or a prototype) has the property.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsHasProperty*(`object`: JsValueRef; propertyId: JsPropertyIdRef; | |
hasProperty: ptr bool): JsErrorCode {.cdecl, | |
importc: "JsHasProperty", dynlib: chakraLib.} | |
## / <summary> | |
## / Deletes an object's property. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object that contains the property.</param> | |
## / <param name="propertyId">The ID of the property.</param> | |
## / <param name="useStrictRules">The property set should follow strict mode rules.</param> | |
## / <param name="result">Whether the property was deleted.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsDeleteProperty*(`object`: JsValueRef; propertyId: JsPropertyIdRef; | |
useStrictRules: bool; result: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsDeleteProperty", dynlib: chakraLib.} | |
## / <summary> | |
## / Defines a new object's own property from a property descriptor. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object that has the property.</param> | |
## / <param name="propertyId">The ID of the property.</param> | |
## / <param name="propertyDescriptor">The property descriptor.</param> | |
## / <param name="result">Whether the property was defined.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsDefineProperty*(`object`: JsValueRef; propertyId: JsPropertyIdRef; | |
propertyDescriptor: JsValueRef; result: ptr bool): JsErrorCode {. | |
cdecl, importc: "JsDefineProperty", dynlib: chakraLib.} | |
## / <summary> | |
## / Tests whether an object has a value at the specified index. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object to operate on.</param> | |
## / <param name="index">The index to test.</param> | |
## / <param name="result">Whether the object has a value at the specified index.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsHasIndexedProperty*(`object`: JsValueRef; index: JsValueRef; | |
result: ptr bool): JsErrorCode {.cdecl, | |
importc: "JsHasIndexedProperty", dynlib: chakraLib.} | |
## / <summary> | |
## / Retrieve the value at the specified index of an object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object to operate on.</param> | |
## / <param name="index">The index to retrieve.</param> | |
## / <param name="result">The retrieved value.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetIndexedProperty*(`object`: JsValueRef; index: JsValueRef; | |
result: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsGetIndexedProperty", dynlib: chakraLib.} | |
## / <summary> | |
## / Set the value at the specified index of an object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object to operate on.</param> | |
## / <param name="index">The index to set.</param> | |
## / <param name="value">The value to set.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetIndexedProperty*(`object`: JsValueRef; index: JsValueRef; | |
value: JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsSetIndexedProperty", dynlib: chakraLib.} | |
## / <summary> | |
## / Delete the value at the specified index of an object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object to operate on.</param> | |
## / <param name="index">The index to delete.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsDeleteIndexedProperty*(`object`: JsValueRef; index: JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsDeleteIndexedProperty", dynlib: chakraLib.} | |
## / <summary> | |
## / Determines whether an object has its indexed properties in external data. | |
## / </summary> | |
## / <param name="object">The object.</param> | |
## / <param name="value">Whether the object has its indexed properties in external data.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsHasIndexedPropertiesExternalData*(`object`: JsValueRef; value: ptr bool): JsErrorCode {. | |
cdecl, importc: "JsHasIndexedPropertiesExternalData", dynlib: chakraLib.} | |
## / <summary> | |
## / Retrieves an object's indexed properties external data information. | |
## / </summary> | |
## / <param name="object">The object.</param> | |
## / <param name="data">The external data back store for the object's indexed properties.</param> | |
## / <param name="arrayType">The array element type in external data.</param> | |
## / <param name="elementLength">The number of array elements in external data.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetIndexedPropertiesExternalData*(`object`: JsValueRef; data: ptr pointer; | |
arrayType: ptr JsTypedArrayType; elementLength: ptr cuint): JsErrorCode {.cdecl, | |
importc: "JsGetIndexedPropertiesExternalData", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets an object's indexed properties to external data. The external data will be used as back | |
## / store for the object's indexed properties and accessed like a typed array. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="object">The object to operate on.</param> | |
## / <param name="data">The external data to be used as back store for the object's indexed properties.</param> | |
## / <param name="arrayType">The array element type in external data.</param> | |
## / <param name="elementLength">The number of array elements in external data.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetIndexedPropertiesToExternalData*(`object`: JsValueRef; data: pointer; | |
arrayType: JsTypedArrayType; elementLength: cuint): JsErrorCode {.cdecl, | |
importc: "JsSetIndexedPropertiesToExternalData", dynlib: chakraLib.} | |
## / <summary> | |
## / Compare two JavaScript values for equality. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / This function is equivalent to the <c>==</c> operator in Javascript. | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="object1">The first object to compare.</param> | |
## / <param name="object2">The second object to compare.</param> | |
## / <param name="result">Whether the values are equal.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsEquals*(object1: JsValueRef; object2: JsValueRef; result: ptr bool): JsErrorCode {. | |
cdecl, importc: "JsEquals", dynlib: chakraLib.} | |
## / <summary> | |
## / Compare two JavaScript values for strict equality. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / This function is equivalent to the <c>===</c> operator in Javascript. | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="object1">The first object to compare.</param> | |
## / <param name="object2">The second object to compare.</param> | |
## / <param name="result">Whether the values are strictly equal.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsStrictEquals*(object1: JsValueRef; object2: JsValueRef; result: ptr bool): JsErrorCode {. | |
cdecl, importc: "JsStrictEquals", dynlib: chakraLib.} | |
## / <summary> | |
## / Determines whether an object is an external object. | |
## / </summary> | |
## / <param name="object">The object.</param> | |
## / <param name="value">Whether the object is an external object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsHasExternalData*(`object`: JsValueRef; value: ptr bool): JsErrorCode {.cdecl, | |
importc: "JsHasExternalData", dynlib: chakraLib.} | |
## / <summary> | |
## / Retrieves the data from an external object. | |
## / </summary> | |
## / <param name="object">The external object.</param> | |
## / <param name="externalData"> | |
## / The external data stored in the object. Can be null if no external data is stored in the | |
## / object. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetExternalData*(`object`: JsValueRef; externalData: ptr pointer): JsErrorCode {. | |
cdecl, importc: "JsGetExternalData", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets the external data on an external object. | |
## / </summary> | |
## / <param name="object">The external object.</param> | |
## / <param name="externalData"> | |
## / The external data to be stored in the object. Can be null if no external data is | |
## / to be stored in the object. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetExternalData*(`object`: JsValueRef; externalData: pointer): JsErrorCode {. | |
cdecl, importc: "JsSetExternalData", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a Javascript array object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="length">The initial length of the array.</param> | |
## / <param name="result">The new array object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateArray*(length: cuint; result: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsCreateArray", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a Javascript ArrayBuffer object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="byteLength"> | |
## / The number of bytes in the ArrayBuffer. | |
## / </param> | |
## / <param name="result">The new ArrayBuffer object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateArrayBuffer*(byteLength: cuint; result: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateArrayBuffer", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a Javascript ArrayBuffer object to access external memory. | |
## / </summary> | |
## / <remarks>Requires an active script context.</remarks> | |
## / <param name="data">A pointer to the external memory.</param> | |
## / <param name="byteLength">The number of bytes in the external memory.</param> | |
## / <param name="finalizeCallback">A callback for when the object is finalized. May be null.</param> | |
## / <param name="callbackState">User provided state that will be passed back to finalizeCallback.</param> | |
## / <param name="result">The new ArrayBuffer object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateExternalArrayBuffer*(data: pointer; byteLength: cuint; | |
finalizeCallback: JsFinalizeCallback; | |
callbackState: pointer; result: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateExternalArrayBuffer", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a Javascript typed array object. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / The <c>baseArray</c> can be an <c>ArrayBuffer</c>, another typed array, or a JavaScript | |
## / <c>Array</c>. The returned typed array will use the baseArray if it is an ArrayBuffer, or | |
## / otherwise create and use a copy of the underlying source array. | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="arrayType">The type of the array to create.</param> | |
## / <param name="baseArray"> | |
## / The base array of the new array. Use <c>JS_INVALID_REFERENCE</c> if no base array. | |
## / </param> | |
## / <param name="byteOffset"> | |
## / The offset in bytes from the start of baseArray (ArrayBuffer) for result typed array to reference. | |
## / Only applicable when baseArray is an ArrayBuffer object. Must be 0 otherwise. | |
## / </param> | |
## / <param name="elementLength"> | |
## / The number of elements in the array. Only applicable when creating a new typed array without | |
## / baseArray (baseArray is <c>JS_INVALID_REFERENCE</c>) or when baseArray is an ArrayBuffer object. | |
## / Must be 0 otherwise. | |
## / </param> | |
## / <param name="result">The new typed array object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateTypedArray*(arrayType: JsTypedArrayType; baseArray: JsValueRef; | |
byteOffset: cuint; elementLength: cuint; | |
result: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsCreateTypedArray", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a Javascript DataView object. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="arrayBuffer"> | |
## / An existing ArrayBuffer object to use as the storage for the result DataView object. | |
## / </param> | |
## / <param name="byteOffset"> | |
## / The offset in bytes from the start of arrayBuffer for result DataView to reference. | |
## / </param> | |
## / <param name="byteLength"> | |
## / The number of bytes in the ArrayBuffer for result DataView to reference. | |
## / </param> | |
## / <param name="result">The new DataView object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateDataView*(arrayBuffer: JsValueRef; byteOffset: cuint; | |
byteLength: cuint; result: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateDataView", dynlib: chakraLib.} | |
## / <summary> | |
## / Obtains frequently used properties of a typed array. | |
## / </summary> | |
## / <param name="typedArray">The typed array instance.</param> | |
## / <param name="arrayType">The type of the array.</param> | |
## / <param name="arrayBuffer">The ArrayBuffer backstore of the array.</param> | |
## / <param name="byteOffset">The offset in bytes from the start of arrayBuffer referenced by the array.</param> | |
## / <param name="byteLength">The number of bytes in the array.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetTypedArrayInfo*(typedArray: JsValueRef; | |
arrayType: ptr JsTypedArrayType; | |
arrayBuffer: ptr JsValueRef; byteOffset: ptr cuint; | |
byteLength: ptr cuint): JsErrorCode {.cdecl, | |
importc: "JsGetTypedArrayInfo", dynlib: chakraLib.} | |
## / <summary> | |
## / Obtains the underlying memory storage used by an <c>ArrayBuffer</c>. | |
## / </summary> | |
## / <param name="arrayBuffer">The ArrayBuffer instance.</param> | |
## / <param name="buffer"> | |
## / The ArrayBuffer's buffer. The lifetime of the buffer returned is the same as the lifetime of the | |
## / the ArrayBuffer. The buffer pointer does not count as a reference to the ArrayBuffer for the purpose | |
## / of garbage collection. | |
## / </param> | |
## / <param name="bufferLength">The number of bytes in the buffer.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetArrayBufferStorage*(arrayBuffer: JsValueRef; buffer: ptr ChakraBytePtr; | |
bufferLength: ptr cuint): JsErrorCode {.cdecl, | |
importc: "JsGetArrayBufferStorage", dynlib: chakraLib.} | |
## / <summary> | |
## / Obtains the underlying memory storage used by a typed array. | |
## / </summary> | |
## / <param name="typedArray">The typed array instance.</param> | |
## / <param name="buffer"> | |
## / The array's buffer. The lifetime of the buffer returned is the same as the lifetime of the | |
## / the array. The buffer pointer does not count as a reference to the array for the purpose | |
## / of garbage collection. | |
## / </param> | |
## / <param name="bufferLength">The number of bytes in the buffer.</param> | |
## / <param name="arrayType">The type of the array.</param> | |
## / <param name="elementSize"> | |
## / The size of an element of the array. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetTypedArrayStorage*(typedArray: JsValueRef; buffer: ptr ChakraBytePtr; | |
bufferLength: ptr cuint; | |
arrayType: ptr JsTypedArrayType; | |
elementSize: ptr cint): JsErrorCode {.cdecl, | |
importc: "JsGetTypedArrayStorage", dynlib: chakraLib.} | |
## / <summary> | |
## / Obtains the underlying memory storage used by a DataView. | |
## / </summary> | |
## / <param name="dataView">The DataView instance.</param> | |
## / <param name="buffer"> | |
## / The DataView's buffer. The lifetime of the buffer returned is the same as the lifetime of the | |
## / the DataView. The buffer pointer does not count as a reference to the DataView for the purpose | |
## / of garbage collection. | |
## / </param> | |
## / <param name="bufferLength">The number of bytes in the buffer.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetDataViewStorage*(dataView: JsValueRef; buffer: ptr ChakraBytePtr; | |
bufferLength: ptr cuint): JsErrorCode {.cdecl, | |
importc: "JsGetDataViewStorage", dynlib: chakraLib.} | |
## / <summary> | |
## / Invokes a function. | |
## / </summary> | |
## / <remarks> | |
## / Requires thisArg as first argument of arguments. | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="function">The function to invoke.</param> | |
## / <param name="arguments">The arguments to the call.</param> | |
## / <param name="argumentCount">The number of arguments being passed in to the function.</param> | |
## / <param name="result">The value returned from the function invocation, if any.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCallFunction*(function: JsValueRef; arguments: ptr JsValueRef; | |
argumentCount: cushort; result: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCallFunction", dynlib: chakraLib.} | |
## / <summary> | |
## / Invokes a function as a constructor. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="function">The function to invoke as a constructor.</param> | |
## / <param name="arguments">The arguments to the call.</param> | |
## / <param name="argumentCount">The number of arguments being passed in to the function.</param> | |
## / <param name="result">The value returned from the function invocation.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsConstructObject*(function: JsValueRef; arguments: ptr JsValueRef; | |
argumentCount: cushort; result: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsConstructObject", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new JavaScript function. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="nativeFunction">The method to call when the function is invoked.</param> | |
## / <param name="callbackState"> | |
## / User provided state that will be passed back to the callback. | |
## / </param> | |
## / <param name="function">The new function object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateFunction*(nativeFunction: JsNativeFunction; callbackState: pointer; | |
function: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsCreateFunction", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new JavaScript function with name. | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="name">The name of this function that will be used for diagnostics and stringification purposes.</param> | |
## / <param name="nativeFunction">The method to call when the function is invoked.</param> | |
## / <param name="callbackState"> | |
## / User provided state that will be passed back to the callback. | |
## / </param> | |
## / <param name="function">The new function object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateNamedFunction*(name: JsValueRef; nativeFunction: JsNativeFunction; | |
callbackState: pointer; function: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateNamedFunction", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new JavaScript error object | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="message">Message for the error object.</param> | |
## / <param name="error">The new error object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateError*(message: JsValueRef; error: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsCreateError", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new JavaScript RangeError error object | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="message">Message for the error object.</param> | |
## / <param name="error">The new error object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateRangeError*(message: JsValueRef; error: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateRangeError", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new JavaScript ReferenceError error object | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="message">Message for the error object.</param> | |
## / <param name="error">The new error object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateReferenceError*(message: JsValueRef; error: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateReferenceError", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new JavaScript SyntaxError error object | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="message">Message for the error object.</param> | |
## / <param name="error">The new error object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateSyntaxError*(message: JsValueRef; error: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateSyntaxError", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new JavaScript TypeError error object | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="message">Message for the error object.</param> | |
## / <param name="error">The new error object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateTypeError*(message: JsValueRef; error: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateTypeError", dynlib: chakraLib.} | |
## / <summary> | |
## / Creates a new JavaScript URIError error object | |
## / </summary> | |
## / <remarks> | |
## / Requires an active script context. | |
## / </remarks> | |
## / <param name="message">Message for the error object.</param> | |
## / <param name="error">The new error object.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateURIError*(message: JsValueRef; error: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateURIError", dynlib: chakraLib.} | |
## / <summary> | |
## / Determines whether the runtime of the current context is in an exception state. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / If a call into the runtime results in an exception (either as the result of running a | |
## / script or due to something like a conversion failure), the runtime is placed into an | |
## / "exception state." All calls into any context created by the runtime (except for the | |
## / exception APIs) will fail with <c>JsErrorInExceptionState</c> until the exception is | |
## / cleared. | |
## / </para> | |
## / <para> | |
## / If the runtime of the current context is in the exception state when a callback returns | |
## / into the engine, the engine will automatically rethrow the exception. | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="hasException"> | |
## / Whether the runtime of the current context is in the exception state. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsHasException*(hasException: ptr bool): JsErrorCode {.cdecl, | |
importc: "JsHasException", dynlib: chakraLib.} | |
## / <summary> | |
## / Returns the exception that caused the runtime of the current context to be in the | |
## / exception state and resets the exception state for that runtime. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / If the runtime of the current context is not in an exception state, this API will return | |
## / <c>JsErrorInvalidArgument</c>. If the runtime is disabled, this will return an exception | |
## / indicating that the script was terminated, but it will not clear the exception (the | |
## / exception will be cleared if the runtime is re-enabled using | |
## / <c>JsEnableRuntimeExecution</c>). | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="exception">The exception for the runtime of the current context.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetAndClearException*(exception: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsGetAndClearException", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets the runtime of the current context to an exception state. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / If the runtime of the current context is already in an exception state, this API will | |
## / return <c>JsErrorInExceptionState</c>. | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="exception"> | |
## / The JavaScript exception to set for the runtime of the current context. | |
## / </param> | |
## / <returns> | |
## / JsNoError if the engine was set into an exception state, a failure code otherwise. | |
## / </returns> | |
proc JsSetException*(exception: JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsSetException", dynlib: chakraLib.} | |
## / <summary> | |
## / Suspends script execution and terminates any running scripts in a runtime. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Calls to a suspended runtime will fail until <c>JsEnableRuntimeExecution</c> is called. | |
## / </para> | |
## / <para> | |
## / This API does not have to be called on the thread the runtime is active on. Although the | |
## / runtime will be set into a suspended state, an executing script may not be suspended | |
## / immediately; a running script will be terminated with an uncatchable exception as soon as | |
## / possible. | |
## / </para> | |
## / <para> | |
## / Suspending execution in a runtime that is already suspended is a no-op. | |
## / </para> | |
## / </remarks> | |
## / <param name="runtime">The runtime to be suspended.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsDisableRuntimeExecution*(runtime: JsRuntimeHandle): JsErrorCode {.cdecl, | |
importc: "JsDisableRuntimeExecution", dynlib: chakraLib.} | |
## / <summary> | |
## / Enables script execution in a runtime. | |
## / </summary> | |
## / <remarks> | |
## / Enabling script execution in a runtime that already has script execution enabled is a | |
## / no-op. | |
## / </remarks> | |
## / <param name="runtime">The runtime to be enabled.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsEnableRuntimeExecution*(runtime: JsRuntimeHandle): JsErrorCode {.cdecl, | |
importc: "JsEnableRuntimeExecution", dynlib: chakraLib.} | |
## / <summary> | |
## / Returns a value that indicates whether script execution is disabled in the runtime. | |
## / </summary> | |
## / <param name="runtime">Specifies the runtime to check if execution is disabled.</param> | |
## / <param name="isDisabled">If execution is disabled, <c>true</c>, <c>false</c> otherwise.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsIsRuntimeExecutionDisabled*(runtime: JsRuntimeHandle; isDisabled: ptr bool): JsErrorCode {. | |
cdecl, importc: "JsIsRuntimeExecutionDisabled", dynlib: chakraLib.} | |
## / <summary> | |
## / Sets a promise continuation callback function that is called by the context when a task | |
## / needs to be queued for future execution | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="promiseContinuationCallback">The callback function being set.</param> | |
## / <param name="callbackState"> | |
## / User provided state that will be passed back to the callback. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetPromiseContinuationCallback*(promiseContinuationCallback: JsPromiseContinuationCallback; | |
callbackState: pointer): JsErrorCode {. | |
cdecl, importc: "JsSetPromiseContinuationCallback", dynlib: chakraLib.} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ------------------------------------------------------------------------------------------------------- | |
## Copyright (C) Microsoft. All rights reserved. | |
## Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | |
## ------------------------------------------------------------------------------------------------------- | |
## / \mainpage Chakra Hosting API Reference | |
## / | |
## / Chakra is Microsoft's JavaScript engine. It is an integral part of Internet Explorer but can | |
## / also be hosted independently by other applications. This reference describes the APIs available | |
## / to applications to host Chakra. | |
## / | |
## / \file | |
## / \brief The Chakra Core hosting API. | |
## / | |
## / This file contains a flat C API layer. This is the API exported by ChakraCore.dll. | |
{.deadCodeElim: on.} | |
const | |
chakraLib* = "./libChakraCore.so" | |
when not defined(CHAKRACORE_H): | |
import | |
ChakraCommon, ChakraDebug | |
type | |
JsModuleRecord* = pointer | |
JsParseModuleSourceFlags* {.size: sizeof(cint).} = enum | |
JsParseModuleSourceFlags_DataIsUTF16LE = 0x00000000, | |
JsParseModuleSourceFlags_DataIsUTF8 = 0x00000001 | |
JsModuleHostInfoKind* {.size: sizeof(cint).} = enum | |
JsModuleHostInfo_Exception = 0x00000001, | |
JsModuleHostInfo_HostDefined = 0x00000002, | |
JsModuleHostInfo_NotifyModuleReadyCallback = 0x00000003, | |
JsModuleHostInfo_FetchImportedModuleCallback = 0x00000004 | |
## / <summary> | |
## / User implemented callback to fetch additional imported modules. | |
## / </summary> | |
## / <remarks> | |
## / Notify the host to fetch the dependent module. This is the "import" part before HostResolveImportedModule in ES6 spec. | |
## / This notifies the host that the referencing module has the specified module dependency, and the host need to retrieve the module back. | |
## / </remarks> | |
## / <param name="referencingModule">The referencing module that is requesting the dependency modules.</param> | |
## / <param name="specifier">The specifier coming from the module source code.</param> | |
## / <param name="dependentModuleRecord">The ModuleRecord of the dependent module. If the module was requested before from other source, return the | |
## / existing ModuleRecord, otherwise return a newly created ModuleRecord.</param> | |
## / <returns> | |
## / true if the operation succeeded, false otherwise. | |
## / </returns> | |
type | |
FetchImportedModuleCallBack* = proc (referencingModule: JsModuleRecord; | |
specifier: JsValueRef; | |
dependentModuleRecord: ptr JsModuleRecord): JsErrorCode {. | |
cdecl.} | |
## / <summary> | |
## / User implemented callback to get notification when the module is ready. | |
## / </summary> | |
## / <remarks> | |
## / Notify the host after ModuleDeclarationInstantiation step (15.2.1.1.6.4) is finished. If there was error in the process, exceptionVar | |
## / holds the exception. Otherwise the referencingModule is ready and the host should schedule execution afterwards. | |
## / </remarks> | |
## / <param name="referencingModule">The referencing module that have finished running ModuleDeclarationInstantiation step.</param> | |
## / <param name="exceptionVar">If nullptr, the module is successfully initialized and host should queue the execution job | |
## / otherwise it's the exception object.</param> | |
## / <returns> | |
## / true if the operation succeeded, false otherwise. | |
## / </returns> | |
type | |
NotifyModuleReadyCallback* = proc (referencingModule: JsModuleRecord; | |
exceptionVar: JsValueRef): JsErrorCode {.cdecl.} | |
## / <summary> | |
## / Initialize a ModuleRecord from host | |
## / </summary> | |
## / <remarks> | |
## / Bootstrap the module loading process by creating a new module record. | |
## / </remarks> | |
## / <param name="referencingModule">The referencingModule as in HostResolveImportedModule (15.2.1.17). nullptr if this is the top level module.</param> | |
## / <param name="normalizedSpecifier">The host normalized specifier. This is the key to a unique ModuleRecord.</param> | |
## / <param name="moduleRecord">The new ModuleRecord created. The host should not try to call this API twice with the same normalizedSpecifier. | |
## / chakra will return an existing ModuleRecord if the specifier was passed in before.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsInitializeModuleRecord*(referencingModule: JsModuleRecord; | |
normalizedSpecifier: JsValueRef; | |
moduleRecord: ptr JsModuleRecord): JsErrorCode {. | |
cdecl, importc: "JsInitializeModuleRecord", dynlib: chakraLib.} | |
## / <summary> | |
## / Parse the module source | |
## / </summary> | |
## / <remarks> | |
## / This is basically ParseModule operation in ES6 spec. It is slightly different in that the ModuleRecord was initialized earlier, and passed in as an argument. | |
## / </remarks> | |
## / <param name="requestModule">The ModuleRecord that holds the parse tree of the source code.</param> | |
## / <param name="sourceContext">A cookie identifying the script that can be used by debuggable script contexts.</param> | |
## / <param name="script">The source script to be parsed, but not executed in this code.</param> | |
## / <param name="scriptLength">The source length of sourceText. The input might contain embedded null.</param> | |
## / <param name="sourceFlag">The type of the source code passed in. It could be UNICODE or utf8 at this time.</param> | |
## / <param name="exceptionValueRef">The error object if there is parse error.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsParseModuleSource*(requestModule: JsModuleRecord; | |
sourceContext: JsSourceContext; script: ptr BYTE; | |
scriptLength: cuint; | |
sourceFlag: JsParseModuleSourceFlags; | |
exceptionValueRef: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsParseModuleSource", dynlib: chakraLib.} | |
## / <summary> | |
## / Execute module code. | |
## / </summary> | |
## / <remarks> | |
## / This method implements 15.2.1.1.6.5, "ModuleEvaluation" concrete method. | |
## / When this methid is called, the chakra engine should have notified the host that the module and all its dependent are ready to be executed. | |
## / One moduleRecord will be executed only once. Additional execution call on the same moduleRecord will fail. | |
## / </remarks> | |
## / <param name="requestModule">The module to be executed.</param> | |
## / <param name="result">The return value of the module.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsModuleEvaluation*(requestModule: JsModuleRecord; result: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsModuleEvaluation", dynlib: chakraLib.} | |
## / <summary> | |
## / Set the host info for the specified module. | |
## / </summary> | |
## / <param name="requestModule">The request module.</param> | |
## / <param name="moduleHostInfo">The type of host info to be set.</param> | |
## / <param name="hostInfo">The host info to be set.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSetModuleHostInfo*(requestModule: JsModuleRecord; | |
moduleHostInfo: JsModuleHostInfoKind; hostInfo: pointer): JsErrorCode {. | |
cdecl, importc: "JsSetModuleHostInfo", dynlib: chakraLib.} | |
## / <summary> | |
## / Retrieve the host info for the specified module. | |
## / </summary> | |
## / <param name="requestModule">The request module.</param> | |
## / <param name="moduleHostInfo">The type of host info to get.</param> | |
## / <param name="hostInfo">The host info to be retrieved.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsGetModuleHostInfo*(requestModule: JsModuleRecord; | |
moduleHostInfo: JsModuleHostInfoKind; | |
hostInfo: ptr pointer): JsErrorCode {.cdecl, | |
importc: "JsGetModuleHostInfo", dynlib: chakraLib.} | |
## / <summary> | |
## / Called by the runtime to load the source code of the serialized script. | |
## / </summary> | |
## / <param name="sourceContext">The context passed to Js[Parse|Run]SerializedScriptCallback</param> | |
## / <param name="script">The script returned.</param> | |
## / <returns> | |
## / true if the operation succeeded, false otherwise. | |
## / </returns> | |
type | |
JsSerializedLoadScriptCallback* = proc (sourceContext: JsSourceContext; | |
value: ptr JsValueRef; parseAttributes: ptr JsParseScriptAttributes): bool {. | |
cdecl.} | |
## / <summary> | |
## / Create JavascriptString variable from ASCII or Utf8 string | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Input string can be either ASCII or Utf8 | |
## / </para> | |
## / </remarks> | |
## / <param name="content">Pointer to string memory.</param> | |
## / <param name="length">Number of bytes within the string</param> | |
## / <param name="value">JsValueRef representing the JavascriptString</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateString*(content: cstring; length: csize; value: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateString", dynlib: chakraLib.} | |
## / <summary> | |
## / Create JavascriptString variable from Utf16 string | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Expects Utf16 string | |
## / </para> | |
## / </remarks> | |
## / <param name="content">Pointer to string memory.</param> | |
## / <param name="length">Number of characters within the string</param> | |
## / <param name="value">JsValueRef representing the JavascriptString</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreateStringUtf16*(content: ptr uint16; length: csize; value: ptr JsValueRef): JsErrorCode {. | |
cdecl, importc: "JsCreateStringUtf16", dynlib: chakraLib.} | |
## / <summary> | |
## / Write JavascriptString value into C string buffer (Utf8) | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / When size of the `buffer` is unknown, | |
## / `buffer` argument can be nullptr. | |
## / In that case, `written` argument will return the length needed. | |
## / </para> | |
## / </remarks> | |
## / <param name="value">JavascriptString value</param> | |
## / <param name="buffer">Pointer to buffer</param> | |
## / <param name="bufferSize">Buffer size</param> | |
## / <param name="written">Total number of characters written</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCopyString*(value: JsValueRef; buffer: cstring; bufferSize: csize; | |
written: ptr csize): JsErrorCode {.cdecl, | |
importc: "JsCopyString", dynlib: chakraLib.} | |
## / <summary> | |
## / Write string value into Utf16 string buffer | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / When size of the `buffer` is unknown, | |
## / `buffer` argument can be nullptr. | |
## / In that case, `written` argument will return the length needed. | |
## / </para> | |
## / <para> | |
## / when start is out of range or < 0, returns JsErrorInvalidArgument | |
## / and `written` will be equal to 0. | |
## / If calculated length is 0 (It can be due to string length or `start` | |
## / and length combination), then `written` will be equal to 0 and call | |
## / returns JsNoError | |
## / </para> | |
## / </remarks> | |
## / <param name="value">JavascriptString value</param> | |
## / <param name="start">start offset of buffer</param> | |
## / <param name="length">length to be written</param> | |
## / <param name="buffer">Pointer to buffer</param> | |
## / <param name="written">Total number of characters written</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCopyStringUtf16*(value: JsValueRef; start: cint; length: cint; | |
buffer: ptr uint16; written: ptr csize): JsErrorCode {.cdecl, | |
importc: "JsCopyStringUtf16", dynlib: chakraLib.} | |
## / <summary> | |
## / Parses a script and returns a function representing the script. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / <para> | |
## / Script source can be either JavascriptString or JavascriptExternalArrayBuffer. | |
## / In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16, | |
## / JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes. | |
## / </para> | |
## / <para> | |
## / Use JavascriptExternalArrayBuffer with Utf8/ASCII script source | |
## / for better performance and smaller memory footprint. | |
## / </para> | |
## / </remarks> | |
## / <param name="script">The script to run.</param> | |
## / <param name="sourceContext"> | |
## / A cookie identifying the script that can be used by debuggable script contexts. | |
## / </param> | |
## / <param name="sourceUrl">The location the script came from.</param> | |
## / <param name="parseAttributes">Attribute mask for parsing the script</param> | |
## / <param name="result">The result of the compiled script.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsParse*(script: JsValueRef; sourceContext: JsSourceContext; | |
sourceUrl: JsValueRef; parseAttributes: JsParseScriptAttributes; | |
result: ptr JsValueRef): JsErrorCode {.cdecl, importc: "JsParse", | |
dynlib: chakraLib.} | |
## / <summary> | |
## / Executes a script. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / <para> | |
## / Script source can be either JavascriptString or JavascriptExternalArrayBuffer. | |
## / In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16, | |
## / JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes. | |
## / </para> | |
## / <para> | |
## / Use JavascriptExternalArrayBuffer with Utf8/ASCII script source | |
## / for better performance and smaller memory footprint. | |
## / </para> | |
## / </remarks> | |
## / <param name="script">The script to run.</param> | |
## / <param name="sourceContext"> | |
## / A cookie identifying the script that can be used by debuggable script contexts. | |
## / </param> | |
## / <param name="sourceUrl">The location the script came from</param> | |
## / <param name="parseAttributes">Attribute mask for parsing the script</param> | |
## / <param name="result">The result of the script, if any. This parameter can be null.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsRun*(script: JsValueRef; sourceContext: JsSourceContext; | |
sourceUrl: JsValueRef; parseAttributes: JsParseScriptAttributes; | |
result: ptr JsValueRef): JsErrorCode {.cdecl, importc: "JsRun", | |
dynlib: chakraLib.} | |
## / <summary> | |
## / Creates the property ID associated with the name. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Property IDs are specific to a context and cannot be used across contexts. | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="name"> | |
## / The name of the property ID to get or create. The name may consist of only digits. | |
## / The string is expected to be ASCII / utf8 encoded. | |
## / </param> | |
## / <param name="length">length of the name in bytes</param> | |
## / <param name="propertyId">The property ID in this runtime for the given name.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCreatePropertyId*(name: cstring; length: csize; | |
propertyId: ptr JsPropertyIdRef): JsErrorCode {.cdecl, | |
importc: "JsCreatePropertyId", dynlib: chakraLib.} | |
## / <summary> | |
## / Copies the name associated with the property ID into a buffer. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / <para> | |
## / When size of the `buffer` is unknown, | |
## / `buffer` argument can be nullptr. | |
## / `length` argument will return the size needed. | |
## / </para> | |
## / </remarks> | |
## / <param name="propertyId">The property ID to get the name of.</param> | |
## / <param name="buffer">The buffer holding the name associated with the property ID, encoded as utf8</param> | |
## / <param name="bufferSize">Size of the buffer.</param> | |
## / <param name="written">Total number of characters written or to be written</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsCopyPropertyId*(propertyId: JsPropertyIdRef; buffer: cstring; | |
bufferSize: csize; length: ptr csize): JsErrorCode {.cdecl, | |
importc: "JsCopyPropertyId", dynlib: chakraLib.} | |
## / <summary> | |
## / Serializes a parsed script to a buffer than can be reused. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / <c>JsSerializeScript</c> parses a script and then stores the parsed form of the script in a | |
## / runtime-independent format. The serialized script then can be deserialized in any | |
## / runtime without requiring the script to be re-parsed. | |
## / </para> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / <para> | |
## / Script source can be either JavascriptString or JavascriptExternalArrayBuffer. | |
## / In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16, | |
## / JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes. | |
## / </para> | |
## / <para> | |
## / Use JavascriptExternalArrayBuffer with Utf8/ASCII script source | |
## / for better performance and smaller memory footprint. | |
## / </para> | |
## / </remarks> | |
## / <param name="script">The script to serialize</param> | |
## / <param name="buffer">ArrayBuffer</param> | |
## / <param name="parseAttributes">Encoding for the script.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsSerialize*(script: JsValueRef; buffer: ptr JsValueRef; | |
parseAttributes: JsParseScriptAttributes): JsErrorCode {.cdecl, | |
importc: "JsSerialize", dynlib: chakraLib.} | |
## / <summary> | |
## / Parses a serialized script and returns a function representing the script. | |
## / Provides the ability to lazy load the script source only if/when it is needed. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / </remarks> | |
## / <param name="buffer">The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer).</param> | |
## / <param name="scriptLoadCallback"> | |
## / Callback called when the source code of the script needs to be loaded. | |
## / This is an optional parameter, set to null if not needed. | |
## / </param> | |
## / <param name="sourceContext"> | |
## / A cookie identifying the script that can be used by debuggable script contexts. | |
## / This context will passed into scriptLoadCallback. | |
## / </param> | |
## / <param name="sourceUrl">The location the script came from.</param> | |
## / <param name="result">A function representing the script code.</param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsParseSerialized*(buffer: JsValueRef; | |
scriptLoadCallback: JsSerializedLoadScriptCallback; | |
sourceContext: JsSourceContext; sourceUrl: JsValueRef; | |
result: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsParseSerialized", dynlib: chakraLib.} | |
## / <summary> | |
## / Runs a serialized script. | |
## / Provides the ability to lazy load the script source only if/when it is needed. | |
## / </summary> | |
## / <remarks> | |
## / <para> | |
## / Requires an active script context. | |
## / </para> | |
## / <para> | |
## / The runtime will hold on to the buffer until all instances of any functions created from | |
## / the buffer are garbage collected. | |
## / </para> | |
## / </remarks> | |
## / <param name="buffer">The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer).</param> | |
## / <param name="scriptLoadCallback">Callback called when the source code of the script needs to be loaded.</param> | |
## / <param name="sourceContext"> | |
## / A cookie identifying the script that can be used by debuggable script contexts. | |
## / This context will passed into scriptLoadCallback. | |
## / </param> | |
## / <param name="sourceUrl">The location the script came from.</param> | |
## / <param name="result"> | |
## / The result of running the script, if any. This parameter can be null. | |
## / </param> | |
## / <returns> | |
## / The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise. | |
## / </returns> | |
proc JsRunSerialized*(buffer: JsValueRef; | |
scriptLoadCallback: JsSerializedLoadScriptCallback; | |
sourceContext: JsSourceContext; sourceUrl: JsValueRef; | |
result: ptr JsValueRef): JsErrorCode {.cdecl, | |
importc: "JsRunSerialized", dynlib: chakraLib.} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment