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

Side by Side Diff: src/inspector/v8-runtime-agent-impl.cc

Issue 2467853003: [inspector] migrate Runtime to new style (Closed)
Patch Set: addressed comments Created 4 years, 1 month 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/v8-runtime-agent-impl.h ('k') | src/inspector/v8-value-copier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 namespace v8_inspector { 48 namespace v8_inspector {
49 49
50 namespace V8RuntimeAgentImplState { 50 namespace V8RuntimeAgentImplState {
51 static const char customObjectFormatterEnabled[] = 51 static const char customObjectFormatterEnabled[] =
52 "customObjectFormatterEnabled"; 52 "customObjectFormatterEnabled";
53 static const char runtimeEnabled[] = "runtimeEnabled"; 53 static const char runtimeEnabled[] = "runtimeEnabled";
54 }; 54 };
55 55
56 using protocol::Runtime::RemoteObject; 56 using protocol::Runtime::RemoteObject;
57 57
58 static bool hasInternalError(ErrorString* errorString, bool hasError) {
59 if (hasError) *errorString = "Internal error";
60 return hasError;
61 }
62
63 namespace { 58 namespace {
64 59
65 template <typename Callback> 60 template <typename Callback>
66 class ProtocolPromiseHandler { 61 class ProtocolPromiseHandler {
67 public: 62 public:
68 static void add(V8InspectorImpl* inspector, v8::Local<v8::Context> context, 63 static void add(V8InspectorImpl* inspector, v8::Local<v8::Context> context,
69 v8::MaybeLocal<v8::Value> value, 64 v8::MaybeLocal<v8::Value> value,
70 const String16& notPromiseError, int contextGroupId, 65 const String16& notPromiseError, int contextGroupId,
71 int executionContextId, const String16& objectGroup, 66 int executionContextId, const String16& objectGroup,
72 bool returnByValue, bool generatePreview, 67 bool returnByValue, bool generatePreview,
73 std::unique_ptr<Callback> callback) { 68 std::unique_ptr<Callback> callback) {
74 if (value.IsEmpty()) { 69 if (value.IsEmpty()) {
75 callback->sendFailure("Internal error"); 70 callback->sendFailure(Response::InternalError());
76 return; 71 return;
77 } 72 }
78 if (!value.ToLocalChecked()->IsPromise()) { 73 if (!value.ToLocalChecked()->IsPromise()) {
79 callback->sendFailure(notPromiseError); 74 callback->sendFailure(Response::Error(notPromiseError));
80 return; 75 return;
81 } 76 }
82 v8::MicrotasksScope microtasks_scope(inspector->isolate(), 77 v8::MicrotasksScope microtasks_scope(inspector->isolate(),
83 v8::MicrotasksScope::kRunMicrotasks); 78 v8::MicrotasksScope::kRunMicrotasks);
84 v8::Local<v8::Promise> promise = 79 v8::Local<v8::Promise> promise =
85 v8::Local<v8::Promise>::Cast(value.ToLocalChecked()); 80 v8::Local<v8::Promise>::Cast(value.ToLocalChecked());
86 Callback* rawCallback = callback.get(); 81 Callback* rawCallback = callback.get();
87 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler( 82 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler(
88 inspector, contextGroupId, executionContextId, objectGroup, 83 inspector, contextGroupId, executionContextId, objectGroup,
89 returnByValue, generatePreview, std::move(callback)); 84 returnByValue, generatePreview, std::move(callback));
90 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(inspector->isolate()); 85 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(inspector->isolate());
91 86
92 v8::Local<v8::Function> thenCallbackFunction = 87 v8::Local<v8::Function> thenCallbackFunction =
93 v8::Function::New(context, thenCallback, wrapper, 0, 88 v8::Function::New(context, thenCallback, wrapper, 0,
94 v8::ConstructorBehavior::kThrow) 89 v8::ConstructorBehavior::kThrow)
95 .ToLocalChecked(); 90 .ToLocalChecked();
96 if (promise->Then(context, thenCallbackFunction).IsEmpty()) { 91 if (promise->Then(context, thenCallbackFunction).IsEmpty()) {
97 rawCallback->sendFailure("Internal error"); 92 rawCallback->sendFailure(Response::InternalError());
98 return; 93 return;
99 } 94 }
100 v8::Local<v8::Function> catchCallbackFunction = 95 v8::Local<v8::Function> catchCallbackFunction =
101 v8::Function::New(context, catchCallback, wrapper, 0, 96 v8::Function::New(context, catchCallback, wrapper, 0,
102 v8::ConstructorBehavior::kThrow) 97 v8::ConstructorBehavior::kThrow)
103 .ToLocalChecked(); 98 .ToLocalChecked();
104 if (promise->Catch(context, catchCallbackFunction).IsEmpty()) { 99 if (promise->Catch(context, catchCallbackFunction).IsEmpty()) {
105 rawCallback->sendFailure("Internal error"); 100 rawCallback->sendFailure(Response::InternalError());
106 return; 101 return;
107 } 102 }
108 } 103 }
109 104
110 private: 105 private:
111 static void thenCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 106 static void thenCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
112 ProtocolPromiseHandler<Callback>* handler = 107 ProtocolPromiseHandler<Callback>* handler =
113 static_cast<ProtocolPromiseHandler<Callback>*>( 108 static_cast<ProtocolPromiseHandler<Callback>*>(
114 info.Data().As<v8::External>()->Value()); 109 info.Data().As<v8::External>()->Value());
115 DCHECK(handler); 110 DCHECK(handler);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 v8::External::New(inspector->isolate(), this)) { 168 v8::External::New(inspector->isolate(), this)) {
174 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter); 169 m_wrapper.SetWeak(this, cleanup, v8::WeakCallbackType::kParameter);
175 } 170 }
176 171
177 static void cleanup( 172 static void cleanup(
178 const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callback>>& data) { 173 const v8::WeakCallbackInfo<ProtocolPromiseHandler<Callback>>& data) {
179 if (!data.GetParameter()->m_wrapper.IsEmpty()) { 174 if (!data.GetParameter()->m_wrapper.IsEmpty()) {
180 data.GetParameter()->m_wrapper.Reset(); 175 data.GetParameter()->m_wrapper.Reset();
181 data.SetSecondPassCallback(cleanup); 176 data.SetSecondPassCallback(cleanup);
182 } else { 177 } else {
183 data.GetParameter()->m_callback->sendFailure("Promise was collected"); 178 data.GetParameter()->m_callback->sendFailure(
179 Response::Error("Promise was collected"));
184 delete data.GetParameter(); 180 delete data.GetParameter();
185 } 181 }
186 } 182 }
187 183
188 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject( 184 std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(
189 v8::Local<v8::Value> value) { 185 v8::Local<v8::Value> value) {
190 ErrorString errorString; 186 InjectedScript::ContextScope scope(m_inspector, m_contextGroupId,
191 InjectedScript::ContextScope scope(&errorString, m_inspector, 187 m_executionContextId);
192 m_contextGroupId, m_executionContextId); 188 Response response = scope.initialize();
193 if (!scope.initialize()) { 189 if (!response.isSuccess()) {
194 m_callback->sendFailure(errorString); 190 m_callback->sendFailure(response);
195 return nullptr; 191 return nullptr;
196 } 192 }
197 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue = 193 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedValue;
198 scope.injectedScript()->wrapObject(&errorString, value, m_objectGroup, 194 response = scope.injectedScript()->wrapObject(
199 m_returnByValue, m_generatePreview); 195 value, m_objectGroup, m_returnByValue, m_generatePreview,
200 if (!wrappedValue) { 196 &wrappedValue);
201 m_callback->sendFailure(errorString); 197 if (!response.isSuccess()) {
198 m_callback->sendFailure(response);
202 return nullptr; 199 return nullptr;
203 } 200 }
204 return wrappedValue; 201 return wrappedValue;
205 } 202 }
206 203
207 V8InspectorImpl* m_inspector; 204 V8InspectorImpl* m_inspector;
208 int m_contextGroupId; 205 int m_contextGroupId;
209 int m_executionContextId; 206 int m_executionContextId;
210 String16 m_objectGroup; 207 String16 m_objectGroup;
211 bool m_returnByValue; 208 bool m_returnByValue;
212 bool m_generatePreview; 209 bool m_generatePreview;
213 std::unique_ptr<Callback> m_callback; 210 std::unique_ptr<Callback> m_callback;
214 v8::Global<v8::External> m_wrapper; 211 v8::Global<v8::External> m_wrapper;
215 }; 212 };
216 213
217 template <typename Callback> 214 template <typename Callback>
218 bool wrapEvaluateResultAsync(InjectedScript* injectedScript, 215 bool wrapEvaluateResultAsync(InjectedScript* injectedScript,
219 v8::MaybeLocal<v8::Value> maybeResultValue, 216 v8::MaybeLocal<v8::Value> maybeResultValue,
220 const v8::TryCatch& tryCatch, 217 const v8::TryCatch& tryCatch,
221 const String16& objectGroup, bool returnByValue, 218 const String16& objectGroup, bool returnByValue,
222 bool generatePreview, Callback* callback) { 219 bool generatePreview, Callback* callback) {
223 std::unique_ptr<RemoteObject> result; 220 std::unique_ptr<RemoteObject> result;
224 Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails; 221 Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails;
225 222
226 ErrorString errorString; 223 Response response = injectedScript->wrapEvaluateResult(
227 injectedScript->wrapEvaluateResult( 224 maybeResultValue, tryCatch, objectGroup, returnByValue, generatePreview,
228 &errorString, maybeResultValue, tryCatch, objectGroup, returnByValue, 225 &result, &exceptionDetails);
229 generatePreview, &result, &exceptionDetails); 226 if (response.isSuccess()) {
230 if (errorString.isEmpty()) { 227 callback->sendSuccess(std::move(result), std::move(exceptionDetails));
231 callback->sendSuccess(std::move(result), exceptionDetails);
232 return true; 228 return true;
233 } 229 }
234 callback->sendFailure(errorString); 230 callback->sendFailure(response);
235 return false; 231 return false;
236 } 232 }
237 233
238 int ensureContext(ErrorString* errorString, V8InspectorImpl* inspector, 234 Response ensureContext(V8InspectorImpl* inspector, int contextGroupId,
239 int contextGroupId, const Maybe<int>& executionContextId) { 235 Maybe<int> executionContextId, int* contextId) {
240 int contextId;
241 if (executionContextId.isJust()) { 236 if (executionContextId.isJust()) {
242 contextId = executionContextId.fromJust(); 237 *contextId = executionContextId.fromJust();
243 } else { 238 } else {
244 v8::HandleScope handles(inspector->isolate()); 239 v8::HandleScope handles(inspector->isolate());
245 v8::Local<v8::Context> defaultContext = 240 v8::Local<v8::Context> defaultContext =
246 inspector->client()->ensureDefaultContextInGroup(contextGroupId); 241 inspector->client()->ensureDefaultContextInGroup(contextGroupId);
247 if (defaultContext.IsEmpty()) { 242 if (defaultContext.IsEmpty())
248 *errorString = "Cannot find default execution context"; 243 return Response::Error("Cannot find default execution context");
249 return 0; 244 *contextId = V8Debugger::contextId(defaultContext);
250 }
251 contextId = V8Debugger::contextId(defaultContext);
252 } 245 }
253 return contextId; 246 return Response::OK();
254 } 247 }
255 248
256 } // namespace 249 } // namespace
257 250
258 V8RuntimeAgentImpl::V8RuntimeAgentImpl( 251 V8RuntimeAgentImpl::V8RuntimeAgentImpl(
259 V8InspectorSessionImpl* session, protocol::FrontendChannel* FrontendChannel, 252 V8InspectorSessionImpl* session, protocol::FrontendChannel* FrontendChannel,
260 protocol::DictionaryValue* state) 253 protocol::DictionaryValue* state)
261 : m_session(session), 254 : m_session(session),
262 m_state(state), 255 m_state(state),
263 m_frontend(FrontendChannel), 256 m_frontend(FrontendChannel),
264 m_inspector(session->inspector()), 257 m_inspector(session->inspector()),
265 m_enabled(false) {} 258 m_enabled(false) {}
266 259
267 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() {} 260 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() {}
268 261
269 void V8RuntimeAgentImpl::evaluate( 262 void V8RuntimeAgentImpl::evaluate(
270 const String16& expression, const Maybe<String16>& objectGroup, 263 const String16& expression, Maybe<String16> objectGroup,
271 const Maybe<bool>& includeCommandLineAPI, const Maybe<bool>& silent, 264 Maybe<bool> includeCommandLineAPI, Maybe<bool> silent,
272 const Maybe<int>& executionContextId, const Maybe<bool>& returnByValue, 265 Maybe<int> executionContextId, Maybe<bool> returnByValue,
273 const Maybe<bool>& generatePreview, const Maybe<bool>& userGesture, 266 Maybe<bool> generatePreview, Maybe<bool> userGesture,
274 const Maybe<bool>& awaitPromise, 267 Maybe<bool> awaitPromise, std::unique_ptr<EvaluateCallback> callback) {
275 std::unique_ptr<EvaluateCallback> callback) {
276 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), 268 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
277 "EvaluateScript"); 269 "EvaluateScript");
278 ErrorString errorString; 270 int contextId = 0;
279 int contextId = 271 Response response = ensureContext(m_inspector, m_session->contextGroupId(),
280 ensureContext(&errorString, m_inspector, m_session->contextGroupId(), 272 std::move(executionContextId), &contextId);
281 executionContextId); 273 if (!response.isSuccess()) {
282 if (!errorString.isEmpty()) { 274 callback->sendFailure(response);
283 callback->sendFailure(errorString);
284 return; 275 return;
285 } 276 }
286 277
287 InjectedScript::ContextScope scope(&errorString, m_inspector, 278 InjectedScript::ContextScope scope(m_inspector, m_session->contextGroupId(),
288 m_session->contextGroupId(), contextId); 279 contextId);
289 if (!scope.initialize()) { 280 response = scope.initialize();
290 callback->sendFailure(errorString); 281 if (!response.isSuccess()) {
282 callback->sendFailure(response);
291 return; 283 return;
292 } 284 }
293 285
294 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole(); 286 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole();
295 if (userGesture.fromMaybe(false)) scope.pretendUserGesture(); 287 if (userGesture.fromMaybe(false)) scope.pretendUserGesture();
296 288
297 if (includeCommandLineAPI.fromMaybe(false) && 289 if (includeCommandLineAPI.fromMaybe(false)) scope.installCommandLineAPI();
298 !scope.installCommandLineAPI()) {
299 callback->sendFailure(errorString);
300 return;
301 }
302 290
303 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed(); 291 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed();
304 // Temporarily enable allow evals for inspector. 292 // Temporarily enable allow evals for inspector.
305 if (evalIsDisabled) scope.context()->AllowCodeGenerationFromStrings(true); 293 if (evalIsDisabled) scope.context()->AllowCodeGenerationFromStrings(true);
306 294
307 v8::MaybeLocal<v8::Value> maybeResultValue; 295 v8::MaybeLocal<v8::Value> maybeResultValue;
308 v8::Local<v8::Script> script = m_inspector->compileScript( 296 v8::Local<v8::Script> script = m_inspector->compileScript(
309 scope.context(), toV8String(m_inspector->isolate(), expression), 297 scope.context(), toV8String(m_inspector->isolate(), expression),
310 String16(), false); 298 String16(), false);
311 if (!script.IsEmpty()) 299 if (!script.IsEmpty())
312 maybeResultValue = m_inspector->runCompiledScript(scope.context(), script); 300 maybeResultValue = m_inspector->runCompiledScript(scope.context(), script);
313 301
314 if (evalIsDisabled) scope.context()->AllowCodeGenerationFromStrings(false); 302 if (evalIsDisabled) scope.context()->AllowCodeGenerationFromStrings(false);
315 303
316 // Re-initialize after running client's code, as it could have destroyed 304 // Re-initialize after running client's code, as it could have destroyed
317 // context or session. 305 // context or session.
318 if (!scope.initialize()) { 306 response = scope.initialize();
319 callback->sendFailure(errorString); 307 if (!response.isSuccess()) {
308 callback->sendFailure(response);
320 return; 309 return;
321 } 310 }
322 311
323 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { 312 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) {
324 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, 313 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue,
325 scope.tryCatch(), objectGroup.fromMaybe(""), 314 scope.tryCatch(), objectGroup.fromMaybe(""),
326 returnByValue.fromMaybe(false), 315 returnByValue.fromMaybe(false),
327 generatePreview.fromMaybe(false), callback.get()); 316 generatePreview.fromMaybe(false), callback.get());
328 return; 317 return;
329 } 318 }
330 ProtocolPromiseHandler<EvaluateCallback>::add( 319 ProtocolPromiseHandler<EvaluateCallback>::add(
331 m_inspector, scope.context(), maybeResultValue, 320 m_inspector, scope.context(), maybeResultValue,
332 "Result of the evaluation is not a promise", m_session->contextGroupId(), 321 "Result of the evaluation is not a promise", m_session->contextGroupId(),
333 scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""), 322 scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""),
334 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), 323 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false),
335 std::move(callback)); 324 std::move(callback));
336 } 325 }
337 326
338 void V8RuntimeAgentImpl::awaitPromise( 327 void V8RuntimeAgentImpl::awaitPromise(
339 const String16& promiseObjectId, const Maybe<bool>& returnByValue, 328 const String16& promiseObjectId, Maybe<bool> returnByValue,
340 const Maybe<bool>& generatePreview, 329 Maybe<bool> generatePreview,
341 std::unique_ptr<AwaitPromiseCallback> callback) { 330 std::unique_ptr<AwaitPromiseCallback> callback) {
342 ErrorString errorString; 331 InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(),
343 InjectedScript::ObjectScope scope( 332 promiseObjectId);
344 &errorString, m_inspector, m_session->contextGroupId(), promiseObjectId); 333 Response response = scope.initialize();
345 if (!scope.initialize()) { 334 if (!response.isSuccess()) {
346 callback->sendFailure(errorString); 335 callback->sendFailure(response);
347 return; 336 return;
348 } 337 }
349 ProtocolPromiseHandler<AwaitPromiseCallback>::add( 338 ProtocolPromiseHandler<AwaitPromiseCallback>::add(
350 m_inspector, scope.context(), scope.object(), 339 m_inspector, scope.context(), scope.object(),
351 "Could not find promise with given id", m_session->contextGroupId(), 340 "Could not find promise with given id", m_session->contextGroupId(),
352 scope.injectedScript()->context()->contextId(), scope.objectGroupName(), 341 scope.injectedScript()->context()->contextId(), scope.objectGroupName(),
353 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), 342 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false),
354 std::move(callback)); 343 std::move(callback));
355 } 344 }
356 345
357 void V8RuntimeAgentImpl::callFunctionOn( 346 void V8RuntimeAgentImpl::callFunctionOn(
358 const String16& objectId, const String16& expression, 347 const String16& objectId, const String16& expression,
359 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& 348 Maybe<protocol::Array<protocol::Runtime::CallArgument>> optionalArguments,
360 optionalArguments, 349 Maybe<bool> silent, Maybe<bool> returnByValue, Maybe<bool> generatePreview,
361 const Maybe<bool>& silent, const Maybe<bool>& returnByValue, 350 Maybe<bool> userGesture, Maybe<bool> awaitPromise,
362 const Maybe<bool>& generatePreview, const Maybe<bool>& userGesture,
363 const Maybe<bool>& awaitPromise,
364 std::unique_ptr<CallFunctionOnCallback> callback) { 351 std::unique_ptr<CallFunctionOnCallback> callback) {
365 ErrorString errorString; 352 InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(),
366 InjectedScript::ObjectScope scope(&errorString, m_inspector, 353 objectId);
367 m_session->contextGroupId(), objectId); 354 Response response = scope.initialize();
368 if (!scope.initialize()) { 355 if (!response.isSuccess()) {
369 callback->sendFailure(errorString); 356 callback->sendFailure(response);
370 return; 357 return;
371 } 358 }
372 359
373 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr; 360 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr;
374 int argc = 0; 361 int argc = 0;
375 if (optionalArguments.isJust()) { 362 if (optionalArguments.isJust()) {
376 protocol::Array<protocol::Runtime::CallArgument>* arguments = 363 protocol::Array<protocol::Runtime::CallArgument>* arguments =
377 optionalArguments.fromJust(); 364 optionalArguments.fromJust();
378 argc = static_cast<int>(arguments->length()); 365 argc = static_cast<int>(arguments->length());
379 argv.reset(new v8::Local<v8::Value>[argc]); 366 argv.reset(new v8::Local<v8::Value>[argc]);
380 for (int i = 0; i < argc; ++i) { 367 for (int i = 0; i < argc; ++i) {
381 v8::Local<v8::Value> argumentValue; 368 v8::Local<v8::Value> argumentValue;
382 if (!scope.injectedScript() 369 response = scope.injectedScript()->resolveCallArgument(arguments->get(i),
383 ->resolveCallArgument(&errorString, arguments->get(i)) 370 &argumentValue);
384 .ToLocal(&argumentValue)) { 371 if (!response.isSuccess()) {
385 callback->sendFailure(errorString); 372 callback->sendFailure(response);
386 return; 373 return;
387 } 374 }
388 argv[i] = argumentValue; 375 argv[i] = argumentValue;
389 } 376 }
390 } 377 }
391 378
392 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole(); 379 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole();
393 if (userGesture.fromMaybe(false)) scope.pretendUserGesture(); 380 if (userGesture.fromMaybe(false)) scope.pretendUserGesture();
394 381
395 v8::MaybeLocal<v8::Value> maybeFunctionValue = 382 v8::MaybeLocal<v8::Value> maybeFunctionValue =
396 m_inspector->compileAndRunInternalScript( 383 m_inspector->compileAndRunInternalScript(
397 scope.context(), 384 scope.context(),
398 toV8String(m_inspector->isolate(), "(" + expression + ")")); 385 toV8String(m_inspector->isolate(), "(" + expression + ")"));
399 // Re-initialize after running client's code, as it could have destroyed 386 // Re-initialize after running client's code, as it could have destroyed
400 // context or session. 387 // context or session.
401 if (!scope.initialize()) { 388 response = scope.initialize();
402 callback->sendFailure(errorString); 389 if (!response.isSuccess()) {
390 callback->sendFailure(response);
403 return; 391 return;
404 } 392 }
405 393
406 if (scope.tryCatch().HasCaught()) { 394 if (scope.tryCatch().HasCaught()) {
407 wrapEvaluateResultAsync(scope.injectedScript(), maybeFunctionValue, 395 wrapEvaluateResultAsync(scope.injectedScript(), maybeFunctionValue,
408 scope.tryCatch(), scope.objectGroupName(), false, 396 scope.tryCatch(), scope.objectGroupName(), false,
409 false, callback.get()); 397 false, callback.get());
410 return; 398 return;
411 } 399 }
412 400
413 v8::Local<v8::Value> functionValue; 401 v8::Local<v8::Value> functionValue;
414 if (!maybeFunctionValue.ToLocal(&functionValue) || 402 if (!maybeFunctionValue.ToLocal(&functionValue) ||
415 !functionValue->IsFunction()) { 403 !functionValue->IsFunction()) {
416 callback->sendFailure("Given expression does not evaluate to a function"); 404 callback->sendFailure(
405 Response::Error("Given expression does not evaluate to a function"));
417 return; 406 return;
418 } 407 }
419 408
420 v8::MaybeLocal<v8::Value> maybeResultValue = m_inspector->callFunction( 409 v8::MaybeLocal<v8::Value> maybeResultValue = m_inspector->callFunction(
421 functionValue.As<v8::Function>(), scope.context(), scope.object(), argc, 410 functionValue.As<v8::Function>(), scope.context(), scope.object(), argc,
422 argv.get()); 411 argv.get());
423 // Re-initialize after running client's code, as it could have destroyed 412 // Re-initialize after running client's code, as it could have destroyed
424 // context or session. 413 // context or session.
425 if (!scope.initialize()) { 414 response = scope.initialize();
426 callback->sendFailure(errorString); 415 if (!response.isSuccess()) {
416 callback->sendFailure(response);
427 return; 417 return;
428 } 418 }
429 419
430 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { 420 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) {
431 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, 421 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue,
432 scope.tryCatch(), scope.objectGroupName(), 422 scope.tryCatch(), scope.objectGroupName(),
433 returnByValue.fromMaybe(false), 423 returnByValue.fromMaybe(false),
434 generatePreview.fromMaybe(false), callback.get()); 424 generatePreview.fromMaybe(false), callback.get());
435 return; 425 return;
436 } 426 }
437 427
438 ProtocolPromiseHandler<CallFunctionOnCallback>::add( 428 ProtocolPromiseHandler<CallFunctionOnCallback>::add(
439 m_inspector, scope.context(), maybeResultValue, 429 m_inspector, scope.context(), maybeResultValue,
440 "Result of the function call is not a promise", 430 "Result of the function call is not a promise",
441 m_session->contextGroupId(), 431 m_session->contextGroupId(),
442 scope.injectedScript()->context()->contextId(), scope.objectGroupName(), 432 scope.injectedScript()->context()->contextId(), scope.objectGroupName(),
443 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), 433 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false),
444 std::move(callback)); 434 std::move(callback));
445 } 435 }
446 436
447 void V8RuntimeAgentImpl::getProperties( 437 Response V8RuntimeAgentImpl::getProperties(
448 ErrorString* errorString, const String16& objectId, 438 const String16& objectId, Maybe<bool> ownProperties,
449 const Maybe<bool>& ownProperties, const Maybe<bool>& accessorPropertiesOnly, 439 Maybe<bool> accessorPropertiesOnly, Maybe<bool> generatePreview,
450 const Maybe<bool>& generatePreview,
451 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* 440 std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>*
452 result, 441 result,
453 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* 442 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>*
454 internalProperties, 443 internalProperties,
455 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { 444 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) {
456 using protocol::Runtime::InternalPropertyDescriptor; 445 using protocol::Runtime::InternalPropertyDescriptor;
457 446
458 InjectedScript::ObjectScope scope(errorString, m_inspector, 447 InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(),
459 m_session->contextGroupId(), objectId); 448 objectId);
460 if (!scope.initialize()) return; 449 Response response = scope.initialize();
450 if (!response.isSuccess()) return response;
461 451
462 scope.ignoreExceptionsAndMuteConsole(); 452 scope.ignoreExceptionsAndMuteConsole();
463 if (!scope.object()->IsObject()) { 453 if (!scope.object()->IsObject())
464 *errorString = "Value with given id is not an object"; 454 return Response::Error("Value with given id is not an object");
465 return;
466 }
467 455
468 v8::Local<v8::Object> object = scope.object().As<v8::Object>(); 456 v8::Local<v8::Object> object = scope.object().As<v8::Object>();
469 scope.injectedScript()->getProperties( 457 response = scope.injectedScript()->getProperties(
470 errorString, object, scope.objectGroupName(), 458 object, scope.objectGroupName(), ownProperties.fromMaybe(false),
471 ownProperties.fromMaybe(false), accessorPropertiesOnly.fromMaybe(false), 459 accessorPropertiesOnly.fromMaybe(false), generatePreview.fromMaybe(false),
472 generatePreview.fromMaybe(false), result, exceptionDetails); 460 result, exceptionDetails);
473 if (!errorString->isEmpty() || exceptionDetails->isJust() || 461 if (!response.isSuccess()) return response;
474 accessorPropertiesOnly.fromMaybe(false)) 462 if (exceptionDetails->isJust() || accessorPropertiesOnly.fromMaybe(false))
475 return; 463 return Response::OK();
476 v8::Local<v8::Array> propertiesArray; 464 v8::Local<v8::Array> propertiesArray;
477 if (hasInternalError(errorString, !m_inspector->debugger() 465 if (!m_inspector->debugger()
478 ->internalProperties(scope.context(), 466 ->internalProperties(scope.context(), scope.object())
479 scope.object()) 467 .ToLocal(&propertiesArray)) {
480 .ToLocal(&propertiesArray))) 468 return Response::InternalError();
481 return; 469 }
482 std::unique_ptr<protocol::Array<InternalPropertyDescriptor>> 470 std::unique_ptr<protocol::Array<InternalPropertyDescriptor>>
483 propertiesProtocolArray = 471 propertiesProtocolArray =
484 protocol::Array<InternalPropertyDescriptor>::create(); 472 protocol::Array<InternalPropertyDescriptor>::create();
485 for (uint32_t i = 0; i < propertiesArray->Length(); i += 2) { 473 for (uint32_t i = 0; i < propertiesArray->Length(); i += 2) {
486 v8::Local<v8::Value> name; 474 v8::Local<v8::Value> name;
487 if (hasInternalError( 475 if (!propertiesArray->Get(scope.context(), i).ToLocal(&name) ||
488 errorString, 476 !name->IsString()) {
489 !propertiesArray->Get(scope.context(), i).ToLocal(&name)) || 477 return Response::InternalError();
490 !name->IsString()) 478 }
491 return;
492 v8::Local<v8::Value> value; 479 v8::Local<v8::Value> value;
493 if (hasInternalError( 480 if (!propertiesArray->Get(scope.context(), i + 1).ToLocal(&value))
494 errorString, 481 return Response::InternalError();
495 !propertiesArray->Get(scope.context(), i + 1).ToLocal(&value))) 482 std::unique_ptr<RemoteObject> wrappedValue;
496 return; 483 protocol::Response response = scope.injectedScript()->wrapObject(
497 std::unique_ptr<RemoteObject> wrappedValue = 484 value, scope.objectGroupName(), false, false, &wrappedValue);
498 scope.injectedScript()->wrapObject(errorString, value, 485 if (!response.isSuccess()) return response;
499 scope.objectGroupName());
500 if (!wrappedValue) return;
501 propertiesProtocolArray->addItem( 486 propertiesProtocolArray->addItem(
502 InternalPropertyDescriptor::create() 487 InternalPropertyDescriptor::create()
503 .setName(toProtocolString(name.As<v8::String>())) 488 .setName(toProtocolString(name.As<v8::String>()))
504 .setValue(std::move(wrappedValue)) 489 .setValue(std::move(wrappedValue))
505 .build()); 490 .build());
506 } 491 }
507 if (!propertiesProtocolArray->length()) return; 492 if (propertiesProtocolArray->length())
508 *internalProperties = std::move(propertiesProtocolArray); 493 *internalProperties = std::move(propertiesProtocolArray);
494 return Response::OK();
509 } 495 }
510 496
511 void V8RuntimeAgentImpl::releaseObject(ErrorString* errorString, 497 Response V8RuntimeAgentImpl::releaseObject(const String16& objectId) {
512 const String16& objectId) { 498 InjectedScript::ObjectScope scope(m_inspector, m_session->contextGroupId(),
513 InjectedScript::ObjectScope scope(errorString, m_inspector, 499 objectId);
514 m_session->contextGroupId(), objectId); 500 Response response = scope.initialize();
515 if (!scope.initialize()) return; 501 if (!response.isSuccess()) return response;
516 scope.injectedScript()->releaseObject(objectId); 502 scope.injectedScript()->releaseObject(objectId);
503 return Response::OK();
517 } 504 }
518 505
519 void V8RuntimeAgentImpl::releaseObjectGroup(ErrorString*, 506 Response V8RuntimeAgentImpl::releaseObjectGroup(const String16& objectGroup) {
520 const String16& objectGroup) {
521 m_session->releaseObjectGroup(objectGroup); 507 m_session->releaseObjectGroup(objectGroup);
508 return Response::OK();
522 } 509 }
523 510
524 void V8RuntimeAgentImpl::runIfWaitingForDebugger(ErrorString* errorString) { 511 Response V8RuntimeAgentImpl::runIfWaitingForDebugger() {
525 m_inspector->client()->runIfWaitingForDebugger(m_session->contextGroupId()); 512 m_inspector->client()->runIfWaitingForDebugger(m_session->contextGroupId());
513 return Response::OK();
526 } 514 }
527 515
528 void V8RuntimeAgentImpl::setCustomObjectFormatterEnabled(ErrorString*, 516 Response V8RuntimeAgentImpl::setCustomObjectFormatterEnabled(bool enabled) {
529 bool enabled) {
530 m_state->setBoolean(V8RuntimeAgentImplState::customObjectFormatterEnabled, 517 m_state->setBoolean(V8RuntimeAgentImplState::customObjectFormatterEnabled,
531 enabled); 518 enabled);
532 m_session->setCustomObjectFormatterEnabled(enabled); 519 m_session->setCustomObjectFormatterEnabled(enabled);
520 return Response::OK();
533 } 521 }
534 522
535 void V8RuntimeAgentImpl::discardConsoleEntries(ErrorString*) { 523 Response V8RuntimeAgentImpl::discardConsoleEntries() {
536 V8ConsoleMessageStorage* storage = 524 V8ConsoleMessageStorage* storage =
537 m_inspector->ensureConsoleMessageStorage(m_session->contextGroupId()); 525 m_inspector->ensureConsoleMessageStorage(m_session->contextGroupId());
538 storage->clear(); 526 storage->clear();
527 return Response::OK();
539 } 528 }
540 529
541 void V8RuntimeAgentImpl::compileScript( 530 Response V8RuntimeAgentImpl::compileScript(
542 ErrorString* errorString, const String16& expression, 531 const String16& expression, const String16& sourceURL, bool persistScript,
543 const String16& sourceURL, bool persistScript, 532 Maybe<int> executionContextId, Maybe<String16>* scriptId,
544 const Maybe<int>& executionContextId, Maybe<String16>* scriptId,
545 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { 533 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) {
546 if (!m_enabled) { 534 if (!m_enabled) return Response::Error("Runtime agent is not enabled");
547 *errorString = "Runtime agent is not enabled"; 535
548 return; 536 int contextId = 0;
549 } 537 Response response = ensureContext(m_inspector, m_session->contextGroupId(),
550 int contextId = 538 std::move(executionContextId), &contextId);
551 ensureContext(errorString, m_inspector, m_session->contextGroupId(), 539 if (!response.isSuccess()) return response;
552 executionContextId); 540 InjectedScript::ContextScope scope(m_inspector, m_session->contextGroupId(),
553 if (!errorString->isEmpty()) return; 541 contextId);
554 InjectedScript::ContextScope scope(errorString, m_inspector, 542 response = scope.initialize();
555 m_session->contextGroupId(), contextId); 543 if (!response.isSuccess()) return response;
556 if (!scope.initialize()) return;
557 544
558 if (!persistScript) m_inspector->debugger()->muteScriptParsedEvents(); 545 if (!persistScript) m_inspector->debugger()->muteScriptParsedEvents();
559 v8::Local<v8::Script> script = m_inspector->compileScript( 546 v8::Local<v8::Script> script = m_inspector->compileScript(
560 scope.context(), toV8String(m_inspector->isolate(), expression), 547 scope.context(), toV8String(m_inspector->isolate(), expression),
561 sourceURL, false); 548 sourceURL, false);
562 if (!persistScript) m_inspector->debugger()->unmuteScriptParsedEvents(); 549 if (!persistScript) m_inspector->debugger()->unmuteScriptParsedEvents();
563 if (script.IsEmpty()) { 550 if (script.IsEmpty()) {
564 if (scope.tryCatch().HasCaught()) 551 if (scope.tryCatch().HasCaught()) {
565 *exceptionDetails = scope.injectedScript()->createExceptionDetails( 552 response = scope.injectedScript()->createExceptionDetails(
566 errorString, scope.tryCatch(), String16(), false); 553 scope.tryCatch(), String16(), false, exceptionDetails);
567 else 554 if (!response.isSuccess()) return response;
568 *errorString = "Script compilation failed"; 555 return Response::OK();
569 return; 556 } else {
557 return Response::Error("Script compilation failed");
558 }
570 } 559 }
571 560
572 if (!persistScript) return; 561 if (!persistScript) return Response::OK();
573 562
574 String16 scriptValueId = 563 String16 scriptValueId =
575 String16::fromInteger(script->GetUnboundScript()->GetId()); 564 String16::fromInteger(script->GetUnboundScript()->GetId());
576 std::unique_ptr<v8::Global<v8::Script>> global( 565 std::unique_ptr<v8::Global<v8::Script>> global(
577 new v8::Global<v8::Script>(m_inspector->isolate(), script)); 566 new v8::Global<v8::Script>(m_inspector->isolate(), script));
578 m_compiledScripts[scriptValueId] = std::move(global); 567 m_compiledScripts[scriptValueId] = std::move(global);
579 *scriptId = scriptValueId; 568 *scriptId = scriptValueId;
569 return Response::OK();
580 } 570 }
581 571
582 void V8RuntimeAgentImpl::runScript( 572 void V8RuntimeAgentImpl::runScript(
583 const String16& scriptId, const Maybe<int>& executionContextId, 573 const String16& scriptId, Maybe<int> executionContextId,
584 const Maybe<String16>& objectGroup, const Maybe<bool>& silent, 574 Maybe<String16> objectGroup, Maybe<bool> silent,
585 const Maybe<bool>& includeCommandLineAPI, const Maybe<bool>& returnByValue, 575 Maybe<bool> includeCommandLineAPI, Maybe<bool> returnByValue,
586 const Maybe<bool>& generatePreview, const Maybe<bool>& awaitPromise, 576 Maybe<bool> generatePreview, Maybe<bool> awaitPromise,
587 std::unique_ptr<RunScriptCallback> callback) { 577 std::unique_ptr<RunScriptCallback> callback) {
588 if (!m_enabled) { 578 if (!m_enabled) {
589 callback->sendFailure("Runtime agent is not enabled"); 579 callback->sendFailure(Response::Error("Runtime agent is not enabled"));
590 return; 580 return;
591 } 581 }
592 582
593 auto it = m_compiledScripts.find(scriptId); 583 auto it = m_compiledScripts.find(scriptId);
594 if (it == m_compiledScripts.end()) { 584 if (it == m_compiledScripts.end()) {
595 callback->sendFailure("No script with given id"); 585 callback->sendFailure(Response::Error("No script with given id"));
596 return; 586 return;
597 } 587 }
598 588
599 ErrorString errorString; 589 int contextId = 0;
600 int contextId = 590 Response response = ensureContext(m_inspector, m_session->contextGroupId(),
601 ensureContext(&errorString, m_inspector, m_session->contextGroupId(), 591 std::move(executionContextId), &contextId);
602 executionContextId); 592 if (!response.isSuccess()) {
603 if (!errorString.isEmpty()) { 593 callback->sendFailure(response);
604 callback->sendFailure(errorString);
605 return; 594 return;
606 } 595 }
607 596
608 InjectedScript::ContextScope scope(&errorString, m_inspector, 597 InjectedScript::ContextScope scope(m_inspector, m_session->contextGroupId(),
609 m_session->contextGroupId(), contextId); 598 contextId);
610 if (!scope.initialize()) { 599 response = scope.initialize();
611 callback->sendFailure(errorString); 600 if (!response.isSuccess()) {
601 callback->sendFailure(response);
612 return; 602 return;
613 } 603 }
614 604
615 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole(); 605 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole();
616 606
617 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second); 607 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second);
618 m_compiledScripts.erase(it); 608 m_compiledScripts.erase(it);
619 v8::Local<v8::Script> script = scriptWrapper->Get(m_inspector->isolate()); 609 v8::Local<v8::Script> script = scriptWrapper->Get(m_inspector->isolate());
620 if (script.IsEmpty()) { 610 if (script.IsEmpty()) {
621 callback->sendFailure("Script execution failed"); 611 callback->sendFailure(Response::Error("Script execution failed"));
622 return; 612 return;
623 } 613 }
624 614
625 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()) 615 if (includeCommandLineAPI.fromMaybe(false)) scope.installCommandLineAPI();
626 return;
627 616
628 v8::MaybeLocal<v8::Value> maybeResultValue = 617 v8::MaybeLocal<v8::Value> maybeResultValue =
629 m_inspector->runCompiledScript(scope.context(), script); 618 m_inspector->runCompiledScript(scope.context(), script);
630 619
631 // Re-initialize after running client's code, as it could have destroyed 620 // Re-initialize after running client's code, as it could have destroyed
632 // context or session. 621 // context or session.
633 if (!scope.initialize()) return; 622 response = scope.initialize();
623 if (!response.isSuccess()) {
624 callback->sendFailure(response);
625 return;
626 }
634 627
635 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { 628 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) {
636 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, 629 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue,
637 scope.tryCatch(), objectGroup.fromMaybe(""), 630 scope.tryCatch(), objectGroup.fromMaybe(""),
638 returnByValue.fromMaybe(false), 631 returnByValue.fromMaybe(false),
639 generatePreview.fromMaybe(false), callback.get()); 632 generatePreview.fromMaybe(false), callback.get());
640 return; 633 return;
641 } 634 }
642 ProtocolPromiseHandler<RunScriptCallback>::add( 635 ProtocolPromiseHandler<RunScriptCallback>::add(
643 m_inspector, scope.context(), maybeResultValue.ToLocalChecked(), 636 m_inspector, scope.context(), maybeResultValue.ToLocalChecked(),
644 "Result of the script execution is not a promise", 637 "Result of the script execution is not a promise",
645 m_session->contextGroupId(), 638 m_session->contextGroupId(),
646 scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""), 639 scope.injectedScript()->context()->contextId(), objectGroup.fromMaybe(""),
647 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), 640 returnByValue.fromMaybe(false), generatePreview.fromMaybe(false),
648 std::move(callback)); 641 std::move(callback));
649 } 642 }
650 643
651 void V8RuntimeAgentImpl::restore() { 644 void V8RuntimeAgentImpl::restore() {
652 if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false)) 645 if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false))
653 return; 646 return;
654 m_frontend.executionContextsCleared(); 647 m_frontend.executionContextsCleared();
655 ErrorString error; 648 enable();
656 enable(&error);
657 if (m_state->booleanProperty( 649 if (m_state->booleanProperty(
658 V8RuntimeAgentImplState::customObjectFormatterEnabled, false)) 650 V8RuntimeAgentImplState::customObjectFormatterEnabled, false))
659 m_session->setCustomObjectFormatterEnabled(true); 651 m_session->setCustomObjectFormatterEnabled(true);
660 } 652 }
661 653
662 void V8RuntimeAgentImpl::enable(ErrorString* errorString) { 654 Response V8RuntimeAgentImpl::enable() {
663 if (m_enabled) return; 655 if (m_enabled) return Response::OK();
664 m_inspector->client()->beginEnsureAllContextsInGroup( 656 m_inspector->client()->beginEnsureAllContextsInGroup(
665 m_session->contextGroupId()); 657 m_session->contextGroupId());
666 m_enabled = true; 658 m_enabled = true;
667 m_state->setBoolean(V8RuntimeAgentImplState::runtimeEnabled, true); 659 m_state->setBoolean(V8RuntimeAgentImplState::runtimeEnabled, true);
668 m_inspector->enableStackCapturingIfNeeded(); 660 m_inspector->enableStackCapturingIfNeeded();
669 m_session->reportAllContexts(this); 661 m_session->reportAllContexts(this);
670 V8ConsoleMessageStorage* storage = 662 V8ConsoleMessageStorage* storage =
671 m_inspector->ensureConsoleMessageStorage(m_session->contextGroupId()); 663 m_inspector->ensureConsoleMessageStorage(m_session->contextGroupId());
672 for (const auto& message : storage->messages()) { 664 for (const auto& message : storage->messages()) {
673 if (!reportMessage(message.get(), false)) return; 665 if (!reportMessage(message.get(), false)) break;
674 } 666 }
667 return Response::OK();
675 } 668 }
676 669
677 void V8RuntimeAgentImpl::disable(ErrorString* errorString) { 670 Response V8RuntimeAgentImpl::disable() {
678 if (!m_enabled) return; 671 if (!m_enabled) return Response::OK();
679 m_enabled = false; 672 m_enabled = false;
680 m_state->setBoolean(V8RuntimeAgentImplState::runtimeEnabled, false); 673 m_state->setBoolean(V8RuntimeAgentImplState::runtimeEnabled, false);
681 m_inspector->disableStackCapturingIfNeeded(); 674 m_inspector->disableStackCapturingIfNeeded();
682 m_session->discardInjectedScripts(); 675 m_session->discardInjectedScripts();
683 reset(); 676 reset();
684 m_inspector->client()->endEnsureAllContextsInGroup( 677 m_inspector->client()->endEnsureAllContextsInGroup(
685 m_session->contextGroupId()); 678 m_session->contextGroupId());
679 return Response::OK();
686 } 680 }
687 681
688 void V8RuntimeAgentImpl::reset() { 682 void V8RuntimeAgentImpl::reset() {
689 m_compiledScripts.clear(); 683 m_compiledScripts.clear();
690 if (m_enabled) { 684 if (m_enabled) {
691 if (const V8InspectorImpl::ContextByIdMap* contexts = 685 if (const V8InspectorImpl::ContextByIdMap* contexts =
692 m_inspector->contextGroup(m_session->contextGroupId())) { 686 m_inspector->contextGroup(m_session->contextGroupId())) {
693 for (auto& idContext : *contexts) idContext.second->setReported(false); 687 for (auto& idContext : *contexts) idContext.second->setReported(false);
694 } 688 }
695 m_frontend.executionContextsCleared(); 689 m_frontend.executionContextsCleared();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 } 726 }
733 727
734 bool V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, 728 bool V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message,
735 bool generatePreview) { 729 bool generatePreview) {
736 message->reportToFrontend(&m_frontend, m_session, generatePreview); 730 message->reportToFrontend(&m_frontend, m_session, generatePreview);
737 m_frontend.flush(); 731 m_frontend.flush();
738 return m_inspector->hasConsoleMessageStorage(m_session->contextGroupId()); 732 return m_inspector->hasConsoleMessageStorage(m_session->contextGroupId());
739 } 733 }
740 734
741 } // namespace v8_inspector 735 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-runtime-agent-impl.h ('k') | src/inspector/v8-value-copier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698