#pragma option push -b -a8 -pc -A- -w-pun /*P_O_Push*/ // Copyright (C) Microsoft. All rights reserved. /// \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 base Chakra hosting API. /// /// This file contains a flat C API layer. This is the API exported by chakra.dll. #ifdef _MSC_VER #pragma once #endif // _MSC_VER #ifndef _JSRT_ #error "You should include instead of or ." #endif #ifdef _JSRT9_H_ #error "It is invalid to include both jscript9-mode and edge-mode JsRT headers. To include edge, use #define USE_EDGEMODE_JSRT and then include jsrt.h, and link against chakrart.lib. To use jscript9 mode, include jsrt.h and link against jsrt.lib." #endif #ifndef _CHAKRART_H_ #define _CHAKRART_H_ #if NTDDI_VERSION >= NTDDI_WIN7 #include #include #pragma region Application Family #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) /// /// An error code returned from a Chakra hosting API. /// typedef _Return_type_success_(return == 0) enum JsErrorCode : unsigned int { /// /// Success error code. /// JsNoError = 0, /// /// Category of errors that relates to incorrect usage of the API itself. /// JsErrorCategoryUsage = 0x10000, /// /// An argument to a hosting API was invalid. /// JsErrorInvalidArgument, /// /// An argument to a hosting API was null in a context where null is not allowed. /// JsErrorNullArgument, /// /// The hosting API requires that a context be current, but there is no current context. /// JsErrorNoCurrentContext, /// /// The engine is in an exception state and no APIs can be called until the exception is /// cleared. /// JsErrorInExceptionState, /// /// A hosting API is not yet implemented. /// JsErrorNotImplemented, /// /// A hosting API was called on the wrong thread. /// JsErrorWrongThread, /// /// A runtime that is still in use cannot be disposed. /// JsErrorRuntimeInUse, /// /// A bad serialized script was used, or the serialized script was serialized by a /// different version of the Chakra engine. /// JsErrorBadSerializedScript, /// /// The runtime is in a disabled state. /// JsErrorInDisabledState, /// /// Runtime does not support reliable script interruption. /// JsErrorCannotDisableExecution, /// /// A heap enumeration is currently underway in the script context. /// JsErrorHeapEnumInProgress, /// /// A hosting API that operates on object values was called with a non-object value. /// JsErrorArgumentNotObject, /// /// A script context is in the middle of a profile callback. /// JsErrorInProfileCallback, /// /// A thread service callback is currently underway. /// JsErrorInThreadServiceCallback, /// /// Scripts cannot be serialized in debug contexts. /// JsErrorCannotSerializeDebugScript, /// /// The context cannot be put into a debug state because it is already in a debug state. /// JsErrorAlreadyDebuggingContext, /// /// The context cannot start profiling because it is already profiling. /// JsErrorAlreadyProfilingContext, /// /// Idle notification given when the host did not enable idle processing. /// JsErrorIdleNotEnabled, /// /// The context did not accept the enqueue callback. /// JsCannotSetProjectionEnqueueCallback, /// /// Failed to start WinRT projection. /// JsErrorCannotStartProjection, /// /// The operation is not supported in an object before collect callback. /// JsErrorInObjectBeforeCollectCallback, /// /// Object cannot be unwrapped to IInspectable pointer. /// JsErrorObjectNotInspectable, /// /// 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. /// JsErrorPropertyNotSymbol, /// /// 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. /// JsErrorPropertyNotString, /// /// Category of errors that relates to errors occurring within the engine itself. /// JsErrorCategoryEngine = 0x20000, /// /// The Chakra engine has run out of memory. /// JsErrorOutOfMemory, /// /// Category of errors that relates to errors in a script. /// JsErrorCategoryScript = 0x30000, /// /// A JavaScript exception occurred while running a script. /// JsErrorScriptException, /// /// JavaScript failed to compile. /// JsErrorScriptCompile, /// /// A script was terminated due to a request to suspend a runtime. /// JsErrorScriptTerminated, /// /// A script was terminated because it tried to use eval or function and eval /// was disabled. /// JsErrorScriptEvalDisabled, /// /// Category of errors that are fatal and signify failure of the engine. /// JsErrorCategoryFatal = 0x40000, /// /// A fatal error in the engine has occurred. /// JsErrorFatal, }; /// /// A handle to a Chakra runtime. /// /// /// /// 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. /// /// /// Runtimes can be used on any thread, but only one thread can call into a runtime at any /// time. /// /// /// NOTE: A JsRuntimeHandle, 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 JsDisposeRuntime is called. /// /// typedef void *JsRuntimeHandle; /// /// An invalid runtime handle. /// const JsRuntimeHandle JS_INVALID_RUNTIME_HANDLE = NULL; /// /// A reference to an object owned by the Chakra garbage collector. /// /// /// A Chakra runtime will automatically track JsRef references as long as they are /// stored in local variables or in parameters (i.e. on the stack). Storing a JsRef /// somewhere other than on the stack requires calling JsAddRef and JsRelease to /// manage the lifetime of the object, otherwise the garbage collector may free the object /// while it is still in use. /// typedef void *JsRef; /// /// An invalid reference. /// const JsRef JS_INVALID_REFERENCE = NULL; /// /// A reference to a script context. /// /// /// /// Each script context contains its own global object, distinct from the global object in /// other script contexts. /// /// /// Many Chakra hosting APIs require an "active" script context, which can be set using /// JsSetCurrentContext. Chakra hosting APIs that require a current context to be set /// will note that explicitly in their documentation. /// /// typedef JsRef JsContextRef; /// /// A reference to a JavaScript value. /// /// /// A JavaScript value is one of the following types of values: undefined, null, Boolean, /// string, number, or object. /// typedef JsRef JsValueRef; /// /// A cookie that identifies a script for debugging purposes. /// typedef DWORD_PTR JsSourceContext; /// /// An empty source context. /// const JsSourceContext JS_SOURCE_CONTEXT_NONE = (JsSourceContext)-1; /// /// A property identifier. /// /// /// Property identifiers are used to refer to properties of JavaScript objects instead of using /// strings. /// typedef JsRef JsPropertyIdRef; /// /// Attributes of a runtime. /// typedef enum JsRuntimeAttributes { /// /// No special attributes. /// JsRuntimeAttributeNone = 0x00000000, /// /// The runtime will not do any work (such as garbage collection) on background threads. /// JsRuntimeAttributeDisableBackgroundWork = 0x00000001, /// /// 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. /// JsRuntimeAttributeAllowScriptInterrupt = 0x00000002, /// /// Host will call JsIdle, so enable idle processing. Otherwise, the runtime will /// manage memory slightly more aggressively. /// JsRuntimeAttributeEnableIdleProcessing = 0x00000004, /// /// Runtime will not generate native code. /// JsRuntimeAttributeDisableNativeCodeGeneration = 0x00000008, /// /// Using eval or function constructor will throw an exception. /// JsRuntimeAttributeDisableEval = 0x00000010, }; /// /// The type of a typed JavaScript array. /// typedef enum JsTypedArrayType { /// /// An int8 array. /// JsArrayTypeInt8, /// /// An uint8 array. /// JsArrayTypeUint8, /// /// An uint8 clamped array. /// JsArrayTypeUint8Clamped, /// /// An int16 array. /// JsArrayTypeInt16, /// /// An uint16 array. /// JsArrayTypeUint16, /// /// An int32 array. /// JsArrayTypeInt32, /// /// An uint32 array. /// JsArrayTypeUint32, /// /// A float32 array. /// JsArrayTypeFloat32, /// /// A float64 array. /// JsArrayTypeFloat64 }; /// /// Allocation callback event type. /// typedef enum JsMemoryEventType { /// /// Indicates a request for memory allocation. /// JsMemoryAllocate = 0, /// /// Indicates a memory freeing event. /// JsMemoryFree = 1, /// /// Indicates a failed allocation event. /// JsMemoryFailure = 2 }; /// /// User implemented callback routine for memory allocation events /// /// /// Use JsSetRuntimeMemoryAllocationCallback to register this callback. /// /// /// The state passed to JsSetRuntimeMemoryAllocationCallback. /// /// The type of type allocation event. /// The size of the allocation. /// /// For the JsMemoryAllocate event, returning true 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. /// typedef bool (CALLBACK * JsMemoryAllocationCallback)(_In_opt_ void *callbackState, _In_ JsMemoryEventType allocationEvent, _In_ size_t allocationSize); /// /// A callback called before collection. /// /// /// Use JsSetBeforeCollectCallback to register this callback. /// /// The state passed to JsSetBeforeCollectCallback. typedef void (CALLBACK *JsBeforeCollectCallback)(_In_opt_ void *callbackState); /// /// A callback called before collecting an object. /// /// /// Use JsSetObjectBeforeCollectCallback to register this callback. /// /// The object to be collected. /// The state passed to JsSetObjectBeforeCollectCallback. typedef void (CALLBACK *JsObjectBeforeCollectCallback)(_In_ JsRef ref, _In_opt_ void *callbackState); /// /// A background work item callback. /// /// /// 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. /// /// Data argument passed to the thread service. typedef void (CALLBACK *JsBackgroundWorkItemCallback)(_In_opt_ void *callbackState); /// /// A thread service callback. /// /// /// The host can specify a background thread service when calling JsCreateRuntime. 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. /// /// The callback for the background work item. /// The data argument to be passed to the callback. typedef bool (CALLBACK *JsThreadServiceCallback)(_In_ JsBackgroundWorkItemCallback callback, _In_opt_ void *callbackState); /// /// Version of the runtime. /// typedef enum JsRuntimeVersion { /// /// Create runtime with highest version present on the machine at runtime. /// JsRuntimeVersionEdge = -1, }; /// /// Create runtime with IE10 version. /// __declspec(deprecated("Only JsRuntimeVersionEdge is supported when targeting the edge-mode JavaScript Runtime header. To use jscript9 mode, which supports targeting docmode 10 or 11, omit USE_EDGEMODE_JSRT before including jsrt.h, and link against jsrt.lib. For more information, go to http://go.microsoft.com/fwlink/?LinkId=522493")) const JsRuntimeVersion JsRuntimeVersion10 = (JsRuntimeVersion)0; /// /// Create runtime with IE11 version. /// __declspec(deprecated("Only JsRuntimeVersionEdge is supported when targeting the edge-mode JavaScript Runtime header. To use jscript9 mode, which supports targeting docmode 10 or 11, omit USE_EDGEMODE_JSRT before including jsrt.h, and link against jsrt.lib. For more information, go to http://go.microsoft.com/fwlink/?LinkId=522493")) const JsRuntimeVersion JsRuntimeVersion11 = (JsRuntimeVersion)1; /// /// Creates a new runtime. /// /// The attributes of the runtime to be created. /// The thread service for the runtime. Can be null. /// The runtime created. /// In the edge-mode binary, chakra.dll, this function lacks the runtimeVersion /// parameter (compare to jsrt9.h). /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateRuntime( _In_ JsRuntimeAttributes attributes, _In_opt_ JsThreadServiceCallback threadService, _Out_ JsRuntimeHandle *runtime); /// /// Performs a full garbage collection. /// /// The runtime in which the garbage collection will be performed. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCollectGarbage( _In_ JsRuntimeHandle runtime); /// /// Disposes a runtime. /// /// /// 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. /// /// The runtime to dispose. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsDisposeRuntime( _In_ JsRuntimeHandle runtime); /// /// Gets the current memory usage for a runtime. /// /// /// Memory usage can be always be retrieved, regardless of whether or not the runtime is active /// on another thread. /// /// The runtime whose memory usage is to be retrieved. /// The runtime's current memory usage, in bytes. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetRuntimeMemoryUsage( _In_ JsRuntimeHandle runtime, _Out_ size_t *memoryUsage); /// /// Gets the current memory limit for a runtime. /// /// /// The memory limit of a runtime can be always be retrieved, regardless of whether or not the /// runtime is active on another thread. /// /// The runtime whose memory limit is to be retrieved. /// /// The runtime's current memory limit, in bytes, or -1 if no limit has been set. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetRuntimeMemoryLimit( _In_ JsRuntimeHandle runtime, _Out_ size_t *memoryLimit); /// /// Sets the current memory limit for a runtime. /// /// /// /// 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. /// /// /// A runtime's memory limit can be always be set, regardless of whether or not the runtime is /// active on another thread. /// /// /// The runtime whose memory limit is to be set. /// /// The new runtime memory limit, in bytes, or -1 for no memory limit. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetRuntimeMemoryLimit( _In_ JsRuntimeHandle runtime, _In_ size_t memoryLimit); /// /// Sets a memory allocation callback for specified runtime /// /// /// /// 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. /// /// /// The callback is invoked on the current runtime execution thread, therefore execution is /// blocked until the callback completes. /// /// /// 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. /// /// /// The runtime for which to register the allocation callback. /// /// User provided state that will be passed back to the callback. /// /// /// Memory allocation callback to be called for memory allocation events. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetRuntimeMemoryAllocationCallback( _In_ JsRuntimeHandle runtime, _In_opt_ void *callbackState, _In_ JsMemoryAllocationCallback allocationCallback); /// /// Sets a callback function that is called by the runtime before garbage collection. /// /// /// /// The callback is invoked on the current runtime execution thread, therefore execution is /// blocked until the callback completes. /// /// /// The callback can be used by hosts to prepare for garbage collection. For example, by /// releasing unnecessary references on Chakra objects. /// /// /// The runtime for which to register the allocation callback. /// /// User provided state that will be passed back to the callback. /// /// The callback function being set. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetRuntimeBeforeCollectCallback( _In_ JsRuntimeHandle runtime, _In_opt_ void *callbackState, _In_ JsBeforeCollectCallback beforeCollectCallback); /// /// Adds a reference to a garbage collected object. /// /// /// This only needs to be called on JsRef handles that are not going to be stored /// somewhere on the stack. Calling JsAddRef ensures that the object the JsRef /// refers to will not be freed until JsRelease is called. /// /// The object to add a reference to. /// The object's new reference count (can pass in null). /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsAddRef( _In_ JsRef ref, _Out_opt_ unsigned int *count); /// /// Releases a reference to a garbage collected object. /// /// /// Removes a reference to a JsRef handle that was created by JsAddRef. /// /// The object to add a reference to. /// The object's new reference count (can pass in null). /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsRelease( _In_ JsRef ref, _Out_opt_ unsigned int *count); /// /// Sets a callback function that is called by the runtime before garbage collection of /// an object. /// /// /// /// The callback is invoked on the current runtime execution thread, therefore execution is /// blocked until the callback completes. /// /// /// The object for which to register the callback. /// /// User provided state that will be passed back to the callback. /// /// The callback function being set. Use null to clear /// previously registered callback. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetObjectBeforeCollectCallback( _In_ JsRef ref, _In_opt_ void *callbackState, _In_ JsObjectBeforeCollectCallback objectBeforeCollectCallback); /// /// Creates a script context for running scripts. /// /// /// Each script context has its own global object that is isolated from all other script /// contexts. /// /// The runtime the script context is being created in. /// The created script context. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateContext( _In_ JsRuntimeHandle runtime, _Out_ JsContextRef *newContext); /// /// Starts debugging in the current context. /// /// /// /// The host should make sure that CoInitializeEx is called with COINIT_MULTITHREADED or COINIT_APARTMENTTHREADED at least once before using this API /// /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsStartDebugging(); /// /// Gets the current script context on the thread. /// /// /// The current script context on the thread, null if there is no current script context. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetCurrentContext( _Out_ JsContextRef *currentContext); /// /// Sets the current script context on the thread. /// /// The script context to make current. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetCurrentContext( _In_ JsContextRef context); /// /// Gets the runtime that the context belongs to. /// /// The context to get the runtime from. /// The runtime the context belongs to. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetRuntime( _In_ JsContextRef context, _Out_ JsRuntimeHandle *runtime); /// /// Tells the runtime to do any idle processing it need to do. /// /// /// /// If idle processing has been enabled for the current runtime, calling JsIdle will /// inform the current runtime that the host is idle and that the runtime can perform /// memory cleanup tasks. /// /// /// JsIdle can also return the number of system ticks until there will be more idle work /// for the runtime to do. Calling JsIdle before this number of ticks has passed will do /// no work. /// /// /// Requires an active script context. /// /// /// /// 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. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsIdle( _Out_opt_ unsigned int *nextIdleTick); /// /// Parses a script and returns a function representing the script. /// /// /// Requires an active script context. /// /// The script to parse. /// /// A cookie identifying the script that can be used by debuggable script contexts. /// /// The location the script came from. /// A function representing the script code. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsParseScript( _In_z_ const wchar_t *script, _In_ JsSourceContext sourceContext, _In_z_ const wchar_t *sourceUrl, _Out_ JsValueRef *result); /// /// Executes a script. /// /// /// Requires an active script context. /// /// The script to run. /// /// A cookie identifying the script that can be used by debuggable script contexts. /// /// The location the script came from. /// The result of the script, if any. This parameter can be null. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsRunScript( _In_z_ const wchar_t *script, _In_ JsSourceContext sourceContext, _In_z_ const wchar_t *sourceUrl, _Out_ JsValueRef *result); /// /// Serializes a parsed script to a buffer than can be reused. /// /// /// /// JsSerializeScript 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. /// /// /// Requires an active script context. /// /// /// The script to serialize. /// The buffer to put the serialized script into. Can be null. /// /// On entry, the size of the buffer, in bytes; on exit, the size of the buffer, in bytes, /// required to hold the serialized script. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSerializeScript( _In_z_ const wchar_t *script, _Out_writes_to_opt_(*bufferSize, *bufferSize) BYTE *buffer, _Inout_ unsigned long *bufferSize); /// /// Parses a serialized script and returns a function representing the script. /// /// /// /// Requires an active script context. /// /// /// The runtime will hold on to the buffer until all instances of any functions created from /// the buffer are garbage collected. /// /// /// The script to parse. /// The serialized script. /// /// A cookie identifying the script that can be used by debuggable script contexts. /// /// The location the script came from. /// A function representing the script code. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsParseSerializedScript( _In_z_ const wchar_t *script, _In_ BYTE *buffer, _In_ JsSourceContext sourceContext, _In_z_ const wchar_t *sourceUrl, _Out_ JsValueRef *result); /// /// Runs a serialized script. /// /// /// /// Requires an active script context. /// /// /// The runtime will hold on to the buffer until all instances of any functions created from /// the buffer are garbage collected. /// /// /// The source code of the serialized script. /// The serialized script. /// /// A cookie identifying the script that can be used by debuggable script contexts. /// /// The location the script came from. /// /// The result of running the script, if any. This parameter can be null. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsRunSerializedScript( _In_z_ const wchar_t *script, _In_ BYTE *buffer, _In_ JsSourceContext sourceContext, _In_z_ const wchar_t *sourceUrl, _Out_ JsValueRef *result); /// /// Gets the property ID associated with the name. /// /// /// /// Property IDs are specific to a context and cannot be used across contexts. /// /// /// Requires an active script context. /// /// /// /// The name of the property ID to get or create. The name may consist of only digits. /// /// The property ID in this runtime for the given name. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetPropertyIdFromName( _In_z_ const wchar_t *name, _Out_ JsPropertyIdRef *propertyId); /// /// Gets the name associated with the property ID. /// /// /// /// Requires an active script context. /// /// /// The returned buffer is valid as long as the runtime is alive and cannot be used /// once the runtime has been disposed. /// /// /// The property ID to get the name of. /// The name associated with the property ID. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetPropertyNameFromId( _In_ JsPropertyIdRef propertyId, _Outptr_result_z_ const wchar_t **name); /// /// Gets the symbol associated with the property ID. /// /// /// /// Requires an active script context. /// /// /// The property ID to get the symbol of. /// The symbol associated with the property ID. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetSymbolFromPropertyId( _In_ JsPropertyIdRef propertyId, _Out_ JsValueRef *symbol); /// /// Type enumeration of a JavaScript property /// typedef enum JsPropertyIdType { /// /// Type enumeration of a JavaScript string property /// JsPropertyIdTypeString, /// /// Type enumeration of a JavaScript symbol property /// JsPropertyIdTypeSymbol }; /// /// Gets the type of property /// /// /// /// Requires an active script context. /// /// /// The property ID to get the type of. /// The JsPropertyIdType of the given property ID /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetPropertyIdType( _In_ JsPropertyIdRef propertyId, _Out_ JsPropertyIdType* propertyIdType); /// /// Gets the property ID associated with the symbol. /// /// /// /// Property IDs are specific to a context and cannot be used across contexts. /// /// /// Requires an active script context. /// /// /// /// The symbol whose property ID is being retrieved. /// /// The property ID for the given symbol. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetPropertyIdFromSymbol( _In_ JsValueRef symbol, _Out_ JsPropertyIdRef *propertyId); /// /// Creates a Javascript symbol. /// /// /// Requires an active script context. /// /// The string description of the symbol. Can be null. /// The new symbol. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateSymbol( _In_ JsValueRef description, _Out_ JsValueRef *result); /// /// Gets the list of all symbol properties on the object. /// /// /// Requires an active script context. /// /// The object from which to get the property symbols. /// An array of property symbols. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetOwnPropertySymbols( _In_ JsValueRef object, _Out_ JsValueRef *propertySymbols); /// /// Gets the value of undefined in the current script context. /// /// /// Requires an active script context. /// /// The undefined value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetUndefinedValue( _Out_ JsValueRef *undefinedValue); /// /// Gets the value of null in the current script context. /// /// /// Requires an active script context. /// /// The null value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetNullValue( _Out_ JsValueRef *nullValue); /// /// Gets the value of true in the current script context. /// /// /// Requires an active script context. /// /// The true value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetTrueValue( _Out_ JsValueRef *trueValue); /// /// Gets the value of false in the current script context. /// /// /// Requires an active script context. /// /// The false value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetFalseValue( _Out_ JsValueRef *falseValue); /// /// Creates a Boolean value from a bool value. /// /// /// Requires an active script context. /// /// The value to be converted. /// The converted value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsBoolToBoolean( _In_ bool value, _Out_ JsValueRef *booleanValue); /// /// Retrieves the bool value of a Boolean value. /// /// /// Requires an active script context. /// /// The value to be converted. /// The converted value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsBooleanToBool( _In_ JsValueRef value, _Out_ bool *boolValue); /// /// Converts the value to Boolean using standard JavaScript semantics. /// /// /// Requires an active script context. /// /// The value to be converted. /// The converted value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsConvertValueToBoolean( _In_ JsValueRef value, _Out_ JsValueRef *booleanValue); /// /// The JavaScript type of a JsValueRef. /// typedef enum JsValueType { /// /// The value is the undefined value. /// JsUndefined = 0, /// /// The value is the null value. /// JsNull = 1, /// /// The value is a JavaScript number value. /// JsNumber = 2, /// /// The value is a JavaScript string value. /// JsString = 3, /// /// The value is a JavaScript Boolean value. /// JsBoolean = 4, /// /// The value is a JavaScript object value. /// JsObject = 5, /// /// The value is a JavaScript function object value. /// JsFunction = 6, /// /// The value is a JavaScript error object value. /// JsError = 7, /// /// The value is a JavaScript array object value. /// JsArray = 8, /// /// The value is a JavaScript symbol value. /// JsSymbol = 9, /// /// The value is a JavaScript ArrayBuffer object value. /// JsArrayBuffer = 10, /// /// The value is a JavaScript typed array object value. /// JsTypedArray = 11, /// /// The value is a JavaScript DataView object value. /// JsDataView = 12, }; /// /// Gets the JavaScript type of a JsValueRef. /// /// /// Requires an active script context. /// /// The value whose type is to be returned. /// The type of the value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetValueType( _In_ JsValueRef value, _Out_ JsValueType *type); /// /// Creates a number value from a double value. /// /// /// Requires an active script context. /// /// The double to convert to a number value. /// The new number value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsDoubleToNumber( _In_ double doubleValue, _Out_ JsValueRef *value); /// /// Creates a number value from an int value. /// /// /// Requires an active script context. /// /// The int to convert to a number value. /// The new number value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsIntToNumber( _In_ int intValue, _Out_ JsValueRef *value); /// /// Retrieves the double value of a number value. /// /// /// /// This function retrieves the value of a number value. It will fail with /// JsErrorInvalidArgument if the type of the value is not number. /// /// /// Requires an active script context. /// /// /// The number value to convert to a double value. /// The double value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsNumberToDouble( _In_ JsValueRef value, _Out_ double *doubleValue); /// /// Retrieves the int value of a number value. /// /// /// /// This function retrieves the value of a number value and converts to an int value. /// It will fail with JsErrorInvalidArgument if the type of the value is not number. /// /// /// Requires an active script context. /// /// /// The number value to convert to an int value. /// The int value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsNumberToInt( _In_ JsValueRef value, _Out_ int *intValue); /// /// Converts the value to number using standard JavaScript semantics. /// /// /// Requires an active script context. /// /// The value to be converted. /// The converted value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsConvertValueToNumber( _In_ JsValueRef value, _Out_ JsValueRef *numberValue); /// /// Gets the length of a string value. /// /// /// Requires an active script context. /// /// The string value to get the length of. /// The length of the string. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetStringLength( _In_ JsValueRef stringValue, _Out_ int *length); /// /// Creates a string value from a string pointer. /// /// /// Requires an active script context. /// /// The string pointer to convert to a string value. /// The length of the string to convert. /// The new string value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsPointerToString( _In_reads_(stringLength) const wchar_t *stringValue, _In_ size_t stringLength, _Out_ JsValueRef *value); /// /// Retrieves the string pointer of a string value. /// /// /// /// This function retrieves the string pointer of a string value. It will fail with /// JsErrorInvalidArgument if the type of the value is not string. The lifetime /// of the string returned will be the same as the lifetime of the value it came from, however /// the string pointer is not considered a reference to the value (and so will not keep it /// from being collected). /// /// /// Requires an active script context. /// /// /// The string value to convert to a string pointer. /// The string pointer. /// The length of the string. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsStringToPointer( _In_ JsValueRef value, _Outptr_result_buffer_(*stringLength) const wchar_t **stringValue, _Out_ size_t *stringLength); /// /// Converts the value to string using standard JavaScript semantics. /// /// /// Requires an active script context. /// /// The value to be converted. /// The converted value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsConvertValueToString( _In_ JsValueRef value, _Out_ JsValueRef *stringValue); /// /// Creates a JavaScript value that is a projection of the passed in VARIANT. /// /// /// /// The projected value can be used by script to call a COM automation object from script. /// Hosts are responsible for enforcing COM threading rules. /// /// /// Requires an active script context. /// /// /// A VARIANT to be projected. /// A JavaScript value that is a projection of the VARIANT. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsVariantToValue( _In_ VARIANT *variant, _Out_ JsValueRef *value); /// /// Initializes the passed in VARIANT as a projection of a JavaScript value. /// /// /// /// The projection VARIANT can be used by COM automation clients to call into the /// projected JavaScript object. /// /// /// Requires an active script context. /// /// /// A JavaScript value to project as a VARIANT. /// /// A pointer to a VARIANT struct that will be initialized as a projection. /// STDAPI_(JsErrorCode) JsValueToVariant( _In_ JsValueRef object, _Out_ VARIANT *variant); /// /// Gets the global object in the current script context. /// /// /// Requires an active script context. /// /// The global object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetGlobalObject( _Out_ JsValueRef *globalObject); /// /// Creates a new object. /// /// /// Requires an active script context. /// /// The new object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateObject( _Out_ JsValueRef *object); /// /// A finalizer callback. /// /// /// The external data that was passed in when creating the object being finalized. /// typedef void (CALLBACK *JsFinalizeCallback)(_In_opt_ void *data); /// /// Creates a new object that stores some external data. /// /// /// Requires an active script context. /// /// External data that the object will represent. May be null. /// /// A callback for when the object is finalized. May be null. /// /// The new object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateExternalObject( _In_opt_ void *data, _In_opt_ JsFinalizeCallback finalizeCallback, _Out_ JsValueRef *object); /// /// Converts the value to object using standard JavaScript semantics. /// /// /// Requires an active script context. /// /// The value to be converted. /// The converted value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsConvertValueToObject( _In_ JsValueRef value, _Out_ JsValueRef *object); /// /// Returns the prototype of an object. /// /// /// Requires an active script context. /// /// The object whose prototype is to be returned. /// The object's prototype. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetPrototype( _In_ JsValueRef object, _Out_ JsValueRef *prototypeObject); /// /// Sets the prototype of an object. /// /// /// Requires an active script context. /// /// The object whose prototype is to be changed. /// The object's new prototype. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetPrototype( _In_ JsValueRef object, _In_ JsValueRef prototypeObject); /// /// Returns a value that indicates whether an object is extensible or not. /// /// /// Requires an active script context. /// /// The object to test. /// Whether the object is extensible or not. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetExtensionAllowed( _In_ JsValueRef object, _Out_ bool *value); /// /// Makes an object non-extensible. /// /// /// Requires an active script context. /// /// The object to make non-extensible. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsPreventExtension( _In_ JsValueRef object); /// /// Gets an object's property. /// /// /// Requires an active script context. /// /// The object that contains the property. /// The ID of the property. /// The value of the property. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetProperty( _In_ JsValueRef object, _In_ JsPropertyIdRef propertyId, _Out_ JsValueRef *value); /// /// Gets a property descriptor for an object's own property. /// /// /// Requires an active script context. /// /// The object that has the property. /// The ID of the property. /// The property descriptor. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetOwnPropertyDescriptor( _In_ JsValueRef object, _In_ JsPropertyIdRef propertyId, _Out_ JsValueRef *propertyDescriptor); /// /// Gets the list of all properties on the object. /// /// /// Requires an active script context. /// /// The object from which to get the property names. /// An array of property names. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetOwnPropertyNames( _In_ JsValueRef object, _Out_ JsValueRef *propertyNames); /// /// Puts an object's property. /// /// /// Requires an active script context. /// /// The object that contains the property. /// The ID of the property. /// The new value of the property. /// The property set should follow strict mode rules. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetProperty( _In_ JsValueRef object, _In_ JsPropertyIdRef propertyId, _In_ JsValueRef value, _In_ bool useStrictRules); /// /// Determines whether an object has a property. /// /// /// Requires an active script context. /// /// The object that may contain the property. /// The ID of the property. /// Whether the object (or a prototype) has the property. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsHasProperty( _In_ JsValueRef object, _In_ JsPropertyIdRef propertyId, _Out_ bool *hasProperty); /// /// Deletes an object's property. /// /// /// Requires an active script context. /// /// The object that contains the property. /// The ID of the property. /// Whether the property was deleted. /// The property set should follow strict mode rules. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsDeleteProperty( _In_ JsValueRef object, _In_ JsPropertyIdRef propertyId, _In_ bool useStrictRules, _Out_ JsValueRef *result); /// /// Defines a new object's own property from a property descriptor. /// /// /// Requires an active script context. /// /// The object that has the property. /// The ID of the property. /// The property descriptor. /// Whether the property was defined. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsDefineProperty( _In_ JsValueRef object, _In_ JsPropertyIdRef propertyId, _In_ JsValueRef propertyDescriptor, _Out_ bool *result); /// /// Tests whether an object has a value at the specified index. /// /// /// Requires an active script context. /// /// The object to operate on. /// The index to test. /// Whether the object has an value at the specified index. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsHasIndexedProperty( _In_ JsValueRef object, _In_ JsValueRef index, _Out_ bool *result); /// /// Retrieve the value at the specified index of an object. /// /// /// Requires an active script context. /// /// The object to operate on. /// The index to retrieve. /// The retrieved value. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetIndexedProperty( _In_ JsValueRef object, _In_ JsValueRef index, _Out_ JsValueRef *result); /// /// Set the value at the specified index of an object. /// /// /// Requires an active script context. /// /// The object to operate on. /// The index to set. /// The value to set. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetIndexedProperty( _In_ JsValueRef object, _In_ JsValueRef index, _In_ JsValueRef value); /// /// Delete the value at the specified index of an object. /// /// /// Requires an active script context. /// /// The object to operate on. /// The index to delete. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsDeleteIndexedProperty( _In_ JsValueRef object, _In_ JsValueRef index); /// /// Determines whether an object has its indexed properties in external data. /// /// The object. /// Whether the object has its indexed properties in external data. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsHasIndexedPropertiesExternalData( _In_ JsValueRef object, _Out_ bool* value); /// /// Retrieves an object's indexed properties external data information. /// /// The object. /// The external data back store for the object's indexed properties. /// The array element type in external data. /// The number of array elements in external data. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetIndexedPropertiesExternalData( _In_ JsValueRef object, _Out_ void** data, _Out_ JsTypedArrayType* arrayType, _Out_ unsigned int* elementLength); /// /// 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. /// /// /// Requires an active script context. /// /// The object to operate on. /// The external data to be used as back store for the object's indexed properties. /// The array element type in external data. /// The number of array elements in external data. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetIndexedPropertiesToExternalData( _In_ JsValueRef object, _In_ void* data, _In_ JsTypedArrayType arrayType, _In_ unsigned int elementLength); /// /// Compare two JavaScript values for equality. /// /// /// /// This function is equivalent to the == operator in Javascript. /// /// /// Requires an active script context. /// /// /// The first object to compare. /// The second object to compare. /// Whether the values are equal. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsEquals( _In_ JsValueRef object1, _In_ JsValueRef object2, _Out_ bool *result); /// /// Compare two JavaScript values for strict equality. /// /// /// /// This function is equivalent to the === operator in Javascript. /// /// /// Requires an active script context. /// /// /// The first object to compare. /// The second object to compare. /// Whether the values are strictly equal. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsStrictEquals( _In_ JsValueRef object1, _In_ JsValueRef object2, _Out_ bool *result); /// /// Determines whether an object is an external object. /// /// /// Requires an active script context. /// /// The object. /// Whether the object is an external object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsHasExternalData( _In_ JsValueRef object, _Out_ bool *value); /// /// Retrieves the data from an external object. /// /// /// Requires an active script context. /// /// The external object. /// /// The external data stored in the object. Can be null if no external data is stored in the /// object. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetExternalData( _In_ JsValueRef object, _Out_ void **externalData); /// /// Sets the external data on an external object. /// /// /// Requires an active script context. /// /// The external object. /// /// The external data to be stored in the object. Can be null if no external data is /// to be stored in the object. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetExternalData( _In_ JsValueRef object, _In_opt_ void *externalData); /// /// Creates a Javascript array object. /// /// /// Requires an active script context. /// /// The initial length of the array. /// The new array object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateArray( _In_ unsigned int length, _Out_ JsValueRef *result); /// /// Creates a Javascript ArrayBuffer object. /// /// /// Requires an active script context. /// /// /// The number of bytes in the ArrayBuffer. /// /// The new ArrayBuffer object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateArrayBuffer( _In_ unsigned int byteLength, _Out_ JsValueRef *result); /// /// Creates a Javascript typed array object. /// /// /// /// The baseArray can be an ArrayBuffer, another typed array, or a JavaScript /// Array. 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. /// /// /// Requires an active script context. /// /// /// The type of the array to create. /// /// The base array of the new array. Use JS_INVALID_REFERENCE if no base array. /// /// /// 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. /// /// /// The number of elements in the array. Only applicable when creating a new typed array without /// baseArray (baseArray is JS_INVALID_REFERENCE) or when baseArray is an ArrayBuffer object. /// Must be 0 otherwise. /// /// The new typed array object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateTypedArray( _In_ JsTypedArrayType arrayType, _In_ JsValueRef baseArray, _In_ unsigned int byteOffset, _In_ unsigned int elementLength, _Out_ JsValueRef *result); /// /// Creates a Javascript DataView object. /// /// /// Requires an active script context. /// /// /// An existing ArrayBuffer object to use as the storage for the result DataView object. /// /// /// The offset in bytes from the start of arrayBuffer for result DataView to reference. /// /// /// The number of bytes in the ArrayBuffer for result DataView to reference. /// /// The new DataView object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateDataView( _In_ JsValueRef arrayBuffer, _In_ unsigned int byteOffset, _In_ unsigned int byteLength, _Out_ JsValueRef *result); /// /// Obtains the underlying memory storage used by an ArrayBuffer. /// /// /// Requires an active script context. /// /// The ArrayBuffer instance. /// /// 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. /// /// The number of bytes in the buffer. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetArrayBufferStorage( _In_ JsValueRef arrayBuffer, _Outptr_result_bytebuffer_(*bufferLength) BYTE **buffer, _Out_ unsigned int *bufferLength); /// /// Obtains the underlying memory storage used by a typed array. /// /// /// Requires an active script context. /// /// The typed array instance. /// /// 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. /// /// The number of bytes in the buffer. /// The type of the array. /// /// The size of an element of the array. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetTypedArrayStorage( _In_ JsValueRef typedArray, _Outptr_result_bytebuffer_(*bufferLength) BYTE **buffer, _Out_ unsigned int *bufferLength, _Out_opt_ JsTypedArrayType *arrayType, _Out_opt_ int *elementSize); /// /// Obtains the underlying memory storage used by a DataView. /// /// /// Requires an active script context. /// /// The DataView instance. /// /// 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. /// /// The number of bytes in the buffer. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetDataViewStorage( _In_ JsValueRef dataView, _Outptr_result_bytebuffer_(*bufferLength) BYTE **buffer, _Out_ unsigned int *bufferLength); /// /// Invokes a function. /// /// /// Requires an active script context. /// /// The function to invoke. /// The arguments to the call. /// The number of arguments being passed in to the function. /// The value returned from the function invocation, if any. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCallFunction( _In_ JsValueRef function, _In_reads_(argumentCount) JsValueRef *arguments, _In_ unsigned short argumentCount, _Out_opt_ JsValueRef *result); /// /// Invokes a function as a constructor. /// /// /// Requires an active script context. /// /// The function to invoke as a constructor. /// The arguments to the call. /// The number of arguments being passed in to the function. /// The value returned from the function invocation. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsConstructObject( _In_ JsValueRef function, _In_reads_(argumentCount) JsValueRef *arguments, _In_ unsigned short argumentCount, _Out_ JsValueRef *result); /// /// A function callback. /// /// /// A function object that represents the function being invoked. /// /// Indicates whether this is a regular call or a 'new' call. /// The arguments to the call. /// The number of arguments. /// /// The state passed to JsCreateFunction. /// /// The result of the call, if any. typedef _Ret_maybenull_ JsValueRef(CALLBACK * JsNativeFunction)(_In_ JsValueRef callee, _In_ bool isConstructCall, _In_ JsValueRef *arguments, _In_ unsigned short argumentCount, _In_opt_ void *callbackState); /// /// Creates a new JavaScript function. /// /// /// Requires an active script context. /// /// The method to call when the function is invoked. /// /// User provided state that will be passed back to the callback. /// /// The new function object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateFunction( _In_ JsNativeFunction nativeFunction, _In_opt_ void *callbackState, _Out_ JsValueRef *function); /// /// Creates a new JavaScript function with name. /// /// /// Requires an active script context. /// /// The name of this function that will be used for diagnostics and stringification purposes. /// The method to call when the function is invoked. /// /// User provided state that will be passed back to the callback. /// /// The new function object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateNamedFunction( _In_ JsValueRef name, _In_ JsNativeFunction nativeFunction, _In_opt_ void *callbackState, _Out_ JsValueRef *function); /// /// Creates a new JavaScript error object /// /// /// Requires an active script context. /// /// Message for the error object. /// The new error object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateError( _In_ JsValueRef message, _Out_ JsValueRef *error); /// /// Creates a new JavaScript RangeError error object /// /// /// Requires an active script context. /// /// Message for the error object. /// The new error object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateRangeError( _In_ JsValueRef message, _Out_ JsValueRef *error); /// /// Creates a new JavaScript ReferenceError error object /// /// /// Requires an active script context. /// /// Message for the error object. /// The new error object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateReferenceError( _In_ JsValueRef message, _Out_ JsValueRef *error); /// /// Creates a new JavaScript SyntaxError error object /// /// /// Requires an active script context. /// /// Message for the error object. /// The new error object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateSyntaxError( _In_ JsValueRef message, _Out_ JsValueRef *error); /// /// Creates a new JavaScript TypeError error object /// /// /// Requires an active script context. /// /// Message for the error object. /// The new error object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateTypeError( _In_ JsValueRef message, _Out_ JsValueRef *error); /// /// Creates a new JavaScript URIError error object /// /// /// Requires an active script context. /// /// Message for the error object. /// The new error object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsCreateURIError( _In_ JsValueRef message, _Out_ JsValueRef *error); /// /// Determines whether the runtime of the current context is in an exception state. /// /// /// /// 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 JsErrorInExceptionState until the exception is /// cleared. /// /// /// 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. /// /// /// Requires an active script context. /// /// /// /// Whether the runtime of the current context is in the exception state. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsHasException( _Out_ bool *hasException); /// /// 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. /// /// /// /// If the runtime of the current context is not in an exception state, this API will return /// JsErrorInvalidArgument. 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 /// JsEnableRuntimeExecution). /// /// /// Requires an active script context. /// /// /// The exception for the runtime of the current context. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsGetAndClearException( _Out_ JsValueRef *exception); /// /// Sets the runtime of the current context to an exception state. /// /// /// /// If the runtime of the current context is already in an exception state, this API will /// return JsErrorInExceptionState. /// /// /// Requires an active script context. /// /// /// /// The JavaScript exception to set for the runtime of the current context. /// /// /// JsNoError if the engine was set into an exception state, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetException( _In_ JsValueRef exception); /// /// Suspends script execution and terminates any running scripts in a runtime. /// /// /// /// Calls to a suspended runtime will fail until JsEnableRuntimeExecution is called. /// /// /// 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. /// /// /// Suspending execution in a runtime that is already suspended is a no-op. /// /// /// The runtime to be suspended. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsDisableRuntimeExecution( _In_ JsRuntimeHandle runtime); /// /// Enables script execution in a runtime. /// /// /// Enabling script execution in a runtime that already has script execution enabled is a /// no-op. /// /// The runtime to be enabled. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsEnableRuntimeExecution( _In_ JsRuntimeHandle runtime); /// /// Returns a value that indicates whether script execution is disabled in the runtime. /// /// Specifies the runtime to check if execution is disabled. /// If execution is disabled, true, false otherwise. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsIsRuntimeExecutionDisabled( _In_ JsRuntimeHandle runtime, _Out_ bool *isDisabled); /// /// A promise continuation callback. /// /// /// The host can specify a promise continuation callback in JsSetPromiseContinuationCallback. 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. /// /// The task, represented as a JavaScript function. /// The data argument to be passed to the callback. typedef void (CALLBACK *JsPromiseContinuationCallback)(_In_ JsValueRef task, _In_opt_ void *callbackState); /// /// Sets a promise continuation callback function that is called by the context when a task /// needs to be queued for future execution /// /// /// /// Requires an active script context. /// /// /// The callback function being set. /// /// User provided state that will be passed back to the callback. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetPromiseContinuationCallback( _In_ JsPromiseContinuationCallback promiseContinuationCallback, _In_opt_ void *callbackState); /// /// Creates a JavaScript value that is a projection of the passed in IInspectable pointer. /// /// /// /// The projected value can be used by script to call a WinRT object. /// Hosts are responsible for enforcing COM threading rules. /// /// /// Requires an active script context. /// /// /// A IInspectable to be projected. /// A JavaScript value that is a projection of the IInspectable. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsInspectableToObject( _In_ IInspectable *inspectable, _Out_ JsValueRef *value); /// /// Unwraps a JavaScript object to an IInspectable pointer /// /// /// /// Hosts are responsible for enforcing COM threading rules. /// /// /// Requires an active script context. /// /// /// A JavaScript value that should be projected to IInspectable. /// A IInspectable value of the object. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsObjectToInspectable( _In_ JsValueRef value, _Out_ IInspectable **inspectable); /// /// The context passed into application callback, JsProjectionEnqueueCallback, from Jsrt and /// then passed back to Jsrt in the provided callback, JsProjectionCallback, by the application /// on the correct thread. /// /// /// Requires calling JsSetProjectionEnqueueCallback to receive callbacks. /// typedef void *JsProjectionCallbackContext; /// /// The Jsrt callback which should be called with the context passed to JsProjectionEnqueueCallback on /// the correct thread. /// /// /// Requires calling JsSetProjectionEnqueueCallback to receive callbacks. /// /// The context originally received by a call to JsProjectionEnqueueCallback. typedef void (CALLBACK *JsProjectionCallback)(_In_ JsProjectionCallbackContext jsContext); /// /// The application callback which is called by Jsrt when a projection API is completed on /// a different thread than the original. /// /// /// Requires calling JsSetProjectionEnqueueCallback to receive callbacks. /// /// The callback to be invoked on the original thread. /// The applications context. /// The Jsrt context that must be passed into jsCallback. typedef void (CALLBACK *JsProjectionEnqueueCallback)(_In_ JsProjectionCallback jsCallback, _In_ JsProjectionCallbackContext jsContext, _In_opt_ void *callbackState); /// /// Sets the callback to be used in order to invoke a projection completion back to the /// callers required thread. /// /// /// Requires an active script context. /// The call should be coming from a different COM apartment or from a different thread in the same MTA. /// /// /// The callback that will be invoked any time a projection completion occurs on a background thread. /// /// The application context provided to projectionEnqueueContext /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsSetProjectionEnqueueCallback( _In_ JsProjectionEnqueueCallback projectionEnqueueCallback, _In_opt_ void *projectionEnqueueContext); /// /// Project a WinRT namespace. /// /// /// Requires an active script context. /// /// The WinRT namespace to be projected. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsProjectWinRTNamespace( _In_z_ const wchar_t *namespaceName); #endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) #pragma endregion #pragma region Desktop Family #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #include /// /// Starts profiling in the current context. /// /// /// Requires an active script context. /// /// The profiling callback to use. /// The profiling events to callback with. /// A context to pass to the profiling callback. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsStartProfiling( _In_ IActiveScriptProfilerCallback *callback, _In_ PROFILER_EVENT_MASK eventMask, _In_ unsigned long context); /// /// Stops profiling in the current context. /// /// /// /// Will not return an error if profiling has not started. /// /// /// Requires an active script context. /// /// /// /// The reason for stopping profiling to pass to the profiler callback. /// /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsStopProfiling( _In_ HRESULT reason); /// /// Enumerates the heap of the current context. /// /// /// /// While the heap is being enumerated, the current context cannot be removed, and all calls to /// modify the state of the context will fail until the heap enumerator is released. /// /// /// Requires an active script context. /// /// /// The heap enumerator. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsEnumerateHeap( _Out_ IActiveScriptProfilerHeapEnum **enumerator); /// /// Returns a value that indicates whether the heap of the current context is being enumerated. /// /// /// Requires an active script context. /// /// Whether the heap is being enumerated. /// /// The code JsNoError if the operation succeeded, a failure code otherwise. /// STDAPI_(JsErrorCode) JsIsEnumeratingHeap( _Out_ bool *isEnumeratingHeap); #endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #pragma endregion #endif // NTDDI_VERSION #endif // _CHAKRART_H_ #pragma option pop /*P_O_Pop*/