Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: src/inspector/JavaScriptCallFrame.cpp

Issue 2292573002: [inspector] Initial import of v8_inspector. (Closed)
Patch Set: format the code, disable cpplint Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/inspector/JavaScriptCallFrame.h ('k') | src/inspector/ProtocolPlatform.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "src/inspector/JavaScriptCallFrame.h"
32
33 #include "src/inspector/StringUtil.h"
34 #include "src/inspector/V8Compat.h"
35
36 #include <v8-debug.h>
37
38 namespace v8_inspector {
39
40 JavaScriptCallFrame::JavaScriptCallFrame(v8::Local<v8::Context> debuggerContext,
41 v8::Local<v8::Object> callFrame)
42 : m_isolate(debuggerContext->GetIsolate()),
43 m_debuggerContext(m_isolate, debuggerContext),
44 m_callFrame(m_isolate, callFrame) {}
45
46 JavaScriptCallFrame::~JavaScriptCallFrame() {}
47
48 int JavaScriptCallFrame::callV8FunctionReturnInt(const char* name) const {
49 v8::HandleScope handleScope(m_isolate);
50 v8::MicrotasksScope microtasks(m_isolate,
51 v8::MicrotasksScope::kDoNotRunMicrotasks);
52 v8::Local<v8::Context> context =
53 v8::Local<v8::Context>::New(m_isolate, m_debuggerContext);
54 v8::Local<v8::Object> callFrame =
55 v8::Local<v8::Object>::New(m_isolate, m_callFrame);
56 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(
57 callFrame->Get(toV8StringInternalized(m_isolate, name)));
58 v8::Local<v8::Value> result;
59 if (!func->Call(context, callFrame, 0, nullptr).ToLocal(&result) ||
60 !result->IsInt32())
61 return 0;
62 return result.As<v8::Int32>()->Value();
63 }
64
65 int JavaScriptCallFrame::sourceID() const {
66 return callV8FunctionReturnInt("sourceID");
67 }
68
69 int JavaScriptCallFrame::line() const {
70 return callV8FunctionReturnInt("line");
71 }
72
73 int JavaScriptCallFrame::column() const {
74 return callV8FunctionReturnInt("column");
75 }
76
77 int JavaScriptCallFrame::contextId() const {
78 return callV8FunctionReturnInt("contextId");
79 }
80
81 bool JavaScriptCallFrame::isAtReturn() const {
82 v8::HandleScope handleScope(m_isolate);
83 v8::Local<v8::Value> result =
84 v8::Local<v8::Object>::New(m_isolate, m_callFrame)
85 ->Get(toV8StringInternalized(m_isolate, "isAtReturn"));
86 if (result.IsEmpty() || !result->IsBoolean()) return false;
87 return result->BooleanValue();
88 }
89
90 v8::Local<v8::Object> JavaScriptCallFrame::details() const {
91 v8::MicrotasksScope microtasks(m_isolate,
92 v8::MicrotasksScope::kDoNotRunMicrotasks);
93 v8::Local<v8::Object> callFrame =
94 v8::Local<v8::Object>::New(m_isolate, m_callFrame);
95 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(
96 callFrame->Get(toV8StringInternalized(m_isolate, "details")));
97 return v8::Local<v8::Object>::Cast(
98 func->Call(m_debuggerContext.Get(m_isolate), callFrame, 0, nullptr)
99 .ToLocalChecked());
100 }
101
102 v8::MaybeLocal<v8::Value> JavaScriptCallFrame::evaluate(
103 v8::Local<v8::Value> expression) {
104 v8::MicrotasksScope microtasks(m_isolate,
105 v8::MicrotasksScope::kRunMicrotasks);
106 v8::Local<v8::Object> callFrame =
107 v8::Local<v8::Object>::New(m_isolate, m_callFrame);
108 v8::Local<v8::Function> evalFunction = v8::Local<v8::Function>::Cast(
109 callFrame->Get(toV8StringInternalized(m_isolate, "evaluate")));
110 return evalFunction->Call(m_debuggerContext.Get(m_isolate), callFrame, 1,
111 &expression);
112 }
113
114 v8::MaybeLocal<v8::Value> JavaScriptCallFrame::restart() {
115 v8::MicrotasksScope microtasks(m_isolate,
116 v8::MicrotasksScope::kDoNotRunMicrotasks);
117 v8::Local<v8::Object> callFrame =
118 v8::Local<v8::Object>::New(m_isolate, m_callFrame);
119 v8::Local<v8::Function> restartFunction = v8::Local<v8::Function>::Cast(
120 callFrame->Get(toV8StringInternalized(m_isolate, "restart")));
121 v8::Debug::SetLiveEditEnabled(m_isolate, true);
122 v8::MaybeLocal<v8::Value> result = restartFunction->Call(
123 m_debuggerContext.Get(m_isolate), callFrame, 0, nullptr);
124 v8::Debug::SetLiveEditEnabled(m_isolate, false);
125 return result;
126 }
127
128 v8::MaybeLocal<v8::Value> JavaScriptCallFrame::setVariableValue(
129 int scopeNumber, v8::Local<v8::Value> variableName,
130 v8::Local<v8::Value> newValue) {
131 v8::MicrotasksScope microtasks(m_isolate,
132 v8::MicrotasksScope::kDoNotRunMicrotasks);
133 v8::Local<v8::Object> callFrame =
134 v8::Local<v8::Object>::New(m_isolate, m_callFrame);
135 v8::Local<v8::Function> setVariableValueFunction =
136 v8::Local<v8::Function>::Cast(callFrame->Get(
137 toV8StringInternalized(m_isolate, "setVariableValue")));
138 v8::Local<v8::Value> argv[] = {
139 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)),
140 variableName, newValue};
141 return setVariableValueFunction->Call(m_debuggerContext.Get(m_isolate),
142 callFrame,
143 V8_INSPECTOR_ARRAY_LENGTH(argv), argv);
144 }
145
146 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/JavaScriptCallFrame.h ('k') | src/inspector/ProtocolPlatform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698