Bug 1119490 - Test for source maps in workers;r=jryans

This commit is contained in:
Eddy Bruel 2016-03-02 12:38:25 +01:00
parent 6e4bbbd268
commit d57667806d
8 changed files with 195 additions and 13 deletions

View File

@ -82,7 +82,10 @@ const EVENTS = {
OPTIONS_POPUP_HIDDEN: "Debugger:OptionsPopupHidden",
// When the widgets layout has been changed.
LAYOUT_CHANGED: "Debugger:LayoutChanged"
LAYOUT_CHANGED: "Debugger:LayoutChanged",
// When a worker has been selected.
WORKER_SELECTED: "Debugger::WorkerSelected"
};
// Descriptions for what a stack frame represents after the debugger pauses.
@ -491,8 +494,8 @@ Workers.prototype = {
for (let workerActor in this._workerForms) {
if (!(workerActor in workerForms)) {
DebuggerView.Workers.removeWorker(this._workerForms[workerActor]);
delete this._workerForms[workerActor];
DebuggerView.Workers.removeWorker(workerActor);
}
}
@ -500,7 +503,7 @@ Workers.prototype = {
if (!(workerActor in this._workerForms)) {
let workerForm = workerForms[workerActor];
this._workerForms[workerActor] = workerForm;
DebuggerView.Workers.addWorker(workerActor, workerForm.url);
DebuggerView.Workers.addWorker(workerForm);
}
}
});
@ -510,10 +513,11 @@ Workers.prototype = {
this._updateWorkerList();
},
_onWorkerSelect: function (workerActor) {
DebuggerController.client.attachWorker(workerActor, (response, workerClient) => {
gDevTools.showToolbox(TargetFactory.forWorker(workerClient),
"jsdebugger", Toolbox.HostType.WINDOW);
_onWorkerSelect: function (workerForm) {
DebuggerController.client.attachWorker(workerForm.actor, (response, workerClient) => {
let toolbox = gDevTools.showToolbox(TargetFactory.forWorker(workerClient),
"jsdebugger", Toolbox.HostType.WINDOW);
window.emit(EVENTS.WORKER_SELECTED, toolbox);
});
}
};

View File

@ -45,6 +45,9 @@ support-files =
code_ugly-7.js
code_ugly-8
code_ugly-8^headers^
code_worker-source-map.coffee
code_worker-source-map.js
code_worker-source-map.js.map
code_WorkerActor.attach-worker1.js
code_WorkerActor.attach-worker2.js
code_WorkerActor.attachThread-worker.js
@ -112,6 +115,7 @@ support-files =
doc_watch-expressions.html
doc_watch-expression-button.html
doc_with-frame.html
doc_worker-source-map.html
doc_WorkerActor.attach-tab1.html
doc_WorkerActor.attach-tab2.html
doc_WorkerActor.attachThread-tab.html
@ -592,6 +596,8 @@ skip-if = e10s && debug
skip-if = e10s && debug
[browser_dbg_worker-console.js]
skip-if = e10s && debug
[browser_dbg_worker-source-map.js]
skip-if = e10s && debug
[browser_dbg_worker-window.js]
skip-if = e10s && debug
[browser_dbg_WorkerActor.attach.js]

View File

@ -0,0 +1,85 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "doc_worker-source-map.html";
const WORKER_URL = "code_worker-source-map.js";
const COFFEE_URL = EXAMPLE_URL + "code_worker-source-map.coffee";
function selectWorker(aPanel, aURL) {
let panelWin = aPanel.panelWin;
let promise = waitForDebuggerEvents(aPanel, panelWin.EVENTS.WORKER_SELECTED);
let Workers = panelWin.DebuggerView.Workers;
let item = Workers.getItemForAttachment((workerForm) => {
return workerForm.url === aURL;
});
Workers.selectedItem = item;
return promise;
}
function test() {
return Task.spawn(function* () {
yield pushPrefs(["devtools.debugger.workers", true]);
let [tab,, panel] = yield initDebugger(TAB_URL);
let toolbox = yield selectWorker(panel, WORKER_URL);
let workerPanel = toolbox.getCurrentPanel();
yield waitForSourceShown(workerPanel, ".coffee");
let panelWin = workerPanel.panelWin;
let Sources = panelWin.DebuggerView.Sources;
let editor = panelWin.DebuggerView.editor;
let threadClient = panelWin.gThreadClient;
isnot(Sources.selectedItem.attachment.source.url.indexOf(".coffee"), -1,
"The debugger should show the source mapped coffee source file.");
is(Sources.selectedValue.indexOf(".js"), -1,
"The debugger should not show the generated js source file.");
is(editor.getText().indexOf("isnt"), 211,
"The debugger's editor should have the coffee source source displayed.");
is(editor.getText().indexOf("function"), -1,
"The debugger's editor should not have the JS source displayed.");
yield threadClient.interrupt();
let sourceForm = getSourceForm(Sources, COFFEE_URL);
let source = threadClient.source(sourceForm);
let response = yield source.setBreakpoint({ line: 5 });
ok(!response.error,
"Should be able to set a breakpoint in a coffee source file.");
ok(!response.actualLocation,
"Should be able to set a breakpoint on line 5.");
let promise = new Promise((resolve) => {
threadClient.addOneTimeListener("paused", (event, packet) => {
is(packet.type, "paused",
"We should now be paused again.");
is(packet.why.type, "breakpoint",
"and the reason we should be paused is because we hit a breakpoint.");
// Check that we stopped at the right place, by making sure that the
// environment is in the state that we expect.
is(packet.frame.environment.bindings.variables.start.value, 0,
"'start' is 0.");
is(packet.frame.environment.bindings.variables.stop.value.type, "undefined",
"'stop' hasn't been assigned to yet.");
is(packet.frame.environment.bindings.variables.pivot.value.type, "undefined",
"'pivot' hasn't been assigned to yet.");
waitForCaretUpdated(workerPanel, 5).then(resolve);
});
});
// This will cause the breakpoint to be hit, and put us back in the
// paused state.
yield threadClient.resume();
callInTab(tab, "binary_search", [0, 2, 3, 5, 7, 10], 5);
yield promise;
yield threadClient.resume();
yield toolbox.destroy();
yield closeDebuggerAndFinish(panel);
yield popPrefs();
});
}

View File

@ -0,0 +1,22 @@
# Uses a binary search algorithm to locate a value in the specified array.
binary_search = (items, value) ->
start = 0
stop = items.length - 1
pivot = Math.floor (start + stop) / 2
while items[pivot] isnt value and start < stop
# Adjust the search area.
stop = pivot - 1 if value < items[pivot]
start = pivot + 1 if value > items[pivot]
# Recalculate the pivot.
pivot = Math.floor (stop + start) / 2
# Make sure we've found the correct value.
if items[pivot] is value then pivot else -1
self.onmessage = (event) ->
data = event.data
binary_search(data.items, data.value)

View File

@ -0,0 +1,35 @@
// Generated by CoffeeScript 1.10.0
(function() {
var binary_search;
binary_search = function(items, value) {
var pivot, start, stop;
start = 0;
stop = items.length - 1;
pivot = Math.floor((start + stop) / 2);
while (items[pivot] !== value && start < stop) {
if (value < items[pivot]) {
stop = pivot - 1;
}
if (value > items[pivot]) {
start = pivot + 1;
}
pivot = Math.floor((stop + start) / 2);
}
if (items[pivot] === value) {
return pivot;
} else {
return -1;
}
};
self.onmessage = function(event) {
console.log("EUTA");
var data;
data = event.data;
return binary_search(data.items, data.value);
};
}).call(this);
//# sourceMappingURL=code_worker-source-map.js.map

View File

@ -0,0 +1,10 @@
{
"version": 3,
"file": "code_worker-source-map.js",
"sourceRoot": "",
"sources": [
"code_worker-source-map.coffee"
],
"names": [],
"mappings": ";AACA;AAAA,MAAA;;EAAA,aAAA,GAAgB,SAAC,KAAD,EAAQ,KAAR;AAEd,QAAA;IAAA,KAAA,GAAQ;IACR,IAAA,GAAQ,KAAK,CAAC,MAAN,GAAe;IACvB,KAAA,GAAQ,IAAI,CAAC,KAAL,CAAW,CAAC,KAAA,GAAQ,IAAT,CAAA,GAAiB,CAA5B;AAER,WAAM,KAAM,CAAA,KAAA,CAAN,KAAkB,KAAlB,IAA4B,KAAA,GAAQ,IAA1C;MAGE,IAAqB,KAAA,GAAQ,KAAM,CAAA,KAAA,CAAnC;QAAA,IAAA,GAAQ,KAAA,GAAQ,EAAhB;;MACA,IAAqB,KAAA,GAAQ,KAAM,CAAA,KAAA,CAAnC;QAAA,KAAA,GAAQ,KAAA,GAAQ,EAAhB;;MAGA,KAAA,GAAQ,IAAI,CAAC,KAAL,CAAW,CAAC,IAAA,GAAO,KAAR,CAAA,GAAiB,CAA5B;IAPV;IAUA,IAAG,KAAM,CAAA,KAAA,CAAN,KAAgB,KAAnB;aAA8B,MAA9B;KAAA,MAAA;aAAyC,CAAC,EAA1C;;EAhBc;;EAkBhB,IAAI,CAAC,SAAL,GAAiB,SAAC,KAAD;AACf,QAAA;IAAA,IAAA,GAAO,KAAK,CAAC;WACb,aAAA,CAAc,IAAI,CAAC,KAAnB,EAA0B,IAAI,CAAC,KAA/B;EAFe;AAlBjB"
}

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<script>
var worker = new Worker("code_worker-source-map.js");
function binary_search(items, value) {
worker.postMessage({
items: items,
value: value
});
}
</script>
</head>
<body>
</body>
</html>

View File

@ -28,22 +28,24 @@ WorkersView.prototype = Heritage.extend(WidgetMethods, {
this.widget.addEventListener("select", this._onWorkerSelect, false);
},
addWorker: function (actor, name) {
addWorker: function (workerForm) {
let element = document.createElement("label");
element.className = "plain dbg-worker-item";
element.setAttribute("value", name);
element.setAttribute("value", workerForm.url);
element.setAttribute("flex", "1");
this.push([element, actor], {});
this.push([element, workerForm.actor], {
attachment: workerForm
});
},
removeWorker: function (actor) {
this.remove(this.getItemByValue(actor));
removeWorker: function (workerForm) {
this.remove(this.getItemByValue(workerForm.actor));
},
_onWorkerSelect: function () {
if (this.selectedItem !== null) {
DebuggerController.Workers._onWorkerSelect(this.selectedItem.value);
DebuggerController.Workers._onWorkerSelect(this.selectedItem.attachment);
this.selectedItem = null;
}
}