summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/content/utils.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/debugger/content/utils.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/debugger/content/utils.js')
-rw-r--r--devtools/client/debugger/content/utils.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/devtools/client/debugger/content/utils.js b/devtools/client/debugger/content/utils.js
new file mode 100644
index 000000000..59993e9b4
--- /dev/null
+++ b/devtools/client/debugger/content/utils.js
@@ -0,0 +1,88 @@
+/* -*- 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 { reportException } = require("devtools/shared/DevToolsUtils");
+const { Task } = require("devtools/shared/task");
+
+function asPaused(client, func) {
+ if (client.state != "paused") {
+ return Task.spawn(function* () {
+ yield client.interrupt();
+ let result;
+
+ try {
+ result = yield func();
+ }
+ catch (e) {
+ // Try to put the debugger back in a working state by resuming
+ // it
+ yield client.resume();
+ throw e;
+ }
+
+ yield client.resume();
+ return result;
+ });
+ } else {
+ return func();
+ }
+}
+
+function handleError(err) {
+ reportException("promise", err.toString());
+}
+
+function onReducerEvents(controller, listeners, thisContext) {
+ Object.keys(listeners).forEach(name => {
+ const listener = listeners[name];
+ controller.onChange(name, payload => {
+ listener.call(thisContext, payload);
+ });
+ });
+}
+
+function _getIn(destObj, path) {
+ return path.reduce(function (acc, name) {
+ return acc[name];
+ }, destObj);
+}
+
+function mergeIn(destObj, path, value) {
+ path = [...path];
+ path.reverse();
+ var obj = path.reduce(function (acc, name) {
+ return { [name]: acc };
+ }, value);
+
+ return destObj.merge(obj, { deep: true });
+}
+
+function setIn(destObj, path, value) {
+ destObj = mergeIn(destObj, path, null);
+ return mergeIn(destObj, path, value);
+}
+
+function updateIn(destObj, path, fn) {
+ return setIn(destObj, path, fn(_getIn(destObj, path)));
+}
+
+function deleteIn(destObj, path) {
+ const objPath = path.slice(0, -1);
+ const propName = path[path.length - 1];
+ const obj = _getIn(destObj, objPath);
+ return setIn(destObj, objPath, obj.without(propName));
+}
+
+module.exports = {
+ asPaused,
+ handleError,
+ onReducerEvents,
+ mergeIn,
+ setIn,
+ updateIn,
+ deleteIn
+};