| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 if (includeCommandLineAPI.fromMaybe(false)) scope.installCommandLineAPI(); | 290 if (includeCommandLineAPI.fromMaybe(false)) scope.installCommandLineAPI(); |
| 291 | 291 |
| 292 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed(); | 292 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed(); |
| 293 // Temporarily enable allow evals for inspector. | 293 // Temporarily enable allow evals for inspector. |
| 294 if (evalIsDisabled) scope.context()->AllowCodeGenerationFromStrings(true); | 294 if (evalIsDisabled) scope.context()->AllowCodeGenerationFromStrings(true); |
| 295 | 295 |
| 296 v8::MaybeLocal<v8::Value> maybeResultValue; | 296 v8::MaybeLocal<v8::Value> maybeResultValue; |
| 297 v8::Local<v8::Script> script; | 297 v8::Local<v8::Script> script; |
| 298 if (m_inspector->compileScript(scope.context(), expression, String16()) | 298 if (m_inspector->compileScript(scope.context(), expression, String16()) |
| 299 .ToLocal(&script)) { | 299 .ToLocal(&script)) { |
| 300 maybeResultValue = m_inspector->runCompiledScript(scope.context(), script); | 300 v8::MicrotasksScope microtasksScope(m_inspector->isolate(), |
| 301 v8::MicrotasksScope::kRunMicrotasks); |
| 302 maybeResultValue = script->Run(scope.context()); |
| 301 } | 303 } |
| 302 | 304 |
| 303 if (evalIsDisabled) scope.context()->AllowCodeGenerationFromStrings(false); | 305 if (evalIsDisabled) scope.context()->AllowCodeGenerationFromStrings(false); |
| 304 | 306 |
| 305 // Re-initialize after running client's code, as it could have destroyed | 307 // Re-initialize after running client's code, as it could have destroyed |
| 306 // context or session. | 308 // context or session. |
| 307 response = scope.initialize(); | 309 response = scope.initialize(); |
| 308 if (!response.isSuccess()) { | 310 if (!response.isSuccess()) { |
| 309 callback->sendFailure(response); | 311 callback->sendFailure(response); |
| 310 return; | 312 return; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 380 } |
| 379 | 381 |
| 380 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole(); | 382 if (silent.fromMaybe(false)) scope.ignoreExceptionsAndMuteConsole(); |
| 381 if (userGesture.fromMaybe(false)) scope.pretendUserGesture(); | 383 if (userGesture.fromMaybe(false)) scope.pretendUserGesture(); |
| 382 | 384 |
| 383 v8::MaybeLocal<v8::Value> maybeFunctionValue; | 385 v8::MaybeLocal<v8::Value> maybeFunctionValue; |
| 384 v8::Local<v8::Script> functionScript; | 386 v8::Local<v8::Script> functionScript; |
| 385 if (m_inspector | 387 if (m_inspector |
| 386 ->compileScript(scope.context(), "(" + expression + ")", String16()) | 388 ->compileScript(scope.context(), "(" + expression + ")", String16()) |
| 387 .ToLocal(&functionScript)) { | 389 .ToLocal(&functionScript)) { |
| 388 maybeFunctionValue = | 390 v8::MicrotasksScope microtasksScope(m_inspector->isolate(), |
| 389 m_inspector->runCompiledScript(scope.context(), functionScript); | 391 v8::MicrotasksScope::kRunMicrotasks); |
| 392 maybeFunctionValue = functionScript->Run(scope.context()); |
| 390 } | 393 } |
| 391 // Re-initialize after running client's code, as it could have destroyed | 394 // Re-initialize after running client's code, as it could have destroyed |
| 392 // context or session. | 395 // context or session. |
| 393 response = scope.initialize(); | 396 response = scope.initialize(); |
| 394 if (!response.isSuccess()) { | 397 if (!response.isSuccess()) { |
| 395 callback->sendFailure(response); | 398 callback->sendFailure(response); |
| 396 return; | 399 return; |
| 397 } | 400 } |
| 398 | 401 |
| 399 if (scope.tryCatch().HasCaught()) { | 402 if (scope.tryCatch().HasCaught()) { |
| 400 wrapEvaluateResultAsync(scope.injectedScript(), maybeFunctionValue, | 403 wrapEvaluateResultAsync(scope.injectedScript(), maybeFunctionValue, |
| 401 scope.tryCatch(), scope.objectGroupName(), false, | 404 scope.tryCatch(), scope.objectGroupName(), false, |
| 402 false, callback.get()); | 405 false, callback.get()); |
| 403 return; | 406 return; |
| 404 } | 407 } |
| 405 | 408 |
| 406 v8::Local<v8::Value> functionValue; | 409 v8::Local<v8::Value> functionValue; |
| 407 if (!maybeFunctionValue.ToLocal(&functionValue) || | 410 if (!maybeFunctionValue.ToLocal(&functionValue) || |
| 408 !functionValue->IsFunction()) { | 411 !functionValue->IsFunction()) { |
| 409 callback->sendFailure( | 412 callback->sendFailure( |
| 410 Response::Error("Given expression does not evaluate to a function")); | 413 Response::Error("Given expression does not evaluate to a function")); |
| 411 return; | 414 return; |
| 412 } | 415 } |
| 413 | 416 |
| 414 v8::MaybeLocal<v8::Value> maybeResultValue = m_inspector->callFunction( | 417 v8::MaybeLocal<v8::Value> maybeResultValue; |
| 415 functionValue.As<v8::Function>(), scope.context(), scope.object(), argc, | 418 { |
| 416 argv.get()); | 419 v8::MicrotasksScope microtasksScope(m_inspector->isolate(), |
| 420 v8::MicrotasksScope::kRunMicrotasks); |
| 421 maybeResultValue = functionValue.As<v8::Function>()->Call( |
| 422 scope.context(), scope.object(), argc, argv.get()); |
| 423 } |
| 417 // Re-initialize after running client's code, as it could have destroyed | 424 // Re-initialize after running client's code, as it could have destroyed |
| 418 // context or session. | 425 // context or session. |
| 419 response = scope.initialize(); | 426 response = scope.initialize(); |
| 420 if (!response.isSuccess()) { | 427 if (!response.isSuccess()) { |
| 421 callback->sendFailure(response); | 428 callback->sendFailure(response); |
| 422 return; | 429 return; |
| 423 } | 430 } |
| 424 | 431 |
| 425 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { | 432 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { |
| 426 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, | 433 wrapEvaluateResultAsync(scope.injectedScript(), maybeResultValue, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second); | 620 std::unique_ptr<v8::Global<v8::Script>> scriptWrapper = std::move(it->second); |
| 614 m_compiledScripts.erase(it); | 621 m_compiledScripts.erase(it); |
| 615 v8::Local<v8::Script> script = scriptWrapper->Get(m_inspector->isolate()); | 622 v8::Local<v8::Script> script = scriptWrapper->Get(m_inspector->isolate()); |
| 616 if (script.IsEmpty()) { | 623 if (script.IsEmpty()) { |
| 617 callback->sendFailure(Response::Error("Script execution failed")); | 624 callback->sendFailure(Response::Error("Script execution failed")); |
| 618 return; | 625 return; |
| 619 } | 626 } |
| 620 | 627 |
| 621 if (includeCommandLineAPI.fromMaybe(false)) scope.installCommandLineAPI(); | 628 if (includeCommandLineAPI.fromMaybe(false)) scope.installCommandLineAPI(); |
| 622 | 629 |
| 623 v8::MaybeLocal<v8::Value> maybeResultValue = | 630 v8::MaybeLocal<v8::Value> maybeResultValue; |
| 624 m_inspector->runCompiledScript(scope.context(), script); | 631 { |
| 632 v8::MicrotasksScope microtasksScope(m_inspector->isolate(), |
| 633 v8::MicrotasksScope::kRunMicrotasks); |
| 634 maybeResultValue = script->Run(scope.context()); |
| 635 } |
| 625 | 636 |
| 626 // Re-initialize after running client's code, as it could have destroyed | 637 // Re-initialize after running client's code, as it could have destroyed |
| 627 // context or session. | 638 // context or session. |
| 628 response = scope.initialize(); | 639 response = scope.initialize(); |
| 629 if (!response.isSuccess()) { | 640 if (!response.isSuccess()) { |
| 630 callback->sendFailure(response); | 641 callback->sendFailure(response); |
| 631 return; | 642 return; |
| 632 } | 643 } |
| 633 | 644 |
| 634 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { | 645 if (!awaitPromise.fromMaybe(false) || scope.tryCatch().HasCaught()) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 } | 744 } |
| 734 | 745 |
| 735 bool V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, | 746 bool V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, |
| 736 bool generatePreview) { | 747 bool generatePreview) { |
| 737 message->reportToFrontend(&m_frontend, m_session, generatePreview); | 748 message->reportToFrontend(&m_frontend, m_session, generatePreview); |
| 738 m_frontend.flush(); | 749 m_frontend.flush(); |
| 739 return m_inspector->hasConsoleMessageStorage(m_session->contextGroupId()); | 750 return m_inspector->hasConsoleMessageStorage(m_session->contextGroupId()); |
| 740 } | 751 } |
| 741 | 752 |
| 742 } // namespace v8_inspector | 753 } // namespace v8_inspector |
| OLD | NEW |