diff --git a/browser/metro/base/content/Util.js b/browser/metro/base/content/Util.js index 316e5c317fd8..dc7176747eb2 100644 --- a/browser/metro/base/content/Util.js +++ b/browser/metro/base/content/Util.js @@ -2,6 +2,8 @@ * 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/. */ +Components.utils.import("resource:///modules/ContentUtil.jsm"); + let Util = { /* * General purpose utilities @@ -37,44 +39,6 @@ let Util = { Services.io.offline = false; }, - // Pass several objects in and it will combine them all into the first object and return it. - // NOTE: Deep copy is not supported - extend: function extend() { - // copy reference to target object - let target = arguments[0] || {}; - let length = arguments.length; - - if (length === 1) { - return target; - } - - // Handle case when target is a string or something - if (typeof target != "object" && typeof target != "function") { - target = {}; - } - - for (let i = 1; i < length; i++) { - // Only deal with non-null/undefined values - let options = arguments[i]; - if (options != null) { - // Extend the base object - for (let name in options) { - let copy = options[name]; - - // Prevent never-ending loop - if (target === copy) - continue; - - if (copy !== undefined) - target[name] = copy; - } - } - } - - // Return the modified object - return target; - }, - /* * Timing utilties */ @@ -540,3 +504,11 @@ Util.Timeout.prototype = { } }; +// Mixin the ContentUtil module exports +{ + for (let name in ContentUtil) { + let copy = ContentUtil[name]; + if (copy !== undefined) + Util[name] = copy; + } +} diff --git a/browser/metro/base/tests/unit/test_util_extend.js b/browser/metro/base/tests/unit/test_util_extend.js index 2d32c9760804..a22ca7adbc5f 100644 --- a/browser/metro/base/tests/unit/test_util_extend.js +++ b/browser/metro/base/tests/unit/test_util_extend.js @@ -1,10 +1,10 @@ "use strict"; -load('Util.js'); +load("Util.js"); function run_test() { do_print("Testing Util.extend"); - + do_print("Check if function is defined"); do_check_true(!!Util.extend); @@ -14,7 +14,7 @@ function run_test() { let nullRes = Util.extend(null); do_check_true(nullRes && typeof nullRes == "object"); - + do_print("Simple extend"); let simpleExtend = {a: 1, b: 2}; let simpleExtendResult = Util.extend(simpleExtend, {b: 3, c: 4}); diff --git a/browser/metro/base/tests/unit/xpcshell.ini b/browser/metro/base/tests/unit/xpcshell.ini index 8d01cd7508fd..8cc41da1188c 100644 --- a/browser/metro/base/tests/unit/xpcshell.ini +++ b/browser/metro/base/tests/unit/xpcshell.ini @@ -1,5 +1,6 @@ [DEFAULT] -head = +head = tail = +firefox-appdir = metro [test_util_extend.js] diff --git a/browser/metro/modules/ContentUtil.jsm b/browser/metro/modules/ContentUtil.jsm new file mode 100644 index 000000000000..2b80a571f91b --- /dev/null +++ b/browser/metro/modules/ContentUtil.jsm @@ -0,0 +1,47 @@ +/* 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"; + +this.EXPORTED_SYMBOLS = ["ContentUtil"]; + +this.ContentUtil = { + // Pass several objects in and it will combine them all into the first object and return it. + // NOTE: Deep copy is not supported + extend: function extend() { + // copy reference to target object + let target = arguments[0] || {}; + let length = arguments.length; + + if (length === 1) { + return target; + } + + // Handle case when target is a string or something + if (typeof target != "object" && typeof target != "function") { + target = {}; + } + + for (let i = 1; i < length; i++) { + // Only deal with non-null/undefined values + let options = arguments[i]; + if (options != null) { + // Extend the base object + for (let name in options) { + let copy = options[name]; + + // Prevent never-ending loop + if (target === copy) + continue; + + if (copy !== undefined) + target[name] = copy; + } + } + } + + // Return the modified object + return target; + } + +}; diff --git a/browser/metro/modules/moz.build b/browser/metro/modules/moz.build index 835b2bd21f71..69f8f89b0809 100644 --- a/browser/metro/modules/moz.build +++ b/browser/metro/modules/moz.build @@ -5,6 +5,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. EXTRA_JS_MODULES += [ + 'ContentUtil.jsm', 'CrossSlide.jsm', 'View.jsm', 'colorUtils.jsm',