Skip to content

Commit

Permalink
Merge inbound to mozilla-central. a=merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianbrindusan committed Apr 17, 2019
2 parents c6ac17d + c47237c commit ee39054
Show file tree
Hide file tree
Showing 28 changed files with 409 additions and 208 deletions.
31 changes: 29 additions & 2 deletions caps/nsJSPrincipals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ bool nsJSPrincipals::ReadPrincipals(JSContext* aCx,

if (!(tag == SCTAG_DOM_NULL_PRINCIPAL || tag == SCTAG_DOM_SYSTEM_PRINCIPAL ||
tag == SCTAG_DOM_CONTENT_PRINCIPAL ||
tag == SCTAG_DOM_EXPANDED_PRINCIPAL)) {
tag == SCTAG_DOM_EXPANDED_PRINCIPAL ||
tag == SCTAG_DOM_WORKER_PRINCIPAL)) {
xpc::Throw(aCx, NS_ERROR_DOM_DATA_CLONE_ERR);
return false;
}
Expand Down Expand Up @@ -286,6 +287,19 @@ static bool ReadPrincipalInfo(JSStructuredCloneReader* aReader, uint32_t aTag,
return true;
}

static StaticRefPtr<nsIPrincipal> sActiveWorkerPrincipal;

nsJSPrincipals::AutoSetActiveWorkerPrincipal::AutoSetActiveWorkerPrincipal
(nsIPrincipal* aPrincipal) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_RELEASE_ASSERT(!sActiveWorkerPrincipal);
sActiveWorkerPrincipal = aPrincipal;
}

nsJSPrincipals::AutoSetActiveWorkerPrincipal::~AutoSetActiveWorkerPrincipal() {
sActiveWorkerPrincipal = nullptr;
}

