Bug 1386584 - Remove JSM boilerplate in devtools/shared/platform/chrome/stack;r=ochameau
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 02 Aug 2017 13:24:14 +0200
changeset 422367 1014c8e695a6ea680917717b4caf9c8c26eab563
parent 422366 0d9b4108bf57c329f0f4ebb752b2592af0d67a44
child 422368 76dcd1e6797b48a6e4b061b6c1865ae037e24812
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1386584
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1386584 - Remove JSM boilerplate in devtools/shared/platform/chrome/stack;r=ochameau MozReview-Commit-ID: EgbKH70NsM9
devtools/shared/platform/chrome/stack.js
--- a/devtools/shared/platform/chrome/stack.js
+++ b/devtools/shared/platform/chrome/stack.js
@@ -2,74 +2,60 @@
  * 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/. */
 
 // A few wrappers for stack-manipulation.  This version of the module
 // is used in chrome code.
 
 "use strict";
 
-(function (factory) {
-  // This file might be require()d, but might also be loaded via
-  // Cu.import.  Account for the differences here.
-  if (this.module && module.id.indexOf("stack") >= 0) {
-    // require.
-    const {components, Cu} = require("chrome");
-    factory.call(this, components, Cu, exports);
-  } else {
-    // Cu.import.
-    this.isWorker = false;
-    factory.call(this, Components, Components.utils, this);
-    this.EXPORTED_SYMBOLS = ["callFunctionWithAsyncStack", "describeNthCaller",
-                             "getStack"];
+const { Cu, components } = require("chrome");
+
+/**
+ * Return a description of the Nth caller, suitable for logging.
+ *
+ * @param {Number} n the caller to describe
+ * @return {String} a description of the nth caller.
+ */
+function describeNthCaller(n) {
+  if (isWorker) {
+    return "";
   }
-}).call(this, function (components, Cu, exports) {
-  /**
-   * Return a description of the Nth caller, suitable for logging.
-   *
-   * @param {Number} n the caller to describe
-   * @return {String} a description of the nth caller.
-   */
-  function describeNthCaller(n) {
-    if (isWorker) {
-      return "";
-    }
 
-    let caller = components.stack;
-    // Do one extra iteration to skip this function.
-    while (n >= 0) {
-      --n;
-      caller = caller.caller;
-    }
-
-    let func = caller.name;
-    let file = caller.filename;
-    if (file.includes(" -> ")) {
-      file = caller.filename.split(/ -> /)[1];
-    }
-    let path = file + ":" + caller.lineNumber;
-
-    return func + "() -> " + path;
+  let caller = components.stack;
+  // Do one extra iteration to skip this function.
+  while (n >= 0) {
+    --n;
+    caller = caller.caller;
   }
 
-  /**
-   * Return a stack object that can be serialized and, when
-   * deserialized, passed to callFunctionWithAsyncStack.
-   */
-  function getStack() {
-    return components.stack.caller;
+  let func = caller.name;
+  let file = caller.filename;
+  if (file.includes(" -> ")) {
+    file = caller.filename.split(/ -> /)[1];
   }
+  let path = file + ":" + caller.lineNumber;
+
+  return func + "() -> " + path;
+}
 
-  /**
-   * Like Cu.callFunctionWithAsyncStack but handles the isWorker case
-   * -- |Cu| isn't defined in workers.
-   */
-  function callFunctionWithAsyncStack(callee, stack, id) {
-    if (isWorker) {
-      return callee();
-    }
-    return Cu.callFunctionWithAsyncStack(callee, stack, id);
+/**
+ * Return a stack object that can be serialized and, when
+ * deserialized, passed to callFunctionWithAsyncStack.
+ */
+function getStack() {
+  return components.stack.caller;
+}
+
+/**
+ * Like Cu.callFunctionWithAsyncStack but handles the isWorker case
+ * -- |Cu| isn't defined in workers.
+ */
+function callFunctionWithAsyncStack(callee, stack, id) {
+  if (isWorker) {
+    return callee();
   }
+  return Cu.callFunctionWithAsyncStack(callee, stack, id);
+}
 
-  exports.callFunctionWithAsyncStack = callFunctionWithAsyncStack;
-  exports.describeNthCaller = describeNthCaller;
-  exports.getStack = getStack;
-});
+exports.callFunctionWithAsyncStack = callFunctionWithAsyncStack;
+exports.describeNthCaller = describeNthCaller;
+exports.getStack = getStack;