diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 090a2d486beb..dc8ecce90f63 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -194,6 +194,7 @@ #include "mozilla/dom/SelectionChangeEvent.h" +#include "mozilla/AddonPathService.h" #include "mozilla/Services.h" #include "mozilla/Telemetry.h" #include "nsLocation.h" @@ -2264,6 +2265,7 @@ CreateNativeGlobalForInner(JSContext* aCx, top = aNewInner->GetTop(); } JS::CompartmentOptions options; + options.setAddonId(MapURIToAddonID(aURI)); if (top) { if (top->GetGlobalJSObject()) { options.setSameZoneAs(top->GetGlobalJSObject()); diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index 35eedabb6415..fcbf337c9e98 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -346,6 +346,11 @@ XPCWrappedNativeScope::EnsureAddonScope(JSContext *cx, JSAddonId *addonId) MOZ_ASSERT(addonId); MOZ_ASSERT(nsContentUtils::IsSystemPrincipal(GetPrincipal())); + // If the global is already part of the add-on then there's no reason to + // create a new one. + if (AddonIdOfObject(global) == addonId) + return global; + // If we already have an addon scope object, we know what to use. for (size_t i = 0; i < mAddonScopes.Length(); i++) { if (JS::AddonIdOfObject(js::UncheckedUnwrap(mAddonScopes[i])) == addonId)