зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1260589 - Add the ThreadSafeDevToolsUtils.flatten utility; r=jimb a=kwierso
The `flatten` function takes an array of arrays and flattens them to a single array, removing one level of nesting. It does not recursively flatten multiple levels of nesting. MozReview-Commit-ID: ErDMHbT2IX --HG-- extra : histedit_source : eb6e4f8c54f536c84b08da22ef60cfa56a5075c8
This commit is contained in:
Родитель
ff953effdf
Коммит
546829d13e
|
@ -243,3 +243,14 @@ exports.isPromise = function (p) {
|
||||||
exports.isSavedFrame = function (thing) {
|
exports.isSavedFrame = function (thing) {
|
||||||
return Object.prototype.toString.call(thing) === "[object SavedFrame]";
|
return Object.prototype.toString.call(thing) === "[object SavedFrame]";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a list of lists, flatten it. Only flattens one level; does not
|
||||||
|
* recursively flatten all levels.
|
||||||
|
*
|
||||||
|
* @param {Array<Array<Any>>} lists
|
||||||
|
* @return {Array<Any>}
|
||||||
|
*/
|
||||||
|
exports.flatten = function(lists) {
|
||||||
|
return Array.prototype.concat.apply([], lists);
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
// Test ThreadSafeDevToolsUtils.flatten
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
const { flatten } = DevToolsUtils;
|
||||||
|
|
||||||
|
const flat = flatten([["a", "b", "c"],
|
||||||
|
["d", "e", "f"],
|
||||||
|
["g", "h", "i"]]);
|
||||||
|
|
||||||
|
equal(flat.length, 9);
|
||||||
|
equal(flat[0], "a");
|
||||||
|
equal(flat[1], "b");
|
||||||
|
equal(flat[2], "c");
|
||||||
|
equal(flat[3], "d");
|
||||||
|
equal(flat[4], "e");
|
||||||
|
equal(flat[5], "f");
|
||||||
|
equal(flat[6], "g");
|
||||||
|
equal(flat[7], "h");
|
||||||
|
equal(flat[8], "i");
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ support-files =
|
||||||
[test_fetch-file.js]
|
[test_fetch-file.js]
|
||||||
[test_fetch-http.js]
|
[test_fetch-http.js]
|
||||||
[test_fetch-resource.js]
|
[test_fetch-resource.js]
|
||||||
|
[test_flatten.js]
|
||||||
[test_indentation.js]
|
[test_indentation.js]
|
||||||
[test_independent_loaders.js]
|
[test_independent_loaders.js]
|
||||||
[test_invisible_loader.js]
|
[test_invisible_loader.js]
|
||||||
|
|
Загрузка…
Ссылка в новой задаче