Bug 744910 - Remove FileException from workers. r=bent

This commit is contained in:
Masatoshi Kimura 2012-04-24 19:50:00 -04:00
parent cbad079392
commit 7a010701c4
11 changed files with 152 additions and 292 deletions

View File

@ -177,7 +177,7 @@ NSResultToNameAndMessage(nsresult aNSResult,
nsresult
NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, const char** aName,
const char** aMessage)
const char** aMessage, PRUint16* aCode)
{
const char* name = nsnull;
const char* message = nsnull;
@ -187,6 +187,9 @@ NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, const char** aName,
if (name && message) {
*aName = name;
*aMessage = message;
if (aCode) {
*aCode = code;
}
return NS_OK;
}

View File

@ -64,7 +64,8 @@ protected:
nsresult
NS_GetNameAndMessageForDOMNSResult(nsresult aNSResult, const char** aName,
const char** aMessage);
const char** aMessage,
PRUint16* aCode = nsnull);
#define DECL_INTERNAL_DOM_EXCEPTION(domname) \
nsresult \

View File

@ -8,6 +8,7 @@
#define mozilla_dom_bindings_Utils_h__
#include "mozilla/dom/bindings/DOMJSClass.h"
#include "mozilla/dom/workers/Workers.h"
#include "jsapi.h"
#include "jsfriendapi.h"
@ -25,12 +26,14 @@ template<bool mainThread>
inline bool
Throw(JSContext* cx, nsresult rv)
{
using mozilla::dom::workers::exceptions::ThrowDOMExceptionForNSResult;
// XXX Introduce exception machinery.
if (mainThread) {
XPCThrower::Throw(rv, cx);
} else {
if (!JS_IsExceptionPending(cx)) {
JS_ReportError(cx, "Exception thrown (nsresult = %x).", rv);
ThrowDOMExceptionForNSResult(cx, rv);
}
}
return false;

View File

@ -43,6 +43,7 @@
#include "jsfriendapi.h"
#include "jsprf.h"
#include "mozilla/Util.h"
#include "nsDOMException.h"
#include "nsTraceRefcnt.h"
#include "WorkerInlines.h"
@ -68,6 +69,7 @@ class DOMException : public PrivatizableBase
enum SLOT {
SLOT_code = 0,
SLOT_name,
SLOT_message,
SLOT_COUNT
};
@ -87,7 +89,7 @@ public:
}
static JSObject*
Create(JSContext* aCx, int aCode);
Create(JSContext* aCx, nsresult aNSResult);
private:
DOMException()
@ -131,18 +133,23 @@ private:
return false;
}
char buf[100];
JS_snprintf(buf, sizeof(buf), "%s: ", sClass.name);
jsval name = JS_GetReservedSlot(obj, SLOT_name);
JS_ASSERT(name.isString());
JSString* classString = JS_NewStringCopyZ(aCx, buf);
if (!classString) {
JSString *colon = JS_NewStringCopyN(aCx, ": ", 2);
if (!colon){
return false;
}
jsval name = JS_GetReservedSlot(obj, SLOT_name);
JS_ASSERT(JSVAL_IS_STRING(name));
JSString* out = JS_ConcatStrings(aCx, name.toString(), colon);
if (!out) {
return false;
}
JSString* out = JS_ConcatStrings(aCx, classString, JSVAL_TO_STRING(name));
jsval message = JS_GetReservedSlot(obj, SLOT_message);
JS_ASSERT(message.isString());
out = JS_ConcatStrings(aCx, out, message.toString());
if (!out) {
return false;
}
@ -190,6 +197,7 @@ JSClass DOMException::sClass = {
JSPropertySpec DOMException::sProperties[] = {
{ "code", SLOT_code, PROPERTY_FLAGS, GetProperty, js_GetterOnlyPropertyStub },
{ "name", SLOT_name, PROPERTY_FLAGS, GetProperty, js_GetterOnlyPropertyStub },
{ "message", SLOT_message, PROPERTY_FLAGS, GetProperty, js_GetterOnlyPropertyStub },
{ 0, 0, 0, NULL, NULL }
};
@ -203,9 +211,6 @@ JSPropertySpec DOMException::sStaticProperties[] = {
#define EXCEPTION_ENTRY(_name) \
{ #_name, _name, CONSTANT_FLAGS, GetConstant, NULL },
// Make sure this one is always first.
EXCEPTION_ENTRY(UNKNOWN_ERR)
EXCEPTION_ENTRY(INDEX_SIZE_ERR)
EXCEPTION_ENTRY(DOMSTRING_SIZE_ERR)
EXCEPTION_ENTRY(HIERARCHY_REQUEST_ERR)
@ -239,32 +244,35 @@ JSPropertySpec DOMException::sStaticProperties[] = {
// static
JSObject*
DOMException::Create(JSContext* aCx, int aCode)
DOMException::Create(JSContext* aCx, nsresult aNSResult)
{
JSObject* obj = JS_NewObject(aCx, &sClass, NULL, NULL);
if (!obj) {
return NULL;
}
size_t foundIndex = size_t(-1);
for (size_t index = 0; index < ArrayLength(sStaticProperties) - 1; index++) {
if (sStaticProperties[index].tinyid == aCode) {
foundIndex = index;
break;
}
}
if (foundIndex == size_t(-1)) {
foundIndex = 0;
}
JSString* name = JS_NewStringCopyZ(aCx, sStaticProperties[foundIndex].name);
if (!name) {
const char* name;
const char* message;
uint16_t code;
if (NS_FAILED(NS_GetNameAndMessageForDOMNSResult(aNSResult, &name, &message,
&code))) {
JS_ReportError(aCx, "Exception thrown (nsresult = 0x%x).", aNSResult);
return NULL;
}
JS_SetReservedSlot(obj, SLOT_code, INT_TO_JSVAL(aCode));
JS_SetReservedSlot(obj, SLOT_name, STRING_TO_JSVAL(name));
JSString* jsname = JS_NewStringCopyZ(aCx, name);
if (!jsname) {
return NULL;
}
JSString* jsmessage = JS_NewStringCopyZ(aCx, message);
if (!jsmessage) {
return NULL;
}
JS_SetReservedSlot(obj, SLOT_code, INT_TO_JSVAL(code));
JS_SetReservedSlot(obj, SLOT_name, STRING_TO_JSVAL(jsname));
JS_SetReservedSlot(obj, SLOT_message, STRING_TO_JSVAL(jsmessage));
DOMException* priv = new DOMException();
SetJSPrivateSafeish(obj, priv);
@ -272,147 +280,6 @@ DOMException::Create(JSContext* aCx, int aCode)
return obj;
}
class FileException : public PrivatizableBase
{
static JSClass sClass;
static JSPropertySpec sProperties[];
static JSPropertySpec sStaticProperties[];
enum SLOT {
SLOT_code = 0,
SLOT_name,
SLOT_COUNT
};
public:
static JSObject*
InitClass(JSContext* aCx, JSObject* aObj)
{
return JS_InitClass(aCx, aObj, NULL, &sClass, Construct, 0, sProperties,
NULL, sStaticProperties, NULL);
}
static JSObject*
Create(JSContext* aCx, int aCode);
private:
FileException()
{
MOZ_COUNT_CTOR(mozilla::dom::workers::exceptions::FileException);
}
~FileException()
{
MOZ_COUNT_DTOR(mozilla::dom::workers::exceptions::FileException);
}
static JSBool
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
{
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_WRONG_CONSTRUCTOR,
sClass.name);
return false;
}
static void
Finalize(JSFreeOp* aFop, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
delete GetJSPrivateSafeish<FileException>(aObj);
}
static JSBool
GetProperty(JSContext* aCx, JSObject* aObj, jsid aIdval, jsval* aVp)
{
JS_ASSERT(JSID_IS_INT(aIdval));
int32 slot = JSID_TO_INT(aIdval);
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr != &sClass || !GetJSPrivateSafeish<FileException>(aObj)) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name,
sProperties[slot].name, classPtr->name);
return false;
}
*aVp = JS_GetReservedSlot(aObj, slot);
return true;
}
static JSBool
GetConstant(JSContext* aCx, JSObject* aObj, jsid idval, jsval* aVp)
{
JS_ASSERT(JSID_IS_INT(idval));
*aVp = INT_TO_JSVAL(JSID_TO_INT(idval));
return true;
}
};
JSClass FileException::sClass = {
"FileException",
JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(SLOT_COUNT),
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize
};
JSPropertySpec FileException::sProperties[] = {
{ "code", SLOT_code, PROPERTY_FLAGS, GetProperty, js_GetterOnlyPropertyStub },
{ "name", SLOT_name, PROPERTY_FLAGS, GetProperty, js_GetterOnlyPropertyStub },
{ 0, 0, 0, NULL, NULL }
};
JSPropertySpec FileException::sStaticProperties[] = {
#define EXCEPTION_ENTRY(_name) \
{ #_name, FILE_##_name, CONSTANT_FLAGS, GetConstant, NULL },
EXCEPTION_ENTRY(NOT_FOUND_ERR)
EXCEPTION_ENTRY(SECURITY_ERR)
EXCEPTION_ENTRY(ABORT_ERR)
EXCEPTION_ENTRY(NOT_READABLE_ERR)
EXCEPTION_ENTRY(ENCODING_ERR)
#undef EXCEPTION_ENTRY
{ 0, 0, 0, NULL, NULL }
};
// static
JSObject*
FileException::Create(JSContext* aCx, int aCode)
{
JSObject* obj = JS_NewObject(aCx, &sClass, NULL, NULL);
if (!obj) {
return NULL;
}
size_t foundIndex = size_t(-1);
for (size_t index = 0; index < ArrayLength(sStaticProperties) - 1; index++) {
if (sStaticProperties[index].tinyid == aCode) {
foundIndex = index;
break;
}
}
JS_ASSERT(foundIndex != size_t(-1));
JSString* name = JS_NewStringCopyZ(aCx, sStaticProperties[foundIndex].name);
if (!name) {
return NULL;
}
JS_SetReservedSlot(obj, SLOT_code, INT_TO_JSVAL(aCode));
JS_SetReservedSlot(obj, SLOT_name, STRING_TO_JSVAL(name));
FileException* priv = new FileException();
SetJSPrivateSafeish(obj, priv);
return obj;
}
} // anonymous namespace
BEGIN_WORKERS_NAMESPACE
@ -422,24 +289,16 @@ namespace exceptions {
bool
InitClasses(JSContext* aCx, JSObject* aGlobal)
{
return DOMException::InitClass(aCx, aGlobal) &&
FileException::InitClass(aCx, aGlobal);
return DOMException::InitClass(aCx, aGlobal);
}
void
ThrowDOMExceptionForCode(JSContext* aCx, int aCode)
ThrowDOMExceptionForNSResult(JSContext* aCx, nsresult aNSResult)
{
JSObject* exception = DOMException::Create(aCx, aCode);
JS_ASSERT(exception);
JS_SetPendingException(aCx, OBJECT_TO_JSVAL(exception));
}
void
ThrowFileExceptionForCode(JSContext* aCx, int aCode)
{
JSObject* exception = FileException::Create(aCx, aCode);
JS_ASSERT(exception);
JSObject* exception = DOMException::Create(aCx, aNSResult);
if (!exception) {
return;
}
JS_SetPendingException(aCx, OBJECT_TO_JSVAL(exception));
}

View File

@ -71,16 +71,6 @@
#define INVALID_NODE_TYPE_ERR 24
#define DATA_CLONE_ERR 25
// This one isn't actually spec'd anywhere, use it when we can't find a match.
#define UNKNOWN_ERR 0
// FileException Codes
#define FILE_NOT_FOUND_ERR 1
#define FILE_SECURITY_ERR 2
#define FILE_ABORT_ERR 3
#define FILE_NOT_READABLE_ERR 4
#define FILE_ENCODING_ERR 5
BEGIN_WORKERS_NAMESPACE
namespace exceptions {
@ -88,12 +78,6 @@ namespace exceptions {
bool
InitClasses(JSContext* aCx, JSObject* aGlobal);
void
ThrowDOMExceptionForCode(JSContext* aCx, int aCode);
void
ThrowFileExceptionForCode(JSContext* aCx, int aCode);
} // namespace exceptions
END_WORKERS_NAMESPACE

View File

@ -41,6 +41,7 @@
#include "nsIDOMFile.h"
#include "nsDOMBlobBuilder.h"
#include "nsDOMError.h"
#include "jsapi.h"
#include "jsatom.h"
@ -58,8 +59,7 @@
USING_WORKERS_NAMESPACE
using mozilla::dom::workers::exceptions::ThrowDOMExceptionForCode;
using mozilla::dom::workers::exceptions::ThrowFileExceptionForCode;
using mozilla::dom::workers::exceptions::ThrowDOMExceptionForNSResult;
namespace {
@ -125,9 +125,7 @@ private:
nsresult rv = file->InitInternal(aCx, aArgc, JS_ARGV(aCx, aVp),
Unwrap);
if (NS_FAILED(rv)) {
ThrowDOMExceptionForCode(aCx,
NS_ERROR_GET_MODULE(rv) == NS_ERROR_MODULE_DOM ?
NS_ERROR_GET_CODE(rv) : UNKNOWN_ERR);
ThrowDOMExceptionForNSResult(aCx, rv);
return false;
}
@ -159,7 +157,8 @@ private:
PRUint64 size;
if (NS_FAILED(blob->GetSize(&size))) {
ThrowFileExceptionForCode(aCx, FILE_NOT_READABLE_ERR);
ThrowDOMExceptionForNSResult(aCx, NS_ERROR_DOM_FILE_NOT_READABLE_ERR);
return false;
}
if (!JS_NewNumberValue(aCx, double(size), aVp)) {
@ -179,7 +178,8 @@ private:
nsString type;
if (NS_FAILED(blob->GetType(type))) {
ThrowFileExceptionForCode(aCx, FILE_NOT_READABLE_ERR);
ThrowDOMExceptionForNSResult(aCx, NS_ERROR_DOM_FILE_NOT_READABLE_ERR);
return false;
}
JSString* jsType = JS_NewUCStringCopyN(aCx, type.get(), type.Length());
@ -223,7 +223,7 @@ private:
static_cast<PRUint64>(end),
contentType, optionalArgc,
getter_AddRefs(rtnBlob)))) {
ThrowFileExceptionForCode(aCx, FILE_NOT_READABLE_ERR);
ThrowDOMExceptionForNSResult(aCx, NS_ERROR_DOM_FILE_NOT_READABLE_ERR);
return false;
}
@ -350,7 +350,7 @@ private:
if (GetWorkerPrivateFromContext(aCx)->UsesSystemPrincipal() &&
NS_FAILED(file->GetMozFullPathInternal(fullPath))) {
ThrowFileExceptionForCode(aCx, FILE_NOT_READABLE_ERR);
ThrowDOMExceptionForNSResult(aCx, NS_ERROR_DOM_FILE_NOT_READABLE_ERR);
return false;
}

View File

@ -40,6 +40,7 @@
#include "FileReaderSync.h"
#include "nsIDOMFile.h"
#include "nsDOMError.h"
#include "jsapi.h"
#include "jsatom.h"
@ -56,7 +57,7 @@
USING_WORKERS_NAMESPACE
using mozilla::dom::workers::exceptions::ThrowFileExceptionForCode;
using mozilla::dom::workers::exceptions::ThrowDOMExceptionForNSResult;
namespace {
@ -67,10 +68,10 @@ EnsureSucceededOrThrow(JSContext* aCx, nsresult rv)
return true;
}
int code = rv == NS_ERROR_FILE_NOT_FOUND ?
FILE_NOT_FOUND_ERR :
FILE_NOT_READABLE_ERR;
ThrowFileExceptionForCode(aCx, code);
rv = rv == NS_ERROR_FILE_NOT_FOUND ?
NS_ERROR_DOM_FILE_NOT_FOUND_ERR :
NS_ERROR_DOM_FILE_NOT_READABLE_ERR;
ThrowDOMExceptionForNSResult(aCx, rv);
return false;
}

View File

@ -100,7 +100,7 @@
using mozilla::MutexAutoLock;
using mozilla::TimeDuration;
using mozilla::TimeStamp;
using mozilla::dom::workers::exceptions::ThrowDOMExceptionForCode;
using mozilla::dom::workers::exceptions::ThrowDOMExceptionForNSResult;
USING_WORKERS_NAMESPACE
using namespace mozilla::dom::workers::events;
@ -415,7 +415,7 @@ struct WorkerStructuredCloneCallbacks
static void
Error(JSContext* aCx, uint32_t /* aErrorId */)
{
ThrowDOMExceptionForCode(aCx, DATA_CLONE_ERR);
ThrowDOMExceptionForNSResult(aCx, NS_ERROR_DOM_DATA_CLONE_ERR);
}
};

View File

@ -97,6 +97,14 @@ GetWorkerCrossThreadDispatcher(JSContext* aCx, jsval aWorker);
// Random unique constant to facilitate JSPrincipal debugging
const uint32_t kJSPrincipalsDebugToken = 0x7e2df9d2;
namespace exceptions {
// Implemented in Exceptions.cpp
void
ThrowDOMExceptionForNSResult(JSContext* aCx, nsresult aNSResult);
} // namespace exceptions
END_WORKERS_NAMESPACE
#endif // mozilla_dom_workers_workers_h__

View File

@ -34,7 +34,7 @@ USING_WORKERS_NAMESPACE
namespace XMLHttpRequestResponseTypeValues =
mozilla::dom::bindings::prototypes::XMLHttpRequestResponseType;
using mozilla::dom::workers::exceptions::ThrowDOMExceptionForCode;
using mozilla::dom::workers::exceptions::ThrowDOMExceptionForNSResult;
// XXX Need to figure this out...
#define UNCATCHABLE_EXCEPTION NS_ERROR_OUT_OF_MEMORY
@ -214,21 +214,6 @@ END_WORKERS_NAMESPACE
namespace {
inline int
GetDOMExceptionCodeFromResult(nsresult aResult)
{
if (NS_SUCCEEDED(aResult)) {
return 0;
}
if (NS_ERROR_GET_MODULE(aResult) == NS_ERROR_MODULE_DOM) {
return NS_ERROR_GET_CODE(aResult);
}
NS_WARNING("Update main thread implementation for a DOM error code here!");
return INVALID_STATE_ERR;
}
inline void
ConvertResponseTypeToString(XMLHttpRequestResponseType aType, nsString& aString)
{
@ -783,11 +768,11 @@ private:
class ResponseRunnable : public MainThreadProxyRunnable
{
PRUint32 mSyncQueueKey;
int mErrorCode;
nsresult mErrorCode;
public:
ResponseRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
PRUint32 aSyncQueueKey, int aErrorCode)
PRUint32 aSyncQueueKey, nsresult aErrorCode)
: MainThreadProxyRunnable(aWorkerPrivate, SkipWhenClearing, aProxy),
mSyncQueueKey(aSyncQueueKey), mErrorCode(aErrorCode)
{
@ -797,8 +782,8 @@ private:
bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
{
if (mErrorCode) {
ThrowDOMExceptionForCode(aCx, mErrorCode);
if (NS_FAILED(mErrorCode)) {
ThrowDOMExceptionForNSResult(aCx, mErrorCode);
aWorkerPrivate->StopSyncLoop(mSyncQueueKey, false);
}
else {
@ -836,7 +821,7 @@ public:
return true;
}
virtual int
virtual nsresult
MainThreadRun() = 0;
NS_IMETHOD
@ -847,7 +832,7 @@ public:
PRUint32 oldSyncQueueKey = mProxy->mSyncEventResponseSyncQueueKey;
mProxy->mSyncEventResponseSyncQueueKey = mSyncQueueKey;
int rv = MainThreadRun();
nsresult rv = MainThreadRun();
nsRefPtr<ResponseRunnable> response =
new ResponseRunnable(mWorkerPrivate, mProxy, mSyncQueueKey, rv);
@ -871,7 +856,7 @@ public:
MOZ_ASSERT(aProxy);
}
virtual int
virtual nsresult
MainThreadRun()
{
AssertIsOnMainThread();
@ -892,10 +877,10 @@ public:
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy), mValue(aValue)
{ }
int
nsresult
MainThreadRun()
{
return GetDOMExceptionCodeFromResult(mProxy->mXHR->SetMultipart(mValue));
return mProxy->mXHR->SetMultipart(mValue);
}
};
@ -909,11 +894,10 @@ public:
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy), mValue(aValue)
{ }
int
nsresult
MainThreadRun()
{
nsresult rv = mProxy->mXHR->SetMozBackgroundRequest(mValue);
return GetDOMExceptionCodeFromResult(rv);
return mProxy->mXHR->SetMozBackgroundRequest(mValue);
}
};
@ -927,11 +911,10 @@ public:
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy), mValue(aValue)
{ }
int
nsresult
MainThreadRun()
{
nsresult rv = mProxy->mXHR->SetWithCredentials(mValue);
return GetDOMExceptionCodeFromResult(rv);
return mProxy->mXHR->SetWithCredentials(mValue);
}
};
@ -946,7 +929,7 @@ public:
mResponseType(aResponseType)
{ }
int
nsresult
MainThreadRun()
{
nsresult rv = mProxy->mXHR->SetResponseType(mResponseType);
@ -954,7 +937,7 @@ public:
if (NS_SUCCEEDED(rv)) {
rv = mProxy->mXHR->GetResponseType(mResponseType);
}
return GetDOMExceptionCodeFromResult(rv);
return rv;
}
void
@ -974,10 +957,10 @@ public:
mTimeout(aTimeout)
{ }
int
nsresult
MainThreadRun()
{
return GetDOMExceptionCodeFromResult(mProxy->mXHR->SetTimeout(mTimeout));
return mProxy->mXHR->SetTimeout(mTimeout);
}
};
@ -988,7 +971,7 @@ public:
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy)
{ }
int
nsresult
MainThreadRun()
{
mProxy->mInnerEventStreamId++;
@ -1002,7 +985,7 @@ public:
mProxy->Reset();
return 0;
return NS_OK;
}
};
@ -1017,11 +1000,11 @@ public:
mResponseHeaders(aResponseHeaders)
{ }
int
nsresult
MainThreadRun()
{
mProxy->mXHR->GetAllResponseHeaders(mResponseHeaders);
return 0;
return NS_OK;
}
};
@ -1037,11 +1020,10 @@ public:
mValue(aValue)
{ }
int
nsresult
MainThreadRun()
{
nsresult rv = mProxy->mXHR->GetResponseHeader(mHeader, mValue);
return GetDOMExceptionCodeFromResult(rv);
return mProxy->mXHR->GetResponseHeader(mHeader, mValue);
}
};
@ -1068,53 +1050,45 @@ public:
mTimeout(aTimeout)
{ }
int
nsresult
MainThreadRun()
{
WorkerPrivate* oldWorker = mProxy->mWorkerPrivate;
mProxy->mWorkerPrivate = mWorkerPrivate;
int retval = MainThreadRunInternal();
nsresult rv = MainThreadRunInternal();
mProxy->mWorkerPrivate = oldWorker;
return retval;
return rv;
}
int
nsresult
MainThreadRunInternal()
{
if (!mProxy->Init()) {
return INVALID_STATE_ERR;
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
nsresult rv;
if (mMultipart) {
rv = mProxy->mXHR->SetMultipart(mMultipart);
if (NS_FAILED(rv)) {
return GetDOMExceptionCodeFromResult(rv);
}
NS_ENSURE_SUCCESS(rv, rv);
}
if (mBackgroundRequest) {
rv = mProxy->mXHR->SetMozBackgroundRequest(mBackgroundRequest);
if (NS_FAILED(rv)) {
return GetDOMExceptionCodeFromResult(rv);
}
NS_ENSURE_SUCCESS(rv, rv);
}
if (mWithCredentials) {
rv = mProxy->mXHR->SetWithCredentials(mWithCredentials);
if (NS_FAILED(rv)) {
return GetDOMExceptionCodeFromResult(rv);
}
NS_ENSURE_SUCCESS(rv, rv);
}
if (mTimeout) {
rv = mProxy->mXHR->SetTimeout(mTimeout);
if (NS_FAILED(rv)) {
return GetDOMExceptionCodeFromResult(rv);
}
NS_ENSURE_SUCCESS(rv, rv);
}
NS_ASSERTION(!mProxy->mInOpen, "Reentrancy is bad!");
@ -1129,7 +1103,7 @@ public:
rv = mProxy->mXHR->SetResponseType(NS_LITERAL_STRING("text"));
}
return GetDOMExceptionCodeFromResult(rv);
return rv;
}
};
@ -1154,7 +1128,7 @@ public:
mClonedObjects.SwapElements(aClonedObjects);
}
int
nsresult
MainThreadRun()
{
nsCOMPtr<nsIVariant> variant;
@ -1164,7 +1138,7 @@ public:
nsIXPConnect* xpc = nsContentUtils::XPConnect();
NS_ASSERTION(xpc, "This should never be null!");
int error = 0;
nsresult rv = NS_OK;
JSStructuredCloneCallbacks* callbacks =
mWorkerPrivate->IsChromeWorker() ?
@ -1175,24 +1149,22 @@ public:
if (mBody.read(cx, &body, callbacks, &mClonedObjects)) {
if (NS_FAILED(xpc->JSValToVariant(cx, &body,
getter_AddRefs(variant)))) {
error = INVALID_STATE_ERR;
rv = NS_ERROR_DOM_INVALID_STATE_ERR;
}
}
else {
error = DATA_CLONE_ERR;
rv = NS_ERROR_DOM_DATA_CLONE_ERR;
}
mBody.clear();
mClonedObjects.Clear();
if (error) {
return error;
}
NS_ENSURE_SUCCESS(rv, rv);
}
else {
nsCOMPtr<nsIWritableVariant> wvariant =
do_CreateInstance(NS_VARIANT_CONTRACTID);
NS_ENSURE_TRUE(wvariant, UNKNOWN_ERR);
NS_ENSURE_TRUE(wvariant, NS_ERROR_UNEXPECTED);
if (NS_FAILED(wvariant->SetAsAString(mStringBody))) {
NS_ERROR("This should never fail!");
@ -1229,7 +1201,7 @@ public:
}
}
return GetDOMExceptionCodeFromResult(rv);
return rv;
}
};
@ -1245,11 +1217,10 @@ public:
mValue(aValue)
{ }
int
nsresult
MainThreadRun()
{
nsresult rv = mProxy->mXHR->SetRequestHeader(mHeader, mValue);
return GetDOMExceptionCodeFromResult(rv);
return mProxy->mXHR->SetRequestHeader(mHeader, mValue);
}
};
@ -1263,11 +1234,11 @@ public:
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy), mMimeType(aMimeType)
{ }
int
nsresult
MainThreadRun()
{
mProxy->mXHR->OverrideMimeType(mMimeType);
return 0;
return NS_OK;
}
};

