Commit 49c3b9da authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

DevTools: add frontend support for Runtime.evaluate's timeout option

Bug: 810176
Change-Id: I03d9cbe50625ad0dd067bbf19502ede59b412b94
Reviewed-on: https://chromium-review.googlesource.com/1020524
Commit-Queue: Erik Luo <luoe@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552458}
parent 10dc3f9a
Test frontend's timeout support.
Testing expression 1 + 1 with timeout: 0
Result: 2
Testing expression while (1){} with timeout: 0
error: Execution was terminated
Error occurred.
Does the runtime support side effect checks? true
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
await TestRunner.loadModule('sources_test_runner');
TestRunner.addResult("Test frontend's timeout support.\n");
const executionContext = UI.context.flavor(SDK.ExecutionContext);
const regularExpression = '1 + 1';
const infiniteExpression = 'while (1){}';
await runtimeTestCase(regularExpression);
await runtimeTestCase(infiniteExpression);
let supports = executionContext.runtimeModel.hasSideEffectSupport();
TestRunner.addResult(`\nDoes the runtime support side effect checks? ${supports}`);
TestRunner.completeTest();
async function runtimeTestCase(expression) {
TestRunner.addResult(`\nTesting expression ${expression} with timeout: 0`);
const result = await executionContext.evaluate({expression, timeout: 0});
printDetails(result);
}
function printDetails(result) {
if (result.error) {
TestRunner.addResult(`Error occurred.`);
} else if (result.exceptionDetails) {
let exceptionDescription = result.exceptionDetails.exception.description;
TestRunner.addResult(`Exception: ${exceptionDescription.split("\n")[0]}`);
} else if (result.object) {
let objectDescription = result.object.description;
TestRunner.addResult(`Result: ${objectDescription}`);
}
}
})();
......@@ -1297,6 +1297,9 @@ SDK.DebuggerModel.CallFrame = class {
(runtimeModel.hasSideEffectSupport() === false ||
(runtimeModel.hasSideEffectSupport() === null && !await runtimeModel.checkSideEffectSupport())))
return {error: 'Side-effect checks not supported by backend.'};
// TODO(luoe): remove this check when evaluateOnCallFrame supports timeout.
if (typeof options.timeout !== 'undefined')
return {error: 'Evaluation with timeout on pause not supported by backend.'};
const response = await this.debuggerModel._agent.invoke_evaluateOnCallFrame({
callFrameId: this.id,
......
......@@ -559,7 +559,8 @@ SDK.RuntimeModel.CompileScriptResult;
* silent: (boolean|undefined),
* returnByValue: (boolean|undefined),
* generatePreview: (boolean|undefined),
* throwOnSideEffect: (boolean|undefined)
* throwOnSideEffect: (boolean|undefined),
* timeout: (number|undefined)
* }}
*/
SDK.RuntimeModel.EvaluationOptions;
......@@ -738,7 +739,9 @@ SDK.ExecutionContext = class {
// FIXME: It will be moved to separate ExecutionContext.
if (this.debuggerModel.selectedCallFrame())
return this.debuggerModel.evaluateOnSelectedCallFrame(options);
if (!options.throwOnSideEffect || this.runtimeModel.hasSideEffectSupport())
// Assume backends either support both throwOnSideEffect and timeout options or neither.
const needsTerminationOptions = !!options.throwOnSideEffect || options.timeout !== undefined;
if (!needsTerminationOptions || this.runtimeModel.hasSideEffectSupport())
return this._evaluateGlobal(options, userGesture, awaitPromise);
/** @type {!SDK.RuntimeModel.EvaluationResult} */
......@@ -793,7 +796,8 @@ SDK.ExecutionContext = class {
generatePreview: options.generatePreview,
userGesture: userGesture,
awaitPromise: awaitPromise,
throwOnSideEffect: options.throwOnSideEffect
throwOnSideEffect: options.throwOnSideEffect,
timeout: options.timeout
});
const error = response[Protocol.Error];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment