Skip to content

Commit

Permalink
Bug 1438482 - logErrorInPage should produce an error log; r=bgrins,jr…
Browse files Browse the repository at this point in the history
…yans

MozReview-Commit-ID: Ly9kDNwGthG

--HG--
extra : rebase_source : e59e9c0fca83215dd834122ec4a38591a67c5b62
  • Loading branch information
janodvarko committed Feb 20, 2018
1 parent 62ad2cb commit d0c3503
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
32 changes: 30 additions & 2 deletions devtools/client/framework/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,34 @@ TabTarget.prototype = {
* The category of the message. @see nsIScriptError.
*/
logErrorInPage: function (text, category) {
if (this.activeTab && this.activeTab.traits.logErrorInPage) {
if (this.activeTab && this.activeTab.traits.logInPage) {
const errorFlag = 0;
let packet = {
to: this.form.actor,
type: "logErrorInPage",
type: "logInPage",
flags: errorFlag,
text,
category,
};
this.client.request(packet);
}
},

/**
* Log a warning of some kind to the tab's console.
*
* @param {String} text
* The text to log.
* @param {String} category
* The category of the message. @see nsIScriptError.
*/
logWarningInPage: function (text, category) {
if (this.activeTab && this.activeTab.traits.logInPage) {
const warningFlag = 1;
let packet = {
to: this.form.actor,
type: "logInPage",
flags: warningFlag,
text,
category,
};
Expand Down Expand Up @@ -887,4 +911,8 @@ WorkerTarget.prototype = {
logErrorInPage: function () {
// No-op. See bug 1368680.
},

logWarningInPage: function () {
// No-op. See bug 1368680.
},
};
6 changes: 3 additions & 3 deletions devtools/client/framework/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ Toolbox.prototype = {
let message = L10N.getFormatStr("toolbox.sourceMapFailure",
text, urlInfo.url,
urlInfo.sourceMapURL);
this.target.logErrorInPage(message, "source map");
this.target.logWarningInPage(message, "source map");
// It's ok to swallow errors here, because a null
// result just means that no source map was found.
return null;
Expand All @@ -622,7 +622,7 @@ Toolbox.prototype = {
.catch(text => {
let message = L10N.getFormatStr("toolbox.sourceMapSourceFailure",
text, originalSource.url);
this.target.logErrorInPage(message, "source map");
this.target.logWarningInPage(message, "source map");
// Also replace the result with the error text.
// Note that this result has to have the same form
// as whatever the upstream getOriginalSourceText
Expand Down Expand Up @@ -3082,7 +3082,7 @@ Toolbox.prototype = {
// once in order to receive `onRequestFinished` events.
let message = "The Network panel needs to be selected at least" +
" once in order to receive 'onRequestFinished' events.";
this.target.logErrorInPage(message, "har");
this.target.logWarningInPage(message, "har");

// Add the listener into internal list.
this._requestFinishedListeners.add(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ skip-if = true # Bug 1405343
[browser_webconsole_location_styleeditor_link.js]
[browser_webconsole_logErrorInPage.js]
[browser_webconsole_loglimit.js]
[browser_webconsole_logWarningInPage.js]
[browser_webconsole_longstring_expand.js]
skip-if = true # Bug 1403448
[browser_webconsole_longstring_hang.js]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ add_task(async function () {

const node = await waitFor(() => findMessage(hud, "octopus"));
ok(node, "text is displayed in web console");
ok(node.classList.contains("error"), "the log represents an error");
});
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/ */

"use strict";

// Test that we can log warning message to the web console from the toolbox.

const TEST_URI = "data:text/html;charset=utf-8,<p>test logErrorInPage";

add_task(async function () {
const hud = await openNewTabAndConsole(TEST_URI);
const toolbox = hud.ui.newConsoleOutput.toolbox;

toolbox.target.logWarningInPage("beware the octopus", "content javascript");

const node = await waitFor(() => findMessage(hud, "octopus"));
ok(node, "text is displayed in web console");
ok(node.classList.contains("warn"), "the log represents a warning");
});
2 changes: 1 addition & 1 deletion devtools/client/webconsole/new-webconsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ NewWebConsoleFrame.prototype = {
},

logWarningAboutReplacedAPI() {
this.owner.target.logErrorInPage(l10n.getStr("ConsoleAPIDisabled"),
this.owner.target.logWarningInPage(l10n.getStr("ConsoleAPIDisabled"),
"ConsoleAPIDisabled");
},

Expand Down
12 changes: 6 additions & 6 deletions devtools/server/actors/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ function TabActor(connection) {
// Do not require to send reconfigure request to reset the document state
// to what it was before using the TabActor
noTabReconfigureOnClose: true,
// Supports the logErrorInPage request.
logErrorInPage: true,
// Supports the logInPage request.
logInPage: true,
};

this._workerActorList = null;
Expand Down Expand Up @@ -656,11 +656,11 @@ TabActor.prototype = {
});
},

onLogErrorInPage(request) {
let {text, category} = request;
onLogInPage(request) {
let {text, category, flags} = request;
let scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
scriptError.initWithWindowID(text, null, null, 0, 0, 1,
scriptError.initWithWindowID(text, null, null, 0, 0, flags,
category, getInnerId(this.window));
Services.console.logMessage(scriptError);
return {};
Expand Down Expand Up @@ -1433,7 +1433,7 @@ TabActor.prototype.requestTypes = {
"switchToFrame": TabActor.prototype.onSwitchToFrame,
"listFrames": TabActor.prototype.onListFrames,
"listWorkers": TabActor.prototype.onListWorkers,
"logErrorInPage": TabActor.prototype.onLogErrorInPage,
"logInPage": TabActor.prototype.onLogInPage,
};

exports.TabActor = TabActor;
Expand Down

0 comments on commit d0c3503

Please sign in to comment.