From 4897fac06f9fd0d7527e62ce797a981af0de6c3e Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Wed, 17 May 2017 14:07:03 -0700 Subject: [PATCH] Bug 1364047 - Pull WebConsoleUtils.l10n into its own module;r=Honza MozReview-Commit-ID: LI5Hrs33CVS --HG-- extra : rebase_source : 5da9d9ac8acf90f2446d1068589f1a4d314c0695 --- devtools/client/webconsole/console-output.js | 3 +- devtools/client/webconsole/hudservice.js | 3 +- devtools/client/webconsole/jsterm.js | 3 +- devtools/client/webconsole/moz.build | 5 +- .../test/components/console-api-call.test.js | 3 +- .../test/components/evaluation-result.test.js | 3 +- .../components/network-event-message.test.js | 3 +- .../test/components/page-error.test.js | 3 +- .../new-console-output/test/mochitest/head.js | 4 +- .../new-console-output/test/require-helper.js | 2 - .../new-console-output/utils/messages.js | 4 +- devtools/client/webconsole/test/head.js | 3 +- devtools/client/webconsole/utils.js | 63 ----------------- .../webconsole/webconsole-connection-proxy.js | 3 +- devtools/client/webconsole/webconsole-l10n.js | 70 +++++++++++++++++++ devtools/client/webconsole/webconsole.js | 3 +- devtools/client/webconsole/webpack.config.js | 1 + 17 files changed, 86 insertions(+), 93 deletions(-) create mode 100644 devtools/client/webconsole/webconsole-l10n.js diff --git a/devtools/client/webconsole/console-output.js b/devtools/client/webconsole/console-output.js index 353df6be45de..a87f742e22ba 100644 --- a/devtools/client/webconsole/console-output.js +++ b/devtools/client/webconsole/console-output.js @@ -19,12 +19,11 @@ loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/main", tr const { extend } = require("sdk/core/heritage"); const XHTML_NS = "http://www.w3.org/1999/xhtml"; const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; -const STRINGS_URI = "devtools/client/locales/webconsole.properties"; const WebConsoleUtils = require("devtools/client/webconsole/utils").Utils; const { getSourceNames } = require("devtools/client/shared/source-utils"); const {Task} = require("devtools/shared/task"); -const l10n = new WebConsoleUtils.L10n(STRINGS_URI); +const l10n = require("devtools/client/webconsole/webconsole-l10n"); const nodeConstants = require("devtools/shared/dom-node-constants"); const {PluralForm} = require("devtools/shared/plural-form"); diff --git a/devtools/client/webconsole/hudservice.js b/devtools/client/webconsole/hudservice.js index 2c3e9f6fabfe..b36658900842 100644 --- a/devtools/client/webconsole/hudservice.js +++ b/devtools/client/webconsole/hudservice.js @@ -22,8 +22,7 @@ loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/main", loader.lazyRequireGetter(this, "showDoorhanger", "devtools/client/shared/doorhanger", true); loader.lazyRequireGetter(this, "viewSource", "devtools/client/shared/view-source"); -const STRINGS_URI = "devtools/client/locales/webconsole.properties"; -var l10n = new WebConsoleUtils.L10n(STRINGS_URI); +const l10n = require("devtools/client/webconsole/webconsole-l10n"); const BROWSER_CONSOLE_WINDOW_FEATURES = "chrome,titlebar,toolbar,centerscreen,resizable,dialog=no"; diff --git a/devtools/client/webconsole/jsterm.js b/devtools/client/webconsole/jsterm.js index 0da5a905a677..ddf9853b4c5e 100644 --- a/devtools/client/webconsole/jsterm.js +++ b/devtools/client/webconsole/jsterm.js @@ -27,8 +27,7 @@ loader.lazyImporter(this, "VariablesView", "resource://devtools/client/shared/wi loader.lazyImporter(this, "VariablesViewController", "resource://devtools/client/shared/widgets/VariablesViewController.jsm"); loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true); -const STRINGS_URI = "devtools/client/locales/webconsole.properties"; -var l10n = new WebConsoleUtils.L10n(STRINGS_URI); +const l10n = require("devtools/client/webconsole/webconsole-l10n"); // Constants used for defining the direction of JSTerm input history navigation. const HISTORY_BACK = -1; diff --git a/devtools/client/webconsole/moz.build b/devtools/client/webconsole/moz.build index da24b4b99a46..56c3cb89dae3 100644 --- a/devtools/client/webconsole/moz.build +++ b/devtools/client/webconsole/moz.build @@ -19,8 +19,9 @@ DevToolsModules( 'panel.js', 'utils.js', 'webconsole-connection-proxy.js', + 'webconsole-l10n.js', 'webconsole.js', ) -with Files('**'): - BUG_COMPONENT = ('Firefox', 'Developer Tools: Console') +with Files('**'): + BUG_COMPONENT = ('Firefox', 'Developer Tools: Console') diff --git a/devtools/client/webconsole/new-console-output/test/components/console-api-call.test.js b/devtools/client/webconsole/new-console-output/test/components/console-api-call.test.js index bcf353329b5d..78125dceea92 100644 --- a/devtools/client/webconsole/new-console-output/test/components/console-api-call.test.js +++ b/devtools/client/webconsole/new-console-output/test/components/console-api-call.test.js @@ -99,8 +99,7 @@ describe("ConsoleAPICall component:", () => { serviceContainer, timestampsVisible: true, })); - const L10n = require("devtools/client/webconsole/new-console-output/test/fixtures/L10n"); - const { timestampString } = new L10n(); + const { timestampString } = require("devtools/client/webconsole/webconsole-l10n"); expect(wrapper.find(".timestamp").text()).toBe(timestampString(message.timeStamp)); }); diff --git a/devtools/client/webconsole/new-console-output/test/components/evaluation-result.test.js b/devtools/client/webconsole/new-console-output/test/components/evaluation-result.test.js index 742e48675cf0..d334ba8995fa 100644 --- a/devtools/client/webconsole/new-console-output/test/components/evaluation-result.test.js +++ b/devtools/client/webconsole/new-console-output/test/components/evaluation-result.test.js @@ -97,8 +97,7 @@ describe("EvaluationResult component:", () => { message, timestampsVisible: true, })); - const L10n = require("devtools/client/webconsole/new-console-output/test/fixtures/L10n"); - const { timestampString } = new L10n(); + const { timestampString } = require("devtools/client/webconsole/webconsole-l10n"); expect(wrapper.find(".timestamp").text()).toBe(timestampString(message.timeStamp)); }); diff --git a/devtools/client/webconsole/new-console-output/test/components/network-event-message.test.js b/devtools/client/webconsole/new-console-output/test/components/network-event-message.test.js index 02aa0103a1bf..20cfa5079e80 100644 --- a/devtools/client/webconsole/new-console-output/test/components/network-event-message.test.js +++ b/devtools/client/webconsole/new-console-output/test/components/network-event-message.test.js @@ -29,8 +29,7 @@ describe("NetworkEventMessage component:", () => { serviceContainer, timestampsVisible: true, })); - const L10n = require("devtools/client/webconsole/new-console-output/test/fixtures/L10n"); - const { timestampString } = new L10n(); + const { timestampString } = require("devtools/client/webconsole/webconsole-l10n"); expect(wrapper.find(".timestamp").text()).toBe(timestampString(message.timeStamp)); expect(wrapper.find(".message-body .method").text()).toBe("GET"); diff --git a/devtools/client/webconsole/new-console-output/test/components/page-error.test.js b/devtools/client/webconsole/new-console-output/test/components/page-error.test.js index 8b6a4c497f55..fda157bea969 100644 --- a/devtools/client/webconsole/new-console-output/test/components/page-error.test.js +++ b/devtools/client/webconsole/new-console-output/test/components/page-error.test.js @@ -32,8 +32,7 @@ describe("PageError component:", () => { serviceContainer, timestampsVisible: true, })); - const L10n = require("devtools/client/webconsole/new-console-output/test/fixtures/L10n"); - const { timestampString } = new L10n(); + const { timestampString } = require("devtools/client/webconsole/webconsole-l10n"); expect(wrapper.find(".timestamp").text()).toBe(timestampString(message.timeStamp)); diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/head.js b/devtools/client/webconsole/new-console-output/test/mochitest/head.js index 4ef934e1f043..46d974c2e7b4 100644 --- a/devtools/client/webconsole/new-console-output/test/mochitest/head.js +++ b/devtools/client/webconsole/new-console-output/test/mochitest/head.js @@ -14,9 +14,7 @@ Services.scriptloader.loadSubScript( "chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js", this); -var {Utils: WebConsoleUtils} = require("devtools/client/webconsole/utils"); -const WEBCONSOLE_STRINGS_URI = "devtools/client/locales/webconsole.properties"; -var WCUL10n = new WebConsoleUtils.L10n(WEBCONSOLE_STRINGS_URI); +var WCUL10n = require("devtools/client/webconsole/webconsole-l10n"); Services.prefs.setBoolPref("devtools.webconsole.new-frontend-enabled", true); registerCleanupFunction(function* () { diff --git a/devtools/client/webconsole/new-console-output/test/require-helper.js b/devtools/client/webconsole/new-console-output/test/require-helper.js index 5d9a380aba51..fdb2c98983f4 100644 --- a/devtools/client/webconsole/new-console-output/test/require-helper.js +++ b/devtools/client/webconsole/new-console-output/test/require-helper.js @@ -27,8 +27,6 @@ requireHacker.global_hook("default", path => { // Some modules depend on Chrome APIs which don't work in mocha. When such a module // is required, replace it with a mock version. switch (path) { - case "devtools/client/webconsole/utils": - return `module.exports = require("devtools/client/webconsole/new-console-output/test/fixtures/WebConsoleUtils")`; case "devtools/shared/l10n": return `module.exports = require("devtools/client/webconsole/new-console-output/test/fixtures/LocalizationHelper")`; case "devtools/shared/plural-form": diff --git a/devtools/client/webconsole/new-console-output/utils/messages.js b/devtools/client/webconsole/new-console-output/utils/messages.js index 32b1b6d26bf4..536773ce4eb7 100644 --- a/devtools/client/webconsole/new-console-output/utils/messages.js +++ b/devtools/client/webconsole/new-console-output/utils/messages.js @@ -6,9 +6,7 @@ "use strict"; -const WebConsoleUtils = require("devtools/client/webconsole/utils").Utils; -const STRINGS_URI = "devtools/client/locales/webconsole.properties"; -const l10n = new WebConsoleUtils.L10n(STRINGS_URI); +const l10n = require("devtools/client/webconsole/webconsole-l10n"); const { MESSAGE_SOURCE, diff --git a/devtools/client/webconsole/test/head.js b/devtools/client/webconsole/test/head.js index f46b85f558fc..f997c654c604 100644 --- a/devtools/client/webconsole/test/head.js +++ b/devtools/client/webconsole/test/head.js @@ -37,8 +37,7 @@ const SEVERITY_LOG = 3; // The indent of a console group in pixels. const GROUP_INDENT = 12; -const WEBCONSOLE_STRINGS_URI = "devtools/client/locales/webconsole.properties"; -var WCUL10n = new WebConsoleUtils.L10n(WEBCONSOLE_STRINGS_URI); +var WCUL10n = require("devtools/client/webconsole/webconsole-l10n"); const DOCS_GA_PARAMS = "?utm_source=mozilla" + "&utm_medium=firefox-console-errors" + diff --git a/devtools/client/webconsole/utils.js b/devtools/client/webconsole/utils.js index 8f9ce52e8475..ccf836df48a0 100644 --- a/devtools/client/webconsole/utils.js +++ b/devtools/client/webconsole/utils.js @@ -8,7 +8,6 @@ const {Cc, Ci} = require("chrome"); const Services = require("Services"); -const {LocalizationHelper} = require("devtools/shared/l10n"); // Match the function name from the result of toString() or toSource(). // @@ -285,65 +284,3 @@ var WebConsoleUtils = { exports.Utils = WebConsoleUtils; -// Localization - -WebConsoleUtils.L10n = function (bundleURI) { - this._helper = new LocalizationHelper(bundleURI); -}; - -WebConsoleUtils.L10n.prototype = { - /** - * Generates a formatted timestamp string for displaying in console messages. - * - * @param integer [milliseconds] - * Optional, allows you to specify the timestamp in milliseconds since - * the UNIX epoch. - * @return string - * The timestamp formatted for display. - */ - timestampString: function (milliseconds) { - let d = new Date(milliseconds ? milliseconds : null); - let hours = d.getHours(), minutes = d.getMinutes(); - let seconds = d.getSeconds(); - milliseconds = d.getMilliseconds(); - let parameters = [hours, minutes, seconds, milliseconds]; - return this.getFormatStr("timestampFormat", parameters); - }, - - /** - * Retrieve a localized string. - * - * @param string name - * The string name you want from the Web Console string bundle. - * @return string - * The localized string. - */ - getStr: function (name) { - try { - return this._helper.getStr(name); - } catch (ex) { - console.error("Failed to get string: " + name); - throw ex; - } - }, - - /** - * Retrieve a localized string formatted with values coming from the given - * array. - * - * @param string name - * The string name you want from the Web Console string bundle. - * @param array array - * The array of values you want in the formatted string. - * @return string - * The formatted local string. - */ - getFormatStr: function (name, array) { - try { - return this._helper.getFormatStr(name, ...array); - } catch (ex) { - console.error("Failed to format string: " + name); - throw ex; - } - }, -}; diff --git a/devtools/client/webconsole/webconsole-connection-proxy.js b/devtools/client/webconsole/webconsole-connection-proxy.js index bfeed32d68ec..263e2b10da35 100644 --- a/devtools/client/webconsole/webconsole-connection-proxy.js +++ b/devtools/client/webconsole/webconsole-connection-proxy.js @@ -10,8 +10,7 @@ const {Utils: WebConsoleUtils} = require("devtools/client/webconsole/utils"); const defer = require("devtools/shared/defer"); const Services = require("Services"); -const STRINGS_URI = "devtools/client/locales/webconsole.properties"; -var l10n = new WebConsoleUtils.L10n(STRINGS_URI); +const l10n = require("devtools/client/webconsole/webconsole-l10n"); const PREF_CONNECTION_TIMEOUT = "devtools.debugger.remote-timeout"; // Web Console connection proxy diff --git a/devtools/client/webconsole/webconsole-l10n.js b/devtools/client/webconsole/webconsole-l10n.js new file mode 100644 index 000000000000..58efe4ed97aa --- /dev/null +++ b/devtools/client/webconsole/webconsole-l10n.js @@ -0,0 +1,70 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const {LocalizationHelper} = require("devtools/shared/l10n"); +const helper = new LocalizationHelper("devtools/client/locales/webconsole.properties"); + +const l10n = { + + /** + * Generates a formatted timestamp string for displaying in console messages. + * + * @param integer [milliseconds] + * Optional, allows you to specify the timestamp in milliseconds since + * the UNIX epoch. + * @return string + * The timestamp formatted for display. + */ + timestampString: function (milliseconds) { + let d = new Date(milliseconds ? milliseconds : null); + let hours = d.getHours(), minutes = d.getMinutes(); + let seconds = d.getSeconds(); + milliseconds = d.getMilliseconds(); + let parameters = [hours, minutes, seconds, milliseconds]; + return l10n.getFormatStr("timestampFormat", parameters); + }, + + /** + * Retrieve a localized string. + * + * @param string name + * The string name you want from the Web Console string bundle. + * @return string + * The localized string. + */ + getStr: function (name) { + try { + return helper.getStr(name); + } catch (ex) { + console.error("Failed to get string: " + name); + throw ex; + } + }, + + /** + * Retrieve a localized string formatted with values coming from the given + * array. + * + * @param string name + * The string name you want from the Web Console string bundle. + * @param array array + * The array of values you want in the formatted string. + * @return string + * The formatted local string. + */ + getFormatStr: function (name, array) { + try { + return helper.getFormatStr(name, ...array); + } catch (ex) { + console.error("Failed to format string: " + name); + throw ex; + } + }, +}; + +module.exports = l10n; diff --git a/devtools/client/webconsole/webconsole.js b/devtools/client/webconsole/webconsole.js index d17f1dc33aa1..935f80e4a35a 100644 --- a/devtools/client/webconsole/webconsole.js +++ b/devtools/client/webconsole/webconsole.js @@ -38,8 +38,7 @@ loader.lazyRequireGetter(this, "ZoomKeys", "devtools/client/shared/zoom-keys"); loader.lazyRequireGetter(this, "WebConsoleConnectionProxy", "devtools/client/webconsole/webconsole-connection-proxy", true); const {PluralForm} = require("devtools/shared/plural-form"); -const STRINGS_URI = "devtools/client/locales/webconsole.properties"; -var l10n = new WebConsoleUtils.L10n(STRINGS_URI); +const l10n = require("devtools/client/webconsole/webconsole-l10n"); const XHTML_NS = "http://www.w3.org/1999/xhtml"; diff --git a/devtools/client/webconsole/webpack.config.js b/devtools/client/webconsole/webpack.config.js index 9992feabe712..703232f39eee 100644 --- a/devtools/client/webconsole/webpack.config.js +++ b/devtools/client/webconsole/webpack.config.js @@ -49,6 +49,7 @@ webpackConfig.resolve = { "devtools/client/webconsole/utils": path.join(__dirname, "new-console-output/test/fixtures/WebConsoleUtils"), "devtools/client/webconsole/new-console-output": path.join(__dirname, "new-console-output"), "devtools/client/webconsole/webconsole-connection-proxy": path.join(__dirname, "webconsole-connection-proxy"), + "devtools/client/webconsole/webconsole-l10n": path.join(__dirname, "webconsole-l10n"), "react": path.join(__dirname, "node_modules/react"), "devtools/client/shared/vendor/immutable": "immutable",