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

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

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

Powered by Google App Engine
This is Rietveld 408576698