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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp

Issue 2199943004: [DevTools] Rename V8Debugger to V8Inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" 31 #include "platform/v8_inspector/V8RuntimeAgentImpl.h"
32 32
33 #include "platform/inspector_protocol/Values.h" 33 #include "platform/inspector_protocol/Values.h"
34 #include "platform/v8_inspector/InjectedScript.h" 34 #include "platform/v8_inspector/InjectedScript.h"
35 #include "platform/v8_inspector/InspectedContext.h" 35 #include "platform/v8_inspector/InspectedContext.h"
36 #include "platform/v8_inspector/RemoteObjectId.h" 36 #include "platform/v8_inspector/RemoteObjectId.h"
37 #include "platform/v8_inspector/V8ConsoleMessage.h" 37 #include "platform/v8_inspector/V8ConsoleMessage.h"
38 #include "platform/v8_inspector/V8DebuggerImpl.h" 38 #include "platform/v8_inspector/V8InspectorImpl.h"
39 #include "platform/v8_inspector/V8InspectorSessionImpl.h" 39 #include "platform/v8_inspector/V8InspectorSessionImpl.h"
40 #include "platform/v8_inspector/V8StackTraceImpl.h" 40 #include "platform/v8_inspector/V8StackTraceImpl.h"
41 #include "platform/v8_inspector/V8StringUtil.h" 41 #include "platform/v8_inspector/V8StringUtil.h"
42 #include "platform/v8_inspector/public/V8DebuggerClient.h" 42 #include "platform/v8_inspector/public/V8InspectorClient.h"
43 43
44 namespace blink { 44 namespace blink {
45 45
46 namespace V8RuntimeAgentImplState { 46 namespace V8RuntimeAgentImplState {
47 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled "; 47 static const char customObjectFormatterEnabled[] = "customObjectFormatterEnabled ";
48 static const char runtimeEnabled[] = "runtimeEnabled"; 48 static const char runtimeEnabled[] = "runtimeEnabled";
49 }; 49 };
50 50
51 using protocol::Runtime::ExceptionDetails; 51 using protocol::Runtime::ExceptionDetails;
52 using protocol::Runtime::RemoteObject; 52 using protocol::Runtime::RemoteObject;
53 53
54 static bool hasInternalError(ErrorString* errorString, bool hasError) 54 static bool hasInternalError(ErrorString* errorString, bool hasError)
55 { 55 {
56 if (hasError) 56 if (hasError)
57 *errorString = "Internal error"; 57 *errorString = "Internal error";
58 return hasError; 58 return hasError;
59 } 59 }
60 60
61 namespace { 61 namespace {
62 62
63 template<typename Callback> 63 template<typename Callback>
64 class ProtocolPromiseHandler { 64 class ProtocolPromiseHandler {
65 public: 65 public:
66 static void add(V8DebuggerImpl* debugger, int contextGroupId, const String16 & promiseObjectId, std::unique_ptr<Callback> callback, bool returnByValue, bool generatePreview) 66 static void add(V8InspectorImpl* inspector, int contextGroupId, const String 16& promiseObjectId, std::unique_ptr<Callback> callback, bool returnByValue, boo l generatePreview)
67 { 67 {
68 ErrorString errorString; 68 ErrorString errorString;
69 InjectedScript::ObjectScope scope(&errorString, debugger, contextGroupId , promiseObjectId); 69 InjectedScript::ObjectScope scope(&errorString, inspector, contextGroupI d, promiseObjectId);
70 if (!scope.initialize()) { 70 if (!scope.initialize()) {
71 callback->sendFailure(errorString); 71 callback->sendFailure(errorString);
72 return; 72 return;
73 } 73 }
74 if (!scope.object()->IsPromise()) { 74 if (!scope.object()->IsPromise()) {
75 callback->sendFailure("Could not find promise with given id"); 75 callback->sendFailure("Could not find promise with given id");
76 return; 76 return;
77 } 77 }
78 78
79 Callback* rawCallback = callback.get(); 79 Callback* rawCallback = callback.get();
80 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler(d ebugger, contextGroupId, promiseObjectId, std::move(callback), returnByValue, ge neratePreview); 80 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler(i nspector, contextGroupId, promiseObjectId, std::move(callback), returnByValue, g eneratePreview);
81 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(debugger->isolate( )); 81 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(inspector->isolate ());
82 v8::Local<v8::Promise> promise = v8::Local<v8::Promise>::Cast(scope.obje ct()); 82 v8::Local<v8::Promise> promise = v8::Local<v8::Promise>::Cast(scope.obje ct());
83 83
84 v8::Local<v8::Function> thenCallbackFunction = v8::Function::New(scope.c ontext(), thenCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalChec ked(); 84 v8::Local<v8::Function> thenCallbackFunction = v8::Function::New(scope.c ontext(), thenCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalChec ked();
85 if (promise->Then(scope.context(), thenCallbackFunction).IsEmpty()) { 85 if (promise->Then(scope.context(), thenCallbackFunction).IsEmpty()) {
86 rawCallback->sendFailure("Internal error"); 86 rawCallback->sendFailure("Internal error");
87 return; 87 return;
88 } 88 }
89 v8::Local<v8::Function> catchCallbackFunction = v8::Function::New(scope. context(), catchCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalCh ecked(); 89 v8::Local<v8::Function> catchCallbackFunction = v8::Function::New(scope. context(), catchCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalCh ecked();
90 if (promise->Catch(scope.context(), catchCallbackFunction).IsEmpty()) { 90 if (promise->Catch(scope.context(), catchCallbackFunction).IsEmpty()) {
91 rawCallback->sendFailure("Internal error"); 91 rawCallback->sendFailure("Internal error");
(...skipping 10 matching lines...) Expand all
102 handler->m_callback->sendSuccess(handler->wrapObject(value), Maybe<bool> (), Maybe<protocol::Runtime::ExceptionDetails>()); 102 handler->m_callback->sendSuccess(handler->wrapObject(value), Maybe<bool> (), Maybe<protocol::Runtime::ExceptionDetails>());
103 } 103 }
104 104
105 static void catchCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 105 static void catchCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
106 { 106 {
107 ProtocolPromiseHandler<Callback>* handler = static_cast<ProtocolPromiseH andler<Callback>*>(info.Data().As<v8::External>()->Value()); 107 ProtocolPromiseHandler<Callback>* handler = static_cast<ProtocolPromiseH andler<Callback>*>(info.Data().As<v8::External>()->Value());
108 DCHECK(handler); 108 DCHECK(handler);
109 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8: :Value>::Cast(v8::Undefined(info.GetIsolate())); 109 v8::Local<v8::Value> value = info.Length() > 0 ? info[0] : v8::Local<v8: :Value>::Cast(v8::Undefined(info.GetIsolate()));
110 110
111 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails; 111 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetails;
112 std::unique_ptr<V8StackTraceImpl> stack = handler->m_debugger->captureSt ackTraceImpl(true); 112 std::unique_ptr<V8StackTraceImpl> stack = handler->m_inspector->captureS tackTraceImpl(true);
113 if (stack) { 113 if (stack) {
114 exceptionDetails = protocol::Runtime::ExceptionDetails::create() 114 exceptionDetails = protocol::Runtime::ExceptionDetails::create()
115 .setText("Promise was rejected") 115 .setText("Promise was rejected")
116 .setLineNumber(!stack->isEmpty() ? stack->topLineNumber() : 0) 116 .setLineNumber(!stack->isEmpty() ? stack->topLineNumber() : 0)
117 .setColumnNumber(!stack->isEmpty() ? stack->topColumnNumber() : 0) 117 .setColumnNumber(!stack->isEmpty() ? stack->topColumnNumber() : 0)
118 .setScriptId(!stack->isEmpty() ? stack->topScriptId() : String16 ()) 118 .setScriptId(!stack->isEmpty() ? stack->topScriptId() : String16 ())
119 .setStackTrace(stack->buildInspectorObjectImpl()) 119 .setStackTrace(stack->buildInspectorObjectImpl())
120 .build(); 120 .build();
121 } 121 }
122 handler->m_callback->sendSuccess(handler->wrapObject(value), true, std:: move(exceptionDetails)); 122 handler->m_callback->sendSuccess(handler->wrapObject(value), true, std:: move(exceptionDetails));
123 } 123 }
124 124
125 ProtocolPromiseHandler(V8DebuggerImpl* debugger, int contextGroupId, const S tring16& promiseObjectId, std::unique_ptr<Callback> callback, bool returnByValue , bool generatePreview) 125 ProtocolPromiseHandler(V8InspectorImpl* inspector, int contextGroupId, const String16& promiseObjectId, std::unique_ptr<Callback> callback, bool returnByVal ue, bool generatePreview)
126 : m_debugger(debugger) 126 : m_inspector(inspector)
127 , m_contextGroupId(contextGroupId) 127 , m_contextGroupId(contextGroupId)
128 , m_promiseObjectId(promiseObjectId) 128 , m_promiseObjectId(promiseObjectId)
129 , m_callback(std::move(callback)) 129 , m_callback(std::move(callback))
130 , m_returnByValue(returnByValue) 130 , m_returnByValue(returnByValue)
131 , m_generatePreview(generatePreview) 131 , m_generatePreview(generatePreview)
132 , m_wrapper(debugger->isolate(), v8::External::New(debugger->isolate(), this)) 132 , m_wrapper(inspector->isolate(), v8::External::New(inspector->isolate() , this))
133 { 133 {
134 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter); 134 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter);
135 } 135 }
136 136
137 static void cleanup(const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callba ck>>& data) 137 static void cleanup(const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callba ck>>& data)
138 { 138 {
139 if (!data.GetParameter()->m_wrapper.IsEmpty()) { 139 if (!data.GetParameter()->m_wrapper.IsEmpty()) {
140 data.GetParameter()->m_wrapper.Reset(); 140 data.GetParameter()->m_wrapper.Reset();
141 data.SetSecondPassCallback(cleanup); 141 data.SetSecondPassCallback(cleanup);
142 } else { 142 } else {
143 data.GetParameter()->m_callback->sendFailure("Promise was collected" ); 143 data.GetParameter()->m_callback->sendFailure("Promise was collected" );
144 delete data.GetParameter(); 144 delete data.GetParameter();
145 } 145 }
146 } 146 }
147 147
148 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(v8::Local<v8::Va lue> value) 148 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(v8::Local<v8::Va lue> value)
149 { 149 {
150 ErrorString errorString; 150 ErrorString errorString;
151 InjectedScript::ObjectScope scope(&errorString, m_debugger, m_contextGro upId, m_promiseObjectId); 151 InjectedScript::ObjectScope scope(&errorString, m_inspector, m_contextGr oupId, m_promiseObjectId);
152 if (!scope.initialize()) { 152 if (!scope.initialize()) {
153 m_callback->sendFailure(errorString); 153 m_callback->sendFailure(errorString);
154 return nullptr; 154 return nullptr;
155 } 155 }
156 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue = scope.in jectedScript()->wrapObject(&errorString, value, scope.objectGroupName(), m_retur nByValue, m_generatePreview); 156 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue = scope.in jectedScript()->wrapObject(&errorString, value, scope.objectGroupName(), m_retur nByValue, m_generatePreview);
157 if (!wrappedValue) { 157 if (!wrappedValue) {
158 m_callback->sendFailure(errorString); 158 m_callback->sendFailure(errorString);
159 return nullptr; 159 return nullptr;
160 } 160 }
161 return wrappedValue; 161 return wrappedValue;
162 } 162 }
163 163
164 V8DebuggerImpl* m_debugger; 164 V8InspectorImpl* m_inspector;
165 int m_contextGroupId; 165 int m_contextGroupId;
166 String16 m_promiseObjectId; 166 String16 m_promiseObjectId;
167 std::unique_ptr<Callback> m_callback; 167 std::unique_ptr<Callback> m_callback;
168 bool m_returnByValue; 168 bool m_returnByValue;
169 bool m_generatePreview; 169 bool m_generatePreview;
170 v8::Global<v8::External> m_wrapper; 170 v8::Global<v8::External> m_wrapper;
171 }; 171 };
172 172
173 } // namespace 173 } // namespace
174 174
175 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8InspectorSessionImpl* session, protocol ::FrontendChannel* FrontendChannel, protocol::DictionaryValue* state) 175 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8InspectorSessionImpl* session, protocol ::FrontendChannel* FrontendChannel, protocol::DictionaryValue* state)
176 : m_session(session) 176 : m_session(session)
177 , m_state(state) 177 , m_state(state)
178 , m_frontend(FrontendChannel) 178 , m_frontend(FrontendChannel)
179 , m_debugger(session->debugger()) 179 , m_inspector(session->inspector())
180 , m_enabled(false) 180 , m_enabled(false)
181 { 181 {
182 } 182 }
183 183
184 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() 184 V8RuntimeAgentImpl::~V8RuntimeAgentImpl()
185 { 185 {
186 } 186 }
187 187
188 void V8RuntimeAgentImpl::evaluate( 188 void V8RuntimeAgentImpl::evaluate(
189 ErrorString* errorString, 189 ErrorString* errorString,
190 const String16& expression, 190 const String16& expression,
191 const Maybe<String16>& objectGroup, 191 const Maybe<String16>& objectGroup,
192 const Maybe<bool>& includeCommandLineAPI, 192 const Maybe<bool>& includeCommandLineAPI,
193 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 193 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
194 const Maybe<int>& executionContextId, 194 const Maybe<int>& executionContextId,
195 const Maybe<bool>& returnByValue, 195 const Maybe<bool>& returnByValue,
196 const Maybe<bool>& generatePreview, 196 const Maybe<bool>& generatePreview,
197 const Maybe<bool>& userGesture, 197 const Maybe<bool>& userGesture,
198 const Maybe<bool>& awaitPromise, 198 const Maybe<bool>& awaitPromise,
199 std::unique_ptr<EvaluateCallback> callback) 199 std::unique_ptr<EvaluateCallback> callback)
200 { 200 {
201 int contextId; 201 int contextId;
202 if (executionContextId.isJust()) { 202 if (executionContextId.isJust()) {
203 contextId = executionContextId.fromJust(); 203 contextId = executionContextId.fromJust();
204 } else { 204 } else {
205 v8::HandleScope handles(m_debugger->isolate()); 205 v8::HandleScope handles(m_inspector->isolate());
206 v8::Local<v8::Context> defaultContext = m_debugger->client()->ensureDefa ultContextInGroup(m_session->contextGroupId()); 206 v8::Local<v8::Context> defaultContext = m_inspector->client()->ensureDef aultContextInGroup(m_session->contextGroupId());
207 if (defaultContext.IsEmpty()) { 207 if (defaultContext.IsEmpty()) {
208 callback->sendFailure("Cannot find default execution context"); 208 callback->sendFailure("Cannot find default execution context");
209 return; 209 return;
210 } 210 }
211 contextId = V8DebuggerImpl::contextId(defaultContext); 211 contextId = V8InspectorImpl::contextId(defaultContext);
212 } 212 }
213 213
214 InjectedScript::ContextScope scope(errorString, m_debugger, m_session->conte xtGroupId(), contextId); 214 InjectedScript::ContextScope scope(errorString, m_inspector, m_session->cont extGroupId(), contextId);
215 if (!scope.initialize()) { 215 if (!scope.initialize()) {
216 callback->sendFailure(*errorString); 216 callback->sendFailure(*errorString);
217 return; 217 return;
218 } 218 }
219 219
220 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) 220 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false))
221 scope.ignoreExceptionsAndMuteConsole(); 221 scope.ignoreExceptionsAndMuteConsole();
222 if (userGesture.fromMaybe(false)) 222 if (userGesture.fromMaybe(false))
223 scope.pretendUserGesture(); 223 scope.pretendUserGesture();
224 224
225 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI() ) { 225 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI() ) {
226 callback->sendFailure(*errorString); 226 callback->sendFailure(*errorString);
227 return; 227 return;
228 } 228 }
229 229
230 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed() ; 230 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed() ;
231 // Temporarily enable allow evals for inspector. 231 // Temporarily enable allow evals for inspector.
232 if (evalIsDisabled) 232 if (evalIsDisabled)
233 scope.context()->AllowCodeGenerationFromStrings(true); 233 scope.context()->AllowCodeGenerationFromStrings(true);
234 234
235 v8::MaybeLocal<v8::Value> maybeResultValue; 235 v8::MaybeLocal<v8::Value> maybeResultValue;
236 v8::Local<v8::Script> script = m_debugger->compileScript(scope.context(), to V8String(m_debugger->isolate(), expression), String16(), false); 236 v8::Local<v8::Script> script = m_inspector->compileScript(scope.context(), t oV8String(m_inspector->isolate(), expression), String16(), false);
237 if (!script.IsEmpty()) 237 if (!script.IsEmpty())
238 maybeResultValue = m_debugger->runCompiledScript(scope.context(), script ); 238 maybeResultValue = m_inspector->runCompiledScript(scope.context(), scrip t);
239 239
240 if (evalIsDisabled) 240 if (evalIsDisabled)
241 scope.context()->AllowCodeGenerationFromStrings(false); 241 scope.context()->AllowCodeGenerationFromStrings(false);
242 242
243 // Re-initialize after running client's code, as it could have destroyed con text or session. 243 // Re-initialize after running client's code, as it could have destroyed con text or session.
244 if (!scope.initialize()) { 244 if (!scope.initialize()) {
245 callback->sendFailure(*errorString); 245 callback->sendFailure(*errorString);
246 return; 246 return;
247 } 247 }
248 248
(...skipping 23 matching lines...) Expand all
272 if (maybeResultValue.IsEmpty()) { 272 if (maybeResultValue.IsEmpty()) {
273 callback->sendFailure("Internal error"); 273 callback->sendFailure("Internal error");
274 return; 274 return;
275 } 275 }
276 276
277 if (!maybeResultValue.ToLocalChecked()->IsPromise()) { 277 if (!maybeResultValue.ToLocalChecked()->IsPromise()) {
278 callback->sendFailure("Result of expression is not a promise."); 278 callback->sendFailure("Result of expression is not a promise.");
279 return; 279 return;
280 } 280 }
281 281
282 ProtocolPromiseHandler<EvaluateCallback>::add(m_debugger, m_session->context GroupId(), result->getObjectId(String16()), std::move(callback), returnByValue.f romMaybe(false), generatePreview.fromMaybe(false)); 282 ProtocolPromiseHandler<EvaluateCallback>::add(m_inspector, m_session->contex tGroupId(), result->getObjectId(String16()), std::move(callback), returnByValue. fromMaybe(false), generatePreview.fromMaybe(false));
283 } 283 }
284 284
285 void V8RuntimeAgentImpl::awaitPromise(ErrorString* errorString, 285 void V8RuntimeAgentImpl::awaitPromise(ErrorString* errorString,
286 const String16& promiseObjectId, 286 const String16& promiseObjectId,
287 const Maybe<bool>& returnByValue, 287 const Maybe<bool>& returnByValue,
288 const Maybe<bool>& generatePreview, 288 const Maybe<bool>& generatePreview,
289 std::unique_ptr<AwaitPromiseCallback> callback) 289 std::unique_ptr<AwaitPromiseCallback> callback)
290 { 290 {
291 ProtocolPromiseHandler<AwaitPromiseCallback>::add(m_debugger, m_session->con textGroupId(), promiseObjectId, std::move(callback), returnByValue.fromMaybe(fal se), generatePreview.fromMaybe(false)); 291 ProtocolPromiseHandler<AwaitPromiseCallback>::add(m_inspector, m_session->co ntextGroupId(), promiseObjectId, std::move(callback), returnByValue.fromMaybe(fa lse), generatePreview.fromMaybe(false));
292 } 292 }
293 293
294 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, 294 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString,
295 const String16& objectId, 295 const String16& objectId,
296 const String16& expression, 296 const String16& expression,
297 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents, 297 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum ents,
298 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 298 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
299 const Maybe<bool>& returnByValue, 299 const Maybe<bool>& returnByValue,
300 const Maybe<bool>& generatePreview, 300 const Maybe<bool>& generatePreview,
301 const Maybe<bool>& userGesture, 301 const Maybe<bool>& userGesture,
302 std::unique_ptr<RemoteObject>* result, 302 std::unique_ptr<RemoteObject>* result,
303 Maybe<bool>* wasThrown) 303 Maybe<bool>* wasThrown)
304 { 304 {
305 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex tGroupId(), objectId); 305 InjectedScript::ObjectScope scope(errorString, m_inspector, m_session->conte xtGroupId(), objectId);
306 if (!scope.initialize()) 306 if (!scope.initialize())
307 return; 307 return;
308 308
309 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr; 309 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr;
310 int argc = 0; 310 int argc = 0;
311 if (optionalArguments.isJust()) { 311 if (optionalArguments.isJust()) {
312 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr guments.fromJust(); 312 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr guments.fromJust();
313 argc = arguments->length(); 313 argc = arguments->length();
314 argv.reset(new v8::Local<v8::Value>[argc]); 314 argv.reset(new v8::Local<v8::Value>[argc]);
315 for (int i = 0; i < argc; ++i) { 315 for (int i = 0; i < argc; ++i) {
316 v8::Local<v8::Value> argumentValue; 316 v8::Local<v8::Value> argumentValue;
317 if (!scope.injectedScript()->resolveCallArgument(errorString, argume nts->get(i)).ToLocal(&argumentValue)) 317 if (!scope.injectedScript()->resolveCallArgument(errorString, argume nts->get(i)).ToLocal(&argumentValue))
318 return; 318 return;
319 argv[i] = argumentValue; 319 argv[i] = argumentValue;
320 } 320 }
321 } 321 }
322 322
323 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) 323 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false))
324 scope.ignoreExceptionsAndMuteConsole(); 324 scope.ignoreExceptionsAndMuteConsole();
325 if (userGesture.fromMaybe(false)) 325 if (userGesture.fromMaybe(false))
326 scope.pretendUserGesture(); 326 scope.pretendUserGesture();
327 327
328 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_debugger->compileAndRunInte rnalScript(scope.context(), toV8String(m_debugger->isolate(), "(" + expression + ")")); 328 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_inspector->compileAndRunInt ernalScript(scope.context(), toV8String(m_inspector->isolate(), "(" + expression + ")"));
329 // Re-initialize after running client's code, as it could have destroyed con text or session. 329 // Re-initialize after running client's code, as it could have destroyed con text or session.
330 if (!scope.initialize()) 330 if (!scope.initialize())
331 return; 331 return;
332 332
333 if (scope.tryCatch().HasCaught()) { 333 if (scope.tryCatch().HasCaught()) {
334 scope.injectedScript()->wrapEvaluateResult(errorString, maybeFunctionVal ue, scope.tryCatch(), scope.objectGroupName(), false, false, result, wasThrown, nullptr); 334 scope.injectedScript()->wrapEvaluateResult(errorString, maybeFunctionVal ue, scope.tryCatch(), scope.objectGroupName(), false, false, result, wasThrown, nullptr);
335 return; 335 return;
336 } 336 }
337 337
338 v8::Local<v8::Value> functionValue; 338 v8::Local<v8::Value> functionValue;
339 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio n()) { 339 if (!maybeFunctionValue.ToLocal(&functionValue) || !functionValue->IsFunctio n()) {
340 *errorString = "Given expression does not evaluate to a function"; 340 *errorString = "Given expression does not evaluate to a function";
341 return; 341 return;
342 } 342 }
343 343
344 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->callFunction(functi onValue.As<v8::Function>(), scope.context(), scope.object(), argc, argv.get()); 344 v8::MaybeLocal<v8::Value> maybeResultValue = m_inspector->callFunction(funct ionValue.As<v8::Function>(), scope.context(), scope.object(), argc, argv.get());
345 // Re-initialize after running client's code, as it could have destroyed con text or session. 345 // Re-initialize after running client's code, as it could have destroyed con text or session.
346 if (!scope.initialize()) 346 if (!scope.initialize())
347 return; 347 return;
348 348
349 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc ope.tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generat ePreview.fromMaybe(false), result, wasThrown, nullptr); 349 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc ope.tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generat ePreview.fromMaybe(false), result, wasThrown, nullptr);
350 } 350 }
351 351
352 void V8RuntimeAgentImpl::getProperties( 352 void V8RuntimeAgentImpl::getProperties(
353 ErrorString* errorString, 353 ErrorString* errorString,
354 const String16& objectId, 354 const String16& objectId,
355 const Maybe<bool>& ownProperties, 355 const Maybe<bool>& ownProperties,
356 const Maybe<bool>& accessorPropertiesOnly, 356 const Maybe<bool>& accessorPropertiesOnly,
357 const Maybe<bool>& generatePreview, 357 const Maybe<bool>& generatePreview,
358 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* res ult, 358 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* res ult,
359 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties, 359 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter nalProperties,
360 Maybe<ExceptionDetails>* exceptionDetails) 360 Maybe<ExceptionDetails>* exceptionDetails)
361 { 361 {
362 using protocol::Runtime::InternalPropertyDescriptor; 362 using protocol::Runtime::InternalPropertyDescriptor;
363 363
364 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex tGroupId(), objectId); 364 InjectedScript::ObjectScope scope(errorString, m_inspector, m_session->conte xtGroupId(), objectId);
365 if (!scope.initialize()) 365 if (!scope.initialize())
366 return; 366 return;
367 367
368 scope.ignoreExceptionsAndMuteConsole(); 368 scope.ignoreExceptionsAndMuteConsole();
369 if (!scope.object()->IsObject()) { 369 if (!scope.object()->IsObject()) {
370 *errorString = "Value with given id is not an object"; 370 *errorString = "Value with given id is not an object";
371 return; 371 return;
372 } 372 }
373 373
374 v8::Local<v8::Object> object = scope.object().As<v8::Object>(); 374 v8::Local<v8::Object> object = scope.object().As<v8::Object>();
375 scope.injectedScript()->getProperties(errorString, object, scope.objectGroup Name(), ownProperties.fromMaybe(false), accessorPropertiesOnly.fromMaybe(false), generatePreview.fromMaybe(false), result, exceptionDetails); 375 scope.injectedScript()->getProperties(errorString, object, scope.objectGroup Name(), ownProperties.fromMaybe(false), accessorPropertiesOnly.fromMaybe(false), generatePreview.fromMaybe(false), result, exceptionDetails);
376 if (!errorString->isEmpty() || exceptionDetails->isJust() || accessorPropert iesOnly.fromMaybe(false)) 376 if (!errorString->isEmpty() || exceptionDetails->isJust() || accessorPropert iesOnly.fromMaybe(false))
377 return; 377 return;
378 v8::Local<v8::Array> propertiesArray; 378 v8::Local<v8::Array> propertiesArray;
379 if (hasInternalError(errorString, !m_debugger->internalProperties(scope.cont ext(), scope.object()).ToLocal(&propertiesArray))) 379 if (hasInternalError(errorString, !m_inspector->internalProperties(scope.con text(), scope.object()).ToLocal(&propertiesArray)))
380 return; 380 return;
381 std::unique_ptr<protocol::Array<InternalPropertyDescriptor>> propertiesProto colArray = protocol::Array<InternalPropertyDescriptor>::create(); 381 std::unique_ptr<protocol::Array<InternalPropertyDescriptor>> propertiesProto colArray = protocol::Array<InternalPropertyDescriptor>::create();
382 for (uint32_t i = 0; i < propertiesArray->Length(); i += 2) { 382 for (uint32_t i = 0; i < propertiesArray->Length(); i += 2) {
383 v8::Local<v8::Value> name; 383 v8::Local<v8::Value> name;
384 if (hasInternalError(errorString, !propertiesArray->Get(scope.context(), i).ToLocal(&name)) || !name->IsString()) 384 if (hasInternalError(errorString, !propertiesArray->Get(scope.context(), i).ToLocal(&name)) || !name->IsString())
385 return; 385 return;
386 v8::Local<v8::Value> value; 386 v8::Local<v8::Value> value;
387 if (hasInternalError(errorString, !propertiesArray->Get(scope.context(), i + 1).ToLocal(&value))) 387 if (hasInternalError(errorString, !propertiesArray->Get(scope.context(), i + 1).ToLocal(&value)))
388 return; 388 return;
389 std::unique_ptr<RemoteObject> wrappedValue = scope.injectedScript()->wra pObject(errorString, value, scope.objectGroupName()); 389 std::unique_ptr<RemoteObject> wrappedValue = scope.injectedScript()->wra pObject(errorString, value, scope.objectGroupName());
390 if (!wrappedValue) 390 if (!wrappedValue)
391 return; 391 return;
392 propertiesProtocolArray->addItem(InternalPropertyDescriptor::create() 392 propertiesProtocolArray->addItem(InternalPropertyDescriptor::create()
393 .setName(toProtocolString(name.As<v8::String>())) 393 .setName(toProtocolString(name.As<v8::String>()))
394 .setValue(std::move(wrappedValue)).build()); 394 .setValue(std::move(wrappedValue)).build());
395 } 395 }
396 if (!propertiesProtocolArray->length()) 396 if (!propertiesProtocolArray->length())
397 return; 397 return;
398 *internalProperties = std::move(propertiesProtocolArray); 398 *internalProperties = std::move(propertiesProtocolArray);
399 } 399 }
400 400
401 void V8RuntimeAgentImpl::releaseObject(ErrorString* errorString, const String16& objectId) 401 void V8RuntimeAgentImpl::releaseObject(ErrorString* errorString, const String16& objectId)
402 { 402 {
403 InjectedScript::ObjectScope scope(errorString, m_debugger, m_session->contex tGroupId(), objectId); 403 InjectedScript::ObjectScope scope(errorString, m_inspector, m_session->conte xtGroupId(), objectId);
404 if (!scope.initialize()) 404 if (!scope.initialize())
405 return; 405 return;
406 scope.injectedScript()->releaseObject(objectId); 406 scope.injectedScript()->releaseObject(objectId);
407 } 407 }
408 408
409 void V8RuntimeAgentImpl::releaseObjectGroup(ErrorString*, const String16& object Group) 409 void V8RuntimeAgentImpl::releaseObjectGroup(ErrorString*, const String16& object Group)
410 { 410 {
411 m_session->releaseObjectGroup(objectGroup); 411 m_session->releaseObjectGroup(objectGroup);
412 } 412 }
413 413
414 void V8RuntimeAgentImpl::run(ErrorString* errorString) 414 void V8RuntimeAgentImpl::run(ErrorString* errorString)
415 { 415 {
416 m_session->client()->resumeStartup(); 416 m_session->client()->resumeStartup();
417 } 417 }
418 418
419 void V8RuntimeAgentImpl::setCustomObjectFormatterEnabled(ErrorString*, bool enab led) 419 void V8RuntimeAgentImpl::setCustomObjectFormatterEnabled(ErrorString*, bool enab led)
420 { 420 {
421 m_state->setBoolean(V8RuntimeAgentImplState::customObjectFormatterEnabled, e nabled); 421 m_state->setBoolean(V8RuntimeAgentImplState::customObjectFormatterEnabled, e nabled);
422 m_session->setCustomObjectFormatterEnabled(enabled); 422 m_session->setCustomObjectFormatterEnabled(enabled);
423 } 423 }
424 424
425 void V8RuntimeAgentImpl::discardConsoleEntries(ErrorString*) 425 void V8RuntimeAgentImpl::discardConsoleEntries(ErrorString*)
426 { 426 {
427 V8ConsoleMessageStorage* storage = m_session->debugger()->ensureConsoleMessa geStorage(m_session->contextGroupId()); 427 V8ConsoleMessageStorage* storage = m_inspector->ensureConsoleMessageStorage( m_session->contextGroupId());
428 storage->clear(); 428 storage->clear();
429 } 429 }
430 430
431 void V8RuntimeAgentImpl::compileScript(ErrorString* errorString, 431 void V8RuntimeAgentImpl::compileScript(ErrorString* errorString,
432 const String16& expression, 432 const String16& expression,
433 const String16& sourceURL, 433 const String16& sourceURL,
434 bool persistScript, 434 bool persistScript,
435 int executionContextId, 435 int executionContextId,
436 Maybe<String16>* scriptId, 436 Maybe<String16>* scriptId,
437 Maybe<ExceptionDetails>* exceptionDetails) 437 Maybe<ExceptionDetails>* exceptionDetails)
438 { 438 {
439 if (!m_enabled) { 439 if (!m_enabled) {
440 *errorString = "Runtime agent is not enabled"; 440 *errorString = "Runtime agent is not enabled";
441 return; 441 return;
442 } 442 }
443 InjectedScript::ContextScope scope(errorString, m_debugger, m_session->conte xtGroupId(), executionContextId); 443 InjectedScript::ContextScope scope(errorString, m_inspector, m_session->cont extGroupId(), executionContextId);
444 if (!scope.initialize()) 444 if (!scope.initialize())
445 return; 445 return;
446 446
447 v8::Local<v8::Script> script = m_debugger->compileScript(scope.context(), to V8String(m_debugger->isolate(), expression), sourceURL, false); 447 v8::Local<v8::Script> script = m_inspector->compileScript(scope.context(), t oV8String(m_inspector->isolate(), expression), sourceURL, false);
448 if (script.IsEmpty()) { 448 if (script.IsEmpty()) {
449 v8::Local<v8::Message> message = scope.tryCatch().Message(); 449 v8::Local<v8::Message> message = scope.tryCatch().Message();
450 if (!message.IsEmpty()) 450 if (!message.IsEmpty())
451 *exceptionDetails = scope.injectedScript()->createExceptionDetails(m essage); 451 *exceptionDetails = scope.injectedScript()->createExceptionDetails(m essage);
452 else 452 else
453 *errorString = "Script compilation failed"; 453 *errorString = "Script compilation failed";
454 return; 454 return;
455 } 455 }
456 456
457 if (!persistScript) 457 if (!persistScript)
458 return; 458 return;
459 459
460 String16 scriptValueId = String16::fromInteger(script->GetUnboundScript()->G etId()); 460 String16 scriptValueId = String16::fromInteger(script->GetUnboundScript()->G etId());
461 std::unique_ptr<v8::Global<v8::Script>> global(new v8::Global<v8::Script>(m_ debugger->isolate(), script)); 461 std::unique_ptr<v8::Global<v8::Script>> global(new v8::Global<v8::Script>(m_ inspector->isolate(), script));
462 m_compiledScripts[scriptValueId] = std::move(global); 462 m_compiledScripts[scriptValueId] = std::move(global);
463 *scriptId = scriptValueId; 463 *scriptId = scriptValueId;
464 } 464 }
465 465
466 void V8RuntimeAgentImpl::runScript(ErrorString* errorString, 466 void V8RuntimeAgentImpl::runScript(ErrorString* errorString,
467 const String16& scriptId, 467 const String16& scriptId,
468 int executionContextId, 468 int executionContextId,
469 const Maybe<String16>& objectGroup, 469 const Maybe<String16>& objectGroup,
470 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, 470 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole,
471 const Maybe<bool>& includeCommandLineAPI, 471 const Maybe<bool>& includeCommandLineAPI,
472 std::unique_ptr<RemoteObject>* result, 472 std::unique_ptr<RemoteObject>* result,
473 Maybe<ExceptionDetails>* exceptionDetails) 473 Maybe<ExceptionDetails>* exceptionDetails)
474 { 474 {
475 if (!m_enabled) { 475 if (!m_enabled) {
476 *errorString = "Runtime agent is not enabled"; 476 *errorString = "Runtime agent is not enabled";
477 return; 477 return;
478 } 478 }
479 479
480 auto it = m_compiledScripts.find(scriptId); 480 auto it = m_compiledScripts.find(scriptId);
481 if (it == m_compiledScripts.end()) { 481 if (it == m_compiledScripts.end()) {
482 *errorString = "Script execution failed"; 482 *errorString = "Script execution failed";
483 return; 483 return;
484 } 484 }
485 485
486 InjectedScript::ContextScope scope(errorString, m_debugger, m_session->conte xtGroupId(), executionContextId); 486 InjectedScript::ContextScope scope(errorString, m_inspector, m_session->cont extGroupId(), executionContextId);
487 if (!scope.initialize()) 487 if (!scope.initialize())
488 return; 488 return;
489 489
490 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) 490 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false))
491 scope.ignoreExceptionsAndMuteConsole(); 491 scope.ignoreExceptionsAndMuteConsole();
492 492
493 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second ); 493 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second );
494 m_compiledScripts.erase(it); 494 m_compiledScripts.erase(it);
495 v8::Local<v8::Script> script = scriptWrapper->Get(m_debugger->isolate()); 495 v8::Local<v8::Script> script = scriptWrapper->Get(m_inspector->isolate());
496 if (script.IsEmpty()) { 496 if (script.IsEmpty()) {
497 *errorString = "Script execution failed"; 497 *errorString = "Script execution failed";
498 return; 498 return;
499 } 499 }
500 500
501 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI() ) 501 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI() )
502 return; 502 return;
503 503
504 v8::MaybeLocal<v8::Value> maybeResultValue = m_debugger->runCompiledScript(s cope.context(), script); 504 v8::MaybeLocal<v8::Value> maybeResultValue = m_inspector->runCompiledScript( scope.context(), script);
505 505
506 // Re-initialize after running client's code, as it could have destroyed con text or session. 506 // Re-initialize after running client's code, as it could have destroyed con text or session.
507 if (!scope.initialize()) 507 if (!scope.initialize())
508 return; 508 return;
509 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc ope.tryCatch(), objectGroup.fromMaybe(""), false, false, result, nullptr, except ionDetails); 509 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc ope.tryCatch(), objectGroup.fromMaybe(""), false, false, result, nullptr, except ionDetails);
510 } 510 }
511 511
512 void V8RuntimeAgentImpl::restore() 512 void V8RuntimeAgentImpl::restore()
513 { 513 {
514 if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false )) 514 if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false ))
515 return; 515 return;
516 m_frontend.executionContextsCleared(); 516 m_frontend.executionContextsCleared();
517 ErrorString error; 517 ErrorString error;
518 enable(&error); 518 enable(&error);
519 if (m_state->booleanProperty(V8RuntimeAgentImplState::customObjectFormatterE nabled, false)) 519 if (m_state->booleanProperty(V8RuntimeAgentImplState::customObjectFormatterE nabled, false))
520 m_session->setCustomObjectFormatterEnabled(true); 520 m_session->setCustomObjectFormatterEnabled(true);
521 } 521 }
522 522
523 void V8RuntimeAgentImpl::enable(ErrorString* errorString) 523 void V8RuntimeAgentImpl::enable(ErrorString* errorString)
524 { 524 {
525 if (m_enabled) 525 if (m_enabled)
526 return; 526 return;
527 m_debugger->client()->beginEnsureAllContextsInGroup(m_session->contextGroupI d()); 527 m_inspector->client()->beginEnsureAllContextsInGroup(m_session->contextGroup Id());
528 m_enabled = true; 528 m_enabled = true;
529 m_state->setBoolean(V8RuntimeAgentImplState::runtimeEnabled, true); 529 m_state->setBoolean(V8RuntimeAgentImplState::runtimeEnabled, true);
530 m_session->debugger()->enableStackCapturingIfNeeded(); 530 m_inspector->enableStackCapturingIfNeeded();
531 m_session->reportAllContexts(this); 531 m_session->reportAllContexts(this);
532 V8ConsoleMessageStorage* storage = m_session->debugger()->ensureConsoleMessa geStorage(m_session->contextGroupId()); 532 V8ConsoleMessageStorage* storage = m_inspector->ensureConsoleMessageStorage( m_session->contextGroupId());
533 for (const auto& message : storage->messages()) 533 for (const auto& message : storage->messages())
534 reportMessage(message.get(), false); 534 reportMessage(message.get(), false);
535 } 535 }
536 536
537 void V8RuntimeAgentImpl::disable(ErrorString* errorString) 537 void V8RuntimeAgentImpl::disable(ErrorString* errorString)
538 { 538 {
539 if (!m_enabled) 539 if (!m_enabled)
540 return; 540 return;
541 m_enabled = false; 541 m_enabled = false;
542 m_state->setBoolean(V8RuntimeAgentImplState::runtimeEnabled, false); 542 m_state->setBoolean(V8RuntimeAgentImplState::runtimeEnabled, false);
543 m_session->debugger()->disableStackCapturingIfNeeded(); 543 m_inspector->disableStackCapturingIfNeeded();
544 m_session->discardInjectedScripts(); 544 m_session->discardInjectedScripts();
545 reset(); 545 reset();
546 m_debugger->client()->endEnsureAllContextsInGroup(m_session->contextGroupId( )); 546 m_inspector->client()->endEnsureAllContextsInGroup(m_session->contextGroupId ());
547 } 547 }
548 548
549 void V8RuntimeAgentImpl::reset() 549 void V8RuntimeAgentImpl::reset()
550 { 550 {
551 m_compiledScripts.clear(); 551 m_compiledScripts.clear();
552 if (m_enabled) { 552 if (m_enabled) {
553 if (const V8DebuggerImpl::ContextByIdMap* contexts = m_debugger->context Group(m_session->contextGroupId())) { 553 if (const V8InspectorImpl::ContextByIdMap* contexts = m_inspector->conte xtGroup(m_session->contextGroupId())) {
554 for (auto& idContext : *contexts) 554 for (auto& idContext : *contexts)
555 idContext.second->setReported(false); 555 idContext.second->setReported(false);
556 } 556 }
557 m_frontend.executionContextsCleared(); 557 m_frontend.executionContextsCleared();
558 } 558 }
559 } 559 }
560 560
561 void V8RuntimeAgentImpl::reportExecutionContextCreated(InspectedContext* context ) 561 void V8RuntimeAgentImpl::reportExecutionContextCreated(InspectedContext* context )
562 { 562 {
563 if (!m_enabled) 563 if (!m_enabled)
(...skipping 28 matching lines...) Expand all
592 reportMessage(message, true); 592 reportMessage(message, true);
593 } 593 }
594 594
595 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP review) 595 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP review)
596 { 596 {
597 message->reportToFrontend(&m_frontend, m_session, generatePreview); 597 message->reportToFrontend(&m_frontend, m_session, generatePreview);
598 m_frontend.flush(); 598 m_frontend.flush();
599 } 599 }
600 600
601 } // namespace blink 601 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698