зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1499070 - Fix timestamp for evaluation result; r=Honza.
When sending a command to the server, a timestamp is computed before evaluating the string, and is then sent back to the client in the packet. However, if top-level await, or somme :commands, the evaluation takes more time, which means the timestamp is now innacurate. For those cases, we update the timestamp before sending the packet to the client. Differential Revision: https://phabricator.services.mozilla.com/D8734 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6ddaa66fe8
Коммит
ee4dfd3370
|
@ -550,6 +550,7 @@ class JSTerm extends Component {
|
|||
const { ConsoleCommand } = require("devtools/client/webconsole/types");
|
||||
const cmdMessage = new ConsoleCommand({
|
||||
messageText: executeString,
|
||||
timeStamp: Date.now(),
|
||||
});
|
||||
this.hud.proxy.dispatchMessageAdd(cmdMessage);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ function ConsoleCommand(props) {
|
|||
type,
|
||||
level,
|
||||
messageText,
|
||||
timeStamp,
|
||||
} = message;
|
||||
|
||||
// This uses a Custom Element to syntax highlight when possible. If it's not
|
||||
|
@ -48,6 +49,7 @@ function ConsoleCommand(props) {
|
|||
messageBody,
|
||||
serviceContainer,
|
||||
indent,
|
||||
timeStamp,
|
||||
timestampsVisible,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -39,6 +39,17 @@ async function performTests() {
|
|||
is(messagesText, `${simpleAwait} - Array [ "await1" ]`,
|
||||
"The output contains the the expected messages");
|
||||
|
||||
// Check that the timestamp of the result is accurate
|
||||
const {
|
||||
visibleMessages,
|
||||
messagesById
|
||||
} = hud.ui.consoleOutput.getStore().getState().messages;
|
||||
const [commandId, resultId] = visibleMessages;
|
||||
const delta = messagesById.get(resultId).timeStamp -
|
||||
messagesById.get(commandId).timeStamp;
|
||||
ok(delta >= 500,
|
||||
`The result has a timestamp at least 500ms (${delta}ms) older than the command`);
|
||||
|
||||
info("Check that assigning the result of a top-level await expression works");
|
||||
await executeAndWaitForResultMessage(
|
||||
`x = await new Promise(r => setTimeout(() => r("await2"), 500))`,
|
||||
|
|
|
@ -22,6 +22,7 @@ exports.ConsoleCommand = function(props) {
|
|||
groupId: null,
|
||||
indent: 0,
|
||||
private: false,
|
||||
timeStamp: null,
|
||||
}, props);
|
||||
};
|
||||
|
||||
|
|
|
@ -976,11 +976,14 @@ WebConsoleActor.prototype =
|
|||
* `resultID` field, with a sanitized helperResult field.
|
||||
*/
|
||||
_waitForResultAndSend: async function(response) {
|
||||
let updateTimestamp = false;
|
||||
|
||||
// Wait for asynchronous command completion before sending back the response
|
||||
if (
|
||||
response.helperResult && typeof response.helperResult.then == "function"
|
||||
) {
|
||||
response.helperResult = await response.helperResult;
|
||||
updateTimestamp = true;
|
||||
} else if (response.awaitResult && typeof response.awaitResult.then === "function") {
|
||||
let result;
|
||||
try {
|
||||
|
@ -1000,6 +1003,14 @@ WebConsoleActor.prototype =
|
|||
|
||||
// Remove the promise from the response object.
|
||||
delete response.awaitResult;
|
||||
|
||||
updateTimestamp = true;
|
||||
}
|
||||
|
||||
if (updateTimestamp) {
|
||||
// We need to compute the timestamp again as the one in the response was set before
|
||||
// doing the evaluation, which is now innacurate since we waited for a bit.
|
||||
response.timestamp = Date.now();
|
||||
}
|
||||
|
||||
// Finally, send an unsolicited evaluationResult packet with
|
||||
|
|
Загрузка…
Ссылка в новой задаче