Bug 1365767 - Stop bootlegging TextEncoder and TextDecoder from osfile.jsm in devtools. r=jryans draft
authorAndrew McCreight <continuation@gmail.com>
Wed, 17 May 2017 13:52:39 -0700
changeset 580535 a21b04aca3c53b4d51fe5bf766eaa0eba943daed
parent 580534 af840142ab955187d417551e56bbefb012f8ee6f
child 580536 bd7998af0b5e67523f4e533ad728bdb603265745
child 580614 c2c9c6fe647ff3e42ba2c2fa34ad64d6c09de9d2
push id59611
push userbmo:continuation@gmail.com
push dateThu, 18 May 2017 18:14:41 +0000
reviewersjryans
bugs1365767
milestone55.0a1
Bug 1365767 - Stop bootlegging TextEncoder and TextDecoder from osfile.jsm in devtools. r=jryans MozReview-Commit-ID: DI4OqSGdzgl
devtools/.eslintrc.js
devtools/client/styleeditor/StyleSheetEditor.jsm
devtools/client/webide/modules/app-manager.js
devtools/client/webide/modules/build.js
devtools/client/webide/test/test_build.html
devtools/client/webide/test/test_manifestUpdate.html
devtools/shared/DevToolsUtils.js
devtools/shared/builtin-modules.js
devtools/shared/gcli/commands/cmd.js
--- a/devtools/.eslintrc.js
+++ b/devtools/.eslintrc.js
@@ -23,16 +23,18 @@ module.exports = {
     "loader": true,
     "module": true,
     "Node": true,
     "reportError": true,
     "require": true,
     "setInterval": true,
     "setTimeout": true,
     "uneval": true,
+    "TextDecoder": true,
+    "TextEncoder": true,
     "URL": true,
     "WebSocket": true,
     "XMLHttpRequest": true
   },
   "rules": {
     // These are the rules that have been configured so far to match the
     // devtools coding style.
 
--- a/devtools/client/styleeditor/StyleSheetEditor.jsm
+++ b/devtools/client/styleeditor/StyleSheetEditor.jsm
@@ -16,17 +16,17 @@ const Editor = require("devtools/client/
 const promise = require("promise");
 const {shortSource, prettifyCSS} = require("devtools/shared/inspector/css-logic");
 const {console} = require("resource://gre/modules/Console.jsm");
 const Services = require("Services");
 const EventEmitter = require("devtools/shared/event-emitter");
 const {Task} = require("devtools/shared/task");
 const {FileUtils} = require("resource://gre/modules/FileUtils.jsm");
 const {NetUtil} = require("resource://gre/modules/NetUtil.jsm");
-const {TextDecoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
+const {OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
 const {
   getString,
   showFilePicker,
 } = require("resource://devtools/client/styleeditor/StyleEditorUtil.jsm");
 
 const LOAD_ERROR = "error-load";
 const SAVE_ERROR = "error-save";
 
--- a/devtools/client/webide/modules/app-manager.js
+++ b/devtools/client/webide/modules/app-manager.js
@@ -4,17 +4,17 @@
 
 const {Cu} = require("chrome");
 
 const promise = require("promise");
 const {TargetFactory} = require("devtools/client/framework/target");
 const Services = require("Services");
 const {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", {});
 const EventEmitter = require("devtools/shared/event-emitter");
-const {TextEncoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
+const {OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
 const {AppProjects} = require("devtools/client/webide/modules/app-projects");
 const TabStore = require("devtools/client/webide/modules/tab-store");
 const {AppValidator} = require("devtools/client/webide/modules/app-validator");
 const {ConnectionManager, Connection} = require("devtools/shared/client/connection-manager");
 const {AppActorFront} = require("devtools/shared/apps/app-actor-front");
 const {getDeviceFront} = require("devtools/shared/fronts/device");
 const {getPreferenceFront} = require("devtools/shared/fronts/preference");
 const {Task} = require("devtools/shared/task");
--- a/devtools/client/webide/modules/build.js
+++ b/devtools/client/webide/modules/build.js
@@ -1,17 +1,17 @@
 /* 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/. */
 
 const {Cu, Cc, Ci} = require("chrome");
 
 const promise = require("promise");
 const { Task } = require("devtools/shared/task");
-const { TextDecoder, OS } = Cu.import("resource://gre/modules/osfile.jsm", {});
+const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {});
 const Subprocess = require("sdk/system/child_process/subprocess");
 
 const ProjectBuilding = exports.ProjectBuilding = {
   fetchPackageManifest: Task.async(function* (project) {
     let manifestPath = OS.Path.join(project.location, "package.json");
     let exists = yield OS.File.exists(manifestPath);
     if (!exists) {
       // No explicit manifest, try to generate one if possible
--- a/devtools/client/webide/test/test_build.html
+++ b/devtools/client/webide/test/test_build.html
@@ -13,17 +13,17 @@
   </head>
 
   <body>
 
     <script type="application/javascript">
       window.onload = function() {
         SimpleTest.waitForExplicitFinish();
 
-        let {TextDecoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
+        let {OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
         let {ProjectBuilding} = require("devtools/client/webide/modules/build");
 
         Task.spawn(function* () {
             let win = yield openWebIDE();
             let winProject = getProjectWindow(win);
             let AppManager = win.AppManager;
 
             function isProjectMarkedAsValid() {
--- a/devtools/client/webide/test/test_manifestUpdate.html
+++ b/devtools/client/webide/test/test_manifestUpdate.html
@@ -13,17 +13,17 @@
   </head>
 
   <body>
 
     <script type="application/javascript">
       window.onload = function() {
         SimpleTest.waitForExplicitFinish();
 
-        let {TextDecoder, OS}  = Cu.import("resource://gre/modules/osfile.jsm", {});
+        let {OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
 
         Task.spawn(function* () {
             let win = yield openWebIDE();
             let winProject = getProjectWindow(win);
             let AppManager = win.AppManager;
 
             function isProjectMarkedAsValid() {
               let details = win.frames[1];
--- a/devtools/shared/DevToolsUtils.js
+++ b/devtools/shared/DevToolsUtils.js
@@ -358,20 +358,16 @@ exports.defineLazyModuleGetter = functio
 DevToolsUtils.defineLazyGetter(this, "NetUtil", () => {
   return Cu.import("resource://gre/modules/NetUtil.jsm", {}).NetUtil;
 });
 
 DevToolsUtils.defineLazyGetter(this, "OS", () => {
   return Cu.import("resource://gre/modules/osfile.jsm", {}).OS;
 });
 
-DevToolsUtils.defineLazyGetter(this, "TextDecoder", () => {
-  return Cu.import("resource://gre/modules/osfile.jsm", {}).TextDecoder;
-});
-
 DevToolsUtils.defineLazyGetter(this, "NetworkHelper", () => {
   return require("devtools/shared/webconsole/network-helper");
 });
 
 /**
  * Performs a request to load the desired URL and returns a promise.
  *
  * @param urlIn String
--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -15,17 +15,17 @@
 
 const { Cu, CC, Cc, Ci } = require("chrome");
 const { Loader } = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {});
 const promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
 const jsmScope = Cu.import("resource://gre/modules/Services.jsm", {});
 const { Services } = jsmScope;
 // Steal various globals only available in JSM scope (and not Sandbox one)
 const { PromiseDebugging, ChromeUtils, ThreadSafeChromeUtils, HeapSnapshot,
-        atob, btoa } = jsmScope;
+        atob, btoa, TextEncoder, TextDecoder } = jsmScope;
 const { URL } = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
                            {wantGlobalProperties: ["URL"]});
 
 /**
  * Defines a getter on a specified object that will be created upon first use.
  *
  * @param object
  *        The object to define the lazy getter on.
@@ -210,16 +210,18 @@ defineLazyGetter(exports.modules, "FileR
 
 // List of all custom globals exposed to devtools modules.
 // Changes here should be mirrored to devtools/.eslintrc.
 exports.globals = {
   isWorker: false,
   reportError: Cu.reportError,
   atob: atob,
   btoa: btoa,
+  TextEncoder: TextEncoder,
+  TextDecoder: TextDecoder,
   URL,
   loader: {
     lazyGetter: defineLazyGetter,
     lazyImporter: defineLazyModuleGetter,
     lazyServiceGetter: defineLazyServiceGetter,
     lazyRequireGetter: lazyRequireGetter,
     // Defined by Loader.jsm
     id: null
--- a/devtools/shared/gcli/commands/cmd.js
+++ b/devtools/shared/gcli/commands/cmd.js
@@ -1,16 +1,16 @@
 /* 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 { Cc, Ci, Cu } = require("chrome");
-const { OS, TextDecoder } = Cu.import("resource://gre/modules/osfile.jsm", {});
+const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {});
 const { Task } = require("devtools/shared/task");
 
 const gcli = require("gcli/index");
 const l10n = require("gcli/l10n");
 
 loader.lazyGetter(this, "prefBranch", function () {
   let prefService = Cc["@mozilla.org/preferences-service;1"]
                       .getService(Ci.nsIPrefService);