From 1b915490b54e4c17c718a499767f6b1ca037fe63 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Sat, 23 Apr 2016 17:51:14 -0700 Subject: [PATCH] Bug 1280362 - Move newGlobal's browser polyfill into shell.js, as the first step of unifying shell.js/browser.js. r=arai --HG-- extra : rebase_source : 7e26155a9d83ed7d9f99b823c86e9697bb5e018b --- js/src/tests/browser.js | 39 +++++++++++++++++++++++++++++---------- js/src/tests/shell.js | 2 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/js/src/tests/browser.js b/js/src/tests/browser.js index 2f55c563e000..ea6df673f03e 100644 --- a/js/src/tests/browser.js +++ b/js/src/tests/browser.js @@ -3,6 +3,35 @@ * 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/. */ +// NOTE: If you're adding new test harness functionality to this file -- first, +// should you at all? Most stuff is better in specific tests, or in +// nested shell.js/browser.js. Second, can you instead add it to +// shell.js? Our goal is to unify these two files for readability, and +// the plan is to empty out this file into that one over time. Third, +// supposing you must add to this file, please add it to this IIFE for +// better modularity/resilience against tests that must do particularly +// bizarre things that might break the harness. + +(function(global) { + /**************************** + * UTILITY FUNCTION EXPORTS * + ****************************/ + + var newGlobal = global.newGlobal; + if (typeof newGlobal !== "function") { + newGlobal = function newGlobal() { + var iframe = global.document.createElement("iframe"); + global.document.documentElement.appendChild(iframe); + var win = iframe.contentWindow; + iframe.remove(); + // Shim in "evaluate" + win.evaluate = win.eval; + return win; + }; + global.newGlobal = newGlobal; + } +})(this); + var gPageCompleted; var GLOBAL = this + ''; @@ -560,16 +589,6 @@ function closeDialog() } } -function newGlobal() { - var iframe = document.createElement("iframe"); - document.documentElement.appendChild(iframe); - var win = iframe.contentWindow; - iframe.remove(); - // Shim in "evaluate" - win.evaluate = win.eval; - return win; -} - registerDialogCloser(); window.addEventListener('unload', unregisterDialogCloser, true); diff --git a/js/src/tests/shell.js b/js/src/tests/shell.js index 258875ff7fe6..fe4af5b6501d 100644 --- a/js/src/tests/shell.js +++ b/js/src/tests/shell.js @@ -6,7 +6,7 @@ // NOTE: If you're adding new test harness functionality -- first, should you // at all? Most stuff is better in specific tests, or in nested shell.js // or browser.js. Second, supposing you should, please add it to this -// IIFE for better modularity/resilience against tests that have to do +// IIFE for better modularity/resilience against tests that must do // particularly bizarre things that might break the harness. (function(global) {