| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "platform/v8_inspector/JavaScriptCallFrame.h" | |
| 32 | |
| 33 #include "platform/v8_inspector/StringUtil.h" | |
| 34 #include "platform/v8_inspector/V8Compat.h" | |
| 35 | |
| 36 #include <v8-debug.h> | |
| 37 | |
| 38 namespace v8_inspector { | |
| 39 | |
| 40 JavaScriptCallFrame::JavaScriptCallFrame(v8::Local<v8::Context> debuggerContext,
v8::Local<v8::Object> callFrame) | |
| 41 : m_isolate(debuggerContext->GetIsolate()) | |
| 42 , m_debuggerContext(m_isolate, debuggerContext) | |
| 43 , m_callFrame(m_isolate, callFrame) | |
| 44 { | |
| 45 } | |
| 46 | |
| 47 JavaScriptCallFrame::~JavaScriptCallFrame() | |
| 48 { | |
| 49 } | |
| 50 | |
| 51 int JavaScriptCallFrame::callV8FunctionReturnInt(const char* name) const | |
| 52 { | |
| 53 v8::HandleScope handleScope(m_isolate); | |
| 54 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); | |
| 55 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(m_isolate, m_de
buggerContext); | |
| 56 v8::Local<v8::Object> callFrame = v8::Local<v8::Object>::New(m_isolate, m_ca
llFrame); | |
| 57 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get(
toV8StringInternalized(m_isolate, name))); | |
| 58 v8::Local<v8::Value> result; | |
| 59 if (!func->Call(context, callFrame, 0, nullptr).ToLocal(&result) || !result-
>IsInt32()) | |
| 60 return 0; | |
| 61 return result.As<v8::Int32>()->Value(); | |
| 62 } | |
| 63 | |
| 64 int JavaScriptCallFrame::sourceID() const | |
| 65 { | |
| 66 return callV8FunctionReturnInt("sourceID"); | |
| 67 } | |
| 68 | |
| 69 int JavaScriptCallFrame::line() const | |
| 70 { | |
| 71 return callV8FunctionReturnInt("line"); | |
| 72 } | |
| 73 | |
| 74 int JavaScriptCallFrame::column() const | |
| 75 { | |
| 76 return callV8FunctionReturnInt("column"); | |
| 77 } | |
| 78 | |
| 79 int JavaScriptCallFrame::contextId() const | |
| 80 { | |
| 81 return callV8FunctionReturnInt("contextId"); | |
| 82 } | |
| 83 | |
| 84 bool JavaScriptCallFrame::isAtReturn() const | |
| 85 { | |
| 86 v8::HandleScope handleScope(m_isolate); | |
| 87 v8::Local<v8::Value> result = v8::Local<v8::Object>::New(m_isolate, m_callFr
ame)->Get(toV8StringInternalized(m_isolate, "isAtReturn")); | |
| 88 if (result.IsEmpty() || !result->IsBoolean()) | |
| 89 return false; | |
| 90 return result->BooleanValue(); | |
| 91 } | |
| 92 | |
| 93 v8::Local<v8::Object> JavaScriptCallFrame::details() const | |
| 94 { | |
| 95 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); | |
| 96 v8::Local<v8::Object> callFrame = v8::Local<v8::Object>::New(m_isolate, m_ca
llFrame); | |
| 97 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(callFrame->Get(
toV8StringInternalized(m_isolate, "details"))); | |
| 98 return v8::Local<v8::Object>::Cast(func->Call(m_debuggerContext.Get(m_isolat
e), callFrame, 0, nullptr).ToLocalChecked()); | |
| 99 } | |
| 100 | |
| 101 v8::MaybeLocal<v8::Value> JavaScriptCallFrame::evaluate(v8::Local<v8::Value> exp
ression) | |
| 102 { | |
| 103 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kRunMicrotask
s); | |
| 104 v8::Local<v8::Object> callFrame = v8::Local<v8::Object>::New(m_isolate, m_ca
llFrame); | |
| 105 v8::Local<v8::Function> evalFunction = v8::Local<v8::Function>::Cast(callFra
me->Get(toV8StringInternalized(m_isolate, "evaluate"))); | |
| 106 return evalFunction->Call(m_debuggerContext.Get(m_isolate), callFrame, 1, &e
xpression); | |
| 107 } | |
| 108 | |
| 109 v8::MaybeLocal<v8::Value> JavaScriptCallFrame::restart() | |
| 110 { | |
| 111 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); | |
| 112 v8::Local<v8::Object> callFrame = v8::Local<v8::Object>::New(m_isolate, m_ca
llFrame); | |
| 113 v8::Local<v8::Function> restartFunction = v8::Local<v8::Function>::Cast(call
Frame->Get(toV8StringInternalized(m_isolate, "restart"))); | |
| 114 v8::Debug::SetLiveEditEnabled(m_isolate, true); | |
| 115 v8::MaybeLocal<v8::Value> result = restartFunction->Call(m_debuggerContext.G
et(m_isolate), callFrame, 0, nullptr); | |
| 116 v8::Debug::SetLiveEditEnabled(m_isolate, false); | |
| 117 return result; | |
| 118 } | |
| 119 | |
| 120 v8::MaybeLocal<v8::Value> JavaScriptCallFrame::setVariableValue(int scopeNumber,
v8::Local<v8::Value> variableName, v8::Local<v8::Value> newValue) | |
| 121 { | |
| 122 v8::MicrotasksScope microtasks(m_isolate, v8::MicrotasksScope::kDoNotRunMicr
otasks); | |
| 123 v8::Local<v8::Object> callFrame = v8::Local<v8::Object>::New(m_isolate, m_ca
llFrame); | |
| 124 v8::Local<v8::Function> setVariableValueFunction = v8::Local<v8::Function>::
Cast(callFrame->Get(toV8StringInternalized(m_isolate, "setVariableValue"))); | |
| 125 v8::Local<v8::Value> argv[] = { | |
| 126 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)), | |
| 127 variableName, | |
| 128 newValue | |
| 129 }; | |
| 130 return setVariableValueFunction->Call(m_debuggerContext.Get(m_isolate), call
Frame, V8_INSPECTOR_ARRAY_LENGTH(argv), argv); | |
| 131 } | |
| 132 | |
| 133 } // namespace v8_inspector | |
| OLD | NEW |