| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- #include "JsrtPch.h"
- #include "JsrtInternal.h"
- #include "RuntimeDebugPch.h"
- #include "ThreadContextTlsEntry.h"
- #include "JsrtDebugUtils.h"
- #include "Codex/Utf8Helper.h"
- #define VALIDATE_IS_DEBUGGING(jsrtDebugManager) \
- if (jsrtDebugManager == nullptr || !jsrtDebugManager->IsDebugEventCallbackSet()) \
- { \
- return JsErrorDiagNotInDebugMode; \
- }
- #define VALIDATE_RUNTIME_IS_AT_BREAK(runtime) \
- if (runtime->GetThreadContext()->GetDebugManager() == nullptr || !runtime->GetThreadContext()->GetDebugManager()->IsAtDispatchHalt()) \
- { \
- return JsErrorDiagNotAtBreak; \
- }
- #define VALIDATE_RUNTIME_STATE_FOR_START_STOP_DEBUGGING(threadContext) \
- if (threadContext->GetRecycler() && threadContext->GetRecycler()->IsHeapEnumInProgress()) \
- { \
- return JsErrorHeapEnumInProgress; \
- } \
- else if (threadContext->IsInThreadServiceCallback()) \
- { \
- return JsErrorInThreadServiceCallback; \
- } \
- else if (threadContext->IsInScript()) \
- { \
- return JsErrorRuntimeInUse; \
- } \
- ThreadContextScope scope(threadContext); \
- if (!scope.IsValid()) \
- { \
- return JsErrorWrongThread; \
- }
- CHAKRA_API JsDiagStartDebugging(
- _In_ JsRuntimeHandle runtimeHandle,
- _In_ JsDiagDebugEventCallback debugEventCallback,
- _In_opt_ void* callbackState)
- {
- return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
- VALIDATE_INCOMING_RUNTIME_HANDLE(runtimeHandle);
- PARAM_NOT_NULL(debugEventCallback);
- JsrtRuntime * runtime = JsrtRuntime::FromHandle(runtimeHandle);
- ThreadContext * threadContext = runtime->GetThreadContext();
- VALIDATE_RUNTIME_STATE_FOR_START_STOP_DEBUGGING(threadContext);
- if (runtime->GetJsrtDebugManager() != nullptr && runtime->GetJsrtDebugManager()->IsDebugEventCallbackSet())
- {
- return JsErrorDiagAlreadyInDebugMode;
- }
- // Create the debug object to save callback function and data
- runtime->EnsureJsrtDebugManager();
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- jsrtDebugManager->SetDebugEventCallback(debugEventCallback, callbackState);
- if (threadContext->GetDebugManager() != nullptr)
- {
- threadContext->GetDebugManager()->SetLocalsDisplayFlags(Js::DebugManager::LocalsDisplayFlags::LocalsDisplayFlags_NoGroupMethods);
- }
- for (Js::ScriptContext *scriptContext = runtime->GetThreadContext()->GetScriptContextList();
- scriptContext != nullptr && !scriptContext->IsClosed();
- scriptContext = scriptContext->next)
- {
- Assert(!scriptContext->IsScriptContextInDebugMode());
- Js::DebugContext* debugContext = scriptContext->GetDebugContext();
- if (debugContext->GetHostDebugContext() == nullptr)
- {
- debugContext->SetHostDebugContext(jsrtDebugManager);
- }
- HRESULT hr;
- if (FAILED(hr = scriptContext->OnDebuggerAttached()))
- {
- Debugger_AttachDetach_fatal_error(hr); // Inconsistent state, we can't continue from here
- return JsErrorFatal;
- }
- Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
- probeContainer->InitializeInlineBreakEngine(jsrtDebugManager);
- probeContainer->InitializeDebuggerScriptOptionCallback(jsrtDebugManager);
- }
- return JsNoError;
- });
- }
- CHAKRA_API JsDiagStopDebugging(
- _In_ JsRuntimeHandle runtimeHandle,
- _Out_ void** callbackState)
- {
- return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
- VALIDATE_INCOMING_RUNTIME_HANDLE(runtimeHandle);
- PARAM_NOT_NULL(callbackState);
- *callbackState = nullptr;
- JsrtRuntime * runtime = JsrtRuntime::FromHandle(runtimeHandle);
- ThreadContext * threadContext = runtime->GetThreadContext();
- VALIDATE_RUNTIME_STATE_FOR_START_STOP_DEBUGGING(threadContext);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- for (Js::ScriptContext *scriptContext = runtime->GetThreadContext()->GetScriptContextList();
- scriptContext != nullptr && !scriptContext->IsClosed();
- scriptContext = scriptContext->next)
- {
- Assert(scriptContext->IsScriptContextInDebugMode());
- HRESULT hr;
- if (FAILED(hr = scriptContext->OnDebuggerDetached()))
- {
- Debugger_AttachDetach_fatal_error(hr); // Inconsistent state, we can't continue from here
- return JsErrorFatal;
- }
- Js::DebugContext* debugContext = scriptContext->GetDebugContext();
- Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
- probeContainer->UninstallInlineBreakpointProbe(nullptr);
- probeContainer->UninstallDebuggerScriptOptionCallback();
- jsrtDebugManager->ClearBreakpointDebugDocumentDictionary();
- }
- *callbackState = jsrtDebugManager->GetAndClearCallbackState();
- return JsNoError;
- });
- }
- CHAKRA_API JsDiagGetScripts(
- _Out_ JsValueRef *scriptsArray)
- {
- return ContextAPIWrapper_NoRecord<false>([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
- PARAM_NOT_NULL(scriptsArray);
- *scriptsArray = JS_INVALID_REFERENCE;
- JsrtContext *currentContext = JsrtContext::GetCurrent();
- JsrtDebugManager* jsrtDebugManager = currentContext->GetRuntime()->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- Js::JavascriptArray* scripts = jsrtDebugManager->GetScripts(scriptContext);
- if (scripts != nullptr)
- {
- *scriptsArray = scripts;
- return JsNoError;
- }
- return JsErrorDiagUnableToPerformAction;
- });
- }
- CHAKRA_API JsDiagGetSource(
- _In_ unsigned int scriptId,
- _Out_ JsValueRef *source)
- {
- return ContextAPIWrapper_NoRecord<false>([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
- PARAM_NOT_NULL(source);
- *source = JS_INVALID_REFERENCE;
- JsrtContext *currentContext = JsrtContext::GetCurrent();
- JsrtDebugManager* jsrtDebugManager = currentContext->GetRuntime()->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- Js::DynamicObject* sourceObject = jsrtDebugManager->GetSource(scriptContext, scriptId);
- if (sourceObject != nullptr)
- {
- *source = sourceObject;
- return JsNoError;
- }
- return JsErrorInvalidArgument;
- });
- }
- CHAKRA_API JsDiagRequestAsyncBreak(
- _In_ JsRuntimeHandle runtimeHandle)
- {
- return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
- VALIDATE_INCOMING_RUNTIME_HANDLE(runtimeHandle);
- JsrtRuntime * runtime = JsrtRuntime::FromHandle(runtimeHandle);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- for (Js::ScriptContext *scriptContext = runtime->GetThreadContext()->GetScriptContextList();
- scriptContext != nullptr && !scriptContext->IsClosed();
- scriptContext = scriptContext->next)
- {
- jsrtDebugManager->EnableAsyncBreak(scriptContext);
- }
- return JsNoError;
- });
- }
- CHAKRA_API JsDiagGetBreakpoints(
- _Out_ JsValueRef *breakpoints)
- {
- return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
- PARAM_NOT_NULL(breakpoints);
- *breakpoints = JS_INVALID_REFERENCE;
- JsrtContext *currentContext = JsrtContext::GetCurrent();
- Js::JavascriptArray* bpsArray = currentContext->GetScriptContext()->GetLibrary()->CreateArray();
- JsrtRuntime * runtime = currentContext->GetRuntime();
- ThreadContextScope scope(runtime->GetThreadContext());
- if (!scope.IsValid())
- {
- return JsErrorWrongThread;
- }
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- for (Js::ScriptContext *scriptContext = runtime->GetThreadContext()->GetScriptContextList();
- scriptContext != nullptr && !scriptContext->IsClosed();
- scriptContext = scriptContext->next)
- {
- jsrtDebugManager->GetBreakpoints(&bpsArray, scriptContext);
- }
- *breakpoints = bpsArray;
- return JsNoError;
- });
- }
- CHAKRA_API JsDiagSetBreakpoint(
- _In_ unsigned int scriptId,
- _In_ unsigned int lineNumber,
- _In_ unsigned int columnNumber,
- _Out_ JsValueRef *breakpoint)
- {
- return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
- PARAM_NOT_NULL(breakpoint);
- *breakpoint = JS_INVALID_REFERENCE;
- JsrtContext *currentContext = JsrtContext::GetCurrent();
- JsrtRuntime * runtime = currentContext->GetRuntime();
- ThreadContextScope scope(runtime->GetThreadContext());
- if (!scope.IsValid())
- {
- return JsErrorWrongThread;
- }
- VALIDATE_IS_DEBUGGING(runtime->GetJsrtDebugManager());
- Js::Utf8SourceInfo* utf8SourceInfo = nullptr;
- for (Js::ScriptContext *scriptContext = runtime->GetThreadContext()->GetScriptContextList();
- scriptContext != nullptr && utf8SourceInfo == nullptr && !scriptContext->IsClosed();
- scriptContext = scriptContext->next)
- {
- scriptContext->MapScript([&](Js::Utf8SourceInfo* sourceInfo) -> bool
- {
- if (sourceInfo->GetSourceInfoId() == scriptId)
- {
- utf8SourceInfo = sourceInfo;
- return true;
- }
- return false;
- });
- }
- if (utf8SourceInfo != nullptr && utf8SourceInfo->HasDebugDocument())
- {
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- Js::DynamicObject* bpObject = jsrtDebugManager->SetBreakPoint(currentContext->GetScriptContext(), utf8SourceInfo, lineNumber, columnNumber);
- if(bpObject != nullptr)
- {
- *breakpoint = bpObject;
- return JsNoError;
- }
- return JsErrorDiagUnableToPerformAction;
- }
- return JsErrorDiagObjectNotFound;
- });
- }
- CHAKRA_API JsDiagRemoveBreakpoint(
- _In_ unsigned int breakpointId)
- {
- return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
- JsrtContext *currentContext = JsrtContext::GetCurrent();
- JsrtRuntime* runtime = currentContext->GetRuntime();
- ThreadContextScope scope(runtime->GetThreadContext());
- if (!scope.IsValid())
- {
- return JsErrorWrongThread;
- }
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- if (!jsrtDebugManager->RemoveBreakpoint(breakpointId))
- {
- return JsErrorInvalidArgument;
- }
- return JsNoError;
- });
- }
- CHAKRA_API JsDiagSetBreakOnException(
- _In_ JsRuntimeHandle runtimeHandle,
- _In_ JsDiagBreakOnExceptionAttributes exceptionAttributes)
- {
- return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
- VALIDATE_INCOMING_RUNTIME_HANDLE(runtimeHandle);
- JsrtRuntime * runtime = JsrtRuntime::FromHandle(runtimeHandle);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- jsrtDebugManager->SetBreakOnException(exceptionAttributes);
- return JsNoError;
- });
- }
- CHAKRA_API JsDiagGetBreakOnException(
- _In_ JsRuntimeHandle runtimeHandle,
- _Out_ JsDiagBreakOnExceptionAttributes* exceptionAttributes)
- {
- return GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
- VALIDATE_INCOMING_RUNTIME_HANDLE(runtimeHandle);
- PARAM_NOT_NULL(exceptionAttributes);
- *exceptionAttributes = JsDiagBreakOnExceptionAttributeNone;
- JsrtRuntime * runtime = JsrtRuntime::FromHandle(runtimeHandle);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- *exceptionAttributes = jsrtDebugManager->GetBreakOnException();
- return JsNoError;
- });
- }
- CHAKRA_API JsDiagSetStepType(
- _In_ JsDiagStepType stepType)
- {
- return ContextAPIWrapper_NoRecord<true>([&](Js::ScriptContext * scriptContext) -> JsErrorCode {
- JsrtContext *currentContext = JsrtContext::GetCurrent();
- JsrtRuntime* runtime = currentContext->GetRuntime();
- VALIDATE_RUNTIME_IS_AT_BREAK(runtime);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- if (stepType == JsDiagStepTypeStepIn)
- {
- jsrtDebugManager->SetResumeType(BREAKRESUMEACTION_STEP_INTO);
- }
- else if (stepType == JsDiagStepTypeStepOut)
- {
- jsrtDebugManager->SetResumeType(BREAKRESUMEACTION_STEP_OUT);
- }
- else if (stepType == JsDiagStepTypeStepOver)
- {
- jsrtDebugManager->SetResumeType(BREAKRESUMEACTION_STEP_OVER);
- }
- else if (stepType == JsDiagStepTypeStepBack)
- {
- #if ENABLE_TTD
- ThreadContext* threadContext = runtime->GetThreadContext();
- if(!threadContext->IsRuntimeInTTDMode())
- {
- return JsErrorInvalidArgument;
- }
- TTD::TTDebuggerSourceLocation bpLocation;
- threadContext->TTDLog->GetPreviousTimeAndPositionForDebugger(bpLocation);
- threadContext->TTDLog->SetPendingTTDBPInfo(bpLocation);
- threadContext->TTDLog->SetPendingTTDMoveMode(JsTTDMoveMode::JsTTDMoveNone);
- //don't worry about BP suppression because we are just going to throw after we return
- jsrtDebugManager->SetResumeType(BREAKRESUMEACTION_CONTINUE);
- #else
- return JsErrorInvalidArgument;
- #endif
- }
- else if(stepType == JsDiagStepTypeStepReverseContinue)
- {
- #if ENABLE_TTD
- ThreadContext* threadContext = runtime->GetThreadContext();
- if(!threadContext->IsRuntimeInTTDMode())
- {
- return JsErrorInvalidArgument;
- }
- TTD::TTDebuggerSourceLocation bpLocation;
- threadContext->TTDLog->GetTimeAndPositionForDebugger(bpLocation);
- threadContext->TTDLog->SetPendingTTDBPInfo(bpLocation);
- threadContext->TTDLog->SetPendingTTDMoveMode(JsTTDMoveMode::JsTTDMoveScanIntervalForContinue);
- //don't worry about BP suppression because we are just going to throw after we return
- jsrtDebugManager->SetResumeType(BREAKRESUMEACTION_CONTINUE);
- #else
- return JsErrorInvalidArgument;
- #endif
- }
- return JsNoError;
- });
- }
- CHAKRA_API JsDiagGetFunctionPosition(
- _In_ JsValueRef function,
- _Out_ JsValueRef *functionPosition)
- {
- return ContextAPIWrapper_NoRecord<false>([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
- VALIDATE_INCOMING_REFERENCE(function, scriptContext);
- PARAM_NOT_NULL(functionPosition);
- *functionPosition = JS_INVALID_REFERENCE;
- if (!Js::RecyclableObject::Is(function) || !Js::ScriptFunction::Is(function))
- {
- return JsErrorInvalidArgument;
- }
- Js::ScriptFunction* jsFunction = Js::ScriptFunction::FromVar(function);
- Js::FunctionBody* functionBody = jsFunction->GetFunctionBody();
- if (functionBody != nullptr)
- {
- Js::Utf8SourceInfo* utf8SourceInfo = functionBody->GetUtf8SourceInfo();
- if (utf8SourceInfo != nullptr && !utf8SourceInfo->GetIsLibraryCode())
- {
- ULONG lineNumber = functionBody->GetLineNumber();
- ULONG columnNumber = functionBody->GetColumnNumber();
- uint startOffset = functionBody->GetStatementStartOffset(0);
- ULONG firstStatementLine;
- LONG firstStatementColumn;
- if (functionBody->GetLineCharOffsetFromStartChar(startOffset, &firstStatementLine, &firstStatementColumn))
- {
- Js::DynamicObject* funcPositionObject = (Js::DynamicObject*)Js::CrossSite::MarshalVar(utf8SourceInfo->GetScriptContext(), scriptContext->GetLibrary()->CreateObject());
- if (funcPositionObject != nullptr)
- {
- JsrtDebugUtils::AddScriptIdToObject(funcPositionObject, utf8SourceInfo);
- JsrtDebugUtils::AddFileNameOrScriptTypeToObject(funcPositionObject, utf8SourceInfo);
- JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::line, (uint32) lineNumber, scriptContext);
- JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::column, (uint32) columnNumber, scriptContext);
- JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::firstStatementLine, (uint32) firstStatementLine, scriptContext);
- JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::firstStatementColumn, (int32) firstStatementColumn, scriptContext);
- *functionPosition = funcPositionObject;
- return JsNoError;
- }
- }
- }
- }
- return JsErrorDiagObjectNotFound;
- });
- }
- CHAKRA_API JsDiagGetStackTrace(
- _Out_ JsValueRef *stackTrace)
- {
- return ContextAPIWrapper_NoRecord<false>([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
- PARAM_NOT_NULL(stackTrace);
- *stackTrace = JS_INVALID_REFERENCE;
- JsrtContext* context = JsrtContext::GetCurrent();
- JsrtRuntime* runtime = context->GetRuntime();
- VALIDATE_RUNTIME_IS_AT_BREAK(runtime);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- *stackTrace = jsrtDebugManager->GetStackFrames(scriptContext);
- return JsNoError;
- });
- }
- CHAKRA_API JsDiagGetStackProperties(
- _In_ unsigned int stackFrameIndex,
- _Out_ JsValueRef *properties)
- {
- return ContextAPIWrapper_NoRecord<false>([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
- PARAM_NOT_NULL(properties);
- *properties = JS_INVALID_REFERENCE;
- JsrtContext* context = JsrtContext::GetCurrent();
- JsrtRuntime* runtime = context->GetRuntime();
- VALIDATE_RUNTIME_IS_AT_BREAK(runtime);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- JsrtDebuggerStackFrame* debuggerStackFrame = nullptr;
- if (!jsrtDebugManager->TryGetFrameObjectFromFrameIndex(scriptContext, stackFrameIndex, &debuggerStackFrame))
- {
- return JsErrorDiagObjectNotFound;
- }
- Js::DynamicObject* localsObject = debuggerStackFrame->GetLocalsObject(scriptContext);
- if (localsObject != nullptr)
- {
- *properties = localsObject;
- return JsNoError;
- }
- return JsErrorDiagUnableToPerformAction;
- });
- }
- CHAKRA_API JsDiagGetProperties(
- _In_ unsigned int objectHandle,
- _In_ unsigned int fromCount,
- _In_ unsigned int totalCount,
- _Out_ JsValueRef *propertiesObject)
- {
- return ContextAPIWrapper_NoRecord<false>([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
- PARAM_NOT_NULL(propertiesObject);
- *propertiesObject = JS_INVALID_REFERENCE;
- JsrtContext* context = JsrtContext::GetCurrent();
- JsrtRuntime* runtime = context->GetRuntime();
- VALIDATE_RUNTIME_IS_AT_BREAK(runtime);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- JsrtDebuggerObjectBase* debuggerObject = nullptr;
- if (!jsrtDebugManager->GetDebuggerObjectsManager()->TryGetDebuggerObjectFromHandle(objectHandle, &debuggerObject) || debuggerObject == nullptr)
- {
- return JsErrorDiagInvalidHandle;
- }
- Js::DynamicObject* properties = debuggerObject->GetChildren(scriptContext, fromCount, totalCount);
- if (properties != nullptr)
- {
- *propertiesObject = properties;
- return JsNoError;
- }
- return JsErrorDiagUnableToPerformAction;
- });
- }
- CHAKRA_API JsDiagGetObjectFromHandle(
- _In_ unsigned int objectHandle,
- _Out_ JsValueRef *handleObject)
- {
- return ContextAPIWrapper_NoRecord<false>([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
- PARAM_NOT_NULL(handleObject);
- *handleObject = JS_INVALID_REFERENCE;
- JsrtContext* context = JsrtContext::GetCurrent();
- JsrtRuntime* runtime = context->GetRuntime();
- VALIDATE_RUNTIME_IS_AT_BREAK(runtime);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- JsrtDebuggerObjectBase* debuggerObject = nullptr;
- if (!jsrtDebugManager->GetDebuggerObjectsManager()->TryGetDebuggerObjectFromHandle(objectHandle, &debuggerObject) || debuggerObject == nullptr)
- {
- return JsErrorDiagInvalidHandle;
- }
- Js::DynamicObject* object = debuggerObject->GetJSONObject(scriptContext);
- if (object != nullptr)
- {
- *handleObject = object;
- return JsNoError;
- }
- return JsErrorDiagUnableToPerformAction;
- });
- }
- CHAKRA_API JsDiagEvaluate(
- _In_z_ const WCHAR *expression,
- _In_ unsigned int stackFrameIndex,
- _Out_ JsValueRef *evalResult)
- {
- return ContextAPINoScriptWrapper_NoRecord([&](Js::ScriptContext *scriptContext) -> JsErrorCode {
- PARAM_NOT_NULL(expression);
- PARAM_NOT_NULL(evalResult);
- *evalResult = JS_INVALID_REFERENCE;
- JsrtContext* context = JsrtContext::GetCurrent();
- JsrtRuntime* runtime = context->GetRuntime();
- VALIDATE_RUNTIME_IS_AT_BREAK(runtime);
- JsrtDebugManager* jsrtDebugManager = runtime->GetJsrtDebugManager();
- VALIDATE_IS_DEBUGGING(jsrtDebugManager);
- JsrtDebuggerStackFrame* debuggerStackFrame = nullptr;
- if (!jsrtDebugManager->TryGetFrameObjectFromFrameIndex(scriptContext, stackFrameIndex, &debuggerStackFrame))
- {
- return JsErrorDiagObjectNotFound;
- }
- size_t len = wcslen(expression);
- if (len != static_cast<int>(len))
- {
- return JsErrorInvalidArgument;
- }
- Js::DynamicObject* result = nullptr;
- bool success = debuggerStackFrame->Evaluate(scriptContext, expression, static_cast<int>(len), false, &result);
- if (result != nullptr)
- {
- *evalResult = result;
- }
- return success ? JsNoError : JsErrorScriptException;
- }, false /*allowInObjectBeforeCollectCallback*/, true /*scriptExceptionAllowed*/);
- }
- #ifdef CHAKRACOREBUILD_
- CHAKRA_API JsDiagEvaluateUtf8(
- _In_z_ const char *expression,
- _In_ unsigned int stackFrameIndex,
- _Out_ JsValueRef *evalResult)
- {
- PARAM_NOT_NULL(expression);
- utf8::NarrowToWide wstr(expression, strlen(expression));
- if (!wstr)
- {
- return JsErrorOutOfMemory;
- }
- return JsDiagEvaluate(wstr, stackFrameIndex, evalResult);
- }
- #endif
|