diff --git a/vnext/ChakraCoreShim/ChakraCore.x64.def b/vnext/ChakraCoreShim/ChakraCore.x64.def deleted file mode 100644 index 6d85339f737..00000000000 --- a/vnext/ChakraCoreShim/ChakraCore.x64.def +++ /dev/null @@ -1,45 +0,0 @@ -EXPORTS - -JsAddRef=MyJsAddRef -JsCallFunction=MyJsCallFunction -JsConstructObject=MyJsConstructObject -JsConvertValueToObject=MyJsConvertValueToObject -JsConvertValueToString=MyJsConvertValueToString -JsCopyString=MyJsCopyString -JsCreateContext=MyJsCreateContext -JsCreateError=MyJsCreateError -JsCreateExternalArrayBuffer=MyJsCreateExternalArrayBuffer -JsCreateExternalObject=MyJsCreateExternalObject -JsCreateFunction=MyJsCreateFunction -JsCreateNamedFunction=MyJsCreateNamedFunction -JsCreateObject=MyJsCreateObject -JsCreateRuntime=MyJsCreateRuntime -JsDisposeRuntime=MyJsDisposeRuntime -JsDoubleToNumber=MyJsDoubleToNumber -JsGetAndClearException=MyJsGetAndClearException -JsGetContextData=MyJsGetContextData -JsGetCurrentContext=MyJsGetCurrentContext -JsGetGlobalObject=MyJsGetGlobalObject -JsGetIndexedProperty=MyJsGetIndexedProperty -JsGetNullValue=MyJsGetNullValue -JsGetOwnPropertyNames=MyJsGetOwnPropertyNames -JsGetProperty=MyJsGetProperty -JsGetPropertyIdFromName=MyJsGetPropertyIdFromName -JsGetStringLength=MyJsGetStringLength -JsGetUndefinedValue=MyJsGetUndefinedValue -JsGetValueType=MyJsGetValueType -JsHasException=MyJsHasException -JsIntToNumber=MyJsIntToNumber -JsNumberToDouble=MyJsNumberToDouble -JsNumberToInt=MyJsNumberToInt -JsPointerToString=MyJsPointerToString -JsRelease=MyJsRelease -JsRun=MyJsRun -JsRunScript=MyJsRunScript -JsRunSerialized=MyJsRunSerialized -JsSerializeScript=MyJsSerializeScript -JsSetContextData=MyJsSetContextData -JsSetCurrentContext=MyJsSetCurrentContext -JsSetProperty=MyJsSetProperty -JsSetRuntimeMemoryLimit=MyJsSetRuntimeMemoryLimit -JsStringToPointer=MyJsStringToPointer diff --git a/vnext/ChakraCoreShim/ChakraCore.x86.def b/vnext/ChakraCoreShim/ChakraCore.x86.def deleted file mode 100644 index 18239855230..00000000000 --- a/vnext/ChakraCoreShim/ChakraCore.x86.def +++ /dev/null @@ -1,45 +0,0 @@ -EXPORTS - -_JsAddRef@8=MyJsAddRef -_JsCallFunction@16=MyJsCallFunction -_JsConstructObject@16=MyJsConstructObject -_JsConvertValueToObject@8=MyJsConvertValueToObject -_JsConvertValueToString@8=MyJsConvertValueToString -_JsCopyString@16=MyJsCopyString -_JsCreateContext@8=MyJsCreateContext -_JsCreateError@8=MyJsCreateError -_JsCreateExternalArrayBuffer@20=MyJsCreateExternalArrayBuffer -_JsCreateExternalObject@12=MyJsCreateExternalObject -_JsCreateFunction@12=MyJsCreateFunction -_JsCreateNamedFunction@16=MyJsCreateNamedFunction -_JsCreateObject@4=MyJsCreateObject -_JsCreateRuntime@12=MyJsCreateRuntime -_JsDisposeRuntime@4=MyJsDisposeRuntime -_JsDoubleToNumber@12=MyJsDoubleToNumber -_JsGetAndClearException@4=MyJsGetAndClearException -_JsGetContextData@8=MyJsGetContextData -_JsGetCurrentContext@4=MyJsGetCurrentContext -_JsGetGlobalObject@4=MyJsGetGlobalObject -_JsGetIndexedProperty@12=MyJsGetIndexedProperty -_JsGetNullValue@4=MyJsGetNullValue -_JsGetOwnPropertyNames@8=MyJsGetOwnPropertyNames -_JsGetProperty@12=MyJsGetProperty -_JsGetPropertyIdFromName@8=MyJsGetPropertyIdFromName -_JsGetStringLength@8=MyJsGetStringLength -_JsGetUndefinedValue@4=MyJsGetUndefinedValue -_JsGetValueType@8=MyJsGetValueType -_JsHasException@4=MyJsHasException -_JsIntToNumber@8=MyJsIntToNumber -_JsNumberToDouble@8=MyJsNumberToDouble -_JsNumberToInt@8=MyJsNumberToInt -_JsPointerToString@12=MyJsPointerToString -_JsRelease@8=MyJsRelease -_JsRun@20=MyJsRun -_JsRunScript@16=MyJsRunScript -_JsRunSerialized@20=MyJsRunSerialized -_JsSerializeScript@12=MyJsSerializeScript -_JsSetContextData@8=MyJsSetContextData -_JsSetCurrentContext@4=MyJsSetCurrentContext -_JsSetProperty@16=MyJsSetProperty -_JsSetRuntimeMemoryLimit@8=MyJsSetRuntimeMemoryLimit -_JsStringToPointer@12=MyJsStringToPointer diff --git a/vnext/ChakraCoreShim/ChakraCoreShim.cpp b/vnext/ChakraCoreShim/ChakraCoreShim.cpp deleted file mode 100644 index 0d5e0e8fdc9..00000000000 --- a/vnext/ChakraCoreShim/ChakraCoreShim.cpp +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include // for uint16_t - -#include "Redirects.h" - -#include "ChakraHeaders/ChakraCore.h" - -// This file contains all the public API surface shim ChakraCore.dll exports. -// As such, all of the APIs are here are explicitly exported with proper name (e.g. with the actual -// ChakraCore export name, MyJsAddRef -> JsAddRef) in the relevant .def files in the same folder. -// -// As our react-native-win32.dll starts calling new ChakraCore exports that it didn't used to call, -// let's say JsFoo API, that export should also be added to this shim dll, by following these steps: -// 1. Add MyJsFoo export to this cpp file. -// 2. Add Redirects::JsFoo API in in Redirects.h -// 3. Export the MyJsFoo under the name JsFoo by adding JsFoo=MyJsFoo in x64 and x86 def files in this folder. -// -// -// ============================ DESIGN -// Here is the general strategy for the shim approach and some details for the design: -// -// 1) This shim dll can currently redirect to both ChakraRT and legacy Chakra(e.g.jscript9.dll) as a proof of concept. -// -// 2) Principle: This shim dll exports the exact same set APIs the react - native - win32.dll calls in -// real ChakraCore.dll, so that applications that used to load ChakraCore.dll can transparently continue to do so. -// -// That is why this file includes ChakraCore.h. The APIs this dll exports have the exact same signatures and -// types as ChakraCore APIs. -// -// 3) Given the API signatures are completely different between ChakraRT and legacy Chakra(jscript9.dll), -// this design adds a Redirect layer that does the proper redirection, which are all defined in Redirects.h. -// -// 4) Since the Redirect layer would shim calls to ChakraRT or jscript9.dll(based on USE_EDMODE_JSRT definition. -// More details in the Readme.md file), that means the Redirect layer cannot reference any types from ChakraCore -// or ChakraRT or jscript9.dll. After all, JsValueRef is actually defined in three different dlls in three -// different ways. There is a definition of JsValueRef in ChakraCore.h, ChakraRT.h and jsrt9.h, one -// for each engine. -// -// 5) Instead all types in the API signatures in Redirects layer should be "neutralized". That is, -// JsValueRef becomes void*, JsValueRef* becomes void**, JsValueType enum becomes int, similarly -// JsErrorCode becomes unsigned int. -// -// 6) Redirect layer receives the neutralized form of the call from the ChakraCoreShim entry points, -// then translates it either to ChakraRT or legacy Chakra. -// -// 7) Redirect layer receives a result from the actual JS engine. In the case of translating to ChakraRT, -// this would be the JsErrorCode defined in ChakraRT.h, and in the case of translating to legacy Chakra, -// this would be the JsErrorCode defined in jsrt9.h. Both of these types can be reduced to unsigned int. -// -// 8) Entry points in this cpp file, receives the unsigned int result from the Redirect layer, and then casts -// it to JsErrorCode type as defined in ChakraCommon.h header of ChakraCore and return it to caller -// (e.g.react - native - win32.dll) as if the call was actually made to ChakraCore. - -JsErrorCode MyJsAddRef(JsRef ref, unsigned int *count) -{ - return static_cast(Redirects::JsAddRef(ref, count)); -} - -JsErrorCode MyJsCallFunction(JsValueRef function, JsValueRef* arguments, unsigned short argumentCount, JsValueRef* result) -{ - return static_cast(Redirects::JsCallFunction(function, arguments, argumentCount, result)); -} - -JsErrorCode MyJsConstructObject(JsValueRef function, JsValueRef *arguments, unsigned short argumentCount, JsValueRef *result) -{ - return static_cast(Redirects::JsConstructObject(function, arguments, argumentCount, result)); -} - -JsErrorCode MyJsConvertValueToObject(JsValueRef value, JsValueRef *object) -{ - return static_cast(Redirects::JsConvertValueToObject(value, object)); -} - -JsErrorCode MyJsConvertValueToString(JsValueRef value, JsValueRef* stringValue) -{ - return static_cast(Redirects::JsConvertValueToString(value, stringValue)); -} - -JsErrorCode MyJsCopyString(JsValueRef value, char* buffer, size_t length, size_t* written) -{ - return static_cast(Redirects::JsCopyString(value, buffer, length, written)); -} - -JsErrorCode MyJsCreateContext(JsRuntimeHandle runtime, JsContextRef* newContext) -{ - return static_cast(Redirects::JsCreateContext(runtime, newContext)); -} - -JsErrorCode MyJsCreateError(JsValueRef message, JsValueRef* error) -{ - return static_cast(Redirects::JsCreateError(message, error)); -} - -JsErrorCode MyJsCreateExternalArrayBuffer(void *data, unsigned int byteLength, JsFinalizeCallback finalizeCallback, void* callbackState, JsValueRef *result) -{ - return static_cast(Redirects::JsCreateExternalArrayBuffer(data, byteLength, finalizeCallback, callbackState, result)); -} - -JsErrorCode MyJsCreateExternalObject(void *data, JsFinalizeCallback finalizeCallback, JsValueRef *object) -{ - return static_cast(Redirects::JsCreateExternalObject(data, finalizeCallback, object)); -} - -JsErrorCode MyJsCreateFunction(JsNativeFunction nativeFunction, void *callbackState, JsValueRef *function) -{ - return static_cast(Redirects::JsCreateFunction(nativeFunction, callbackState, function)); -} - -JsErrorCode MyJsCreateNamedFunction(JsValueRef name, JsNativeFunction nativeFunction, void *callbackState, JsValueRef *function) -{ - return static_cast(Redirects::JsCreateNamedFunction(name, nativeFunction, callbackState, function)); -} - -JsErrorCode MyJsCreateObject(JsValueRef *object) -{ - return static_cast(Redirects::JsCreateObject(object)); -} - -JsErrorCode MyJsCreateRuntime(JsRuntimeAttributes attributes, JsThreadServiceCallback threadService, JsRuntimeHandle *runtime) -{ - return static_cast(Redirects::JsCreateRuntime(attributes, threadService, runtime)); -} - -JsErrorCode MyJsDisposeRuntime(JsRuntimeHandle runtime) -{ - return static_cast(Redirects::JsDisposeRuntime(runtime)); -} - -JsErrorCode MyJsDoubleToNumber(double doubleValue, JsValueRef *value) -{ - return static_cast(Redirects::JsDoubleToNumber(doubleValue, value)); -} - -JsErrorCode MyJsGetAndClearException(JsValueRef *exception) -{ - return static_cast(Redirects::JsGetAndClearException(exception)); -} - -JsErrorCode MyJsGetContextData(JsContextRef context, void **data) -{ - return static_cast(Redirects::JsGetContextData(context, data)); -} - -JsErrorCode MyJsGetCurrentContext(JsContextRef *currentContext) -{ - return static_cast(Redirects::JsGetCurrentContext(currentContext)); -} - -JsErrorCode MyJsGetGlobalObject(JsValueRef* globalObject) -{ - return static_cast(Redirects::JsGetGlobalObject(globalObject)); -} - -JsErrorCode MyJsGetIndexedProperty(JsValueRef object, JsValueRef index, JsValueRef *result) -{ - return static_cast(Redirects::JsGetIndexedProperty(object, index, result)); -} - -JsErrorCode MyJsGetNullValue(JsValueRef *nullValue) -{ - return static_cast(Redirects::JsGetNullValue(nullValue)); -} - -JsErrorCode MyJsGetOwnPropertyNames(JsValueRef object, JsValueRef *propertyNames) -{ - return static_cast(Redirects::JsGetOwnPropertyNames(object, propertyNames)); -} - -JsErrorCode MyJsGetProperty(JsValueRef object, JsPropertyIdRef propertyId, JsValueRef *value) -{ - return static_cast(Redirects::JsGetProperty(object, propertyId, value)); -} - -JsErrorCode MyJsGetPropertyIdFromName(const wchar_t *name, JsPropertyIdRef *propertyId) -{ - return static_cast(Redirects::JsGetPropertyIdFromName(name, propertyId)); -} - -JsErrorCode MyJsGetStringLength(JsValueRef stringValue, int *length) -{ - return static_cast(Redirects::JsGetStringLength(stringValue, length)); -} - -JsErrorCode MyJsGetUndefinedValue(JsValueRef *value) -{ - return static_cast(Redirects::JsGetUndefinedValue(value)); -} - -JsErrorCode MyJsGetValueType(JsValueRef value, JsValueType *type) -{ - return static_cast(Redirects::JsGetValueType(value, reinterpret_cast(type))); -} - -JsErrorCode MyJsHasException(bool *hasException) -{ - return static_cast(Redirects::JsHasException(hasException)); -} - -JsErrorCode MyJsIntToNumber(int intValue, JsValueRef *value) -{ - return static_cast(Redirects::JsIntToNumber(intValue, value)); -} - -JsErrorCode MyJsNumberToDouble(JsValueRef value, double *doubleValue) -{ - return static_cast(Redirects::JsNumberToDouble(value, doubleValue)); -} - -JsErrorCode MyJsNumberToInt(JsValueRef value, int *intValue) -{ - return static_cast(Redirects::JsNumberToInt(value, intValue)); -} - -JsErrorCode MyJsPointerToString(const wchar_t *stringValue, size_t stringLength, JsValueRef *value) -{ - return static_cast(Redirects::JsPointerToString(stringValue, stringLength, value)); -} - -JsErrorCode MyJsRelease(JsRef ref, unsigned int *count) -{ - return static_cast(Redirects::JsRelease(ref, count)); -} - -JsErrorCode MyJsRun(JsValueRef script, JsSourceContext sourceContext, JsValueRef sourceUrl, JsParseScriptAttributes parseAttributes, JsValueRef *result) -{ - return static_cast(Redirects::JsRun(script, sourceContext, sourceUrl, parseAttributes, result)); -} - -JsErrorCode MyJsRunScript(const wchar_t *script, JsSourceContext sourceContext, const wchar_t *sourceUrl, JsValueRef *result) -{ - return static_cast(Redirects::JsRunScript(script, sourceContext, sourceUrl, result)); -} - -JsErrorCode MyJsRunSerialized( - _In_ JsValueRef buffer, - _In_ JsSerializedLoadScriptCallback scriptLoadCallback, - _In_ JsSourceContext sourceContext, - _In_ JsValueRef sourceUrl, - _Out_ JsValueRef* result) -{ - return static_cast(Redirects::JsRunSerialized(buffer, scriptLoadCallback, sourceContext, sourceUrl, result)); -} - -JsErrorCode MyJsSerializeScript( - _In_z_ const wchar_t *script, - _Out_writes_to_opt_(*bufferSize, *bufferSize) BYTE *buffer, - _Inout_ unsigned int *bufferSize) -{ - return static_cast(Redirects::JsSerializeScript(script, buffer, bufferSize)); -} - -JsErrorCode MyJsSetContextData(JsContextRef context, void *data) -{ - return static_cast(Redirects::JsSetContextData(context, data)); -} - -JsErrorCode MyJsSetCurrentContext(JsContextRef context) -{ - return static_cast(Redirects::JsSetCurrentContext(context)); -} - -JsErrorCode MyJsSetProperty(JsValueRef object, JsPropertyIdRef propertyId, JsValueRef value, bool useStrictRules) -{ - return static_cast(Redirects::JsSetProperty(object, propertyId, value, useStrictRules)); -} - -JsErrorCode MyJsSetRuntimeMemoryLimit(JsRuntimeHandle runtime, size_t memoryLimit) -{ - return static_cast(Redirects::JsSetRuntimeMemoryLimit(runtime, memoryLimit)); -} - -JsErrorCode MyJsStringToPointer(JsValueRef value, const wchar_t **stringValue, size_t *stringLength) -{ - return static_cast(Redirects::JsStringToPointer(value, stringValue, stringLength)); -} - diff --git a/vnext/ChakraCoreShim/ChakraCoreShim.vcxproj b/vnext/ChakraCoreShim/ChakraCoreShim.vcxproj deleted file mode 100644 index fcf97d8ffb2..00000000000 --- a/vnext/ChakraCoreShim/ChakraCoreShim.vcxproj +++ /dev/null @@ -1,126 +0,0 @@ - - - - - Debug - x86 - - - Release - x86 - - - Debug - x64 - - - Release - x64 - - - - Debug - Win32 - - - Release - Win32 - - - - {00830A8B-97E0-4320-B7B0-0078B405997B} - Win32Proj - ChakraCoreShim - - - DynamicLibrary - - - - - - - - - - - - - - - - ChakraCore - - - true - - - false - - - - - - _WINDOWS;_USRDLL;CHAKRACORESHIM_EXPORTS;USE_EDGEMODE_JSRT;NOJSC;%(PreprocessorDefinitions) - true - - - Windows - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;chakrart.lib;%(AdditionalDependencies) - - - - - - - _DEBUG;%(PreprocessorDefinitions) - - - - - MaxSpeed - NDEBUG;%(PreprocessorDefinitions) - - - - - $(TargetName).$(Platform).def - - - - - WIN32;%(PreprocessorDefinitions) - - - $(TargetName).x86.def - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/vnext/ChakraCoreShim/ChakraCoreShim.vcxproj.filters b/vnext/ChakraCoreShim/ChakraCoreShim.vcxproj.filters deleted file mode 100644 index 3610f23634a..00000000000 --- a/vnext/ChakraCoreShim/ChakraCoreShim.vcxproj.filters +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - ChakraHeaders - - - ChakraHeaders - - - ChakraHeaders - - - ChakraHeaders - - - - - {35e2f250-82b5-4be1-a47d-07538ea0e8a1} - - - - - - - \ No newline at end of file diff --git a/vnext/ChakraCoreShim/ChakraHeaders/ChakraCommon.h b/vnext/ChakraCoreShim/ChakraHeaders/ChakraCommon.h deleted file mode 100644 index e67af6e50db..00000000000 --- a/vnext/ChakraCoreShim/ChakraHeaders/ChakraCommon.h +++ /dev/null @@ -1,2418 +0,0 @@ -//------------------------------------------------------------------------------------------------------- -// 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. - -#ifdef _MSC_VER -#pragma once -#endif // _MSC_VER - -#ifndef _CHAKRACOMMON_H_ -#define _CHAKRACOMMON_H_ - -// Platform specific code -#if defined(_WIN32) && defined(_MSC_VER) -#include - -// Header macros -#define CHAKRA_CALLBACK CALLBACK -#define CHAKRA_API STDAPI_(JsErrorCode) - -typedef DWORD_PTR ChakraCookie; -typedef BYTE* ChakraBytePtr; -#else // Non-Windows VC++ - -// SAL compat -#define _Return_type_success_(x) -#define _In_ -#define _In_z_ -#define _In_opt_ -#define _Inout_ -#define _Out_ -#define _Out_opt_ -#define _In_reads_(x) -#define _Pre_maybenull_ -#define _Pre_writable_byte_size_(byteLength) -#define _Outptr_result_buffer_(byteLength) -#define _Outptr_result_bytebuffer_(byteLength) -#define _Outptr_result_maybenull_ -#define _Outptr_result_z_ -#define _Ret_maybenull_ -#define _Out_writes_(size) -#define _Out_writes_to_opt_(byteLength, byteLength2) - -// Header macros -#ifdef __i386___ -#define CHAKRA_CALLBACK __attribute__((cdecl)) -#else // non-32 bit x86 doesn't have cdecl support -#define CHAKRA_CALLBACK -#endif // __i386__ - -#ifndef _WIN32 -#define SET_API_VISIBILITY __attribute__((visibility("default"))) -#else -#define SET_API_VISIBILITY -#endif - -#ifdef __cplusplus -#define CHAKRA_API extern "C" SET_API_VISIBILITY JsErrorCode -#else -#define CHAKRA_API extern SET_API_VISIBILITY JsErrorCode -#include -#endif - -#include // for size_t -#include // for uintptr_t -typedef uintptr_t ChakraCookie; -typedef unsigned char* ChakraBytePtr; - -// xplat-todo: try reduce usage of following types -#if !defined(__MSTYPES_DEFINED) -typedef uint32_t UINT32; -typedef int64_t INT64; -typedef void* HANDLE; -typedef unsigned char BYTE; -typedef BYTE byte; -typedef UINT32 DWORD; -typedef unsigned short WCHAR; -#endif - -#endif // defined(_WIN32) && defined(_MSC_VER) - -#if (defined(_MSC_VER) && _MSC_VER <= 1900) || (!defined(_MSC_VER) && __cplusplus <= 199711L) // !C++11 -typedef unsigned short uint16_t; -#else -#include -#endif - - /// - /// An error code returned from a Chakra hosting API. - /// - typedef _Return_type_success_(return == 0) enum _JsErrorCode - { - /// - /// 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 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, - /// - /// Module evaluation is called in wrong context. - /// - JsErrorInvalidContext, - /// - /// Module evaluation is called in wrong context. - /// - JsInvalidModuleHostInfoKind, - /// - /// Module was parsed already when JsParseModuleSource is called. - /// - JsErrorModuleParsed, - /// - /// Argument passed to JsCreateWeakReference is a primitive that is not managed by the GC. - /// No weak reference is required, the value will never be collected. - /// - JsNoWeakRefRequired, - /// - /// The Promise object is still in the pending state. - /// - JsErrorPromisePending, - /// - /// Module was not yet evaluated when JsGetModuleNamespace was called. - /// - JsErrorModuleNotEvaluated, - /// - /// Category of errors that relates to errors occurring within the engine itself. - /// - JsErrorCategoryEngine = 0x20000, - /// - /// The Chakra engine has run out of memory. - /// - JsErrorOutOfMemory, - /// - /// The Chakra engine failed to set the Floating Point Unit state. - /// - JsErrorBadFPUState, - - /// - /// 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 hosting API was called with object created on different javascript runtime. - /// - JsErrorWrongRuntime, - - /// - /// Category of errors that are related to failures during diagnostic operations. - /// - JsErrorCategoryDiagError = 0x50000, - /// - /// The object for which the debugging API was called was not found - /// - JsErrorDiagAlreadyInDebugMode, - /// - /// The debugging API can only be called when VM is in debug mode - /// - JsErrorDiagNotInDebugMode, - /// - /// The debugging API can only be called when VM is at a break - /// - JsErrorDiagNotAtBreak, - /// - /// Debugging API was called with an invalid handle. - /// - JsErrorDiagInvalidHandle, - /// - /// The object for which the debugging API was called was not found - /// - JsErrorDiagObjectNotFound, - /// - /// VM was unable to perform the request action - /// - JsErrorDiagUnableToPerformAction, - } JsErrorCode; - - /// - /// 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. - /// -#ifdef __cplusplus - const JsRuntimeHandle JS_INVALID_RUNTIME_HANDLE = 0; -#else - #define JS_INVALID_RUNTIME_HANDLE (JsRuntimeHandle)0 -#endif - - /// - /// 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. - /// -#ifdef __cplusplus - const JsRef JS_INVALID_REFERENCE = 0; -#else - #define JS_INVALID_REFERENCE (JsRef)0 -#endif - - /// - /// 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 ChakraCookie JsSourceContext; - - /// - /// An empty source context. - /// -#ifdef __cplusplus - const JsSourceContext JS_SOURCE_CONTEXT_NONE = (JsSourceContext)-1; -#else - #define JS_SOURCE_CONTEXT_NONE (JsSourceContext)-1 -#endif - - /// - /// 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, - /// - /// Runtime will enable all experimental features. - /// - JsRuntimeAttributeEnableExperimentalFeatures = 0x00000020, - /// - /// Calling JsSetException will also dispatch the exception to the script debugger - /// (if any) giving the debugger a chance to break on the exception. - /// - JsRuntimeAttributeDispatchSetExceptionsToDebugger = 0x00000040, - /// - /// Disable Failfast fatal error on OOM - /// - JsRuntimeAttributeDisableFatalOnOOM = 0x00000080, - /// - /// Runtime will not allocate executable code pages - /// This also implies that Native Code generation will be turned off - /// Note that this will break JavaScript stack decoding in tools - // like WPA since they rely on allocation of unique thunks to - // interpret each function and allocation of those thunks will be - // disabled as well - /// - JsRuntimeAttributeDisableExecutablePageAllocation = 0x00000100, - - } JsRuntimeAttributes; - - /// - /// 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 - } JsTypedArrayType; - - /// - /// 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 - } JsMemoryEventType; - - /// - /// Attribute mask for JsParseScriptWithAttributes - /// - typedef enum _JsParseScriptAttributes { - /// - /// Default attribute - /// - JsParseScriptAttributeNone = 0x0, - /// - /// Specified script is internal and non-user code. Hidden from debugger - /// - JsParseScriptAttributeLibraryCode = 0x1, - /// - /// ChakraCore assumes ExternalArrayBuffer is Utf8 by default. - /// This one needs to be set for Utf16 - /// - JsParseScriptAttributeArrayBufferIsUtf16Encoded = 0x2, - } JsParseScriptAttributes; - - /// - /// 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 - } JsPropertyIdType; - - /// - /// 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, - } JsValueType; - - /// - /// 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 (CHAKRA_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 (CHAKRA_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 (CHAKRA_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 (CHAKRA_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 (CHAKRA_CALLBACK *JsThreadServiceCallback)(_In_ JsBackgroundWorkItemCallback callback, _In_opt_ void *callbackState); - - /// - /// 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. - /// - /// The context passed to Js[Parse|Run]SerializedScriptWithCallback - typedef void (CHAKRA_CALLBACK * JsSerializedScriptUnloadCallback)(_In_ JsSourceContext sourceContext); - - /// - /// A finalizer callback. - /// - /// - /// The external data that was passed in when creating the object being finalized. - /// - typedef void (CHAKRA_CALLBACK *JsFinalizeCallback)(_In_opt_ void *data); - - /// - /// 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(CHAKRA_CALLBACK * JsNativeFunction)(_In_ JsValueRef callee, _In_ bool isConstructCall, _In_ JsValueRef *arguments, _In_ unsigned short argumentCount, _In_opt_ void *callbackState); - - /// - /// 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 (CHAKRA_CALLBACK *JsPromiseContinuationCallback)(_In_ JsValueRef task, _In_opt_ void *callbackState); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsCreateContext( - _In_ JsRuntimeHandle runtime, - _Out_ JsContextRef *newContext); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsSetCurrentContext( - _In_ JsContextRef context); - - /// - /// Gets the script context that the object belongs to. - /// - /// The object to get the context from. - /// The context the object belongs to. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsGetContextOfObject( - _In_ JsValueRef object, - _Out_ JsContextRef *context); - - /// - /// Gets the internal data set on JsrtContext. - /// - /// The context to get the data from. - /// The pointer to the data where data will be returned. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsGetContextData( - _In_ JsContextRef context, - _Out_ void **data); - - /// - /// Sets the internal data of JsrtContext. - /// - /// The context to set the data to. - /// The pointer to the data to be set. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsSetContextData( - _In_ JsContextRef context, - _In_ void *data); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsIdle( - _Out_opt_ unsigned int *nextIdleTick); - - /// - /// 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. - /// - CHAKRA_API - JsGetSymbolFromPropertyId( - _In_ JsPropertyIdRef propertyId, - _Out_ JsValueRef *symbol); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsBoolToBoolean( - _In_ bool value, - _Out_ JsValueRef *booleanValue); - - /// - /// Retrieves the bool value of a Boolean value. - /// - /// The value to be converted. - /// The converted value. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsConvertValueToBoolean( - _In_ JsValueRef value, - _Out_ JsValueRef *booleanValue); - - - /// - /// Gets the JavaScript type of a JsValueRef. - /// - /// The value whose type is to be returned. - /// The type of the value. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - /// The number value to convert to a double value. - /// The double value. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - 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. - /// - /// The number value to convert to an int value. - /// The int value. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsConvertValueToNumber( - _In_ JsValueRef value, - _Out_ JsValueRef *numberValue); - - /// - /// Gets the length of a string value. - /// - /// The string value to get the length of. - /// The length of the string. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsGetStringLength( - _In_ JsValueRef stringValue, - _Out_ int *length); - - /// - /// 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. - /// - CHAKRA_API - JsConvertValueToString( - _In_ JsValueRef value, - _Out_ JsValueRef *stringValue); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsCreateObject( - _Out_ JsValueRef *object); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsSetPrototype( - _In_ JsValueRef object, - _In_ JsValueRef prototypeObject); - - /// - /// Performs JavaScript "instanceof" operator test. - /// - /// - /// Requires an active script context. - /// - /// The object to test. - /// The constructor function to test against. - /// Whether "object instanceof constructor" is true. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsInstanceOf( - _In_ JsValueRef object, - _In_ JsValueRef constructor, - _Out_ bool *result); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// The property set should follow strict mode rules. - /// Whether the property was deleted. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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 a value at the specified index. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsStrictEquals( - _In_ JsValueRef object1, - _In_ JsValueRef object2, - _Out_ bool *result); - - /// - /// Determines whether an object is an external object. - /// - /// The object. - /// Whether the object is an external object. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsHasExternalData( - _In_ JsValueRef object, - _Out_ bool *value); - - /// - /// Retrieves the data from an external object. - /// - /// 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. - /// - CHAKRA_API - JsGetExternalData( - _In_ JsValueRef object, - _Out_ void **externalData); - - /// - /// Sets the external data on an external object. - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsCreateArrayBuffer( - _In_ unsigned int byteLength, - _Out_ JsValueRef *result); - - /// - /// Creates a Javascript ArrayBuffer object to access external memory. - /// - /// Requires an active script context. - /// A pointer to the external memory. - /// The number of bytes in the external memory. - /// A callback for when the object is finalized. May be null. - /// User provided state that will be passed back to finalizeCallback. - /// The new ArrayBuffer object. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsCreateExternalArrayBuffer( - _Pre_maybenull_ _Pre_writable_byte_size_(byteLength) void *data, - _In_ unsigned int byteLength, - _In_opt_ JsFinalizeCallback finalizeCallback, - _In_opt_ void *callbackState, - _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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsCreateDataView( - _In_ JsValueRef arrayBuffer, - _In_ unsigned int byteOffset, - _In_ unsigned int byteLength, - _Out_ JsValueRef *result); - - /// - /// Obtains frequently used properties of a typed array. - /// - /// The typed array instance. - /// The type of the array. - /// The ArrayBuffer backstore of the array. - /// The offset in bytes from the start of arrayBuffer referenced by the array. - /// The number of bytes in the array. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsGetTypedArrayInfo( - _In_ JsValueRef typedArray, - _Out_opt_ JsTypedArrayType *arrayType, - _Out_opt_ JsValueRef *arrayBuffer, - _Out_opt_ unsigned int *byteOffset, - _Out_opt_ unsigned int *byteLength); - - /// - /// Obtains the underlying memory storage used by an ArrayBuffer. - /// - /// 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. - /// - CHAKRA_API - JsGetArrayBufferStorage( - _In_ JsValueRef arrayBuffer, - _Outptr_result_bytebuffer_(*bufferLength) ChakraBytePtr *buffer, - _Out_ unsigned int *bufferLength); - - /// - /// Obtains the underlying memory storage used by a typed array. - /// - /// 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. - /// - CHAKRA_API - JsGetTypedArrayStorage( - _In_ JsValueRef typedArray, - _Outptr_result_bytebuffer_(*bufferLength) ChakraBytePtr *buffer, - _Out_ unsigned int *bufferLength, - _Out_opt_ JsTypedArrayType *arrayType, - _Out_opt_ int *elementSize); - - /// - /// Obtains the underlying memory storage used by a DataView. - /// - /// 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. - /// - CHAKRA_API - JsGetDataViewStorage( - _In_ JsValueRef dataView, - _Outptr_result_bytebuffer_(*bufferLength) ChakraBytePtr *buffer, - _Out_ unsigned int *bufferLength); - - - /// - /// Invokes a function. - /// - /// - /// Requires thisArg as first argument of arguments. - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsConstructObject( - _In_ JsValueRef function, - _In_reads_(argumentCount) JsValueRef *arguments, - _In_ unsigned short argumentCount, - _Out_ JsValueRef *result); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsIsRuntimeExecutionDisabled( - _In_ JsRuntimeHandle runtime, - _Out_ bool *isDisabled); - - /// - /// 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. - /// - CHAKRA_API - JsSetPromiseContinuationCallback( - _In_opt_ JsPromiseContinuationCallback promiseContinuationCallback, - _In_opt_ void *callbackState); - -#ifdef _WIN32 -#include "ChakraCommonWindows.h" -#endif // _WIN32 -#endif // _CHAKRACOMMON_H_ diff --git a/vnext/ChakraCoreShim/ChakraHeaders/ChakraCommonWindows.h b/vnext/ChakraCoreShim/ChakraHeaders/ChakraCommonWindows.h deleted file mode 100644 index 3c634a5309e..00000000000 --- a/vnext/ChakraCoreShim/ChakraHeaders/ChakraCommonWindows.h +++ /dev/null @@ -1,367 +0,0 @@ -//------------------------------------------------------------------------------------------------------- -// Copyright (C) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. -//------------------------------------------------------------------------------------------------------- - -#ifdef _MSC_VER -#pragma once -#endif // _MSC_VER - -#ifndef _CHAKRACOMMONWINDOWS_H_ -#define _CHAKRACOMMONWINDOWS_H_ - - /// - /// Called by the runtime to load the source code of the serialized script. - /// The caller must keep the script buffer valid until the JsSerializedScriptUnloadCallback. - /// This callback is only supported by the Win32 version of the API - /// - /// The context passed to Js[Parse|Run]SerializedScriptWithCallback - /// The script returned. - /// - /// true if the operation succeeded, false otherwise. - /// - typedef bool (CHAKRA_CALLBACK * JsSerializedScriptLoadSourceCallback)(_In_ JsSourceContext sourceContext, _Outptr_result_z_ const WCHAR** scriptBuffer); - - /// - /// 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. - /// - CHAKRA_API - JsParseScript( - _In_z_ const wchar_t *script, - _In_ JsSourceContext sourceContext, - _In_z_ const wchar_t *sourceUrl, - _Out_ JsValueRef *result); - - /// - /// 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. - /// Attribute mask for parsing the script - /// A function representing the script code. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsParseScriptWithAttributes( - _In_z_ const wchar_t *script, - _In_ JsSourceContext sourceContext, - _In_z_ const wchar_t *sourceUrl, - _In_ JsParseScriptAttributes parseAttributes, - _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. - /// - CHAKRA_API - JsRunScript( - _In_z_ const wchar_t *script, - _In_ JsSourceContext sourceContext, - _In_z_ const wchar_t *sourceUrl, - _Out_ JsValueRef *result); - - /// - /// Executes a module. - /// - /// - /// Requires an active script context. - /// - /// The module script to parse and execute. - /// - /// A cookie identifying the script that can be used by debuggable script contexts. - /// - /// The location the module script came from. - /// The result of executing the module script, if any. This parameter can be null. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsExperimentalApiRunModule( - _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. - /// - CHAKRA_API - JsSerializeScript( - _In_z_ const wchar_t *script, - _Out_writes_to_opt_(*bufferSize, *bufferSize) BYTE *buffer, - _Inout_ unsigned int *bufferSize); - - /// - /// 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. - /// - /// - /// - /// 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. It will then call scriptUnloadCallback to inform the - /// caller it is safe to release. - /// - /// - /// Callback called when the source code of the script needs to be loaded. - /// Callback called when the serialized script and source code are no longer needed. - /// The serialized script. - /// - /// A cookie identifying the script that can be used by debuggable script contexts. - /// This context will passed into scriptLoadCallback and scriptUnloadCallback. - /// - /// The location the script came from. - /// A function representing the script code. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsParseSerializedScriptWithCallback( - _In_ JsSerializedScriptLoadSourceCallback scriptLoadCallback, - _In_ JsSerializedScriptUnloadCallback scriptUnloadCallback, - _In_ BYTE *buffer, - _In_ JsSourceContext sourceContext, - _In_z_ const wchar_t *sourceUrl, - _Out_ JsValueRef * result); - - /// - /// Runs a serialized script. - /// Provides the ability to lazy load the script source only if/when it is needed. - /// - /// - /// - /// 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. It will then call scriptUnloadCallback to inform the - /// caller it is safe to release. - /// - /// - /// Callback called when the source code of the script needs to be loaded. - /// Callback called when the serialized script and source code are no longer needed. - /// The serialized script. - /// - /// A cookie identifying the script that can be used by debuggable script contexts. - /// This context will passed into scriptLoadCallback and scriptUnloadCallback. - /// - /// 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. - /// - CHAKRA_API - JsRunSerializedScriptWithCallback( - _In_ JsSerializedScriptLoadSourceCallback scriptLoadCallback, - _In_ JsSerializedScriptUnloadCallback scriptUnloadCallback, - _In_ BYTE *buffer, - _In_ JsSourceContext sourceContext, - _In_z_ const wchar_t *sourceUrl, - _Out_opt_ JsValueRef * result); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsGetPropertyNameFromId( - _In_ JsPropertyIdRef propertyId, - _Outptr_result_z_ const wchar_t **name); - - /// - /// 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. - /// - CHAKRA_API - 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. - /// - CHAKRA_API - JsStringToPointer( - _In_ JsValueRef value, - _Outptr_result_buffer_(*stringLength) const wchar_t **stringValue, - _Out_ size_t *stringLength); - -#endif // _CHAKRACOMMONWINDOWS_H_ diff --git a/vnext/ChakraCoreShim/ChakraHeaders/ChakraCore.h b/vnext/ChakraCoreShim/ChakraHeaders/ChakraCore.h deleted file mode 100644 index fa37e3215cd..00000000000 --- a/vnext/ChakraCoreShim/ChakraHeaders/ChakraCore.h +++ /dev/null @@ -1,1275 +0,0 @@ -//------------------------------------------------------------------------------------------------------- -// 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. - -#ifdef _MSC_VER -#pragma once -#endif // _MSC_VER - -#ifndef _CHAKRACORE_H_ -#define _CHAKRACORE_H_ - -#if !defined(NTBUILD) && !defined(_CHAKRACOREBUILD) -#define _CHAKRACOREBUILD -#endif - -#include "ChakraCommon.h" -#include "ChakraDebug.h" - -// Begin ChakraCore only APIs -#ifdef _CHAKRACOREBUILD - -/// -/// A reference to an ES module. -/// -/// -/// A module record represents an ES module. -/// -typedef void* JsModuleRecord; - -/// -/// A reference to an object owned by the SharedArrayBuffer. -/// -/// -/// This represents SharedContents which is heap allocated object, it can be passed through -/// different runtimes to share the underlying buffer. -/// -typedef void *JsSharedArrayBufferContentHandle; - -/// -/// Flags for parsing a module. -/// -typedef enum JsParseModuleSourceFlags -{ - /// - /// Module source is UTF16. - /// - JsParseModuleSourceFlags_DataIsUTF16LE = 0x00000000, - /// - /// Module source is UTF8. - /// - JsParseModuleSourceFlags_DataIsUTF8 = 0x00000001 -} JsParseModuleSourceFlags; - -/// -/// The types of host info that can be set on a module record with JsSetModuleHostInfo. -/// -/// -/// For more information see JsSetModuleHostInfo. -/// -typedef enum JsModuleHostInfoKind -{ - /// - /// An exception object - e.g. if the module file cannot be found. - /// - JsModuleHostInfo_Exception = 0x01, - /// - /// Host defined info. - /// - JsModuleHostInfo_HostDefined = 0x02, - /// - /// Callback for receiving notification when module is ready. - /// - JsModuleHostInfo_NotifyModuleReadyCallback = 0x3, - /// - /// Callback for receiving notification to fetch a dependent module. - /// - JsModuleHostInfo_FetchImportedModuleCallback = 0x4, - /// - /// Callback for receiving notification for calls to ```import()``` - /// - JsModuleHostInfo_FetchImportedModuleFromScriptCallback = 0x5, - /// - /// URL for use in error stack traces and debugging. - /// - JsModuleHostInfo_Url = 0x6 -} JsModuleHostInfoKind; - -/// -/// The possible states for a Promise object. -/// -typedef enum _JsPromiseState -{ - JsPromiseStatePending = 0x0, - JsPromiseStateFulfilled = 0x1, - JsPromiseStateRejected = 0x2 -} JsPromiseState; - -/// -/// User implemented callback to fetch additional imported modules in ES modules. -/// -/// -/// The callback is invoked on the current runtime execution thread, therefore execution is blocked until -/// the callback completes. 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 needs to retrieve the module back. -/// -/// Callback should: -/// 1. Check if the requested module has been requested before - if yes return the existing -/// module record -/// 2. If no create and initialize a new module record with JsInitializeModuleRecord to -/// return and schedule a call to JsParseModuleSource for the new record. -/// -/// The referencing module that is requesting the dependent module. -/// The specifier coming from the module source code. -/// 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. -/// -/// Returns a JsNoError if the operation succeeded an error code otherwise. -/// -typedef JsErrorCode(CHAKRA_CALLBACK * FetchImportedModuleCallBack)(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord); - -/// -/// User implemented callback to fetch imported modules dynamically in scripts. -/// -/// -/// The callback is invoked on the current runtime execution thread, therefore execution is blocked untill -/// the callback completes. Notify the host to fetch the dependent module. This is used for the dynamic -/// import() syntax. -/// -/// Callback should: -/// 1. Check if the requested module has been requested before - if yes return the existing module record -/// 2. If no create and initialize a new module record with JsInitializeModuleRecord to return and -/// schedule a call to JsParseModuleSource for the new record. -/// -/// The referencing script context that calls import() -/// The specifier provided to the import() call. -/// 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. -/// -/// Returns JsNoError if the operation succeeded or an error code otherwise. -/// -typedef JsErrorCode(CHAKRA_CALLBACK * FetchImportedModuleFromScriptCallBack)(_In_ JsSourceContext dwReferencingSourceContext, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord); - -/// -/// User implemented callback to get notification when the module is ready. -/// -/// -/// The callback is invoked on the current runtime execution thread, therefore execution is blocked until the -/// callback completes. This callback should schedule a call to JsEvaluateModule to run the module that has been loaded. -/// -/// The referencing module that has finished running ModuleDeclarationInstantiation step. -/// If nullptr, the module is successfully initialized and host should queue the execution job -/// otherwise it's the exception object. -/// -/// Returns a JsErrorCode - note, the return value is ignored. -/// -typedef JsErrorCode(CHAKRA_CALLBACK * NotifyModuleReadyCallback)(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar); - -/// -/// A structure containing information about a native function callback. -/// -typedef struct JsNativeFunctionInfo -{ - JsValueRef thisArg; - JsValueRef newTargetArg; - bool isConstructCall; -}JsNativeFunctionInfo; - -/// -/// A function callback. -/// -/// -/// A function object that represents the function being invoked. -/// -/// The arguments to the call. -/// The number of arguments. -/// Additional information about this function call. -/// -/// The state passed to JsCreateFunction. -/// -/// The result of the call, if any. -typedef _Ret_maybenull_ JsValueRef(CHAKRA_CALLBACK * JsEnhancedNativeFunction)(_In_ JsValueRef callee, _In_ JsValueRef *arguments, _In_ unsigned short argumentCount, _In_ JsNativeFunctionInfo *info, _In_opt_ void *callbackState); - -/// -/// A Promise Rejection Tracker callback. -/// -/// -/// The host can specify a promise rejection tracker callback in JsSetHostPromiseRejectionTracker. -/// If a promise is rejected with no reactions or a reaction is added to a promise that was rejected -/// before it had reactions by default nothing is done. -/// A Promise Rejection Tracker callback may be set - which will then be called when this occurs. -/// Note - per draft ECMASpec 2018 25.4.1.9 this function should not set or return an exception -/// Note also the promise and reason parameters may be garbage collected after this function is called -/// if you wish to make further use of them you will need to use JsAddRef to preserve them -/// However if you use JsAddRef you must also call JsRelease and not hold unto them after -/// a handled notification (both per spec and to avoid memory leaks) -/// -/// The promise object, represented as a JsValueRef. -/// The value/cause of the rejection, represented as a JsValueRef. -/// Boolean - false for promiseRejected: i.e. if the promise has just been rejected with no handler, -/// true for promiseHandled: i.e. if it was rejected before without a handler and is now being handled. -/// The state passed to JsSetHostPromiseRejectionTracker. -typedef void (CHAKRA_CALLBACK *JsHostPromiseRejectionTrackerCallback)(_In_ JsValueRef promise, _In_ JsValueRef reason, _In_ bool handled, _In_opt_ void *callbackState); - -/// -/// Creates a new enhanced JavaScript function. -/// -/// -/// Requires an active script context. -/// -/// The method to call when the function is invoked. -/// If this is not JS_INVALID_REFERENCE, it is converted to a string and used as the name of the function. -/// -/// 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. -/// -CHAKRA_API -JsCreateEnhancedFunction( - _In_ JsEnhancedNativeFunction nativeFunction, - _In_opt_ JsValueRef metadata, - _In_opt_ void *callbackState, - _Out_ JsValueRef *function); - -/// -/// Initialize a ModuleRecord from host -/// -/// -/// Bootstrap the module loading process by creating a new module record. -/// -/// The parent module of the new module - nullptr for a root module. -/// The normalized specifier for the module. -/// The new module record. The host should not try to call this API twice -/// with the same normalizedSpecifier. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsInitializeModuleRecord( - _In_opt_ JsModuleRecord referencingModule, - _In_ JsValueRef normalizedSpecifier, - _Outptr_result_maybenull_ JsModuleRecord* moduleRecord); - -/// -/// Parse the source for an ES module -/// -/// -/// This is basically ParseModule operation in ES6 spec. It is slightly different in that: -/// a) The ModuleRecord was initialized earlier, and passed in as an argument. -/// b) This includes a check to see if the module being Parsed is the last module in the -/// dependency tree. If it is it automatically triggers Module Instantiation. -/// -/// The ModuleRecord being parsed. -/// A cookie identifying the script that can be used by debuggable script contexts. -/// The source script to be parsed, but not executed in this code. -/// The length of sourceText in bytes. As the input might contain a embedded null. -/// The type of the source code passed in. It could be utf16 or utf8 at this time. -/// The error object if there is parse error. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsParseModuleSource( - _In_ JsModuleRecord requestModule, - _In_ JsSourceContext sourceContext, - _In_ BYTE* script, - _In_ unsigned int scriptLength, - _In_ JsParseModuleSourceFlags sourceFlag, - _Outptr_result_maybenull_ JsValueRef* exceptionValueRef); - -/// -/// Execute module code. -/// -/// -/// This method implements 15.2.1.1.6.5, "ModuleEvaluation" concrete method. -/// This method should be called after the engine notifies the host that the module is ready. -/// This method only needs to be called on root modules - it will execute all of the dependent modules. -/// -/// One moduleRecord will be executed only once. Additional execution call on the same moduleRecord will fail. -/// -/// The ModuleRecord being executed. -/// The return value of the module. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsModuleEvaluation( - _In_ JsModuleRecord requestModule, - _Outptr_result_maybenull_ JsValueRef* result); - -/// -/// Set host info for the specified module. -/// -/// -/// This is used for four things: -/// 1. Setting up the callbacks for module loading - note these are actually -/// set on the current Context not the module so only have to be set for -/// the first root module in any given context. -/// 2. Setting host defined info on a module record - can be anything that -/// you wish to associate with your modules. -/// 3. Setting a URL for a module to be used for stack traces/debugging - -/// note this must be set before calling JsParseModuleSource on the module -/// or it will be ignored. -/// 4. Setting an exception on the module object - only relevant prior to it being Parsed. -/// -/// The request module. -/// The type of host info to be set. -/// The host info to be set. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsSetModuleHostInfo( - _In_ JsModuleRecord requestModule, - _In_ JsModuleHostInfoKind moduleHostInfo, - _In_ void* hostInfo); - -/// -/// Retrieve the host info for the specified module. -/// -/// -/// This can used to retrieve info previously set with JsSetModuleHostInfo. -/// -/// The request module. -/// The type of host info to be retrieved. -/// The retrieved host info for the module. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsGetModuleHostInfo( - _In_ JsModuleRecord requestModule, - _In_ JsModuleHostInfoKind moduleHostInfo, - _Outptr_result_maybenull_ void** hostInfo); - -/// -/// Returns metadata relating to the exception that caused the runtime of the current context -/// to be in the exception state and resets the exception state for that runtime. The metadata -/// includes a reference to the exception itself. -/// -/// -/// -/// 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). -/// -/// -/// The metadata value is a javascript object with the following properties: exception, the -/// thrown exception object; line, the 0 indexed line number where the exception was thrown; -/// column, the 0 indexed column number where the exception was thrown; length, the -/// source-length of the cause of the exception; source, a string containing the line of -/// source code where the exception was thrown; and url, a string containing the name of -/// the script file containing the code that threw the exception. -/// -/// -/// Requires an active script context. -/// -/// -/// The exception metadata for the runtime of the current context. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsGetAndClearExceptionWithMetadata( - _Out_ JsValueRef *metadata); - -/// -/// Called by the runtime to load the source code of the serialized script. -/// -/// The context passed to Js[Parse|Run]SerializedScriptCallback -/// The script returned. -/// -/// true if the operation succeeded, false otherwise. -/// -typedef bool (CHAKRA_CALLBACK * JsSerializedLoadScriptCallback) - (JsSourceContext sourceContext, _Out_ JsValueRef *value, - _Out_ JsParseScriptAttributes *parseAttributes); - -/// -/// Create JavascriptString variable from ASCII or Utf8 string -/// -/// -/// -/// Requires an active script context. -/// -/// -/// Input string can be either ASCII or Utf8 -/// -/// -/// Pointer to string memory. -/// Number of bytes within the string -/// JsValueRef representing the JavascriptString -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsCreateString( - _In_ const char *content, - _In_ size_t length, - _Out_ JsValueRef *value); - -/// -/// Create JavascriptString variable from Utf16 string -/// -/// -/// -/// Requires an active script context. -/// -/// -/// Expects Utf16 string -/// -/// -/// Pointer to string memory. -/// Number of characters within the string -/// JsValueRef representing the JavascriptString -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsCreateStringUtf16( - _In_ const uint16_t *content, - _In_ size_t length, - _Out_ JsValueRef *value); - -/// -/// Write JavascriptString value into C string buffer (Utf8) -/// -/// -/// -/// When size of the `buffer` is unknown, -/// `buffer` argument can be nullptr. -/// In that case, `length` argument will return the length needed. -/// -/// -/// JavascriptString value -/// Pointer to buffer -/// Buffer size -/// Total number of characters needed or written -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsCopyString( - _In_ JsValueRef value, - _Out_opt_ char* buffer, - _In_ size_t bufferSize, - _Out_opt_ size_t* length); - -/// -/// Write string value into Utf16 string buffer -/// -/// -/// -/// When size of the `buffer` is unknown, -/// `buffer` argument can be nullptr. -/// In that case, `written` argument will return the length needed. -/// -/// -/// 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 -/// -/// -/// JavascriptString value -/// start offset of buffer -/// length to be written -/// Pointer to buffer -/// Total number of characters written -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsCopyStringUtf16( - _In_ JsValueRef value, - _In_ int start, - _In_ int length, - _Out_opt_ uint16_t* buffer, - _Out_opt_ size_t* written); - -/// -/// Parses a script and returns a function representing the script. -/// -/// -/// -/// Requires an active script context. -/// -/// -/// 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. -/// -/// -/// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source -/// for better performance and smaller memory footprint. -/// -/// -/// The script to run. -/// -/// A cookie identifying the script that can be used by debuggable script contexts. -/// -/// The location the script came from. -/// Attribute mask for parsing the script -/// The result of the compiled script. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsParse( - _In_ JsValueRef script, - _In_ JsSourceContext sourceContext, - _In_ JsValueRef sourceUrl, - _In_ JsParseScriptAttributes parseAttributes, - _Out_ JsValueRef *result); - -/// -/// Executes a script. -/// -/// -/// -/// Requires an active script context. -/// -/// -/// 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. -/// -/// -/// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source -/// for better performance and smaller memory footprint. -/// -/// -/// The script to run. -/// -/// A cookie identifying the script that can be used by debuggable script contexts. -/// -/// The location the script came from -/// Attribute mask for parsing the script -/// The result of the script, if any. This parameter can be null. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsRun( - _In_ JsValueRef script, - _In_ JsSourceContext sourceContext, - _In_ JsValueRef sourceUrl, - _In_ JsParseScriptAttributes parseAttributes, - _Out_ JsValueRef *result); - -/// -/// Creates 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 string is expected to be ASCII / utf8 encoded. -/// -/// length of the name in bytes -/// The property ID in this runtime for the given name. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsCreatePropertyId( - _In_z_ const char *name, - _In_ size_t length, - _Out_ JsPropertyIdRef *propertyId); - -/// -/// Copies the name associated with the property ID into a buffer. -/// -/// -/// -/// Requires an active script context. -/// -/// -/// When size of the `buffer` is unknown, -/// `buffer` argument can be nullptr. -/// `length` argument will return the size needed. -/// -/// -/// The property ID to get the name of. -/// The buffer holding the name associated with the property ID, encoded as utf8 -/// Size of the buffer. -/// Total number of characters written or to be written -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsCopyPropertyId( - _In_ JsPropertyIdRef propertyId, - _Out_ char* buffer, - _In_ size_t bufferSize, - _Out_ size_t* length); - -/// -/// 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. -/// -/// -/// 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. -/// -/// -/// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source -/// for better performance and smaller memory footprint. -/// -/// -/// The script to serialize -/// ArrayBuffer -/// Encoding for the script. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsSerialize( - _In_ JsValueRef script, - _Out_ JsValueRef *buffer, - _In_ JsParseScriptAttributes parseAttributes); - -/// -/// 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. -/// -/// -/// -/// Requires an active script context. -/// -/// -/// The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer). -/// -/// Callback called when the source code of the script needs to be loaded. -/// This is an optional parameter, set to null if not needed. -/// -/// -/// A cookie identifying the script that can be used by debuggable script contexts. -/// This context will passed into scriptLoadCallback. -/// -/// The location the script came from. -/// A function representing the script code. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsParseSerialized( - _In_ JsValueRef buffer, - _In_ JsSerializedLoadScriptCallback scriptLoadCallback, - _In_ JsSourceContext sourceContext, - _In_ JsValueRef sourceUrl, - _Out_ JsValueRef *result); - -/// -/// Runs a serialized script. -/// Provides the ability to lazy load the script source only if/when it is needed. -/// -/// -/// -/// Requires an active script context. -/// -/// -/// The runtime will detach the data from the buffer and hold on to it until all -/// instances of any functions created from the buffer are garbage collected. -/// -/// -/// The serialized script as an ArrayBuffer (preferably ExternalArrayBuffer). -/// Callback called when the source code of the script needs to be loaded. -/// -/// A cookie identifying the script that can be used by debuggable script contexts. -/// This context will passed into scriptLoadCallback. -/// -/// 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. -/// -CHAKRA_API - JsRunSerialized( - _In_ JsValueRef buffer, - _In_ JsSerializedLoadScriptCallback scriptLoadCallback, - _In_ JsSourceContext sourceContext, - _In_ JsValueRef sourceUrl, - _Out_ JsValueRef *result); - -/// -/// Gets the state of a given Promise object. -/// -/// -/// Requires an active script context. -/// -/// The Promise object. -/// The current state of the Promise. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsGetPromiseState( - _In_ JsValueRef promise, - _Out_ JsPromiseState *state); - -/// -/// Gets the result of a given Promise object. -/// -/// -/// Requires an active script context. -/// -/// The Promise object. -/// The result of the Promise. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsGetPromiseResult( - _In_ JsValueRef promise, - _Out_ JsValueRef *result); - -/// -/// Creates a new JavaScript Promise object. -/// -/// -/// Requires an active script context. -/// -/// The new Promise object. -/// The function called to resolve the created Promise object. -/// The function called to reject the created Promise object. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsCreatePromise( - _Out_ JsValueRef *promise, - _Out_ JsValueRef *resolveFunction, - _Out_ JsValueRef *rejectFunction); - -/// -/// A weak reference to a JavaScript value. -/// -/// -/// A value with only weak references is available for garbage-collection. A strong reference -/// to the value (JsValueRef) may be obtained from a weak reference if the value happens -/// to still be available. -/// -typedef JsRef JsWeakRef; - -/// -/// Creates a weak reference to a value. -/// -/// The value to be referenced. -/// Weak reference to the value. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsCreateWeakReference( - _In_ JsValueRef value, - _Out_ JsWeakRef* weakRef); - -/// -/// Gets a strong reference to the value referred to by a weak reference. -/// -/// A weak reference. -/// Reference to the value, or JS_INVALID_REFERENCE if the value is -/// no longer available. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsGetWeakReferenceValue( - _In_ JsWeakRef weakRef, - _Out_ JsValueRef* value); - -/// -/// Creates a Javascript SharedArrayBuffer object with shared content get from JsGetSharedArrayBufferContent. -/// -/// -/// Requires an active script context. -/// -/// -/// The storage object of a SharedArrayBuffer which can be shared between multiple thread. -/// -/// The new SharedArrayBuffer object. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsCreateSharedArrayBufferWithSharedContent( - _In_ JsSharedArrayBufferContentHandle sharedContents, - _Out_ JsValueRef *result); - -/// -/// Get the storage object from a SharedArrayBuffer. -/// -/// -/// Requires an active script context. -/// -/// The SharedArrayBuffer object. -/// -/// The storage object of a SharedArrayBuffer which can be shared between multiple thread. -/// User should call JsReleaseSharedArrayBufferContentHandle after finished using it. -/// -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsGetSharedArrayBufferContent( - _In_ JsValueRef sharedArrayBuffer, - _Out_ JsSharedArrayBufferContentHandle *sharedContents); - -/// -/// Decrease the reference count on a SharedArrayBuffer storage object. -/// -/// -/// Requires an active script context. -/// -/// -/// The storage object of a SharedArrayBuffer which can be shared between multiple thread. -/// -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsReleaseSharedArrayBufferContentHandle( - _In_ JsSharedArrayBufferContentHandle sharedContents); - -/// -/// Determines whether an object has a non-inherited property. -/// -/// -/// Requires an active script context. -/// -/// The object that may contain the property. -/// The ID of the property. -/// Whether the object has the non-inherited property. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsHasOwnProperty( - _In_ JsValueRef object, - _In_ JsPropertyIdRef propertyId, - _Out_ bool *hasOwnProperty); - -/// -/// Write JS string value into char string buffer without a null terminator -/// -/// -/// -/// When size of the `buffer` is unknown, -/// `buffer` argument can be nullptr. -/// In that case, `written` argument will return the length needed. -/// -/// -/// 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 -/// -/// -/// The JS string `value` will be converted one utf16 code point at a time, -/// and if it has code points that do not fit in one byte, those values -/// will be truncated. -/// -/// -/// JavascriptString value -/// Start offset of buffer -/// Number of characters to be written -/// Pointer to buffer -/// Total number of characters written -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API -JsCopyStringOneByte( - _In_ JsValueRef value, - _In_ int start, - _In_ int length, - _Out_opt_ char* buffer, - _Out_opt_ size_t* written); - -/// -/// Obtains frequently used properties of a data view. -/// -/// The data view instance. -/// The ArrayBuffer backstore of the view. -/// The offset in bytes from the start of arrayBuffer referenced by the array. -/// The number of bytes in the array. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsGetDataViewInfo( - _In_ JsValueRef dataView, - _Out_opt_ JsValueRef *arrayBuffer, - _Out_opt_ unsigned int *byteOffset, - _Out_opt_ unsigned int *byteLength); - -/// -/// Determine if one JavaScript value is less than another JavaScript value. -/// -/// -/// -/// 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 object1 is less than object2. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsLessThan( - _In_ JsValueRef object1, - _In_ JsValueRef object2, - _Out_ bool *result); - -/// -/// Determine if one JavaScript value is less than or equal to another JavaScript value. -/// -/// -/// -/// 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 object1 is less than or equal to object2. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsLessThanOrEqual( - _In_ JsValueRef object1, - _In_ JsValueRef object2, - _Out_ bool *result); - -/// -/// Creates a new object (with prototype) 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. -/// -/// Prototype object or nullptr. -/// The new object. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsCreateExternalObjectWithPrototype( - _In_opt_ void *data, - _In_opt_ JsFinalizeCallback finalizeCallback, - _In_opt_ JsValueRef prototype, - _Out_ JsValueRef *object); - -/// -/// Gets an object's property. -/// -/// -/// Requires an active script context. -/// -/// The object that contains the property. -/// The key (JavascriptString or JavascriptSymbol) to the property. -/// The value of the property. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsObjectGetProperty( - _In_ JsValueRef object, - _In_ JsValueRef key, - _Out_ JsValueRef *value); - -/// -/// Puts an object's property. -/// -/// -/// Requires an active script context. -/// -/// The object that contains the property. -/// The key (JavascriptString or JavascriptSymbol) to 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. -/// -CHAKRA_API - JsObjectSetProperty( - _In_ JsValueRef object, - _In_ JsValueRef key, - _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 key (JavascriptString or JavascriptSymbol) to the property. -/// Whether the object (or a prototype) has the property. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsObjectHasProperty( - _In_ JsValueRef object, - _In_ JsValueRef key, - _Out_ bool *hasProperty); - -/// -/// Defines a new object's own property from a property descriptor. -/// -/// -/// Requires an active script context. -/// -/// The object that has the property. -/// The key (JavascriptString or JavascriptSymbol) to the property. -/// The property descriptor. -/// Whether the property was defined. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsObjectDefineProperty( - _In_ JsValueRef object, - _In_ JsValueRef key, - _In_ JsValueRef propertyDescriptor, - _Out_ bool *result); - -/// -/// Deletes an object's property. -/// -/// -/// Requires an active script context. -/// -/// The object that contains the property. -/// The key (JavascriptString or JavascriptSymbol) to the property. -/// The property set should follow strict mode rules. -/// Whether the property was deleted. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsObjectDeleteProperty( - _In_ JsValueRef object, - _In_ JsValueRef key, - _In_ bool useStrictRules, - _Out_ JsValueRef *result); - -/// -/// Gets a property descriptor for an object's own property. -/// -/// -/// Requires an active script context. -/// -/// The object that has the property. -/// The key (JavascriptString or JavascriptSymbol) to the property. -/// The property descriptor. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsObjectGetOwnPropertyDescriptor( - _In_ JsValueRef object, - _In_ JsValueRef key, - _Out_ JsValueRef *propertyDescriptor); - -/// -/// Determines whether an object has a non-inherited property. -/// -/// -/// Requires an active script context. -/// -/// The object that may contain the property. -/// The key (JavascriptString or JavascriptSymbol) to the property. -/// Whether the object has the non-inherited property. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsObjectHasOwnProperty( - _In_ JsValueRef object, - _In_ JsValueRef key, - _Out_ bool *hasOwnProperty); - -/// -/// Sets whether any action should be taken when a promise is rejected with no reactions -/// or a reaction is added to a promise that was rejected before it had reactions. -/// By default in either of these cases nothing occurs. -/// This function allows you to specify if something should occur and provide a callback -/// to implement whatever should occur. -/// -/// -/// 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. -/// -CHAKRA_API - JsSetHostPromiseRejectionTracker( - _In_ JsHostPromiseRejectionTrackerCallback promiseRejectionTrackerCallback, - _In_opt_ void *callbackState); - -/// -/// Retrieve the namespace object for a module. -/// -/// -/// Requires an active script context and that the module has already been evaluated. -/// -/// The JsModuleRecord for which the namespace is being requested. -/// A JsValueRef - the requested namespace object. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsGetModuleNamespace( - _In_ JsModuleRecord requestModule, - _Outptr_result_maybenull_ JsValueRef *moduleNamespace); - -/// -/// Determines if a provided object is a JavscriptProxy Object and -/// provides references to a Proxy's target and handler. -/// -/// -/// Requires an active script context. -/// If object is not a Proxy object the target and handler parameters are not touched. -/// If nullptr is supplied for target or handler the function returns after -/// setting the isProxy value. -/// If the object is a revoked Proxy target and handler are set to JS_INVALID_REFERENCE. -/// If it is a Proxy object that has not been revoked target and handler are set to the -/// the object's target and handler. -/// -/// The object that may be a Proxy. -/// Pointer to a Boolean - is the object a proxy? -/// Pointer to a JsValueRef - the object's target. -/// Pointer to a JsValueRef - the object's handler. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsGetProxyProperties( - _In_ JsValueRef object, - _Out_ bool* isProxy, - _Out_opt_ JsValueRef* target, - _Out_opt_ JsValueRef* handler); - -/// -/// Parses a script and stores the generated parser state cache into a buffer which can be reused. -/// -/// -/// -/// JsSerializeParserState parses a script and then stores a cache of the parser state -/// in a runtime-independent format. The parser state may be deserialized in any runtime along -/// with the same script to skip the initial parse phase. -/// -/// -/// Requires an active script context. -/// -/// -/// 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. -/// -/// -/// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source -/// for better performance and smaller memory footprint. -/// -/// -/// The script to parse. -/// The buffer to put the serialized parser state cache into. -/// Encoding for the script. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsSerializeParserState( - _In_ JsValueRef scriptVal, - _Out_ JsValueRef *bufferVal, - _In_ JsParseScriptAttributes parseAttributes); - -/// -/// Deserializes the cache of initial parser state and (along with the same -/// script source) executes the script and returns the result. -/// -/// -/// -/// Requires an active script context. -/// -/// -/// 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. -/// -/// -/// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source -/// for better performance and smaller memory footprint. -/// -/// -/// The script to run. -/// -/// A cookie identifying the script that can be used by debuggable script contexts. -/// -/// The location the script came from -/// Attribute mask for parsing the script -/// -/// A buffer containing a cache of the parser state generated by JsSerializeParserState. -/// -/// The result of the script, if any. This parameter can be null. -/// -/// The code JsNoError if the operation succeeded, a failure code otherwise. -/// -CHAKRA_API - JsRunScriptWithParserState( - _In_ JsValueRef script, - _In_ JsSourceContext sourceContext, - _In_ JsValueRef sourceUrl, - _In_ JsParseScriptAttributes parseAttributes, - _In_ JsValueRef parserState, - _Out_ JsValueRef * result); - -#endif // _CHAKRACOREBUILD -#endif // _CHAKRACORE_H_ diff --git a/vnext/ChakraCoreShim/ChakraHeaders/ChakraDebug.h b/vnext/ChakraCoreShim/ChakraHeaders/ChakraDebug.h deleted file mode 100644 index e7239766d5c..00000000000 --- a/vnext/ChakraCoreShim/ChakraHeaders/ChakraDebug.h +++ /dev/null @@ -1,1041 +0,0 @@ -//------------------------------------------------------------------------------------------------------- -// 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 Debugging 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 debug JavaScript. - -/// \file -/// \brief The Chakra hosting debugging API. -/// -/// This file contains a flat C API layer. This is the API exported by ChakraCore.dll. - -#ifdef _MSC_VER -#pragma once -#endif // _MSC_VER - -#ifndef _CHAKRADEBUG_H_ -#define _CHAKRADEBUG_H_ - -#ifdef _WIN32 -//Other platforms already include and have this defined automatically -typedef __int64 int64_t; -typedef unsigned __int32 uint32_t; -#endif - - /// - /// Debug events reported from ChakraCore engine. - /// - typedef enum _JsDiagDebugEvent - { - /// - /// Indicates a new script being compiled, this includes script, eval, new function. - /// - JsDiagDebugEventSourceCompile = 0, - /// - /// Indicates compile error for a script. - /// - JsDiagDebugEventCompileError = 1, - /// - /// Indicates a break due to a breakpoint. - /// - JsDiagDebugEventBreakpoint = 2, - /// - /// Indicates a break after completion of step action. - /// - JsDiagDebugEventStepComplete = 3, - /// - /// Indicates a break due to debugger statement. - /// - JsDiagDebugEventDebuggerStatement = 4, - /// - /// Indicates a break due to async break. - /// - JsDiagDebugEventAsyncBreak = 5, - /// - /// Indicates a break due to a runtime script exception. - /// - JsDiagDebugEventRuntimeException = 6 - } JsDiagDebugEvent; - - /// - /// Break on Exception attributes. - /// - typedef enum _JsDiagBreakOnExceptionAttributes - { - /// - /// Don't break on any exception. - /// - JsDiagBreakOnExceptionAttributeNone = 0x0, - /// - /// Break on uncaught exception. - /// - JsDiagBreakOnExceptionAttributeUncaught = 0x1, - /// - /// Break on first chance exception. - /// - JsDiagBreakOnExceptionAttributeFirstChance = 0x2 - } JsDiagBreakOnExceptionAttributes; - - /// - /// Stepping types. - /// - typedef enum _JsDiagStepType - { - /// - /// Perform a step operation to next statement. - /// - JsDiagStepTypeStepIn = 0, - /// - /// Perform a step out from the current function. - /// - JsDiagStepTypeStepOut = 1, - /// - /// Perform a single step over after a debug break if the next statement is a function call, else behaves as a stepin. - /// - JsDiagStepTypeStepOver = 2, - /// - /// Perform a single step back to the previous statement (only applicable in TTD mode). - /// - JsDiagStepTypeStepBack = 3, - /// - /// Perform a reverse continue operation (only applicable in TTD mode). - /// - JsDiagStepTypeReverseContinue = 4, - /// - /// Perform a forward continue operation. Clears any existing step value. - /// - JsDiagStepTypeContinue = 5 - } JsDiagStepType; - - /// - /// User implemented callback routine for debug events. - /// - /// - /// Use JsDiagStartDebugging to register the callback. - /// - /// The type of JsDiagDebugEvent event. - /// Additional data related to the debug event. - /// The state passed to JsDiagStartDebugging. - typedef void (CHAKRA_CALLBACK * JsDiagDebugEventCallback)(_In_ JsDiagDebugEvent debugEvent, _In_ JsValueRef eventData, _In_opt_ void* callbackState); - - /// - /// Starts debugging in the given runtime. - /// - /// Runtime to put into debug mode. - /// Registers a callback to be called on every JsDiagDebugEvent. - /// User provided state that will be passed back to the callback. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The runtime should be active on the current thread and should not be in debug state. - /// - CHAKRA_API - JsDiagStartDebugging( - _In_ JsRuntimeHandle runtimeHandle, - _In_ JsDiagDebugEventCallback debugEventCallback, - _In_opt_ void* callbackState); - - /// - /// Stops debugging in the given runtime. - /// - /// Runtime to stop debugging. - /// User provided state that was passed in JsDiagStartDebugging. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The runtime should be active on the current thread and in debug state. - /// - CHAKRA_API - JsDiagStopDebugging( - _In_ JsRuntimeHandle runtimeHandle, - _Out_opt_ void** callbackState); - - /// - /// Request the runtime to break on next JavaScript statement. - /// - /// Runtime to request break. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The runtime should be in debug state. This API can be called from another runtime. - /// - CHAKRA_API - JsDiagRequestAsyncBreak( - _In_ JsRuntimeHandle runtimeHandle); - - /// - /// List all breakpoints in the current runtime. - /// - /// Array of breakpoints. - /// - /// - /// [{ - /// "breakpointId" : 1, - /// "scriptId" : 1, - /// "line" : 0, - /// "column" : 62 - /// }] - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can be called when runtime is at a break or running. - /// - CHAKRA_API - JsDiagGetBreakpoints( - _Out_ JsValueRef *breakpoints); - - /// - /// Sets breakpoint in the specified script at give location. - /// - /// Id of script from JsDiagGetScripts or JsDiagGetSource to put breakpoint. - /// 0 based line number to put breakpoint. - /// 0 based column number to put breakpoint. - /// Breakpoint object with id, line and column if success. - /// - /// - /// { - /// "breakpointId" : 1, - /// "line" : 2, - /// "column" : 4 - /// } - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can be called when runtime is at a break or running. - /// - CHAKRA_API - JsDiagSetBreakpoint( - _In_ unsigned int scriptId, - _In_ unsigned int lineNumber, - _In_ unsigned int columnNumber, - _Out_ JsValueRef *breakpoint); - - /// - /// Remove a breakpoint. - /// - /// Breakpoint id returned from JsDiagSetBreakpoint. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can be called when runtime is at a break or running. - /// - CHAKRA_API - JsDiagRemoveBreakpoint( - _In_ unsigned int breakpointId); - - /// - /// Sets break on exception handling. - /// - /// Runtime to set break on exception attributes. - /// Mask of JsDiagBreakOnExceptionAttributes to set. - /// - /// - /// If this API is not called the default value is set to JsDiagBreakOnExceptionAttributeUncaught in the runtime. - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The runtime should be in debug state. This API can be called from another runtime. - /// - CHAKRA_API - JsDiagSetBreakOnException( - _In_ JsRuntimeHandle runtimeHandle, - _In_ JsDiagBreakOnExceptionAttributes exceptionAttributes); - - /// - /// Gets break on exception setting. - /// - /// Runtime from which to get break on exception attributes, should be in debug mode. - /// Mask of JsDiagBreakOnExceptionAttributes. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The runtime should be in debug state. This API can be called from another runtime. - /// - CHAKRA_API - JsDiagGetBreakOnException( - _In_ JsRuntimeHandle runtimeHandle, - _Out_ JsDiagBreakOnExceptionAttributes* exceptionAttributes); - - /// - /// Sets the step type in the runtime after a debug break. - /// - /// - /// Requires to be at a debug break. - /// - /// Type of JsDiagStepType. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can only be called when runtime is at a break. - /// - CHAKRA_API - JsDiagSetStepType( - _In_ JsDiagStepType stepType); - - /// - /// Gets list of scripts. - /// - /// Array of script objects. - /// - /// - /// [{ - /// "scriptId" : 2, - /// "fileName" : "c:\\Test\\Test.js", - /// "lineCount" : 4, - /// "sourceLength" : 111 - /// }, { - /// "scriptId" : 3, - /// "parentScriptId" : 2, - /// "scriptType" : "eval code", - /// "lineCount" : 1, - /// "sourceLength" : 12 - /// }] - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can be called when runtime is at a break or running. - /// - CHAKRA_API - JsDiagGetScripts( - _Out_ JsValueRef *scriptsArray); - - /// - /// Gets source for a specific script identified by scriptId from JsDiagGetScripts. - /// - /// Id of the script. - /// Source object. - /// - /// - /// { - /// "scriptId" : 1, - /// "fileName" : "c:\\Test\\Test.js", - /// "lineCount" : 12, - /// "sourceLength" : 15154, - /// "source" : "var x = 1;" - /// } - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can be called when runtime is at a break or running. - /// - CHAKRA_API - JsDiagGetSource( - _In_ unsigned int scriptId, - _Out_ JsValueRef *source); - - /// - /// Gets the source information for a function object. - /// - /// JavaScript function. - /// Function position - scriptId, start line, start column, line number of first statement, column number of first statement. - /// - /// - /// { - /// "scriptId" : 1, - /// "fileName" : "c:\\Test\\Test.js", - /// "line" : 1, - /// "column" : 2, - /// "firstStatementLine" : 6, - /// "firstStatementColumn" : 0 - /// } - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// This API can be called when runtime is at a break or running. - /// - CHAKRA_API - JsDiagGetFunctionPosition( - _In_ JsValueRef function, - _Out_ JsValueRef *functionPosition); - - /// - /// Gets the stack trace information. - /// - /// Stack trace information. - /// - /// - /// [{ - /// "index" : 0, - /// "scriptId" : 2, - /// "line" : 3, - /// "column" : 0, - /// "sourceLength" : 9, - /// "sourceText" : "var x = 1", - /// "functionHandle" : 1 - /// }] - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can only be called when runtime is at a break. - /// - CHAKRA_API - JsDiagGetStackTrace( - _Out_ JsValueRef *stackTrace); - - /// - /// Gets the list of properties corresponding to the frame. - /// - /// Index of stack frame from JsDiagGetStackTrace. - /// Object of properties array (properties, scopes and globals). - /// - /// - /// propertyAttributes is a bit mask of - /// NONE = 0x1, - /// HAVE_CHILDRENS = 0x2, - /// READ_ONLY_VALUE = 0x4, - /// IN_TDZ = 0x8, - /// - /// - /// { - /// "thisObject": { - /// "name": "this", - /// "type" : "object", - /// "className" : "Object", - /// "display" : "{...}", - /// "propertyAttributes" : 1, - /// "handle" : 306 - /// }, - /// "exception" : { - /// "name" : "{exception}", - /// "type" : "object", - /// "display" : "'a' is undefined", - /// "className" : "Error", - /// "propertyAttributes" : 1, - /// "handle" : 307 - /// } - /// "arguments" : { - /// "name" : "arguments", - /// "type" : "object", - /// "display" : "{...}", - /// "className" : "Object", - /// "propertyAttributes" : 1, - /// "handle" : 190 - /// }, - /// "returnValue" : { - /// "name" : "[Return value]", - /// "type" : "undefined", - /// "propertyAttributes" : 0, - /// "handle" : 192 - /// }, - /// "functionCallsReturn" : [{ - /// "name" : "[foo1 returned]", - /// "type" : "number", - /// "value" : 1, - /// "propertyAttributes" : 2, - /// "handle" : 191 - /// } - /// ], - /// "locals" : [], - /// "scopes" : [{ - /// "index" : 0, - /// "handle" : 193 - /// } - /// ], - /// "globals" : { - /// "handle" : 194 - /// } - /// } - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can only be called when runtime is at a break. - /// - CHAKRA_API - JsDiagGetStackProperties( - _In_ unsigned int stackFrameIndex, - _Out_ JsValueRef *properties); - - /// - /// Gets the list of children of a handle. - /// - /// Handle of object. - /// 0-based from count of properties, usually 0. - /// Number of properties to return. - /// Array of properties. - /// Handle should be from objects returned from call to JsDiagGetStackProperties. - /// For scenarios where object have large number of properties totalCount can be used to control how many properties are given. - /// - /// - /// { - /// "totalPropertiesOfObject": 10, - /// "properties" : [{ - /// "name" : "__proto__", - /// "type" : "object", - /// "display" : "{...}", - /// "className" : "Object", - /// "propertyAttributes" : 1, - /// "handle" : 156 - /// } - /// ], - /// "debuggerOnlyProperties" : [{ - /// "name" : "[Map]", - /// "type" : "string", - /// "value" : "size = 0", - /// "propertyAttributes" : 2, - /// "handle" : 157 - /// } - /// ] - /// } - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can only be called when runtime is at a break. - /// - CHAKRA_API - JsDiagGetProperties( - _In_ unsigned int objectHandle, - _In_ unsigned int fromCount, - _In_ unsigned int totalCount, - _Out_ JsValueRef *propertiesObject); - - /// - /// Gets the object corresponding to handle. - /// - /// Handle of object. - /// Object corresponding to the handle. - /// - /// - /// { - /// "scriptId" : 24, - /// "line" : 1, - /// "column" : 63, - /// "name" : "foo", - /// "type" : "function", - /// "handle" : 2 - /// } - /// - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - /// - /// The current runtime should be in debug state. This API can only be called when runtime is at a break. - /// - CHAKRA_API - JsDiagGetObjectFromHandle( - _In_ unsigned int objectHandle, - _Out_ JsValueRef *handleObject); - - /// - /// Evaluates an expression on given frame. - /// - /// - /// Javascript String or ArrayBuffer (incl. ExternalArrayBuffer). - /// - /// Index of stack frame on which to evaluate the expression. - /// - /// Defines how `expression` (JsValueRef) should be parsed. - /// - `JsParseScriptAttributeNone` when `expression` is a Utf8 encoded ArrayBuffer and/or a Javascript String (encoding independent) - /// - `JsParseScriptAttributeArrayBufferIsUtf16Encoded` when `expression` is Utf16 Encoded ArrayBuffer - /// - `JsParseScriptAttributeLibraryCode` has no use for this function and has similar effect with `JsParseScriptAttributeNone` - /// - /// Forces the result to contain the raw value of the expression result. - /// Result of evaluation. - /// - /// - /// evalResult when evaluating 'this' and return is JsNoError - /// { - /// "name" : "this", - /// "type" : "object", - /// "className" : "Object", - /// "display" : "{...}", - /// "propertyAttributes" : 1, - /// "handle" : 18 - /// } - /// - /// evalResult when evaluating a script which throws JavaScript error and return is JsErrorScriptException - /// { - /// "name" : "a.b.c", - /// "type" : "object", - /// "className" : "Error", - /// "display" : "'a' is undefined", - /// "propertyAttributes" : 1, - /// "handle" : 18 - /// } - /// - /// - /// - /// The code JsNoError if the operation succeeded, evalResult will contain the result - /// The code JsErrorScriptException if evaluate generated a JavaScript exception, evalResult will contain the error details - /// Other error code for invalid parameters or API was not called at break - /// - /// - /// The current runtime should be in debug state. This API can only be called when runtime is at a break. - /// - CHAKRA_API - JsDiagEvaluate( - _In_ JsValueRef expression, - _In_ unsigned int stackFrameIndex, - _In_ JsParseScriptAttributes parseAttributes, - _In_ bool forceSetValueProp, - _Out_ JsValueRef *evalResult); - - ///////////////////// - /// - /// TimeTravel move options as bit flag enum. - /// - typedef enum _JsTTDMoveModes - { - /// - /// Indicates no special actions needed for move. - /// - JsTTDMoveNone = 0x0, - - /// - /// Indicates that we want to move to the first event. - /// - JsTTDMoveFirstEvent = 0x1, - - /// - /// Indicates that we want to move to the last event. - /// - JsTTDMoveLastEvent = 0x2, - - /// - /// Indicates that we want to move to the kth event -- top 32 bits are event count. - /// - JsTTDMoveKthEvent = 0x4, - - /// - /// Indicates if we are doing the scan for a continue operation - /// - JsTTDMoveScanIntervalForContinue = 0x10, - - /// - /// Indicates if we are doing the scan for a continue operation and are in the time-segment where the active breakpoint was - /// - JsTTDMoveScanIntervalForContinueInActiveBreakpointSegment = 0x20, - - /// - /// Indicates if we want to set break on entry or just run and let something else trigger breakpoints. - /// - JsTTDMoveBreakOnEntry = 0x100 - } JsTTDMoveMode; - - /// - /// A handle for URI's that TTD information is written to/read from. - /// - typedef void* JsTTDStreamHandle; - - /// - /// TTD API -- may change in future versions: - /// Construct a JsTTDStreamHandle that will be used to read/write the event log portion of the TTD data based on the uri - /// provided by JsTTDInitializeUriCallback. - /// - /// - /// Exactly one of read or write will be set to true. - /// - /// The length of the uri array that the host passed in for storing log info. - /// The URI that the host passed in for storing log info. - /// The length of the ascii name array that the host passed in for storing log info. - /// An optional ascii string giving a unique name to the resource that the JsTTDStreamHandle will be created for. - /// If the handle should be opened for reading. - /// If the handle should be opened for writing. - /// A JsTTDStreamHandle opened in read/write mode as specified. - typedef JsTTDStreamHandle (CHAKRA_CALLBACK *TTDOpenResourceStreamCallback)(_In_ size_t uriLength, _In_reads_(uriLength) const char* uri, _In_ size_t asciiNameLength, _In_reads_(asciiNameLength) const char* asciiResourceName, _In_ bool read, _In_ bool write); - - /// - /// TTD API -- may change in future versions: - /// A callback for reading data from a handle. - /// - /// The JsTTDStreamHandle to read the data from. - /// The buffer to place the data into. - /// The max number of bytes that should be read. - /// The actual number of bytes read and placed in the buffer. - /// true if the read was successful false otherwise. - typedef bool (CHAKRA_CALLBACK *JsTTDReadBytesFromStreamCallback)(_In_ JsTTDStreamHandle handle, _Out_writes_(size) byte* buff, _In_ size_t size, _Out_ size_t* readCount); - - /// - /// TTD API -- may change in future versions: - /// A callback for writing data to a handle. - /// - /// The JsTTDStreamHandle to write the data to. - /// The buffer to copy the data from. - /// The max number of bytes that should be written. - /// The actual number of bytes written to the HANDLE. - /// true if the write was successful false otherwise. - typedef bool (CHAKRA_CALLBACK *JsTTDWriteBytesToStreamCallback)(_In_ JsTTDStreamHandle handle, _In_reads_(size) const byte* buff, _In_ size_t size, _Out_ size_t* writtenCount); - - /// - /// TTD API -- may change in future versions: - /// Flush and close the stream represented by the HANDLE as needed. - /// - /// - /// Exactly one of read or write will be set to true. - /// - /// The JsTTDStreamHandle to close. - /// If the handle was opened for reading. - /// If the handle was opened for writing. - typedef void (CHAKRA_CALLBACK *JsTTDFlushAndCloseStreamCallback)(_In_ JsTTDStreamHandle handle, _In_ bool read, _In_ bool write); - - /// - /// TTD API -- may change in future versions: - /// Creates a new runtime in Record Mode. - /// - /// The attributes of the runtime to be created. - /// A flag to enable debugging during record. - /// The interval to wait between snapshots (measured in millis). - /// The amount of history to maintain before discarding -- measured in number of snapshots and controls how far back in time a trace can be reversed. - /// The TTDOpenResourceStreamCallback function for generating a JsTTDStreamHandle to read/write serialized data. - /// The JsTTDWriteBytesToStreamCallback function for writing bytes to a JsTTDStreamHandle. - /// The JsTTDFlushAndCloseStreamCallback function for flushing and closing a JsTTDStreamHandle as needed. - /// The thread service for the runtime. Can be null. - /// The runtime created. - /// - /// See JsCreateRuntime for additional information. - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsTTDCreateRecordRuntime( - _In_ JsRuntimeAttributes attributes, - _In_ bool enableDebugging, - _In_ size_t snapInterval, - _In_ size_t snapHistoryLength, - _In_ TTDOpenResourceStreamCallback openResourceStream, - _In_ JsTTDWriteBytesToStreamCallback writeBytesToStream, - _In_ JsTTDFlushAndCloseStreamCallback flushAndCloseStream, - _In_opt_ JsThreadServiceCallback threadService, - _Out_ JsRuntimeHandle *runtime); - - /// - /// TTD API -- may change in future versions: - /// Creates a new runtime in Debug Mode. - /// - /// The attributes of the runtime to be created. - /// The uri where the recorded Time-Travel data should be loaded from. - /// A flag to enable additional debugging operation support during replay. - /// The TTDOpenResourceStreamCallback function for generating a JsTTDStreamHandle to read/write serialized data. - /// The JsTTDReadBytesFromStreamCallback function for reading bytes from a JsTTDStreamHandle. - /// The JsTTDFlushAndCloseStreamCallback function for flushing and closing a JsTTDStreamHandle as needed. - /// The thread service for the runtime. Can be null. - /// The runtime created. - /// - /// See JsCreateRuntime for additional information. - /// - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API - JsTTDCreateReplayRuntime( - _In_ JsRuntimeAttributes attributes, - _In_reads_(infoUriCount) const char* infoUri, - _In_ size_t infoUriCount, - _In_ bool enableDebugging, - _In_ TTDOpenResourceStreamCallback openResourceStream, - _In_ JsTTDReadBytesFromStreamCallback readBytesFromStream, - _In_ JsTTDFlushAndCloseStreamCallback flushAndCloseStream, - _In_opt_ JsThreadServiceCallback threadService, - _Out_ JsRuntimeHandle *runtime); - - /// - /// TTD API -- may change in future versions: - /// Creates a script context that takes the TTD mode from the log or explicitly is not in TTD mode (regular takes mode from currently active script). - /// - /// The runtime the script context is being created in. - /// Set to true to use runtime TTD mode false to explicitly be non-TTD context. - /// The created script context. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API JsTTDCreateContext( - _In_ JsRuntimeHandle runtimeHandle, - _In_ bool useRuntimeTTDMode, - _Out_ JsContextRef *newContext); - - /// - /// TTD API -- may change in future versions: - /// Notify the time-travel system that a context has been identified as dead by the gc (and is being de-allocated). - /// - /// The script context that is now dead. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - /// - CHAKRA_API JsTTDNotifyContextDestroy( - _In_ JsContextRef context); - - /// - /// TTD API -- may change in future versions: - /// Start Time-Travel record or replay at next turn of event loop. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDStart(); - - /// - /// TTD API -- may change in future versions: - /// Stop Time-Travel record or replay. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDStop(); - - /// - /// TTD API -- may change in future versions: - /// Pause Time-Travel recording before executing code on behalf of debugger or other diagnostic/telemetry. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDPauseTimeTravelBeforeRuntimeOperation(); - - /// - /// TTD API -- may change in future versions: - /// ReStart Time-Travel recording after executing code on behalf of debugger or other diagnostic/telemetry. - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDReStartTimeTravelAfterRuntimeOperation(); - - /// - /// TTD API -- may change in future versions: - /// Notify the Js runtime we are at a safe yield point in the event loop (i.e. no locals on the stack and we can process as desired). - /// - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDNotifyYield(); - - /// - /// TTD API -- may change in future versions: - /// Notify the TTD runtime that we are doing a weak add on a reference (we may use this in external API calls and the release will happen in a GC callback). - /// - /// The value we are adding the ref to. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDNotifyLongLivedReferenceAdd(_In_ JsValueRef value); - - /// - /// TTD API -- may change in future versions: - /// Notify the Js runtime the host is aborting the process and what the status code is. - /// - /// The exit status code. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDHostExit(_In_ int statusCode); - - /// - /// TTD API -- may change in future versions: - /// Notify the event log that the contents of one buffer have been copied to a second buffer. - /// - /// The buffer that was written into. - /// The first index modified. - /// The buffer that was copied from. - /// The first index copied. - /// The number of bytes copied. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDRawBufferCopySyncIndirect( - _In_ JsValueRef dst, - _In_ size_t dstIndex, - _In_ JsValueRef src, - _In_ size_t srcIndex, - _In_ size_t count); - - /// - /// TTD API -- may change in future versions: - /// Notify the event log that the contents of a naked byte* buffer passed to the host have been modified synchronously. - /// - /// The buffer that was modified. - /// The first index modified. - /// The number of bytes written. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDRawBufferModifySyncIndirect( - _In_ JsValueRef buffer, - _In_ size_t index, - _In_ size_t count); - - /// - /// TTD API -- may change in future versions: - /// Get info for notifying the TTD system that a raw buffer it shares with the host has been modified. - /// - /// The array buffer we want to monitor for contents modification. - /// The first position in the buffer that may be modified. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDRawBufferAsyncModificationRegister( - _In_ JsValueRef instance, - _In_ byte* initialModPos); - - /// - /// TTD API -- may change in future versions: - /// Notify the event log that the contents of a naked byte* buffer passed to the host have been modified asynchronously. - /// - /// One past the last modified position in the buffer. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDRawBufferAsyncModifyComplete( - _In_ byte* finalModPos); - - /// - /// TTD API -- may change in future versions: - /// A check for unimplemented TTD actions in the host. - /// This API is a TEMPORARY API while we complete the implementation of TTD support in the Node host and will be deleted once that is complete. - /// - /// The message to print if we should be catching this as a TTD operation. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDCheckAndAssertIfTTDRunning( - _In_ const char* msg); - - /// - /// TTD API -- may change in future versions: - /// Before calling JsTTDMoveToTopLevelEvent (which inflates a snapshot and replays) check to see if we want to reset the script context. - /// We reset the script context if the move will require inflating from a different snapshot that the last one. - /// - /// The runtime handle that the script is executing in. - /// Flags controlling the way the move it performed and how other parameters are interpreted. - /// When moveMode == JsTTDMoveKthEvent indicates which event, otherwise this parameter is ignored. - /// The event time we want to move to or -1 if not relevant. - /// Out parameter with the event time of the snapshot that we should inflate from. - /// Optional Out parameter with the snapshot time following the event. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API JsTTDGetSnapTimeTopLevelEventMove( - _In_ JsRuntimeHandle runtimeHandle, - _In_ JsTTDMoveMode moveMode, - _In_opt_ uint32_t kthEvent, - _Inout_ int64_t* targetEventTime, - _Out_ int64_t* targetStartSnapTime, - _Out_opt_ int64_t* targetEndSnapTime); - - /// - /// TTD API -- may change in future versions: - /// Get the snapshot interval that bounds the target event time. - /// - /// The runtime handle that the script is executing in. - /// The event time we want to get the interval for. - /// The snapshot time that comes before the desired event. - /// The snapshot time that comes after the desired event (-1 if the leg ends before a snapshot appears). - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API JsTTDGetSnapShotBoundInterval( - _In_ JsRuntimeHandle runtimeHandle, - _In_ int64_t targetEventTime, - _Out_ int64_t* startSnapTime, - _Out_ int64_t* endSnapTime); - - /// - /// TTD API -- may change in future versions: - /// Get the snapshot interval that precedes the one given by currentSnapStartTime (or -1 if there is no such interval). - /// - /// The runtime handle that the script is executing in. - /// The current snapshot interval start time. - /// The resulting previous snapshot interval start time or -1 if no such time. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API JsTTDGetPreviousSnapshotInterval( - _In_ JsRuntimeHandle runtimeHandle, - _In_ int64_t currentSnapStartTime, - _Out_ int64_t* previousSnapTime); - - /// - /// TTD API -- may change in future versions: - /// During debug operations some additional information is populated during replay. This runs the code between the given - /// snapshots to populate this information which may be needed by the debugger to determine time-travel jump targets. - /// - /// The runtime handle that the script is executing in. - ///The snapshot time that we will start executing from.< / param> - ///The snapshot time that we will stop at (or -1 if we want to run to the end).< / param> - /// Additional flags for controling how the move is done. - /// The updated target event time set according to the moveMode (-1 if not found). - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API JsTTDPreExecuteSnapShotInterval( - _In_ JsRuntimeHandle runtimeHandle, - _In_ int64_t startSnapTime, - _In_ int64_t endSnapTime, - _In_ JsTTDMoveMode moveMode, - _Out_ int64_t* newTargetEventTime); - - /// - /// TTD API -- may change in future versions: - /// Move to the given top-level call event time (assuming JsTTDPrepContextsForTopLevelEventMove) was called previously to reset any script contexts. - /// This also computes the ready-to-run snapshot if needed. - /// - /// The runtime handle that the script is executing in. - /// Additional flags for controling how the move is done. - /// The event time that we will start executing from to move to the given target time. - /// The event that we want to move to. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDMoveToTopLevelEvent( - _In_ JsRuntimeHandle runtimeHandle, - _In_ JsTTDMoveMode moveMode, - _In_ int64_t snapshotTime, - _In_ int64_t eventTime); - - /// - /// TTD API -- may change in future versions: - /// Execute from the current point in the log to the end returning the error code. - /// - /// Additional flags for controling how the move is done. - /// The event time that we should move to next or notification (-1) that replay has ended. - /// - /// If the debugger requested an abort the code is JsNoError -- rootEventTime is the target event time we need to move to and re - execute from. - /// If we aborted at the end of the replay log the code is JsNoError -- rootEventTime is -1. - /// If there was an unhandled script exception the code is JsErrorCategoryScript. - /// - CHAKRA_API - JsTTDReplayExecution( - _Inout_ JsTTDMoveMode* moveMode, - _Out_ int64_t* rootEventTime); - - /// - /// TTD API -- may change in future versions: - /// Enable or disable autotrace ability from JsRT. - /// - /// True to enable autotracing false to disable it. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDDiagSetAutoTraceStatus( - _In_ bool status - ); - - /// - /// TTD API -- may change in future versions: - /// A way for the debugger to programatically write a trace when it is at a breakpoint. - /// - /// The URI that the log should be written into. - /// The length of the uri array that the host passed in for storing log info. - /// The code JsNoError if the operation succeeded, a failure code otherwise. - CHAKRA_API - JsTTDDiagWriteLog( - _In_reads_(uriLength) const char* uri, - _In_ size_t uriLength - ); - -#endif // _CHAKRADEBUG_H_ diff --git a/vnext/ChakraCoreShim/README.md b/vnext/ChakraCoreShim/README.md deleted file mode 100644 index aa9e9b197bb..00000000000 --- a/vnext/ChakraCoreShim/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# ChakraCore Debugging with Visual Studio -This project creates a fake ChakraCore.dll which acts as a shim and translates calls from the ChakraCore to ChakraRT. -Since ChakraRT supports in-process script debugging in VS, this means you would be then be able to attach to process -in "Script" debugging mode and be able to debug React Native JavaScript bundles. - -You can clone the repo and build the ChakraCoreShim project yourself to get the shim ChakraCore.dll, or you can check -\\\\officefile\public\denizdem\ChakraCore2RTShim and just grab the fake dlls from there. You then need to overwrite the -actual ChakraCore.dll on your machine. Check Modules window of Visual Studio to see where ChakraCore is getting loaded from, -and replace that dll with the shim. - -That is all you have to do. This shim dll will make all React Native instances and Chakra contexts debuggable by default. -Once the script is loaded into the context, find the script file in Solution Explorer, where you can start putting -breakpoints. - - -## Debugging Script Load Time -Script file will appear in VS Solution Explorer window only after the script is fully loaded (through JsRun or JsParse), -which makes debugging initial script load time a bit harder. There is a simple fix though. Adding the statement -"debugger;" (without the quotes) to the very top of your React Native bundle.js file would cause Visual Studio debugger -to automatically break-in before anything after the statement executes. Diff would look like: - -```bash -1 (function(global) { -2 -3 + debugger; -4 + -5 global.__DEV__ = true; -6 -7 global.__BUNDLE_START_TIME__ = global.nativePerformanceNow ? global.nativePerformanceNow() : Date.now(); -8 })(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this); -9 (function(global) { -``` - - -## Is Remote Debugging in Chrome dead? -No. Chrome offers a really nice debugger that offers many capabilities Visual Studio script debugger does not. -Besides, ChakraCore is really used only in Win32 platforms, so other platforms would need to continue to use -Chrome debugger anyway. - -Also, this solution works only on Windows 10, where ChakraRT is present. In prior versions of Windows, we would have to -use remote debugging through Chrome even for Win32. - - -## Cool, can I start shimming to other JS engines now? -You definitely can, using the same technique. In fact, ChakraCoreShim project also implements shimming to legacy -Chakra (the one called as jsrt9) as well, given signatures are very similar between ChakraRT and legacy Chakra. - -This does not work with React Native bundles though, given legacy Chakra dll has not been geting any investments lately -and does not support the latest developments JavaScript world had. It barfs when trying to parse/compile the bundle. -But the redirection/shim works. - -In order to test this out, you need to do two things. Both are configurable through the project properties in VS: -1) Remove USE_EDGEMODE_JSRT prom the preprocessor defines of the project, which would cause the shim to use legacy -Chakra APIs, not Microsoft Edge mode Chakra ones. -2) Remove chakrart.lib from the linked libs of the project and add jsrt.lib. diff --git a/vnext/ChakraCoreShim/Redirects.cpp b/vnext/ChakraCoreShim/Redirects.cpp deleted file mode 100644 index b6a28368d85..00000000000 --- a/vnext/ChakraCoreShim/Redirects.cpp +++ /dev/null @@ -1,411 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "Redirects.h" - -#include -#include -#include -#include -#include - -#include - -// If we are not using edge mode jsrt, e.g. we are redirecting to legacy engine, then define the winapi_family -#ifndef USE_EDGEMODE_JSRT -#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP -#endif // !USE_EDGEMODE_JSRT - -#include - -namespace Redirects { - -struct ArrayBufferData; - -// Global storages for APIs that we use from ChakraCore but are not available in jsrt9 -static std::map g_contextDataMap; -static std::map<::JsValueRef, std::shared_ptr> g_arrayBuffers; - -// Helper structures for APIs that we use from ChakraCore but are not available in jsrt9 -struct ArrayBufferData -{ - ::JsValueRef Array = nullptr; - void* Data = nullptr; - unsigned int ByteLength = 0; - ::JsFinalizeCallback ActualFinalizeCallback = nullptr; - void* CallbackState = nullptr; - wchar_t* WideScript = nullptr; - - static void __stdcall FinalizeCallback(void* data) - { - std::unique_ptr> thisPtr(static_cast*>(data)); - if ((*thisPtr)->ActualFinalizeCallback) - (*thisPtr)->ActualFinalizeCallback((*thisPtr)->CallbackState); - - // Delete our copy WideScript, if we had to do conversion during JsRun. - if ((*thisPtr)->WideScript) - { - delete[]((*thisPtr)->WideScript); - (*thisPtr)->WideScript = nullptr; - } - - // Remove the arrayBuffer fromt he list of tracked buffers - g_arrayBuffers.erase((*thisPtr)->Array); - } -}; - -unsigned int JsAddRef(void* ref, unsigned int *count) -{ - return ::JsAddRef(ref, count); -} - -unsigned int JsCallFunction(void* function, void** arguments, unsigned short argumentCount, void** result) -{ - return ::JsCallFunction(function, arguments, argumentCount, result); -} - -unsigned int JsConstructObject(void* function, void** arguments, unsigned short argumentCount, void** result) -{ - return ::JsConstructObject(function, arguments, argumentCount, result); -} - -unsigned int JsConvertValueToObject(void* value, void** object) -{ - return ::JsConvertValueToObject(value, object); -} - -unsigned int JsConvertValueToString(void* value, void** stringValue) -{ - return ::JsConvertValueToString(value, stringValue); -} - -unsigned int JsCopyString(void* value, char* buffer, size_t length, size_t* written) -{ - JsErrorCode result = JsNoError; - - int stringLength = 0; - result = ::JsGetStringLength(value, &stringLength); - if (result != JsNoError) - return result; - - if (!buffer) - { - if (written) - *written = length; - return JsNoError; - } - - const wchar_t* wzBuffer = new wchar_t[stringLength]; - size_t stringLength2 = 0; - result = ::JsStringToPointer(value, &wzBuffer, &stringLength2); - if (result != JsNoError) - return result; - - wcstombs_s(&stringLength2, buffer, stringLength, wzBuffer, _TRUNCATE); - - if (written) - *written = stringLength2; - - return result; -} - -unsigned int JsCreateContext(void* runtime, void** newContext) -{ -#ifdef USE_EDGEMODE_JSRT - unsigned int returnResult = ::JsCreateContext(runtime, newContext); -#else - unsigned int returnResult = ::JsCreateContext(runtime, nullptr, newContext); -#endif - - // Make all contexts created through this shim debuggable. - // JsStartDebugging API expects an active context. So preverseve (any) current one to restore later. - JsContextRef currentContext; - ::JsGetCurrentContext(¤tContext); - - ::JsSetCurrentContext(*newContext); -#ifdef USE_EDGEMODE_JSRT - ::JsStartDebugging(); -#else - // TODO: DenizDem - Proper debugging support for jsrt9 - ::JsStartDebugging(nullptr); -#endif - - // Restore - ::JsSetCurrentContext(currentContext); - - return returnResult; -} - -unsigned int JsCreateError(void* message, void** error) -{ - return ::JsCreateError(message, error); -} - -unsigned int JsCreateExternalArrayBuffer(void *data, unsigned int byteLength, void* finalizeCallback, void* callbackState, void** jsArrayBuffer) -{ - std::unique_ptr> arrayBufferData(std::make_unique>(std::make_shared())); - (*arrayBufferData)->Data = data; - (*arrayBufferData)->ByteLength = byteLength; - (*arrayBufferData)->ActualFinalizeCallback = static_cast<::JsFinalizeCallback>(finalizeCallback); - (*arrayBufferData)->CallbackState = callbackState; - - unsigned int result = ::JsCreateExternalObject(arrayBufferData.get(), static_cast<::JsFinalizeCallback>(ArrayBufferData::FinalizeCallback), jsArrayBuffer); - if (result != JsNoError) - return result; - - // Save the ArrayBuffer as well - (*arrayBufferData)->Array = *jsArrayBuffer; - g_arrayBuffers[*jsArrayBuffer] = *arrayBufferData.get(); - - arrayBufferData.release(); - - return JsNoError; -} - -unsigned int JsCreateExternalObject(void *data, void* finalizeCallback, void** object) -{ - return ::JsCreateExternalObject(data, static_cast<::JsFinalizeCallback>(finalizeCallback), object); -} - -unsigned int JsCreateFunction(void* nativeFunction, void* callbackState, void** function) -{ - return ::JsCreateFunction(static_cast(nativeFunction), callbackState, function); -} - -unsigned int JsCreateNamedFunction(void* name, void* nativeFunction, void *callbackState, void** function) -{ - JsValueRef globalObject; - unsigned int result = ::JsGetGlobalObject(&globalObject); - if (result != JsNoError) - return result; - - size_t nameLength = 0; - const wchar_t* nameString = nullptr; - result = ::JsStringToPointer(name, &nameString, &nameLength); - if (result != JsNoError) - return result; - - ::JsPropertyIdRef propertyId; - result = ::JsGetPropertyIdFromName(nameString, &propertyId); - if (result != JsNoError) - return result; - - result = ::JsCreateFunction(static_cast<::JsNativeFunction>(nativeFunction), callbackState, function); - if (result != JsNoError) - return result; - - result = ::JsSetProperty(globalObject, propertyId, *function, true); - if (result != JsNoError) - return result; - - return JsNoError; -} - -unsigned int JsCreateObject(void** object) -{ - return ::JsCreateObject(object); -} - -unsigned int JsCreateRuntime(int attributes, void* threadService, void** runtime) -{ -#ifdef USE_EDGEMODE_JSRT - return ::JsCreateRuntime(static_cast<::JsRuntimeAttributes>(attributes), static_cast<::JsThreadServiceCallback>(threadService), runtime); -#else - return ::JsCreateRuntime(static_cast<::JsRuntimeAttributes>(attributes), JsRuntimeVersion11, static_cast<::JsThreadServiceCallback>(threadService), runtime); -#endif -} - -unsigned int JsDisposeRuntime(void* runtime) -{ - return ::JsDisposeRuntime(runtime); -} - -unsigned int JsDoubleToNumber(double doubleValue, void** value) -{ - return ::JsDoubleToNumber(doubleValue, value); -} - -unsigned int JsGetAndClearException(void** exception) -{ - return ::JsGetAndClearException(exception); -} - -unsigned int JsGetContextData(void* context, void **data) -{ - *data = g_contextDataMap[context]; - return JsNoError; -} - -unsigned int JsGetCurrentContext(void** currentContext) -{ - return ::JsGetCurrentContext(currentContext); -} - -unsigned int JsGetGlobalObject(void** globalObject) -{ - return ::JsGetGlobalObject(globalObject); -} - -unsigned int JsGetIndexedProperty(void* object, void* index, void** result) -{ - return ::JsGetIndexedProperty(object, index, result); -} - -unsigned int JsGetNullValue(void** nullValue) -{ - return ::JsGetNullValue(nullValue); -} - -unsigned int JsGetOwnPropertyNames(void* object, void** propertyNames) -{ - return ::JsGetOwnPropertyNames(object, propertyNames); -} - -unsigned int JsGetProperty(void* object, void* propertyId, void** value) -{ - return ::JsGetProperty(object, propertyId, value); -} - -unsigned int JsGetPropertyIdFromName(const wchar_t *name, void** propertyId) -{ - return ::JsGetPropertyIdFromName(name, propertyId); -} - -unsigned int JsGetStringLength(void* stringValue, int *length) -{ - return ::JsGetStringLength(stringValue, length); -} - -unsigned int JsGetUndefinedValue(void** value) -{ - return ::JsGetUndefinedValue(value); -} - -unsigned int JsGetValueType(void* value, unsigned int* type) -{ - return ::JsGetValueType(value, static_cast((void*) type)); -} - -unsigned int JsHasException(bool *hasException) -{ - return ::JsHasException(hasException); -} - -unsigned int JsIntToNumber(int intValue, void** value) -{ - return ::JsIntToNumber(intValue, value); -} - -unsigned int JsNumberToDouble(void* value, double *doubleValue) -{ - return ::JsNumberToDouble(value, doubleValue); -} - -unsigned int JsNumberToInt(void* value, int *intValue) -{ - double doubleValue = 0; - unsigned int errorCode = JsNumberToDouble(value, &doubleValue); - if (errorCode != JsNoError) - return errorCode; - // Round and assign - *intValue = static_cast(doubleValue >= 0 ? doubleValue + 0.5 : doubleValue - 0.5); - - return JsNoError; -} - -unsigned int JsPointerToString(const wchar_t *stringValue, size_t stringLength, void** value) -{ - return ::JsPointerToString(stringValue, stringLength, value); -} - -unsigned int JsRelease(void* ref, unsigned int *count) -{ - return ::JsRelease(ref, count); -} - -unsigned int JsRun(void* script, uintptr_t sourceContext, void* sourceUrl, unsigned int parseAttributes, void** scriptResult) -{ - // void* script must be the JsValueRef for the external array buffer - std::shared_ptr arrayBufferData = g_arrayBuffers[script]; - if (!arrayBufferData) - return JsErrorArgumentNotObject; - - wchar_t* wzScript = nullptr; - - const wchar_t* wzSourceUrl = nullptr; - size_t sourceUrlLength = 0; - unsigned int result = ::JsStringToPointer(sourceUrl, &wzSourceUrl, &sourceUrlLength); - if (result != JsNoError) - return result; - - // Take a look at the parse attributes to see the encoding of the array buffer - if (parseAttributes & 0x2 /*JsParseScriptAttributeArrayBufferIsUtf16Encoded*/) - { - wzScript = static_cast(arrayBufferData->Data); - } - else // Buffer is utf8 encoded - { - const char* szScript = static_cast(arrayBufferData->Data); - size_t szScriptLength = strlen(szScript); - // Reserve space for wzScript - wzScript = new wchar_t[szScriptLength + 1]; - // Save this to delete later - arrayBufferData->WideScript = wzScript; - mbstowcs_s(nullptr, wzScript, szScriptLength + 1, szScript, szScriptLength); - } - - return ::JsRunScript(wzScript, sourceContext, wzSourceUrl, scriptResult); -} - -unsigned int JsRunScript(const wchar_t *script, uintptr_t sourceContext, const wchar_t *sourceUrl, void** result) -{ - return ::JsRunScript(script, sourceContext, sourceUrl, result); -} - -unsigned int JsRunSerialized( - /* _In_ JsValueRef */ void* /*buffer*/, - /* _In_ JsSerializedLoadScriptCallback */ void* /*scriptLoadCallback*/, - /* _In_ JsSourceContext */ uintptr_t /*sourceContext*/, - /* _In_ JsValueRef */ void* /*sourceUrl*/, - /* _Out_ JsValueRef* */ void** /*result*/) -{ - // 'JsRunSerialized' appears to be a ChakraCore-only API. Not sure if/how we can translate this to Chakra or JScript9. - // For now, we just ensure that loading binaries does not fail due to missing symbols. - assert(false); - return JsErrorNotImplemented; -} - -unsigned int JsSerializeScript(const wchar_t* /*script*/, void* /*buffer*/, unsigned int* /*bufferSize*/) -{ - // For now, we just ensure that loading binaries does not fail due to missing symbols. - assert(false); - return JsErrorNotImplemented; -} - -unsigned int JsSetContextData(void* context, void *data) -{ - g_contextDataMap[context] = data; - return JsNoError; -} - -unsigned int JsSetCurrentContext(void* context) -{ - return ::JsSetCurrentContext(context); -} - -unsigned int JsSetProperty(void* object, void* propertyId, void* value, bool useStrictRules) -{ - return ::JsSetProperty(object, propertyId, value, useStrictRules); -} - -unsigned int JsSetRuntimeMemoryLimit(void* runtime, size_t memoryLimit) -{ - return ::JsSetRuntimeMemoryLimit(runtime, memoryLimit); -} - -unsigned int JsStringToPointer(void* value, const wchar_t **stringValue, size_t *stringLength) -{ - return ::JsStringToPointer(value, stringValue, stringLength); -} - -} // namespace Redirects diff --git a/vnext/ChakraCoreShim/Redirects.h b/vnext/ChakraCoreShim/Redirects.h deleted file mode 100644 index ddba2063c39..00000000000 --- a/vnext/ChakraCoreShim/Redirects.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -#include - -namespace Redirects { - -unsigned int JsAddRef(void* ref, unsigned int *count); -unsigned int JsCallFunction(void* function, void** arguments, unsigned short argumentCount, void** result); -unsigned int JsConstructObject(void* function, void** arguments, unsigned short argumentCount, void** result); -unsigned int JsConvertValueToObject(void* value, void** object); -unsigned int JsConvertValueToString(void* value, void** stringValue); - -unsigned int JsCopyString(void* value, char* buffer, size_t length, size_t* written); - -unsigned int JsCreateContext(void* runtime, void** newContext); -unsigned int JsCreateError(void* message, void** error); -unsigned int JsCreateExternalArrayBuffer(void *data, unsigned int byteLength, void* finalizeCallback, void* callbackState, void** result); -unsigned int JsCreateExternalObject(void *data, void* finalizeCallback, void** object); -unsigned int JsCreateFunction(void* nativeFunction, void* callbackState, void** function); -unsigned int JsCreateNamedFunction(void* name, void* nativeFunction, void *callbackState, void** function); -unsigned int JsCreateObject(void** object); -unsigned int JsCreateRuntime(int attributes, void* threadService, void** runtime); -unsigned int JsDisposeRuntime(void* runtime); -unsigned int JsDoubleToNumber(double doubleValue, void** value); -unsigned int JsGetAndClearException(void** exception); -unsigned int JsGetContextData(void* context, void **data); -unsigned int JsGetCurrentContext(void** currentContext); -unsigned int JsGetGlobalObject(void** globalObject); -unsigned int JsGetIndexedProperty(void* object, void* index, void** result); -unsigned int JsGetNullValue(void** nullValue); -unsigned int JsGetOwnPropertyNames(void* object, void** propertyNames); -unsigned int JsGetProperty(void* object, void* propertyId, void** value); -unsigned int JsGetPropertyIdFromName(const wchar_t *name, void** propertyId); -unsigned int JsGetStringLength(void* stringValue, int *length); -unsigned int JsGetUndefinedValue(void** nullValue); -unsigned int JsGetValueType(void* value, unsigned int* type); -unsigned int JsHasException(bool *hasException); -unsigned int JsIntToNumber(int intValue, void** value); -unsigned int JsNumberToDouble(void* value, double *doubleValue); -unsigned int JsNumberToInt(void* value, int *intValue); -unsigned int JsPointerToString(const wchar_t *stringValue, size_t stringLength, void** value); -unsigned int JsRelease(void* ref, unsigned int *count); -unsigned int JsRun(void* script, uintptr_t sourceContext, void* sourceUrl, unsigned int parseAttributes, void** result); -unsigned int JsRunScript(const wchar_t *script, uintptr_t sourceContext, const wchar_t *sourceUrl, void** result); -unsigned int JsRunSerialized(void* buffer, void* scriptLoadCallback, uintptr_t sourceContext, void* sourceUrl, void** result); -unsigned int JsSerializeScript(const wchar_t *script, void* buffer, unsigned int* bufferSize); -unsigned int JsSetContextData(void* context, void *data); -unsigned int JsSetCurrentContext(void* context); -unsigned int JsSetProperty(void* object, void* propertyId, void* value, bool useStrictRules); -unsigned int JsSetRuntimeMemoryLimit(void* runtime, size_t memoryLimit); -unsigned int JsStringToPointer(void* value, const wchar_t **stringValue, size_t *stringLength); - -} diff --git a/vnext/ReactWindows.sln b/vnext/ReactWindows.sln index f8f137504fd..dbcb73cd93e 100644 --- a/vnext/ReactWindows.sln +++ b/vnext/ReactWindows.sln @@ -54,8 +54,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "React.Windows.Universal.Uni EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FollyWin32", "FollyWin32\FollyWin32.vcxproj", "{74085F13-2DDE-45E5-A0CA-927AC9D0B953}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChakraCoreShim", "ChakraCoreShim\ChakraCoreShim.vcxproj", "{00830A8B-97E0-4320-B7B0-0078B405997B}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PropertySheets", "PropertySheets", "{6F24927E-EE45-4DB2-91DA-DCC6E98B0C42}" ProjectSection(SolutionItems) = preProject PropertySheets\ARM.props = PropertySheets\ARM.props @@ -237,16 +235,6 @@ Global {74085F13-2DDE-45E5-A0CA-927AC9D0B953}.Release|x64.Build.0 = Release|x64 {74085F13-2DDE-45E5-A0CA-927AC9D0B953}.Release|x86.ActiveCfg = Release|Win32 {74085F13-2DDE-45E5-A0CA-927AC9D0B953}.Release|x86.Build.0 = Release|Win32 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Debug|ARM.ActiveCfg = Debug|Win32 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Debug|x64.ActiveCfg = Debug|x64 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Debug|x64.Build.0 = Debug|x64 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Debug|x86.ActiveCfg = Debug|Win32 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Debug|x86.Build.0 = Debug|Win32 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Release|ARM.ActiveCfg = Release|Win32 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Release|x64.ActiveCfg = Release|x64 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Release|x64.Build.0 = Release|x64 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Release|x86.ActiveCfg = Release|Win32 - {00830A8B-97E0-4320-B7B0-0078B405997B}.Release|x86.Build.0 = Release|Win32 {95048601-C3DC-475F-ADF8-7C0C764C10D5}.Debug|ARM.ActiveCfg = Debug|Win32 {95048601-C3DC-475F-ADF8-7C0C764C10D5}.Debug|x64.ActiveCfg = Debug|x64 {95048601-C3DC-475F-ADF8-7C0C764C10D5}.Debug|x64.Build.0 = Debug|x64 diff --git a/vnext/make.inc b/vnext/make.inc index b1c3030030c..46561837133 100644 --- a/vnext/make.inc +++ b/vnext/make.inc @@ -18,7 +18,6 @@ INCLUDES = $(INCLUDES); \ $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\include\ReactWindowsCore; \ $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\Desktop; \ $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\ReactWindowsCore; \ - $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\ChakraCoreShim\ChakraHeaders; \ $(OPENSOURCE_OPENSSL); \ !LISTFILES -recursive JAVASCRIPTCORE_TEMP_HEADERS = $(PKGJAVASCRIPTCORE_TEMP) *.h diff --git a/vnext/makewinrt.inc b/vnext/makewinrt.inc index def2b71d1b1..de68c87d337 100644 --- a/vnext/makewinrt.inc +++ b/vnext/makewinrt.inc @@ -23,7 +23,6 @@ INCLUDES = $(INCLUDES); \ $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\include; \ $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\include\ReactWindowsCore; \ $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\ReactWindowsCore; \ - $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\ChakraCoreShim\ChakraHeaders; \ $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\ReactUWP; \ $(OPENSOURCE_REACTNATIVE)\OfficeISS\ReactWindows\ReactUWP\Pch; \ $(PKGJAVASCRIPTCORE_TEMP)\build\native\include; \