Files
tubestation/devtools/shared/ThreadSafeDevToolsUtils.js
Nick Fitzgerald 3c27e3ee73 Bug 1235457 - Create ThreadSafeDevToolsUtils for the utilities that can be used in workers; r=jsantell
This commit adds the ThreadSafeDevToolsUtils module for utilities that are
guaranteed to work off the main thread. It also makes DevToolsUtils re-export
the thread-safe utilities. This is similar to ChromeUtils and
ThreadSafeChromeUtils webidl interfaces.
2015-12-30 09:37:01 -08:00

36 lines
1.1 KiB
JavaScript

/* 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";
/**
* General utilities used throughout devtools that can also be used in
* workers.
*/
/**
* Immutably reduce the given `...objs` into one object. The reduction is
* applied from left to right, so `immutableUpdate({ a: 1 }, { a: 2 })` will
* result in `{ a: 2 }`. The resulting object is frozen.
*
* Example usage:
*
* const original = { foo: 1, bar: 2, baz: 3 };
* const modified = immutableUpdate(original, { baz: 0, bang: 4 });
*
* // We get the new object that we expect...
* assert(modified.baz === 0);
* assert(modified.bang === 4);
*
* // However, the original is not modified.
* assert(original.baz === 2);
* assert(original.bang === undefined);
*
* @param {...Object} ...objs
* @returns {Object}
*/
exports.immutableUpdate = function (...objs) {
return Object.freeze(Object.assign({}, ...objs));
};