/* static */
bool nsJSPrincipals::ReadKnownPrincipalType(JSContext* aCx,
JSStructuredCloneReader* aReader,
Expand All @@ -294,13 +308,26 @@ bool nsJSPrincipals::ReadKnownPrincipalType(JSContext* aCx,
MOZ_ASSERT(aTag == SCTAG_DOM_NULL_PRINCIPAL ||
aTag == SCTAG_DOM_SYSTEM_PRINCIPAL ||
aTag == SCTAG_DOM_CONTENT_PRINCIPAL ||
aTag == SCTAG_DOM_EXPANDED_PRINCIPAL);
aTag == SCTAG_DOM_EXPANDED_PRINCIPAL ||
aTag == SCTAG_DOM_WORKER_PRINCIPAL);

if (NS_WARN_IF(!NS_IsMainThread())) {
xpc::Throw(aCx, NS_ERROR_UNCATCHABLE_EXCEPTION);
return false;
}

if (aTag == SCTAG_DOM_WORKER_PRINCIPAL) {
// When reading principals which were written on a worker thread, we need to
// know the principal of the worker which did the write.
if (!sActiveWorkerPrincipal) {
xpc::Throw(aCx, NS_ERROR_DOM_DATA_CLONE_ERR);
return false;
}
RefPtr<nsJSPrincipals> retval = get(sActiveWorkerPrincipal);
retval.forget(aOutPrincipals);
return true;
}

PrincipalInfo info;
if (!ReadPrincipalInfo(aReader, aTag, info)) {
return false;
Expand Down
11 changes: 11 additions & 0 deletions caps/nsJSPrincipals.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ class nsJSPrincipals : public nsIPrincipal, public JSPrincipals {
uint32_t aTag,
JSPrincipals** aOutPrincipals);

// This class is used on the main thread to specify which principal to use
// when reading principals data that was set on a DOM worker thread.
// DOM workers do not use principals from Gecko's point of view, and any
// JSPrincipals used internally will be a shared singleton object. When that
// singleton is written out and later read on the main thread, we substitute
// the principal specified with this class.
struct MOZ_RAII AutoSetActiveWorkerPrincipal {
explicit AutoSetActiveWorkerPrincipal(nsIPrincipal* aPrincipal);
~AutoSetActiveWorkerPrincipal();
};

bool write(JSContext* aCx, JSStructuredCloneWriter* aWriter) final;

/*
Expand Down
2 changes: 1 addition & 1 deletion devtools/client/debugger/src/utils/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function removeEditor() {
}

function getCodeMirror() {
return editor && editor.codeMirror;
return editor && editor.hasCodeMirror ? editor.codeMirror : null;
}

export function startOperation() {
Expand Down
5 changes: 4 additions & 1 deletion devtools/client/debugger/src/utils/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { isDevelopment } from "devtools-environment";
import Services from "devtools-services";
import { asyncStoreHelper } from "./asyncStoreHelper";

// Schema version to bump when the async store format has changed incompatibly
// and old stores should be cleared. This needs to match the prefs schema
// version in devtools/client/preferences/debugger.js.
const prefsSchemaVersion = "1.0.9";
const pref = Services.pref;

Expand Down Expand Up @@ -43,7 +46,7 @@ if (isDevelopment()) {
pref("devtools.debugger.file-search-regex-match", false);
pref("devtools.debugger.project-directory-root", "");
pref("devtools.debugger.map-scopes-enabled", false);
pref("devtools.debugger.prefs-schema-version", "1.0.1");
pref("devtools.debugger.prefs-schema-version", prefsSchemaVersion);
pref("devtools.debugger.skip-pausing", false);
pref("devtools.debugger.features.workers", true);
pref("devtools.debugger.features.async-stepping", true);
Expand Down
1 change: 1 addition & 0 deletions devtools/client/debugger/test/mochitest/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,4 @@ skip-if = true
[browser_dbg-event-handler.js]
[browser_dbg-eval-throw.js]
[browser_dbg-sourceURL-breakpoint.js]
[browser_dbg-old-breakpoint.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that we show a breakpoint in the UI when there is an old pending
// breakpoint with an invalid original location.
add_task(async function() {
clearDebuggerPreferences();

const pending = {
bp1: {
location: {
sourceId: "",
sourceUrl: EXAMPLE_URL + "nowhere2.js",
line: 5
},
generatedLocation: {
sourceUrl: EXAMPLE_URL + "simple1.js",
line: 4
},
options: {},
disabled: false
},
bp2: {
location: {
sourceId: "",
sourceUrl: EXAMPLE_URL + "nowhere.js",
line: 5
},
generatedLocation: {
sourceUrl: EXAMPLE_URL + "simple3.js",
line: 2
},
options: {},
disabled: false
},
};
asyncStorage.setItem("debugger.pending-breakpoints", pending);

const toolbox = await openNewTabAndToolbox(EXAMPLE_URL + "doc-scripts.html", "jsdebugger");
const dbg = createDebuggerContext(toolbox);

// Pending breakpoints are installed asynchronously, keep invoking the entry
// function until the debugger pauses.
await waitUntil(() => {
invokeInTab("main");
return isPaused(dbg);
});

ok(true, "paused at unmapped breakpoint");
await waitForState(dbg, state => dbg.selectors.getBreakpointCount(state) == 2);
ok(true, "unmapped breakpoints shown in UI");
});

// Test that if we show a breakpoint with an old generated location, it is
// removed after we load the original source and find the new generated
// location.
add_task(async function() {
clearDebuggerPreferences();

const pending = {
bp1: {
location: {
sourceId: "",
sourceUrl: "webpack:///entry.js",
line: 15,
column: 0
},
generatedLocation: {
sourceUrl: EXAMPLE_URL + "sourcemaps/bundle.js",
line: 47,
column: 16
},
astLocation: {},
options: {},
disabled: false
},
};
asyncStorage.setItem("debugger.pending-breakpoints", pending);

const toolbox = await openNewTabAndToolbox(EXAMPLE_URL + "doc-sourcemaps.html", "jsdebugger");
const dbg = createDebuggerContext(toolbox);

await waitForState(dbg, state => {
const bps = dbg.selectors.getBreakpointsList(state);
return bps.length == 1
&& bps[0].location.sourceUrl.includes("entry.js")
&& bps[0].location.line == 15;
});
ok(true, "removed old breakpoint during sync");
});
3 changes: 2 additions & 1 deletion devtools/client/preferences/debugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pref("devtools.debugger.auto-black-box", true);
pref("devtools.debugger.workers", false);

// The default Debugger UI settings
pref("devtools.debugger.prefs-schema-version", "1.0.0");
// This schema version needs to match that in devtools/client/debugger/src/utils/prefs.js.
pref("devtools.debugger.prefs-schema-version", "1.0.9");
pref("devtools.debugger.ui.panes-workers-and-sources-width", 200);
pref("devtools.debugger.ui.panes-instruments-width", 300);
pref("devtools.debugger.ui.panes-visible-on-startup", false);
Expand Down
7 changes: 7 additions & 0 deletions devtools/client/shared/sourceeditor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ Editor.prototype = {
return editors.get(this);
},

/**
* Return whether there is a CodeMirror instance associated with this Editor.
*/
get hasCodeMirror() {
return editors.has(this);
},

/**
* Appends the current Editor instance to the element specified by
* 'el'. You can also provide your own iframe to host the editor as
Expand Down
30 changes: 20 additions & 10 deletions devtools/client/webconsole/test/fixtures/stubs/pageError.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ stubPreparedMessages.set(`throw ""`, new ConsoleMessage({
"category": "content javascript",
"messageText": "uncaught exception: ",
"parameters": null,
"repeatId": "{\"frame\":null,\"groupId\":null,\"indent\":0,\"level\":\"error\",\"messageText\":\"uncaught exception: \",\"parameters\":null,\"source\":\"javascript\",\"type\":\"log\",\"userProvidedStyles\":null,\"private\":false,\"stacktrace\":[{\"filename\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":\"server1.conn0.child1/source24\",\"lineNumber\":1,\"columnNumber\":1,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js line 59 > eval\",\"sourceId\":null,\"lineNumber\":7,\"columnNumber\":31,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js\",\"sourceId\":null,\"lineNumber\":60,\"columnNumber\":29,\"functionName\":null}]}",
"repeatId": "{\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":null,\"line\":1,\"column\":1},\"groupId\":null,\"indent\":0,\"level\":\"error\",\"messageText\":\"uncaught exception: \",\"parameters\":null,\"source\":\"javascript\",\"type\":\"log\",\"userProvidedStyles\":null,\"private\":false,\"stacktrace\":[{\"filename\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":\"server1.conn0.child1/source24\",\"lineNumber\":1,\"columnNumber\":1,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js line 59 > eval\",\"sourceId\":null,\"lineNumber\":7,\"columnNumber\":31,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js\",\"sourceId\":null,\"lineNumber\":60,\"columnNumber\":29,\"functionName\":null}]}",
"stacktrace": [
{
"filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
Expand All @@ -229,7 +229,12 @@ stubPreparedMessages.set(`throw ""`, new ConsoleMessage({
"functionName": null
}
],
"frame": null,
"frame": {
"source": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
"sourceId": null,
"line": 1,
"column": 1
},
"groupId": null,
"errorMessageName": "JSMSG_UNCAUGHT_EXCEPTION",
"userProvidedStyles": null,
Expand All @@ -252,7 +257,7 @@ stubPreparedMessages.set(`throw "tomato"`, new ConsoleMessage({
"category": "content javascript",
"messageText": "uncaught exception: tomato",
"parameters": null,
"repeatId": "{\"frame\":null,\"groupId\":null,\"indent\":0,\"level\":\"error\",\"messageText\":\"uncaught exception: tomato\",\"parameters\":null,\"source\":\"javascript\",\"type\":\"log\",\"userProvidedStyles\":null,\"private\":false,\"stacktrace\":[{\"filename\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":\"server1.conn0.child1/source24\",\"lineNumber\":1,\"columnNumber\":1,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js line 59 > eval\",\"sourceId\":null,\"lineNumber\":7,\"columnNumber\":31,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js\",\"sourceId\":null,\"lineNumber\":60,\"columnNumber\":29,\"functionName\":null}]}",
"repeatId": "{\"frame\":{\"source\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":null,\"line\":1,\"column\":1},\"groupId\":null,\"indent\":0,\"level\":\"error\",\"messageText\":\"uncaught exception: tomato\",\"parameters\":null,\"source\":\"javascript\",\"type\":\"log\",\"userProvidedStyles\":null,\"private\":false,\"stacktrace\":[{\"filename\":\"http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html\",\"sourceId\":\"server1.conn0.child1/source24\",\"lineNumber\":1,\"columnNumber\":1,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js line 59 > eval\",\"sourceId\":null,\"lineNumber\":7,\"columnNumber\":31,\"functionName\":null},{\"filename\":\"resource://testing-common/content-task.js\",\"sourceId\":null,\"lineNumber\":60,\"columnNumber\":29,\"functionName\":null}]}",
"stacktrace": [
{
"filename": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
Expand All @@ -276,7 +281,12 @@ stubPreparedMessages.set(`throw "tomato"`, new ConsoleMessage({
"functionName": null
}
],
"frame": null,
"frame": {
"source": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
"sourceId": null,
"line": 1,
"column": 1
},
"groupId": null,
"errorMessageName": "JSMSG_UNCAUGHT_EXCEPTION",
"userProvidedStyles": null,
Expand Down Expand Up @@ -459,11 +469,11 @@ stubPackets.set(`throw ""`, {
"pageError": {
"errorMessage": "uncaught exception: ",
"errorMessageName": "JSMSG_UNCAUGHT_EXCEPTION",
"sourceName": "",
"sourceName": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
"sourceId": null,
"lineText": "",
"lineNumber": 0,
"columnNumber": 0,
"lineNumber": 1,
"columnNumber": 1,
"category": "content javascript",
"innerWindowID": 6442450949,
"timeStamp": 1517942398629,
Expand Down Expand Up @@ -507,11 +517,11 @@ stubPackets.set(`throw "tomato"`, {
"pageError": {
"errorMessage": "uncaught exception: tomato",
"errorMessageName": "JSMSG_UNCAUGHT_EXCEPTION",
"sourceName": "",
"sourceName": "http://example.com/browser/devtools/client/webconsole/test/fixtures/stub-generators/test-console-api.html",
"sourceId": null,
"lineText": "",
"lineNumber": 0,
"columnNumber": 0,
"lineNumber": 1,
"columnNumber": 1,
"category": "content javascript",
"innerWindowID": 6442450949,
"timeStamp": 1517942398637,
Expand Down
4 changes: 4 additions & 0 deletions devtools/client/webconsole/test/mochitest/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ support-files =
test-dynamic-import.html
test-dynamic-import.js
test-error.html
test-error-worker.html
test-error-worker.js
test-error-worker2.js
test-eval-in-stackframe.html
test-eval-sources.html
test-external-script-errors.html
Expand Down Expand Up @@ -408,3 +411,4 @@ tags = trackingprotection
[browser_webconsole_warning_groups_outside_console_group.js]
[browser_webconsole_warning_groups.js]
[browser_webconsole_websocket.js]
[browser_webconsole_worker_error.js]
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);

await checkMessage("hello", 14, 3);
await checkMessage("1,2,3", 20, 1);

async function checkMessage(text, line, numFrames) {
const msgNode = await waitFor(() => findMessage(hud, text));
ok(!msgNode.classList.contains("open"), `Error logged not expanded`);

const button = msgNode.querySelector(".collapse-button");
button.click();

const framesNode = await waitFor(() => msgNode.querySelector(".frames"));
const frameNodes = framesNode.querySelectorAll(".frame");
ok(frameNodes.length == numFrames);
ok(frameNodes[0].querySelector(".line").textContent == "" + line);
}
await checkMessageStack(hud, "hello", [14, 10, 7]);
await checkMessageStack(hud, "1,2,3", [20]);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* -*- 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/ */

// Tests that throwing uncaught errors and primitive values in workers shows a
// stack in the console.

"use strict";

const TEST_URI = "http://example.com/browser/devtools/client/webconsole/" +
"test/mochitest/test-error-worker.html";

add_task(async function() {
const hud = await openNewTabAndConsole(TEST_URI);

await checkMessageStack(hud, "hello", [11, 3]);
await checkMessageStack(hud, "there", [14, 3]);
await checkMessageStack(hud, "dom", [16, 3]);
await checkMessageStack(hud, "worker2", [6, 3]);
});
25 changes: 25 additions & 0 deletions devtools/client/webconsole/test/mochitest/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,3 +1320,28 @@ function checkConsoleOutputForWarningGroup(hud, expectedMessages) {
`the expected "${expectedMessage}" content - "${message.textContent.trim()}"`);
});
}

/**
* Check that there is a message with the specified text that has the specified
* stack information.
* @param {WebConsole} hud
* @param {string} text
* message substring to look for
* @param {Array<number>} frameLines
* line numbers of the frames expected in the stack
*/
async function checkMessageStack(hud, text, frameLines) {
const msgNode = await waitFor(() => findMessage(hud, text));
ok(!msgNode.classList.contains("open"), `Error logged not expanded`);

const button = msgNode.querySelector(".collapse-button");
button.click();

const framesNode = await waitFor(() => msgNode.querySelector(".frames"));
const frameNodes = framesNode.querySelectorAll(".frame");
ok(frameNodes.length == frameLines.length, `Found ${frameLines.length} frames`);
for (let i = 0; i < frameLines.length; i++) {
ok(frameNodes[i].querySelector(".line").textContent == "" + frameLines[i],
`Found line ${frameLines[i]} for frame #${i}`);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
"use strict";
var w = new Worker("test-error-worker.js");
w.postMessage(1);
w.postMessage(2);
w.postMessage(3);
</script>
Loading

0 comments on commit ee39054

Please sign in to comment.