diff --git a/dom/workers/XMLHttpRequest.cpp b/dom/workers/XMLHttpRequest.cpp index 2265be93af2a..2d0bb23dfc12 100644 --- a/dom/workers/XMLHttpRequest.cpp +++ b/dom/workers/XMLHttpRequest.cpp @@ -1965,8 +1965,12 @@ XMLHttpRequest::Send(const nsAString& aBody, ErrorResult& aRv) void XMLHttpRequest::Send(JSObject* aBody, ErrorResult& aRv) { - mWorkerPrivate->AssertIsOnWorkerThread(); + JSContext* cx = mWorkerPrivate->GetJSContext(); + MOZ_ASSERT(aBody); + JS::Rooted body(cx, aBody); + + mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { aRv.Throw(UNCATCHABLE_EXCEPTION); @@ -1978,15 +1982,13 @@ XMLHttpRequest::Send(JSObject* aBody, ErrorResult& aRv) return; } - JSContext* cx = mWorkerPrivate->GetJSContext(); - JS::Rooted valToClone(cx); - if (JS_IsArrayBufferObject(aBody) || JS_IsArrayBufferViewObject(aBody) || - file::GetDOMBlobFromJSObject(aBody)) { - valToClone.setObject(*aBody); + if (JS_IsArrayBufferObject(body) || JS_IsArrayBufferViewObject(body) || + file::GetDOMBlobFromJSObject(body)) { + valToClone.setObject(*body); } else { - JS::Rooted obj(cx, JS::ObjectValue(*aBody)); + JS::Rooted obj(cx, JS::ObjectValue(*body)); JSString* bodyStr = JS::ToString(cx, obj); if (!bodyStr) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY);