mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 730161 - Implement IDBRequest.error. r=sicking
This commit is contained in:
parent
b219309fc2
commit
cdcec97b74
@ -8,6 +8,7 @@
|
||||
|
||||
#include "mozilla/Util.h"
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "nsDOMException.h"
|
||||
|
||||
using mozilla::ArrayLength;
|
||||
using mozilla::dom::DOMError;
|
||||
@ -22,6 +23,19 @@ struct NameMap
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIDOMDOMError>
|
||||
DOMError::CreateForNSResult(nsresult aRv)
|
||||
{
|
||||
const char* name;
|
||||
const char* message;
|
||||
aRv = NS_GetNameAndMessageForDOMNSResult(aRv, &name, &message);
|
||||
if (NS_FAILED(aRv) || !name) {
|
||||
return nsnull;
|
||||
}
|
||||
return CreateWithName(NS_ConvertASCIItoUTF16(name));
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIDOMDOMError>
|
||||
DOMError::CreateForDOMExceptionCode(PRUint16 aDOMExceptionCode)
|
||||
|
@ -23,6 +23,9 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMDOMERROR
|
||||
|
||||
static already_AddRefed<nsIDOMDOMError>
|
||||
CreateForNSResult(nsresult rv);
|
||||
|
||||
static already_AddRefed<nsIDOMDOMError>
|
||||
CreateForDOMExceptionCode(PRUint16 aDOMExceptionCode);
|
||||
|
||||
|
@ -56,12 +56,12 @@
|
||||
#include "AsyncConnectionHelper.h"
|
||||
#include "IDBEvents.h"
|
||||
#include "IDBTransaction.h"
|
||||
#include "DOMError.h"
|
||||
|
||||
USING_INDEXEDDB_NAMESPACE
|
||||
|
||||
IDBRequest::IDBRequest()
|
||||
: mResultVal(JSVAL_VOID),
|
||||
mErrorCode(0),
|
||||
mHaveResultOrErrorCode(false),
|
||||
mRooted(false)
|
||||
{
|
||||
@ -100,7 +100,7 @@ IDBRequest::Reset()
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
mResultVal = JSVAL_VOID;
|
||||
mHaveResultOrErrorCode = false;
|
||||
mErrorCode = 0;
|
||||
mError = nsnull;
|
||||
UnrootResultVal();
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ IDBRequest::NotifyHelperCompleted(HelperBase* aHelper)
|
||||
|
||||
// If the request failed then set the error code and return.
|
||||
if (NS_FAILED(rv)) {
|
||||
mErrorCode = NS_ERROR_GET_CODE(rv);
|
||||
mError = DOMError::CreateForNSResult(rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ IDBRequest::NotifyHelperCompleted(HelperBase* aHelper)
|
||||
if (NS_FAILED(cxStack->GetSafeJSContext(&cx))) {
|
||||
NS_WARNING("Failed to get safe JSContext!");
|
||||
rv = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
mErrorCode = NS_ERROR_GET_CODE(rv);
|
||||
mError = DOMError::CreateForNSResult(rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@ -167,16 +167,25 @@ IDBRequest::NotifyHelperCompleted(HelperBase* aHelper)
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mErrorCode = 0;
|
||||
mError = nsnull;
|
||||
}
|
||||
else {
|
||||
mErrorCode = NS_ERROR_GET_CODE(rv);
|
||||
mError = DOMError::CreateForNSResult(rv);
|
||||
mResultVal = JSVAL_VOID;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
IDBRequest::SetError(nsresult rv)
|
||||
{
|
||||
NS_ASSERTION(NS_FAILED(rv), "Er, what?");
|
||||
NS_ASSERTION(!mError, "Already have an error?");
|
||||
|
||||
mError = DOMError::CreateForNSResult(rv);
|
||||
}
|
||||
|
||||
void
|
||||
IDBRequest::RootResultValInternal()
|
||||
{
|
||||
@ -239,7 +248,7 @@ IDBRequest::GetResult(jsval* aResult)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBRequest::GetErrorCode(PRUint16* aErrorCode)
|
||||
IDBRequest::GetError(nsIDOMDOMError** aError)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
@ -248,7 +257,7 @@ IDBRequest::GetErrorCode(PRUint16* aErrorCode)
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
||||
}
|
||||
|
||||
*aErrorCode = mErrorCode;
|
||||
NS_IF_ADDREF(*aError = mError);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -82,13 +82,7 @@ public:
|
||||
|
||||
nsresult NotifyHelperCompleted(HelperBase* aHelper);
|
||||
|
||||
void SetError(nsresult rv)
|
||||
{
|
||||
NS_ASSERTION(NS_FAILED(rv), "Er, what?");
|
||||
NS_ASSERTION(mErrorCode == NS_OK, "Already have an error?");
|
||||
|
||||
mErrorCode = rv;
|
||||
}
|
||||
void SetError(nsresult rv);
|
||||
|
||||
protected:
|
||||
IDBRequest();
|
||||
@ -121,7 +115,7 @@ protected:
|
||||
|
||||
jsval mResultVal;
|
||||
|
||||
PRUint16 mErrorCode;
|
||||
nsCOMPtr<nsIDOMDOMError> mError;
|
||||
bool mHaveResultOrErrorCode;
|
||||
bool mRooted;
|
||||
};
|
||||
|
@ -2201,11 +2201,11 @@ OpenDatabaseHelper::DispatchErrorEvent()
|
||||
return;
|
||||
}
|
||||
|
||||
PRUint16 errorCode = 0;
|
||||
nsCOMPtr<nsIDOMDOMError> error;
|
||||
DebugOnly<nsresult> rv =
|
||||
mOpenDBRequest->GetErrorCode(&errorCode);
|
||||
mOpenDBRequest->GetError(getter_AddRefs(error));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "This shouldn't be failing at this point!");
|
||||
if (!errorCode) {
|
||||
if (!error) {
|
||||
mOpenDBRequest->SetError(mResultCode);
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIDOMDOMError.idl"
|
||||
|
||||
interface nsIDOMEventListener;
|
||||
interface nsIIDBTransaction;
|
||||
@ -48,19 +49,19 @@ interface nsIIDBTransaction;
|
||||
* http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBRequest for more
|
||||
* information.
|
||||
*/
|
||||
[scriptable, builtinclass, uuid(fe30ca60-bb90-4d68-af2f-4735f9228a54)]
|
||||
[scriptable, builtinclass, uuid(4b9d901b-14a4-430c-b41b-5ecb238f4184)]
|
||||
interface nsIIDBRequest : nsISupports
|
||||
{
|
||||
// "pending" or "done"
|
||||
readonly attribute DOMString readyState;
|
||||
readonly attribute jsval result;
|
||||
|
||||
readonly attribute nsIDOMDOMError error;
|
||||
|
||||
readonly attribute nsISupports source;
|
||||
|
||||
readonly attribute nsIIDBTransaction transaction;
|
||||
|
||||
readonly attribute jsval result;
|
||||
|
||||
readonly attribute unsigned short errorCode;
|
||||
// "pending" or "done"
|
||||
readonly attribute DOMString readyState;
|
||||
|
||||
attribute nsIDOMEventListener onsuccess;
|
||||
attribute nsIDOMEventListener onerror;
|
||||
|
Loading…
Reference in New Issue
Block a user