Bug 1070696 - Rename xpc::GetNativeForGlobal to xpc::NativeGlobal and make it accept non-global JSObjects. r=smaug
The method is infallible, and making the callers invoke js::GetGlobalForObjectCrossCompartment manually is dumb.
This commit is contained in:
@@ -107,7 +107,7 @@ nsDOMFileReader::Init()
|
||||
// Instead of grabbing some random global from the context stack,
|
||||
// let's use the default one (junk scope) for now.
|
||||
// We should move away from this Init...
|
||||
BindToOwner(xpc::GetNativeForGlobal(xpc::PrivilegedJunkScope()));
|
||||
BindToOwner(xpc::NativeGlobal(xpc::PrivilegedJunkScope()));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -2154,7 +2154,7 @@ nsDocument::Init()
|
||||
// we use the default compartment for this document, instead of creating
|
||||
// wrapper in some random compartment when the document is exposed to js
|
||||
// via some events.
|
||||
nsCOMPtr<nsIGlobalObject> global = xpc::GetNativeForGlobal(xpc::PrivilegedJunkScope());
|
||||
nsCOMPtr<nsIGlobalObject> global = xpc::NativeGlobal(xpc::PrivilegedJunkScope());
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
|
||||
mScopeObject = do_GetWeakReference(global);
|
||||
MOZ_ASSERT(mScopeObject);
|
||||
|
||||
@@ -968,7 +968,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
||||
// }
|
||||
// JSContext* cx = aes.cx();
|
||||
nsIGlobalObject* nativeGlobal =
|
||||
xpc::GetNativeForGlobal(js::GetGlobalForObjectCrossCompartment(wrappedJS->GetJSObject()));
|
||||
xpc::NativeGlobal(js::GetGlobalForObjectCrossCompartment(wrappedJS->GetJSObject()));
|
||||
AutoEntryScript aes(nativeGlobal);
|
||||
JSContext* cx = aes.cx();
|
||||
JS::Rooted<JSObject*> object(cx, wrappedJS->GetJSObject());
|
||||
|
||||
@@ -352,7 +352,7 @@ nsXMLHttpRequest::Init()
|
||||
// Instead of grabbing some random global from the context stack,
|
||||
// let's use the default one (junk scope) for now.
|
||||
// We should move away from this Init...
|
||||
Construct(subjectPrincipal, xpc::GetNativeForGlobal(xpc::PrivilegedJunkScope()));
|
||||
Construct(subjectPrincipal, xpc::NativeGlobal(xpc::PrivilegedJunkScope()));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ GetIncumbentGlobal()
|
||||
// there's nothing on the JS stack, which will cause us to check the
|
||||
// incumbent script stack below.
|
||||
if (JSObject *global = JS::GetScriptedCallerGlobal(cx)) {
|
||||
return xpc::GetNativeForGlobal(global);
|
||||
return xpc::NativeGlobal(global);
|
||||
}
|
||||
|
||||
// Ok, nothing from the JS engine. Let's use whatever's on the
|
||||
@@ -175,7 +175,7 @@ GetCurrentGlobal()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return xpc::GetNativeForGlobal(global);
|
||||
return xpc::NativeGlobal(global);
|
||||
}
|
||||
|
||||
nsIPrincipal*
|
||||
|
||||
@@ -484,7 +484,7 @@ SystemErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
|
||||
}
|
||||
|
||||
if (!globalObject) {
|
||||
globalObject = xpc::GetNativeForGlobal(xpc::PrivilegedJunkScope());
|
||||
globalObject = xpc::NativeGlobal(xpc::PrivilegedJunkScope());
|
||||
}
|
||||
|
||||
if (globalObject) {
|
||||
@@ -2581,7 +2581,7 @@ NS_DOMReadStructuredClone(JSContext* cx,
|
||||
if (tag == SCTAG_DOM_IMAGEDATA) {
|
||||
return ReadStructuredCloneImageData(cx, reader);
|
||||
} else if (tag == SCTAG_DOM_WEBCRYPTO_KEY) {
|
||||
nsIGlobalObject *global = xpc::GetNativeForGlobal(JS::CurrentGlobalOrNull(cx));
|
||||
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(cx));
|
||||
if (!global) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ nsStructuredCloneContainer::InitFromJSVal(JS::Handle<JS::Value> aData)
|
||||
// part of the "own" "deep clone" sub-steps, so we need an AutoEntryScript.
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#internal-structured-cloning-algorithm
|
||||
nsIGlobalObject* nativeGlobal =
|
||||
xpc::GetNativeForGlobal(js::GetGlobalForObjectCrossCompartment(&aData.toObject()));
|
||||
xpc::NativeGlobal(js::GetGlobalForObjectCrossCompartment(&aData.toObject()));
|
||||
dom::AutoEntryScript aes(nativeGlobal);
|
||||
success = JS_WriteStructuredClone(aes.cx(), aData, &jsBytes, &mSize,
|
||||
nullptr, nullptr,
|
||||
|
||||
@@ -109,7 +109,7 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
|
||||
} else {
|
||||
// No DOM Window. Store the global and use the SafeJSContext.
|
||||
JSObject* glob = js::GetGlobalForObjectCrossCompartment(realCallback);
|
||||
globalObject = xpc::GetNativeForGlobal(glob);
|
||||
globalObject = xpc::NativeGlobal(glob);
|
||||
MOZ_ASSERT(globalObject);
|
||||
cx = nsContentUtils::GetSafeJSContext();
|
||||
}
|
||||
|
||||
@@ -1286,7 +1286,7 @@ public:
|
||||
mDataIsSet = false;
|
||||
|
||||
// Get the current global object from the context
|
||||
nsIGlobalObject *global = xpc::GetNativeForGlobal(JS::CurrentGlobalOrNull(aCx));
|
||||
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
|
||||
if (!global) {
|
||||
mEarlyRv = NS_ERROR_DOM_UNKNOWN_ERR;
|
||||
return;
|
||||
@@ -1955,7 +1955,7 @@ public:
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
nsIGlobalObject* global = xpc::GetNativeForGlobal(JS::CurrentGlobalOrNull(aCx));
|
||||
nsIGlobalObject* global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
|
||||
if (!global) {
|
||||
mEarlyRv = NS_ERROR_DOM_UNKNOWN_ERR;
|
||||
return;
|
||||
@@ -2082,7 +2082,7 @@ public:
|
||||
const ObjectOrString& aAlgorithm, bool aExtractable,
|
||||
const Sequence<nsString>& aKeyUsages)
|
||||
{
|
||||
nsIGlobalObject* global = xpc::GetNativeForGlobal(JS::CurrentGlobalOrNull(aCx));
|
||||
nsIGlobalObject* global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
|
||||
if (!global) {
|
||||
mEarlyRv = NS_ERROR_DOM_UNKNOWN_ERR;
|
||||
return;
|
||||
|
||||
@@ -1024,7 +1024,7 @@ Promise::MaybeReportRejected()
|
||||
|
||||
nsRefPtr<xpc::ErrorReport> xpcReport = new xpc::ErrorReport();
|
||||
if (MOZ_LIKELY(NS_IsMainThread())) {
|
||||
nsIGlobalObject* global = xpc::GetNativeForGlobal(js::GetGlobalForObjectCrossCompartment(obj));
|
||||
nsIGlobalObject* global = xpc::NativeGlobal(js::GetGlobalForObjectCrossCompartment(obj));
|
||||
xpcReport->Init(report.report(), report.message(), global);
|
||||
} else {
|
||||
xpcReport->InitOnWorkerThread(report.report(), report.message(),
|
||||
|
||||
@@ -70,7 +70,7 @@ TestShellCommandParent::RunCallback(const nsString& aResponse)
|
||||
|
||||
// We're about to run script via JS_CallFunctionValue, so we need an
|
||||
// AutoEntryScript. This is just for testing and not in any spec.
|
||||
dom::AutoEntryScript aes(xpc::GetNativeForGlobal(js::GetGlobalForObjectCrossCompartment(mCallback.ToJSObject())));
|
||||
dom::AutoEntryScript aes(xpc::NativeGlobal(js::GetGlobalForObjectCrossCompartment(mCallback.ToJSObject())));
|
||||
JSContext* cx = aes.cx();
|
||||
JS::Rooted<JSObject*> global(cx, JS::CurrentGlobalOrNull(cx));
|
||||
|
||||
|
||||
@@ -728,7 +728,7 @@ mozJSComponentLoader::PrepareObjectForLocation(JSContext* aCx,
|
||||
if (createdNewGlobal) {
|
||||
// AutoEntryScript required to invoke debugger hook, which is a
|
||||
// Gecko-specific concept at present.
|
||||
dom::AutoEntryScript aes(GetNativeForGlobal(holder->GetJSObject()));
|
||||
dom::AutoEntryScript aes(NativeGlobal(holder->GetJSObject()));
|
||||
RootedObject global(aes.cx(), holder->GetJSObject());
|
||||
JS_FireOnNewGlobalObject(aes.cx(), global);
|
||||
}
|
||||
@@ -1006,7 +1006,7 @@ mozJSComponentLoader::ObjectForLocation(ComponentLoaderInfo &aInfo,
|
||||
// We're going to run script via JS_ExecuteScriptVersion or
|
||||
// JS_CallFunction, so we need an AutoEntryScript.
|
||||
// This is Gecko-specific and not in any spec.
|
||||
dom::AutoEntryScript aes(GetNativeForGlobal(CurrentGlobalOrNull(cx)));
|
||||
dom::AutoEntryScript aes(NativeGlobal(CurrentGlobalOrNull(cx)));
|
||||
AutoSaveContextOptions asco(cx);
|
||||
if (aPropagateExceptions)
|
||||
ContextOptionsRef(cx).setDontReportUncaught(true);
|
||||
|
||||
@@ -489,7 +489,7 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
|
||||
// QI on an XPCWrappedJS can run script, so we need an AutoEntryScript.
|
||||
// This is inherently Gecko-specific.
|
||||
nsIGlobalObject* nativeGlobal =
|
||||
GetNativeForGlobal(js::GetGlobalForObjectCrossCompartment(self->GetJSObject()));
|
||||
NativeGlobal(js::GetGlobalForObjectCrossCompartment(self->GetJSObject()));
|
||||
AutoEntryScript aes(nativeGlobal, /* aIsMainThread = */ true);
|
||||
XPCCallContext ccx(NATIVE_CALLER, aes.cx());
|
||||
if (!ccx.IsValid()) {
|
||||
@@ -890,7 +890,7 @@ nsXPCWrappedJSClass::CallMethod(nsXPCWrappedJS* wrapper, uint16_t methodIndex,
|
||||
// AutoEntryScript. This is probably Gecko-specific at this point, and
|
||||
// definitely will be when we turn off XPConnect for the web.
|
||||
nsIGlobalObject* nativeGlobal =
|
||||
GetNativeForGlobal(js::GetGlobalForObjectCrossCompartment(wrapper->GetJSObject()));
|
||||
NativeGlobal(js::GetGlobalForObjectCrossCompartment(wrapper->GetJSObject()));
|
||||
AutoEntryScript aes(nativeGlobal, /* aIsMainThread = */ true);
|
||||
XPCCallContext ccx(NATIVE_CALLER, aes.cx());
|
||||
if (!ccx.IsValid())
|
||||
|
||||
@@ -1524,7 +1524,7 @@ SetAddonInterposition(const nsACString &addonIdStr, nsIAddonInterposition *inter
|
||||
// We enter the junk scope just to allocate a string, which actually will go
|
||||
// in the system zone.
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(xpc::GetNativeForGlobal(xpc::PrivilegedJunkScope()));
|
||||
jsapi.Init(xpc::NativeGlobal(xpc::PrivilegedJunkScope()));
|
||||
addonId = NewAddonId(jsapi.cx(), addonIdStr);
|
||||
if (!addonId)
|
||||
return false;
|
||||
|
||||
@@ -424,12 +424,6 @@ ReportJSRuntimeExplicitTreeStats(const JS::RuntimeStats &rtStats,
|
||||
bool
|
||||
Throw(JSContext *cx, nsresult rv);
|
||||
|
||||
/**
|
||||
* Every global should hold a native that implements the nsIGlobalObject interface.
|
||||
*/
|
||||
nsIGlobalObject *
|
||||
GetNativeForGlobal(JSObject *global);
|
||||
|
||||
/**
|
||||
* Returns the nsISupports native behind a given reflector (either DOM or
|
||||
* XPCWN).
|
||||
@@ -458,6 +452,12 @@ PrivilegedJunkScope();
|
||||
JSObject *
|
||||
CompilationScope();
|
||||
|
||||
/**
|
||||
* Returns the nsIGlobalObject corresponding to |aObj|'s JS global.
|
||||
*/
|
||||
nsIGlobalObject*
|
||||
NativeGlobal(JSObject *aObj);
|
||||
|
||||
/**
|
||||
* If |aObj| is a window, returns the associated nsGlobalWindow.
|
||||
* Otherwise, returns null.
|
||||
|
||||
@@ -644,9 +644,9 @@ TransplantObject(JSContext *cx, JS::HandleObject origobj, JS::HandleObject targe
|
||||
}
|
||||
|
||||
nsIGlobalObject *
|
||||
GetNativeForGlobal(JSObject *obj)
|
||||
NativeGlobal(JSObject *obj)
|
||||
{
|
||||
MOZ_ASSERT(JS_IsGlobalObject(obj));
|
||||
obj = js::GetGlobalForObjectCrossCompartment(obj);
|
||||
|
||||
// Every global needs to hold a native as its private or be a
|
||||
// WebIDL object with an nsISupports DOM object.
|
||||
|
||||
Reference in New Issue
Block a user