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