Bug 1033153 - Part 2: Have the VariablesView stringifier expose internal Promise state. r=vporof

This commit is contained in:
Nick Fitzgerald 2014-10-23 15:52:00 +02:00
Родитель 26af250a18
Коммит 75c0105dd1
3 изменённых файлов: 87 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,75 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const Cu = Components.utils;
const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
const { VariablesView } = Cu.import("resource:///modules/devtools/VariablesView.jsm", {});
const PENDING = {
"type": "object",
"class": "Promise",
"actor": "conn0.pausedobj35",
"extensible": true,
"frozen": false,
"sealed": false,
"promiseState": {
"state": "pending"
},
"preview": {
"kind": "Object",
"ownProperties": {},
"ownPropertiesLength": 0,
"safeGetterValues": {}
}
};
const FULFILLED = {
"type": "object",
"class": "Promise",
"actor": "conn0.pausedobj35",
"extensible": true,
"frozen": false,
"sealed": false,
"promiseState": {
"state": "fulfilled",
"value": 10
},
"preview": {
"kind": "Object",
"ownProperties": {},
"ownPropertiesLength": 0,
"safeGetterValues": {}
}
};
const REJECTED = {
"type": "object",
"class": "Promise",
"actor": "conn0.pausedobj35",
"extensible": true,
"frozen": false,
"sealed": false,
"promiseState": {
"state": "rejected",
"reason": 10
},
"preview": {
"kind": "Object",
"ownProperties": {},
"ownPropertiesLength": 0,
"safeGetterValues": {}
}
};
function run_test() {
equal(VariablesView.getString(PENDING, { concise: true }), "Promise");
equal(VariablesView.getString(PENDING), 'Promise {<state>: "pending"}');
equal(VariablesView.getString(FULFILLED, { concise: true }), "Promise");
equal(VariablesView.getString(FULFILLED), 'Promise {<state>: "fulfilled", <value>: 10}');
equal(VariablesView.getString(REJECTED, { concise: true }), "Promise");
equal(VariablesView.getString(REJECTED), 'Promise {<state>: "rejected", <reason>: 10}');
}

Просмотреть файл

@ -7,3 +7,4 @@ skip-if = toolkit == 'android' || toolkit == 'gonk'
[test_bezierCanvas.js]
[test_cubicBezier.js]
[test_undoStack.js]
[test_VariablesView_getString_promise.js]

Просмотреть файл

@ -3575,6 +3575,17 @@ VariablesView.stringifiers.byObjectKind = {
let {preview} = aGrip;
let props = [];
if (aGrip.class == "Promise" && aGrip.promiseState) {
let { state, value, reason } = aGrip.promiseState;
props.push("<state>: " + VariablesView.getString(state));
if (state == "fulfilled") {
props.push("<value>: " + VariablesView.getString(value, { concise: true }));
} else if (state == "rejected") {
props.push("<reason>: " + VariablesView.getString(reason, { concise: true }));
}
}
for (let key of Object.keys(preview.ownProperties || {})) {
let value = preview.ownProperties[key];
let valueString = "";