From bc1e511e33f1a9b8ff3546b25995f1208cad127e Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 11 Jun 2014 16:26:52 -0400 Subject: [PATCH] Bug 1009675 part 2. Return WebIDL 'any' values as handles. r=peterv --- content/base/public/nsINode.h | 14 ++-- content/base/src/nsDOMFileReader.cpp | 9 ++- content/base/src/nsDOMFileReader.h | 3 +- content/base/src/nsINode.cpp | 32 ++++----- content/base/src/nsObjectLoadingContent.cpp | 27 ++++--- content/base/src/nsObjectLoadingContent.h | 7 +- content/base/src/nsXMLHttpRequest.cpp | 65 +++++++++-------- content/base/src/nsXMLHttpRequest.h | 6 +- .../canvas/src/CanvasRenderingContext2D.cpp | 8 ++- content/canvas/src/CanvasRenderingContext2D.h | 3 +- content/canvas/src/CanvasUtils.h | 12 ++-- content/canvas/src/WebGLContext.h | 65 ++++++++++++----- content/canvas/src/WebGLContextState.cpp | 19 +++-- .../content/src/HTMLPropertiesCollection.cpp | 3 +- .../html/content/src/nsGenericHTMLElement.cpp | 16 ++--- .../html/content/src/nsGenericHTMLElement.h | 10 +-- dom/base/DOMRequest.cpp | 2 +- dom/base/DOMRequest.h | 7 +- dom/base/nsGlobalWindow.cpp | 70 ++++++++++--------- dom/base/nsGlobalWindow.h | 20 ++++-- dom/base/nsHistory.cpp | 26 +++---- dom/base/nsHistory.h | 3 +- dom/bindings/BindingUtils.cpp | 13 ++-- dom/bindings/BindingUtils.h | 12 ++-- dom/bindings/Codegen.py | 17 ++++- dom/bindings/test/TestBindingHeader.h | 4 +- dom/bluetooth/BluetoothAdapter.cpp | 20 +++--- dom/bluetooth/BluetoothAdapter.h | 6 +- dom/bluetooth/BluetoothDevice.cpp | 20 +++--- dom/bluetooth/BluetoothDevice.h | 6 +- dom/bluetooth2/BluetoothAdapter.cpp | 20 +++--- dom/bluetooth2/BluetoothAdapter.h | 6 +- dom/bluetooth2/BluetoothDevice.cpp | 20 +++--- dom/bluetooth2/BluetoothDevice.h | 6 +- dom/camera/DOMCameraCapabilities.cpp | 8 ++- dom/camera/DOMCameraCapabilities.h | 2 +- dom/datastore/DataStoreDB.cpp | 6 +- dom/datastore/DataStoreService.cpp | 3 +- dom/events/DataTransfer.cpp | 16 ++--- dom/events/DataTransfer.h | 5 +- dom/events/JSEventHandler.cpp | 7 +- dom/events/MessageEvent.cpp | 13 ++-- dom/events/MessageEvent.h | 3 +- dom/indexedDB/IDBCursor.cpp | 43 ++++++++---- dom/indexedDB/IDBCursor.h | 15 ++-- dom/indexedDB/IDBIndex.cpp | 16 +++-- dom/indexedDB/IDBIndex.h | 5 +- dom/indexedDB/IDBKeyRange.cpp | 20 +++--- dom/indexedDB/IDBKeyRange.h | 10 +-- dom/indexedDB/IDBObjectStore.cpp | 16 +++-- dom/indexedDB/IDBObjectStore.h | 5 +- dom/indexedDB/IDBRequest.cpp | 8 ++- dom/indexedDB/IDBRequest.h | 11 +-- dom/indexedDB/ipc/IndexedDBParent.cpp | 3 +- dom/promise/PromiseCallback.cpp | 4 +- dom/workers/XMLHttpRequest.cpp | 11 +-- dom/workers/XMLHttpRequest.h | 11 +-- js/xpconnect/src/event_impl_gen.py | 12 ++-- 58 files changed, 493 insertions(+), 337 deletions(-) diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h index 3193274d94f3..d2f225dae8f6 100644 --- a/content/base/public/nsINode.h +++ b/content/base/public/nsINode.h @@ -1617,12 +1617,14 @@ public: // HasAttributes is defined inline in Element.h. bool HasAttributes() const; nsDOMAttributeMap* GetAttributes(); - JS::Value SetUserData(JSContext* aCx, const nsAString& aKey, - JS::Handle aData, - nsIDOMUserDataHandler* aHandler, - mozilla::ErrorResult& aError); - JS::Value GetUserData(JSContext* aCx, const nsAString& aKey, - mozilla::ErrorResult& aError); + void SetUserData(JSContext* aCx, const nsAString& aKey, + JS::Handle aData, + nsIDOMUserDataHandler* aHandler, + JS::MutableHandle aRetval, + mozilla::ErrorResult& aError); + void GetUserData(JSContext* aCx, const nsAString& aKey, + JS::MutableHandle aRetval, + mozilla::ErrorResult& aError); // Helper method to remove this node from its parent. This is not exposed // through WebIDL. diff --git a/content/base/src/nsDOMFileReader.cpp b/content/base/src/nsDOMFileReader.cpp index bbb982ee17e5..16b587eb9dea 100644 --- a/content/base/src/nsDOMFileReader.cpp +++ b/content/base/src/nsDOMFileReader.cpp @@ -146,12 +146,11 @@ nsDOMFileReader::GetReadyState(uint16_t *aReadyState) return NS_OK; } -JS::Value -nsDOMFileReader::GetResult(JSContext* aCx, ErrorResult& aRv) +void +nsDOMFileReader::GetResult(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) { - JS::Rooted result(aCx); - aRv = GetResult(aCx, &result); - return result; + aRv = GetResult(aCx, aResult); } NS_IMETHODIMP diff --git a/content/base/src/nsDOMFileReader.h b/content/base/src/nsDOMFileReader.h index ad30df5fdccd..69701ee6a94a 100644 --- a/content/base/src/nsDOMFileReader.h +++ b/content/base/src/nsDOMFileReader.h @@ -85,7 +85,8 @@ public: // Inherited ReadyState(). - JS::Value GetResult(JSContext* aCx, ErrorResult& aRv); + void GetResult(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv); using FileIOObject::GetError; diff --git a/content/base/src/nsINode.cpp b/content/base/src/nsINode.cpp index 432f712f5542..3c18ff54c6a2 100644 --- a/content/base/src/nsINode.cpp +++ b/content/base/src/nsINode.cpp @@ -779,33 +779,33 @@ nsINode::SetUserData(const nsAString &aKey, nsIVariant *aData, return NS_OK; } -JS::Value +void nsINode::SetUserData(JSContext* aCx, const nsAString& aKey, JS::Handle aData, - nsIDOMUserDataHandler* aHandler, ErrorResult& aError) + nsIDOMUserDataHandler* aHandler, + JS::MutableHandle aRetval, + ErrorResult& aError) { nsCOMPtr data; - JS::Rooted dataVal(aCx, aData); - aError = nsContentUtils::XPConnect()->JSValToVariant(aCx, dataVal, getter_AddRefs(data)); + aError = nsContentUtils::XPConnect()->JSValToVariant(aCx, aData, getter_AddRefs(data)); if (aError.Failed()) { - return JS::UndefinedValue(); + return; } nsCOMPtr oldData; aError = SetUserData(aKey, data, aHandler, getter_AddRefs(oldData)); if (aError.Failed()) { - return JS::UndefinedValue(); + return; } if (!oldData) { - return JS::NullValue(); + aRetval.setNull(); + return; } - JS::Rooted result(aCx); JSAutoCompartment ac(aCx, GetWrapper()); aError = nsContentUtils::XPConnect()->VariantToJS(aCx, GetWrapper(), oldData, - &result); - return result; + aRetval); } nsIVariant* @@ -820,19 +820,19 @@ nsINode::GetUserData(const nsAString& aKey) return static_cast(GetProperty(DOM_USER_DATA, key)); } -JS::Value -nsINode::GetUserData(JSContext* aCx, const nsAString& aKey, ErrorResult& aError) +void +nsINode::GetUserData(JSContext* aCx, const nsAString& aKey, + JS::MutableHandle aRetval, ErrorResult& aError) { nsIVariant* data = GetUserData(aKey); if (!data) { - return JS::NullValue(); + aRetval.setNull(); + return; } - JS::Rooted result(aCx); JSAutoCompartment ac(aCx, GetWrapper()); aError = nsContentUtils::XPConnect()->VariantToJS(aCx, GetWrapper(), data, - &result); - return result; + aRetval); } uint16_t diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp index 4e4efb74e40f..aa9c6961654d 100644 --- a/content/base/src/nsObjectLoadingContent.cpp +++ b/content/base/src/nsObjectLoadingContent.cpp @@ -3204,10 +3204,11 @@ nsObjectLoadingContent::GetContentDocument() return sub_doc; } -JS::Value +void nsObjectLoadingContent::LegacyCall(JSContext* aCx, JS::Handle aThisVal, const Sequence& aArguments, + JS::MutableHandle aRetval, ErrorResult& aRv) { nsCOMPtr thisContent = @@ -3221,12 +3222,12 @@ nsObjectLoadingContent::LegacyCall(JSContext* aCx, // this is not an Xray situation by hand. if (!JS_WrapObject(aCx, &obj)) { aRv.Throw(NS_ERROR_UNEXPECTED); - return JS::UndefinedValue(); + return; } if (nsDOMClassInfo::ObjectIsNativeWrapper(aCx, obj)) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); - return JS::UndefinedValue(); + return; } obj = thisContent->GetWrapper(); @@ -3235,33 +3236,33 @@ nsObjectLoadingContent::LegacyCall(JSContext* aCx, JS::AutoValueVector args(aCx); if (!args.append(aArguments.Elements(), aArguments.Length())) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); - return JS::UndefinedValue(); + return; } for (size_t i = 0; i < args.length(); i++) { if (!JS_WrapValue(aCx, args[i])) { aRv.Throw(NS_ERROR_UNEXPECTED); - return JS::UndefinedValue(); + return; } } JS::Rooted thisVal(aCx, aThisVal); if (!JS_WrapValue(aCx, &thisVal)) { aRv.Throw(NS_ERROR_UNEXPECTED); - return JS::UndefinedValue(); + return; } nsRefPtr pi; nsresult rv = ScriptRequestPluginInstance(aCx, getter_AddRefs(pi)); if (NS_FAILED(rv)) { aRv.Throw(rv); - return JS::UndefinedValue(); + return; } // if there's no plugin around for this object, throw. if (!pi) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); - return JS::UndefinedValue(); + return; } JS::Rooted pi_obj(aCx); @@ -3270,23 +3271,21 @@ nsObjectLoadingContent::LegacyCall(JSContext* aCx, rv = GetPluginJSObject(aCx, obj, pi, &pi_obj, &pi_proto); if (NS_FAILED(rv)) { aRv.Throw(rv); - return JS::UndefinedValue(); + return; } if (!pi_obj) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); - return JS::UndefinedValue(); + return; } - JS::Rooted retval(aCx); - bool ok = JS::Call(aCx, thisVal, pi_obj, args, &retval); + bool ok = JS::Call(aCx, thisVal, pi_obj, args, aRetval); if (!ok) { aRv.Throw(NS_ERROR_FAILURE); - return JS::UndefinedValue(); + return; } Telemetry::Accumulate(Telemetry::PLUGIN_CALLED_DIRECTLY, true); - return retval; } void diff --git a/content/base/src/nsObjectLoadingContent.h b/content/base/src/nsObjectLoadingContent.h index df963b5a7e41..fd8910abcfdb 100644 --- a/content/base/src/nsObjectLoadingContent.h +++ b/content/base/src/nsObjectLoadingContent.h @@ -214,9 +214,10 @@ class nsObjectLoadingContent : public nsImageLoadingContent { aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); } - JS::Value LegacyCall(JSContext* aCx, JS::Handle aThisVal, - const mozilla::dom::Sequence& aArguments, - mozilla::ErrorResult& aRv); + void LegacyCall(JSContext* aCx, JS::Handle aThisVal, + const mozilla::dom::Sequence& aArguments, + JS::MutableHandle aRetval, + mozilla::ErrorResult& aRv); protected: /** diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index 029abc0cc02d..658efa0b1e75 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -936,12 +936,14 @@ NS_IMETHODIMP nsXMLHttpRequest::GetResponse(JSContext *aCx, JS::MutableHandle aResult) { ErrorResult rv; - aResult.set(GetResponse(aCx, rv)); + GetResponse(aCx, aResult, rv); return rv.ErrorCode(); } -JS::Value -nsXMLHttpRequest::GetResponse(JSContext* aCx, ErrorResult& aRv) +void +nsXMLHttpRequest::GetResponse(JSContext* aCx, + JS::MutableHandle aResponse, + ErrorResult& aRv) { switch (mResponseType) { case XML_HTTP_RESPONSE_TYPE_DEFAULT: @@ -951,14 +953,12 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, ErrorResult& aRv) nsString str; aRv = GetResponseText(str); if (aRv.Failed()) { - return JSVAL_NULL; + return; } - JS::Rooted result(aCx); - if (!xpc::StringToJsval(aCx, str, &result)) { + if (!xpc::StringToJsval(aCx, str, aResponse)) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); - return JSVAL_NULL; } - return result; + return; } case XML_HTTP_RESPONSE_TYPE_ARRAYBUFFER: @@ -968,7 +968,8 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, ErrorResult& aRv) mState & XML_HTTP_REQUEST_DONE) && !(mResponseType == XML_HTTP_RESPONSE_TYPE_CHUNKED_ARRAYBUFFER && mInLoadProgressEvent)) { - return JSVAL_NULL; + aResponse.setNull(); + return; } if (!mResultArrayBuffer) { @@ -977,17 +978,20 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, ErrorResult& aRv) mResultArrayBuffer = mArrayBufferBuilder.getArrayBuffer(aCx); if (!mResultArrayBuffer) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); - return JSVAL_NULL; + return; } } - return OBJECT_TO_JSVAL(mResultArrayBuffer); + JS::ExposeObjectToActiveJS(mResultArrayBuffer); + aResponse.setObject(*mResultArrayBuffer); + return; } case XML_HTTP_RESPONSE_TYPE_BLOB: case XML_HTTP_RESPONSE_TYPE_MOZ_BLOB: { if (!(mState & XML_HTTP_REQUEST_DONE)) { if (mResponseType != XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) { - return JSVAL_NULL; + aResponse.setNull(); + return; } if (!mResponseBlob) { @@ -996,30 +1000,31 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, ErrorResult& aRv) } if (!mResponseBlob) { - return JSVAL_NULL; + aResponse.setNull(); + return; } - JS::Rooted result(aCx); - aRv = nsContentUtils::WrapNative(aCx, mResponseBlob, &result); - return result; + aRv = nsContentUtils::WrapNative(aCx, mResponseBlob, aResponse); + return; } case XML_HTTP_RESPONSE_TYPE_DOCUMENT: { if (!(mState & XML_HTTP_REQUEST_DONE) || !mResponseXML) { - return JSVAL_NULL; + aResponse.setNull(); + return; } - JS::Rooted result(aCx); - aRv = nsContentUtils::WrapNative(aCx, mResponseXML, &result); - return result; + aRv = nsContentUtils::WrapNative(aCx, mResponseXML, aResponse); + return; } case XML_HTTP_RESPONSE_TYPE_JSON: { if (!(mState & XML_HTTP_REQUEST_DONE)) { - return JSVAL_NULL; + aResponse.setNull(); + return; } - if (mResultJSON == JSVAL_VOID) { + if (mResultJSON.isUndefined()) { aRv = CreateResponseParsedJSON(aCx); mResponseText.Truncate(); if (aRv.Failed()) { @@ -1028,16 +1033,18 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx, ErrorResult& aRv) // It would be nice to log the error to the console. That's hard to // do without calling window.onerror as a side effect, though. JS_ClearPendingException(aCx); - mResultJSON = JSVAL_NULL; + mResultJSON.setNull(); } } - return mResultJSON; + JS::ExposeValueToActiveJS(mResultJSON); + aResponse.set(mResultJSON); + return; } default: NS_ERROR("Should not happen"); } - return JSVAL_NULL; + aResponse.setNull(); } bool @@ -3757,10 +3764,12 @@ nsXMLHttpRequest::GetInterface(const nsIID & aIID, void **aResult) return QueryInterface(aIID, aResult); } -JS::Value -nsXMLHttpRequest::GetInterface(JSContext* aCx, nsIJSID* aIID, ErrorResult& aRv) +void +nsXMLHttpRequest::GetInterface(JSContext* aCx, nsIJSID* aIID, + JS::MutableHandle aRetval, + ErrorResult& aRv) { - return dom::GetInterface(aCx, this, aIID, aRv); + dom::GetInterface(aCx, this, aIID, aRetval, aRv); } nsXMLHttpRequestUpload* diff --git a/content/base/src/nsXMLHttpRequest.h b/content/base/src/nsXMLHttpRequest.h index 13b131b6a7f7..5d7bf04fb74d 100644 --- a/content/base/src/nsXMLHttpRequest.h +++ b/content/base/src/nsXMLHttpRequest.h @@ -494,7 +494,8 @@ public: return XMLHttpRequestResponseType(mResponseType); } void SetResponseType(XMLHttpRequestResponseType aType, ErrorResult& aRv); - JS::Value GetResponse(JSContext* aCx, ErrorResult& aRv); + void GetResponse(JSContext* aCx, JS::MutableHandle aResponse, + ErrorResult& aRv); void GetResponseText(nsString& aResponseText, ErrorResult& aRv); nsIDocument* GetResponseXML(ErrorResult& aRv); @@ -510,7 +511,8 @@ public: } // We need a GetInterface callable from JS for chrome JS - JS::Value GetInterface(JSContext* aCx, nsIJSID* aIID, ErrorResult& aRv); + void GetInterface(JSContext* aCx, nsIJSID* aIID, + JS::MutableHandle aRetval, ErrorResult& aRv); // This creates a trusted readystatechange event, which is not cancelable and // doesn't bubble. diff --git a/content/canvas/src/CanvasRenderingContext2D.cpp b/content/canvas/src/CanvasRenderingContext2D.cpp index 395665e196a9..9e2e9bf93bc8 100644 --- a/content/canvas/src/CanvasRenderingContext2D.cpp +++ b/content/canvas/src/CanvasRenderingContext2D.cpp @@ -3111,10 +3111,12 @@ CanvasRenderingContext2D::SetMozDash(JSContext* cx, } } -JS::Value -CanvasRenderingContext2D::GetMozDash(JSContext* cx, ErrorResult& error) +void +CanvasRenderingContext2D::GetMozDash(JSContext* cx, + JS::MutableHandle retval, + ErrorResult& error) { - return DashArrayToJSVal(CurrentState().dash, cx, error); + DashArrayToJSVal(CurrentState().dash, cx, retval, error); } void diff --git a/content/canvas/src/CanvasRenderingContext2D.h b/content/canvas/src/CanvasRenderingContext2D.h index a8357b6b64e9..caa9f303b2d7 100644 --- a/content/canvas/src/CanvasRenderingContext2D.h +++ b/content/canvas/src/CanvasRenderingContext2D.h @@ -400,7 +400,8 @@ public: mozilla::ErrorResult& error); void GetFillRule(nsAString& fillRule); void SetFillRule(const nsAString& fillRule); - JS::Value GetMozDash(JSContext* cx, mozilla::ErrorResult& error); + void GetMozDash(JSContext* cx, JS::MutableHandle retval, + mozilla::ErrorResult& error); void SetMozDash(JSContext* cx, const JS::Value& mozDash, mozilla::ErrorResult& error); diff --git a/content/canvas/src/CanvasUtils.h b/content/canvas/src/CanvasUtils.h index 03ad723d9faf..ba72c0da8ecb 100644 --- a/content/canvas/src/CanvasUtils.h +++ b/content/canvas/src/CanvasUtils.h @@ -151,18 +151,20 @@ JSValToDashArray(JSContext* cx, const JS::Value& patternArray, } template -JS::Value +void DashArrayToJSVal(FallibleTArray& dashes, - JSContext* cx, mozilla::ErrorResult& rv) + JSContext* cx, + JS::MutableHandle retval, + mozilla::ErrorResult& rv) { if (dashes.IsEmpty()) { - return JS::NullValue(); + retval.setNull(); + return; } JS::Rooted val(cx); - if (!mozilla::dom::ToJSValue(cx, dashes, &val)) { + if (!mozilla::dom::ToJSValue(cx, dashes, retval)) { rv.Throw(NS_ERROR_OUT_OF_MEMORY); } - return val; } } diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index 85836f65a6fd..c9c0aeb64450 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -357,9 +357,10 @@ public: dom::Nullable< nsTArray > &retval); GLint GetAttribLocation(WebGLProgram* prog, const nsAString& name); JS::Value GetBufferParameter(GLenum target, GLenum pname); - JS::Value GetBufferParameter(JSContext* /* unused */, GLenum target, - GLenum pname) { - return GetBufferParameter(target, pname); + void GetBufferParameter(JSContext* /* unused */, GLenum target, + GLenum pname, + JS::MutableHandle retval) { + retval.set(GetBufferParameter(target, pname)); } GLenum GetError(); JS::Value GetFramebufferAttachmentParameter(JSContext* cx, @@ -367,22 +368,34 @@ public: GLenum attachment, GLenum pname, ErrorResult& rv); + void GetFramebufferAttachmentParameter(JSContext* cx, + GLenum target, + GLenum attachment, + GLenum pname, + JS::MutableHandle retval, + ErrorResult& rv) { + retval.set(GetFramebufferAttachmentParameter(cx, target, attachment, + pname, rv)); + } JS::Value GetProgramParameter(WebGLProgram *prog, GLenum pname); - JS::Value GetProgramParameter(JSContext* /* unused */, WebGLProgram *prog, - GLenum pname) { - return GetProgramParameter(prog, pname); + void GetProgramParameter(JSContext* /* unused */, WebGLProgram *prog, + GLenum pname, + JS::MutableHandle retval) { + retval.set(GetProgramParameter(prog, pname)); } void GetProgramInfoLog(WebGLProgram *prog, nsACString& retval); void GetProgramInfoLog(WebGLProgram *prog, nsAString& retval); JS::Value GetRenderbufferParameter(GLenum target, GLenum pname); - JS::Value GetRenderbufferParameter(JSContext* /* unused */, - GLenum target, GLenum pname) { - return GetRenderbufferParameter(target, pname); + void GetRenderbufferParameter(JSContext* /* unused */, + GLenum target, GLenum pname, + JS::MutableHandle retval) { + retval.set(GetRenderbufferParameter(target, pname)); } JS::Value GetShaderParameter(WebGLShader *shader, GLenum pname); - JS::Value GetShaderParameter(JSContext* /* unused */, WebGLShader *shader, - GLenum pname) { - return GetShaderParameter(shader, pname); + void GetShaderParameter(JSContext* /* unused */, WebGLShader *shader, + GLenum pname, + JS::MutableHandle retval) { + retval.set(GetShaderParameter(shader, pname)); } already_AddRefed GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype); @@ -391,12 +404,18 @@ public: void GetShaderSource(WebGLShader *shader, nsAString& retval); void GetShaderTranslatedSource(WebGLShader *shader, nsAString& retval); JS::Value GetTexParameter(GLenum target, GLenum pname); - JS::Value GetTexParameter(JSContext * /* unused */, GLenum target, - GLenum pname) { - return GetTexParameter(target, pname); + void GetTexParameter(JSContext * /* unused */, GLenum target, + GLenum pname, + JS::MutableHandle retval) { + retval.set(GetTexParameter(target, pname)); } JS::Value GetUniform(JSContext* cx, WebGLProgram *prog, WebGLUniformLocation *location); + void GetUniform(JSContext* cx, WebGLProgram *prog, + WebGLUniformLocation *location, + JS::MutableHandle retval) { + retval.set(GetUniform(cx, prog, location)); + } already_AddRefed GetUniformLocation(WebGLProgram *prog, const nsAString& name); void Hint(GLenum target, GLenum mode); @@ -691,6 +710,10 @@ public: bool IsQuery(WebGLQuery *query); already_AddRefed GetQuery(GLenum target, GLenum pname); JS::Value GetQueryObject(JSContext* cx, WebGLQuery *query, GLenum pname); + void GetQueryObject(JSContext* cx, WebGLQuery *query, GLenum pname, + JS::MutableHandle retval) { + retval.set(GetQueryObject(cx, query, pname)); + } private: // ANY_SAMPLES_PASSED(_CONSERVATIVE) slot @@ -740,7 +763,12 @@ public: void Disable(GLenum cap); void Enable(GLenum cap); JS::Value GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv); - JS::Value GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index); + void GetParameter(JSContext* cx, GLenum pname, + JS::MutableHandle retval, ErrorResult& rv) { + retval.set(GetParameter(cx, pname, rv)); + } + void GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index, + JS::MutableHandle retval); bool IsEnabled(GLenum cap); private: @@ -766,6 +794,11 @@ public: JS::Value GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname, ErrorResult& rv); + void GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname, + JS::MutableHandle retval, + ErrorResult& rv) { + retval.set(GetVertexAttrib(cx, index, pname, rv)); + } WebGLsizeiptr GetVertexAttribOffset(GLuint index, GLenum pname); void VertexAttrib1f(GLuint index, GLfloat x0); diff --git a/content/canvas/src/WebGLContextState.cpp b/content/canvas/src/WebGLContextState.cpp index dffe5f6cf7a4..0eace1a38bdf 100644 --- a/content/canvas/src/WebGLContextState.cpp +++ b/content/canvas/src/WebGLContextState.cpp @@ -454,11 +454,14 @@ WebGLContext::GetParameter(JSContext* cx, GLenum pname, ErrorResult& rv) return JS::NullValue(); } -JS::Value -WebGLContext::GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index) +void +WebGLContext::GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index, + JS::MutableHandle retval) { - if (IsContextLost()) - return JS::NullValue(); + if (IsContextLost()) { + retval.setNull(); + return; + } MakeContextCurrent(); @@ -467,9 +470,11 @@ WebGLContext::GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index) { if (index >= mGLMaxTransformFeedbackSeparateAttribs) { ErrorInvalidValue("getParameterIndexed: index should be less than MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", index); - return JS::NullValue(); + retval.setNull(); + return; } - return JS::NullValue(); // See bug 903594 + retval.setNull(); // See bug 903594 + return; } default: @@ -477,7 +482,7 @@ WebGLContext::GetParameterIndexed(JSContext* cx, GLenum pname, GLuint index) } ErrorInvalidEnumInfo("getParameterIndexed: parameter", pname); - return JS::NullValue(); + retval.setNull(); } bool diff --git a/content/html/content/src/HTMLPropertiesCollection.cpp b/content/html/content/src/HTMLPropertiesCollection.cpp index 95833483aab3..238508c849bf 100644 --- a/content/html/content/src/HTMLPropertiesCollection.cpp +++ b/content/html/content/src/HTMLPropertiesCollection.cpp @@ -426,7 +426,8 @@ PropertyNodeList::GetValues(JSContext* aCx, nsTArray& aResult, JSAutoCompartment ac(aCx, wrapper); uint32_t length = mElements.Length(); for (uint32_t i = 0; i < length; ++i) { - JS::Value v = mElements.ElementAt(i)->GetItemValue(aCx, wrapper, aError); + JS::Rooted v(aCx); + mElements.ElementAt(i)->GetItemValue(aCx, wrapper, &v, aError); if (aError.Failed()) { return; } diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 69fc2f906656..4b72322cb86c 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -3041,33 +3041,31 @@ nsGenericHTMLFormElementWithState::NodeInfoChanged(nsINodeInfo* aOldNodeInfo) mStateKey.SetIsVoid(true); } -JS::Value +void nsGenericHTMLElement::GetItemValue(JSContext* aCx, JSObject* aScope, + JS::MutableHandle aRetval, ErrorResult& aError) { JS::Rooted scope(aCx, aScope); if (!HasAttr(kNameSpaceID_None, nsGkAtoms::itemprop)) { - return JS::NullValue(); + aRetval.setNull(); + return; } if (ItemScope()) { JS::Rooted v(aCx); JSAutoCompartment ac(aCx, scope); - if (!mozilla::dom::WrapObject(aCx, this, &v)) { + if (!mozilla::dom::WrapObject(aCx, this, aRetval)) { aError.Throw(NS_ERROR_FAILURE); - return JS::UndefinedValue(); } - return v; + return; } nsString string; GetItemValueText(string); - JS::Rooted v(aCx); - if (!xpc::NonVoidStringToJsval(aCx, string, &v)) { + if (!xpc::NonVoidStringToJsval(aCx, string, aRetval)) { aError.Throw(NS_ERROR_FAILURE); - return JS::UndefinedValue(); } - return v; } NS_IMETHODIMP diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index 2653d8c5a09a..cefa6bb5e3e3 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -124,11 +124,13 @@ public: return GetTokenList(nsGkAtoms::itemprop); } mozilla::dom::HTMLPropertiesCollection* Properties(); - JS::Value GetItemValue(JSContext* aCx, JSObject* aScope, - mozilla::ErrorResult& aError); - JS::Value GetItemValue(JSContext* aCx, mozilla::ErrorResult& aError) + void GetItemValue(JSContext* aCx, JSObject* aScope, + JS::MutableHandle aRetval, + mozilla::ErrorResult& aError); + void GetItemValue(JSContext* aCx, JS::MutableHandle aRetval, + mozilla::ErrorResult& aError) { - return GetItemValue(aCx, GetWrapperPreserveColor(), aError); + GetItemValue(aCx, GetWrapperPreserveColor(), aRetval, aError); } void SetItemValue(JSContext* aCx, JS::Value aValue, mozilla::ErrorResult& aError); diff --git a/dom/base/DOMRequest.cpp b/dom/base/DOMRequest.cpp index cb48a8a71b22..ae1391ada65f 100644 --- a/dom/base/DOMRequest.cpp +++ b/dom/base/DOMRequest.cpp @@ -83,7 +83,7 @@ DOMRequest::GetReadyState(nsAString& aReadyState) NS_IMETHODIMP DOMRequest::GetResult(JS::MutableHandle aResult) { - aResult.set(Result()); + GetResult(nullptr, aResult); return NS_OK; } diff --git a/dom/base/DOMRequest.h b/dom/base/DOMRequest.h index 20759dcfb905..cf2fc0daeee6 100644 --- a/dom/base/DOMRequest.h +++ b/dom/base/DOMRequest.h @@ -49,11 +49,12 @@ public: : DOMRequestReadyState::Pending; } - JS::Value Result(JSContext* = nullptr) const + void GetResult(JSContext*, JS::MutableHandle aRetval) const { NS_ASSERTION(mDone || mResult == JSVAL_VOID, - "Result should be undefined when pending"); - return mResult; + "Result should be undefined when pending"); + JS::ExposeValueToActiveJS(mResult); + aRetval.set(mResult); } DOMError* GetError() const diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index a77c0bab1d6e..fef2e38fc24e 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -4503,17 +4503,17 @@ nsGlobalWindow::GetOpenerWindow(ErrorResult& aError) return nullptr; } -JS::Value -nsGlobalWindow::GetOpener(JSContext* aCx, ErrorResult& aError) +void +nsGlobalWindow::GetOpener(JSContext* aCx, JS::MutableHandle aRetval, + ErrorResult& aError) { nsCOMPtr opener = GetOpenerWindow(aError); if (aError.Failed() || !opener) { - return JS::NullValue(); + aRetval.setNull(); + return; } - JS::Rooted val(aCx); - aError = nsContentUtils::WrapNative(aCx, opener, &val); - return val; + aError = nsContentUtils::WrapNative(aCx, opener, aRetval); } NS_IMETHODIMP @@ -4521,7 +4521,7 @@ nsGlobalWindow::GetScriptableOpener(JSContext* aCx, JS::MutableHandle aOpener) { ErrorResult rv; - aOpener.set(GetOpener(aCx, rv)); + GetOpener(aCx, aOpener, rv); return rv.ErrorCode(); } @@ -9110,10 +9110,11 @@ nsGlobalWindow::ShowModalDialog(const nsAString& aUrl, nsIVariant* aArgument, return retVal.forget(); } -JS::Value +void nsGlobalWindow::ShowModalDialog(JSContext* aCx, const nsAString& aUrl, JS::Handle aArgument, const nsAString& aOptions, + JS::MutableHandle aRetval, ErrorResult& aError) { nsCOMPtr args; @@ -9121,23 +9122,22 @@ nsGlobalWindow::ShowModalDialog(JSContext* aCx, const nsAString& aUrl, aArgument, getter_AddRefs(args)); if (aError.Failed()) { - return JS::UndefinedValue(); + return; } nsCOMPtr retVal = ShowModalDialog(aUrl, args, aOptions, aError); if (aError.Failed()) { - return JS::UndefinedValue(); + return; } JS::Rooted result(aCx); if (retVal) { aError = nsContentUtils::XPConnect()->VariantToJS(aCx, FastGetGlobalJSObject(), - retVal, &result); + retVal, aRetval); } else { - result = JS::NullValue(); + aRetval.setNull(); } - return result; } NS_IMETHODIMP @@ -10585,10 +10585,12 @@ nsGlobalWindow::GetInterface(const nsIID & aIID, void **aSink) return *aSink ? NS_OK : NS_ERROR_NO_INTERFACE; } -JS::Value -nsGlobalWindow::GetInterface(JSContext* aCx, nsIJSID* aIID, ErrorResult& aError) +void +nsGlobalWindow::GetInterface(JSContext* aCx, nsIJSID* aIID, + JS::MutableHandle aRetval, + ErrorResult& aError) { - return dom::GetInterface(aCx, this, aIID, aError); + dom::GetInterface(aCx, this, aIID, aRetval, aError); } void @@ -12098,7 +12100,8 @@ nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout, // Hold strong ref to ourselves while we call the callback. nsCOMPtr me(static_cast(this)); ErrorResult ignored; - callback->Call(me, handler->GetArgs(), ignored); + JS::Rooted ignoredVal(CycleCollectedJSRuntime::Get()->Runtime()); + callback->Call(me, handler->GetArgs(), &ignoredVal, ignored); } // We ignore any failures from calling EvaluateString() on the context or @@ -13623,28 +13626,29 @@ NS_IMPL_ADDREF_INHERITED(nsGlobalModalWindow, nsGlobalWindow) NS_IMPL_RELEASE_INHERITED(nsGlobalModalWindow, nsGlobalWindow) -JS::Value -nsGlobalWindow::GetDialogArguments(JSContext* aCx, ErrorResult& aError) +void +nsGlobalWindow::GetDialogArguments(JSContext* aCx, + JS::MutableHandle aRetval, + ErrorResult& aError) { - FORWARD_TO_OUTER_OR_THROW(GetDialogArguments, (aCx, aError), aError, - JS::UndefinedValue()); + FORWARD_TO_OUTER_OR_THROW(GetDialogArguments, (aCx, aRetval, aError), + aError, ); MOZ_ASSERT(IsModalContentWindow(), "This should only be called on modal windows!"); if (!mDialogArguments) { MOZ_ASSERT(mIsClosed, "This window should be closed!"); - return JS::UndefinedValue(); + aRetval.setUndefined(); + return; } // This does an internal origin check, and returns undefined if the subject // does not subsumes the origin of the arguments. JS::Rooted wrapper(aCx, GetWrapper()); JSAutoCompartment ac(aCx, wrapper); - JS::Rooted args(aCx); mDialogArguments->Get(aCx, wrapper, nsContentUtils::SubjectPrincipal(), - &args, aError); - return args; + aRetval, aError); } NS_IMETHODIMP @@ -13658,23 +13662,25 @@ nsGlobalModalWindow::GetDialogArguments(nsIVariant **aArguments) return mDialogArguments->Get(nsContentUtils::SubjectPrincipal(), aArguments); } -JS::Value -nsGlobalWindow::GetReturnValue(JSContext* aCx, ErrorResult& aError) +void +nsGlobalWindow::GetReturnValue(JSContext* aCx, + JS::MutableHandle aReturnValue, + ErrorResult& aError) { - FORWARD_TO_OUTER_OR_THROW(GetReturnValue, (aCx, aError), aError, - JS::UndefinedValue()); + FORWARD_TO_OUTER_OR_THROW(GetReturnValue, (aCx, aReturnValue, aError), + aError, ); MOZ_ASSERT(IsModalContentWindow(), "This should only be called on modal windows!"); - JS::Rooted returnValue(aCx); if (mReturnValue) { JS::Rooted wrapper(aCx, GetWrapper()); JSAutoCompartment ac(aCx, wrapper); mReturnValue->Get(aCx, wrapper, nsContentUtils::SubjectPrincipal(), - &returnValue, aError); + aReturnValue, aError); + } else { + aReturnValue.setUndefined(); } - return returnValue; } NS_IMETHODIMP diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index dbbe2cffa1c3..d09df681842c 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -837,7 +837,8 @@ public: protected: nsIDOMWindow* GetOpenerWindow(mozilla::ErrorResult& aError); public: - JS::Value GetOpener(JSContext* aCx, mozilla::ErrorResult& aError); + void GetOpener(JSContext* aCx, JS::MutableHandle aRetval, + mozilla::ErrorResult& aError); void SetOpener(JSContext* aCx, JS::Handle aOpener, mozilla::ErrorResult& aError); using nsIDOMWindow::GetParent; @@ -867,7 +868,11 @@ public: void Prompt(const nsAString& aMessage, const nsAString& aInitial, nsAString& aReturn, mozilla::ErrorResult& aError); void Print(mozilla::ErrorResult& aError); - JS::Value ShowModalDialog(JSContext* aCx, const nsAString& aUrl, JS::Handle aArgument, const nsAString& aOptions, mozilla::ErrorResult& aError); + void ShowModalDialog(JSContext* aCx, const nsAString& aUrl, + JS::Handle aArgument, + const nsAString& aOptions, + JS::MutableHandle aRetval, + mozilla::ErrorResult& aError); void PostMessageMoz(JSContext* aCx, JS::Handle aMessage, const nsAString& aTargetOrigin, const mozilla::dom::Optional >& aTransfer, @@ -1017,13 +1022,16 @@ public: mozilla::dom::Element* aPanel, mozilla::ErrorResult& aError); - JS::Value GetDialogArguments(JSContext* aCx, mozilla::ErrorResult& aError); - JS::Value GetReturnValue(JSContext* aCx, mozilla::ErrorResult& aError); + void GetDialogArguments(JSContext* aCx, JS::MutableHandle aRetval, + mozilla::ErrorResult& aError); + void GetReturnValue(JSContext* aCx, JS::MutableHandle aReturnValue, + mozilla::ErrorResult& aError); void SetReturnValue(JSContext* aCx, JS::Handle aReturnValue, mozilla::ErrorResult& aError); - JS::Value GetInterface(JSContext* aCx, nsIJSID* aIID, - mozilla::ErrorResult& aError); + void GetInterface(JSContext* aCx, nsIJSID* aIID, + JS::MutableHandle aRetval, + mozilla::ErrorResult& aError); protected: // Array of idle observers that are notified of idle events. diff --git a/dom/base/nsHistory.cpp b/dom/base/nsHistory.cpp index 2911355dd4d8..9ec76e65a70c 100644 --- a/dom/base/nsHistory.cpp +++ b/dom/base/nsHistory.cpp @@ -96,50 +96,46 @@ nsHistory::GetLength(ErrorResult& aRv) const return len >= 0 ? len : 0; } -JS::Value -nsHistory::GetState(JSContext* aCx, ErrorResult& aRv) const +void +nsHistory::GetState(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) const { nsCOMPtr win(do_QueryReferent(mInnerWindow)); if (!win) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); - - return JS::UndefinedValue(); + return; } if (!win->HasActiveDocument()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); - - return JS::UndefinedValue(); + return; } nsCOMPtr doc = do_QueryInterface(win->GetExtantDoc()); if (!doc) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); - - return JS::UndefinedValue(); + return; } nsCOMPtr variant; doc->GetStateObject(getter_AddRefs(variant)); if (variant) { - JS::Rooted jsData(aCx); - aRv = variant->GetAsJSVal(&jsData); + aRv = variant->GetAsJSVal(aResult); if (aRv.Failed()) { - return JS::UndefinedValue(); + return; } - if (!JS_WrapValue(aCx, &jsData)) { + if (!JS_WrapValue(aCx, aResult)) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); - return JS::UndefinedValue(); } - return jsData; + return; } - return JS::NullValue(); + aResult.setNull(); } void diff --git a/dom/base/nsHistory.h b/dom/base/nsHistory.h index 9361538a5da2..a06945f85a93 100644 --- a/dom/base/nsHistory.h +++ b/dom/base/nsHistory.h @@ -37,7 +37,8 @@ public: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; uint32_t GetLength(mozilla::ErrorResult& aRv) const; - JS::Value GetState(JSContext* aCx, mozilla::ErrorResult& aRv) const; + void GetState(JSContext* aCx, JS::MutableHandle aResult, + mozilla::ErrorResult& aRv) const; void Go(int32_t aDelta, mozilla::ErrorResult& aRv); void Back(mozilla::ErrorResult& aRv); void Forward(mozilla::ErrorResult& aRv); diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 5a0d397f80c3..c423ab7f3a90 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -884,25 +884,22 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp) return true; } -JS::Value +void GetInterfaceImpl(JSContext* aCx, nsIInterfaceRequestor* aRequestor, - nsWrapperCache* aCache, nsIJSID* aIID, ErrorResult& aError) + nsWrapperCache* aCache, nsIJSID* aIID, + JS::MutableHandle aRetval, ErrorResult& aError) { const nsID* iid = aIID->GetID(); nsRefPtr result; aError = aRequestor->GetInterface(*iid, getter_AddRefs(result)); if (aError.Failed()) { - return JS::NullValue(); + return; } - JS::Rooted v(aCx, JSVAL_NULL); - if (!WrapObject(aCx, result, iid, &v)) { + if (!WrapObject(aCx, result, iid, aRetval)) { aError.Throw(NS_ERROR_FAILURE); - return JS::NullValue(); } - - return v; } bool diff --git a/dom/bindings/BindingUtils.h b/dom/bindings/BindingUtils.h index 5e4219afb4d4..ea754e7dabfe 100644 --- a/dom/bindings/BindingUtils.h +++ b/dom/bindings/BindingUtils.h @@ -1649,15 +1649,17 @@ WantsQueryInterface } }; -JS::Value +void GetInterfaceImpl(JSContext* aCx, nsIInterfaceRequestor* aRequestor, - nsWrapperCache* aCache, nsIJSID* aIID, ErrorResult& aError); + nsWrapperCache* aCache, nsIJSID* aIID, + JS::MutableHandle aRetval, ErrorResult& aError); template -JS::Value -GetInterface(JSContext* aCx, T* aThis, nsIJSID* aIID, ErrorResult& aError) +void +GetInterface(JSContext* aCx, T* aThis, nsIJSID* aIID, + JS::MutableHandle aRetval, ErrorResult& aError) { - return GetInterfaceImpl(aCx, aThis, aThis, aIID, aError); + GetInterfaceImpl(aCx, aThis, aThis, aIID, aRetval, aError); } bool diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 8338c5e84a09..ae22833c291c 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -5638,7 +5638,9 @@ def getRetvalDeclarationForType(returnType, descriptorProvider, name = returnType.unroll().identifier.name return CGGeneric("nsRefPtr<%s>" % name), None, None, None if returnType.isAny(): - return CGGeneric("JS::Value"), None, None, None + if isMember: + return CGGeneric("JS::Value"), None, None, None + return CGGeneric("JS::Rooted"), "ptr", None, "cx" if returnType.isObject() or returnType.isSpiderMonkeyInterface(): return CGGeneric("JSObject*"), None, None, None if returnType.isSequence(): @@ -11579,7 +11581,12 @@ class CGNativeMember(ClassMethod): return ("already_AddRefed<%s>" % type.unroll().identifier.name, "nullptr", "return ${declName}.forget();\n") if type.isAny(): - return "JS::Value", "JS::UndefinedValue()", "return ${declName};\n" + if isMember: + # No need for a third element in the isMember case + return "JS::Value", None, None + # Outparam + return "void", "", "aRetVal.set(${declName});\n" + if type.isObject(): return "JSObject*", "nullptr", "return ${declName};\n" if type.isSpiderMonkeyInterface(): @@ -11677,6 +11684,9 @@ class CGNativeMember(ClassMethod): args.append(Argument("%s&" % CGUnionStruct.unionTypeDecl(returnType, True), "aRetVal")) + elif returnType.isAny(): + args.append(Argument("JS::MutableHandle", "aRetVal")) + # And the ErrorResult if 'infallible' not in self.extendedAttrs: # Use aRv so it won't conflict with local vars named "rv" @@ -13563,7 +13573,8 @@ class CGEventGetter(CGNativeMember): return fill( """ JS::ExposeValueToActiveJS(${memberName}); - return ${memberName}; + aRetVal.set(${memberName}); + return; """, memberName=memberName) if type.isUnion(): diff --git a/dom/bindings/test/TestBindingHeader.h b/dom/bindings/test/TestBindingHeader.h index ae7e01212e93..2f9e8b2cab3f 100644 --- a/dom/bindings/test/TestBindingHeader.h +++ b/dom/bindings/test/TestBindingHeader.h @@ -523,7 +523,7 @@ public: void PassOptionalNullableMozMapOfNullableMozMapOfAny(JSContext*, const Optional>>>>&); void PassOptionalNullableMozMapOfNullableSequenceOfAny(JSContext*, const Optional>>>>&); void PassOptionalNullableSequenceOfNullableMozMapOfAny(JSContext*, const Optional>>>>&); - JS::Value ReceiveAny(JSContext*); + void ReceiveAny(JSContext*, JS::MutableHandle); // object types void PassObject(JSContext*, JS::Handle); @@ -767,7 +767,7 @@ public: TestInterface* PutForwardsAttr(); TestInterface* PutForwardsAttr2(); TestInterface* PutForwardsAttr3(); - JS::Value JsonifierShouldSkipThis(JSContext*); + void GetJsonifierShouldSkipThis(JSContext*, JS::MutableHandle); void SetJsonifierShouldSkipThis(JSContext*, JS::Rooted&); TestParentInterface* JsonifierShouldSkipThis2(); void SetJsonifierShouldSkipThis2(TestParentInterface&); diff --git a/dom/bluetooth/BluetoothAdapter.cpp b/dom/bluetooth/BluetoothAdapter.cpp index 79001c0282ca..f494d88dc8e6 100644 --- a/dom/bluetooth/BluetoothAdapter.cpp +++ b/dom/bluetooth/BluetoothAdapter.cpp @@ -429,30 +429,34 @@ BluetoothAdapter::StopDiscovery(ErrorResult& aRv) return StartStopDiscovery(false, aRv); } -JS::Value -BluetoothAdapter::GetDevices(JSContext* aContext, ErrorResult& aRv) +void +BluetoothAdapter::GetDevices(JSContext* aContext, + JS::MutableHandle aDevices, + ErrorResult& aRv) { if (!mJsDeviceAddresses) { BT_WARNING("Devices not yet set!\n"); aRv.Throw(NS_ERROR_FAILURE); - return JS::NullValue(); + return; } JS::ExposeObjectToActiveJS(mJsDeviceAddresses); - return JS::ObjectValue(*mJsDeviceAddresses); + aDevices.setObject(*mJsDeviceAddresses); } -JS::Value -BluetoothAdapter::GetUuids(JSContext* aContext, ErrorResult& aRv) +void +BluetoothAdapter::GetUuids(JSContext* aContext, + JS::MutableHandle aUuids, + ErrorResult& aRv) { if (!mJsUuids) { BT_WARNING("UUIDs not yet set!\n"); aRv.Throw(NS_ERROR_FAILURE); - return JS::NullValue(); + return; } JS::ExposeObjectToActiveJS(mJsUuids); - return JS::ObjectValue(*mJsUuids); + aUuids.setObject(*mJsUuids); } already_AddRefed diff --git a/dom/bluetooth/BluetoothAdapter.h b/dom/bluetooth/BluetoothAdapter.h index 11582aa44aa3..6329a10226da 100644 --- a/dom/bluetooth/BluetoothAdapter.h +++ b/dom/bluetooth/BluetoothAdapter.h @@ -83,8 +83,10 @@ public: return mDiscoverableTimeout; } - JS::Value GetDevices(JSContext* aContext, ErrorResult& aRv); - JS::Value GetUuids(JSContext* aContext, ErrorResult& aRv); + void GetDevices(JSContext* aContext, JS::MutableHandle aDevices, + ErrorResult& aRv); + void GetUuids(JSContext* aContext, JS::MutableHandle aUuids, + ErrorResult& aRv); already_AddRefed SetName(const nsAString& aName, ErrorResult& aRv); diff --git a/dom/bluetooth/BluetoothDevice.cpp b/dom/bluetooth/BluetoothDevice.cpp index 283555c3e387..cf00a4f11b81 100644 --- a/dom/bluetooth/BluetoothDevice.cpp +++ b/dom/bluetooth/BluetoothDevice.cpp @@ -206,30 +206,34 @@ BluetoothDevice::Notify(const BluetoothSignal& aData) } } -JS::Value -BluetoothDevice::GetUuids(JSContext* aCx, ErrorResult& aRv) +void +BluetoothDevice::GetUuids(JSContext* aContext, + JS::MutableHandle aUuids, + ErrorResult& aRv) { if (!mJsUuids) { BT_WARNING("UUIDs not yet set!"); aRv.Throw(NS_ERROR_FAILURE); - return JS::NullValue(); + return; } JS::ExposeObjectToActiveJS(mJsUuids); - return JS::ObjectValue(*mJsUuids); + aUuids.setObject(*mJsUuids); } -JS::Value -BluetoothDevice::GetServices(JSContext* aCx, ErrorResult& aRv) +void +BluetoothDevice::GetServices(JSContext* aCx, + JS::MutableHandle aServices, + ErrorResult& aRv) { if (!mJsServices) { BT_WARNING("Services not yet set!"); aRv.Throw(NS_ERROR_FAILURE); - return JS::Value(JSVAL_NULL); + return; } JS::ExposeObjectToActiveJS(mJsServices); - return JS::ObjectValue(*mJsServices); + aServices.setObject(*mJsServices); } JSObject* diff --git a/dom/bluetooth/BluetoothDevice.h b/dom/bluetooth/BluetoothDevice.h index e5a04fd01d71..ad179981f422 100644 --- a/dom/bluetooth/BluetoothDevice.h +++ b/dom/bluetooth/BluetoothDevice.h @@ -66,8 +66,10 @@ public: return mConnected; } - JS::Value GetUuids(JSContext* aContext, ErrorResult& aRv); - JS::Value GetServices(JSContext* aContext, ErrorResult& aRv); + void GetUuids(JSContext* aContext, JS::MutableHandle aUuids, + ErrorResult& aRv); + void GetServices(JSContext* aContext, JS::MutableHandle aServices, + ErrorResult& aRv); nsISupports* ToISupports() diff --git a/dom/bluetooth2/BluetoothAdapter.cpp b/dom/bluetooth2/BluetoothAdapter.cpp index 1e0cd38437a5..f79fb21c11ff 100644 --- a/dom/bluetooth2/BluetoothAdapter.cpp +++ b/dom/bluetooth2/BluetoothAdapter.cpp @@ -457,30 +457,34 @@ BluetoothAdapter::StopDiscovery(ErrorResult& aRv) return StartStopDiscovery(false, aRv); } -JS::Value -BluetoothAdapter::GetDevices(JSContext* aContext, ErrorResult& aRv) +void +BluetoothAdapter::GetDevices(JSContext* aContext, + JS::MutableHandle aDevices, + ErrorResult& aRv) { if (!mJsDeviceAddresses) { BT_WARNING("Devices not yet set!\n"); aRv.Throw(NS_ERROR_FAILURE); - return JS::NullValue(); + return; } JS::ExposeObjectToActiveJS(mJsDeviceAddresses); - return JS::ObjectValue(*mJsDeviceAddresses); + aDevices.setObject(*mJsDeviceAddresses); } -JS::Value -BluetoothAdapter::GetUuids(JSContext* aContext, ErrorResult& aRv) +void +BluetoothAdapter::GetUuids(JSContext* aContext, + JS::MutableHandle aUuids, + ErrorResult& aRv) { if (!mJsUuids) { BT_WARNING("UUIDs not yet set!\n"); aRv.Throw(NS_ERROR_FAILURE); - return JS::NullValue(); + return; } JS::ExposeObjectToActiveJS(mJsUuids); - return JS::ObjectValue(*mJsUuids); + aUuids.setObject(*mJsUuids); } already_AddRefed diff --git a/dom/bluetooth2/BluetoothAdapter.h b/dom/bluetooth2/BluetoothAdapter.h index f067905c2700..faf4b31cab87 100644 --- a/dom/bluetooth2/BluetoothAdapter.h +++ b/dom/bluetooth2/BluetoothAdapter.h @@ -90,8 +90,10 @@ public: return mDiscoverableTimeout; } - JS::Value GetDevices(JSContext* aContext, ErrorResult& aRv); - JS::Value GetUuids(JSContext* aContext, ErrorResult& aRv); + void GetDevices(JSContext* aContext, JS::MutableHandle aDevices, + ErrorResult& aRv); + void GetUuids(JSContext* aContext, JS::MutableHandle aUuids, + ErrorResult& aRv); already_AddRefed SetName(const nsAString& aName, ErrorResult& aRv); diff --git a/dom/bluetooth2/BluetoothDevice.cpp b/dom/bluetooth2/BluetoothDevice.cpp index c33aec40db08..d4233767dba6 100644 --- a/dom/bluetooth2/BluetoothDevice.cpp +++ b/dom/bluetooth2/BluetoothDevice.cpp @@ -206,30 +206,34 @@ BluetoothDevice::Notify(const BluetoothSignal& aData) } } -JS::Value -BluetoothDevice::GetUuids(JSContext* aCx, ErrorResult& aRv) +void +BluetoothDevice::GetUuids(JSContext* aContext, + JS::MutableHandle aUuids, + ErrorResult& aRv) { if (!mJsUuids) { BT_WARNING("UUIDs not yet set!"); aRv.Throw(NS_ERROR_FAILURE); - return JS::NullValue(); + return; } JS::ExposeObjectToActiveJS(mJsUuids); - return JS::ObjectValue(*mJsUuids); + aUuids.setObject(*mJsUuids); } -JS::Value -BluetoothDevice::GetServices(JSContext* aCx, ErrorResult& aRv) +void +BluetoothDevice::GetServices(JSContext* aCx, + JS::MutableHandle aServices, + ErrorResult& aRv) { if (!mJsServices) { BT_WARNING("Services not yet set!"); aRv.Throw(NS_ERROR_FAILURE); - return JS::Value(JSVAL_NULL); + return; } JS::ExposeObjectToActiveJS(mJsServices); - return JS::ObjectValue(*mJsServices); + aServices.setObject(*mJsServices); } JSObject* diff --git a/dom/bluetooth2/BluetoothDevice.h b/dom/bluetooth2/BluetoothDevice.h index e5a04fd01d71..ad179981f422 100644 --- a/dom/bluetooth2/BluetoothDevice.h +++ b/dom/bluetooth2/BluetoothDevice.h @@ -66,8 +66,10 @@ public: return mConnected; } - JS::Value GetUuids(JSContext* aContext, ErrorResult& aRv); - JS::Value GetServices(JSContext* aContext, ErrorResult& aRv); + void GetUuids(JSContext* aContext, JS::MutableHandle aUuids, + ErrorResult& aRv); + void GetServices(JSContext* aContext, JS::MutableHandle aServices, + ErrorResult& aRv); nsISupports* ToISupports() diff --git a/dom/camera/DOMCameraCapabilities.cpp b/dom/camera/DOMCameraCapabilities.cpp index c2df90e972cf..0c9c2cf3b31f 100644 --- a/dom/camera/DOMCameraCapabilities.cpp +++ b/dom/camera/DOMCameraCapabilities.cpp @@ -293,10 +293,12 @@ CameraCapabilities::ExposureCompensationStep() const return mExposureCompensationStep; } -JS::Value -CameraCapabilities::RecorderProfiles(JSContext* aCx) const +void +CameraCapabilities::GetRecorderProfiles(JSContext* aCx, + JS::MutableHandle aRetval) const { - return mRecorderProfiles; + JS::ExposeValueToActiveJS(mRecorderProfiles); + aRetval.set(mRecorderProfiles); } void diff --git a/dom/camera/DOMCameraCapabilities.h b/dom/camera/DOMCameraCapabilities.h index 8540ba663f23..7427b3de3faf 100644 --- a/dom/camera/DOMCameraCapabilities.h +++ b/dom/camera/DOMCameraCapabilities.h @@ -71,7 +71,7 @@ public: double MinExposureCompensation() const; double MaxExposureCompensation() const; double ExposureCompensationStep() const; - JS::Value RecorderProfiles(JSContext* cx) const; + void GetRecorderProfiles(JSContext* aCx, JS::MutableHandle aRetval) const; void GetIsoModes(nsTArray& aRetVal) const; protected: diff --git a/dom/datastore/DataStoreDB.cpp b/dom/datastore/DataStoreDB.cpp index ecb73926e3b0..c9adb749b804 100644 --- a/dom/datastore/DataStoreDB.cpp +++ b/dom/datastore/DataStoreDB.cpp @@ -129,7 +129,8 @@ DataStoreDB::UpgradeSchema() AutoSafeJSContext cx; ErrorResult error; - JS::Rooted result(cx, mRequest->GetResult(error)); + JS::Rooted result(cx); + mRequest->GetResult(&result, error); if (NS_WARN_IF(error.Failed())) { return error.ErrorCode(); } @@ -190,7 +191,8 @@ DataStoreDB::DatabaseOpened() AutoSafeJSContext cx; ErrorResult error; - JS::Rooted result(cx, mRequest->GetResult(error)); + JS::Rooted result(cx); + mRequest->GetResult(&result, error); if (NS_WARN_IF(error.Failed())) { return error.ErrorCode(); } diff --git a/dom/datastore/DataStoreService.cpp b/dom/datastore/DataStoreService.cpp index e0e680cd9f27..97d06f3c1253 100644 --- a/dom/datastore/DataStoreService.cpp +++ b/dom/datastore/DataStoreService.cpp @@ -587,7 +587,8 @@ public: AutoSafeJSContext cx; ErrorResult error; - JS::Rooted result(cx, mRequest->GetResult(error)); + JS::Rooted result(cx); + mRequest->GetResult(cx, &result, error); if (NS_WARN_IF(error.Failed())) { return error.ErrorCode(); } diff --git a/dom/events/DataTransfer.cpp b/dom/events/DataTransfer.cpp index 08299c6f62fb..32d2e1439232 100644 --- a/dom/events/DataTransfer.cpp +++ b/dom/events/DataTransfer.cpp @@ -640,27 +640,27 @@ DataTransfer::MozGetDataAt(const nsAString& aFormat, uint32_t aIndex, return NS_OK; } -JS::Value +void DataTransfer::MozGetDataAt(JSContext* aCx, const nsAString& aFormat, - uint32_t aIndex, mozilla::ErrorResult& aRv) + uint32_t aIndex, + JS::MutableHandle aRetval, + mozilla::ErrorResult& aRv) { nsCOMPtr data; aRv = MozGetDataAt(aFormat, aIndex, getter_AddRefs(data)); if (aRv.Failed()) { - return JS::UndefinedValue(); + return; } if (!data) { - return JS::NullValue(); + return; } JS::Rooted result(aCx); - if (!VariantToJsval(aCx, data, &result)) { + if (!VariantToJsval(aCx, data, aRetval)) { aRv = NS_ERROR_FAILURE; - return JS::UndefinedValue(); + return; } - - return result; } NS_IMETHODIMP diff --git a/dom/events/DataTransfer.h b/dom/events/DataTransfer.h index f76d1362911e..06ae32af7d95 100644 --- a/dom/events/DataTransfer.h +++ b/dom/events/DataTransfer.h @@ -164,8 +164,9 @@ public: void MozSetDataAt(JSContext* aCx, const nsAString& aFormat, JS::Handle aData, uint32_t aIndex, mozilla::ErrorResult& aRv); - JS::Value MozGetDataAt(JSContext* aCx, const nsAString& aFormat, - uint32_t aIndex, mozilla::ErrorResult& aRv); + void MozGetDataAt(JSContext* aCx, const nsAString& aFormat, + uint32_t aIndex, JS::MutableHandle aRetval, + mozilla::ErrorResult& aRv); bool MozUserCancelled() { return mUserCancelled; diff --git a/dom/events/JSEventHandler.cpp b/dom/events/JSEventHandler.cpp index 9eb318adc6b6..ae03f57198f3 100644 --- a/dom/events/JSEventHandler.cpp +++ b/dom/events/JSEventHandler.cpp @@ -18,6 +18,7 @@ #include "nsDOMJSUtils.h" #include "WorkerPrivate.h" #include "mozilla/ContentEvents.h" +#include "mozilla/CycleCollectedJSRuntime.h" #include "mozilla/HoldDropJSObjects.h" #include "mozilla/JSEventHandler.h" #include "mozilla/Likely.h" @@ -155,7 +156,7 @@ JSEventHandler::HandleEvent(nsIDOMEvent* aEvent) ThreadsafeAutoJSContext cx; error.Construct(cx); - error.Value() = scriptEvent->Error(cx); + scriptEvent->GetError(cx, &error.Value()); } else { msgOrEvent.SetAsEvent() = aEvent->InternalDOMEvent(); } @@ -210,8 +211,8 @@ JSEventHandler::HandleEvent(nsIDOMEvent* aEvent) MOZ_ASSERT(mTypedHandler.Type() == TypedEventHandler::eNormal); ErrorResult rv; nsRefPtr handler = mTypedHandler.NormalEventHandler(); - JS::Value retval = - handler->Call(mTarget, *(aEvent->InternalDOMEvent()), rv); + JS::Rooted retval(CycleCollectedJSRuntime::Get()->Runtime()); + handler->Call(mTarget, *(aEvent->InternalDOMEvent()), &retval, rv); if (rv.Failed()) { return rv.ErrorCode(); } diff --git a/dom/events/MessageEvent.cpp b/dom/events/MessageEvent.cpp index 1edc4636405f..66e583658170 100644 --- a/dom/events/MessageEvent.cpp +++ b/dom/events/MessageEvent.cpp @@ -66,18 +66,19 @@ NS_IMETHODIMP MessageEvent::GetData(JSContext* aCx, JS::MutableHandle aData) { ErrorResult rv; - aData.set(GetData(aCx, rv)); + GetData(aCx, aData, rv); return rv.ErrorCode(); } -JS::Value -MessageEvent::GetData(JSContext* aCx, ErrorResult& aRv) +void +MessageEvent::GetData(JSContext* aCx, JS::MutableHandle aData, + ErrorResult& aRv) { - JS::Rooted data(aCx, mData); - if (!JS_WrapValue(aCx, &data)) { + JS::ExposeValueToActiveJS(mData); + aData.set(mData); + if (!JS_WrapValue(aCx, aData)) { aRv.Throw(NS_ERROR_FAILURE); } - return data; } NS_IMETHODIMP diff --git a/dom/events/MessageEvent.h b/dom/events/MessageEvent.h index 04a4bcab1a65..fa403d622be6 100644 --- a/dom/events/MessageEvent.h +++ b/dom/events/MessageEvent.h @@ -46,7 +46,8 @@ public: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; - JS::Value GetData(JSContext* aCx, ErrorResult& aRv); + void GetData(JSContext* aCx, JS::MutableHandle aData, + ErrorResult& aRv); void GetSource(Nullable& aValue) const; diff --git a/dom/indexedDB/IDBCursor.cpp b/dom/indexedDB/IDBCursor.cpp index 18d386c0a510..79ba37abfe30 100644 --- a/dom/indexedDB/IDBCursor.cpp +++ b/dom/indexedDB/IDBCursor.cpp @@ -610,14 +610,16 @@ IDBCursor::GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const } } -JS::Value -IDBCursor::GetKey(JSContext* aCx, ErrorResult& aRv) +void +IDBCursor::GetKey(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(!mKey.IsUnset() || !mHaveValue); if (!mHaveValue) { - return JSVAL_VOID; + aResult.setUndefined(); + return; } if (!mHaveCachedKey) { @@ -627,21 +629,26 @@ IDBCursor::GetKey(JSContext* aCx, ErrorResult& aRv) } aRv = mKey.ToJSVal(aCx, mCachedKey); - ENSURE_SUCCESS(aRv, JSVAL_VOID); + if (NS_WARN_IF(aRv.Failed())) { + return; + } mHaveCachedKey = true; } - return mCachedKey; + JS::ExposeValueToActiveJS(mCachedKey); + aResult.set(mCachedKey); } -JS::Value -IDBCursor::GetPrimaryKey(JSContext* aCx, ErrorResult& aRv) +void +IDBCursor::GetPrimaryKey(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); if (!mHaveValue) { - return JSVAL_VOID; + aResult.setUndefined(); + return; } if (!mHaveCachedPrimaryKey) { @@ -655,22 +662,27 @@ IDBCursor::GetPrimaryKey(JSContext* aCx, ErrorResult& aRv) MOZ_ASSERT(!key.IsUnset()); aRv = key.ToJSVal(aCx, mCachedPrimaryKey); - ENSURE_SUCCESS(aRv, JSVAL_VOID); + if (NS_WARN_IF(aRv.Failed())) { + return; + } mHaveCachedPrimaryKey = true; } - return mCachedPrimaryKey; + JS::ExposeValueToActiveJS(mCachedPrimaryKey); + aResult.set(mCachedPrimaryKey); } -JS::Value -IDBCursor::GetValue(JSContext* aCx, ErrorResult& aRv) +void +IDBCursor::GetValue(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mType == OBJECTSTORE || mType == INDEXOBJECT); if (!mHaveValue) { - return JSVAL_VOID; + aResult.setUndefined(); + return; } if (!mHaveCachedValue) { @@ -682,7 +694,7 @@ IDBCursor::GetValue(JSContext* aCx, ErrorResult& aRv) JS::Rooted val(aCx); if (!IDBObjectStore::DeserializeValue(aCx, mCloneReadInfo, &val)) { aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR); - return JSVAL_VOID; + return; } mCloneReadInfo.mCloneBuffer.clear(); @@ -691,7 +703,8 @@ IDBCursor::GetValue(JSContext* aCx, ErrorResult& aRv) mHaveCachedValue = true; } - return mCachedValue; + JS::ExposeValueToActiveJS(mCachedValue); + aResult.set(mCachedValue); } void diff --git a/dom/indexedDB/IDBCursor.h b/dom/indexedDB/IDBCursor.h index 0f627c96f772..3e0b46431bd1 100644 --- a/dom/indexedDB/IDBCursor.h +++ b/dom/indexedDB/IDBCursor.h @@ -184,11 +184,13 @@ public: IDBCursorDirection GetDirection() const; - JS::Value - GetKey(JSContext* aCx, ErrorResult& aRv); + void + GetKey(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv); - JS::Value - GetPrimaryKey(JSContext* aCx, ErrorResult& aRv); + void + GetPrimaryKey(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv); already_AddRefed Update(JSContext* aCx, JS::Handle aValue, ErrorResult& aRv); @@ -202,8 +204,9 @@ public: already_AddRefed Delete(JSContext* aCx, ErrorResult& aRv); - JS::Value - GetValue(JSContext* aCx, ErrorResult& aRv); + void + GetValue(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv); protected: IDBCursor(); diff --git a/dom/indexedDB/IDBIndex.cpp b/dom/indexedDB/IDBIndex.cpp index 0e2892d9d112..a2a3e154a59d 100644 --- a/dom/indexedDB/IDBIndex.cpp +++ b/dom/indexedDB/IDBIndex.cpp @@ -826,24 +826,30 @@ IDBIndex::WrapObject(JSContext* aCx) return IDBIndexBinding::Wrap(aCx, this); } -JS::Value -IDBIndex::GetKeyPath(JSContext* aCx, ErrorResult& aRv) +void +IDBIndex::GetKeyPath(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); if (!mCachedKeyPath.isUndefined()) { - return mCachedKeyPath; + JS::ExposeValueToActiveJS(mCachedKeyPath); + aResult.set(mCachedKeyPath); + return; } aRv = GetKeyPath().ToJSVal(aCx, mCachedKeyPath); - ENSURE_SUCCESS(aRv, JSVAL_VOID); + if (NS_WARN_IF(aRv.Failed())) { + return; + } if (mCachedKeyPath.isGCThing()) { mozilla::HoldJSObjects(this); mRooted = true; } - return mCachedKeyPath; + JS::ExposeValueToActiveJS(mCachedKeyPath); + aResult.set(mCachedKeyPath); } already_AddRefed diff --git a/dom/indexedDB/IDBIndex.h b/dom/indexedDB/IDBIndex.h index 03ff9aac9106..806f4ec93e9a 100644 --- a/dom/indexedDB/IDBIndex.h +++ b/dom/indexedDB/IDBIndex.h @@ -176,8 +176,9 @@ public: return mObjectStore; } - JS::Value - GetKeyPath(JSContext* aCx, ErrorResult& aRv); + void + GetKeyPath(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv); bool MultiEntry() const diff --git a/dom/indexedDB/IDBKeyRange.cpp b/dom/indexedDB/IDBKeyRange.cpp index 920f9c495206..370b44d15ea3 100644 --- a/dom/indexedDB/IDBKeyRange.cpp +++ b/dom/indexedDB/IDBKeyRange.cpp @@ -164,8 +164,9 @@ IDBKeyRange::WrapObject(JSContext* aCx) return IDBKeyRangeBinding::Wrap(aCx, this); } -JS::Value -IDBKeyRange::GetLower(JSContext* aCx, ErrorResult& aRv) +void +IDBKeyRange::GetLower(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); @@ -177,17 +178,19 @@ IDBKeyRange::GetLower(JSContext* aCx, ErrorResult& aRv) aRv = Lower().ToJSVal(aCx, mCachedLowerVal); if (aRv.Failed()) { - return JS::UndefinedValue(); + return; } mHaveCachedLowerVal = true; } - return mCachedLowerVal; + JS::ExposeValueToActiveJS(mCachedLowerVal); + aResult.set(mCachedLowerVal); } -JS::Value -IDBKeyRange::GetUpper(JSContext* aCx, ErrorResult& aRv) +void +IDBKeyRange::GetUpper(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!"); @@ -199,13 +202,14 @@ IDBKeyRange::GetUpper(JSContext* aCx, ErrorResult& aRv) aRv = Upper().ToJSVal(aCx, mCachedUpperVal); if (aRv.Failed()) { - return JS::UndefinedValue(); + return; } mHaveCachedUpperVal = true; } - return mCachedUpperVal; + JS::ExposeValueToActiveJS(mCachedUpperVal); + aResult.set(mCachedUpperVal); } // static diff --git a/dom/indexedDB/IDBKeyRange.h b/dom/indexedDB/IDBKeyRange.h index 22a06024c728..618a364c53b3 100644 --- a/dom/indexedDB/IDBKeyRange.h +++ b/dom/indexedDB/IDBKeyRange.h @@ -156,11 +156,13 @@ public: return mGlobal; } - JS::Value - GetLower(JSContext* aCx, ErrorResult& aRv); + void + GetLower(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv); - JS::Value - GetUpper(JSContext* aCx, ErrorResult& aRv); + void + GetUpper(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv); bool LowerOpen() const diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index 8b508f196ed4..9b0df2d5a234 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -2622,24 +2622,30 @@ IDBObjectStore::WrapObject(JSContext* aCx) return IDBObjectStoreBinding::Wrap(aCx, this); } -JS::Value -IDBObjectStore::GetKeyPath(JSContext* aCx, ErrorResult& aRv) +void +IDBObjectStore::GetKeyPath(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); if (!mCachedKeyPath.isUndefined()) { - return mCachedKeyPath; + JS::ExposeValueToActiveJS(mCachedKeyPath); + aResult.set(mCachedKeyPath); + return; } aRv = GetKeyPath().ToJSVal(aCx, mCachedKeyPath); - ENSURE_SUCCESS(aRv, JSVAL_VOID); + if (NS_WARN_IF(aRv.Failed())) { + return; + } if (mCachedKeyPath.isGCThing()) { mozilla::HoldJSObjects(this); mRooted = true; } - return mCachedKeyPath; + JS::ExposeValueToActiveJS(mCachedKeyPath); + aResult.set(mCachedKeyPath); } already_AddRefed diff --git a/dom/indexedDB/IDBObjectStore.h b/dom/indexedDB/IDBObjectStore.h index 0a9f864cb4ac..d53d5eebbfd9 100644 --- a/dom/indexedDB/IDBObjectStore.h +++ b/dom/indexedDB/IDBObjectStore.h @@ -282,8 +282,9 @@ public: aName.Assign(mName); } - JS::Value - GetKeyPath(JSContext* aCx, ErrorResult& aRv); + void + GetKeyPath(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv); already_AddRefed GetIndexNames(ErrorResult& aRv); diff --git a/dom/indexedDB/IDBRequest.cpp b/dom/indexedDB/IDBRequest.cpp index dff6ce7218b0..d7771af267f8 100644 --- a/dom/indexedDB/IDBRequest.cpp +++ b/dom/indexedDB/IDBRequest.cpp @@ -326,8 +326,9 @@ IDBRequest::WrapObject(JSContext* aCx) return IDBRequestBinding::Wrap(aCx, this); } -JS::Value -IDBRequest::GetResult(mozilla::ErrorResult& aRv) const +void +IDBRequest::GetResult(JS::MutableHandle aResult, + ErrorResult& aRv) const { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -336,7 +337,8 @@ IDBRequest::GetResult(mozilla::ErrorResult& aRv) const aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR); } - return mResultVal; + JS::ExposeValueToActiveJS(mResultVal); + aResult.set(mResultVal); } mozilla::dom::DOMError* diff --git a/dom/indexedDB/IDBRequest.h b/dom/indexedDB/IDBRequest.h index 34504db644b3..605496e870f4 100644 --- a/dom/indexedDB/IDBRequest.h +++ b/dom/indexedDB/IDBRequest.h @@ -131,13 +131,14 @@ public: return GetOwner(); } - JS::Value - GetResult(ErrorResult& aRv) const; + void + GetResult(JS::MutableHandle aResult, ErrorResult& aRv) const; - JS::Value - GetResult(JSContext* aCx, ErrorResult& aRv) const + void + GetResult(JSContext* aCx, JS::MutableHandle aResult, + ErrorResult& aRv) const { - return GetResult(aRv); + GetResult(aResult, aRv); } IDBTransaction* diff --git a/dom/indexedDB/ipc/IndexedDBParent.cpp b/dom/indexedDB/ipc/IndexedDBParent.cpp index 2338d559a30c..20ff78ec0d62 100644 --- a/dom/indexedDB/ipc/IndexedDBParent.cpp +++ b/dom/indexedDB/ipc/IndexedDBParent.cpp @@ -408,7 +408,8 @@ IndexedDBDatabaseParent::HandleRequestEvent(nsIDOMEvent* aEvent, AutoSafeJSContext cx; ErrorResult error; - JS::Rooted result(cx, mOpenRequest->GetResult(cx, error)); + JS::Rooted result(cx); + mOpenRequest->GetResult(cx, &result, error); ENSURE_SUCCESS(error, error.ErrorCode()); MOZ_ASSERT(!result.isPrimitive()); diff --git a/dom/promise/PromiseCallback.cpp b/dom/promise/PromiseCallback.cpp index 62d1871ed69f..6fb36e57367c 100644 --- a/dom/promise/PromiseCallback.cpp +++ b/dom/promise/PromiseCallback.cpp @@ -219,8 +219,8 @@ WrapperPromiseCallback::Call(JSContext* aCx, // If invoking callback threw an exception, run resolver's reject with the // thrown exception as argument and the synchronous flag set. - JS::Rooted retValue(aCx, - mCallback->Call(value, rv, CallbackObject::eRethrowExceptions)); + JS::Rooted retValue(aCx); + mCallback->Call(value, &retValue, rv, CallbackObject::eRethrowExceptions); rv.WouldReportJSException(); diff --git a/dom/workers/XMLHttpRequest.cpp b/dom/workers/XMLHttpRequest.cpp index fdd45e0f7b1c..d8b54e42f011 100644 --- a/dom/workers/XMLHttpRequest.cpp +++ b/dom/workers/XMLHttpRequest.cpp @@ -2317,8 +2317,10 @@ XMLHttpRequest::SetResponseType(XMLHttpRequestResponseType aResponseType, mResponseType = ConvertStringToResponseType(acceptedResponseTypeString); } -jsval -XMLHttpRequest::GetResponse(JSContext* /* unused */, ErrorResult& aRv) +void +XMLHttpRequest::GetResponse(JSContext* /* unused */, + JS::MutableHandle aResponse, + ErrorResult& aRv) { if (NS_SUCCEEDED(mStateData.mResponseTextResult) && mStateData.mResponse.isUndefined()) { @@ -2331,14 +2333,15 @@ XMLHttpRequest::GetResponse(JSContext* /* unused */, ErrorResult& aRv) mStateData.mResponseText.Length()); if (!str) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); - return JSVAL_VOID; + return; } mStateData.mResponse = STRING_TO_JSVAL(str); } + JS::ExposeValueToActiveJS(mStateData.mResponse); aRv = mStateData.mResponseResult; - return mStateData.mResponse; + aResponse.set(mStateData.mResponse); } void diff --git a/dom/workers/XMLHttpRequest.h b/dom/workers/XMLHttpRequest.h index 963731cbac96..e5ccfce0b501 100644 --- a/dom/workers/XMLHttpRequest.h +++ b/dom/workers/XMLHttpRequest.h @@ -213,8 +213,9 @@ public: void SetResponseType(XMLHttpRequestResponseType aResponseType, ErrorResult& aRv); - jsval - GetResponse(JSContext* /* unused */, ErrorResult& aRv); + void + GetResponse(JSContext* /* unused */, JS::MutableHandle aResponse, + ErrorResult& aRv); void GetResponseText(nsAString& aResponseText, ErrorResult& aRv); @@ -231,11 +232,11 @@ public: return nullptr; } - JS::Value - GetInterface(JSContext* cx, JS::Handle aIID, ErrorResult& aRv) + void + GetInterface(JSContext* cx, JS::Handle aIID, + JS::MutableHandle aRetval, ErrorResult& aRv) { aRv.Throw(NS_ERROR_FAILURE); - return JSVAL_NULL; } XMLHttpRequestUpload* diff --git a/js/xpconnect/src/event_impl_gen.py b/js/xpconnect/src/event_impl_gen.py index dfea30c729c5..be8f2a8403f7 100755 --- a/js/xpconnect/src/event_impl_gen.py +++ b/js/xpconnect/src/event_impl_gen.py @@ -183,7 +183,7 @@ def print_class_declaration(eventname, iface, fd, conf): if a.realtype.nativeType('in').count("nsAString"): continue elif a.realtype.nativeType('in').count("nsIVariant"): - fd.write(" JS::Value Get%s(JSContext* aCx, ErrorResult& aRv);\n\n" % firstCapName); + fd.write(" void Get%s(JSContext* aCx, JS::MutableHandle aRetval, ErrorResult& aRv);\n\n" % firstCapName); elif a.realtype.nativeType('in').endswith('*'): fd.write(" already_AddRefed<%s> Get%s()\n" % (xpidl_to_native(cleanNativeType, conf), firstCapName)) fd.write(" {\n"); @@ -305,15 +305,15 @@ def writeAttributeGetter(fd, classname, a): fd.write(" return NS_OK;\n"); fd.write("}\n\n"); if a.realtype.nativeType('in').count("nsIVariant"): - fd.write("JS::Value\n") - fd.write("%s::Get%s(JSContext* aCx, ErrorResult& aRv)\n" % (classname, firstCap(a.name))) + fd.write("void\n") + fd.write("%s::Get%s(JSContext* aCx, JS::MutableHandle aRetval, ErrorResult& aRv)\n" % (classname, firstCap(a.name))) fd.write("{\n") - fd.write(" JS::Rooted retVal(aCx, JS::NullValue());\n"); fd.write(" nsresult rv = NS_ERROR_UNEXPECTED;\n") - fd.write(" if (m%s && !XPCVariant::VariantDataToJS(m%s, &rv, &retVal)) {\n" % (firstCap(a.name), firstCap(a.name))) + fd.write(" if (!m%s) {\n" % firstCap(a.name)) + fd.write(" aRetval.setNull();\n") + fd.write(" } else if (!XPCVariant::VariantDataToJS(m%s, &rv, aRetval)) {\n" % (firstCap(a.name))) fd.write(" aRv.Throw(NS_ERROR_FAILURE);\n") fd.write(" }\n") - fd.write(" return retVal;\n"); fd.write("}\n\n") def writeAttributeParams(fd, a):