| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 222 } |
| 223 | 223 |
| 224 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() | 224 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() |
| 225 { | 225 { |
| 226 } | 226 } |
| 227 | 227 |
| 228 void V8RuntimeAgentImpl::evaluate( | 228 void V8RuntimeAgentImpl::evaluate( |
| 229 const String16& expression, | 229 const String16& expression, |
| 230 const Maybe<String16>& objectGroup, | 230 const Maybe<String16>& objectGroup, |
| 231 const Maybe<bool>& includeCommandLineAPI, | 231 const Maybe<bool>& includeCommandLineAPI, |
| 232 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 232 const Maybe<bool>& silent, |
| 233 const Maybe<int>& executionContextId, | 233 const Maybe<int>& executionContextId, |
| 234 const Maybe<bool>& returnByValue, | 234 const Maybe<bool>& returnByValue, |
| 235 const Maybe<bool>& generatePreview, | 235 const Maybe<bool>& generatePreview, |
| 236 const Maybe<bool>& userGesture, | 236 const Maybe<bool>& userGesture, |
| 237 const Maybe<bool>& awaitPromise, | 237 const Maybe<bool>& awaitPromise, |
| 238 std::unique_ptr<EvaluateCallback> callback) | 238 std::unique_ptr<EvaluateCallback> callback) |
| 239 { | 239 { |
| 240 ErrorString errorString; | 240 ErrorString errorString; |
| 241 int contextId = ensureContext(&errorString, m_inspector, m_session->contextG
roupId(), executionContextId); | 241 int contextId = ensureContext(&errorString, m_inspector, m_session->contextG
roupId(), executionContextId); |
| 242 if (!errorString.isEmpty()) { | 242 if (!errorString.isEmpty()) { |
| 243 callback->sendFailure(errorString); | 243 callback->sendFailure(errorString); |
| 244 return; | 244 return; |
| 245 } | 245 } |
| 246 | 246 |
| 247 InjectedScript::ContextScope scope(&errorString, m_inspector, m_session->con
textGroupId(), contextId); | 247 InjectedScript::ContextScope scope(&errorString, m_inspector, m_session->con
textGroupId(), contextId); |
| 248 if (!scope.initialize()) { | 248 if (!scope.initialize()) { |
| 249 callback->sendFailure(errorString); | 249 callback->sendFailure(errorString); |
| 250 return; | 250 return; |
| 251 } | 251 } |
| 252 | 252 |
| 253 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) | 253 if (silent.fromMaybe(false)) |
| 254 scope.ignoreExceptionsAndMuteConsole(); | 254 scope.ignoreExceptionsAndMuteConsole(); |
| 255 if (userGesture.fromMaybe(false)) | 255 if (userGesture.fromMaybe(false)) |
| 256 scope.pretendUserGesture(); | 256 scope.pretendUserGesture(); |
| 257 | 257 |
| 258 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) { | 258 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) { |
| 259 callback->sendFailure(errorString); | 259 callback->sendFailure(errorString); |
| 260 return; | 260 return; |
| 261 } | 261 } |
| 262 | 262 |
| 263 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed()
; | 263 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed()
; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 scope.objectGroupName(), | 318 scope.objectGroupName(), |
| 319 returnByValue.fromMaybe(false), | 319 returnByValue.fromMaybe(false), |
| 320 generatePreview.fromMaybe(false), | 320 generatePreview.fromMaybe(false), |
| 321 std::move(callback)); | 321 std::move(callback)); |
| 322 } | 322 } |
| 323 | 323 |
| 324 void V8RuntimeAgentImpl::callFunctionOn( | 324 void V8RuntimeAgentImpl::callFunctionOn( |
| 325 const String16& objectId, | 325 const String16& objectId, |
| 326 const String16& expression, | 326 const String16& expression, |
| 327 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum
ents, | 327 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum
ents, |
| 328 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 328 const Maybe<bool>& silent, |
| 329 const Maybe<bool>& returnByValue, | 329 const Maybe<bool>& returnByValue, |
| 330 const Maybe<bool>& generatePreview, | 330 const Maybe<bool>& generatePreview, |
| 331 const Maybe<bool>& userGesture, | 331 const Maybe<bool>& userGesture, |
| 332 const Maybe<bool>& awaitPromise, | 332 const Maybe<bool>& awaitPromise, |
| 333 std::unique_ptr<CallFunctionOnCallback> callback) | 333 std::unique_ptr<CallFunctionOnCallback> callback) |
| 334 { | 334 { |
| 335 ErrorString errorString; | 335 ErrorString errorString; |
| 336 InjectedScript::ObjectScope scope(&errorString, m_inspector, m_session->cont
extGroupId(), objectId); | 336 InjectedScript::ObjectScope scope(&errorString, m_inspector, m_session->cont
extGroupId(), objectId); |
| 337 if (!scope.initialize()) { | 337 if (!scope.initialize()) { |
| 338 callback->sendFailure(errorString); | 338 callback->sendFailure(errorString); |
| 339 return; | 339 return; |
| 340 } | 340 } |
| 341 | 341 |
| 342 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr; | 342 std::unique_ptr<v8::Local<v8::Value>[]> argv = nullptr; |
| 343 int argc = 0; | 343 int argc = 0; |
| 344 if (optionalArguments.isJust()) { | 344 if (optionalArguments.isJust()) { |
| 345 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr
guments.fromJust(); | 345 protocol::Array<protocol::Runtime::CallArgument>* arguments = optionalAr
guments.fromJust(); |
| 346 argc = arguments->length(); | 346 argc = arguments->length(); |
| 347 argv.reset(new v8::Local<v8::Value>[argc]); | 347 argv.reset(new v8::Local<v8::Value>[argc]); |
| 348 for (int i = 0; i < argc; ++i) { | 348 for (int i = 0; i < argc; ++i) { |
| 349 v8::Local<v8::Value> argumentValue; | 349 v8::Local<v8::Value> argumentValue; |
| 350 if (!scope.injectedScript()->resolveCallArgument(&errorString, argum
ents->get(i)).ToLocal(&argumentValue)) { | 350 if (!scope.injectedScript()->resolveCallArgument(&errorString, argum
ents->get(i)).ToLocal(&argumentValue)) { |
| 351 callback->sendFailure(errorString); | 351 callback->sendFailure(errorString); |
| 352 return; | 352 return; |
| 353 } | 353 } |
| 354 argv[i] = argumentValue; | 354 argv[i] = argumentValue; |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 | 357 |
| 358 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) | 358 if (silent.fromMaybe(false)) |
| 359 scope.ignoreExceptionsAndMuteConsole(); | 359 scope.ignoreExceptionsAndMuteConsole(); |
| 360 if (userGesture.fromMaybe(false)) | 360 if (userGesture.fromMaybe(false)) |
| 361 scope.pretendUserGesture(); | 361 scope.pretendUserGesture(); |
| 362 | 362 |
| 363 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_inspector->compileAndRunInt
ernalScript(scope.context(), toV8String(m_inspector->isolate(), "(" + expression
+ ")")); | 363 v8::MaybeLocal<v8::Value> maybeFunctionValue = m_inspector->compileAndRunInt
ernalScript(scope.context(), toV8String(m_inspector->isolate(), "(" + expression
+ ")")); |
| 364 // Re-initialize after running client's code, as it could have destroyed con
text or session. | 364 // Re-initialize after running client's code, as it could have destroyed con
text or session. |
| 365 if (!scope.initialize()) { | 365 if (!scope.initialize()) { |
| 366 callback->sendFailure(errorString); | 366 callback->sendFailure(errorString); |
| 367 return; | 367 return; |
| 368 } | 368 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 if (!scope.initialize()) | 458 if (!scope.initialize()) |
| 459 return; | 459 return; |
| 460 scope.injectedScript()->releaseObject(objectId); | 460 scope.injectedScript()->releaseObject(objectId); |
| 461 } | 461 } |
| 462 | 462 |
| 463 void V8RuntimeAgentImpl::releaseObjectGroup(ErrorString*, const String16& object
Group) | 463 void V8RuntimeAgentImpl::releaseObjectGroup(ErrorString*, const String16& object
Group) |
| 464 { | 464 { |
| 465 m_session->releaseObjectGroup(objectGroup); | 465 m_session->releaseObjectGroup(objectGroup); |
| 466 } | 466 } |
| 467 | 467 |
| 468 void V8RuntimeAgentImpl::run(ErrorString* errorString) | 468 void V8RuntimeAgentImpl::runIfWaitingForDebugger(ErrorString* errorString) |
| 469 { | 469 { |
| 470 m_inspector->client()->resumeStartup(m_session->contextGroupId()); | 470 m_inspector->client()->runIfWaitingForDebugger(m_session->contextGroupId()); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void V8RuntimeAgentImpl::setCustomObjectFormatterEnabled(ErrorString*, bool enab
led) | 473 void V8RuntimeAgentImpl::setCustomObjectFormatterEnabled(ErrorString*, bool enab
led) |
| 474 { | 474 { |
| 475 m_state->setBoolean(V8RuntimeAgentImplState::customObjectFormatterEnabled, e
nabled); | 475 m_state->setBoolean(V8RuntimeAgentImplState::customObjectFormatterEnabled, e
nabled); |
| 476 m_session->setCustomObjectFormatterEnabled(enabled); | 476 m_session->setCustomObjectFormatterEnabled(enabled); |
| 477 } | 477 } |
| 478 | 478 |
| 479 void V8RuntimeAgentImpl::discardConsoleEntries(ErrorString*) | 479 void V8RuntimeAgentImpl::discardConsoleEntries(ErrorString*) |
| 480 { | 480 { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 String16 scriptValueId = String16::fromInteger(script->GetUnboundScript()->G
etId()); | 521 String16 scriptValueId = String16::fromInteger(script->GetUnboundScript()->G
etId()); |
| 522 std::unique_ptr<v8::Global<v8::Script>> global(new v8::Global<v8::Script>(m_
inspector->isolate(), script)); | 522 std::unique_ptr<v8::Global<v8::Script>> global(new v8::Global<v8::Script>(m_
inspector->isolate(), script)); |
| 523 m_compiledScripts[scriptValueId] = std::move(global); | 523 m_compiledScripts[scriptValueId] = std::move(global); |
| 524 *scriptId = scriptValueId; | 524 *scriptId = scriptValueId; |
| 525 } | 525 } |
| 526 | 526 |
| 527 void V8RuntimeAgentImpl::runScript( | 527 void V8RuntimeAgentImpl::runScript( |
| 528 const String16& scriptId, | 528 const String16& scriptId, |
| 529 const Maybe<int>& executionContextId, | 529 const Maybe<int>& executionContextId, |
| 530 const Maybe<String16>& objectGroup, | 530 const Maybe<String16>& objectGroup, |
| 531 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 531 const Maybe<bool>& silent, |
| 532 const Maybe<bool>& includeCommandLineAPI, | 532 const Maybe<bool>& includeCommandLineAPI, |
| 533 const Maybe<bool>& returnByValue, | 533 const Maybe<bool>& returnByValue, |
| 534 const Maybe<bool>& generatePreview, | 534 const Maybe<bool>& generatePreview, |
| 535 const Maybe<bool>& awaitPromise, | 535 const Maybe<bool>& awaitPromise, |
| 536 std::unique_ptr<RunScriptCallback> callback) | 536 std::unique_ptr<RunScriptCallback> callback) |
| 537 { | 537 { |
| 538 if (!m_enabled) { | 538 if (!m_enabled) { |
| 539 callback->sendFailure("Runtime agent is not enabled"); | 539 callback->sendFailure("Runtime agent is not enabled"); |
| 540 return; | 540 return; |
| 541 } | 541 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 552 callback->sendFailure(errorString); | 552 callback->sendFailure(errorString); |
| 553 return; | 553 return; |
| 554 } | 554 } |
| 555 | 555 |
| 556 InjectedScript::ContextScope scope(&errorString, m_inspector, m_session->con
textGroupId(), contextId); | 556 InjectedScript::ContextScope scope(&errorString, m_inspector, m_session->con
textGroupId(), contextId); |
| 557 if (!scope.initialize()) { | 557 if (!scope.initialize()) { |
| 558 callback->sendFailure(errorString); | 558 callback->sendFailure(errorString); |
| 559 return; | 559 return; |
| 560 } | 560 } |
| 561 | 561 |
| 562 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) | 562 if (silent.fromMaybe(false)) |
| 563 scope.ignoreExceptionsAndMuteConsole(); | 563 scope.ignoreExceptionsAndMuteConsole(); |
| 564 | 564 |
| 565 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second
); | 565 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second
); |
| 566 m_compiledScripts.erase(it); | 566 m_compiledScripts.erase(it); |
| 567 v8::Local<v8::Script> script = scriptWrapper->Get(m_inspector->isolate()); | 567 v8::Local<v8::Script> script = scriptWrapper->Get(m_inspector->isolate()); |
| 568 if (script.IsEmpty()) { | 568 if (script.IsEmpty()) { |
| 569 callback->sendFailure("Script execution failed"); | 569 callback->sendFailure("Script execution failed"); |
| 570 return; | 570 return; |
| 571 } | 571 } |
| 572 | 572 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 reportMessage(message, true); | 679 reportMessage(message, true); |
| 680 } | 680 } |
| 681 | 681 |
| 682 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP
review) | 682 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP
review) |
| 683 { | 683 { |
| 684 message->reportToFrontend(&m_frontend, m_session, generatePreview); | 684 message->reportToFrontend(&m_frontend, m_session, generatePreview); |
| 685 m_frontend.flush(); | 685 m_frontend.flush(); |
| 686 } | 686 } |
| 687 | 687 |
| 688 } // namespace v8_inspector | 688 } // namespace v8_inspector |
| OLD | NEW |