зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1513277 part 2 - Use the scripted caller's global in mozJSComponentLoader::FindTargetObject. r=kmag
We have a few places where C++ calls ChromeUtils::Import directly. I fixed these to pass the target object directly instead of an empty Optional<>. Differential Revision: https://phabricator.services.mozilla.com/D14180 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
0326f72625
Коммит
eee34e39b3
|
@ -1,4 +1,4 @@
|
|||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);
|
||||
|
||||
ChromeUtils.defineModuleGetter(this, "PlacesUtils",
|
||||
"resource://gre/modules/PlacesUtils.jsm");
|
||||
|
|
|
@ -679,11 +679,12 @@ nsresult txEXSLTRegExFunctionCall::evaluate(txIEvalContext* aContext,
|
|||
JSAutoRealm ar(cx, sandbox);
|
||||
ErrorResult er;
|
||||
GlobalObject global(cx, sandbox);
|
||||
Optional<JS::HandleObject> targetObj(cx, sandbox);
|
||||
JS::RootedObject obj(cx);
|
||||
ChromeUtils::Import(
|
||||
global,
|
||||
NS_LITERAL_STRING("resource://gre/modules/txEXSLTRegExFunctions.jsm"),
|
||||
Optional<JS::HandleObject>(), &obj, er);
|
||||
targetObj, &obj, er);
|
||||
MOZ_ALWAYS_TRUE(!er.Failed());
|
||||
|
||||
JS::RootedString str(
|
||||
|
|
|
@ -84,6 +84,7 @@ static LazyLogModule gJSCLLog("JSComponentLoader");
|
|||
|
||||
// Components.utils.import error messages
|
||||
#define ERROR_SCOPE_OBJ "%s - Second argument must be an object."
|
||||
#define ERROR_NO_TARGET_OBJECT "%s - Couldn't find target object for import."
|
||||
#define ERROR_NOT_PRESENT "%s - EXPORTED_SYMBOLS is not present."
|
||||
#define ERROR_NOT_AN_ARRAY "%s - EXPORTED_SYMBOLS is not an array."
|
||||
#define ERROR_GETTING_ARRAY_LENGTH \
|
||||
|
@ -521,7 +522,13 @@ void mozJSComponentLoader::FindTargetObject(JSContext* aCx,
|
|||
// script, since it the FrameScript NSVO will have been found.
|
||||
if (!aTargetObject ||
|
||||
!IsLoaderGlobal(JS::GetNonCCWObjectGlobal(aTargetObject))) {
|
||||
aTargetObject.set(CurrentGlobalOrNull(aCx));
|
||||
aTargetObject.set(JS::GetScriptedCallerGlobal(aCx));
|
||||
|
||||
// Return nullptr if the scripted caller is in a different compartment.
|
||||
if (js::GetObjectCompartment(aTargetObject) !=
|
||||
js::GetContextCompartment(aCx)) {
|
||||
aTargetObject.set(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -993,6 +1000,10 @@ nsresult mozJSComponentLoader::ImportInto(const nsACString& registryLocation,
|
|||
}
|
||||
} else {
|
||||
FindTargetObject(cx, &targetObject);
|
||||
if (!targetObject) {
|
||||
return ReportOnCallerUTF8(cx, ERROR_NO_TARGET_OBJECT,
|
||||
PromiseFlatCString(registryLocation).get());
|
||||
}
|
||||
}
|
||||
|
||||
js::AssertSameCompartment(cx, targetObject);
|
||||
|
|
|
@ -4,8 +4,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/. */
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/Services.jsm", this);
|
||||
ChromeUtils.import("resource://gre/modules/NetUtil.jsm", this);
|
||||
|
||||
/* import-globals-from manifestLibrary.js */
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -433,9 +433,10 @@ void SetupDevtoolsSandbox() {
|
|||
|
||||
ErrorResult er;
|
||||
dom::GlobalObject global(cx, *gDevtoolsSandbox);
|
||||
dom::Optional<JS::HandleObject> targetObj(cx, *gDevtoolsSandbox);
|
||||
RootedObject obj(cx);
|
||||
dom::ChromeUtils::Import(global, NS_LITERAL_STRING(ReplayScriptURL),
|
||||
dom::Optional<HandleObject>(), &obj, er);
|
||||
targetObj, &obj, er);
|
||||
MOZ_RELEASE_ASSERT(!er.Failed());
|
||||
|
||||
gIncludeSystemScripts =
|
||||
|
|
|
@ -93,11 +93,12 @@ static void InitGraphicsSandbox() {
|
|||
|
||||
ErrorResult er;
|
||||
dom::GlobalObject global(cx, *gGraphicsSandbox);
|
||||
dom::Optional<JS::HandleObject> targetObj(cx, *gGraphicsSandbox);
|
||||
RootedObject obj(cx);
|
||||
dom::ChromeUtils::Import(
|
||||
global,
|
||||
NS_LITERAL_STRING("resource://devtools/server/actors/replay/graphics.js"),
|
||||
dom::Optional<HandleObject>(), &obj, er);
|
||||
targetObj, &obj, er);
|
||||
MOZ_RELEASE_ASSERT(!er.Failed());
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче