Bug 765168 - Remove the dependency of XHR::send on a cx parameter. r=smaug

Given the new bindings, I think this is dead code anyway modulo the pref.
This commit is contained in:
Bobby Holley 2012-06-20 12:18:39 +02:00
parent 53d09f54fe
commit 46527f944d
3 changed files with 25 additions and 2 deletions

View File

@ -1572,6 +1572,7 @@ public:
nsresult* aRv);
static JSContext *GetCurrentJSContext();
static JSContext *GetSafeJSContext();
/**
* Case insensitive comparison between two strings. However it only ignores

View File

@ -5454,6 +5454,13 @@ nsContentUtils::GetCurrentJSContext()
return cx;
}
/* static */
JSContext *
nsContentUtils::GetSafeJSContext()
{
return sThreadJSContextStack->GetSafeJSContext();
}
/* static */
nsresult
nsContentUtils::ASCIIToLower(nsAString& aStr)

View File

@ -2680,12 +2680,27 @@ GetRequestBody(nsIVariant* aBody, JSContext *aCx, nsIInputStream** aResult,
// ArrayBuffer?
jsval realVal;
nsCxPusher pusher;
JSAutoEnterCompartment ac;
JSObject* obj;
// If there's a context on the stack, we can just use it. Otherwise, we need
// to use the safe js context (and push it into the stack, so that it's
// visible to cx-less functions that we might call here).
JSContext* cx = nsContentUtils::GetCurrentJSContext();
if (!cx) {
cx = nsContentUtils::GetSafeJSContext();
if (!pusher.Push(cx)) {
return NS_ERROR_FAILURE;
}
}
nsresult rv = aBody->GetAsJSVal(&realVal);
if (NS_SUCCEEDED(rv) && !JSVAL_IS_PRIMITIVE(realVal) &&
(obj = JSVAL_TO_OBJECT(realVal)) &&
(JS_IsArrayBufferObject(obj, aCx))) {
ArrayBuffer buf(aCx, obj);
ac.enter(cx, obj) &&
(JS_IsArrayBufferObject(obj, cx))) {
ArrayBuffer buf(cx, obj);
return GetRequestBody(&buf, aResult, aContentType, aCharset);
}
}