Bug 1378850 - Stop using sdk/core/heritage in DevTools webconsole hudservice; r=zer0, sole draft
authorJan Odvarko <odvarko@gmail.com>
Fri, 07 Jul 2017 13:37:56 +0200
changeset 611363 cf95e82da710221db1a969ee56aa2300e24d73e1
parent 611331 c5ea72577f794635a334a30780d104a1d89267a0
child 638140 22d180d18a67c980e5ac03d2595ae5af2e08d28b
push id69198
push userjodvarko@mozilla.com
push dateWed, 19 Jul 2017 16:30:21 +0000
reviewerszer0, sole
bugs1378850
milestone56.0a1
Bug 1378850 - Stop using sdk/core/heritage in DevTools webconsole hudservice; r=zer0, sole MozReview-Commit-ID: GWH1hYt3pUr
devtools/client/inspector/markup/utils.js
devtools/client/inspector/markup/views/element-container.js
devtools/client/inspector/markup/views/read-only-container.js
devtools/client/inspector/markup/views/text-container.js
devtools/client/webconsole/console-output.js
devtools/client/webconsole/hudservice.js
devtools/shared/extend.js
devtools/shared/moz.build
--- a/devtools/client/inspector/markup/utils.js
+++ b/devtools/client/inspector/markup/utils.js
@@ -1,41 +1,14 @@
 /* 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 getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
-
-function* getNames(x) {
-  yield* Object.getOwnPropertyNames(x);
-  yield* Object.getOwnPropertySymbols(x);
-}
-
-// Utility function to get own properties descriptor map.
-function getOwnPropertyDescriptors(...objects) {
-  let descriptors = {};
-  for (let object of objects) {
-    for (let name of getNames(object)) {
-      descriptors[name] = getOwnPropertyDescriptor(object, name);
-    }
-  }
-  return descriptors;
-}
-
-/**
- * Returns a frozen object with that inherits from the given `prototype` and
- * implements all own properties of the given `properties` object.
- */
-function extend(prototype, properties) {
-  return Object.create(prototype,
-                       getOwnPropertyDescriptors(properties));
-}
-
 /**
  * Apply a 'flashed' background and foreground color to elements. Intended
  * to be used with flashElementOff as a way of drawing attention to an element.
  *
  * @param  {Node} backgroundElt
  *         The element to set the highlighted background color on.
  * @param  {Node} foregroundElt
  *         The element to set the matching foreground color on.
@@ -59,17 +32,17 @@ function flashElementOn(backgroundElt, f
   );
 }
 
 /**
  * Remove a 'flashed' background and foreground color to elements.
  * See flashElementOn.
  *
  * @param  {Node} backgroundElt
- *         The element to reomve the highlighted background color on.
+ *         The element to remove the highlighted background color on.
  * @param  {Node} foregroundElt
  *         The element to remove the matching foreground color on.
  *         Optional.  This will equal backgroundElt if not set.
  */
 function flashElementOff(backgroundElt, foregroundElt = backgroundElt) {
   if (!backgroundElt || !foregroundElt) {
     return;
   }
@@ -149,15 +122,14 @@ function truncateString(str, maxLength) 
   }
 
   return str.substring(0, Math.ceil(maxLength / 2)) +
          "…" +
          str.substring(str.length - Math.floor(maxLength / 2));
 }
 
 module.exports = {
-  extend,
   flashElementOn,
   flashElementOff,
   getAutocompleteMaxWidth,
   parseAttributeValues,
   truncateString,
 };
--- a/devtools/client/inspector/markup/views/element-container.js
+++ b/devtools/client/inspector/markup/views/element-container.js
@@ -10,17 +10,17 @@ const promise = require("promise");
 const Services = require("Services");
 const {Task} = require("devtools/shared/task");
 const nodeConstants = require("devtools/shared/dom-node-constants");
 const clipboardHelper = require("devtools/shared/platform/clipboard");
 const {setImageTooltip, setBrokenImageTooltip} =
       require("devtools/client/shared/widgets/tooltip/ImageTooltipHelper");
 const MarkupContainer = require("devtools/client/inspector/markup/views/markup-container");
 const ElementEditor = require("devtools/client/inspector/markup/views/element-editor");
-const {extend} = require("devtools/client/inspector/markup/utils");
+const {extend} = require("devtools/shared/extend");
 
 // Lazy load this module as _buildEventTooltipContent is only called on click
 loader.lazyRequireGetter(this, "setEventTooltip",
   "devtools/client/shared/widgets/tooltip/EventTooltipHelper", true);
 
 /**
  * An implementation of MarkupContainer for Elements that can contain
  * child nodes.
--- a/devtools/client/inspector/markup/views/read-only-container.js
+++ b/devtools/client/inspector/markup/views/read-only-container.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/. */
 
 "use strict";
 
 const ReadOnlyEditor = require("devtools/client/inspector/markup/views/read-only-editor");
 const MarkupContainer = require("devtools/client/inspector/markup/views/markup-container");
