forked from mirrors/gecko-dev
Bug 1678613 - Use property descriptors in promise previewers. r=nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D97760
This commit is contained in:
parent
e996bcb42b
commit
50f32274b5
8 changed files with 124 additions and 86 deletions
|
|
@ -44,13 +44,13 @@ define(function(require, exports, module) {
|
|||
if (object.promiseState) {
|
||||
const { state, value, reason } = object.promiseState;
|
||||
const ownProperties = Object.create(null);
|
||||
ownProperties["<state>"] = state;
|
||||
ownProperties["<state>"] = { value: state };
|
||||
let ownPropertiesLength = 1;
|
||||
if (state == "fulfilled") {
|
||||
ownProperties["<value>"] = value;
|
||||
ownProperties["<value>"] = { value: value };
|
||||
++ownPropertiesLength;
|
||||
} else if (state == "rejected") {
|
||||
ownProperties["<reason>"] = reason;
|
||||
ownProperties["<reason>"] = { value: reason };
|
||||
++ownPropertiesLength;
|
||||
}
|
||||
object.preview = {
|
||||
|
|
@ -77,7 +77,7 @@ define(function(require, exports, module) {
|
|||
config,
|
||||
getTitle(object),
|
||||
span({ className: "objectLeftBrace" }, " { "),
|
||||
Rep({ object: object.preview.ownProperties["<state>"] }),
|
||||
Rep({ object: object.preview.ownProperties["<state>"].value }),
|
||||
span({ className: "objectRightBrace" }, " }")
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ describe("Promise - fulfilled with object", () => {
|
|||
describe("Promise - fulfilled with array", () => {
|
||||
const object = stubs.get("FulfilledWithArray");
|
||||
const length = getGripLengthBubbleText(
|
||||
object.preview.ownProperties["<value>"],
|
||||
object.preview.ownProperties["<value>"].value,
|
||||
{
|
||||
mode: MODE.TINY,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,12 +179,16 @@ stubs.set("Promise.resolve(1n)", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "fulfilled",
|
||||
"<state>": {
|
||||
value: "fulfilled",
|
||||
},
|
||||
"<value>": {
|
||||
value: {
|
||||
type: "BigInt",
|
||||
text: "1",
|
||||
},
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 2,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ stubs.set("Pending", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "pending",
|
||||
"<state>": {
|
||||
value: "pending",
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 1,
|
||||
},
|
||||
|
|
@ -27,8 +29,12 @@ stubs.set("FulfilledWithNumber", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "fulfilled",
|
||||
"<value>": 42,
|
||||
"<state>": {
|
||||
value: "fulfilled",
|
||||
},
|
||||
"<value>": {
|
||||
value: 42,
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 2,
|
||||
},
|
||||
|
|
@ -42,8 +48,12 @@ stubs.set("FulfilledWithString", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "fulfilled",
|
||||
"<value>": "foo",
|
||||
"<state>": {
|
||||
value: "fulfilled",
|
||||
},
|
||||
"<value>": {
|
||||
value: "foo",
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 2,
|
||||
},
|
||||
|
|
@ -57,8 +67,11 @@ stubs.set("FulfilledWithObject", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "fulfilled",
|
||||
"<state>": {
|
||||
value: "fulfilled",
|
||||
},
|
||||
"<value>": {
|
||||
value: {
|
||||
type: "object",
|
||||
actor: "server1.conn1.child1/obj60",
|
||||
class: "Object",
|
||||
|
|
@ -68,6 +81,7 @@ stubs.set("FulfilledWithObject", {
|
|||
ownPropertyLength: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 2,
|
||||
},
|
||||
});
|
||||
|
|
@ -80,8 +94,11 @@ stubs.set("FulfilledWithArray", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "fulfilled",
|
||||
"<state>": {
|
||||
value: "fulfilled",
|
||||
},
|
||||
"<value>": {
|
||||
value: {
|
||||
type: "object",
|
||||
actor: "server1.conn1.child1/obj58",
|
||||
class: "Array",
|
||||
|
|
@ -95,6 +112,7 @@ stubs.set("FulfilledWithArray", {
|
|||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 2,
|
||||
},
|
||||
});
|
||||
|
|
@ -107,8 +125,11 @@ stubs.set("FulfilledWithNode", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "fulfilled",
|
||||
"<state>": {
|
||||
value: "fulfilled",
|
||||
},
|
||||
"<value>": {
|
||||
value: {
|
||||
type: "object",
|
||||
actor: "server1.conn1.child1/obj218",
|
||||
class: "HTMLButtonElement",
|
||||
|
|
@ -130,6 +151,7 @@ stubs.set("FulfilledWithNode", {
|
|||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 2,
|
||||
},
|
||||
});
|
||||
|
|
@ -142,8 +164,11 @@ stubs.set("FulfilledWithDisconnectedNode", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "fulfilled",
|
||||
"<state>": {
|
||||
value: "fulfilled",
|
||||
},
|
||||
"<value>": {
|
||||
value: {
|
||||
type: "object",
|
||||
actor: "server1.conn1.child1/obj218",
|
||||
class: "HTMLButtonElement",
|
||||
|
|
@ -165,6 +190,7 @@ stubs.set("FulfilledWithDisconnectedNode", {
|
|||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 2,
|
||||
},
|
||||
});
|
||||
|
|
@ -177,8 +203,12 @@ stubs.set("RejectedWithNumber", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "rejected",
|
||||
"<reason>": 123,
|
||||
"<state>": {
|
||||
value: "rejected",
|
||||
},
|
||||
"<reason>": {
|
||||
value: 123,
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 2,
|
||||
},
|
||||
|
|
@ -192,8 +222,11 @@ stubs.set("RejectedWithObject", {
|
|||
preview: {
|
||||
kind: "Object",
|
||||
ownProperties: {
|
||||
"<state>": "rejected",
|
||||
"<state>": {
|
||||
value: "rejected",
|
||||
},
|
||||
"<reason>": {
|
||||
value: {
|
||||
type: "object",
|
||||
actor: "server1.conn1.child1/obj68",
|
||||
class: "Object",
|
||||
|
|
@ -203,6 +236,7 @@ stubs.set("RejectedWithObject", {
|
|||
ownPropertyLength: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
ownPropertiesLength: 2,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -364,17 +364,17 @@ const previewers = {
|
|||
function({ obj, hooks }, grip, rawObj) {
|
||||
const {state, value, reason} = ObjectUtils.getPromiseState(obj);
|
||||
const ownProperties = Object.create(null);
|
||||
ownProperties["<state>"] = state;
|
||||
ownProperties["<state>"] = { value: state };
|
||||
let ownPropertiesLength = 1;
|
||||
|
||||
// Only expose <value> or <reason> in top-level promises, to avoid recursion.
|
||||
// <state> is not problematic because it's a string.
|
||||
if (hooks.getGripDepth() === 1) {
|
||||
if (state == "fulfilled") {
|
||||
ownProperties["<value>"] = hooks.createValueGrip(value);
|
||||
ownProperties["<value>"] = { value: hooks.createValueGrip(value) };
|
||||
++ownPropertiesLength;
|
||||
} else if (state == "rejected") {
|
||||
ownProperties["<reason>"] = hooks.createValueGrip(reason);
|
||||
ownProperties["<reason>"] = { value: hooks.createValueGrip(reason) };
|
||||
++ownPropertiesLength;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ add_task(
|
|||
|
||||
ok(grip.preview);
|
||||
equal(grip.class, "Promise");
|
||||
equal(grip.preview.ownProperties["<state>"], "pending");
|
||||
equal(grip.preview.ownProperties["<state>"].value, "pending");
|
||||
|
||||
const objClient = threadFront.pauseGrip(grip);
|
||||
const { promiseState } = await objClient.getPromiseState();
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ add_task(
|
|||
|
||||
ok(grip.preview);
|
||||
equal(grip.class, "Promise");
|
||||
equal(grip.preview.ownProperties["<state>"], "fulfilled");
|
||||
equal(grip.preview.ownProperties["<state>"].value, "fulfilled");
|
||||
equal(
|
||||
grip.preview.ownProperties["<value>"].actorID,
|
||||
grip.preview.ownProperties["<value>"].value.actorID,
|
||||
packet.frame.arguments[0].actorID,
|
||||
"The promise's fulfilled state value in the preview should be the same " +
|
||||
"value passed to the then function"
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ add_task(
|
|||
const grip = environment.bindings.variables.p.value;
|
||||
ok(grip.preview);
|
||||
equal(grip.class, "Promise");
|
||||
equal(grip.preview.ownProperties["<state>"], "rejected");
|
||||
equal(grip.preview.ownProperties["<state>"].value, "rejected");
|
||||
equal(
|
||||
grip.preview.ownProperties["<reason>"].actorID,
|
||||
grip.preview.ownProperties["<reason>"].value.actorID,
|
||||
packet.frame.arguments[0].actorID,
|
||||
"The promise's rejected state reason in the preview should be the same " +
|
||||
"value passed to the then function"
|
||||
|
|
|
|||
Loading…
Reference in a new issue