From b3a7aa44f6f40a7f63a3c2e069fe81a840f2df99 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 3 Mar 2015 21:01:58 -0500 Subject: [PATCH] Bug 1137591 part 2. Throw if someone does Cu.importGlobalProperties in a Window scope. r=bholley --- dom/contacts/tests/test_contacts_cache.xul | 1 - dom/contacts/tests/test_contacts_upgrade.xul | 1 - dom/indexedDB/test/chromeHelpers.js | 2 -- js/xpconnect/src/XPCComponents.cpp | 8 ++++++++ testing/specialpowers/content/specialpowersAPI.js | 4 +++- .../devtools/server/tests/mochitest/test_css-logic.html | 1 - 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dom/contacts/tests/test_contacts_cache.xul b/dom/contacts/tests/test_contacts_cache.xul index 700565733f97..e6da8e4e30a9 100644 --- a/dom/contacts/tests/test_contacts_cache.xul +++ b/dom/contacts/tests/test_contacts_cache.xul @@ -17,7 +17,6 @@ const { 'utils': Cu } = Components; Cu.import("resource://gre/modules/ContactDB.jsm", window); - Cu.importGlobalProperties(["indexedDB"]); let contactsDB = new ContactDB(); contactsDB.init(); diff --git a/dom/contacts/tests/test_contacts_upgrade.xul b/dom/contacts/tests/test_contacts_upgrade.xul index 54e6ee97f4e8..93d00d20dd25 100644 --- a/dom/contacts/tests/test_contacts_upgrade.xul +++ b/dom/contacts/tests/test_contacts_upgrade.xul @@ -142,7 +142,6 @@ const { 'utils': Cu } = Components; Cu.import("resource://gre/modules/ContactDB.jsm", window); - Cu.importGlobalProperties(["indexedDB"]); let cdb = new ContactDB(); cdb.init(); diff --git a/dom/indexedDB/test/chromeHelpers.js b/dom/indexedDB/test/chromeHelpers.js index cb86f2747ec6..de4213f6248b 100644 --- a/dom/indexedDB/test/chromeHelpers.js +++ b/dom/indexedDB/test/chromeHelpers.js @@ -10,8 +10,6 @@ let testGenerator = testSteps(); if (!window.runTest) { window.runTest = function() { - Cu.importGlobalProperties(["indexedDB"]); - SimpleTest.waitForExplicitFinish(); testGenerator.next(); diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index f981562caef5..56cca949cbd4 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -25,6 +25,7 @@ #include "mozilla/dom/DOMExceptionBinding.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/StructuredCloneTags.h" +#include "mozilla/dom/WindowBinding.h" #include "nsZipArchive.h" #include "nsIDOMFile.h" #include "nsIDOMFileList.h" @@ -2719,6 +2720,13 @@ nsXPCComponents_Utils::ImportGlobalProperties(HandleValue aPropertyList, { RootedObject global(cx, CurrentGlobalOrNull(cx)); MOZ_ASSERT(global); + + // Don't allow doing this if the global is a Window + nsGlobalWindow* win; + if (NS_SUCCEEDED(UNWRAP_OBJECT(Window, global, win))) { + return NS_ERROR_NOT_AVAILABLE; + } + GlobalProperties options; NS_ENSURE_TRUE(aPropertyList.isObject(), NS_ERROR_INVALID_ARG); RootedObject propertyList(cx, &aPropertyList.toObject()); diff --git a/testing/specialpowers/content/specialpowersAPI.js b/testing/specialpowers/content/specialpowersAPI.js index ed13564b2795..57e5ab8dab56 100644 --- a/testing/specialpowers/content/specialpowersAPI.js +++ b/testing/specialpowers/content/specialpowersAPI.js @@ -19,7 +19,9 @@ Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.importGlobalProperties(["File"]); +if (!this.File) { + Cu.importGlobalProperties(["File"]); +} // Allow stuff from this scope to be accessed from non-privileged scopes. This // would crash if used outside of automation. diff --git a/toolkit/devtools/server/tests/mochitest/test_css-logic.html b/toolkit/devtools/server/tests/mochitest/test_css-logic.html index ee40fd985161..99af93468357 100644 --- a/toolkit/devtools/server/tests/mochitest/test_css-logic.html +++ b/toolkit/devtools/server/tests/mochitest/test_css-logic.html @@ -15,7 +15,6 @@ Cu.import("resource://gre/modules/devtools/Loader.jsm"); const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); const {CssLogic} = devtools.require("devtools/styleinspector/css-logic"); -Cu.importGlobalProperties(['CSS']); window.onload = function() { SimpleTest.waitForExplicitFinish();