-const {extend} = require("devtools/client/inspector/markup/utils");
+const {extend} = require("devtools/shared/extend");
 
 /**
  * An implementation of MarkupContainer for Pseudo Elements,
  * Doctype nodes, or any other type generic node that doesn't
  * fit for other editors.
  * Does not allow any editing, just viewing / selecting.
  *
  * @param  {MarkupView} markupView
--- a/devtools/client/inspector/markup/views/text-container.js
+++ b/devtools/client/inspector/markup/views/text-container.js
@@ -2,17 +2,17 @@
  * 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 nodeConstants = require("devtools/shared/dom-node-constants");
 const TextEditor = require("devtools/client/inspector/markup/views/text-editor");
 const MarkupContainer = require("devtools/client/inspector/markup/views/markup-container");
-const {extend} = require("devtools/client/inspector/markup/utils");
+const {extend} = require("devtools/shared/extend");
 
 /**
  * An implementation of MarkupContainer for text node and comment nodes.
  * Allows basic text editing in a textarea.
  *
  * @param  {MarkupView} markupView
  *         The markup view that owns this container.
  * @param  {NodeFront} node
--- a/devtools/client/webconsole/console-output.js
+++ b/devtools/client/webconsole/console-output.js
@@ -19,25 +19,23 @@ loader.lazyRequireGetter(this, "ObjectCl
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
 
 const WebConsoleUtils = require("devtools/client/webconsole/utils").Utils;
 const { getSourceNames } = require("devtools/client/shared/source-utils");
 const {Task} = require("devtools/shared/task");
 const l10n = require("devtools/client/webconsole/webconsole-l10n");
 const nodeConstants = require("devtools/shared/dom-node-constants");
 const {PluralForm} = require("devtools/shared/plural-form");
+const {extend} = require("devtools/shared/extend");
 
 const MAX_STRING_GRIP_LENGTH = 36;
 const {ELLIPSIS} = require("devtools/shared/l10n");
 
 const validProtocols = /^(http|https|ftp|data|javascript|resource|chrome):/i;
 
-const extend = (prototype, properties) =>
-  Object.create(prototype, Object.getOwnPropertyDescriptors(properties));
-
 // Constants for compatibility with the Web Console output implementation before
 // bug 778766.
 // TODO: remove these once bug 778766 is fixed.
 const COMPAT = {
   // The various categories of messages.
   CATEGORIES: {
     NETWORK: 0,
     CSS: 1,
--- a/devtools/client/webconsole/hudservice.js
+++ b/devtools/client/webconsole/hudservice.js
@@ -1,18 +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");
-
 var WebConsoleUtils = require("devtools/client/webconsole/utils").Utils;
-var { extend } = require("sdk/core/heritage");
+const {extend} = require("devtools/shared/extend");
 var {TargetFactory} = require("devtools/client/framework/target");
 var {Tools} = require("devtools/client/definitions");
 const { Task } = require("devtools/shared/task");
 var promise = require("promise");
 var Services = require("Services");
 
 loader.lazyRequireGetter(this, "Telemetry", "devtools/client/shared/telemetry");
 loader.lazyRequireGetter(this, "WebConsoleFrame", "devtools/client/webconsole/webconsole", true);
new file mode 100644
--- /dev/null
+++ b/devtools/shared/extend.js
@@ -0,0 +1,15 @@
+/* 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";
+
+/**
+ * Utility function, that is useful for creating objects that inherit from other
+ * objects, without associated classes.
+ *
+ * Replacement for `extends` API from "sdk/core/heritage".
+ */
+exports.extend = function (prototype, properties) {
+  return Object.create(prototype, Object.getOwnPropertyDescriptors(properties));
+};
--- a/devtools/shared/moz.build
+++ b/devtools/shared/moz.build
@@ -47,25 +47,26 @@ DevToolsModules(
     'builtin-modules.js',
     'content-observer.js',
     'defer.js',
     'deprecated-sync-thenables.js',
     'DevToolsUtils.js',
     'dom-node-constants.js',
     'dom-node-filter-constants.js',
     'event-emitter.js',
+    'extend.js',
     'flags.js',
     'indentation.js',
     'l10n.js',
     'loader-plugin-raw.jsm',
     'Loader.jsm',
     'Parser.jsm',
     'path.js',
     'plural-form.js',
     'protocol.js',
     'system.js',
     'task.js',
     'ThreadSafeDevToolsUtils.js',
     'wasm-source-map.js',
 )
 
-with Files('**'):
-    BUG_COMPONENT = ('Firefox', 'Developer Tools')
+with Files('**'):
+    BUG_COMPONENT = ('Firefox', 'Developer Tools')