View File

@ -66,6 +66,16 @@ onmessage = function(event) {
throw new Error("Failed to throw when getting responseText on '" + type +
"' type");
}
if (exception.name != "InvalidStateError") {
throw new Error("Unexpected error when getting responseText on '" + type +
"' type");
}
if (exception.code != DOMException.INVALID_STATE_ERR) {
throw new Error("Unexpected error code when getting responseText on '" + type +
"' type");
}
}
testResponseTextException("arraybuffer");
@ -102,6 +112,16 @@ onmessage = function(event) {
"calling open()");
}
if (exception.name != "InvalidStateError") {
throw new Error("Unexpected error when setting responseType before " +
"calling open()");
}
if (exception.code != DOMException.INVALID_STATE_ERR) {
throw new Error("Unexpected error code when setting responseType before " +
"calling open()");
}
xhr.open("GET", url);
xhr.responseType = "text";
xhr.onload = function(event) {
@ -152,4 +172,14 @@ onmessage = function(event) {
throw new Error("Failed to throw when setting responseType after " +
"calling send()");
}
if (exception.name != "InvalidStateError") {
throw new Error("Unexpected error when setting responseType after " +
"calling send()");
}
if (exception.code != DOMException.INVALID_STATE_ERR) {
throw new Error("Unexpected error code when setting responseType after " +
"calling send()");
}
}