mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1196319 - Part 2: Implement getRejectionStack method in ObjectClient r=fitzgen
This commit is contained in:
parent
f33e31f4fa
commit
1682205488
@ -88,6 +88,7 @@ support-files =
|
||||
doc_pretty-print-on-paused.html
|
||||
doc_promise-get-allocation-stack.html
|
||||
doc_promise-get-fulfillment-stack.html
|
||||
doc_promise-get-rejection-stack.html
|
||||
doc_promise.html
|
||||
doc_random-javascript.html
|
||||
doc_recursion-stack.html
|
||||
@ -352,6 +353,8 @@ skip-if = e10s && debug
|
||||
skip-if = true # Bug 1177730
|
||||
[browser_dbg_promises-fulfillment-stack.js]
|
||||
skip-if = e10s && debug
|
||||
[browser_dbg_promises-rejection-stack.js]
|
||||
skip-if = e10s && debug
|
||||
[browser_dbg_reload-preferred-script-01.js]
|
||||
skip-if = e10s && debug
|
||||
[browser_dbg_reload-preferred-script-02.js]
|
||||
|
@ -0,0 +1,100 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Test that we can get a stack to a promise's rejection point.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const TAB_URL = EXAMPLE_URL + "doc_promise-get-rejection-stack.html";
|
||||
const { PromisesFront } = require("devtools/server/actors/promises");
|
||||
let events = require("sdk/event/core");
|
||||
|
||||
const TEST_DATA = [
|
||||
{
|
||||
functionDisplayName: "returnPromise/<",
|
||||
line: 19,
|
||||
column: 47
|
||||
},
|
||||
{
|
||||
functionDisplayName: "returnPromise",
|
||||
line: 19,
|
||||
column: 14
|
||||
},
|
||||
{
|
||||
functionDisplayName: "makePromise",
|
||||
line: 14,
|
||||
column: 15
|
||||
},
|
||||
];
|
||||
|
||||
function test() {
|
||||
Task.spawn(function* () {
|
||||
DebuggerServer.init();
|
||||
DebuggerServer.addBrowserActors();
|
||||
|
||||
const [ tab,, panel ] = yield initDebugger(TAB_URL);
|
||||
|
||||
let client = new DebuggerClient(DebuggerServer.connectPipe());
|
||||
yield connect(client);
|
||||
|
||||
let { tabs } = yield listTabs(client);
|
||||
let targetTab = findTab(tabs, TAB_URL);
|
||||
yield attachTab(client, targetTab);
|
||||
|
||||
yield testGetRejectionStack(client, targetTab, tab);
|
||||
|
||||
yield close(client);
|
||||
yield closeDebuggerAndFinish(panel);
|
||||
}).then(null, error => {
|
||||
ok(false, "Got an error: " + error.message + "\n" + error.stack);
|
||||
});
|
||||
}
|
||||
|
||||
function* testGetRejectionStack(client, form, tab) {
|
||||
let front = PromisesFront(client, form);
|
||||
|
||||
yield front.attach();
|
||||
yield front.listPromises();
|
||||
|
||||
// Get the grip for promise p
|
||||
let onNewPromise = new Promise(resolve => {
|
||||
events.on(front, "new-promises", promises => {
|
||||
for (let p of promises) {
|
||||
if (p.preview.ownProperties.name &&
|
||||
p.preview.ownProperties.name.value === "p") {
|
||||
resolve(p);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
callInTab(tab, "makePromise");
|
||||
|
||||
let grip = yield onNewPromise;
|
||||
ok(grip, "Found our promise p");
|
||||
|
||||
let objectClient = new ObjectClient(client, grip);
|
||||
ok(objectClient, "Got Object Client");
|
||||
|
||||
yield new Promise(resolve => {
|
||||
objectClient.getPromiseRejectionStack(response => {
|
||||
ok(response.rejectionStack.length, "Got promise allocation stack.");
|
||||
|
||||
for (let i = 0; i < TEST_DATA.length; i++) {
|
||||
let stack = response.rejectionStack[i];
|
||||
let data = TEST_DATA[i];
|
||||
is(stack.source.url, TAB_URL, "Got correct source URL.");
|
||||
is(stack.functionDisplayName, data.functionDisplayName,
|
||||
"Got correct function display name.");
|
||||
is(stack.line, data.line, "Got correct stack line number.");
|
||||
is(stack.column, data.column, "Got correct stack column number.");
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
yield front.detach();
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Promise test page</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
function makePromise() {
|
||||
var p = returnPromise();
|
||||
p.name = "p";
|
||||
}
|
||||
|
||||
function returnPromise() {
|
||||
return new Promise((resolve, reject) => reject("hello"));
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -2434,6 +2434,21 @@ ObjectClient.prototype = {
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* Request the stack to the promise's rejection point.
|
||||
*/
|
||||
getPromiseRejectionStack: DebuggerClient.requester({
|
||||
type: "rejectionStack"
|
||||
}, {
|
||||
before: function(packet) {
|
||||
if (this._grip.class !== "Promise") {
|
||||
throw new Error("getPromiseRejectionStack is only valid for " +
|
||||
"promise grips.");
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
@ -606,6 +606,36 @@ ObjectActor.prototype = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle a protocol request to get the rejection stack of a promise.
|
||||
*/
|
||||
onRejectionStack: function() {
|
||||
if (this.obj.class != "Promise") {
|
||||
return { error: "objectNotPromise",
|
||||
message: "'rejectionStack' request is only valid for " +
|
||||
"object grips with a 'Promise' class." };
|
||||
}
|
||||
|
||||
let rawPromise = this.obj.unsafeDereference();
|
||||
let stack = PromiseDebugging.getRejectionStack(rawPromise);
|
||||
let rejectionStacks = [];
|
||||
|
||||
while (stack) {
|
||||
if (stack.source) {
|
||||
let source = this._getSourceOriginalLocation(stack);
|
||||
|
||||
if (source) {
|
||||
rejectionStacks.push(source);
|
||||
}
|
||||
}
|
||||
stack = stack.parent;
|
||||
}
|
||||
|
||||
return Promise.all(rejectionStacks).then(stacks => {
|
||||
return { rejectionStack: stacks };
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function for fetching the source location of a SavedFrame stack.
|
||||
*
|
||||
@ -656,7 +686,8 @@ ObjectActor.prototype.requestTypes = {
|
||||
"scope": ObjectActor.prototype.onScope,
|
||||
"dependentPromises": ObjectActor.prototype.onDependentPromises,
|
||||
"allocationStack": ObjectActor.prototype.onAllocationStack,
|
||||
"fulfillmentStack": ObjectActor.prototype.onFulfillmentStack
|
||||
"fulfillmentStack": ObjectActor.prototype.onFulfillmentStack,
|
||||
"rejectionStack": ObjectActor.prototype.onRejectionStack
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user