@@ -36,6 +36,7 @@ struct JsAPIHooks
3636 typedef JsErrorCode (WINAPI *JsrtGetExternalDataPtr)(JsValueRef object, void **data);
3737 typedef JsErrorCode (WINAPI *JsrtCreateArrayPtr)(unsigned int length, JsValueRef *result);
3838 typedef JsErrorCode (WINAPI *JsrtCreateErrorPtr)(JsValueRef message, JsValueRef *error);
39+ typedef JsErrorCode (WINAPI *JsrtHasExceptionPtr)(bool *hasException);
3940 typedef JsErrorCode (WINAPI *JsrtSetExceptionPtr)(JsValueRef exception);
4041 typedef JsErrorCode (WINAPI *JsrtGetAndClearExceptiopnPtr)(JsValueRef* exception);
4142 typedef JsErrorCode (WINAPI *JsrtGetRuntimePtr)(JsContextRef context, JsRuntimeHandle *runtime);
@@ -48,6 +49,24 @@ struct JsAPIHooks
4849 typedef JsErrorCode (WINAPI *JsrtSetPromiseContinuationCallbackPtr)(JsPromiseContinuationCallback callback, void *callbackState);
4950 typedef JsErrorCode (WINAPI *JsrtGetContextOfObject)(JsValueRef object, JsContextRef *callbackState);
5051
52+ typedef JsErrorCode (WINAPI *JsrtParseScriptWithAttributes)(const wchar_t *script, JsSourceContext sourceContext, const wchar_t *sourceUrl, JsParseScriptAttributes parseAttributes, JsValueRef *result);
53+ typedef JsErrorCode (WINAPI *JsrtDiagStartDebugging)(JsRuntimeHandle runtimeHandle, JsDiagDebugEventCallback debugEventCallback, void * callbackState);
54+ typedef JsErrorCode (WINAPI *JsrtDiagStopDebugging)(JsRuntimeHandle runtimeHandle, void ** callbackState);
55+ typedef JsErrorCode (WINAPI *JsrtDiagGetSource)(unsigned int scriptId, JsValueRef *source);
56+ typedef JsErrorCode (WINAPI *JsrtDiagSetBreakpoint)(unsigned int scriptId, unsigned int lineNumber, unsigned int columnNumber, JsValueRef *breakPoint);
57+ typedef JsErrorCode (WINAPI *JsrtDiagGetStackTrace)(JsValueRef *stackTrace);
58+ typedef JsErrorCode (WINAPI *JsrtDiagRequestAsyncBreak)(JsRuntimeHandle runtimeHandle);
59+ typedef JsErrorCode (WINAPI *JsrtDiagGetBreakpoints)(JsValueRef * breakpoints);
60+ typedef JsErrorCode (WINAPI *JsrtDiagRemoveBreakpoint)(unsigned int breakpointId);
61+ typedef JsErrorCode (WINAPI *JsrtDiagSetBreakOnException)(JsRuntimeHandle runtimeHandle, JsDiagBreakOnExceptionAttributes exceptionAttributes);
62+ typedef JsErrorCode (WINAPI *JsrtDiagGetBreakOnException)(JsRuntimeHandle runtimeHandle, JsDiagBreakOnExceptionAttributes * exceptionAttributes);
63+ typedef JsErrorCode (WINAPI *JsrtDiagSetStepType)(JsDiagStepType stepType);
64+ typedef JsErrorCode (WINAPI *JsrtDiagGetScripts)(JsValueRef * scriptsArray);
65+ typedef JsErrorCode (WINAPI *JsrtDiagGetFunctionPosition)(JsValueRef value, JsValueRef * functionInfo);
66+ typedef JsErrorCode (WINAPI *JsrtDiagGetStackProperties)(unsigned int stackFrameIndex, JsValueRef * properties);
67+ typedef JsErrorCode (WINAPI *JsrtDiagGetProperties)(unsigned int objectHandle, unsigned int fromCount, unsigned int totalCount, JsValueRef * propertiesObject);
68+ typedef JsErrorCode (WINAPI *JsrtDiagGetObjectFromHandle)(unsigned int handle, JsValueRef * handleObject);
69+ typedef JsErrorCode (WINAPI *JsrtDiagEvaluate)(const wchar_t * expression, unsigned int stackFrameIndex, JsValueRef * evalResult);
5170 JsrtCreateRuntimePtr pfJsrtCreateRuntime;
5271 JsrtCreateContextPtr pfJsrtCreateContext;
5372 JsrtSetCurrentContextPtr pfJsrtSetCurrentContext;
@@ -80,6 +99,7 @@ struct JsAPIHooks
8099 JsrtGetExternalDataPtr pfJsrtGetExternalData;
81100 JsrtCreateArrayPtr pfJsrtCreateArray;
82101 JsrtCreateErrorPtr pfJsrtCreateError;
102+ JsrtHasExceptionPtr pfJsrtHasException;
83103 JsrtSetExceptionPtr pfJsrtSetException;
84104 JsrtGetAndClearExceptiopnPtr pfJsrtGetAndClearException;
85105 JsrtGetRuntimePtr pfJsrtGetRuntime;
@@ -91,6 +111,24 @@ struct JsAPIHooks
91111 JsrtRunSerializedScriptPtr pfJsrtRunSerializedScript;
92112 JsrtSetPromiseContinuationCallbackPtr pfJsrtSetPromiseContinuationCallback;
93113 JsrtGetContextOfObject pfJsrtGetContextOfObject;
114+ JsrtParseScriptWithAttributes pfJsrtParseScriptWithAttributes;
115+ JsrtDiagStartDebugging pfJsrtDiagStartDebugging;
116+ JsrtDiagStopDebugging pfJsrtDiagStopDebugging;
117+ JsrtDiagGetSource pfJsrtDiagGetSource;
118+ JsrtDiagSetBreakpoint pfJsrtDiagSetBreakpoint;
119+ JsrtDiagGetStackTrace pfJsrtDiagGetStackTrace;
120+ JsrtDiagRequestAsyncBreak pfJsrtDiagRequestAsyncBreak;
121+ JsrtDiagGetBreakpoints pfJsrtDiagGetBreakpoints;
122+ JsrtDiagRemoveBreakpoint pfJsrtDiagRemoveBreakpoint;
123+ JsrtDiagSetBreakOnException pfJsrtDiagSetBreakOnException;
124+ JsrtDiagGetBreakOnException pfJsrtDiagGetBreakOnException;
125+ JsrtDiagSetStepType pfJsrtDiagSetStepType;
126+ JsrtDiagGetScripts pfJsrtDiagGetScripts;
127+ JsrtDiagGetFunctionPosition pfJsrtDiagGetFunctionPosition;
128+ JsrtDiagGetStackProperties pfJsrtDiagGetStackProperties;
129+ JsrtDiagGetProperties pfJsrtDiagGetProperties;
130+ JsrtDiagGetObjectFromHandle pfJsrtDiagGetObjectFromHandle;
131+ JsrtDiagEvaluate pfJsrtDiagEvaluate;
94132};
95133
96134class ChakraRTInterface
@@ -189,6 +227,7 @@ class ChakraRTInterface
189227 static JsErrorCode WINAPI JsGetExternalData (JsValueRef object, void **data) { return m_jsApiHooks.pfJsrtGetExternalData (object, data); }
190228 static JsErrorCode WINAPI JsCreateArray (unsigned int length, JsValueRef *result) { return m_jsApiHooks.pfJsrtCreateArray (length, result); }
191229 static JsErrorCode WINAPI JsCreateError (JsValueRef message, JsValueRef *error) { return m_jsApiHooks.pfJsrtCreateError (message, error); }
230+ static JsErrorCode WINAPI JsHasException (bool *hasException) { return m_jsApiHooks.pfJsrtHasException (hasException); }
192231 static JsErrorCode WINAPI JsSetException (JsValueRef exception) { return m_jsApiHooks.pfJsrtSetException (exception); }
193232 static JsErrorCode WINAPI JsGetAndClearException (JsValueRef *exception) { return m_jsApiHooks.pfJsrtGetAndClearException (exception); }
194233 static JsErrorCode WINAPI JsGetRuntime (JsContextRef context, JsRuntimeHandle *runtime) { return m_jsApiHooks.pfJsrtGetRuntime (context, runtime); }
@@ -200,4 +239,61 @@ class ChakraRTInterface
200239 static JsErrorCode WINAPI JsRunSerializedScript (const char16 *script, BYTE *buffer, DWORD_PTR sourceContext, const char16 *sourceUrl, JsValueRef* result) { return m_jsApiHooks.pfJsrtRunSerializedScript (script, buffer, sourceContext, sourceUrl, result); }
201240 static JsErrorCode WINAPI JsSetPromiseContinuationCallback (JsPromiseContinuationCallback callback, void *callbackState) { return m_jsApiHooks.pfJsrtSetPromiseContinuationCallback (callback, callbackState); }
202241 static JsErrorCode WINAPI JsGetContextOfObject (JsValueRef object, JsContextRef* context) { return m_jsApiHooks.pfJsrtGetContextOfObject (object, context); }
242+ static JsErrorCode WINAPI JsParseScriptWithAttributes (const wchar_t *script, JsSourceContext sourceContext, const wchar_t *sourceUrl, JsParseScriptAttributes parseAttributes, JsValueRef *result) { return m_jsApiHooks.pfJsrtParseScriptWithAttributes (script, sourceContext, sourceUrl, parseAttributes, result); }
243+ static JsErrorCode WINAPI JsDiagStartDebugging (JsRuntimeHandle runtimeHandle, JsDiagDebugEventCallback debugEventCallback, void * callbackState) { return m_jsApiHooks.pfJsrtDiagStartDebugging (runtimeHandle, debugEventCallback, callbackState); }
244+ static JsErrorCode WINAPI JsDiagStopDebugging (JsRuntimeHandle runtimeHandle, void ** callbackState) { return m_jsApiHooks.pfJsrtDiagStopDebugging (runtimeHandle, callbackState); }
245+ static JsErrorCode WINAPI JsDiagGetSource (unsigned int scriptId, JsValueRef *source) { return m_jsApiHooks.pfJsrtDiagGetSource (scriptId, source); }
246+ static JsErrorCode WINAPI JsDiagSetBreakpoint (unsigned int scriptId, unsigned int lineNumber, unsigned int columnNumber, JsValueRef *breakpoint) { return m_jsApiHooks.pfJsrtDiagSetBreakpoint (scriptId, lineNumber, columnNumber, breakpoint); }
247+ static JsErrorCode WINAPI JsDiagGetStackTrace (JsValueRef *stackTrace) { return m_jsApiHooks.pfJsrtDiagGetStackTrace (stackTrace); }
248+ static JsErrorCode WINAPI JsDiagRequestAsyncBreak (JsRuntimeHandle runtimeHandle) { return m_jsApiHooks.pfJsrtDiagRequestAsyncBreak (runtimeHandle); }
249+ static JsErrorCode WINAPI JsDiagGetBreakpoints (JsValueRef * breakpoints) { return m_jsApiHooks.pfJsrtDiagGetBreakpoints (breakpoints); }
250+ static JsErrorCode WINAPI JsDiagRemoveBreakpoint (unsigned int breakpointId) { return m_jsApiHooks.pfJsrtDiagRemoveBreakpoint (breakpointId); }
251+ static JsErrorCode WINAPI JsDiagSetBreakOnException (JsRuntimeHandle runtimeHandle, JsDiagBreakOnExceptionAttributes exceptionAttributes) { return m_jsApiHooks.pfJsrtDiagSetBreakOnException (runtimeHandle, exceptionAttributes); }
252+ static JsErrorCode WINAPI JsDiagGetBreakOnException (JsRuntimeHandle runtimeHandle, JsDiagBreakOnExceptionAttributes * exceptionAttributes) { return m_jsApiHooks.pfJsrtDiagGetBreakOnException (runtimeHandle, exceptionAttributes); }
253+ static JsErrorCode WINAPI JsDiagSetStepType (JsDiagStepType stepType) { return m_jsApiHooks.pfJsrtDiagSetStepType (stepType); }
254+ static JsErrorCode WINAPI JsDiagGetScripts (JsValueRef * scriptsArray) { return m_jsApiHooks.pfJsrtDiagGetScripts (scriptsArray); }
255+ static JsErrorCode WINAPI JsDiagGetFunctionPosition (JsValueRef value, JsValueRef * functionPosition) { return m_jsApiHooks.pfJsrtDiagGetFunctionPosition (value, functionPosition); }
256+ static JsErrorCode WINAPI JsDiagGetStackProperties (unsigned int stackFrameIndex, JsValueRef * properties) { return m_jsApiHooks.pfJsrtDiagGetStackProperties (stackFrameIndex, properties); }
257+ static JsErrorCode WINAPI JsDiagGetProperties (unsigned int objectHandle, unsigned int fromCount, unsigned int totalCount, JsValueRef * propertiesObject) { return m_jsApiHooks.pfJsrtDiagGetProperties (objectHandle, fromCount, totalCount, propertiesObject); }
258+ static JsErrorCode WINAPI JsDiagGetObjectFromHandle (unsigned int handle, JsValueRef * handleObject) { return m_jsApiHooks.pfJsrtDiagGetObjectFromHandle (handle, handleObject); }
259+ static JsErrorCode WINAPI JsDiagEvaluate (const wchar_t * expression, unsigned int stackFrameIndex, JsValueRef * evalResult) { return m_jsApiHooks.pfJsrtDiagEvaluate (expression, stackFrameIndex, evalResult); }
260+ static JsErrorCode WINAPI JsValueToWchar (JsValueRef value, const wchar_t **stringValue, size_t *length)
261+ {
262+ JsValueRef strValue;
263+ IfJsrtErrorFailLogAndRetErrorCode (ChakraRTInterface::JsConvertValueToString (value, &strValue));
264+ IfJsrtErrorFailLogAndRetErrorCode (ChakraRTInterface::JsStringToPointer (strValue, stringValue, length));
265+ return JsNoError;
266+ }
267+ };
268+
269+ class AutoRestoreContext
270+ {
271+ public:
272+ AutoRestoreContext (JsContextRef newContext)
273+ {
274+ JsErrorCode errorCode = ChakraRTInterface::JsGetCurrentContext (&oldContext);
275+ Assert (errorCode == JsNoError);
276+
277+ if (oldContext != newContext)
278+ {
279+ errorCode = ChakraRTInterface::JsSetCurrentContext (newContext);
280+ Assert (errorCode == JsNoError);
281+ contextChanged = true ;
282+ }
283+ else
284+ {
285+ contextChanged = false ;
286+ }
287+ }
288+
289+ ~AutoRestoreContext ()
290+ {
291+ if (contextChanged && oldContext != JS_INVALID_REFERENCE)
292+ {
293+ ChakraRTInterface::JsSetCurrentContext (oldContext);
294+ }
295+ }
296+ private:
297+ JsContextRef oldContext;
298+ bool contextChanged;
203299};
0 commit comments