From cc67ef4fb685c71544c671c0f20972079acfcbbe Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sat, 5 May 2012 21:15:11 -0400 Subject: [PATCH] Bug 749485. Switch new DOM bindings to using a struct for keeping track of failures for fallible methods. r=peterv,bent ErrorResult is in a separate header file so it can be included from all over the place without having to pull in mozilla/dom/Utils.h and all the xpconnect gunk that needs. --- content/base/src/nsXMLHttpRequest.cpp | 96 ++++++------ content/base/src/nsXMLHttpRequest.h | 44 +++--- content/canvas/src/WebGLContext.cpp | 13 +- content/canvas/src/WebGLContext.h | 31 ++-- content/canvas/src/WebGLContextGL.cpp | 119 +++++++-------- content/events/src/nsDOMEventTargetHelper.h | 7 +- dom/bindings/BindingUtils.h | 5 +- dom/bindings/Bindings.conf | 9 +- dom/bindings/Codegen.py | 4 +- dom/bindings/ErrorResult.h | 54 +++++++ dom/bindings/Makefile.in | 6 +- dom/workers/EventListenerManager.cpp | 29 ++-- dom/workers/EventListenerManager.h | 10 +- dom/workers/EventTarget.cpp | 17 ++- dom/workers/EventTarget.h | 12 +- dom/workers/Worker.cpp | 9 +- dom/workers/WorkerScope.cpp | 24 +-- dom/workers/XMLHttpRequest.cpp | 158 ++++++++++---------- dom/workers/XMLHttpRequest.h | 70 ++++----- dom/workers/XMLHttpRequestEventTarget.h | 4 +- 20 files changed, 400 insertions(+), 321 deletions(-) create mode 100644 dom/bindings/ErrorResult.h diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index 70bcb3eab48..e58a0b8dce3 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -788,9 +788,11 @@ static void LogMessage(const char* aWarning, nsPIDOMWindow* aWindow) NS_IMETHODIMP nsXMLHttpRequest::GetResponseXML(nsIDOMDocument **aResponseXML) { - nsresult rv = NS_OK; + ErrorResult rv; nsIDocument* responseXML = GetResponseXML(rv); - NS_ENSURE_SUCCESS(rv, rv); + if (rv.Failed()) { + return rv.ErrorCode(); + } if (!responseXML) { *aResponseXML = nsnull; @@ -801,11 +803,11 @@ nsXMLHttpRequest::GetResponseXML(nsIDOMDocument **aResponseXML) } nsIDocument* -nsXMLHttpRequest::GetResponseXML(nsresult& aRv) +nsXMLHttpRequest::GetResponseXML(ErrorResult& aRv) { if (mResponseType != XML_HTTP_RESPONSE_TYPE_DEFAULT && mResponseType != XML_HTTP_RESPONSE_TYPE_DOCUMENT) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return nsnull; } if (mWarnAboutMultipartHtml) { @@ -929,22 +931,22 @@ nsXMLHttpRequest::AppendToResponseText(const char * aSrcBuffer, NS_IMETHODIMP nsXMLHttpRequest::GetResponseText(nsAString& aResponseText) { - nsresult rv = NS_OK; + ErrorResult rv; nsString responseText; GetResponseText(responseText, rv); aResponseText = responseText; - return rv; + return rv.ErrorCode(); } void -nsXMLHttpRequest::GetResponseText(nsString& aResponseText, nsresult& aRv) +nsXMLHttpRequest::GetResponseText(nsString& aResponseText, ErrorResult& aRv) { aResponseText.Truncate(); if (mResponseType != XML_HTTP_RESPONSE_TYPE_DEFAULT && mResponseType != XML_HTTP_RESPONSE_TYPE_TEXT && mResponseType != XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -972,15 +974,17 @@ nsXMLHttpRequest::GetResponseText(nsString& aResponseText, nsresult& aRv) mResponseText.Truncate(); mResponseBodyDecodedPos = 0; + nsresult rv; nsCOMPtr ccm = - do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &aRv); - if (NS_FAILED(aRv)) { + do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); + if (NS_FAILED(rv)) { + aRv.Throw(rv); return; } aRv = ccm->GetUnicodeDecoderRaw(mResponseCharset.get(), getter_AddRefs(mDecoder)); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } } @@ -989,7 +993,7 @@ nsXMLHttpRequest::GetResponseText(nsString& aResponseText, nsresult& aRv) "Unexpected mResponseBodyDecodedPos"); aRv = AppendToResponseText(mResponseBody.get() + mResponseBodyDecodedPos, mResponseBody.Length() - mResponseBodyDecodedPos); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } @@ -1134,27 +1138,27 @@ NS_IMETHODIMP nsXMLHttpRequest::SetResponseType(const nsAString& aResponseType) return NS_OK; } - nsresult rv = NS_OK; + ErrorResult rv; SetResponseType(responseType, rv); - return rv; + return rv.ErrorCode(); } void nsXMLHttpRequest::SetResponseType(XMLHttpRequestResponseType aType, - nsresult& aRv) + ErrorResult& aRv) { SetResponseType(ResponseType(aType), aRv); } void nsXMLHttpRequest::SetResponseType(nsXMLHttpRequest::ResponseType aResponseType, - nsresult& aRv) + ErrorResult& aRv) { // If the state is not OPENED or HEADERS_RECEIVED raise an // INVALID_STATE_ERR exception and terminate these steps. if (!(mState & (XML_HTTP_REQUEST_OPENED | XML_HTTP_REQUEST_SENT | XML_HTTP_REQUEST_HEADERS_RECEIVED))) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -1162,14 +1166,14 @@ nsXMLHttpRequest::SetResponseType(nsXMLHttpRequest::ResponseType aResponseType, if (HasOrHasHadOwner() && !(mState & (XML_HTTP_REQUEST_UNSENT | XML_HTTP_REQUEST_ASYNC))) { LogMessage("ResponseTypeSyncXHRWarning", GetOwner()); - aRv = NS_ERROR_DOM_INVALID_ACCESS_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR); return; } if (!(mState & XML_HTTP_REQUEST_ASYNC) && (aResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_TEXT || aResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER)) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -1188,20 +1192,19 @@ nsXMLHttpRequest::SetResponseType(nsXMLHttpRequest::ResponseType aResponseType, mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB); } } - aRv = NS_OK; } /* readonly attribute jsval response; */ NS_IMETHODIMP nsXMLHttpRequest::GetResponse(JSContext *aCx, jsval *aResult) { - nsresult rv = NS_OK; + ErrorResult rv; *aResult = GetResponse(aCx, rv); - return rv; + return rv.ErrorCode(); } JS::Value -nsXMLHttpRequest::GetResponse(JSContext* aCx, nsresult& aRv) +nsXMLHttpRequest::GetResponse(JSContext* aCx, ErrorResult& aRv) { switch (mResponseType) { case XML_HTTP_RESPONSE_TYPE_DEFAULT: @@ -1210,12 +1213,12 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, nsresult& aRv) { nsString str; aRv = GetResponseText(str); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return JSVAL_NULL; } JS::Value result; if (!xpc::StringToJsval(aCx, str, &result)) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return JSVAL_NULL; } return result; @@ -1235,7 +1238,7 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, nsresult& aRv) RootResultArrayBuffer(); aRv = nsContentUtils::CreateArrayBuffer(aCx, mResponseBody, &mResultArrayBuffer); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return JSVAL_NULL; } } @@ -1251,7 +1254,7 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, nsresult& aRv) if (!mResponseBlob) { aRv = CreatePartialBlob(); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return JSVAL_NULL; } } @@ -1288,7 +1291,7 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, nsresult& aRv) if (mResultJSON == JSVAL_VOID) { aRv = CreateResponseParsedJSON(aCx); mResponseText.Truncate(); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { // Per spec, errors aren't propagated. null is returned instead. aRv = NS_OK; // It would be nice to log the error to the console. That's hard to @@ -1499,14 +1502,14 @@ NS_IMETHODIMP nsXMLHttpRequest::GetResponseHeader(const nsACString& aHeader, nsACString& aResult) { - nsresult rv = NS_OK; + ErrorResult rv; GetResponseHeader(aHeader, aResult, rv); - return rv; + return rv.ErrorCode(); } void nsXMLHttpRequest::GetResponseHeader(const nsACString& header, - nsACString& _retval, nsresult& aRv) + nsACString& _retval, ErrorResult& aRv) { _retval.SetIsVoid(true); @@ -1610,7 +1613,7 @@ nsXMLHttpRequest::GetResponseHeader(const nsACString& header, } aRv = httpChannel->GetResponseHeader(header, _retval); - if (aRv == NS_ERROR_NOT_AVAILABLE) { + if (aRv.ErrorCode() == NS_ERROR_NOT_AVAILABLE) { // Means no header _retval.SetIsVoid(true); aRv = NS_OK; @@ -2518,17 +2521,18 @@ nsXMLHttpRequest::ChangeStateToDone() NS_IMETHODIMP nsXMLHttpRequest::SendAsBinary(const nsAString &aBody, JSContext *aCx) { - nsresult rv = NS_OK; + ErrorResult rv; SendAsBinary(aCx, aBody, rv); - return rv; + return rv.ErrorCode(); } void -nsXMLHttpRequest::SendAsBinary(JSContext *aCx, const nsAString &aBody, nsresult& aRv) +nsXMLHttpRequest::SendAsBinary(JSContext *aCx, const nsAString &aBody, + ErrorResult& aRv) { char *data = static_cast(NS_Alloc(aBody.Length() + 1)); if (!data) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } @@ -2539,7 +2543,7 @@ nsXMLHttpRequest::SendAsBinary(JSContext *aCx, const nsAString &aBody, nsresult& while (iter != end) { if (*iter & 0xFF00) { NS_Free(data); - aRv = NS_ERROR_DOM_INVALID_CHARACTER_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_CHARACTER_ERR); return; } *p++ = static_cast(*iter++); @@ -2549,7 +2553,7 @@ nsXMLHttpRequest::SendAsBinary(JSContext *aCx, const nsAString &aBody, nsresult& nsCOMPtr stream; aRv = NS_NewByteInputStream(getter_AddRefs(stream), data, aBody.Length(), NS_ASSIGNMENT_ADOPT); - if (NS_FAILED(aRv)){ + if (aRv.Failed()) { NS_Free(data); return; } @@ -2557,7 +2561,7 @@ nsXMLHttpRequest::SendAsBinary(JSContext *aCx, const nsAString &aBody, nsresult& nsCOMPtr variant = new nsVariant(); aRv = variant->SetAsISupports(stream); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } @@ -3298,20 +3302,20 @@ nsXMLHttpRequest::GetTimeout(PRUint32 *aTimeout) NS_IMETHODIMP nsXMLHttpRequest::SetTimeout(PRUint32 aTimeout) { - nsresult rv = NS_OK; + ErrorResult rv; SetTimeout(aTimeout, rv); - return rv; + return rv.ErrorCode(); } void -nsXMLHttpRequest::SetTimeout(uint32_t aTimeout, nsresult& aRv) +nsXMLHttpRequest::SetTimeout(uint32_t aTimeout, ErrorResult& aRv) { if (!(mState & (XML_HTTP_REQUEST_ASYNC | XML_HTTP_REQUEST_UNSENT)) && HasOrHasHadOwner()) { /* Timeout is not supported for synchronous requests with an owning window, per XHR2 spec. */ LogMessage("TimeoutSyncXHRWarning", GetOwner()); - aRv = NS_ERROR_DOM_INVALID_ACCESS_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR); return; } @@ -3871,17 +3875,17 @@ nsXMLHttpRequest::GetInterface(const nsIID & aIID, void **aResult) } JS::Value -nsXMLHttpRequest::GetInterface(JSContext* aCx, nsIJSIID* aIID, nsresult& aRv) +nsXMLHttpRequest::GetInterface(JSContext* aCx, nsIJSIID* aIID, ErrorResult& aRv) { const nsID* iid = aIID->GetID(); nsCOMPtr result; JS::Value v = JSVAL_NULL; aRv = GetInterface(*iid, getter_AddRefs(result)); - NS_ENSURE_SUCCESS(aRv, JSVAL_NULL); + NS_ENSURE_FALSE(aRv.Failed(), JSVAL_NULL); JSObject* global = JS_GetGlobalForObject(aCx, GetWrapper()); aRv = nsContentUtils::WrapNative(aCx, global, result, iid, &v); - return NS_SUCCEEDED(aRv) ? v : JSVAL_NULL; + return aRv.Failed() ? JSVAL_NULL : v; } nsXMLHttpRequestUpload* diff --git a/content/base/src/nsXMLHttpRequest.h b/content/base/src/nsXMLHttpRequest.h index 3c9466e599f..7490f513d81 100644 --- a/content/base/src/nsXMLHttpRequest.h +++ b/content/base/src/nsXMLHttpRequest.h @@ -84,7 +84,7 @@ class nsIDOMFormData; { \ return GetListenerAsJSObject(mOn##_capitalized##Listener); \ } \ - void SetOn##_lowercase(JSContext* aCx, JSObject* aCallback, nsresult& aRv) \ + void SetOn##_lowercase(JSContext* aCx, JSObject* aCallback, ErrorResult& aRv) \ { \ aRv = SetJSObjectListener(aCx, NS_LITERAL_STRING(#_lowercase), \ mOn##_capitalized##Listener, \ @@ -211,12 +211,12 @@ public: // The WebIDL parser converts constructors into methods called _Constructor. static already_AddRefed - _Constructor(nsISupports* aGlobal, nsresult& aRv) + _Constructor(nsISupports* aGlobal, ErrorResult& aRv) { nsCOMPtr window = do_QueryInterface(aGlobal); nsCOMPtr principal = do_QueryInterface(aGlobal); if (!window || ! principal) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return NULL; } @@ -283,13 +283,13 @@ public: // request void Open(const nsAString& aMethod, const nsAString& aUrl, bool aAsync, - const nsAString& aUser, const nsAString& aPassword, nsresult& aRv) + const nsAString& aUser, const nsAString& aPassword, ErrorResult& aRv) { aRv = Open(NS_ConvertUTF16toUTF8(aMethod), NS_ConvertUTF16toUTF8(aUrl), aAsync, aUser, aPassword); } void SetRequestHeader(const nsAString& aHeader, const nsAString& aValue, - nsresult& aRv) + ErrorResult& aRv) { aRv = SetRequestHeader(NS_ConvertUTF16toUTF8(aHeader), NS_ConvertUTF16toUTF8(aValue)); @@ -298,7 +298,7 @@ public: { return mTimeoutMilliseconds; } - void SetTimeout(uint32_t aTimeout, nsresult& aRv); + void SetTimeout(uint32_t aTimeout, ErrorResult& aRv); bool GetWithCredentials(); void SetWithCredentials(bool aWithCredentials, nsresult& aRv); nsXMLHttpRequestUpload* GetUpload(); @@ -387,26 +387,26 @@ private: } public: - void Send(JSContext *aCx, nsresult& aRv) + void Send(JSContext *aCx, ErrorResult& aRv) { aRv = Send(aCx, Nullable()); } - void Send(JSContext *aCx, JSObject* aArrayBuffer, nsresult& aRv) + void Send(JSContext *aCx, JSObject* aArrayBuffer, ErrorResult& aRv) { NS_ASSERTION(aArrayBuffer, "Null should go to string version"); aRv = Send(aCx, RequestBody(aArrayBuffer)); } - void Send(JSContext *aCx, nsIDOMBlob* aBlob, nsresult& aRv) + void Send(JSContext *aCx, nsIDOMBlob* aBlob, ErrorResult& aRv) { NS_ASSERTION(aBlob, "Null should go to string version"); aRv = Send(aCx, RequestBody(aBlob)); } - void Send(JSContext *aCx, nsIDocument* aDoc, nsresult& aRv) + void Send(JSContext *aCx, nsIDocument* aDoc, ErrorResult& aRv) { NS_ASSERTION(aDoc, "Null should go to string version"); aRv = Send(aCx, RequestBody(aDoc)); } - void Send(JSContext *aCx, const nsAString& aString, nsresult& aRv) + void Send(JSContext *aCx, const nsAString& aString, ErrorResult& aRv) { if (DOMStringIsNull(aString)) { Send(aCx, aRv); @@ -415,17 +415,17 @@ public: aRv = Send(aCx, RequestBody(aString)); } } - void Send(JSContext *aCx, nsIDOMFormData* aFormData, nsresult& aRv) + void Send(JSContext *aCx, nsIDOMFormData* aFormData, ErrorResult& aRv) { NS_ASSERTION(aFormData, "Null should go to string version"); aRv = Send(aCx, RequestBody(aFormData)); } - void Send(JSContext *aCx, nsIInputStream* aStream, nsresult& aRv) + void Send(JSContext *aCx, nsIInputStream* aStream, ErrorResult& aRv) { NS_ASSERTION(aStream, "Null should go to string version"); aRv = Send(aCx, RequestBody(aStream)); } - void SendAsBinary(JSContext *aCx, const nsAString& aBody, nsresult& aRv); + void SendAsBinary(JSContext *aCx, const nsAString& aBody, ErrorResult& aRv); void Abort(); @@ -433,9 +433,9 @@ public: uint32_t GetStatus(); void GetStatusText(nsString& aStatusText); void GetResponseHeader(const nsACString& aHeader, nsACString& aResult, - nsresult& aRv); + ErrorResult& aRv); void GetResponseHeader(const nsAString& aHeader, nsString& aResult, - nsresult& aRv) + ErrorResult& aRv) { nsCString result; GetResponseHeader(NS_ConvertUTF16toUTF8(aHeader), result, aRv); @@ -460,10 +460,10 @@ public: { return XMLHttpRequestResponseType(mResponseType); } - void SetResponseType(XMLHttpRequestResponseType aType, nsresult& aRv); - JS::Value GetResponse(JSContext* aCx, nsresult& aRv); - void GetResponseText(nsString& aResponseText, nsresult& aRv); - nsIDocument* GetResponseXML(nsresult& aRv); + void SetResponseType(XMLHttpRequestResponseType aType, ErrorResult& aRv); + JS::Value GetResponse(JSContext* aCx, ErrorResult& aRv); + void GetResponseText(nsString& aResponseText, ErrorResult& aRv); + nsIDocument* GetResponseXML(ErrorResult& aRv); bool GetMozBackgroundRequest(); void SetMozBackgroundRequest(bool aMozBackgroundRequest, nsresult& aRv); @@ -476,7 +476,7 @@ public: } // We need a GetInterface callable from JS for chrome JS - JS::Value GetInterface(JSContext* aCx, nsIJSIID* aIID, nsresult& aRv); + JS::Value GetInterface(JSContext* aCx, nsIJSIID* aIID, ErrorResult& aRv); // This creates a trusted readystatechange event, which is not cancelable and // doesn't bubble. @@ -633,7 +633,7 @@ protected: XML_HTTP_RESPONSE_TYPE_MOZ_BLOB }; - void SetResponseType(nsXMLHttpRequest::ResponseType aType, nsresult& aRv); + void SetResponseType(nsXMLHttpRequest::ResponseType aType, ErrorResult& aRv); ResponseType mResponseType; diff --git a/content/canvas/src/WebGLContext.cpp b/content/canvas/src/WebGLContext.cpp index 39d1ff5962b..a297961c8a1 100644 --- a/content/canvas/src/WebGLContext.cpp +++ b/content/canvas/src/WebGLContext.cpp @@ -785,16 +785,17 @@ WebGLContext::GetCanvasLayer(nsDisplayListBuilder* aBuilder, NS_IMETHODIMP WebGLContext::GetContextAttributes(jsval *aResult) { - nsresult rv = NS_OK; + ErrorResult rv; JSObject* obj = GetContextAttributes(rv); - NS_ENSURE_SUCCESS(rv, rv); + if (rv.Failed()) + return rv.ErrorCode(); *aResult = JS::ObjectOrNullValue(obj); return NS_OK; } JSObject* -WebGLContext::GetContextAttributes(nsresult &rv) +WebGLContext::GetContextAttributes(ErrorResult &rv) { if (!IsContextStable()) { @@ -803,13 +804,13 @@ WebGLContext::GetContextAttributes(nsresult &rv) JSContext *cx = nsContentUtils::GetCurrentJSContext(); if (!cx) { - rv = NS_ERROR_FAILURE; + rv.Throw(NS_ERROR_FAILURE); return NULL; } JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL); if (!obj) { - rv = NS_ERROR_FAILURE; + rv.Throw(NS_ERROR_FAILURE); return NULL; } @@ -830,7 +831,7 @@ WebGLContext::GetContextAttributes(nsresult &rv) mOptions.preserveDrawingBuffer ? JSVAL_TRUE : JSVAL_FALSE, NULL, NULL, JSPROP_ENUMERATE)) { - rv = NS_ERROR_FAILURE; + rv.Throw(NS_ERROR_FAILURE); return NULL; } diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index 3c1f503de8a..c9ba4a04c92 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -694,7 +694,7 @@ public: return mHeight; } - JSObject *GetContextAttributes(nsresult &rv); + JSObject *GetContextAttributes(ErrorResult &rv); bool IsContextLost() const { return !IsContextStable(); } void GetSupportedExtensions(dom::Nullable< nsTArray > &retval); nsIWebGLExtension* GetExtension(const nsAString& aName); @@ -797,28 +797,28 @@ public: dom::Nullable< nsTArray > &retval); WebGLint GetAttribLocation(WebGLProgram* prog, const nsAString& name); JS::Value GetBufferParameter(WebGLenum target, WebGLenum pname); - JS::Value GetParameter(JSContext* cx, WebGLenum pname, nsresult& rv); + JS::Value GetParameter(JSContext* cx, WebGLenum pname, ErrorResult& rv); WebGLenum GetError(); JS::Value GetFramebufferAttachmentParameter(JSContext* cx, WebGLenum target, WebGLenum attachment, WebGLenum pname, - nsresult& rv); + ErrorResult& rv); JS::Value GetProgramParameter(WebGLProgram *prog, WebGLenum pname); - void GetProgramInfoLog(WebGLProgram *prog, nsAString& retval, nsresult& rv); + void GetProgramInfoLog(WebGLProgram *prog, nsAString& retval, ErrorResult& rv); JS::Value GetRenderbufferParameter(WebGLenum target, WebGLenum pname); JS::Value GetShaderParameter(WebGLShader *shader, WebGLenum pname); already_AddRefed GetShaderPrecisionFormat(WebGLenum shadertype, WebGLenum precisiontype); - void GetShaderInfoLog(WebGLShader *shader, nsAString& retval, nsresult& rv); + void GetShaderInfoLog(WebGLShader *shader, nsAString& retval, ErrorResult& rv); void GetShaderSource(WebGLShader *shader, nsAString& retval); JS::Value GetTexParameter(WebGLenum target, WebGLenum pname); JS::Value GetUniform(JSContext* cx, WebGLProgram *prog, - WebGLUniformLocation *location, nsresult& rv); + WebGLUniformLocation *location, ErrorResult& rv); already_AddRefed GetUniformLocation(WebGLProgram *prog, const nsAString& name); JS::Value GetVertexAttrib(JSContext* cx, WebGLuint index, WebGLenum pname, - nsresult& rv); + ErrorResult& rv); WebGLsizeiptr GetVertexAttribOffset(WebGLuint index, WebGLenum pname); void Hint(WebGLenum target, WebGLenum mode); bool IsBuffer(WebGLBuffer *buffer); @@ -834,7 +834,7 @@ public: MakeContextCurrent(); gl->fLineWidth(width); } - void LinkProgram(WebGLProgram *program, nsresult& rv); + void LinkProgram(WebGLProgram *program, ErrorResult& rv); void PixelStorei(WebGLenum pname, WebGLint param); void PolygonOffset(WebGLfloat factor, WebGLfloat units) { if (!IsContextStable()) @@ -844,7 +844,7 @@ public: } void ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height, WebGLenum format, WebGLenum type, - dom::ArrayBufferView* pixels, nsresult& rv); + dom::ArrayBufferView* pixels, ErrorResult& rv); void RenderbufferStorage(WebGLenum target, WebGLenum internalformat, WebGLsizei width, WebGLsizei height); void SampleCoverage(WebGLclampf value, WebGLboolean invert) { @@ -866,13 +866,14 @@ public: void TexImage2D(JSContext* cx, WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLsizei width, WebGLsizei height, WebGLint border, WebGLenum format, - WebGLenum type, dom::ArrayBufferView *pixels, nsresult& rv); + WebGLenum type, dom::ArrayBufferView *pixels, + ErrorResult& rv); void TexImage2D(JSContext* cx, WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLenum format, WebGLenum type, - dom::ImageData* pixels, nsresult& rv); + dom::ImageData* pixels, ErrorResult& rv); void TexImage2D(JSContext* /* unused */, WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLenum format, WebGLenum type, - dom::Element* elt, nsresult& rv); + dom::Element* elt, ErrorResult& rv); void TexParameterf(WebGLenum target, WebGLenum pname, WebGLfloat param) { TexParameter_base(target, pname, nsnull, ¶m); } @@ -884,13 +885,13 @@ public: WebGLint xoffset, WebGLint yoffset, WebGLsizei width, WebGLsizei height, WebGLenum format, WebGLenum type, dom::ArrayBufferView* pixels, - nsresult& rv); + ErrorResult& rv); void TexSubImage2D(JSContext* cx, WebGLenum target, WebGLint level, WebGLint xoffset, WebGLint yoffset, WebGLenum format, - WebGLenum type, dom::ImageData* pixels, nsresult& rv); + WebGLenum type, dom::ImageData* pixels, ErrorResult& rv); void TexSubImage2D(JSContext* /* unused */, WebGLenum target, WebGLint level, WebGLint xoffset, WebGLint yoffset, WebGLenum format, - WebGLenum type, dom::Element* elt, nsresult& rv); + WebGLenum type, dom::Element* elt, ErrorResult& rv); void Uniform1i(WebGLUniformLocation* location, WebGLint x); void Uniform2i(WebGLUniformLocation* location, WebGLint x, WebGLint y); diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index b6753572d0f..cdf0a895d03 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -2321,19 +2321,20 @@ WebGLContext::GetAttribLocation(WebGLProgram *prog, const nsAString& name) NS_IMETHODIMP WebGLContext::GetParameter(PRUint32 pname, JSContext* cx, JS::Value *retval) { - nsresult rv = NS_OK; + ErrorResult rv; JS::Value v = GetParameter(cx, pname, rv); - NS_ENSURE_SUCCESS(rv, rv); + if (rv.Failed()) + return rv.ErrorCode(); *retval = v; return NS_OK; } static JS::Value -StringValue(JSContext* cx, const char* chars, nsresult& rv) +StringValue(JSContext* cx, const char* chars, ErrorResult& rv) { JSString* str = JS_NewStringCopyZ(cx, chars); if (!str) { - rv = NS_ERROR_OUT_OF_MEMORY; + rv.Throw(NS_ERROR_OUT_OF_MEMORY); return JS::NullValue(); } @@ -2341,7 +2342,7 @@ StringValue(JSContext* cx, const char* chars, nsresult& rv) } JS::Value -WebGLContext::GetParameter(JSContext* cx, WebGLenum pname, nsresult& rv) +WebGLContext::GetParameter(JSContext* cx, WebGLenum pname, ErrorResult& rv) { if (!IsContextStable()) return JS::NullValue(); @@ -2747,10 +2748,11 @@ WebGLContext::GetBufferParameter(WebGLenum target, WebGLenum pname) NS_IMETHODIMP WebGLContext::GetFramebufferAttachmentParameter(WebGLenum target, WebGLenum attachment, WebGLenum pname, JSContext* cx, JS::Value *retval) { - nsresult rv = NS_OK; + ErrorResult rv; JS::Value v = GetFramebufferAttachmentParameter(cx, target, attachment, pname, rv); - NS_ENSURE_SUCCESS(rv, rv); + if (rv.Failed()) + return rv.ErrorCode(); *retval = v; return NS_OK; } @@ -2760,7 +2762,7 @@ WebGLContext::GetFramebufferAttachmentParameter(JSContext* cx, WebGLenum target, WebGLenum attachment, WebGLenum pname, - nsresult& rv) + ErrorResult& rv) { if (!IsContextStable()) return JS::NullValue(); @@ -2801,7 +2803,7 @@ WebGLContext::GetFramebufferAttachmentParameter(JSContext* cx, if (!dom::WrapObject(cx, GetWrapper(), const_cast(fba.Renderbuffer()), &v)) { - rv = NS_ERROR_FAILURE; + rv.Throw(NS_ERROR_FAILURE); return JS::NullValue(); } return v; @@ -3022,14 +3024,14 @@ WebGLContext::GetProgramParameter(WebGLProgram *prog, WebGLenum pname) NS_IMETHODIMP WebGLContext::GetProgramInfoLog(nsIWebGLProgram *pobj, nsAString& retval) { - nsresult rv = NS_OK; + ErrorResult rv; GetProgramInfoLog(static_cast(pobj), retval, rv); - return rv; + return rv.ErrorCode(); } void WebGLContext::GetProgramInfoLog(WebGLProgram *prog, nsAString& retval, - nsresult& rv) + ErrorResult& rv) { if (!IsContextStable()) { @@ -3249,17 +3251,18 @@ NS_IMETHODIMP WebGLContext::GetUniform(nsIWebGLProgram *pobj, nsIWebGLUniformLocation *ploc, JSContext *cx, JS::Value *retval) { - nsresult rv = NS_OK; + ErrorResult rv; JS::Value v = GetUniform(cx, static_cast(pobj), static_cast(ploc), rv); - NS_ENSURE_SUCCESS(rv, rv); + if (rv.Failed()) + return rv.ErrorCode(); *retval = v; return NS_OK; } JS::Value WebGLContext::GetUniform(JSContext* cx, WebGLProgram *prog, - WebGLUniformLocation *location, nsresult& rv) + WebGLUniformLocation *location, ErrorResult& rv) { if (!IsContextStable()) return JS::NullValue(); @@ -3328,20 +3331,20 @@ WebGLContext::GetUniform(JSContext* cx, WebGLProgram *prog, } if (index == uniforms) { - rv = NS_ERROR_FAILURE; // XXX GL error? shouldn't happen. + rv.Throw(NS_ERROR_FAILURE); // XXX GL error? shouldn't happen. return JS::NullValue(); } GLenum baseType; GLint unitSize; if (!BaseTypeAndSizeFromUniformType(uniformType, &baseType, &unitSize)) { - rv = NS_ERROR_FAILURE; + rv.Throw(NS_ERROR_FAILURE); return JS::NullValue(); } // this should never happen if (unitSize > 16) { - rv = NS_ERROR_FAILURE; + rv.Throw(NS_ERROR_FAILURE); return JS::NullValue(); } @@ -3353,7 +3356,7 @@ WebGLContext::GetUniform(JSContext* cx, WebGLProgram *prog, } else { JSObject* obj = Float32Array::Create(cx, unitSize, fv); if (!obj) { - rv = NS_ERROR_OUT_OF_MEMORY; + rv.Throw(NS_ERROR_OUT_OF_MEMORY); } return JS::ObjectOrNullValue(obj); } @@ -3365,7 +3368,7 @@ WebGLContext::GetUniform(JSContext* cx, WebGLProgram *prog, } else { JSObject* obj = Int32Array::Create(cx, unitSize, iv); if (!obj) { - rv = NS_ERROR_OUT_OF_MEMORY; + rv.Throw(NS_ERROR_OUT_OF_MEMORY); } return JS::ObjectOrNullValue(obj); } @@ -3380,7 +3383,7 @@ WebGLContext::GetUniform(JSContext* cx, WebGLProgram *prog, uv[k] = JS::BooleanValue(iv[k] ? true : false); JSObject* obj = JS_NewArrayObject(cx, unitSize, uv); if (!obj) { - rv = NS_ERROR_OUT_OF_MEMORY; + rv.Throw(NS_ERROR_OUT_OF_MEMORY); } return JS::ObjectOrNullValue(obj); } @@ -3433,16 +3436,17 @@ NS_IMETHODIMP WebGLContext::GetVertexAttrib(WebGLuint index, WebGLenum pname, JSContext* cx, JS::Value *retval) { - nsresult rv = NS_OK; + ErrorResult rv; JS::Value v = GetVertexAttrib(cx, index, pname, rv); - NS_ENSURE_SUCCESS(rv, rv); + if (rv.Failed()) + return rv.ErrorCode(); *retval = v; return NS_OK; } JS::Value WebGLContext::GetVertexAttrib(JSContext* cx, WebGLuint index, WebGLenum pname, - nsresult& rv) + ErrorResult& rv) { if (!IsContextStable()) return JS::NullValue(); @@ -3458,7 +3462,7 @@ WebGLContext::GetVertexAttrib(JSContext* cx, WebGLuint index, WebGLenum pname, JS::Value v; if (!dom::WrapObject(cx, GetWrapper(), mAttribBuffers[index].buf.get(), &v)) { - rv = NS_ERROR_FAILURE; + rv.Throw(NS_ERROR_FAILURE); return JS::NullValue(); } return v; @@ -3492,7 +3496,7 @@ WebGLContext::GetVertexAttrib(JSContext* cx, WebGLuint index, WebGLenum pname, } JSObject* obj = Float32Array::Create(cx, 4, vec); if (!obj) { - rv = NS_ERROR_OUT_OF_MEMORY; + rv.Throw(NS_ERROR_OUT_OF_MEMORY); } return JS::ObjectOrNullValue(obj); } @@ -3701,13 +3705,13 @@ GL_SAME_METHOD_1(LineWidth, LineWidth, WebGLfloat) NS_IMETHODIMP WebGLContext::LinkProgram(nsIWebGLProgram *pobj) { - nsresult rv = NS_OK; + ErrorResult rv; LinkProgram(static_cast(pobj), rv); - return rv; + return rv.ErrorCode(); } void -WebGLContext::LinkProgram(WebGLProgram *program, nsresult& rv) +WebGLContext::LinkProgram(WebGLProgram *program, ErrorResult& rv) { if (!IsContextStable()) return; @@ -3718,8 +3722,7 @@ WebGLContext::LinkProgram(WebGLProgram *program, nsresult& rv) GLuint progname = program->GLName(); if (!program->NextGeneration()) { - rv = NS_ERROR_FAILURE; - return; + return rv.Throw(NS_ERROR_FAILURE); } if (!program->HasBothShaderTypesAttached()) { @@ -3800,16 +3803,16 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei he } ArrayBufferView pixels(cx, &pixelsVal.toObject()); - nsresult rv = NS_OK; + ErrorResult rv; ReadPixels(x, y, width, height, format, type, &pixels, rv); - return rv; + return rv.ErrorCode(); } void WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, WebGLsizei height, WebGLenum format, WebGLenum type, ArrayBufferView* pixels, - nsresult& rv) + ErrorResult& rv) { if (!IsContextStable()) { return; @@ -3817,8 +3820,7 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, if (HTMLCanvasElement()->IsWriteOnly() && !nsContentUtils::IsCallerTrustedForRead()) { LogMessageIfVerbose("ReadPixels: Not allowed"); - rv = NS_ERROR_DOM_SECURITY_ERR; - return; + return rv.Throw(NS_ERROR_DOM_SECURITY_ERR); } if (width < 0 || height < 0) @@ -4021,8 +4023,7 @@ WebGLContext::ReadPixels(WebGLint x, WebGLint y, WebGLsizei width, } } else { NS_WARNING("Unhandled case, how'd we get here?"); - rv = NS_ERROR_FAILURE; - return; + return rv.Throw(NS_ERROR_FAILURE); } } } @@ -5360,13 +5361,14 @@ WebGLContext::GetShaderParameter(WebGLShader *shader, WebGLenum pname) NS_IMETHODIMP WebGLContext::GetShaderInfoLog(nsIWebGLShader *sobj, nsAString& retval) { - nsresult rv = NS_OK; + ErrorResult rv; GetShaderInfoLog(static_cast(sobj), retval, rv); - return rv; + return rv.ErrorCode(); } void -WebGLContext::GetShaderInfoLog(WebGLShader *shader, nsAString& retval, nsresult& rv) +WebGLContext::GetShaderInfoLog(WebGLShader *shader, nsAString& retval, + ErrorResult& rv) { if (!IsContextStable()) { @@ -5389,8 +5391,7 @@ WebGLContext::GetShaderInfoLog(WebGLShader *shader, nsAString& retval, nsresult& GLint k = -1; gl->fGetShaderiv(shadername, LOCAL_GL_INFO_LOG_LENGTH, &k); if (k == -1) { - rv = NS_ERROR_FAILURE; // XXX GL Error? should never happen. - return; + return rv.Throw(NS_ERROR_FAILURE); // XXX GL Error? should never happen. } if (k == 0) { @@ -5790,7 +5791,7 @@ WebGLContext::TexImage2D_array(WebGLenum target, WebGLint level, WebGLenum inter WebGLenum format, WebGLenum type, JSObject *pixels, JSContext *cx) { - nsresult rv = NS_OK; + ErrorResult rv; if (!pixels) { TexImage2D(cx, target, level, internalformat, width, height, border, format, type, nsnull, rv); @@ -5799,14 +5800,14 @@ WebGLContext::TexImage2D_array(WebGLenum target, WebGLint level, WebGLenum inter TexImage2D(cx, target, level, internalformat, width, height, border, format, type, &view, rv); } - return rv; + return rv.ErrorCode(); } void WebGLContext::TexImage2D(JSContext* cx, WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLsizei width, WebGLsizei height, WebGLint border, WebGLenum format, - WebGLenum type, ArrayBufferView *pixels, nsresult& rv) + WebGLenum type, ArrayBufferView *pixels, ErrorResult& rv) { if (!IsContextStable()) return; @@ -5840,7 +5841,7 @@ WebGLContext::TexImage2D_imageData(WebGLenum target, WebGLint level, WebGLenum i void WebGLContext::TexImage2D(JSContext* cx, WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLenum format, - WebGLenum type, ImageData* pixels, nsresult& rv) + WebGLenum type, ImageData* pixels, ErrorResult& rv) { if (!IsContextStable()) return; @@ -5862,16 +5863,16 @@ NS_IMETHODIMP WebGLContext::TexImage2D_dom(WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLenum format, GLenum type, Element* elt) { - nsresult rv = NS_OK; + ErrorResult rv; TexImage2D(NULL, target, level, internalformat, format, type, elt, rv); - return rv; + return rv.ErrorCode(); } void WebGLContext::TexImage2D(JSContext* /* unused */, WebGLenum target, WebGLint level, WebGLenum internalformat, WebGLenum format, WebGLenum type, Element* elt, - nsresult& rv) + ErrorResult& rv) { if (!IsContextStable()) return; @@ -5880,7 +5881,7 @@ WebGLContext::TexImage2D(JSContext* /* unused */, WebGLenum target, int srcFormat; rv = DOMElementToImageSurface(elt, getter_AddRefs(isurf), &srcFormat); - if (NS_FAILED(rv)) + if (rv.Failed()) return; PRUint32 byteLength = isurf->Stride() * isurf->Height(); @@ -6022,7 +6023,7 @@ WebGLContext::TexSubImage2D_array(WebGLenum target, WebGLint level, WebGLenum format, WebGLenum type, JSObject *pixels, JSContext *cx) { - nsresult rv = NS_OK; + ErrorResult rv; if (!pixels) { TexSubImage2D(cx, target, level, xoffset, yoffset, width, height, format, type, nsnull, rv); @@ -6031,7 +6032,7 @@ WebGLContext::TexSubImage2D_array(WebGLenum target, WebGLint level, TexSubImage2D(cx, target, level, xoffset, yoffset, width, height, format, type, &view, rv); } - return rv; + return rv.ErrorCode(); } void @@ -6040,7 +6041,7 @@ WebGLContext::TexSubImage2D(JSContext* cx, WebGLenum target, WebGLint level, WebGLsizei width, WebGLsizei height, WebGLenum format, WebGLenum type, ArrayBufferView* pixels, - nsresult& rv) + ErrorResult& rv) { if (!IsContextStable()) return; @@ -6084,7 +6085,7 @@ void WebGLContext::TexSubImage2D(JSContext* cx, WebGLenum target, WebGLint level, WebGLint xoffset, WebGLint yoffset, WebGLenum format, WebGLenum type, ImageData* pixels, - nsresult& rv) + ErrorResult& rv) { if (!IsContextStable()) return; @@ -6107,16 +6108,16 @@ WebGLContext::TexSubImage2D_dom(WebGLenum target, WebGLint level, WebGLenum format, WebGLenum type, Element *elt) { - nsresult rv = NS_OK; + ErrorResult rv; TexSubImage2D(NULL, target, level, xoffset, yoffset, format, type, elt, rv); - return rv; + return rv.ErrorCode(); } void WebGLContext::TexSubImage2D(JSContext* /* unused */, WebGLenum target, WebGLint level, WebGLint xoffset, WebGLint yoffset, WebGLenum format, WebGLenum type, - dom::Element* elt, nsresult& rv) + dom::Element* elt, ErrorResult& rv) { if (!IsContextStable()) return; @@ -6125,7 +6126,7 @@ WebGLContext::TexSubImage2D(JSContext* /* unused */, WebGLenum target, int srcFormat; rv = DOMElementToImageSurface(elt, getter_AddRefs(isurf), &srcFormat); - if (NS_FAILED(rv)) + if (rv.Failed()) return; PRUint32 byteLength = isurf->Stride() * isurf->Height(); diff --git a/content/events/src/nsDOMEventTargetHelper.h b/content/events/src/nsDOMEventTargetHelper.h index 32dc3ede5e1..f58c69418e2 100644 --- a/content/events/src/nsDOMEventTargetHelper.h +++ b/content/events/src/nsDOMEventTargetHelper.h @@ -49,6 +49,7 @@ #include "nsEventListenerManager.h" #include "nsIScriptContext.h" #include "nsWrapperCache.h" +#include "mozilla/ErrorResult.h" class nsDOMEventListenerWrapper : public nsIDOMEventListener { @@ -80,7 +81,7 @@ public: void AddEventListener(const nsAString& aType, nsIDOMEventListener* aCallback, // XXX nullable bool aCapture, Nullable& aWantsUntrusted, - nsresult& aRv) + mozilla::ErrorResult& aRv) { aRv = AddEventListener(aType, aCallback, aCapture, !aWantsUntrusted.IsNull() && aWantsUntrusted.Value(), @@ -88,11 +89,11 @@ public: } void RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aCallback, - bool aCapture, nsresult& aRv) + bool aCapture, mozilla::ErrorResult& aRv) { aRv = RemoveEventListener(aType, aCallback, aCapture); } - bool DispatchEvent(nsIDOMEvent* aEvent, nsresult& aRv) + bool DispatchEvent(nsIDOMEvent* aEvent, mozilla::ErrorResult& aRv) { bool result = false; aRv = DispatchEvent(aEvent, &result); diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index e371bf8dccd..586fdd2c4cf 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -9,6 +9,7 @@ #include "mozilla/dom/DOMJSClass.h" #include "mozilla/dom/workers/Workers.h" +#include "mozilla/ErrorResult.h" #include "jsapi.h" #include "jsfriendapi.h" @@ -44,11 +45,11 @@ Throw(JSContext* cx, nsresult rv) template inline bool -ThrowMethodFailedWithDetails(JSContext* cx, nsresult rv, +ThrowMethodFailedWithDetails(JSContext* cx, const ErrorResult& rv, const char* /* ifaceName */, const char* /* memberName */) { - return Throw(cx, rv); + return Throw(cx, rv.ErrorCode()); } inline bool diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 0193d5f50ae..a036382cfd8 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -67,9 +67,12 @@ DOMInterfaces = { 'workers': True, 'nativeType': 'mozilla::dom::workers::XMLHttpRequest', 'headerFile': 'mozilla/dom/workers/bindings/XMLHttpRequest.h', - 'infallible': [ - 'readyState', 'statusText' - ] + 'infallible': { + 'all': ['readyState', 'statusText' ], + 'getterOnly': [ 'timeout', 'withCredentials', 'mozBackgroundRequest', + 'responseType', 'responseXML', 'channel', 'multipart' ] + } + }], 'XMLHttpRequestUpload': [ diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 824135cf832..ddaef06aff4 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -1610,8 +1610,8 @@ class CGCallGenerator(CGThing): self.cgRoot.append(call) if isFallible: - self.cgRoot.prepend(CGGeneric("nsresult rv = NS_OK;")) - self.cgRoot.append(CGGeneric("if (NS_FAILED(rv)) {")) + self.cgRoot.prepend(CGGeneric("ErrorResult rv;")) + self.cgRoot.append(CGGeneric("if (rv.Failed()) {")) self.cgRoot.append(CGIndenter(CGGeneric(errorReport))) self.cgRoot.append(CGGeneric("}")) diff --git a/dom/bindings/ErrorResult.h b/dom/bindings/ErrorResult.h new file mode 100644 index 00000000000..14623411f71 --- /dev/null +++ b/dom/bindings/ErrorResult.h @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ +/* vim: set ts=2 sw=2 et tw=79: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +/** + * A struct for tracking exceptions that need to be thrown to JS. + */ + +#ifndef mozilla_ErrorResult_h +#define mozilla_ErrorResult_h + +#include "nscore.h" + +namespace mozilla { + +class ErrorResult { +public: + ErrorResult() { + mResult = NS_OK; + } + + void Throw(nsresult rv) { + MOZ_ASSERT(NS_FAILED(rv), "Please don't try throwing success"); + mResult = rv; + } + + // In the future, we can add overloads of Throw that take more + // interesting things, like strings or DOM exception types or + // something if desired. + + // Backwards-compat to make conversion simpler. We don't call + // Throw() here because people can easily pass success codes to + // this. + void operator=(nsresult rv) { + mResult = rv; + } + + bool Failed() const { + return NS_FAILED(mResult); + } + + nsresult ErrorCode() const { + return mResult; + } + +private: + nsresult mResult; +}; + +} // namespace mozilla + +#endif /* mozilla_ErrorResult_h */ diff --git a/dom/bindings/Makefile.in b/dom/bindings/Makefile.in index 663da6fdb10..b6076097681 100644 --- a/dom/bindings/Makefile.in +++ b/dom/bindings/Makefile.in @@ -45,7 +45,11 @@ CPPSRCS = \ BindingUtils.cpp \ $(NULL) -EXPORTS_NAMESPACES = $(binding_include_path) +EXPORTS_NAMESPACES = $(binding_include_path) mozilla + +EXPORTS_mozilla = \ + ErrorResult.h \ + $(NULL) EXPORTS_$(binding_include_path) = \ DOMJSClass.h \ diff --git a/dom/workers/EventListenerManager.cpp b/dom/workers/EventListenerManager.cpp index a2274c2eec7..43c3cf20024 100644 --- a/dom/workers/EventListenerManager.cpp +++ b/dom/workers/EventListenerManager.cpp @@ -14,6 +14,7 @@ #include "EventTarget.h" USING_WORKERS_NAMESPACE +using mozilla::ErrorResult; namespace { @@ -194,7 +195,7 @@ EventListenerManager::FinalizeInternal(JSFreeOp* aFop) void EventListenerManager::Add(JSContext* aCx, const jsid& aType, JSObject* aListener, Phase aPhase, - bool aWantsUntrusted, nsresult& aRv) + bool aWantsUntrusted, ErrorResult& aRv) { MOZ_ASSERT(aListener); @@ -205,7 +206,7 @@ EventListenerManager::Add(JSContext* aCx, const jsid& aType, static_cast(&mCollectionHead); collection = ListenerCollection::Add(aCx, head, aType); if (!collection) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } } @@ -225,7 +226,7 @@ EventListenerManager::Add(JSContext* aCx, const jsid& aType, static_cast(&collection->mListenerHead), aListener, aPhase, aWantsUntrusted); if (!listenerData) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } } @@ -279,24 +280,24 @@ EventListenerManager::GetEventListener(const jsid& aType) const bool EventListenerManager::DispatchEvent(JSContext* aCx, const EventTarget& aTarget, - JSObject* aEvent, nsresult& aRv) const + JSObject* aEvent, ErrorResult& aRv) const { using namespace mozilla::dom::workers::events; if (!IsSupportedEventClass(aEvent)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return false; } jsval val; if (!JS_GetProperty(aCx, aEvent, "target", &val)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return false; } if (!JSVAL_IS_NULL(val)) { // Already has a target, must be recursively dispatched. Throw. - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return false; } @@ -310,7 +311,7 @@ EventListenerManager::DispatchEvent(JSContext* aCx, const EventTarget& aTarget, if (!JS_GetProperty(aCx, aEvent, "type", &val) || !(eventType = JS_ValueToString(aCx, val)) || !(eventType = JS_InternJSString(aCx, eventType))) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return false; } @@ -318,7 +319,7 @@ EventListenerManager::DispatchEvent(JSContext* aCx, const EventTarget& aTarget, // there is no need to worry about this property being faked. if (!JS_GetProperty(aCx, aEvent, "isTrusted", &val) || !JS_ValueToBoolean(aCx, val, &eventIsTrusted)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return false; } @@ -341,7 +342,7 @@ EventListenerManager::DispatchEvent(JSContext* aCx, const EventTarget& aTarget, // untrusted event. if ((eventIsTrusted || listenerData->mWantsUntrusted) && !listeners.append(listenerData->mListener)) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return false; } } @@ -368,7 +369,7 @@ EventListenerManager::DispatchEvent(JSContext* aCx, const EventTarget& aTarget, JSObject* listenerObj; if (!JS_ValueToObject(aCx, listenerVal, &listenerObj)) { if (!JS_ReportPendingException(aCx)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return false; } continue; @@ -381,7 +382,7 @@ EventListenerManager::DispatchEvent(JSContext* aCx, const EventTarget& aTarget, JSBool hasHandleEvent; if (!JS_HasProperty(aCx, listenerObj, sHandleEventChars, &hasHandleEvent)) { if (!JS_ReportPendingException(aCx)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return false; } continue; @@ -390,7 +391,7 @@ EventListenerManager::DispatchEvent(JSContext* aCx, const EventTarget& aTarget, if (hasHandleEvent) { if (!JS_GetProperty(aCx, listenerObj, sHandleEventChars, &listenerVal)) { if (!JS_ReportPendingException(aCx)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return false; } continue; @@ -404,7 +405,7 @@ EventListenerManager::DispatchEvent(JSContext* aCx, const EventTarget& aTarget, if (!JS_CallFunctionValue(aCx, thisObj, listenerVal, ArrayLength(argv), argv, &rval)) { if (!JS_ReportPendingException(aCx)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return false; } continue; diff --git a/dom/workers/EventListenerManager.h b/dom/workers/EventListenerManager.h index 35322217133..8cd4b100652 100644 --- a/dom/workers/EventListenerManager.h +++ b/dom/workers/EventListenerManager.h @@ -10,6 +10,8 @@ #include "prclist.h" +#include "mozilla/ErrorResult.h" + BEGIN_WORKERS_NAMESPACE class EventTarget; @@ -56,7 +58,7 @@ public: void AddEventListener(JSContext* aCx, const jsid& aType, JSObject* aListener, - bool aCapturing, bool aWantsUntrusted, nsresult& aRv) + bool aCapturing, bool aWantsUntrusted, ErrorResult& aRv) { Add(aCx, aType, aListener, aCapturing ? Capturing : Bubbling, aWantsUntrusted, aRv); @@ -74,14 +76,14 @@ public: bool DispatchEvent(JSContext* aCx, const EventTarget& aTarget, JSObject* aEvent, - nsresult& aRv) const; + ErrorResult& aRv) const; JSObject* GetEventListener(const jsid& aType) const; void SetEventListener(JSContext* aCx, const jsid& aType, JSObject* aListener, - nsresult& aRv) + ErrorResult& aRv) { JSObject* existing = GetEventListener(aType); if (existing) { @@ -114,7 +116,7 @@ private: void Add(JSContext* aCx, const jsid& aType, JSObject* aListener, Phase aPhase, - bool aWantsUntrusted, nsresult& aRv); + bool aWantsUntrusted, ErrorResult& aRv); void Remove(JSContext* aCx, const jsid& aType, JSObject* aListener, Phase aPhase, diff --git a/dom/workers/EventTarget.cpp b/dom/workers/EventTarget.cpp index 58457428db9..f32c4c35491 100644 --- a/dom/workers/EventTarget.cpp +++ b/dom/workers/EventTarget.cpp @@ -6,6 +6,7 @@ #include "EventTarget.h" USING_WORKERS_NAMESPACE +using mozilla::ErrorResult; void EventTarget::_Trace(JSTracer* aTrc) @@ -22,14 +23,14 @@ EventTarget::_Finalize(JSFreeOp* aFop) } JSObject* -EventTarget::GetEventListener(const nsAString& aType, nsresult& aRv) const +EventTarget::GetEventListener(const nsAString& aType, ErrorResult& aRv) const { JSContext* cx = GetJSContext(); JSString* type = JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length()); if (!type || !(type = JS_InternJSString(cx, type))) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return NULL; } @@ -38,14 +39,14 @@ EventTarget::GetEventListener(const nsAString& aType, nsresult& aRv) const void EventTarget::SetEventListener(const nsAString& aType, JSObject* aListener, - nsresult& aRv) + ErrorResult& aRv) { JSContext* cx = GetJSContext(); JSString* type = JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length()); if (!type || !(type = JS_InternJSString(cx, type))) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } @@ -56,7 +57,7 @@ EventTarget::SetEventListener(const nsAString& aType, JSObject* aListener, void EventTarget::AddEventListener(const nsAString& aType, JSObject* aListener, bool aCapturing, Nullable aWantsUntrusted, - nsresult& aRv) + ErrorResult& aRv) { if (!aListener) { return; @@ -67,7 +68,7 @@ EventTarget::AddEventListener(const nsAString& aType, JSObject* aListener, JSString* type = JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length()); if (!type || !(type = JS_InternJSString(cx, type))) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } @@ -79,7 +80,7 @@ EventTarget::AddEventListener(const nsAString& aType, JSObject* aListener, void EventTarget::RemoveEventListener(const nsAString& aType, JSObject* aListener, - bool aCapturing, nsresult& aRv) + bool aCapturing, ErrorResult& aRv) { if (!aListener) { return; @@ -90,7 +91,7 @@ EventTarget::RemoveEventListener(const nsAString& aType, JSObject* aListener, JSString* type = JS_NewUCStringCopyN(cx, aType.BeginReading(), aType.Length()); if (!type || !(type = JS_InternJSString(cx, type))) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } diff --git a/dom/workers/EventTarget.h b/dom/workers/EventTarget.h index ae601140023..5d56681dc55 100644 --- a/dom/workers/EventTarget.h +++ b/dom/workers/EventTarget.h @@ -12,6 +12,7 @@ #include "mozilla/dom/workers/bindings/EventListenerManager.h" #include "mozilla/dom/Nullable.h" +#include "mozilla/ErrorResult.h" using namespace mozilla::dom; @@ -38,24 +39,25 @@ public: void AddEventListener(const nsAString& aType, JSObject* aListener, - bool aCapture, Nullable aWantsUntrusted, nsresult& aRv); + bool aCapture, Nullable aWantsUntrusted, + ErrorResult& aRv); void RemoveEventListener(const nsAString& aType, JSObject* aListener, - bool aCapture, nsresult& aRv); + bool aCapture, ErrorResult& aRv); bool - DispatchEvent(JSObject* aEvent, nsresult& aRv) const + DispatchEvent(JSObject* aEvent, ErrorResult& aRv) const { return mListenerManager.DispatchEvent(GetJSContext(), *this, aEvent, aRv); } JSObject* - GetEventListener(const nsAString& aType, nsresult& aRv) const; + GetEventListener(const nsAString& aType, ErrorResult& aRv) const; void SetEventListener(const nsAString& aType, JSObject* aListener, - nsresult& aRv); + ErrorResult& aRv); bool HasListeners() const diff --git a/dom/workers/Worker.cpp b/dom/workers/Worker.cpp index 3644b03da1a..87d64220246 100644 --- a/dom/workers/Worker.cpp +++ b/dom/workers/Worker.cpp @@ -56,6 +56,7 @@ USING_WORKERS_NAMESPACE using namespace mozilla::dom; +using mozilla::ErrorResult; namespace { @@ -198,10 +199,10 @@ private: } NS_ConvertASCIItoUTF16 nameStr(name + 2); - nsresult rv = NS_OK; + ErrorResult rv; JSObject* listener = worker->GetEventListener(nameStr, rv); - if (NS_FAILED(rv)) { + if (rv.Failed()) { JS_ReportError(aCx, "Failed to get listener!"); } @@ -228,10 +229,10 @@ private: } NS_ConvertASCIItoUTF16 nameStr(name + 2); - nsresult rv = NS_OK; + ErrorResult rv; worker->SetEventListener(nameStr, listener, rv); - if (NS_FAILED(rv)) { + if (rv.Failed()) { JS_ReportError(aCx, "Failed to set listener!"); return false; } diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index 6616b039460..01b6c4c6c5d 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -177,12 +177,12 @@ private: return false; } - nsresult rv = NS_OK; + ErrorResult rv; JSObject* listener = scope->GetEventListener(NS_ConvertASCIItoUTF16(name + 2), rv); - if (NS_FAILED(rv)) { + if (rv.Failed()) { JS_ReportError(aCx, "Failed to get event listener!"); return false; } @@ -209,10 +209,10 @@ private: return false; } - nsresult rv = NS_OK; + ErrorResult rv; scope->SetEventListener(NS_ConvertASCIItoUTF16(name + 2), JSVAL_TO_OBJECT(*aVp), rv); - if (NS_FAILED(rv)) { + if (rv.Failed()) { JS_ReportError(aCx, "Failed to set event listener!"); return false; } @@ -341,12 +341,12 @@ private: return false; } - nsresult rv = NS_OK; + ErrorResult rv; JSObject* adaptor = scope->GetEventListener(NS_ConvertASCIItoUTF16(name + 2), rv); - if (NS_FAILED(rv)) { + if (rv.Failed()) { JS_ReportError(aCx, "Failed to get event listener!"); return false; } @@ -394,11 +394,11 @@ private: OBJECT_TO_JSVAL(aObj)); js::SetFunctionNativeReserved(listener, SLOT_wrappedFunction, *aVp); - nsresult rv = NS_OK; + ErrorResult rv; scope->SetEventListener(NS_ConvertASCIItoUTF16(name + 2), listener, rv); - if (NS_FAILED(rv)) { + if (rv.Failed()) { JS_ReportError(aCx, "Failed to set event listener!"); return false; } @@ -745,12 +745,12 @@ private: return false; } - nsresult rv = NS_OK; + ErrorResult rv; JSObject* listener = scope->GetEventListener(NS_ConvertASCIItoUTF16(name + 2), rv); - if (NS_FAILED(rv)) { + if (rv.Failed()) { JS_ReportError(aCx, "Failed to get event listener!"); return false; } @@ -777,12 +777,12 @@ private: return false; } - nsresult rv = NS_OK; + ErrorResult rv; scope->SetEventListener(NS_ConvertASCIItoUTF16(name + 2), JSVAL_TO_OBJECT(*aVp), rv); - if (NS_FAILED(rv)) { + if (rv.Failed()) { JS_ReportError(aCx, "Failed to set event listener!"); return false; } diff --git a/dom/workers/XMLHttpRequest.cpp b/dom/workers/XMLHttpRequest.cpp index 8f8a98b7050..8c2267fc9af 100644 --- a/dom/workers/XMLHttpRequest.cpp +++ b/dom/workers/XMLHttpRequest.cpp @@ -32,6 +32,7 @@ USING_WORKERS_NAMESPACE using mozilla::dom::workers::exceptions::ThrowDOMExceptionForNSResult; +using mozilla::ErrorResult; // XXX Need to figure this out... #define UNCATCHABLE_EXCEPTION NS_ERROR_OUT_OF_MEMORY @@ -1447,7 +1448,7 @@ XMLHttpRequest::_Finalize(JSFreeOp* aFop) // static XMLHttpRequest* -XMLHttpRequest::_Constructor(JSContext* aCx, JSObject* aGlobal, nsresult& aRv) +XMLHttpRequest::_Constructor(JSContext* aCx, JSObject* aGlobal, ErrorResult& aRv) { WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); MOZ_ASSERT(workerPrivate); @@ -1455,7 +1456,7 @@ XMLHttpRequest::_Constructor(JSContext* aCx, JSObject* aGlobal, nsresult& aRv) nsRefPtr xhr = new XMLHttpRequest(aCx, workerPrivate); if (!Wrap(aCx, aGlobal, xhr)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return NULL; } @@ -1501,7 +1502,7 @@ XMLHttpRequest::ReleaseProxy(ReleaseType aType) } void -XMLHttpRequest::MaybePin(nsresult& aRv) +XMLHttpRequest::MaybePin(ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); @@ -1512,13 +1513,13 @@ XMLHttpRequest::MaybePin(nsresult& aRv) JSContext* cx = GetJSContext(); if (!JS_AddNamedObjectRoot(cx, &mJSObject, "XMLHttpRequest mJSObject")) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } if (!mWorkerPrivate->AddFeature(cx, this)) { JS_RemoveObjectRoot(cx, &mJSObject); - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } @@ -1526,7 +1527,7 @@ XMLHttpRequest::MaybePin(nsresult& aRv) } void -XMLHttpRequest::MaybeDispatchPrematureAbortEvents(nsresult& aRv) +XMLHttpRequest::MaybeDispatchPrematureAbortEvents(ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); MOZ_ASSERT(mProxy); @@ -1540,12 +1541,12 @@ XMLHttpRequest::MaybeDispatchPrematureAbortEvents(nsresult& aRv) MOZ_ASSERT(target); DispatchPrematureAbortEvent(target, STRING_abort, true, aRv); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } DispatchPrematureAbortEvent(target, STRING_loadend, true, aRv); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } @@ -1557,17 +1558,17 @@ XMLHttpRequest::MaybeDispatchPrematureAbortEvents(nsresult& aRv) MOZ_ASSERT(target); DispatchPrematureAbortEvent(target, STRING_readystatechange, false, aRv); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } DispatchPrematureAbortEvent(target, STRING_abort, false, aRv); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } DispatchPrematureAbortEvent(target, STRING_loadend, false, aRv); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } @@ -1578,7 +1579,8 @@ XMLHttpRequest::MaybeDispatchPrematureAbortEvents(nsresult& aRv) void XMLHttpRequest::DispatchPrematureAbortEvent(JSObject* aTarget, uint8_t aEventType, - bool aUploadTarget, nsresult& aRv) + bool aUploadTarget, + ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); MOZ_ASSERT(mProxy); @@ -1589,7 +1591,7 @@ XMLHttpRequest::DispatchPrematureAbortEvent(JSObject* aTarget, JSString* type = JS_NewStringCopyZ(cx, sEventStrings[aEventType]); if (!type) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } @@ -1611,13 +1613,13 @@ XMLHttpRequest::DispatchPrematureAbortEvent(JSObject* aTarget, } if (!event) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } bool dummy; if (!events::DispatchEventToTarget(cx, aTarget, event, &dummy)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } } @@ -1642,14 +1644,14 @@ void XMLHttpRequest::SendInternal(const nsAString& aStringBody, JSAutoStructuredCloneBuffer& aBody, nsTArray >& aClonedObjects, - nsresult& aRv) + ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); bool hasUploadListeners = mUpload ? mUpload->HasListeners() : false; MaybePin(aRv); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } @@ -1679,7 +1681,7 @@ XMLHttpRequest::SendInternal(const nsAString& aStringBody, } if (mProxy->mIsSyncXHR && !mWorkerPrivate->RunSyncLoop(cx, syncQueueKey)) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } } @@ -1701,18 +1703,18 @@ XMLHttpRequest::Notify(JSContext* aCx, Status aStatus) void XMLHttpRequest::Open(const nsAString& aMethod, const nsAString& aUrl, bool aAsync, const nsAString& aUser, - const nsAString& aPassword, nsresult& aRv) + const nsAString& aPassword, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } if (mProxy) { MaybeDispatchPrematureAbortEvents(aRv); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } } @@ -1729,7 +1731,7 @@ XMLHttpRequest::Open(const nsAString& aMethod, const nsAString& aUrl, if (!runnable->Dispatch(GetJSContext())) { ReleaseProxy(); - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } @@ -1738,17 +1740,17 @@ XMLHttpRequest::Open(const nsAString& aMethod, const nsAString& aUrl, void XMLHttpRequest::SetRequestHeader(const nsAString& aHeader, - const nsAString& aValue, nsresult& aRv) + const nsAString& aValue, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } if (!mProxy) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -1757,18 +1759,18 @@ XMLHttpRequest::SetRequestHeader(const nsAString& aHeader, NS_ConvertUTF16toUTF8(aHeader), NS_ConvertUTF16toUTF8(aValue)); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } } void -XMLHttpRequest::SetTimeout(uint32_t aTimeout, nsresult& aRv) +XMLHttpRequest::SetTimeout(uint32_t aTimeout, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } @@ -1783,18 +1785,18 @@ XMLHttpRequest::SetTimeout(uint32_t aTimeout, nsresult& aRv) nsRefPtr runnable = new SetTimeoutRunnable(mWorkerPrivate, mProxy, aTimeout); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } } void -XMLHttpRequest::SetWithCredentials(bool aWithCredentials, nsresult& aRv) +XMLHttpRequest::SetWithCredentials(bool aWithCredentials, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } @@ -1809,18 +1811,18 @@ XMLHttpRequest::SetWithCredentials(bool aWithCredentials, nsresult& aRv) nsRefPtr runnable = new SetWithCredentialsRunnable(mWorkerPrivate, mProxy, aWithCredentials); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } } void -XMLHttpRequest::SetMultipart(bool aMultipart, nsresult& aRv) +XMLHttpRequest::SetMultipart(bool aMultipart, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } @@ -1835,19 +1837,19 @@ XMLHttpRequest::SetMultipart(bool aMultipart, nsresult& aRv) nsRefPtr runnable = new SetMultipartRunnable(mWorkerPrivate, mProxy, aMultipart); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } } void XMLHttpRequest::SetMozBackgroundRequest(bool aBackgroundRequest, - nsresult& aRv) + ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } @@ -1863,18 +1865,18 @@ XMLHttpRequest::SetMozBackgroundRequest(bool aBackgroundRequest, new SetBackgroundRequestRunnable(mWorkerPrivate, mProxy, aBackgroundRequest); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } } XMLHttpRequestUpload* -XMLHttpRequest::GetUpload(nsresult& aRv) +XMLHttpRequest::GetUpload(ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return NULL; } @@ -1883,7 +1885,7 @@ XMLHttpRequest::GetUpload(nsresult& aRv) XMLHttpRequestUpload::Create(GetJSContext(), this); if (!upload) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return NULL; } @@ -1894,17 +1896,17 @@ XMLHttpRequest::GetUpload(nsresult& aRv) } void -XMLHttpRequest::Send(nsresult& aRv) +XMLHttpRequest::Send(ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } if (!mProxy) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -1916,17 +1918,17 @@ XMLHttpRequest::Send(nsresult& aRv) } void -XMLHttpRequest::Send(const nsAString& aBody, nsresult& aRv) +XMLHttpRequest::Send(const nsAString& aBody, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } if (!mProxy) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -1938,18 +1940,18 @@ XMLHttpRequest::Send(const nsAString& aBody, nsresult& aRv) } void -XMLHttpRequest::Send(JSObject* aBody, nsresult& aRv) +XMLHttpRequest::Send(JSObject* aBody, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); MOZ_ASSERT(aBody); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } if (!mProxy) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -1962,7 +1964,7 @@ XMLHttpRequest::Send(JSObject* aBody, nsresult& aRv) else { JSString* bodyStr = JS_ValueToString(cx, OBJECT_TO_JSVAL(aBody)); if (!bodyStr) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return; } valToClone = STRING_TO_JSVAL(bodyStr); @@ -1977,7 +1979,7 @@ XMLHttpRequest::Send(JSObject* aBody, nsresult& aRv) JSAutoStructuredCloneBuffer buffer; if (!buffer.write(cx, valToClone, callbacks, &clonedObjects)) { - aRv = NS_ERROR_DOM_DATA_CLONE_ERR; + aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR); return; } @@ -1985,20 +1987,20 @@ XMLHttpRequest::Send(JSObject* aBody, nsresult& aRv) } void -XMLHttpRequest::SendAsBinary(const nsAString& aBody, nsresult& aRv) +XMLHttpRequest::SendAsBinary(const nsAString& aBody, ErrorResult& aRv) { NS_NOTYETIMPLEMENTED("Implement me!"); - aRv = NS_ERROR_NOT_IMPLEMENTED; + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); + return; } void -XMLHttpRequest::Abort(nsresult& aRv) +XMLHttpRequest::Abort(ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; - return; + aRv.Throw(UNCATCHABLE_EXCEPTION); } if (!mProxy) { @@ -2006,7 +2008,7 @@ XMLHttpRequest::Abort(nsresult& aRv) } MaybeDispatchPrematureAbortEvents(aRv); - if (NS_FAILED(aRv)) { + if (aRv.Failed()) { return; } @@ -2014,24 +2016,24 @@ XMLHttpRequest::Abort(nsresult& aRv) nsRefPtr runnable = new AbortRunnable(mWorkerPrivate, mProxy); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } } void XMLHttpRequest::GetResponseHeader(const nsAString& aHeader, - nsAString& aResponseHeader, nsresult& aRv) + nsAString& aResponseHeader, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } if (!mProxy) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -2040,7 +2042,7 @@ XMLHttpRequest::GetResponseHeader(const nsAString& aHeader, new GetResponseHeaderRunnable(mWorkerPrivate, mProxy, NS_ConvertUTF16toUTF8(aHeader), value); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2049,17 +2051,17 @@ XMLHttpRequest::GetResponseHeader(const nsAString& aHeader, void XMLHttpRequest::GetAllResponseHeaders(nsAString& aResponseHeaders, - nsresult& aRv) + ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } if (!mProxy) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -2067,7 +2069,7 @@ XMLHttpRequest::GetAllResponseHeaders(nsAString& aResponseHeaders, nsRefPtr runnable = new GetAllResponseHeadersRunnable(mWorkerPrivate, mProxy, responseHeaders); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2075,12 +2077,12 @@ XMLHttpRequest::GetAllResponseHeaders(nsAString& aResponseHeaders, } void -XMLHttpRequest::OverrideMimeType(const nsAString& aMimeType, nsresult& aRv) +XMLHttpRequest::OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } @@ -2090,31 +2092,31 @@ XMLHttpRequest::OverrideMimeType(const nsAString& aMimeType, nsresult& aRv) // (bug 671047). For now we're going to let this work only if the Send() // method has not been called. if (!mProxy || SendInProgress()) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } nsRefPtr runnable = new OverrideMimeTypeRunnable(mWorkerPrivate, mProxy, aMimeType); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } } void XMLHttpRequest::SetResponseType(XMLHttpRequestResponseType aResponseType, - nsresult& aRv) + ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); if (mCanceled) { - aRv = UNCATCHABLE_EXCEPTION; + aRv.Throw(UNCATCHABLE_EXCEPTION); return; } if (!mProxy || SendInProgress()) { - aRv = NS_ERROR_DOM_INVALID_STATE_ERR; + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } @@ -2130,7 +2132,7 @@ XMLHttpRequest::SetResponseType(XMLHttpRequestResponseType aResponseType, nsRefPtr runnable = new SetResponseTypeRunnable(mWorkerPrivate, mProxy, responseType); if (!runnable->Dispatch(GetJSContext())) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2141,7 +2143,7 @@ XMLHttpRequest::SetResponseType(XMLHttpRequestResponseType aResponseType, } jsval -XMLHttpRequest::GetResponse(nsresult& aRv) +XMLHttpRequest::GetResponse(ErrorResult& aRv) { if (NS_SUCCEEDED(mStateData.mResponseTextResult) && JSVAL_IS_VOID(mStateData.mResponse)) { @@ -2152,7 +2154,7 @@ XMLHttpRequest::GetResponse(nsresult& aRv) JS_NewUCStringCopyN(GetJSContext(), mStateData.mResponseText.get(), mStateData.mResponseText.Length()); if (!str) { - aRv = NS_ERROR_OUT_OF_MEMORY; + aRv.Throw(NS_ERROR_OUT_OF_MEMORY); return JSVAL_VOID; } @@ -2164,7 +2166,7 @@ XMLHttpRequest::GetResponse(nsresult& aRv) } void -XMLHttpRequest::GetResponseText(nsAString& aResponseText, nsresult& aRv) +XMLHttpRequest::GetResponseText(nsAString& aResponseText, ErrorResult& aRv) { aRv = mStateData.mResponseTextResult; aResponseText = mStateData.mResponseText; diff --git a/dom/workers/XMLHttpRequest.h b/dom/workers/XMLHttpRequest.h index 0dadf824020..1b4ad2720a3 100644 --- a/dom/workers/XMLHttpRequest.h +++ b/dom/workers/XMLHttpRequest.h @@ -68,7 +68,7 @@ public: _Finalize(JSFreeOp* aFop) MOZ_OVERRIDE; static XMLHttpRequest* - _Constructor(JSContext* aCx, JSObject* aGlobal, nsresult& aRv); + _Constructor(JSContext* aCx, JSObject* aGlobal, ErrorResult& aRv); void Unpin(); @@ -78,13 +78,13 @@ public: #define IMPL_GETTER_AND_SETTER(_type) \ JSObject* \ - GetOn##_type(nsresult& aRv) \ + GetOn##_type(ErrorResult& aRv) \ { \ return GetEventListener(NS_LITERAL_STRING(#_type), aRv); \ } \ \ void \ - SetOn##_type(JSObject* aListener, nsresult& aRv) \ + SetOn##_type(JSObject* aListener, ErrorResult& aRv) \ { \ SetEventListener(NS_LITERAL_STRING(#_type), aListener, aRv); \ } @@ -101,68 +101,68 @@ public: void Open(const nsAString& aMethod, const nsAString& aUrl, bool aAsync, - const nsAString& aUser, const nsAString& aPassword, nsresult& aRv); + const nsAString& aUser, const nsAString& aPassword, ErrorResult& aRv); void SetRequestHeader(const nsAString& aHeader, const nsAString& aValue, - nsresult& aRv); + ErrorResult& aRv); uint32_t - GetTimeout(nsresult& aRv) const + GetTimeout() const { return mTimeout; } void - SetTimeout(uint32_t aTimeout, nsresult& aRv); + SetTimeout(uint32_t aTimeout, ErrorResult& aRv); bool - GetWithCredentials(nsresult& aRv) const + GetWithCredentials() const { return mWithCredentials; } void - SetWithCredentials(bool aWithCredentials, nsresult& aRv); + SetWithCredentials(bool aWithCredentials, ErrorResult& aRv); bool - GetMultipart(nsresult& aRv) const + GetMultipart() const { return mMultipart; } void - SetMultipart(bool aMultipart, nsresult& aRv); + SetMultipart(bool aMultipart, ErrorResult& aRv); bool - GetMozBackgroundRequest(nsresult& aRv) const + GetMozBackgroundRequest() const { return mBackgroundRequest; } void - SetMozBackgroundRequest(bool aBackgroundRequest, nsresult& aRv); + SetMozBackgroundRequest(bool aBackgroundRequest, ErrorResult& aRv); XMLHttpRequestUpload* - GetUpload(nsresult& aRv); + GetUpload(ErrorResult& aRv); void - Send(nsresult& aRv); + Send(ErrorResult& aRv); void - Send(const nsAString& aBody, nsresult& aRv); + Send(const nsAString& aBody, ErrorResult& aRv); void - Send(JSObject* aBody, nsresult& aRv); + Send(JSObject* aBody, ErrorResult& aRv); void - SendAsBinary(const nsAString& aBody, nsresult& aRv); + SendAsBinary(const nsAString& aBody, ErrorResult& aRv); void - Abort(nsresult& aRv); + Abort(ErrorResult& aRv); uint16_t - GetStatus(nsresult& aRv) const + GetStatus(ErrorResult& aRv) const { aRv = mStateData.mStatusResult; return mStateData.mStatus; @@ -176,45 +176,45 @@ public: void GetResponseHeader(const nsAString& aHeader, nsAString& aResponseHeader, - nsresult& aRv); + ErrorResult& aRv); void - GetAllResponseHeaders(nsAString& aResponseHeaders, nsresult& aRv); + GetAllResponseHeaders(nsAString& aResponseHeaders, ErrorResult& aRv); void - OverrideMimeType(const nsAString& aMimeType, nsresult& aRv); + OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv); XMLHttpRequestResponseType - GetResponseType(nsresult& aRv) const + GetResponseType() const { return mResponseType; } void - SetResponseType(XMLHttpRequestResponseType aResponseType, nsresult& aRv); + SetResponseType(XMLHttpRequestResponseType aResponseType, ErrorResult& aRv); jsval - GetResponse(nsresult& aRv); + GetResponse(ErrorResult& aRv); void - GetResponseText(nsAString& aResponseText, nsresult& aRv); + GetResponseText(nsAString& aResponseText, ErrorResult& aRv); JSObject* - GetResponseXML(nsresult& aRv) const + GetResponseXML() const { return NULL; } JSObject* - GetChannel(nsresult& aRv) const + GetChannel() const { return NULL; } JS::Value - GetInterface(JSObject* aIID, nsresult& aRv) + GetInterface(JSObject* aIID, ErrorResult& aRv) { - aRv = NS_ERROR_FAILURE; + aRv.Throw(NS_ERROR_FAILURE); return JSVAL_NULL; } @@ -244,14 +244,14 @@ private: ReleaseProxy(ReleaseType aType = Default); void - MaybePin(nsresult& aRv); + MaybePin(ErrorResult& aRv); void - MaybeDispatchPrematureAbortEvents(nsresult& aRv); + MaybeDispatchPrematureAbortEvents(ErrorResult& aRv); void DispatchPrematureAbortEvent(JSObject* aTarget, uint8_t aEventType, - bool aUploadTarget, nsresult& aRv); + bool aUploadTarget, ErrorResult& aRv); bool SendInProgress() const @@ -263,7 +263,7 @@ private: SendInternal(const nsAString& aStringBody, JSAutoStructuredCloneBuffer& aBody, nsTArray >& aClonedObjects, - nsresult& aRv); + ErrorResult& aRv); }; END_WORKERS_NAMESPACE diff --git a/dom/workers/XMLHttpRequestEventTarget.h b/dom/workers/XMLHttpRequestEventTarget.h index c7e8730d669..343b71a78eb 100644 --- a/dom/workers/XMLHttpRequestEventTarget.h +++ b/dom/workers/XMLHttpRequestEventTarget.h @@ -29,13 +29,13 @@ public: #define IMPL_GETTER_AND_SETTER(_type) \ JSObject* \ - GetOn##_type(nsresult& aRv) \ + GetOn##_type(ErrorResult& aRv) \ { \ return GetEventListener(NS_LITERAL_STRING(#_type), aRv); \ } \ \ void \ - SetOn##_type(JSObject* aListener, nsresult& aRv) \ + SetOn##_type(JSObject* aListener, ErrorResult& aRv) \ { \ SetEventListener(NS_LITERAL_STRING(#_type), aListener, aRv); \ }