| OLD | NEW |
| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 if (hasError) | 57 if (hasError) |
| 58 *errorString = "Internal error"; | 58 *errorString = "Internal error"; |
| 59 return hasError; | 59 return hasError; |
| 60 } | 60 } |
| 61 | 61 |
| 62 namespace { | 62 namespace { |
| 63 | 63 |
| 64 template<typename Callback> | 64 template<typename Callback> |
| 65 class ProtocolPromiseHandler { | 65 class ProtocolPromiseHandler { |
| 66 public: | 66 public: |
| 67 static void add(V8InspectorImpl* inspector, v8::Local<v8::Context> context,
v8::Local<v8::Promise> promise, int contextGroupId, int executionContextId, cons
t String16& objectGroup, bool returnByValue, bool generatePreview, std::unique_p
tr<Callback> callback) | 67 static void add(V8InspectorImpl* inspector, v8::Local<v8::Context> context,
v8::MaybeLocal<v8::Value> value, const String16& notPromiseError, int contextGro
upId, int executionContextId, const String16& objectGroup, bool returnByValue, b
ool generatePreview, std::unique_ptr<Callback> callback) |
| 68 { | 68 { |
| 69 if (value.IsEmpty()) { |
| 70 callback->sendFailure("Internal error"); |
| 71 return; |
| 72 } |
| 73 if (!value.ToLocalChecked()->IsPromise()) { |
| 74 callback->sendFailure(notPromiseError); |
| 75 return; |
| 76 } |
| 77 v8::Local<v8::Promise> promise = v8::Local<v8::Promise>::Cast(value.ToLo
calChecked()); |
| 69 Callback* rawCallback = callback.get(); | 78 Callback* rawCallback = callback.get(); |
| 70 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler(i
nspector, contextGroupId, executionContextId, objectGroup, returnByValue, genera
tePreview, std::move(callback)); | 79 ProtocolPromiseHandler<Callback>* handler = new ProtocolPromiseHandler(i
nspector, contextGroupId, executionContextId, objectGroup, returnByValue, genera
tePreview, std::move(callback)); |
| 71 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(inspector->isolate
()); | 80 v8::Local<v8::Value> wrapper = handler->m_wrapper.Get(inspector->isolate
()); |
| 72 | 81 |
| 73 v8::Local<v8::Function> thenCallbackFunction = v8::Function::New(context
, thenCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalChecked(); | 82 v8::Local<v8::Function> thenCallbackFunction = v8::Function::New(context
, thenCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalChecked(); |
| 74 if (promise->Then(context, thenCallbackFunction).IsEmpty()) { | 83 if (promise->Then(context, thenCallbackFunction).IsEmpty()) { |
| 75 rawCallback->sendFailure("Internal error"); | 84 rawCallback->sendFailure("Internal error"); |
| 76 return; | 85 return; |
| 77 } | 86 } |
| 78 v8::Local<v8::Function> catchCallbackFunction = v8::Function::New(contex
t, catchCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalChecked(); | 87 v8::Local<v8::Function> catchCallbackFunction = v8::Function::New(contex
t, catchCallback, wrapper, 0, v8::ConstructorBehavior::kThrow).ToLocalChecked(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 &wasThrown, | 187 &wasThrown, |
| 179 &exceptionDetails); | 188 &exceptionDetails); |
| 180 if (errorString.isEmpty()) { | 189 if (errorString.isEmpty()) { |
| 181 callback->sendSuccess(std::move(result), wasThrown, exceptionDetails); | 190 callback->sendSuccess(std::move(result), wasThrown, exceptionDetails); |
| 182 return true; | 191 return true; |
| 183 } | 192 } |
| 184 callback->sendFailure(errorString); | 193 callback->sendFailure(errorString); |
| 185 return false; | 194 return false; |
| 186 } | 195 } |
| 187 | 196 |
| 197 int ensureContext(ErrorString* errorString, V8InspectorImpl* inspector, int cont
extGroupId, const Maybe<int>& executionContextId) |
| 198 { |
| 199 int contextId; |
| 200 if (executionContextId.isJust()) { |
| 201 contextId = executionContextId.fromJust(); |
| 202 } else { |
| 203 v8::HandleScope handles(inspector->isolate()); |
| 204 v8::Local<v8::Context> defaultContext = inspector->client()->ensureDefau
ltContextInGroup(contextGroupId); |
| 205 if (defaultContext.IsEmpty()) { |
| 206 *errorString = "Cannot find default execution context"; |
| 207 return 0; |
| 208 } |
| 209 contextId = V8Debugger::contextId(defaultContext); |
| 210 } |
| 211 return contextId; |
| 212 } |
| 213 |
| 188 } // namespace | 214 } // namespace |
| 189 | 215 |
| 190 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8InspectorSessionImpl* session, protocol
::FrontendChannel* FrontendChannel, protocol::DictionaryValue* state) | 216 V8RuntimeAgentImpl::V8RuntimeAgentImpl(V8InspectorSessionImpl* session, protocol
::FrontendChannel* FrontendChannel, protocol::DictionaryValue* state) |
| 191 : m_session(session) | 217 : m_session(session) |
| 192 , m_state(state) | 218 , m_state(state) |
| 193 , m_frontend(FrontendChannel) | 219 , m_frontend(FrontendChannel) |
| 194 , m_inspector(session->inspector()) | 220 , m_inspector(session->inspector()) |
| 195 , m_enabled(false) | 221 , m_enabled(false) |
| 196 { | 222 { |
| 197 } | 223 } |
| 198 | 224 |
| 199 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() | 225 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() |
| 200 { | 226 { |
| 201 } | 227 } |
| 202 | 228 |
| 203 void V8RuntimeAgentImpl::evaluate( | 229 void V8RuntimeAgentImpl::evaluate( |
| 204 const String16& expression, | 230 const String16& expression, |
| 205 const Maybe<String16>& objectGroup, | 231 const Maybe<String16>& objectGroup, |
| 206 const Maybe<bool>& includeCommandLineAPI, | 232 const Maybe<bool>& includeCommandLineAPI, |
| 207 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 233 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 208 const Maybe<int>& executionContextId, | 234 const Maybe<int>& executionContextId, |
| 209 const Maybe<bool>& returnByValue, | 235 const Maybe<bool>& returnByValue, |
| 210 const Maybe<bool>& generatePreview, | 236 const Maybe<bool>& generatePreview, |
| 211 const Maybe<bool>& userGesture, | 237 const Maybe<bool>& userGesture, |
| 212 const Maybe<bool>& awaitPromise, | 238 const Maybe<bool>& awaitPromise, |
| 213 std::unique_ptr<EvaluateCallback> callback) | 239 std::unique_ptr<EvaluateCallback> callback) |
| 214 { | 240 { |
| 215 int contextId; | 241 ErrorString errorString; |
| 216 if (executionContextId.isJust()) { | 242 int contextId = ensureContext(&errorString, m_inspector, m_session->contextG
roupId(), executionContextId); |
| 217 contextId = executionContextId.fromJust(); | 243 if (!errorString.isEmpty()) { |
| 218 } else { | 244 callback->sendFailure(errorString); |
| 219 v8::HandleScope handles(m_inspector->isolate()); | 245 return; |
| 220 v8::Local<v8::Context> defaultContext = m_inspector->client()->ensureDef
aultContextInGroup(m_session->contextGroupId()); | |
| 221 if (defaultContext.IsEmpty()) { | |
| 222 callback->sendFailure("Cannot find default execution context"); | |
| 223 return; | |
| 224 } | |
| 225 contextId = V8Debugger::contextId(defaultContext); | |
| 226 } | 246 } |
| 227 | 247 |
| 228 ErrorString errorString; | |
| 229 InjectedScript::ContextScope scope(&errorString, m_inspector, m_session->con
textGroupId(), contextId); | 248 InjectedScript::ContextScope scope(&errorString, m_inspector, m_session->con
textGroupId(), contextId); |
| 230 if (!scope.initialize()) { | 249 if (!scope.initialize()) { |
| 231 callback->sendFailure(errorString); | 250 callback->sendFailure(errorString); |
| 232 return; | 251 return; |
| 233 } | 252 } |
| 234 | 253 |
| 235 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) | 254 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 236 scope.ignoreExceptionsAndMuteConsole(); | 255 scope.ignoreExceptionsAndMuteConsole(); |
| 237 if (userGesture.fromMaybe(false)) | 256 if (userGesture.fromMaybe(false)) |
| 238 scope.pretendUserGesture(); | 257 scope.pretendUserGesture(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 258 // Re-initialize after running client's code, as it could have destroyed con
text or session. | 277 // Re-initialize after running client's code, as it could have destroyed con
text or session. |
| 259 if (!scope.initialize()) { | 278 if (!scope.initialize()) { |
| 260 callback->sendFailure(errorString); | 279 callback->sendFailure(errorString); |
| 261 return; | 280 return; |
| 262 } | 281 } |
| 263 | 282 |
| 264 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { | 283 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { |
| 265 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, scope.
tryCatch(), objectGroup.fromMaybe(""), returnByValue.fromMaybe(false), generateP
review.fromMaybe(false), callback.get()); | 284 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, scope.
tryCatch(), objectGroup.fromMaybe(""), returnByValue.fromMaybe(false), generateP
review.fromMaybe(false), callback.get()); |
| 266 return; | 285 return; |
| 267 } | 286 } |
| 268 | |
| 269 if (maybeResultValue.IsEmpty()) { | |
| 270 callback->sendFailure("Internal error"); | |
| 271 return; | |
| 272 } | |
| 273 | |
| 274 if (!maybeResultValue.ToLocalChecked()->IsPromise()) { | |
| 275 callback->sendFailure("Result of expression is not a promise."); | |
| 276 return; | |
| 277 } | |
| 278 | |
| 279 ProtocolPromiseHandler<EvaluateCallback>::add( | 287 ProtocolPromiseHandler<EvaluateCallback>::add( |
| 280 m_inspector, | 288 m_inspector, |
| 281 scope.context(), | 289 scope.context(), |
| 282 v8::Local<v8::Promise>::Cast(maybeResultValue.ToLocalChecked()), | 290 maybeResultValue, |
| 291 "Result of the evaluation is not a promise", |
| 283 m_session->contextGroupId(), | 292 m_session->contextGroupId(), |
| 284 scope.injectedScript()->context()->contextId(), | 293 scope.injectedScript()->context()->contextId(), |
| 285 objectGroup.fromMaybe(""), | 294 objectGroup.fromMaybe(""), |
| 286 returnByValue.fromMaybe(false), | 295 returnByValue.fromMaybe(false), |
| 287 generatePreview.fromMaybe(false), | 296 generatePreview.fromMaybe(false), |
| 288 std::move(callback)); | 297 std::move(callback)); |
| 289 } | 298 } |
| 290 | 299 |
| 291 void V8RuntimeAgentImpl::awaitPromise( | 300 void V8RuntimeAgentImpl::awaitPromise( |
| 292 const String16& promiseObjectId, | 301 const String16& promiseObjectId, |
| 293 const Maybe<bool>& returnByValue, | 302 const Maybe<bool>& returnByValue, |
| 294 const Maybe<bool>& generatePreview, | 303 const Maybe<bool>& generatePreview, |
| 295 std::unique_ptr<AwaitPromiseCallback> callback) | 304 std::unique_ptr<AwaitPromiseCallback> callback) |
| 296 { | 305 { |
| 297 ErrorString errorString; | 306 ErrorString errorString; |
| 298 InjectedScript::ObjectScope scope(&errorString, m_inspector, m_session->cont
extGroupId(), promiseObjectId); | 307 InjectedScript::ObjectScope scope(&errorString, m_inspector, m_session->cont
extGroupId(), promiseObjectId); |
| 299 if (!scope.initialize()) { | 308 if (!scope.initialize()) { |
| 300 callback->sendFailure(errorString); | 309 callback->sendFailure(errorString); |
| 301 return; | 310 return; |
| 302 } | 311 } |
| 303 if (!scope.object()->IsPromise()) { | |
| 304 callback->sendFailure("Could not find promise with given id"); | |
| 305 return; | |
| 306 } | |
| 307 ProtocolPromiseHandler<AwaitPromiseCallback>::add( | 312 ProtocolPromiseHandler<AwaitPromiseCallback>::add( |
| 308 m_inspector, | 313 m_inspector, |
| 309 scope.context(), | 314 scope.context(), |
| 310 v8::Local<v8::Promise>::Cast(scope.object()), | 315 scope.object(), |
| 316 "Could not find promise with given id", |
| 311 m_session->contextGroupId(), | 317 m_session->contextGroupId(), |
| 312 scope.injectedScript()->context()->contextId(), | 318 scope.injectedScript()->context()->contextId(), |
| 313 scope.objectGroupName(), | 319 scope.objectGroupName(), |
| 314 returnByValue.fromMaybe(false), | 320 returnByValue.fromMaybe(false), |
| 315 generatePreview.fromMaybe(false), | 321 generatePreview.fromMaybe(false), |
| 316 std::move(callback)); | 322 std::move(callback)); |
| 317 } | 323 } |
| 318 | 324 |
| 319 void V8RuntimeAgentImpl::callFunctionOn( | 325 void V8RuntimeAgentImpl::callFunctionOn( |
| 320 const String16& objectId, | 326 const String16& objectId, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 if (!scope.initialize()) { | 384 if (!scope.initialize()) { |
| 379 callback->sendFailure(errorString); | 385 callback->sendFailure(errorString); |
| 380 return; | 386 return; |
| 381 } | 387 } |
| 382 | 388 |
| 383 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { | 389 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { |
| 384 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, scope.
tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generatePre
view.fromMaybe(false), callback.get()); | 390 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, scope.
tryCatch(), scope.objectGroupName(), returnByValue.fromMaybe(false), generatePre
view.fromMaybe(false), callback.get()); |
| 385 return; | 391 return; |
| 386 } | 392 } |
| 387 | 393 |
| 388 if (maybeResultValue.IsEmpty()) { | |
| 389 callback->sendFailure("Internal error"); | |
| 390 return; | |
| 391 } | |
| 392 | |
| 393 if (!maybeResultValue.ToLocalChecked()->IsPromise()) { | |
| 394 callback->sendFailure("Result of the function call is not a promise."); | |
| 395 return; | |
| 396 } | |
| 397 | |
| 398 ProtocolPromiseHandler<CallFunctionOnCallback>::add( | 394 ProtocolPromiseHandler<CallFunctionOnCallback>::add( |
| 399 m_inspector, | 395 m_inspector, |
| 400 scope.context(), | 396 scope.context(), |
| 401 v8::Local<v8::Promise>::Cast(maybeResultValue.ToLocalChecked()), | 397 maybeResultValue, |
| 398 "Result of the function call is not a promise", |
| 402 m_session->contextGroupId(), | 399 m_session->contextGroupId(), |
| 403 scope.injectedScript()->context()->contextId(), | 400 scope.injectedScript()->context()->contextId(), |
| 404 scope.objectGroupName(), | 401 scope.objectGroupName(), |
| 405 returnByValue.fromMaybe(false), | 402 returnByValue.fromMaybe(false), |
| 406 generatePreview.fromMaybe(false), | 403 generatePreview.fromMaybe(false), |
| 407 std::move(callback)); | 404 std::move(callback)); |
| 408 } | 405 } |
| 409 | 406 |
| 410 void V8RuntimeAgentImpl::getProperties( | 407 void V8RuntimeAgentImpl::getProperties( |
| 411 ErrorString* errorString, | 408 ErrorString* errorString, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 void V8RuntimeAgentImpl::discardConsoleEntries(ErrorString*) | 480 void V8RuntimeAgentImpl::discardConsoleEntries(ErrorString*) |
| 484 { | 481 { |
| 485 V8ConsoleMessageStorage* storage = m_inspector->ensureConsoleMessageStorage(
m_session->contextGroupId()); | 482 V8ConsoleMessageStorage* storage = m_inspector->ensureConsoleMessageStorage(
m_session->contextGroupId()); |
| 486 storage->clear(); | 483 storage->clear(); |
| 487 } | 484 } |
| 488 | 485 |
| 489 void V8RuntimeAgentImpl::compileScript(ErrorString* errorString, | 486 void V8RuntimeAgentImpl::compileScript(ErrorString* errorString, |
| 490 const String16& expression, | 487 const String16& expression, |
| 491 const String16& sourceURL, | 488 const String16& sourceURL, |
| 492 bool persistScript, | 489 bool persistScript, |
| 493 int executionContextId, | 490 const Maybe<int>& executionContextId, |
| 494 Maybe<String16>* scriptId, | 491 Maybe<String16>* scriptId, |
| 495 Maybe<ExceptionDetails>* exceptionDetails) | 492 Maybe<ExceptionDetails>* exceptionDetails) |
| 496 { | 493 { |
| 497 if (!m_enabled) { | 494 if (!m_enabled) { |
| 498 *errorString = "Runtime agent is not enabled"; | 495 *errorString = "Runtime agent is not enabled"; |
| 499 return; | 496 return; |
| 500 } | 497 } |
| 501 InjectedScript::ContextScope scope(errorString, m_inspector, m_session->cont
extGroupId(), executionContextId); | 498 int contextId = ensureContext(errorString, m_inspector, m_session->contextGr
oupId(), executionContextId); |
| 499 if (!errorString->isEmpty()) |
| 500 return; |
| 501 InjectedScript::ContextScope scope(errorString, m_inspector, m_session->cont
extGroupId(), contextId); |
| 502 if (!scope.initialize()) | 502 if (!scope.initialize()) |
| 503 return; | 503 return; |
| 504 | 504 |
| 505 v8::Local<v8::Script> script = m_inspector->compileScript(scope.context(), t
oV8String(m_inspector->isolate(), expression), sourceURL, false); | 505 v8::Local<v8::Script> script = m_inspector->compileScript(scope.context(), t
oV8String(m_inspector->isolate(), expression), sourceURL, false); |
| 506 if (script.IsEmpty()) { | 506 if (script.IsEmpty()) { |
| 507 v8::Local<v8::Message> message = scope.tryCatch().Message(); | 507 v8::Local<v8::Message> message = scope.tryCatch().Message(); |
| 508 if (!message.IsEmpty()) | 508 if (!message.IsEmpty()) |
| 509 *exceptionDetails = scope.injectedScript()->createExceptionDetails(m
essage); | 509 *exceptionDetails = scope.injectedScript()->createExceptionDetails(m
essage); |
| 510 else | 510 else |
| 511 *errorString = "Script compilation failed"; | 511 *errorString = "Script compilation failed"; |
| 512 return; | 512 return; |
| 513 } | 513 } |
| 514 | 514 |
| 515 if (!persistScript) | 515 if (!persistScript) |
| 516 return; | 516 return; |
| 517 | 517 |
| 518 String16 scriptValueId = String16::fromInteger(script->GetUnboundScript()->G
etId()); | 518 String16 scriptValueId = String16::fromInteger(script->GetUnboundScript()->G
etId()); |
| 519 std::unique_ptr<v8::Global<v8::Script>> global(new v8::Global<v8::Script>(m_
inspector->isolate(), script)); | 519 std::unique_ptr<v8::Global<v8::Script>> global(new v8::Global<v8::Script>(m_
inspector->isolate(), script)); |
| 520 m_compiledScripts[scriptValueId] = std::move(global); | 520 m_compiledScripts[scriptValueId] = std::move(global); |
| 521 *scriptId = scriptValueId; | 521 *scriptId = scriptValueId; |
| 522 } | 522 } |
| 523 | 523 |
| 524 void V8RuntimeAgentImpl::runScript(ErrorString* errorString, | 524 void V8RuntimeAgentImpl::runScript( |
| 525 const String16& scriptId, | 525 const String16& scriptId, |
| 526 int executionContextId, | 526 const Maybe<int>& executionContextId, |
| 527 const Maybe<String16>& objectGroup, | 527 const Maybe<String16>& objectGroup, |
| 528 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 528 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 529 const Maybe<bool>& includeCommandLineAPI, | 529 const Maybe<bool>& includeCommandLineAPI, |
| 530 std::unique_ptr<RemoteObject>* result, | 530 const Maybe<bool>& returnByValue, |
| 531 Maybe<ExceptionDetails>* exceptionDetails) | 531 const Maybe<bool>& generatePreview, |
| 532 const Maybe<bool>& awaitPromise, |
| 533 std::unique_ptr<RunScriptCallback> callback) |
| 532 { | 534 { |
| 533 if (!m_enabled) { | 535 if (!m_enabled) { |
| 534 *errorString = "Runtime agent is not enabled"; | 536 callback->sendFailure("Runtime agent is not enabled"); |
| 535 return; | 537 return; |
| 536 } | 538 } |
| 537 | 539 |
| 538 auto it = m_compiledScripts.find(scriptId); | 540 auto it = m_compiledScripts.find(scriptId); |
| 539 if (it == m_compiledScripts.end()) { | 541 if (it == m_compiledScripts.end()) { |
| 540 *errorString = "Script execution failed"; | 542 callback->sendFailure("No script with given id"); |
| 541 return; | 543 return; |
| 542 } | 544 } |
| 543 | 545 |
| 544 InjectedScript::ContextScope scope(errorString, m_inspector, m_session->cont
extGroupId(), executionContextId); | 546 ErrorString errorString; |
| 545 if (!scope.initialize()) | 547 int contextId = ensureContext(&errorString, m_inspector, m_session->contextG
roupId(), executionContextId); |
| 548 if (!errorString.isEmpty()) { |
| 549 callback->sendFailure(errorString); |
| 546 return; | 550 return; |
| 551 } |
| 552 |
| 553 InjectedScript::ContextScope scope(&errorString, m_inspector, m_session->con
textGroupId(), contextId); |
| 554 if (!scope.initialize()) { |
| 555 callback->sendFailure(errorString); |
| 556 return; |
| 557 } |
| 547 | 558 |
| 548 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) | 559 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 549 scope.ignoreExceptionsAndMuteConsole(); | 560 scope.ignoreExceptionsAndMuteConsole(); |
| 550 | 561 |
| 551 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second
); | 562 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second
); |
| 552 m_compiledScripts.erase(it); | 563 m_compiledScripts.erase(it); |
| 553 v8::Local<v8::Script> script = scriptWrapper->Get(m_inspector->isolate()); | 564 v8::Local<v8::Script> script = scriptWrapper->Get(m_inspector->isolate()); |
| 554 if (script.IsEmpty()) { | 565 if (script.IsEmpty()) { |
| 555 *errorString = "Script execution failed"; | 566 callback->sendFailure("Script execution failed"); |
| 556 return; | 567 return; |
| 557 } | 568 } |
| 558 | 569 |
| 559 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) | 570 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) |
| 560 return; | 571 return; |
| 561 | 572 |
| 562 v8::MaybeLocal<v8::Value> maybeResultValue = m_inspector->runCompiledScript(
scope.context(), script); | 573 v8::MaybeLocal<v8::Value> maybeResultValue = m_inspector->runCompiledScript(
scope.context(), script); |
| 563 | 574 |
| 564 // Re-initialize after running client's code, as it could have destroyed con
text or session. | 575 // Re-initialize after running client's code, as it could have destroyed con
text or session. |
| 565 if (!scope.initialize()) | 576 if (!scope.initialize()) |
| 566 return; | 577 return; |
| 567 scope.injectedScript()->wrapEvaluateResult(errorString, maybeResultValue, sc
ope.tryCatch(), objectGroup.fromMaybe(""), false, false, result, nullptr, except
ionDetails); | 578 |
| 579 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { |
| 580 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, scope.
tryCatch(), objectGroup.fromMaybe(""), returnByValue.fromMaybe(false), generateP
review.fromMaybe(false), callback.get()); |
| 581 return; |
| 582 } |
| 583 ProtocolPromiseHandler<RunScriptCallback>::add( |
| 584 m_inspector, |
| 585 scope.context(), |
| 586 maybeResultValue.ToLocalChecked(), |
| 587 "Result of the script execution is not a promise", |
| 588 m_session->contextGroupId(), |
| 589 scope.injectedScript()->context()->contextId(), |
| 590 objectGroup.fromMaybe(""), |
| 591 returnByValue.fromMaybe(false), |
| 592 generatePreview.fromMaybe(false), |
| 593 std::move(callback)); |
| 568 } | 594 } |
| 569 | 595 |
| 570 void V8RuntimeAgentImpl::restore() | 596 void V8RuntimeAgentImpl::restore() |
| 571 { | 597 { |
| 572 if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false
)) | 598 if (!m_state->booleanProperty(V8RuntimeAgentImplState::runtimeEnabled, false
)) |
| 573 return; | 599 return; |
| 574 m_frontend.executionContextsCleared(); | 600 m_frontend.executionContextsCleared(); |
| 575 ErrorString error; | 601 ErrorString error; |
| 576 enable(&error); | 602 enable(&error); |
| 577 if (m_state->booleanProperty(V8RuntimeAgentImplState::customObjectFormatterE
nabled, false)) | 603 if (m_state->booleanProperty(V8RuntimeAgentImplState::customObjectFormatterE
nabled, false)) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 reportMessage(message, true); | 676 reportMessage(message, true); |
| 651 } | 677 } |
| 652 | 678 |
| 653 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP
review) | 679 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP
review) |
| 654 { | 680 { |
| 655 message->reportToFrontend(&m_frontend, m_session, generatePreview); | 681 message->reportToFrontend(&m_frontend, m_session, generatePreview); |
| 656 m_frontend.flush(); | 682 m_frontend.flush(); |
| 657 } | 683 } |
| 658 | 684 |
| 659 } // namespace blink | 685 } // namespace blink |
| OLD | NEW |