зеркало из https://github.com/mozilla/pjs.git
Bug 622042 - 'IndexedDB: Rework events and requests'. r=sicking, a=sicking.
This commit is contained in:
Родитель
0036d1583b
Коммит
54ff7ba2cf
|
@ -91,7 +91,7 @@ DOM_MSG_DEF(NS_ERROR_DOM_DATA_CLONE_ERR, "The object could not be cloned.")
|
|||
DOM_MSG_DEF(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR, "The operation failed for reasons unrelated to the database itself and not covered by any other error code.")
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR, "This error occurred because an operation was not allowed on an object. A retry of the same operation would fail unless the cause of the error is corrected.")
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR, "The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened.")
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR, "A mutation operation in the transaction failed due to a because a constraint was not satisfied. For example, an object such as an object store or index already exists and a new one was being attempted to be created.")
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR, "A mutation operation in the transaction failed because a constraint was not satisfied. For example, an object such as an object store or index already exists and a new one was being attempted to be created.")
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_INDEXEDDB_DATA_ERR, "Data provided to an operation does not meet requirements.")
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR, "A mutation operation was attempted on a database that did not allow mutations.")
|
||||
DOM_MSG_DEF(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR, "A request was placed against a transaction which is currently not active, or which is finished.")
|
||||
|
|
|
@ -1458,12 +1458,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
|||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBDatabase, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBErrorEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBSuccessEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBTransactionEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBObjectStore, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(IDBTransaction, nsDOMGenericSH,
|
||||
|
@ -4098,25 +4092,6 @@ nsDOMClassInfo::Init()
|
|||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(IDBErrorEvent, nsIIDBErrorEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBErrorEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(IDBSuccessEvent, nsIIDBSuccessEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBSuccessEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(IDBTransactionEvent, nsIIDBTransactionEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBTransactionEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBSuccessEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(IDBObjectStore, nsIIDBObjectStore)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBObjectStore)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
@ -4141,7 +4116,6 @@ nsDOMClassInfo::Init()
|
|||
|
||||
DOM_CLASSINFO_MAP_BEGIN(IDBVersionChangeEvent, nsIIDBVersionChangeEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBVersionChangeEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIIDBEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
|
|
|
@ -496,9 +496,6 @@ DOMCI_CLASS(CloseEvent)
|
|||
DOMCI_CLASS(IDBFactory)
|
||||
DOMCI_CLASS(IDBRequest)
|
||||
DOMCI_CLASS(IDBDatabase)
|
||||
DOMCI_CLASS(IDBErrorEvent)
|
||||
DOMCI_CLASS(IDBSuccessEvent)
|
||||
DOMCI_CLASS(IDBTransactionEvent)
|
||||
DOMCI_CLASS(IDBObjectStore)
|
||||
DOMCI_CLASS(IDBTransaction)
|
||||
DOMCI_CLASS(IDBCursor)
|
||||
|
|
|
@ -92,20 +92,20 @@
|
|||
|
||||
/* IndexedDB error codes http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html */
|
||||
|
||||
#define NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,0)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,1)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,2)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,3)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_DATA_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,4)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,5)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,1)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,2)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,3)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,4)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_DATA_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,5)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,6)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,6)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_ABORT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,7)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,11)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_RECOVERABLE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,21)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_TRANSIENT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,31)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_TIMEOUT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,32)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_DEADLOCK_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,33)
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,7)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_ABORT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,8)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,9)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_RECOVERABLE_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,10)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_TRANSIENT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,11)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_TIMEOUT_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,12)
|
||||
#define NS_ERROR_DOM_INDEXEDDB_DEADLOCK_ERR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_DOM_INDEXEDDB,13)
|
||||
|
||||
/* DOM error codes defined by us */
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include "mozilla/storage.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsProxyRelease.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
|
@ -76,6 +77,48 @@ private:
|
|||
IDBTransaction* mTransaction;
|
||||
};
|
||||
|
||||
// This inline is just so that we always clear aBuffers appropriately even if
|
||||
// something fails.
|
||||
inline
|
||||
nsresult
|
||||
ConvertCloneBuffersToArrayInternal(
|
||||
JSContext* aCx,
|
||||
nsTArray<JSAutoStructuredCloneBuffer>& aBuffers,
|
||||
jsval* aResult)
|
||||
{
|
||||
JSObject* array = JS_NewArrayObject(aCx, 0, nsnull);
|
||||
if (!array) {
|
||||
NS_WARNING("Failed to make array!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
if (!aBuffers.IsEmpty()) {
|
||||
if (!JS_SetArrayLength(aCx, array, jsuint(aBuffers.Length()))) {
|
||||
NS_WARNING("Failed to set array length!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
jsint count = jsint(aBuffers.Length());
|
||||
for (jsint index = 0; index < count; index++) {
|
||||
JSAutoStructuredCloneBuffer& buffer = aBuffers[index];
|
||||
|
||||
jsval val;
|
||||
if (!buffer.read(&val, aCx)) {
|
||||
NS_WARNING("Failed to decode!");
|
||||
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
||||
}
|
||||
|
||||
if (!JS_SetElement(aCx, array, index, &val)) {
|
||||
NS_WARNING("Failed to set array element!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*aResult = OBJECT_TO_JSVAL(array);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
AsyncConnectionHelper::AsyncConnectionHelper(IDBDatabase* aDatabase,
|
||||
|
@ -141,10 +184,6 @@ NS_IMETHODIMP
|
|||
AsyncConnectionHelper::Run()
|
||||
{
|
||||
if (NS_IsMainThread()) {
|
||||
if (mRequest) {
|
||||
mRequest->SetDone();
|
||||
}
|
||||
|
||||
if (mTransaction &&
|
||||
mTransaction->IsAborted() &&
|
||||
NS_SUCCEEDED(mResultCode)) {
|
||||
|
@ -156,11 +195,15 @@ AsyncConnectionHelper::Run()
|
|||
IDBTransaction* oldTransaction = gCurrentTransaction;
|
||||
gCurrentTransaction = mTransaction;
|
||||
|
||||
if (mRequest) {
|
||||
mRequest->SetDone(this);
|
||||
}
|
||||
|
||||
// Call OnError if the database had an error or if the OnSuccess handler
|
||||
// has an error.
|
||||
if (NS_FAILED(mResultCode) ||
|
||||
NS_FAILED((mResultCode = OnSuccess(mRequest)))) {
|
||||
OnError(mRequest, mResultCode);
|
||||
NS_FAILED((mResultCode = OnSuccess()))) {
|
||||
OnError();
|
||||
}
|
||||
|
||||
NS_ASSERTION(gCurrentTransaction == mTransaction, "Should be unchanged!");
|
||||
|
@ -330,57 +373,28 @@ AsyncConnectionHelper::GetCurrentTransaction()
|
|||
nsresult
|
||||
AsyncConnectionHelper::Init()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
AsyncConnectionHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
AsyncConnectionHelper::OnSuccess()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsCOMPtr<nsIWritableVariant> variant =
|
||||
do_CreateInstance(NS_VARIANT_CONTRACTID);
|
||||
if (!variant) {
|
||||
NS_ERROR("Couldn't create variant!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
nsresult rv = GetSuccessResult(variant);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Check to make sure we have a listener here before actually firing.
|
||||
nsCOMPtr<nsPIDOMEventTarget> target(do_QueryInterface(aTarget));
|
||||
if (target) {
|
||||
nsIEventListenerManager* manager = target->GetListenerManager(PR_FALSE);
|
||||
if (!manager ||
|
||||
!manager->HasListenersFor(NS_LITERAL_STRING(SUCCESS_EVT_STR))) {
|
||||
// No listeners here, skip creating and dispatching the event.
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(variant->SetWritable(PR_FALSE))) {
|
||||
NS_ERROR("Failed to make variant readonly!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> event =
|
||||
IDBSuccessEvent::Create(mRequest, variant, mTransaction);
|
||||
nsRefPtr<nsDOMEvent> event =
|
||||
CreateGenericEvent(NS_LITERAL_STRING(SUCCESS_EVT_STR));
|
||||
if (!event) {
|
||||
NS_ERROR("Failed to create event!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
PRBool dummy;
|
||||
rv = aTarget->DispatchEvent(event, &dummy);
|
||||
nsresult rv = mRequest->DispatchEvent(event, &dummy);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(event);
|
||||
NS_ASSERTION(privateEvent, "This should always QI properly!");
|
||||
|
||||
nsEvent* internalEvent = privateEvent->GetInternalNSEvent();
|
||||
nsEvent* internalEvent = event->GetInternalNSEvent();
|
||||
NS_ASSERTION(internalEvent, "This should never be null!");
|
||||
|
||||
NS_ASSERTION(!mTransaction ||
|
||||
|
@ -399,20 +413,20 @@ AsyncConnectionHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
|||
}
|
||||
|
||||
void
|
||||
AsyncConnectionHelper::OnError(nsIDOMEventTarget* aTarget,
|
||||
nsresult aErrorCode)
|
||||
AsyncConnectionHelper::OnError()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
// Make an error event and fire it at the target.
|
||||
nsCOMPtr<nsIDOMEvent> event(IDBErrorEvent::Create(mRequest, aErrorCode));
|
||||
nsRefPtr<nsDOMEvent> event =
|
||||
CreateGenericEvent(NS_LITERAL_STRING(ERROR_EVT_STR), PR_TRUE);
|
||||
if (!event) {
|
||||
NS_ERROR("Failed to create event!");
|
||||
return;
|
||||
}
|
||||
|
||||
PRBool doDefault;
|
||||
nsresult rv = aTarget->DispatchEvent(event, &doDefault);
|
||||
nsresult rv = mRequest->DispatchEvent(event, &doDefault);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ASSERTION(!mTransaction ||
|
||||
mTransaction->IsOpen() ||
|
||||
|
@ -432,13 +446,12 @@ AsyncConnectionHelper::OnError(nsIDOMEventTarget* aTarget,
|
|||
}
|
||||
|
||||
nsresult
|
||||
AsyncConnectionHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
AsyncConnectionHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsresult rv = aResult->SetAsVoid();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*aVal = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -452,6 +465,69 @@ AsyncConnectionHelper::ReleaseMainThreadObjects()
|
|||
mRequest = nsnull;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
AsyncConnectionHelper::WrapNative(JSContext* aCx,
|
||||
nsISupports* aNative,
|
||||
jsval* aResult)
|
||||
{
|
||||
JSObject* global = JS_GetGlobalForObject(aCx, JS_GetScopeChain(aCx));
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
nsresult rv =
|
||||
nsContentUtils::WrapNative(aCx, global,
|
||||
static_cast<nsPIDOMEventTarget*>(aNative),
|
||||
aResult);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
AsyncConnectionHelper::ConvertCloneBufferToJSVal(
|
||||
JSContext* aCx,
|
||||
JSAutoStructuredCloneBuffer& aBuffer,
|
||||
jsval* aResult)
|
||||
{
|
||||
JSAutoRequest ar(aCx);
|
||||
|
||||
if (aBuffer.data()) {
|
||||
JSBool ok = aBuffer.read(aResult, aCx);
|
||||
|
||||
aBuffer.clear(aCx);
|
||||
|
||||
if (!ok) {
|
||||
NS_ERROR("Failed to decode!");
|
||||
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*aResult = JSVAL_VOID;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
AsyncConnectionHelper::ConvertCloneBuffersToArray(
|
||||
JSContext* aCx,
|
||||
nsTArray<JSAutoStructuredCloneBuffer>& aBuffers,
|
||||
jsval* aResult)
|
||||
{
|
||||
JSAutoRequest ar(aCx);
|
||||
|
||||
nsresult rv = ConvertCloneBuffersToArrayInternal(aCx, aBuffers, aResult);
|
||||
|
||||
for (PRUint32 index = 0; index < aBuffers.Length(); index++) {
|
||||
aBuffers[index].clear(aCx);
|
||||
}
|
||||
aBuffers.Clear();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
TransactionPoolEventTarget::AddRef()
|
||||
{
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
#include "mozIStorageProgressHandler.h"
|
||||
#include "nsIRunnable.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsIVariant.h"
|
||||
|
||||
#include "mozilla/TimeStamp.h"
|
||||
|
||||
|
@ -70,6 +69,8 @@ class IDBTransaction;
|
|||
class AsyncConnectionHelper : public nsIRunnable,
|
||||
public mozIStorageProgressHandler
|
||||
{
|
||||
friend class IDBRequest;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
@ -93,6 +94,11 @@ public:
|
|||
return mRequest ? mRequest->Source() : nsnull;
|
||||
}
|
||||
|
||||
nsresult GetResultCode()
|
||||
{
|
||||
return mResultCode;
|
||||
}
|
||||
|
||||
protected:
|
||||
AsyncConnectionHelper(IDBDatabase* aDatabase,
|
||||
IDBRequest* aRequest);
|
||||
|
@ -113,42 +119,36 @@ protected:
|
|||
/**
|
||||
* This is called on the main thread after Dispatch is called but before the
|
||||
* runnable is actually dispatched to the database thread. Allows the subclass
|
||||
* to initialize itself. The default implementation does nothing and returns
|
||||
* NS_OK.
|
||||
* to initialize itself.
|
||||
*/
|
||||
virtual nsresult Init();
|
||||
|
||||
/**
|
||||
* This callback is run on the database thread. It should return a valid error
|
||||
* code from nsIIDBDatabaseError or one of the two special values above.
|
||||
* This callback is run on the database thread.
|
||||
*/
|
||||
virtual nsresult DoDatabaseWork(mozIStorageConnection* aConnection) = 0;
|
||||
|
||||
/**
|
||||
* This callback is run on the main thread if the DoDatabaseWork returned OK.
|
||||
* The default implementation constructs an IDBSuccessEvent with its result
|
||||
* property set to the value returned by GetSuccessResult. The event is then
|
||||
* fired at the target. Returning anything other than OK from the OnSuccess
|
||||
* This callback is run on the main thread if DoDatabaseWork returned NS_OK.
|
||||
* The default implementation fires a "success" DOM event with its target set
|
||||
* to the request. Returning anything other than NS_OK from the OnSuccess
|
||||
* callback will trigger the OnError callback.
|
||||
*/
|
||||
virtual nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
virtual nsresult OnSuccess();
|
||||
|
||||
/**
|
||||
* This callback is run on the main thread if DoDatabaseWork returned an error
|
||||
* code. The default implementation constructs an IDBErrorEvent for the error
|
||||
* code and fires it at the target.
|
||||
* This callback is run on the main thread if DoDatabaseWork or OnSuccess
|
||||
* returned an error code. The default implementation fires an "error" DOM
|
||||
* event with its target set to the request.
|
||||
*/
|
||||
virtual void OnError(nsIDOMEventTarget* aTarget,
|
||||
nsresult aErrorCode);
|
||||
virtual void OnError();
|
||||
|
||||
/**
|
||||
* This function is called from the default implementation of OnSuccess. A
|
||||
* valid nsIWritableVariant is passed into the function which can be modified
|
||||
* by the subclass. The default implementation returns an nsIVariant that is
|
||||
* set to nsIDataType::VTYPE_EMPTY. Returning anything other than OK from the
|
||||
* GetSuccessResult function will trigger the OnError callback.
|
||||
* This function is called by the request on the main thread when script
|
||||
* accesses the result property of the request.
|
||||
*/
|
||||
virtual nsresult GetSuccessResult(nsIWritableVariant* aVariant);
|
||||
virtual nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
/**
|
||||
* Gives the subclass a chance to release any objects that must be released
|
||||
|
@ -157,6 +157,30 @@ protected:
|
|||
*/
|
||||
virtual void ReleaseMainThreadObjects();
|
||||
|
||||
/**
|
||||
* Helper to wrap a native into a jsval. Uses the global object of the given
|
||||
* context.
|
||||
*/
|
||||
static nsresult WrapNative(JSContext* aCx,
|
||||
nsISupports* aNative,
|
||||
jsval* aResult);
|
||||
|
||||
/**
|
||||
* Helper to decode a clone buffer to a jsval.
|
||||
*/
|
||||
static nsresult ConvertCloneBufferToJSVal(
|
||||
JSContext* aCx,
|
||||
JSAutoStructuredCloneBuffer& aBuffer,
|
||||
jsval* aResult);
|
||||
|
||||
/**
|
||||
* Helper to make a JS array object out of an array of clone buffers.
|
||||
*/
|
||||
static nsresult ConvertCloneBuffersToArray(
|
||||
JSContext* aCx,
|
||||
nsTArray<JSAutoStructuredCloneBuffer>& aBuffers,
|
||||
jsval* aResult);
|
||||
|
||||
protected:
|
||||
nsRefPtr<IDBDatabase> mDatabase;
|
||||
nsRefPtr<IDBTransaction> mTransaction;
|
||||
|
|
|
@ -85,7 +85,9 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult GetSuccessResult(nsIWritableVariant* aResult);
|
||||
nsresult OnSuccess();
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -273,7 +275,8 @@ IDBCursor::IDBCursor()
|
|||
mCachedValue(JSVAL_VOID),
|
||||
mHaveCachedValue(false),
|
||||
mValueRooted(false),
|
||||
mContinueCalled(false)
|
||||
mContinueCalled(false),
|
||||
mHaveValue(true)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
}
|
||||
|
@ -308,6 +311,7 @@ NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(IDBCursor)
|
|||
tmp->mCachedValue = JSVAL_VOID;
|
||||
tmp->mHaveCachedValue = false;
|
||||
tmp->mValueRooted = false;
|
||||
tmp->mHaveValue = false;
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_END
|
||||
|
||||
|
@ -366,19 +370,21 @@ IDBCursor::GetKey(nsIVariant** aKey)
|
|||
do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
NS_ASSERTION(!mKey.IsUnset(), "Bad key!");
|
||||
NS_ASSERTION(!mKey.IsUnset() || !mHaveValue, "Bad key!");
|
||||
|
||||
if (mKey.IsString()) {
|
||||
if (!mHaveValue) {
|
||||
rv = variant->SetAsVoid();
|
||||
}
|
||||
else if (mKey.IsString()) {
|
||||
rv = variant->SetAsAString(mKey.StringValue());
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
}
|
||||
else if (mKey.IsInt()) {
|
||||
rv = variant->SetAsInt64(mKey.IntValue());
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
}
|
||||
else {
|
||||
NS_NOTREACHED("Huh?!");
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
rv = variant->SetWritable(PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
@ -400,6 +406,11 @@ IDBCursor::GetValue(JSContext* aCx,
|
|||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (!mHaveValue) {
|
||||
*aValue = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (mType == INDEXKEY) {
|
||||
|
@ -442,7 +453,7 @@ IDBCursor::Continue(const jsval &aKey,
|
|||
return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
|
||||
}
|
||||
|
||||
if (mContinueCalled) {
|
||||
if (!mHaveValue || mContinueCalled) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
||||
}
|
||||
|
||||
|
@ -525,7 +536,7 @@ IDBCursor::Update(const jsval& aValue,
|
|||
return NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR;
|
||||
}
|
||||
|
||||
if (mType == INDEXKEY) {
|
||||
if (!mHaveValue || mType == INDEXKEY) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
||||
}
|
||||
|
||||
|
@ -588,7 +599,7 @@ IDBCursor::Delete(JSContext* aCx,
|
|||
return NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR;
|
||||
}
|
||||
|
||||
if (mType == INDEXKEY) {
|
||||
if (!mHaveValue || mType == INDEXKEY) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
||||
}
|
||||
|
||||
|
@ -644,14 +655,38 @@ ContinueHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
ContinueHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
ContinueHelper::OnSuccess()
|
||||
{
|
||||
nsresult rv;
|
||||
// Remove cached stuff from last time.
|
||||
mCursor->mCachedKey = nsnull;
|
||||
mCursor->mCachedObjectKey = nsnull;
|
||||
mCursor->mCachedValue = JSVAL_VOID;
|
||||
mCursor->mHaveCachedValue = false;
|
||||
mCursor->mContinueCalled = false;
|
||||
|
||||
if (mKey.IsUnset()) {
|
||||
rv = aResult->SetAsEmpty();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mCursor->mHaveValue = false;
|
||||
}
|
||||
else {
|
||||
// Set new values.
|
||||
mCursor->mKey = mKey;
|
||||
mCursor->mObjectKey = mObjectKey;
|
||||
mCursor->mCloneBuffer.clear();
|
||||
mCursor->mCloneBuffer.swap(mCloneBuffer);
|
||||
mCursor->mContinueToKey = Key::UNSETKEY;
|
||||
}
|
||||
|
||||
// We want an event, with a result, etc. Call the base class method.
|
||||
return AsyncConnectionHelper::OnSuccess();
|
||||
}
|
||||
|
||||
nsresult
|
||||
ContinueHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
if (mKey.IsUnset()) {
|
||||
NS_ASSERTION(!mCursor->mHaveValue, "Should have unset this!");
|
||||
*aVal = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -661,24 +696,8 @@ ContinueHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
|||
}
|
||||
#endif
|
||||
|
||||
// Remove cached stuff from last time.
|
||||
mCursor->mCachedKey = nsnull;
|
||||
mCursor->mCachedObjectKey = nsnull;
|
||||
mCursor->mCachedValue = JSVAL_VOID;
|
||||
mCursor->mHaveCachedValue = false;
|
||||
mCursor->mContinueCalled = false;
|
||||
|
||||
// And set new values.
|
||||
mCursor->mKey = mKey;
|
||||
mCursor->mObjectKey = mObjectKey;
|
||||
mCursor->mCloneBuffer.clear();
|
||||
mCursor->mCloneBuffer.swap(mCloneBuffer);
|
||||
mCursor->mContinueToKey = Key::UNSETKEY;
|
||||
|
||||
rv = aResult->SetAsISupports(mCursor);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
NS_ASSERTION(mCursor->mHaveValue, "This should still be set to true!");
|
||||
return WrapNative(aCx, mCursor, aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -149,6 +149,7 @@ protected:
|
|||
nsCOMPtr<nsIScriptContext> mScriptContext;
|
||||
nsCOMPtr<nsPIDOMWindow> mOwner;
|
||||
|
||||
// Not cycle-collected, these are guaranteed to be primitives!
|
||||
nsCOMPtr<nsIVariant> mCachedKey;
|
||||
nsCOMPtr<nsIVariant> mCachedObjectKey;
|
||||
|
||||
|
@ -157,6 +158,7 @@ protected:
|
|||
nsCString mContinueQuery;
|
||||
nsCString mContinueToQuery;
|
||||
|
||||
// This one is cycle-collected!
|
||||
jsval mCachedValue;
|
||||
|
||||
Key mRangeKey;
|
||||
|
@ -169,6 +171,7 @@ protected:
|
|||
bool mHaveCachedValue;
|
||||
bool mValueRooted;
|
||||
bool mContinueCalled;
|
||||
bool mHaveValue;
|
||||
};
|
||||
|
||||
END_INDEXEDDB_NAMESPACE
|
||||
|
|
|
@ -82,7 +82,9 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult GetSuccessResult(nsIWritableVariant* aResult);
|
||||
nsresult OnSuccess();
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
private:
|
||||
// In-params
|
||||
|
@ -98,8 +100,16 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
void OnError(nsIDOMEventTarget* aTarget, nsresult aErrorCode);
|
||||
|
||||
nsresult OnSuccess()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void OnError()
|
||||
{
|
||||
NS_ASSERTION(mTransaction->IsAborted(), "How else can this fail?!");
|
||||
}
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -120,8 +130,16 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
void OnError(nsIDOMEventTarget* aTarget, nsresult aErrorCode);
|
||||
|
||||
nsresult OnSuccess()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void OnError()
|
||||
{
|
||||
NS_ASSERTION(mTransaction->IsAborted(), "How else can this fail?!");
|
||||
}
|
||||
|
||||
private:
|
||||
// In-params.
|
||||
|
@ -901,15 +919,20 @@ IDBDatabase::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|||
NS_ENSURE_TRUE(aVisitor.mDOMEvent, NS_ERROR_UNEXPECTED);
|
||||
|
||||
if (aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault) {
|
||||
nsCOMPtr<nsIDOMEvent> duplicateEvent =
|
||||
IDBErrorEvent::MaybeDuplicate(aVisitor.mDOMEvent);
|
||||
nsString type;
|
||||
nsresult rv = aVisitor.mDOMEvent->GetType(type);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (type.EqualsLiteral(ERROR_EVT_STR)) {
|
||||
nsRefPtr<nsDOMEvent> duplicateEvent = CreateGenericEvent(type);
|
||||
NS_ENSURE_STATE(duplicateEvent);
|
||||
|
||||
if (duplicateEvent) {
|
||||
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mOwner));
|
||||
NS_ASSERTION(target, "How can this happen?!");
|
||||
|
||||
PRBool dummy;
|
||||
target->DispatchEvent(duplicateEvent, &dummy);
|
||||
rv = target->DispatchEvent(duplicateEvent, &dummy);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -939,7 +962,7 @@ SetVersionHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
SetVersionHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
SetVersionHelper::OnSuccess()
|
||||
{
|
||||
DatabaseInfo* info;
|
||||
if (!DatabaseInfo::Get(mDatabase->Id(), &info)) {
|
||||
|
@ -948,8 +971,15 @@ SetVersionHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
|||
}
|
||||
info->version = mVersion;
|
||||
|
||||
aResult->SetAsISupports(static_cast<nsPIDOMEventTarget*>(mTransaction));
|
||||
return NS_OK;
|
||||
// We want an event, with a result, etc. Call the base class method.
|
||||
return AsyncConnectionHelper::OnSuccess();
|
||||
}
|
||||
|
||||
nsresult
|
||||
SetVersionHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
return WrapNative(aCx, static_cast<nsPIDOMEventTarget*>(mTransaction), aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -985,20 +1015,6 @@ CreateObjectStoreHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
CreateObjectStoreHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
{
|
||||
NS_ASSERTION(!aTarget, "Huh?!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
CreateObjectStoreHelper::OnError(nsIDOMEventTarget* aTarget,
|
||||
nsresult aErrorCode)
|
||||
{
|
||||
NS_ASSERTION(!aTarget, "Huh?!");
|
||||
}
|
||||
|
||||
nsresult
|
||||
DeleteObjectStoreHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
||||
{
|
||||
|
@ -1019,18 +1035,3 @@ DeleteObjectStoreHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DeleteObjectStoreHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
{
|
||||
NS_ASSERTION(!aTarget, "Huh?!");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
DeleteObjectStoreHelper::OnError(nsIDOMEventTarget* aTarget,
|
||||
nsresult aErrorCode)
|
||||
{
|
||||
NS_NOTREACHED("Removing an object store should never fail here!");
|
||||
}
|
||||
|
|
|
@ -56,16 +56,6 @@ USING_INDEXEDDB_NAMESPACE
|
|||
|
||||
namespace {
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
already_AddRefed<nsIDOMEvent>
|
||||
ForgetEvent(nsRefPtr<T>& aRefPtr)
|
||||
{
|
||||
T* result;
|
||||
aRefPtr.forget(&result);
|
||||
return static_cast<nsIDOMEvent*>(static_cast<nsDOMEvent*>(result));
|
||||
}
|
||||
|
||||
class EventFiringRunnable : public nsRunnable
|
||||
{
|
||||
public:
|
||||
|
@ -86,17 +76,47 @@ private:
|
|||
|
||||
} // anonymous namespace
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIDOMEvent>
|
||||
IDBEvent::CreateGenericEvent(const nsAString& aType)
|
||||
already_AddRefed<nsDOMEvent>
|
||||
mozilla::dom::indexedDB::CreateGenericEvent(const nsAString& aType,
|
||||
PRBool aBubblesAndCancelable)
|
||||
{
|
||||
nsRefPtr<nsDOMEvent> event(new nsDOMEvent(nsnull, nsnull));
|
||||
nsresult rv = event->InitEvent(aType, aBubblesAndCancelable,
|
||||
aBubblesAndCancelable);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
rv = event->SetTrusted(PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
return event.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIRunnable>
|
||||
mozilla::dom::indexedDB::CreateGenericEventRunnable(const nsAString& aType,
|
||||
nsIDOMEventTarget* aTarget)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEvent> event(CreateGenericEvent(aType));
|
||||
NS_ENSURE_TRUE(event, nsnull);
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable(new EventFiringRunnable(aTarget, event));
|
||||
return runnable.forget();
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIDOMEvent>
|
||||
IDBVersionChangeEvent::CreateInternal(const nsAString& aType,
|
||||
const nsAString& aVersion)
|
||||
{
|
||||
nsRefPtr<IDBVersionChangeEvent> event(new IDBVersionChangeEvent());
|
||||
|
||||
nsresult rv = event->InitEvent(aType, PR_FALSE, PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
rv = event->SetTrusted(PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
event->mVersion = aVersion;
|
||||
|
||||
nsDOMEvent* result;
|
||||
event.forget(&result);
|
||||
return result;
|
||||
|
@ -104,520 +124,24 @@ IDBEvent::CreateGenericEvent(const nsAString& aType)
|
|||
|
||||
// static
|
||||
already_AddRefed<nsIRunnable>
|
||||
IDBEvent::CreateGenericEventRunnable(const nsAString& aType,
|
||||
nsIDOMEventTarget* aTarget)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEvent> event(IDBEvent::CreateGenericEvent(aType));
|
||||
NS_ENSURE_TRUE(event, nsnull);
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable(new EventFiringRunnable(aTarget, event));
|
||||
return runnable.forget();
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(IDBEvent, nsDOMEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(IDBEvent, nsDOMEvent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBEvent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBEvent, nsDOMEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSource)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBEvent, nsDOMEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSource)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIIDBEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBEvent::GetSource(nsISupports** aSource)
|
||||
{
|
||||
nsCOMPtr<nsISupports> source(mSource);
|
||||
source.forget(aSource);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIDOMEvent>
|
||||
IDBErrorEvent::Create(IDBRequest* aRequest,
|
||||
nsresult aResult)
|
||||
{
|
||||
NS_ASSERTION(NS_FAILED(aResult), "Not a failure code!");
|
||||
NS_ASSERTION(NS_ERROR_GET_MODULE(aResult) == NS_ERROR_MODULE_DOM_INDEXEDDB,
|
||||
"Not an IndexedDB error code!");
|
||||
|
||||
const char* name = nsnull;
|
||||
const char* message = nsnull;
|
||||
if (NS_FAILED(NS_GetNameAndMessageForDOMNSResult(aResult, &name, &message))) {
|
||||
NS_ERROR("Need a name and message for this code!");
|
||||
}
|
||||
|
||||
nsRefPtr<IDBErrorEvent> event(new IDBErrorEvent());
|
||||
|
||||
event->mSource = aRequest->Source();
|
||||
event->mCode = NS_ERROR_GET_CODE(aResult);
|
||||
event->mMessage.AssignASCII(message);
|
||||
|
||||
nsresult rv = event->InitEvent(NS_LITERAL_STRING(ERROR_EVT_STR), PR_TRUE,
|
||||
PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
rv = event->SetTrusted(PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
return ForgetEvent(event);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIRunnable>
|
||||
IDBErrorEvent::CreateRunnable(IDBRequest* aRequest,
|
||||
nsresult aResult)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEvent> event(Create(aRequest, aResult));
|
||||
NS_ENSURE_TRUE(event, nsnull);
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable(new EventFiringRunnable(aRequest, event));
|
||||
return runnable.forget();
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIDOMEvent>
|
||||
IDBErrorEvent::MaybeDuplicate(nsIDOMEvent* aOther)
|
||||
{
|
||||
NS_ASSERTION(aOther, "Null pointer!");
|
||||
|
||||
nsCOMPtr<nsIDOMNSEvent> domNSEvent(do_QueryInterface(aOther));
|
||||
nsCOMPtr<nsIIDBErrorEvent> errorEvent(do_QueryInterface(aOther));
|
||||
|
||||
if (!domNSEvent || !errorEvent) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
PRBool isTrusted;
|
||||
nsresult rv = domNSEvent->GetIsTrusted(&isTrusted);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
if (!isTrusted) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsString type;
|
||||
rv = errorEvent->GetType(type);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
PRBool canBubble;
|
||||
rv = errorEvent->GetBubbles(&canBubble);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
nsCOMPtr<nsISupports> source;
|
||||
rv = errorEvent->GetSource(getter_AddRefs(source));
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
PRUint16 code;
|
||||
rv = errorEvent->GetCode(&code);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
nsString message;
|
||||
rv = errorEvent->GetMessage(message);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
nsRefPtr<IDBErrorEvent> event(new IDBErrorEvent());
|
||||
|
||||
event->mSource = source;
|
||||
event->mCode = code;
|
||||
event->mMessage = message;
|
||||
|
||||
rv = event->InitEvent(type, canBubble, PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
rv = event->SetTrusted(PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
return ForgetEvent(event);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(IDBErrorEvent, IDBEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(IDBErrorEvent, IDBEvent)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(IDBErrorEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIIDBErrorEvent)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBErrorEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(IDBEvent)
|
||||
|
||||
DOMCI_DATA(IDBErrorEvent, IDBErrorEvent)
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBErrorEvent::GetCode(PRUint16* aCode)
|
||||
{
|
||||
*aCode = mCode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBErrorEvent::GetMessage(nsAString& aMessage)
|
||||
{
|
||||
aMessage.Assign(mMessage);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIDOMEvent>
|
||||
IDBSuccessEvent::Create(IDBRequest* aRequest,
|
||||
nsIVariant* aResult,
|
||||
nsIIDBTransaction* aTransaction)
|
||||
{
|
||||
nsRefPtr<IDBSuccessEvent> event(new IDBSuccessEvent());
|
||||
|
||||
event->mSource = aRequest->Source();
|
||||
event->mResult = aResult;
|
||||
event->mTransaction = aTransaction;
|
||||
|
||||
nsresult rv = event->InitEvent(NS_LITERAL_STRING(SUCCESS_EVT_STR), PR_FALSE,
|
||||
PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
rv = event->SetTrusted(PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
return ForgetEvent(event);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIRunnable>
|
||||
IDBSuccessEvent::CreateRunnable(IDBRequest* aRequest,
|
||||
nsIVariant* aResult,
|
||||
nsIIDBTransaction* aTransaction)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEvent> event(Create(aRequest, aResult, aTransaction));
|
||||
NS_ENSURE_TRUE(event, nsnull);
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable(new EventFiringRunnable(aRequest, event));
|
||||
return runnable.forget();
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(IDBSuccessEvent, IDBEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(IDBSuccessEvent, IDBEvent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBSuccessEvent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBSuccessEvent, IDBEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mResult)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTransaction)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBSuccessEvent, IDBEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mResult)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTransaction)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBSuccessEvent)
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIDBTransactionEvent, mTransaction)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(IDBTransactionEvent,
|
||||
mTransaction)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIIDBSuccessEvent)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBSuccessEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(IDBEvent)
|
||||
|
||||
DOMCI_DATA(IDBSuccessEvent, IDBSuccessEvent)
|
||||
DOMCI_DATA(IDBTransactionEvent, IDBSuccessEvent)
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBSuccessEvent::GetResult(JSContext* aCx,
|
||||
jsval* aResult)
|
||||
{
|
||||
if (!mResult) {
|
||||
*aResult = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIXPConnect* xpc = nsContentUtils::XPConnect();
|
||||
NS_ENSURE_TRUE(xpc, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
JSAutoRequest ar(aCx);
|
||||
JSObject* scope = JS_GetGlobalObject(aCx);
|
||||
NS_ENSURE_TRUE(scope, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
nsresult rv = xpc->VariantToJS(aCx, scope, mResult, aResult);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBSuccessEvent::GetTransaction(nsIIDBTransaction** aTransaction)
|
||||
{
|
||||
nsCOMPtr<nsIIDBTransaction> transaction(mTransaction);
|
||||
transaction.forget(aTransaction);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
GetSuccessEvent::~GetSuccessEvent()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (mValueRooted) {
|
||||
NS_DROP_JS_OBJECTS(this, GetSuccessEvent);
|
||||
}
|
||||
|
||||
IDBObjectStore::ClearStructuredCloneBuffer(mCloneBuffer);
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetSuccessEvent::Init(IDBRequest* aRequest,
|
||||
IDBTransaction* aTransaction)
|
||||
{
|
||||
mSource = aRequest->Source();
|
||||
mTransaction = aTransaction;
|
||||
|
||||
nsresult rv = InitEvent(NS_LITERAL_STRING(SUCCESS_EVT_STR), PR_FALSE,
|
||||
PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = SetTrusted(PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GetSuccessEvent::GetResult(JSContext* aCx,
|
||||
jsval* aResult)
|
||||
{
|
||||
if (!mValueRooted) {
|
||||
RootCachedValue();
|
||||
|
||||
if (mCloneBuffer.data()) {
|
||||
JSAutoRequest ar(aCx);
|
||||
|
||||
if (!mCloneBuffer.read(&mCachedValue, aCx)) {
|
||||
mCachedValue = JSVAL_VOID;
|
||||
NS_ERROR("Failed to decode!");
|
||||
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
||||
}
|
||||
|
||||
mCloneBuffer.clear();
|
||||
}
|
||||
else {
|
||||
NS_ASSERTION(JSVAL_IS_VOID(mCachedValue), "Should be undefined!");
|
||||
}
|
||||
}
|
||||
|
||||
*aResult = mCachedValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
GetSuccessEvent::RootCachedValue()
|
||||
{
|
||||
mValueRooted = PR_TRUE;
|
||||
NS_HOLD_JS_OBJECTS(this, GetSuccessEvent);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(GetSuccessEvent, IDBSuccessEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(GetSuccessEvent, IDBSuccessEvent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(GetSuccessEvent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(GetSuccessEvent,
|
||||
IDBSuccessEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(GetSuccessEvent)
|
||||
if (tmp->mValueRooted) {
|
||||
NS_DROP_JS_OBJECTS(tmp, GetSuccessEvent);
|
||||
tmp->mCachedValue = JSVAL_VOID;
|
||||
tmp->mValueRooted = PR_FALSE;
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(GetSuccessEvent,
|
||||
IDBSuccessEvent)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mResult)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTransaction)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(GetSuccessEvent)
|
||||
if (JSVAL_IS_GCTHING(tmp->mCachedValue)) {
|
||||
void *gcThing = JSVAL_TO_GCTHING(tmp->mCachedValue);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing)
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(GetSuccessEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(IDBSuccessEvent)
|
||||
|
||||
GetAllSuccessEvent::~GetAllSuccessEvent()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
for (PRUint32 index = 0; index < mCloneBuffers.Length(); index++) {
|
||||
IDBObjectStore::ClearStructuredCloneBuffer(mCloneBuffers[index]);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GetAllSuccessEvent::GetResult(JSContext* aCx,
|
||||
jsval* aResult)
|
||||
{
|
||||
if (!mValueRooted) {
|
||||
// Swap into a stack array so that we don't hang on to the buffers if
|
||||
// something fails.
|
||||
nsTArray<JSAutoStructuredCloneBuffer> cloneBuffers;
|
||||
if (!mCloneBuffers.SwapElements(cloneBuffers)) {
|
||||
NS_ERROR("Failed to swap elements!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
JSAutoRequest ar(aCx);
|
||||
|
||||
JSObject* array = JS_NewArrayObject(aCx, 0, NULL);
|
||||
if (!array) {
|
||||
NS_ERROR("Failed to make array!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
RootCachedValue();
|
||||
|
||||
mCachedValue = OBJECT_TO_JSVAL(array);
|
||||
|
||||
if (!cloneBuffers.IsEmpty()) {
|
||||
if (!JS_SetArrayLength(aCx, array, jsuint(cloneBuffers.Length()))) {
|
||||
mCachedValue = JSVAL_VOID;
|
||||
NS_ERROR("Failed to set array length!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
jsint count = jsint(cloneBuffers.Length());
|
||||
|
||||
for (jsint index = 0; index < count; index++) {
|
||||
JSAutoStructuredCloneBuffer& buffer = cloneBuffers[index];
|
||||
|
||||
jsval val;
|
||||
if (!buffer.read(&val, aCx)) {
|
||||
mCachedValue = JSVAL_VOID;
|
||||
NS_ERROR("Failed to decode!");
|
||||
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
||||
}
|
||||
|
||||
buffer.clear(aCx);
|
||||
|
||||
if (!JS_SetElement(aCx, array, index, &val)) {
|
||||
mCachedValue = JSVAL_VOID;
|
||||
NS_ERROR("Failed to set array element!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*aResult = mCachedValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
GetAllKeySuccessEvent::GetResult(JSContext* aCx,
|
||||
jsval* aResult)
|
||||
{
|
||||
if (!mValueRooted) {
|
||||
// Swap into a stack array so that we don't hang on to the strings if
|
||||
// something fails.
|
||||
nsTArray<Key> keys;
|
||||
if (!mKeys.SwapElements(keys)) {
|
||||
NS_ERROR("Failed to swap elements!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
JSAutoRequest ar(aCx);
|
||||
|
||||
JSObject* array = JS_NewArrayObject(aCx, 0, NULL);
|
||||
if (!array) {
|
||||
NS_ERROR("Failed to make array!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
RootCachedValue();
|
||||
|
||||
mCachedValue = OBJECT_TO_JSVAL(array);
|
||||
|
||||
if (!keys.IsEmpty()) {
|
||||
if (!JS_SetArrayLength(aCx, array, jsuint(keys.Length()))) {
|
||||
mCachedValue = JSVAL_VOID;
|
||||
NS_ERROR("Failed to set array length!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
js::AutoValueRooter value(aCx);
|
||||
|
||||
jsint count = jsint(keys.Length());
|
||||
|
||||
for (jsint index = 0; index < count; index++) {
|
||||
const Key& key = keys[index];
|
||||
NS_ASSERTION(!key.IsUnset(), "Bad key!");
|
||||
|
||||
nsresult rv = IDBObjectStore::GetJSValFromKey(key, aCx,
|
||||
value.jsval_addr());
|
||||
if (NS_FAILED(rv)) {
|
||||
mCachedValue = JSVAL_VOID;
|
||||
NS_WARNING("Failed to get jsval for key!");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!JS_SetElement(aCx, array, index, value.jsval_addr())) {
|
||||
mCachedValue = JSVAL_VOID;
|
||||
NS_WARNING("Failed to set array element!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*aResult = mCachedValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIDOMEvent>
|
||||
IDBVersionChangeEvent::CreateInternal(nsISupports* aSource,
|
||||
const nsAString& aType,
|
||||
const nsAString& aVersion)
|
||||
{
|
||||
nsRefPtr<IDBVersionChangeEvent> event(new IDBVersionChangeEvent());
|
||||
|
||||
event->mSource = aSource;
|
||||
event->mVersion = aVersion;
|
||||
|
||||
nsresult rv = event->InitEvent(aType, PR_FALSE, PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
rv = event->SetTrusted(PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
return ForgetEvent(event);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<nsIRunnable>
|
||||
IDBVersionChangeEvent::CreateRunnableInternal(nsISupports* aSource,
|
||||
const nsAString& aType,
|
||||
IDBVersionChangeEvent::CreateRunnableInternal(const nsAString& aType,
|
||||
const nsAString& aVersion,
|
||||
nsIDOMEventTarget* aTarget)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEvent> event = CreateInternal(aSource, aType, aVersion);
|
||||
nsCOMPtr<nsIDOMEvent> event = CreateInternal(aType, aVersion);
|
||||
NS_ENSURE_TRUE(event, nsnull);
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable(new EventFiringRunnable(aTarget, event));
|
||||
return runnable.forget();
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(IDBVersionChangeEvent, IDBEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(IDBVersionChangeEvent, IDBEvent)
|
||||
NS_IMPL_ADDREF_INHERITED(IDBVersionChangeEvent, nsDOMEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(IDBVersionChangeEvent, nsDOMEvent)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(IDBVersionChangeEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIIDBVersionChangeEvent)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBVersionChangeEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(IDBEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
||||
|
||||
DOMCI_DATA(IDBVersionChangeEvent, IDBVersionChangeEvent)
|
||||
|
||||
|
|
|
@ -42,14 +42,8 @@
|
|||
|
||||
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
||||
|
||||
#include "nsIIDBEvent.h"
|
||||
#include "nsIIDBErrorEvent.h"
|
||||
#include "nsIIDBSuccessEvent.h"
|
||||
#include "nsIIDBTransactionEvent.h"
|
||||
#include "nsIIDBTransaction.h"
|
||||
#include "nsIIDBVersionChangeEvent.h"
|
||||
#include "nsIRunnable.h"
|
||||
#include "nsIVariant.h"
|
||||
|
||||
#include "nsDOMEvent.h"
|
||||
|
||||
|
@ -65,215 +59,60 @@
|
|||
|
||||
BEGIN_INDEXEDDB_NAMESPACE
|
||||
|
||||
class IDBRequest;
|
||||
class IDBTransaction;
|
||||
already_AddRefed<nsDOMEvent>
|
||||
CreateGenericEvent(const nsAString& aType,
|
||||
PRBool aBubblesAndCancelable = PR_FALSE);
|
||||
|
||||
class IDBEvent : public nsDOMEvent,
|
||||
public nsIIDBEvent
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIIDBEVENT
|
||||
NS_FORWARD_TO_NSDOMEVENT
|
||||
already_AddRefed<nsIRunnable>
|
||||
CreateGenericEventRunnable(const nsAString& aType,
|
||||
nsIDOMEventTarget* aTarget);
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBEvent, nsDOMEvent)
|
||||
|
||||
static already_AddRefed<nsIDOMEvent>
|
||||
CreateGenericEvent(const nsAString& aType);
|
||||
|
||||
static already_AddRefed<nsIRunnable>
|
||||
CreateGenericEventRunnable(const nsAString& aType,
|
||||
nsIDOMEventTarget* aTarget);
|
||||
|
||||
protected:
|
||||
IDBEvent() : nsDOMEvent(nsnull, nsnull) { }
|
||||
virtual ~IDBEvent() { }
|
||||
|
||||
nsCOMPtr<nsISupports> mSource;
|
||||
};
|
||||
|
||||
class IDBErrorEvent : public IDBEvent,
|
||||
public nsIIDBErrorEvent
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIIDBERROREVENT
|
||||
NS_FORWARD_NSIDOMEVENT(IDBEvent::)
|
||||
NS_FORWARD_NSIIDBEVENT(IDBEvent::)
|
||||
|
||||
static already_AddRefed<nsIDOMEvent>
|
||||
Create(IDBRequest* aRequest,
|
||||
nsresult aResult);
|
||||
|
||||
static already_AddRefed<nsIRunnable>
|
||||
CreateRunnable(IDBRequest* aRequest,
|
||||
nsresult aResult);
|
||||
|
||||
static already_AddRefed<nsIDOMEvent>
|
||||
MaybeDuplicate(nsIDOMEvent* aOther);
|
||||
|
||||
protected:
|
||||
IDBErrorEvent() { }
|
||||
|
||||
PRUint16 mCode;
|
||||
nsString mMessage;
|
||||
};
|
||||
|
||||
class IDBSuccessEvent : public IDBEvent,
|
||||
public nsIIDBTransactionEvent
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIIDBSUCCESSEVENT
|
||||
NS_DECL_NSIIDBTRANSACTIONEVENT
|
||||
NS_FORWARD_NSIDOMEVENT(IDBEvent::)
|
||||
NS_FORWARD_NSIIDBEVENT(IDBEvent::)
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBSuccessEvent, IDBEvent)
|
||||
|
||||
static already_AddRefed<nsIDOMEvent>
|
||||
Create(IDBRequest* aRequest,
|
||||
nsIVariant* aResult,
|
||||
nsIIDBTransaction* aTransaction);
|
||||
|
||||
static already_AddRefed<nsIRunnable>
|
||||
CreateRunnable(IDBRequest* aRequest,
|
||||
nsIVariant* aResult,
|
||||
nsIIDBTransaction* aTransaction);
|
||||
|
||||
protected:
|
||||
IDBSuccessEvent() { }
|
||||
|
||||
nsCOMPtr<nsIVariant> mResult;
|
||||
nsCOMPtr<nsIIDBTransaction> mTransaction;
|
||||
};
|
||||
|
||||
class GetSuccessEvent : public IDBSuccessEvent
|
||||
{
|
||||
public:
|
||||
GetSuccessEvent(JSAutoStructuredCloneBuffer& aCloneBuffer)
|
||||
: mCachedValue(JSVAL_VOID),
|
||||
mValueRooted(PR_FALSE)
|
||||
{
|
||||
mCloneBuffer.swap(aCloneBuffer);
|
||||
}
|
||||
|
||||
GetSuccessEvent()
|
||||
: mCachedValue(JSVAL_VOID),
|
||||
mValueRooted(PR_FALSE)
|
||||
{ }
|
||||
|
||||
~GetSuccessEvent();
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(GetSuccessEvent,
|
||||
IDBSuccessEvent)
|
||||
|
||||
NS_IMETHOD GetResult(JSContext* aCx,
|
||||
jsval* aResult);
|
||||
|
||||
nsresult Init(IDBRequest* aRequest,
|
||||
IDBTransaction* aTransaction);
|
||||
|
||||
private:
|
||||
JSAutoStructuredCloneBuffer mCloneBuffer;
|
||||
|
||||
protected:
|
||||
void RootCachedValue();
|
||||
|
||||
jsval mCachedValue;
|
||||
JSRuntime* mJSRuntime;
|
||||
PRBool mValueRooted;
|
||||
};
|
||||
|
||||
class GetAllSuccessEvent : public GetSuccessEvent
|
||||
{
|
||||
public:
|
||||
GetAllSuccessEvent(nsTArray<JSAutoStructuredCloneBuffer>& aCloneBuffers)
|
||||
{
|
||||
if (!mCloneBuffers.SwapElements(aCloneBuffers)) {
|
||||
NS_ERROR("Failed to swap elements!");
|
||||
}
|
||||
}
|
||||
|
||||
~GetAllSuccessEvent();
|
||||
|
||||
NS_IMETHOD GetResult(JSContext* aCx,
|
||||
jsval* aResult);
|
||||
|
||||
private:
|
||||
nsTArray<JSAutoStructuredCloneBuffer> mCloneBuffers;
|
||||
};
|
||||
|
||||
class GetAllKeySuccessEvent : public GetSuccessEvent
|
||||
{
|
||||
public:
|
||||
GetAllKeySuccessEvent(nsTArray<Key>& aKeys)
|
||||
{
|
||||
if (!mKeys.SwapElements(aKeys)) {
|
||||
NS_ERROR("Failed to swap elements!");
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHOD GetResult(JSContext* aCx,
|
||||
jsval* aResult);
|
||||
|
||||
private:
|
||||
nsTArray<Key> mKeys;
|
||||
};
|
||||
|
||||
class IDBVersionChangeEvent : public IDBEvent,
|
||||
class IDBVersionChangeEvent : public nsDOMEvent,
|
||||
public nsIIDBVersionChangeEvent
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_FORWARD_TO_NSDOMEVENT
|
||||
NS_DECL_NSIIDBVERSIONCHANGEEVENT
|
||||
NS_FORWARD_NSIDOMEVENT(IDBEvent::)
|
||||
NS_FORWARD_NSIIDBEVENT(IDBEvent::)
|
||||
|
||||
inline static already_AddRefed<nsIDOMEvent>
|
||||
Create(const nsAString& aVersion)
|
||||
{
|
||||
NS_NAMED_LITERAL_STRING(type, VERSIONCHANGE_EVT_STR);
|
||||
return CreateInternal(nsnull, type, aVersion);
|
||||
return CreateInternal(NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR), aVersion);
|
||||
}
|
||||
|
||||
inline static already_AddRefed<nsIDOMEvent>
|
||||
CreateBlocked(nsISupports* aSource,
|
||||
const nsAString& aVersion)
|
||||
CreateBlocked(const nsAString& aVersion)
|
||||
{
|
||||
NS_NAMED_LITERAL_STRING(type, BLOCKED_EVT_STR);
|
||||
return CreateInternal(aSource, type, aVersion);
|
||||
return CreateInternal(NS_LITERAL_STRING(BLOCKED_EVT_STR), aVersion);
|
||||
}
|
||||
|
||||
inline static already_AddRefed<nsIRunnable>
|
||||
CreateRunnable(const nsAString& aVersion,
|
||||
nsIDOMEventTarget* aTarget)
|
||||
{
|
||||
NS_NAMED_LITERAL_STRING(type, VERSIONCHANGE_EVT_STR);
|
||||
return CreateRunnableInternal(nsnull, type, aVersion, aTarget);
|
||||
return CreateRunnableInternal(NS_LITERAL_STRING(VERSIONCHANGE_EVT_STR),
|
||||
aVersion, aTarget);
|
||||
}
|
||||
|
||||
static already_AddRefed<nsIRunnable>
|
||||
CreateBlockedRunnable(nsISupports* aSource,
|
||||
const nsAString& aVersion,
|
||||
CreateBlockedRunnable(const nsAString& aVersion,
|
||||
nsIDOMEventTarget* aTarget)
|
||||
{
|
||||
NS_NAMED_LITERAL_STRING(type, BLOCKED_EVT_STR);
|
||||
return CreateRunnableInternal(aSource, type, aVersion, aTarget);
|
||||
return CreateRunnableInternal(NS_LITERAL_STRING(BLOCKED_EVT_STR), aVersion,
|
||||
aTarget);
|
||||
}
|
||||
|
||||
protected:
|
||||
IDBVersionChangeEvent() { }
|
||||
IDBVersionChangeEvent() : nsDOMEvent(nsnull, nsnull) { }
|
||||
virtual ~IDBVersionChangeEvent() { }
|
||||
|
||||
static already_AddRefed<nsIDOMEvent>
|
||||
CreateInternal(nsISupports* aSource,
|
||||
const nsAString& aType,
|
||||
CreateInternal(const nsAString& aType,
|
||||
const nsAString& aVersion);
|
||||
|
||||
static already_AddRefed<nsIRunnable>
|
||||
CreateRunnableInternal(nsISupports* aSource,
|
||||
const nsAString& aType,
|
||||
CreateRunnableInternal(const nsAString& aType,
|
||||
const nsAString& aVersion,
|
||||
nsIDOMEventTarget* aTarget);
|
||||
|
||||
|
|
|
@ -121,7 +121,6 @@ struct ObjectStoreInfoMap
|
|||
ObjectStoreInfo* info;
|
||||
};
|
||||
|
||||
|
||||
class OpenDatabaseHelper : public AsyncConnectionHelper
|
||||
{
|
||||
public:
|
||||
|
@ -134,7 +133,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult GetSuccessResult(nsIWritableVariant* aResult);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
private:
|
||||
// In-params.
|
||||
|
@ -955,7 +955,8 @@ OpenDatabaseHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
OpenDatabaseHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
OpenDatabaseHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
DatabaseInfo* dbInfo;
|
||||
if (DatabaseInfo::Get(mDatabaseId, &dbInfo)) {
|
||||
|
@ -1042,6 +1043,5 @@ OpenDatabaseHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
|||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
aResult->SetAsISupports(static_cast<nsPIDOMEventTarget*>(db));
|
||||
return NS_OK;
|
||||
return WrapNative(aCx, static_cast<nsPIDOMEventTarget*>(db), aVal);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult GetSuccessResult(nsIWritableVariant* aResult);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -96,7 +97,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -120,7 +122,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
protected:
|
||||
const PRUint32 mLimit;
|
||||
|
@ -139,7 +142,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -171,7 +175,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult GetSuccessResult(nsIWritableVariant* aResult);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -213,7 +218,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult GetSuccessResult(nsIWritableVariant* aResult);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -712,21 +718,11 @@ GetKeyHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
GetKeyHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
GetKeyHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
if (mKey.IsUnset()) {
|
||||
aResult->SetAsEmpty();
|
||||
}
|
||||
else if (mKey.IsString()) {
|
||||
aResult->SetAsAString(mKey.StringValue());
|
||||
}
|
||||
else if (mKey.IsInt()) {
|
||||
aResult->SetAsInt64(mKey.IntValue());
|
||||
}
|
||||
else {
|
||||
NS_NOTREACHED("Unknown key type!");
|
||||
}
|
||||
return NS_OK;
|
||||
NS_ASSERTION(!mKey.IsUnset(), "Badness!");
|
||||
return IDBObjectStore::GetJSValFromKey(mKey, aCx, aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -774,15 +770,10 @@ GetHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
GetHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
GetHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
nsRefPtr<GetSuccessEvent> event(new GetSuccessEvent(mCloneBuffer));
|
||||
nsresult rv = event->Init(mRequest, mTransaction);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
PRBool dummy;
|
||||
aTarget->DispatchEvent(static_cast<nsDOMEvent*>(event), &dummy);
|
||||
return NS_OK;
|
||||
return ConvertCloneBufferToJSVal(aCx, mCloneBuffer, aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -896,17 +887,51 @@ GetAllKeysHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
GetAllKeysHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
GetAllKeysHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
nsRefPtr<GetAllKeySuccessEvent> event(new GetAllKeySuccessEvent(mKeys));
|
||||
NS_ASSERTION(mKeys.Length() <= mLimit, "Too many results!");
|
||||
|
||||
NS_ASSERTION(mKeys.IsEmpty(), "Should have swapped!");
|
||||
nsTArray<Key> keys;
|
||||
if (!mKeys.SwapElements(keys)) {
|
||||
NS_ERROR("Failed to swap elements!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
nsresult rv = event->Init(mRequest, mTransaction);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
JSAutoRequest ar(aCx);
|
||||
|
||||
PRBool dummy;
|
||||
aTarget->DispatchEvent(static_cast<nsDOMEvent*>(event), &dummy);
|
||||
JSObject* array = JS_NewArrayObject(aCx, 0, NULL);
|
||||
if (!array) {
|
||||
NS_WARNING("Failed to make array!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
if (!keys.IsEmpty()) {
|
||||
if (!JS_SetArrayLength(aCx, array, jsuint(keys.Length()))) {
|
||||
NS_WARNING("Failed to set array length!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
jsint count = jsint(keys.Length());
|
||||
for (jsint index = 0; index < count; index++) {
|
||||
const Key& key = keys[index];
|
||||
NS_ASSERTION(!key.IsUnset(), "Bad key!");
|
||||
|
||||
jsval value;
|
||||
nsresult rv = IDBObjectStore::GetJSValFromKey(key, aCx, &value);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to get jsval for key!");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!JS_SetElement(aCx, array, index, &value)) {
|
||||
NS_WARNING("Failed to set array element!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*aVal = OBJECT_TO_JSVAL(array);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1011,19 +1036,11 @@ GetAllHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
GetAllHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
GetAllHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
NS_ASSERTION(mCloneBuffers.Length() <= mLimit, "Too many results!");
|
||||
|
||||
nsRefPtr<GetAllSuccessEvent> event = new GetAllSuccessEvent(mCloneBuffers);
|
||||
NS_ASSERTION(mCloneBuffers.IsEmpty(), "Should have swapped!");
|
||||
|
||||
nsresult rv = event->Init(mRequest, mTransaction);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
PRBool dummy;
|
||||
aTarget->DispatchEvent(static_cast<nsDOMEvent*>(event), &dummy);
|
||||
return NS_OK;
|
||||
return ConvertCloneBuffersToArray(aCx, mCloneBuffers, aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -1248,10 +1265,11 @@ OpenKeyCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
OpenKeyCursorHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
OpenKeyCursorHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
if (mKey.IsUnset()) {
|
||||
aResult->SetAsEmpty();
|
||||
*aVal = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1260,8 +1278,7 @@ OpenKeyCursorHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
|||
mContinueQuery, mContinueToQuery, mKey, mObjectKey);
|
||||
NS_ENSURE_TRUE(cursor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
aResult->SetAsISupports(cursor);
|
||||
return NS_OK;
|
||||
return WrapNative(aCx, cursor, aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -1431,15 +1448,6 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
mCloneBuffer);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
/*
|
||||
SELECT index_data.value, object_data.key_value, object_data.data
|
||||
FROM object_data INNER JOIN index_data
|
||||
ON index_data.object_data_id = object_data.id
|
||||
WHERE index_data.index_id = 2 AND index_data.value < 73
|
||||
AND ( ( index_data.value = 65 AND object_data.key_value > "237-23-7736" )
|
||||
OR ( index_data.value > 65 ) )
|
||||
ORDER BY index_data.value ASC, object_data.key_value ASC
|
||||
*/
|
||||
// Now we need to make the query to get the next match.
|
||||
nsCAutoString queryStart = NS_LITERAL_CSTRING("SELECT ") + value +
|
||||
NS_LITERAL_CSTRING(", ") + keyValue +
|
||||
|
@ -1529,10 +1537,11 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
OpenCursorHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
OpenCursorHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
if (mKey.IsUnset()) {
|
||||
aResult->SetAsEmpty();
|
||||
*aVal = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1542,6 +1551,5 @@ OpenCursorHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
|||
mCloneBuffer);
|
||||
NS_ENSURE_TRUE(cursor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
aResult->SetAsISupports(cursor);
|
||||
return NS_OK;
|
||||
return WrapNative(aCx, cursor, aVal);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,8 @@ public:
|
|||
}
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult GetSuccessResult(nsIWritableVariant* aResult);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -117,7 +118,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -147,8 +149,9 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
nsresult GetSuccessResult(nsIWritableVariant* aResult);
|
||||
nsresult OnSuccess();
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
};
|
||||
|
||||
class ClearHelper : public AsyncConnectionHelper
|
||||
|
@ -190,7 +193,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult GetSuccessResult(nsIWritableVariant* aResult);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -225,8 +229,16 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
void OnError(nsIDOMEventTarget* aTarget, nsresult aErrorCode);
|
||||
|
||||
nsresult OnSuccess()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void OnError()
|
||||
{
|
||||
NS_ASSERTION(mTransaction->IsAborted(), "How else can this fail?!");
|
||||
}
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -255,8 +267,16 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
void OnError(nsIDOMEventTarget* aTarget, nsresult aErrorCode);
|
||||
|
||||
nsresult OnSuccess()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void OnError()
|
||||
{
|
||||
NS_ASSERTION(mTransaction->IsAborted(), "How else can this fail?!");
|
||||
}
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -287,7 +307,8 @@ public:
|
|||
{ }
|
||||
|
||||
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
||||
nsresult OnSuccess(nsIDOMEventTarget* aTarget);
|
||||
nsresult GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal);
|
||||
|
||||
void ReleaseMainThreadObjects()
|
||||
{
|
||||
|
@ -1688,20 +1709,11 @@ AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
AddHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
AddHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
NS_ASSERTION(!mKey.IsUnset(), "Badness!");
|
||||
|
||||
if (mKey.IsString()) {
|
||||
aResult->SetAsAString(mKey.StringValue());
|
||||
}
|
||||
else if (mKey.IsInt()) {
|
||||
aResult->SetAsInt64(mKey.IntValue());
|
||||
}
|
||||
else {
|
||||
NS_NOTREACHED("Unknown key type!");
|
||||
}
|
||||
return NS_OK;
|
||||
return IDBObjectStore::GetJSValFromKey(mKey, aCx, aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -1801,20 +1813,10 @@ GetHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
GetHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
GetHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
if (!mCloneBuffer.data()) {
|
||||
// Default is to have an undefined result.
|
||||
return AsyncConnectionHelper::OnSuccess(aTarget);
|
||||
}
|
||||
|
||||
nsRefPtr<GetSuccessEvent> event(new GetSuccessEvent(mCloneBuffer));
|
||||
nsresult rv = event->Init(mRequest, mTransaction);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
PRBool dummy;
|
||||
aTarget->DispatchEvent(static_cast<nsDOMEvent*>(event), &dummy);
|
||||
return NS_OK;
|
||||
return ConvertCloneBufferToJSVal(aCx, mCloneBuffer, aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -1855,26 +1857,17 @@ DeleteHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
DeleteHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
DeleteHelper::OnSuccess()
|
||||
{
|
||||
return AsyncConnectionHelper::OnSuccess(aTarget);
|
||||
return AsyncConnectionHelper::OnSuccess();
|
||||
}
|
||||
|
||||
nsresult
|
||||
DeleteHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
DeleteHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
NS_ASSERTION(!mKey.IsUnset(), "Badness!");
|
||||
|
||||
if (mKey.IsString()) {
|
||||
aResult->SetAsAString(mKey.StringValue());
|
||||
}
|
||||
else if (mKey.IsInt()) {
|
||||
aResult->SetAsInt64(mKey.IntValue());
|
||||
}
|
||||
else {
|
||||
NS_NOTREACHED("Unknown key type!");
|
||||
}
|
||||
return NS_OK;
|
||||
return IDBObjectStore::GetJSValFromKey(mKey, aCx, aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -2078,10 +2071,11 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
OpenCursorHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
||||
OpenCursorHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
if (mKey.IsUnset()) {
|
||||
aResult->SetAsEmpty();
|
||||
*aVal = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -2091,8 +2085,7 @@ OpenCursorHelper::GetSuccessResult(nsIWritableVariant* aResult)
|
|||
mCloneBuffer);
|
||||
NS_ENSURE_TRUE(cursor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
aResult->SetAsISupports(cursor);
|
||||
return NS_OK;
|
||||
return WrapNative(aCx, cursor, aVal);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -2240,20 +2233,6 @@ CreateIndexHelper::InsertDataFromObjectStore(mozIStorageConnection* aConnection)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
CreateIndexHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
{
|
||||
NS_ASSERTION(!aTarget, "Huh?!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
CreateIndexHelper::OnError(nsIDOMEventTarget* aTarget,
|
||||
nsresult aErrorCode)
|
||||
{
|
||||
NS_ASSERTION(!aTarget, "Huh?!");
|
||||
}
|
||||
|
||||
nsresult
|
||||
DeleteIndexHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
||||
{
|
||||
|
@ -2278,21 +2257,6 @@ DeleteIndexHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DeleteIndexHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
{
|
||||
NS_ASSERTION(!aTarget, "Huh?!");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
DeleteIndexHelper::OnError(nsIDOMEventTarget* aTarget,
|
||||
nsresult aErrorCode)
|
||||
{
|
||||
NS_NOTREACHED("Removing an index should never fail here!");
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetAllHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
||||
{
|
||||
|
@ -2406,17 +2370,9 @@ GetAllHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|||
}
|
||||
|
||||
nsresult
|
||||
GetAllHelper::OnSuccess(nsIDOMEventTarget* aTarget)
|
||||
GetAllHelper::GetSuccessResult(JSContext* aCx,
|
||||
jsval* aVal)
|
||||
{
|
||||
NS_ASSERTION(mCloneBuffers.Length() <= mLimit, "Too many results!");
|
||||
|
||||
nsRefPtr<GetAllSuccessEvent> event = new GetAllSuccessEvent(mCloneBuffers);
|
||||
NS_ASSERTION(mCloneBuffers.IsEmpty(), "Should have swapped!");
|
||||
|
||||
nsresult rv = event->Init(mRequest, mTransaction);
|
||||
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
PRBool dummy;
|
||||
aTarget->DispatchEvent(static_cast<nsDOMEvent*>(event), &dummy);
|
||||
return NS_OK;
|
||||
return ConvertCloneBuffersToArray(aCx, mCloneBuffers, aVal);
|
||||
}
|
||||
|
|
|
@ -51,18 +51,32 @@
|
|||
#include "nsStringGlue.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#include "AsyncConnectionHelper.h"
|
||||
#include "IDBEvents.h"
|
||||
#include "IDBTransaction.h"
|
||||
|
||||
USING_INDEXEDDB_NAMESPACE
|
||||
|
||||
IDBRequest::IDBRequest()
|
||||
: mReadyState(nsIIDBRequest::LOADING)
|
||||
: mResultVal(JSVAL_VOID),
|
||||
mErrorCode(0),
|
||||
mResultValRooted(false),
|
||||
mHaveResultOrErrorCode(false)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
}
|
||||
|
||||
IDBRequest::~IDBRequest()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (mResultValRooted) {
|
||||
// Calling a virtual from the destructor is bad... But we know that we won't
|
||||
// call a subclass' implementation because mResultValRooted will be set to
|
||||
// false.
|
||||
UnrootResultVal();
|
||||
}
|
||||
|
||||
if (mListenerManager) {
|
||||
mListenerManager->Disconnect();
|
||||
}
|
||||
|
@ -75,6 +89,8 @@ IDBRequest::Create(nsISupports* aSource,
|
|||
nsPIDOMWindow* aOwner,
|
||||
IDBTransaction* aTransaction)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (!aScriptContext || !aOwner) {
|
||||
NS_ERROR("Null context and owner!");
|
||||
return nsnull;
|
||||
|
@ -90,10 +106,61 @@ IDBRequest::Create(nsISupports* aSource,
|
|||
return request.forget();
|
||||
}
|
||||
|
||||
void
|
||||
IDBRequest::Reset()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
mHelper = nsnull;
|
||||
mResultVal = JSVAL_VOID;
|
||||
mHaveResultOrErrorCode = false;
|
||||
mErrorCode = 0;
|
||||
if (mResultValRooted) {
|
||||
UnrootResultVal();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
IDBRequest::SetDone(AsyncConnectionHelper* aHelper)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(!mHelper, "Already called!");
|
||||
|
||||
mErrorCode = NS_ERROR_GET_CODE(aHelper->GetResultCode());
|
||||
if (mErrorCode) {
|
||||
mHaveResultOrErrorCode = true;
|
||||
}
|
||||
else {
|
||||
mHelper = aHelper;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
IDBRequest::RootResultVal()
|
||||
{
|
||||
NS_ASSERTION(!mResultValRooted, "This should be false!");
|
||||
NS_HOLD_JS_OBJECTS(this, IDBRequest);
|
||||
mResultValRooted = true;
|
||||
}
|
||||
|
||||
void
|
||||
IDBRequest::UnrootResultVal()
|
||||
{
|
||||
NS_ASSERTION(mResultValRooted, "This should be true!");
|
||||
NS_DROP_JS_OBJECTS(this, IDBRequest);
|
||||
mResultValRooted = false;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBRequest::GetReadyState(PRUint16* aReadyState)
|
||||
{
|
||||
*aReadyState = mReadyState;
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (mHaveResultOrErrorCode || mHelper) {
|
||||
*aReadyState = nsIIDBRequest::DONE;
|
||||
}
|
||||
else {
|
||||
*aReadyState = nsIIDBRequest::LOADING;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -107,9 +174,77 @@ IDBRequest::GetSource(nsISupports** aSource)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBRequest::GetTransaction(nsIIDBTransaction** aTransaction)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsCOMPtr<nsIIDBTransaction> transaction(mTransaction);
|
||||
transaction.forget(aTransaction);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBRequest::GetResult(JSContext* aCx,
|
||||
jsval* aResult)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!mHaveResultOrErrorCode) {
|
||||
if (!mHelper) {
|
||||
// XXX Need a real error code here.
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
||||
}
|
||||
|
||||
NS_ASSERTION(!mResultValRooted, "Huh?!");
|
||||
NS_ASSERTION(JSVAL_IS_VOID(mResultVal), "Should be undefined!");
|
||||
|
||||
if (NS_SUCCEEDED(mHelper->GetResultCode())) {
|
||||
// It's common practice for result values to be rooted before being set.
|
||||
// Root now, even though we may unroot below, to make mResultVal safe from
|
||||
// GC.
|
||||
RootResultVal();
|
||||
|
||||
rv = mHelper->GetSuccessResult(aCx, &mResultVal);
|
||||
if (NS_FAILED(rv)) {
|
||||
mResultVal = JSVAL_VOID;
|
||||
}
|
||||
|
||||
// There's no point in rooting non-GCThings. Unroot if possible.
|
||||
if (!JSVAL_IS_GCTHING(mResultVal)) {
|
||||
UnrootResultVal();
|
||||
}
|
||||
}
|
||||
|
||||
mHaveResultOrErrorCode = true;
|
||||
mHelper = nsnull;
|
||||
}
|
||||
|
||||
*aResult = mResultVal;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBRequest::GetErrorCode(PRUint16* aErrorCode)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (!mHaveResultOrErrorCode && !mHelper) {
|
||||
// XXX Need a real error code here.
|
||||
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
||||
}
|
||||
|
||||
*aErrorCode = mErrorCode;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBRequest::SetOnsuccess(nsIDOMEventListener* aSuccessListener)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
return RemoveAddEventListener(NS_LITERAL_STRING(SUCCESS_EVT_STR),
|
||||
mOnSuccessListener, aSuccessListener);
|
||||
}
|
||||
|
@ -117,12 +252,16 @@ IDBRequest::SetOnsuccess(nsIDOMEventListener* aSuccessListener)
|
|||
NS_IMETHODIMP
|
||||
IDBRequest::GetOnsuccess(nsIDOMEventListener** aSuccessListener)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
return GetInnerEventListener(mOnSuccessListener, aSuccessListener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBRequest::SetOnerror(nsIDOMEventListener* aErrorListener)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
return RemoveAddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR),
|
||||
mOnErrorListener, aErrorListener);
|
||||
}
|
||||
|
@ -130,6 +269,8 @@ IDBRequest::SetOnerror(nsIDOMEventListener* aErrorListener)
|
|||
NS_IMETHODIMP
|
||||
IDBRequest::GetOnerror(nsIDOMEventListener** aErrorListener)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
return GetInnerEventListener(mOnErrorListener, aErrorListener);
|
||||
}
|
||||
|
||||
|
@ -137,9 +278,21 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(IDBRequest)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBRequest,
|
||||
nsDOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnSuccessListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSource)
|
||||
|
||||
// mHelper is a threadsafe runnable and can't use a cycle-collecting refcnt.
|
||||
// We traverse manually here.
|
||||
if (tmp->mHelper) {
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mHelper->mDatabase,
|
||||
nsPIDOMEventTarget)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mHelper->mTransaction,
|
||||
nsPIDOMEventTarget)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mHelper->mRequest,
|
||||
nsPIDOMEventTarget)
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBRequest,
|
||||
|
@ -147,8 +300,25 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBRequest,
|
|||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnSuccessListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSource)
|
||||
|
||||
// Unlinking mHelper will unlink all the objects that we really care about.
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBRequest)
|
||||
if (JSVAL_IS_GCTHING(tmp->mResultVal)) {
|
||||
void *gcThing = JSVAL_TO_GCTHING(tmp->mResultVal);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing)
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(IDBRequest)
|
||||
if (tmp->mResultValRooted) {
|
||||
tmp->mResultVal = JSVAL_VOID;
|
||||
tmp->UnrootResultVal();
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBRequest)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIIDBRequest)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBRequest)
|
||||
|
@ -162,11 +332,22 @@ DOMCI_DATA(IDBRequest, IDBRequest)
|
|||
nsresult
|
||||
IDBRequest::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
aVisitor.mCanHandle = PR_TRUE;
|
||||
aVisitor.mParentTarget = mTransaction;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
IDBVersionChangeRequest::~IDBVersionChangeRequest()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (mResultValRooted) {
|
||||
UnrootResultVal();
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<IDBVersionChangeRequest>
|
||||
IDBVersionChangeRequest::Create(nsISupports* aSource,
|
||||
|
@ -174,6 +355,8 @@ IDBVersionChangeRequest::Create(nsISupports* aSource,
|
|||
nsPIDOMWindow* aOwner,
|
||||
IDBTransaction* aTransaction)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
if (!aScriptContext || !aOwner) {
|
||||
NS_ERROR("Null context and owner!");
|
||||
return nsnull;
|
||||
|
@ -189,6 +372,22 @@ IDBVersionChangeRequest::Create(nsISupports* aSource,
|
|||
return request.forget();
|
||||
}
|
||||
|
||||
void
|
||||
IDBVersionChangeRequest::RootResultVal()
|
||||
{
|
||||
NS_ASSERTION(!mResultValRooted, "This should be false!");
|
||||
NS_HOLD_JS_OBJECTS(this, IDBVersionChangeRequest);
|
||||
mResultValRooted = true;
|
||||
}
|
||||
|
||||
void
|
||||
IDBVersionChangeRequest::UnrootResultVal()
|
||||
{
|
||||
NS_ASSERTION(mResultValRooted, "This should be true!");
|
||||
NS_DROP_JS_OBJECTS(this, IDBVersionChangeRequest);
|
||||
mResultValRooted = false;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
IDBVersionChangeRequest::SetOnblocked(nsIDOMEventListener* aBlockedListener)
|
||||
{
|
||||
|
|
|
@ -54,6 +54,7 @@ class nsPIDOMWindow;
|
|||
|
||||
BEGIN_INDEXEDDB_NAMESPACE
|
||||
|
||||
class AsyncConnectionHelper;
|
||||
class IDBTransaction;
|
||||
|
||||
class IDBRequest : public nsDOMEventTargetHelper,
|
||||
|
@ -62,8 +63,8 @@ class IDBRequest : public nsDOMEventTargetHelper,
|
|||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIIDBREQUEST
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBRequest,
|
||||
nsDOMEventTargetHelper)
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IDBRequest,
|
||||
nsDOMEventTargetHelper)
|
||||
|
||||
static
|
||||
already_AddRefed<IDBRequest> Create(nsISupports* aSource,
|
||||
|
@ -79,16 +80,9 @@ public:
|
|||
return mSource;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
mReadyState = nsIIDBRequest::LOADING;
|
||||
}
|
||||
void Reset();
|
||||
|
||||
void SetDone()
|
||||
{
|
||||
NS_ASSERTION(mReadyState != nsIIDBRequest::DONE, "Already set!");
|
||||
mReadyState = nsIIDBRequest::DONE;
|
||||
}
|
||||
void SetDone(AsyncConnectionHelper* aHelper);
|
||||
|
||||
nsIScriptContext* ScriptContext()
|
||||
{
|
||||
|
@ -102,17 +96,25 @@ public:
|
|||
return mOwner;
|
||||
}
|
||||
|
||||
virtual void RootResultVal();
|
||||
virtual void UnrootResultVal();
|
||||
|
||||
protected:
|
||||
IDBRequest();
|
||||
~IDBRequest();
|
||||
|
||||
nsCOMPtr<nsISupports> mSource;
|
||||
nsRefPtr<IDBTransaction> mTransaction;
|
||||
nsRefPtr<AsyncConnectionHelper> mHelper;
|
||||
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnSuccessListener;
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnErrorListener;
|
||||
|
||||
PRUint16 mReadyState;
|
||||
jsval mResultVal;
|
||||
|
||||
PRUint16 mErrorCode;
|
||||
bool mResultValRooted;
|
||||
bool mHaveResultOrErrorCode;
|
||||
};
|
||||
|
||||
class IDBVersionChangeRequest : public IDBRequest,
|
||||
|
@ -125,6 +127,8 @@ public:
|
|||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBVersionChangeRequest,
|
||||
IDBRequest)
|
||||
|
||||
~IDBVersionChangeRequest();
|
||||
|
||||
static
|
||||
already_AddRefed<IDBVersionChangeRequest>
|
||||
Create(nsISupports* aSource,
|
||||
|
@ -132,6 +136,9 @@ public:
|
|||
nsPIDOMWindow* aOwner,
|
||||
IDBTransaction* aTransaction);
|
||||
|
||||
virtual void RootResultVal();
|
||||
virtual void UnrootResultVal();
|
||||
|
||||
protected:
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnBlockedListener;
|
||||
};
|
||||
|
|
|
@ -937,10 +937,10 @@ CommitHelper::Run()
|
|||
}
|
||||
}
|
||||
|
||||
event = IDBEvent::CreateGenericEvent(NS_LITERAL_STRING(ABORT_EVT_STR));
|
||||
event = CreateGenericEvent(NS_LITERAL_STRING(ABORT_EVT_STR));
|
||||
}
|
||||
else {
|
||||
event = IDBEvent::CreateGenericEvent(NS_LITERAL_STRING(COMPLETE_EVT_STR));
|
||||
event = CreateGenericEvent(NS_LITERAL_STRING(COMPLETE_EVT_STR));
|
||||
}
|
||||
NS_ENSURE_TRUE(event, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
||||
|
||||
|
|
|
@ -196,11 +196,8 @@ public:
|
|||
// then fire the blocked event.
|
||||
for (PRUint32 index = 0; index < mWaitingDatabases.Length(); index++) {
|
||||
if (!mWaitingDatabases[index]->IsClosed()) {
|
||||
nsISupports* source =
|
||||
static_cast<nsPIDOMEventTarget*>(mRequestingDatabase);
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> event =
|
||||
IDBVersionChangeEvent::CreateBlocked(source, mVersion);
|
||||
IDBVersionChangeEvent::CreateBlocked(mVersion);
|
||||
NS_ENSURE_TRUE(event, NS_ERROR_FAILURE);
|
||||
|
||||
PRBool dummy;
|
||||
|
|
|
@ -102,16 +102,12 @@ XPIDLSRCS = \
|
|||
nsIIDBCursor.idl \
|
||||
nsIIDBDatabase.idl \
|
||||
nsIIDBDatabaseException.idl \
|
||||
nsIIDBErrorEvent.idl \
|
||||
nsIIDBEvent.idl \
|
||||
nsIIDBFactory.idl \
|
||||
nsIIDBIndex.idl \
|
||||
nsIIDBKeyRange.idl \
|
||||
nsIIDBObjectStore.idl \
|
||||
nsIIDBRequest.idl \
|
||||
nsIIDBSuccessEvent.idl \
|
||||
nsIIDBTransaction.idl \
|
||||
nsIIDBTransactionEvent.idl \
|
||||
nsIIDBVersionChangeEvent.idl \
|
||||
nsIIDBVersionChangeRequest.idl \
|
||||
nsIIndexedDatabaseManager.idl \
|
||||
|
|
|
@ -42,19 +42,20 @@
|
|||
[scriptable, uuid(2f182bf1-1542-47fe-b2f7-4b1741b5283c)]
|
||||
interface nsIIDBDatabaseException : nsISupports
|
||||
{
|
||||
const unsigned short UNKNOWN_ERR = 0;
|
||||
const unsigned short NON_TRANSIENT_ERR = 1;
|
||||
const unsigned short NOT_FOUND_ERR = 2;
|
||||
const unsigned short CONSTRAINT_ERR = 3;
|
||||
const unsigned short DATA_ERR = 4;
|
||||
const unsigned short NOT_ALLOWED_ERR = 5;
|
||||
const unsigned short TRANSACTION_INACTIVE_ERR = 6;
|
||||
const unsigned short ABORT_ERR = 7;
|
||||
const unsigned short READ_ONLY_ERR = 11;
|
||||
const unsigned short RECOVERABLE_ERR = 21;
|
||||
const unsigned short TRANSIENT_ERR = 31;
|
||||
const unsigned short TIMEOUT_ERR = 32;
|
||||
const unsigned short DEADLOCK_ERR = 33;
|
||||
// const unsigned short NO_ERR = 0;
|
||||
const unsigned short UNKNOWN_ERR = 1;
|
||||
const unsigned short NON_TRANSIENT_ERR = 2;
|
||||
const unsigned short NOT_FOUND_ERR = 3;
|
||||
const unsigned short CONSTRAINT_ERR = 4;
|
||||
const unsigned short DATA_ERR = 5;
|
||||
const unsigned short NOT_ALLOWED_ERR = 6;
|
||||
const unsigned short TRANSACTION_INACTIVE_ERR = 7;
|
||||
const unsigned short ABORT_ERR = 8;
|
||||
const unsigned short READ_ONLY_ERR = 9;
|
||||
const unsigned short RECOVERABLE_ERR = 10;
|
||||
const unsigned short TRANSIENT_ERR = 11;
|
||||
const unsigned short TIMEOUT_ERR = 12;
|
||||
const unsigned short DEADLOCK_ERR = 13;
|
||||
|
||||
readonly attribute unsigned short code;
|
||||
};
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Indexed Database.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Turner <bent.mozilla@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIIDBEvent.idl"
|
||||
|
||||
[scriptable, uuid(b2048056-3ed9-4975-97cc-dea74282b607)]
|
||||
interface nsIIDBErrorEvent : nsIIDBEvent
|
||||
{
|
||||
/**
|
||||
* See nsIIDBDatabaseException.idl
|
||||
*/
|
||||
readonly attribute unsigned short code;
|
||||
|
||||
readonly attribute DOMString message;
|
||||
};
|
|
@ -1,46 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Indexed Database.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Turner <bent.mozilla@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIDOMEvent.idl"
|
||||
|
||||
[scriptable, uuid(d5623e5f-e19d-4234-8259-343a5a21c83a)]
|
||||
interface nsIIDBEvent : nsIDOMEvent
|
||||
{
|
||||
readonly attribute nsISupports source;
|
||||
};
|
|
@ -41,13 +41,14 @@
|
|||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMEventListener;
|
||||
interface nsIIDBTransaction;
|
||||
|
||||
/**
|
||||
* IDBReqeust interface. See
|
||||
* http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-IDBRequest for more
|
||||
* information.
|
||||
*/
|
||||
[scriptable, uuid(5d55f15e-9521-4c98-ba0f-e8c07783d8d3)]
|
||||
[scriptable, uuid(a1e4a0ff-e0b2-431c-89cf-43b078189e27)]
|
||||
interface nsIIDBRequest : nsISupports
|
||||
{
|
||||
const unsigned short LOADING = 1;
|
||||
|
@ -56,7 +57,13 @@ interface nsIIDBRequest : nsISupports
|
|||
|
||||
readonly attribute nsISupports source;
|
||||
|
||||
attribute nsIDOMEventListener onsuccess;
|
||||
readonly attribute nsIIDBTransaction transaction;
|
||||
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval result;
|
||||
|
||||
readonly attribute unsigned short errorCode;
|
||||
|
||||
attribute nsIDOMEventListener onsuccess;
|
||||
attribute nsIDOMEventListener onerror;
|
||||
};
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Indexed Database.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Turner <bent.mozilla@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIIDBEvent.idl"
|
||||
|
||||
%{C++
|
||||
#include "jsapi.h"
|
||||
%}
|
||||
|
||||
[scriptable, uuid(9275d34f-54e1-4ab0-b4ca-f8d4359eec9c)]
|
||||
interface nsIIDBSuccessEvent : nsIIDBEvent
|
||||
{
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval result;
|
||||
};
|
|
@ -1,48 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Indexed Database.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Turner <bent.mozilla@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIIDBSuccessEvent.idl"
|
||||
|
||||
interface nsIIDBTransaction;
|
||||
|
||||
[scriptable, uuid(cdf58757-78b9-4f5f-8559-1bf96e1cdfba)]
|
||||
interface nsIIDBTransactionEvent : nsIIDBSuccessEvent
|
||||
{
|
||||
readonly attribute nsIIDBTransaction transaction;
|
||||
};
|
|
@ -37,10 +37,10 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIIDBEvent.idl"
|
||||
#include "nsIDOMEvent.idl"
|
||||
|
||||
[scriptable, uuid(07519073-e626-4d86-994c-801c170d263a)]
|
||||
interface nsIIDBVersionChangeEvent : nsIIDBEvent
|
||||
[scriptable, uuid(6a232c30-1bc4-4d5b-9ce0-6e7c08934755)]
|
||||
interface nsIIDBVersionChangeEvent : nsIDOMEvent
|
||||
{
|
||||
readonly attribute AString version;
|
||||
};
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
<head>
|
||||
<script>
|
||||
mozIndexedDB.open(parent.location).onsuccess = function(e) {
|
||||
var db = e.result;
|
||||
var db = e.target.result;
|
||||
// This should never be called
|
||||
db.onversionchange = function(e) {
|
||||
db.transaction(["mystore"]).objectStore("mystore").put({ hello: "fail" }, 42);
|
||||
}
|
||||
db.setVersion("1.0").onsuccess = function(e) {
|
||||
trans = e.transaction;
|
||||
trans = e.target.transaction;
|
||||
if (db.objectStoreNames.contains("mystore")) {
|
||||
db.deleteObjectStore("mystore");
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<script>
|
||||
var res = {};
|
||||
mozIndexedDB.open(parent.location).onsuccess = function(e) {
|
||||
var db = e.result;
|
||||
var db = e.target.result;
|
||||
res.version = db.version;
|
||||
res.storeCount = db.objectStoreNames.length;
|
||||
|
||||
|
@ -13,9 +13,9 @@ mozIndexedDB.open(parent.location).onsuccess = function(e) {
|
|||
res.blockedFired = true;
|
||||
}
|
||||
req.onsuccess = function(e) {
|
||||
var trans = e.transaction;
|
||||
var trans = req.transaction;
|
||||
trans.objectStore("mystore").get(42).onsuccess = function(e) {
|
||||
res.value = JSON.stringify(e.result);
|
||||
res.value = JSON.stringify(e.target.result);
|
||||
}
|
||||
trans.oncomplete = function() {
|
||||
parent.postMessage(JSON.stringify(res), "http://mochi.test:8888");
|
||||
|
|
|
@ -39,7 +39,7 @@ function grabEventAndContinueHandler(event)
|
|||
|
||||
function errorHandler(event)
|
||||
{
|
||||
throw new Error(event.code + ": " + event.message);
|
||||
throw new Error("indexedDB error, code " + event.target.errorCode);
|
||||
}
|
||||
|
||||
function continueToNextStep()
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
if (event instanceof Components.interfaces.nsIIDBSuccessEvent) {
|
||||
testResult = event.result;
|
||||
if (event.type == "success") {
|
||||
testResult = event.target.result;
|
||||
}
|
||||
else {
|
||||
testException = event.code + ": " + event.message;
|
||||
testException = event.target.errorCode;
|
||||
}
|
||||
|
||||
finishTest()
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
const testPageURL = "http://mochi.test:8888/browser/" +
|
||||
"dom/indexedDB/test/browser_permissionsPrompt.html";
|
||||
const notificationID = "indexedDB-permissions-prompt";
|
||||
const exceptionText = "5: A mutation operation was attempted on a database " +
|
||||
"that did not allow mutations.";
|
||||
|
||||
function test()
|
||||
{
|
||||
|
@ -26,7 +24,8 @@ function test1()
|
|||
|
||||
setFinishedCallback(function(result, exception) {
|
||||
ok(!result, "No database created");
|
||||
is(exception, exceptionText, "Correct exception");
|
||||
is(exception, IDBDatabaseException.NOT_ALLOWED_ERR.toString(),
|
||||
"Correct exception");
|
||||
is(getPermission(testPageURL, "indexedDB"),
|
||||
Components.interfaces.nsIPermissionManager.DENY_ACTION,
|
||||
"Correct permission set");
|
||||
|
@ -61,7 +60,8 @@ function test2()
|
|||
|
||||
setFinishedCallback(function(result, exception) {
|
||||
ok(!result, "No database created");
|
||||
is(exception, exceptionText, "Correct exception");
|
||||
is(exception, IDBDatabaseException.NOT_ALLOWED_ERR.toString(),
|
||||
"Correct exception");
|
||||
is(getPermission(testPageURL, "indexedDB"),
|
||||
Components.interfaces.nsIPermissionManager.DENY_ACTION,
|
||||
"Correct permission set");
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
const testPageURL = "http://mochi.test:8888/browser/" +
|
||||
"dom/indexedDB/test/browser_permissionsPrompt.html";
|
||||
const notificationID = "indexedDB-permissions-prompt";
|
||||
const exceptionText = "5: A mutation operation was attempted on a database " +
|
||||
"that did not allow mutations.";
|
||||
|
||||
function test()
|
||||
{
|
||||
|
@ -52,7 +50,8 @@ function test3()
|
|||
|
||||
setFinishedCallback(function(result, exception) {
|
||||
ok(!result, "No database");
|
||||
is(exception, exceptionText, "Correct exception");
|
||||
is(exception, IDBDatabaseException.NOT_ALLOWED_ERR.toString(),
|
||||
"Correct exception");
|
||||
gBrowser.removeCurrentTab();
|
||||
|
||||
executeSoon(test4);
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
db = event.result;
|
||||
db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
}
|
||||
|
||||
function errorHandler(event) {
|
||||
ok(false, "indexedDB error (" + event.code + "): " + event.message);
|
||||
ok(false, "indexedDB error, code " + event.target.errorCcode);
|
||||
finishTest();
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
is(db.version, "", "Correct version");
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
||||
|
@ -71,8 +71,8 @@
|
|||
request.onerror = errorHandler;
|
||||
event = yield;
|
||||
|
||||
event.transaction.oncomplete = unexpectedSuccessHandler;
|
||||
event.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.target.transaction.oncomplete = unexpectedSuccessHandler;
|
||||
event.target.transaction.onabort = grabEventAndContinueHandler;
|
||||
|
||||
is(db.version, "1", "Correct version");
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
||||
|
@ -95,7 +95,6 @@
|
|||
event = yield;
|
||||
|
||||
is(event.type, "abort", "Got a transaction abort event");
|
||||
|
||||
is(db.version, "", "Correct version");
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
||||
|
||||
|
@ -104,8 +103,8 @@
|
|||
request.onerror = errorHandler;
|
||||
event = yield;
|
||||
|
||||
event.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event.transaction.onabort = unexpectedSuccessHandler;
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event.target.transaction.onabort = unexpectedSuccessHandler;
|
||||
|
||||
is(db.version, "1", "Correct version");
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
}
|
||||
|
||||
function errorHandler(event) {
|
||||
ok(false, "indexedDB error (" + event.code + "): " + event.message);
|
||||
ok(false, "indexedDB error, code " + event.target.errorCode);
|
||||
finishTest();
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
|||
};
|
||||
|
||||
function errorEventCounter(event) {
|
||||
ok(event instanceof IDBErrorEvent, "Got an error event");
|
||||
ok(event.type == "error", "Got an error event");
|
||||
ok(event.target instanceof window[eventChain[0]],
|
||||
"Correct event.target");
|
||||
|
||||
|
@ -100,7 +100,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
db.onerror = errorEventCounter;
|
||||
db.addEventListener("error", errorEventCounter, true);
|
||||
|
||||
|
@ -109,7 +109,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
event.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
|
||||
db.createObjectStore("foo", { autoIncrement: true });
|
||||
yield;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
}
|
||||
|
||||
function errorHandler(event) {
|
||||
ok(false, "indexedDB error (" + event.code + "): " + event.message);
|
||||
ok(false, "indexedDB error, code " + event.target.errorCode);
|
||||
finishTest();
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
db.onerror = function(event) {
|
||||
event.preventDefault();
|
||||
};
|
||||
|
@ -76,8 +76,8 @@
|
|||
db.setVersion("1").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
event.transaction.oncomplete = unexpectedSuccessHandler;
|
||||
event.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.target.transaction.oncomplete = unexpectedSuccessHandler;
|
||||
event.target.transaction.onabort = grabEventAndContinueHandler;
|
||||
|
||||
is(db.version, "1", "Correct version");
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
|
||||
|
|
|
@ -47,7 +47,7 @@ function continueToNextStep()
|
|||
|
||||
function errorHandler(event)
|
||||
{
|
||||
ok(false, "indexedDB error (" + event.code + "): " + event.message);
|
||||
ok(false, "indexedDB error, code " + event.target.errorCode);
|
||||
finishTest();
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,8 @@ function ExpectError(code)
|
|||
ExpectError.prototype = {
|
||||
handleEvent: function(event)
|
||||
{
|
||||
is(this._code, event.code, "Expected error was thrown.");
|
||||
is(event.type, "error", "Got an error event");
|
||||
is(this._code, event.target.errorCode, "Expected error was thrown.");
|
||||
event.preventDefault();
|
||||
grabEventAndContinueHandler(event);
|
||||
}
|
||||
|
|
|
@ -21,13 +21,15 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = request.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
ok(event.target === request, "Good event target");
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "" });
|
||||
let key = 10;
|
||||
|
||||
|
@ -36,7 +38,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, key, "Correct key");
|
||||
is(request.result, key, "Correct key");
|
||||
|
||||
request = objectStore.add({}, key);
|
||||
request.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = request.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
|
|
@ -24,14 +24,14 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = request.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
event.transaction.oncomplete = continueToNextStep;
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
|||
request.onerror = errorHandler;
|
||||
if (!i) {
|
||||
request.onsuccess = function(event) {
|
||||
firstKey = event.result;
|
||||
firstKey = event.target.result;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@
|
|||
request = db.transaction("foo").objectStore("foo").openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
seenEntryCount++;
|
||||
cursor.continue();
|
||||
|
@ -80,12 +80,14 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.result === undefined, "Correct event.result");
|
||||
ok(event.target.result === undefined, "Correct event.target.result");
|
||||
ok(request.result === undefined, "Correct request.result");
|
||||
ok(request === event.target, "Correct event.target");
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
let cursor = event.result;
|
||||
let cursor = request.result;
|
||||
if (cursor) {
|
||||
ok(false, "Shouldn't have any entries");
|
||||
}
|
||||
|
@ -98,7 +100,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
isnot(event.result, firstKey, "Got a different key");
|
||||
isnot(event.target.result, firstKey, "Got a different key");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -111,15 +111,16 @@
|
|||
}
|
||||
ok(found, "Name is on objectStore.indexNames");
|
||||
|
||||
ok(event.transaction, "event has a transaction");
|
||||
ok(event.transaction.db === db, "transaction has the right db");
|
||||
is(event.transaction.readyState, nsIIDBTransaction.LOADING,
|
||||
ok(event.target.transaction, "event has a transaction");
|
||||
ok(event.target.transaction.db === db,
|
||||
"transaction has the right db");
|
||||
is(event.target.transaction.readyState, nsIIDBTransaction.LOADING,
|
||||
"transaction has the correct readyState");
|
||||
is(event.transaction.mode, nsIIDBTransaction.VERSION_CHANGE,
|
||||
is(event.target.transaction.mode, nsIIDBTransaction.VERSION_CHANGE,
|
||||
"transaction has the correct mode");
|
||||
is(event.transaction.objectStoreNames.length, i + 1,
|
||||
is(event.target.transaction.objectStoreNames.length, i + 1,
|
||||
"transaction only has one object store");
|
||||
is(event.transaction.objectStoreNames.item(0), objectStoreName,
|
||||
is(event.target.transaction.objectStoreNames.item(0), objectStoreName,
|
||||
"transaction has the correct object store");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,9 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
ok(event.source === mozIndexedDB, "event.source is correct");
|
||||
let db = event.result;
|
||||
ok(event.target.source === mozIndexedDB,
|
||||
"event.target.source is correct");
|
||||
let db = event.target.result;
|
||||
|
||||
let count = db.objectStoreNames.length;
|
||||
is(count, 0, "correct objectStoreNames length");
|
||||
|
@ -48,7 +49,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.source === db, "event.source is correct");
|
||||
ok(event.target.source === db, "event.target.source is correct");
|
||||
|
||||
try {
|
||||
db.createObjectStore(null);
|
||||
|
@ -108,17 +109,18 @@
|
|||
"Bad keyPath");
|
||||
if(objectStore.indexNames.length, 0, "Bad indexNames");
|
||||
|
||||
ok(event.transaction, "event has a transaction");
|
||||
ok(event.transaction.db === db, "transaction has the right db");
|
||||
is(event.transaction.readyState, nsIIDBTransaction.LOADING,
|
||||
ok(event.target.transaction, "event has a transaction");
|
||||
ok(event.target.transaction.db === db, "transaction has the right db");
|
||||
is(event.target.transaction.readyState, nsIIDBTransaction.LOADING,
|
||||
"transaction has the correct readyState");
|
||||
is(event.transaction.mode, nsIIDBTransaction.VERSION_CHANGE,
|
||||
is(event.target.transaction.mode, nsIIDBTransaction.VERSION_CHANGE,
|
||||
"transaction has the correct mode");
|
||||
is(event.transaction.objectStoreNames.length, index + 1,
|
||||
is(event.target.transaction.objectStoreNames.length, index + 1,
|
||||
"transaction has correct objectStoreNames list");
|
||||
found = false;
|
||||
for (let j = 0; j < event.transaction.objectStoreNames.length; j++) {
|
||||
if (event.transaction.objectStoreNames.item(j) == info.name) {
|
||||
for (let j = 0; j < event.target.transaction.objectStoreNames.length;
|
||||
j++) {
|
||||
if (event.target.transaction.objectStoreNames.item(j) == info.name) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -35,12 +35,12 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
db.setVersion("1").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
event.transaction.oncomplete = continueToNextStep;
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { keyPath: "ss" });
|
||||
objectStore.createIndex("name", "name", { unique: true });
|
||||
|
@ -57,8 +57,8 @@
|
|||
|
||||
db.transaction("foo").objectStore("foo").openCursor().onsuccess =
|
||||
function(event) {
|
||||
event.transaction.oncomplete = continueToNextStep;
|
||||
let cursor = event.result;
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value.name == objectStoreData[0].name) {
|
||||
sawRemoved = true;
|
||||
|
@ -83,8 +83,8 @@
|
|||
|
||||
db.transaction("foo", IDBTransaction.READ_WRITE).objectStore("foo")
|
||||
.index("name").openCursor().onsuccess = function(event) {
|
||||
event.transaction.oncomplete = continueToNextStep;
|
||||
let cursor = event.result;
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
if (cursor.value.name == objectStoreData[0].name) {
|
||||
sawRemoved = true;
|
||||
|
@ -99,7 +99,7 @@
|
|||
"Correct name");
|
||||
|
||||
if (count == 1) {
|
||||
let objectStore = event.transaction.objectStore("foo");
|
||||
let objectStore = event.target.transaction.objectStore("foo");
|
||||
objectStore.delete(objectStoreData[0].ss)
|
||||
.onsuccess = function(event) {
|
||||
objectStore.add(objectStoreData[objectStoreData.length - 1])
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
for (let i = 0; i < objectStoreInfo.length; i++) {
|
||||
// Create our object stores.
|
||||
|
@ -58,7 +58,6 @@
|
|||
{ unique: false });
|
||||
let uniqueIndex = objectStore.createIndex("unique_data_index", "data",
|
||||
{ unique: true });
|
||||
|
||||
// Populate the object store with one entry of data.
|
||||
request = info.hasOwnProperty("key") ?
|
||||
objectStore.add(info.entry, info.key) :
|
||||
|
@ -75,7 +74,7 @@
|
|||
event = yield;
|
||||
ok(true, "4");
|
||||
|
||||
let cursor = event.result;
|
||||
let cursor = request.result;
|
||||
let obj = cursor.value;
|
||||
obj.data = END_DATA;
|
||||
request = cursor.update(obj);
|
||||
|
@ -90,7 +89,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
ok(true, "6");
|
||||
SimpleTest.ok(obj.data, event.result.data,
|
||||
SimpleTest.ok(obj.data, event.target.result.data,
|
||||
"Non-unique index was properly updated.");
|
||||
|
||||
request = uniqueIndex.get(END_DATA);
|
||||
|
@ -99,7 +98,7 @@
|
|||
event = yield;
|
||||
|
||||
ok(true, "7");
|
||||
SimpleTest.ok(obj.data, event.result.data,
|
||||
SimpleTest.ok(obj.data, event.target.result.data,
|
||||
"Unique index was properly updated.");
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -38,7 +38,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.result, "No results");
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -50,7 +50,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.result, "No results");
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -60,7 +60,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.result, "No results");
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -70,7 +70,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
ok(!event.result, "No results");
|
||||
ok(!event.target.result, "No results");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -93,7 +93,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
@ -128,7 +128,7 @@
|
|||
request = objectStore.openCursor(range);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
@ -153,7 +153,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
@ -183,7 +183,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
@ -213,7 +213,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
@ -243,7 +243,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
@ -274,7 +274,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, "bar", "Update succeeded");
|
||||
is(event.target.result, "bar", "Update succeeded");
|
||||
|
||||
request = objectStore.put("foo", sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
|
@ -289,7 +289,7 @@
|
|||
request = objectStore.openCursor(null, IDBCursor.NEXT);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
@ -298,7 +298,7 @@
|
|||
request = cursor.delete();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.result, sortedKeys[4], "Correct key");
|
||||
is(event.target.result, sortedKeys[4], "Correct key");
|
||||
is(keyIndex, 5, "Got result of remove before next continue");
|
||||
gotRemoveEvent = true;
|
||||
};
|
||||
|
@ -321,7 +321,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, undefined, "Entry was deleted");
|
||||
is(event.target.result, undefined, "Entry was deleted");
|
||||
|
||||
request = objectStore.add("foo", sortedKeys[4]);
|
||||
request.onerror = errorHandler;
|
||||
|
@ -333,7 +333,7 @@
|
|||
request = objectStore.openCursor(null, IDBCursor.PREV);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, sortedKeys[keyIndex], "Correct key");
|
||||
is(cursor.value, "foo", "Correct value");
|
||||
|
|
|
@ -22,16 +22,16 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
var event = yield;
|
||||
|
||||
ok(event.source === mozIndexedDB, "correct event.source");
|
||||
ok(event.target.source === mozIndexedDB, "correct event.target.source");
|
||||
|
||||
var db = event.result;
|
||||
var db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.source === db, "correct event.source");
|
||||
ok(event.target.source === db, "correct event.target.source");
|
||||
|
||||
var objectStore = db.createObjectStore(objectStoreName,
|
||||
{ autoIncrement: true });
|
||||
|
@ -40,7 +40,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.source === objectStore, "correct event.source");
|
||||
ok(event.target.source === objectStore, "correct event.source");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -37,8 +37,8 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 0, "No elements");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 0, "No elements");
|
||||
|
||||
let addedCount = 0;
|
||||
|
||||
|
@ -58,11 +58,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, values.length, "Same length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, values.length, "Same length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], values[i], "Same value");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[i], "Same value");
|
||||
}
|
||||
|
||||
request = db.transaction("foo").objectStore("foo").getAll(null, 5);
|
||||
|
@ -70,11 +70,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 5, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 5, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], values[i], "Same value");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[i], "Same value");
|
||||
}
|
||||
|
||||
let keyRange = IDBKeyRange.bound(1, 9);
|
||||
|
@ -84,11 +84,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, values.length, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, values.length, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], values[i], "Same value");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[i], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
@ -98,11 +98,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 4, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], values[parseInt(i) + 3], "Same value");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
// Get should take a key range also.
|
||||
|
@ -111,11 +111,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 4, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], values[parseInt(i) + 3], "Same value");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
@ -125,11 +125,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 2, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], values[parseInt(i) + 3], "Same value");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
@ -139,11 +139,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 4, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], values[parseInt(i) + 3], "Same value");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 3], "Same value");
|
||||
}
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7);
|
||||
|
@ -153,8 +153,8 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 0, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 0, "Correct length");
|
||||
|
||||
keyRange = IDBKeyRange.bound(4, 7, true, true);
|
||||
|
||||
|
@ -163,11 +163,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 2, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], values[parseInt(i) + 4], "Same value");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], values[parseInt(i) + 4], "Same value");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db1 = event.result;
|
||||
let db1 = event.target.result;
|
||||
|
||||
request = db1.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -42,7 +42,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let db2 = event.result;
|
||||
let db2 = event.target.result;
|
||||
|
||||
ok(db1 !== db2, "Databases are not the same object");
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -107,11 +107,11 @@
|
|||
event = yield;
|
||||
ok(true, "3");
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 2, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
||||
"Correct key");
|
||||
}
|
||||
|
||||
|
@ -121,12 +121,12 @@
|
|||
event = yield;
|
||||
ok(true, "4");
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, objectStoreDataHeightSort.length,
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, objectStoreDataHeightSort.length,
|
||||
"Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAllKeys(null, 4);
|
||||
|
@ -135,11 +135,11 @@
|
|||
event = yield;
|
||||
|
||||
ok(true, "5");
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 4, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[i].key, "Correct key");
|
||||
}
|
||||
|
||||
request = objectStore.index("height").getAllKeys(65, 1);
|
||||
|
@ -148,11 +148,11 @@
|
|||
event = yield;
|
||||
|
||||
ok(true, "6");
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 1, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 1, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
is(event.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
||||
for (let i in event.target.result) {
|
||||
is(event.target.result[i], objectStoreDataHeightSort[parseInt(i) + 3].key,
|
||||
"Correct key");
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -104,11 +104,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 2, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 2, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
let result = event.result[i];
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
|
@ -124,12 +124,12 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, objectStoreDataHeightSort.length,
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, objectStoreDataHeightSort.length,
|
||||
"Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
let result = event.result[i];
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[i].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
|
@ -145,11 +145,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 4, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 4, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
let result = event.result[i];
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[i].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
|
@ -165,11 +165,11 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result instanceof Array, true, "Got an array object");
|
||||
is(event.result.length, 1, "Correct length");
|
||||
is(event.target.result instanceof Array, true, "Got an array object");
|
||||
is(event.target.result.length, 1, "Correct length");
|
||||
|
||||
for (let i in event.result) {
|
||||
let result = event.result[i];
|
||||
for (let i in event.target.result) {
|
||||
let result = event.target.result[i];
|
||||
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
|
||||
|
||||
is(result.name, testObj.name, "Correct name");
|
||||
|
|
|
@ -35,13 +35,13 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
db.setVersion("1").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
event.result.oncomplete = continueToNextStep;
|
||||
event.target.result.oncomplete = continueToNextStep;
|
||||
|
||||
for (let objectStoreIndex in objectStoreData) {
|
||||
const objectStoreInfo = objectStoreData[objectStoreIndex];
|
||||
|
@ -85,7 +85,7 @@
|
|||
let keyIndex = 0;
|
||||
|
||||
index.openCursor().onsuccess = function(event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (!cursor) {
|
||||
continueToNextStep();
|
||||
return;
|
||||
|
@ -123,7 +123,7 @@
|
|||
db.transaction(objectStoreName).objectStore(objectStoreName)
|
||||
.openCursor()
|
||||
.onsuccess = function(event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (!cursor) {
|
||||
continueToNextStep();
|
||||
return;
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -133,16 +133,16 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, "237-23-7732", "Correct key returned!");
|
||||
is(event.target.result, "237-23-7732", "Correct key returned!");
|
||||
|
||||
request = objectStore.index("name").get("Bob");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result.name, "Bob", "Correct name returned!");
|
||||
is(event.result.height, 60, "Correct height returned!");
|
||||
is(event.result.weight, 120, "Correct weight returned!");
|
||||
is(event.target.result.name, "Bob", "Correct name returned!");
|
||||
is(event.target.result.height, 60, "Correct height returned!");
|
||||
is(event.target.result.weight, 120, "Correct weight returned!");
|
||||
|
||||
ok(true, "Test group 1");
|
||||
|
||||
|
@ -151,7 +151,7 @@
|
|||
request = objectStore.index("name").openKeyCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -182,7 +182,7 @@
|
|||
request = objectStore.index("weight").openKeyCursor(null, NEXT);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
|
||||
"Correct key");
|
||||
|
@ -222,7 +222,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(null, PREV);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -254,7 +254,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -280,7 +280,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -306,7 +306,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -332,7 +332,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -358,7 +358,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -384,7 +384,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -410,7 +410,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -436,7 +436,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -462,7 +462,7 @@
|
|||
request = objectStore.index("name").openKeyCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -487,7 +487,7 @@
|
|||
request = objectStore.index("name").openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -534,7 +534,7 @@
|
|||
request = objectStore.index("name").openCursor(null, PREV);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -582,7 +582,7 @@
|
|||
request = objectStore.index("name").openCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -630,7 +630,7 @@
|
|||
request = objectStore.index("name").openCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -678,7 +678,7 @@
|
|||
request = objectStore.index("name").openCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -726,7 +726,7 @@
|
|||
request = objectStore.index("name").openCursor(keyRange);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -774,7 +774,7 @@
|
|||
request = objectStore.index("name").openCursor(keyRange, PREV);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -823,7 +823,7 @@
|
|||
request = objectStore.index("height").openKeyCursor(keyRange, NEXT);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
|
||||
"Correct key");
|
||||
|
@ -850,7 +850,7 @@
|
|||
NEXT_NO_DUPLICATE);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
|
||||
"Correct key");
|
||||
|
@ -876,7 +876,7 @@
|
|||
PREV_NO_DUPLICATE);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
|
||||
"Correct key");
|
||||
|
@ -905,7 +905,7 @@
|
|||
request = objectStore.index("height").openCursor(keyRange, NEXT);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
|
||||
"Correct key");
|
||||
|
@ -940,7 +940,7 @@
|
|||
NEXT_NO_DUPLICATE);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
|
||||
"Correct key");
|
||||
|
@ -974,7 +974,7 @@
|
|||
PREV_NO_DUPLICATE);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
|
||||
"Correct key");
|
||||
|
@ -1010,7 +1010,7 @@
|
|||
request = objectStore.index("name").openKeyCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -1048,7 +1048,7 @@
|
|||
request = objectStore.index("name").openKeyCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -1081,7 +1081,7 @@
|
|||
request = objectStore.index("name").openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
@ -1135,7 +1135,7 @@
|
|||
request = objectStore.index("name").openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
|
||||
"Correct key");
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -102,7 +102,7 @@
|
|||
request = objectStore.index("weight").openKeyCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
|
||||
"Correct key");
|
||||
|
@ -125,7 +125,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
let cursor = event.result;
|
||||
let cursor = event.target.result;
|
||||
if (cursor) {
|
||||
keyIndex++;
|
||||
cursor.continue();
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
db.addEventListener("error", function(event) {
|
||||
event.preventDefault();
|
||||
}, false);
|
||||
|
@ -38,14 +38,14 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let key1 = event.result;
|
||||
let key1 = event.target.result;
|
||||
|
||||
request = objectStore.put({}, key1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, key1, "put gave the same key back");
|
||||
is(event.target.result, key1, "put gave the same key back");
|
||||
|
||||
let key2 = 10;
|
||||
|
||||
|
@ -54,7 +54,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, key2, "put gave the same key back");
|
||||
is(event.target.result, key2, "put gave the same key back");
|
||||
|
||||
key2 = 100;
|
||||
|
||||
|
@ -63,7 +63,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, key2, "put gave the same key back");
|
||||
is(event.target.result, key2, "put gave the same key back");
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
|
@ -172,21 +172,21 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, key1, "add gave back the same key");
|
||||
is(event.target.result, key1, "add gave back the same key");
|
||||
|
||||
request = objectStore.put({id:10});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, key1, "put gave back the same key");
|
||||
is(event.target.result, key1, "put gave back the same key");
|
||||
|
||||
request = objectStore.put({id:10});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, key1, "put gave back the same key");
|
||||
is(event.target.result, key1, "put gave back the same key");
|
||||
|
||||
request = objectStore.add({id:10});
|
||||
request.onerror = new ExpectError(IDBDatabaseException.CONSTRAINT_ERR);
|
||||
|
@ -233,14 +233,14 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
key1 = event.result;
|
||||
key1 = event.target.result;
|
||||
|
||||
request = objectStore.put({id:key1});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, key1, "put gave the same key back");
|
||||
is(event.target.result, key1, "put gave the same key back");
|
||||
|
||||
key2 = 10;
|
||||
|
||||
|
@ -249,7 +249,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, key2, "put gave the same key back");
|
||||
is(event.target.result, key2, "put gave the same key back");
|
||||
|
||||
try {
|
||||
objectStore.put({});
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
for (let i in objectStores) {
|
||||
request = db.setVersion("1");
|
||||
|
@ -58,13 +58,13 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.result == 1 || event.result == 2, "Good id");
|
||||
ok(event.target.result == 1 || event.target.result == 2, "Good id");
|
||||
}
|
||||
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
|
||||
let objectStore = event.result;
|
||||
let objectStore = event.target.result;
|
||||
|
||||
for (let i in objectStores) {
|
||||
for (let j in indexes) {
|
||||
|
@ -75,7 +75,7 @@
|
|||
request = index.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function (event) {
|
||||
is(event.result.value.name, "Ben", "Good object");
|
||||
is(event.target.result.value.name, "Ben", "Good object");
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
}
|
||||
yield;
|
||||
|
|
|
@ -24,7 +24,7 @@ function testSteps()
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
var event = yield;
|
||||
|
||||
var db = event.result;
|
||||
var db = event.target.result;
|
||||
|
||||
var test = {
|
||||
name: "inline key; key generator",
|
||||
|
@ -47,18 +47,18 @@ function testSteps()
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let id = event.result;
|
||||
let id = event.target.result;
|
||||
request = objectStore.get(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
// Sanity check!
|
||||
is(event.result.name, test.storedObject.name,
|
||||
is(event.target.result.name, test.storedObject.name,
|
||||
"The correct object was stored.");
|
||||
|
||||
// Ensure that the id was also stored on the object.
|
||||
is(event.result.id, id, "The object had the id stored on it.");
|
||||
is(event.target.result.id, id, "The object had the id stored on it.");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
|
|
|
@ -24,7 +24,7 @@ function testSteps()
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
var event = yield;
|
||||
|
||||
var db = event.result;
|
||||
var db = event.target.result;
|
||||
|
||||
var data = [
|
||||
{ name: "inline key; key generator",
|
||||
|
@ -71,14 +71,14 @@ function testSteps()
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let id = event.result;
|
||||
let id = event.target.result;
|
||||
request = objectStore.get(id);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
// Sanity check!
|
||||
is(test.storedObject.name, event.result.name,
|
||||
is(test.storedObject.name, event.target.result.name,
|
||||
"The correct object was stored.");
|
||||
|
||||
request = objectStore.delete(id);
|
||||
|
@ -92,7 +92,7 @@ function testSteps()
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
ok(event.result === undefined, "Object was deleted");
|
||||
ok(event.target.result === undefined, "Object was deleted");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let transaction = event.transaction;
|
||||
let transaction = event.target.transaction;
|
||||
|
||||
let objectStore1 = db.createObjectStore("foo");
|
||||
let objectStore2 = transaction.objectStore("foo");
|
||||
|
|
|
@ -43,11 +43,16 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
is(db.name, name, "Bad name");
|
||||
is(db.version, "", "Bad version");
|
||||
is(db.objectStoreNames.length, 0, "Bad objectStores list");
|
||||
|
||||
is(db.name, request.result.name, "Bad name");
|
||||
is(db.version, request.result.version, "Bad version");
|
||||
is(db.objectStoreNames.length, request.result.objectStoreNames.length,
|
||||
"Bad objectStores list");
|
||||
|
||||
finishTest();
|
||||
yield;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Bad objectStores list");
|
||||
|
||||
request = db.setVersion("1");
|
||||
|
|
|
@ -24,13 +24,13 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
event.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
for (let i in objectStores) {
|
||||
db.createObjectStore(objectStores[i], { autoIncrement: true });
|
||||
}
|
||||
|
@ -86,7 +86,7 @@
|
|||
request.onsuccess = function(event) {
|
||||
is(stepNumber, 5, "This callback came fifth");
|
||||
stepNumber++;
|
||||
event.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
}
|
||||
|
||||
stepNumber++;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -38,22 +38,22 @@
|
|||
request = objectStore.add(testString.value, testString.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.result, testString.key, "Got the right key");
|
||||
is(event.target.result, testString.key, "Got the right key");
|
||||
request = objectStore.get(testString.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.result, testString.value, "Got the right value");
|
||||
is(event.target.result, testString.value, "Got the right value");
|
||||
};
|
||||
};
|
||||
|
||||
request = objectStore.add(testInt.value, testInt.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.result, testInt.key, "Got the right key");
|
||||
is(event.target.result, testInt.key, "Got the right key");
|
||||
request = objectStore.get(testInt.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.result, testInt.value, "Got the right value");
|
||||
is(event.target.result, testInt.value, "Got the right value");
|
||||
finishTest();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -38,22 +38,22 @@
|
|||
request = objectStore.add(testString.value);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
testString.key = event.result;
|
||||
testString.key = event.target.result;
|
||||
request = objectStore.get(testString.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.result, testString.value, "Got the right value");
|
||||
is(event.target.result, testString.value, "Got the right value");
|
||||
};
|
||||
};
|
||||
|
||||
request = objectStore.add(testInt.value);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
testInt.key = event.result;
|
||||
testInt.key = event.target.result;
|
||||
request = objectStore.get(testInt.key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.result, testInt.value, "Got the right value");
|
||||
is(event.target.result, testInt.value, "Got the right value");
|
||||
finishTest();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
request = db.setVersion("1");
|
||||
|
@ -42,8 +42,8 @@
|
|||
.add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.transaction.mode, READ_WRITE, "Correct mode");
|
||||
key1 = event.result;
|
||||
is(event.target.transaction.mode, READ_WRITE, "Correct mode");
|
||||
key1 = event.target.result;
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -51,8 +51,8 @@
|
|||
request = db.transaction(osName, READ_WRITE).objectStore(osName).add({});
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.transaction.mode, READ_WRITE, "Correct mode");
|
||||
key2 = event.result;
|
||||
is(event.target.transaction.mode, READ_WRITE, "Correct mode");
|
||||
key2 = event.target.result;
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -62,7 +62,7 @@
|
|||
.put({}, key1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.transaction.mode, READ_WRITE, "Correct mode");
|
||||
is(event.target.transaction.mode, READ_WRITE, "Correct mode");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -72,7 +72,7 @@
|
|||
.put({}, key2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.transaction.mode, READ_WRITE, "Correct mode");
|
||||
is(event.target.transaction.mode, READ_WRITE, "Correct mode");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -82,7 +82,7 @@
|
|||
.put({}, key1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.transaction.mode, READ_WRITE, "Correct mode");
|
||||
is(event.target.transaction.mode, READ_WRITE, "Correct mode");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -92,7 +92,7 @@
|
|||
.put({}, key1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.transaction.mode, READ_WRITE, "Correct mode");
|
||||
is(event.target.transaction.mode, READ_WRITE, "Correct mode");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -102,7 +102,7 @@
|
|||
.delete(key1);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.transaction.mode, READ_WRITE, "Correct mode");
|
||||
is(event.target.transaction.mode, READ_WRITE, "Correct mode");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
@ -112,7 +112,7 @@
|
|||
.delete(key2);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.transaction.mode, READ_WRITE, "Correct mode");
|
||||
is(event.target.transaction.mode, READ_WRITE, "Correct mode");
|
||||
testGenerator.next();
|
||||
}
|
||||
yield;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
request = db.setVersion("1");
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
is(db.objectStoreNames.length, 0, "Correct objectStoreNames list");
|
||||
|
||||
request = db.setVersion("1");
|
||||
|
@ -68,7 +68,7 @@
|
|||
request = objectStore.openCursor();
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.result, undefined, "ObjectStore shouldn't have any items");
|
||||
is(event.target.result, undefined, "ObjectStore shouldn't have any items");
|
||||
testGenerator.send(event);
|
||||
}
|
||||
event = yield;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
is(request.readyState, DONE, "Correct readyState");
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
is(request.readyState, LOADING, "Correct readyState");
|
||||
|
@ -50,7 +50,7 @@
|
|||
event = yield;
|
||||
|
||||
is(request.readyState, DONE, "Correct readyState");
|
||||
is(event.result, key, "Correct key");
|
||||
is(event.target.result, key, "Correct key");
|
||||
|
||||
request = objectStore.get(key);
|
||||
request.onerror = errorHandler;
|
||||
|
@ -58,7 +58,7 @@
|
|||
is(request.readyState, LOADING, "Correct readyState");
|
||||
event = yield;
|
||||
|
||||
ok(event.result, "Got something");
|
||||
ok(event.target.result, "Got something");
|
||||
is(request.readyState, DONE, "Correct readyState");
|
||||
|
||||
finishTest();
|
||||
|
|
|
@ -25,7 +25,7 @@ function testSteps()
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
// Check default state.
|
||||
is(db.version, "", "Correct default version for a new database.");
|
||||
|
@ -44,7 +44,7 @@ function testSteps()
|
|||
event = yield;
|
||||
|
||||
is(db.version, version, "Database version number updated correctly");
|
||||
is(event.transaction.mode, VERSION_CHANGE, "Correct mode");
|
||||
is(event.target.transaction.mode, VERSION_CHANGE, "Correct mode");
|
||||
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
|
|
|
@ -25,7 +25,7 @@ function testSteps()
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
|
@ -39,9 +39,9 @@ function testSteps()
|
|||
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
|
||||
is(objectStore.indexNames.length, 1, "Correct indexNames length");
|
||||
|
||||
event.transaction.oncomplete = unexpectedSuccessHandler;
|
||||
event.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.transaction.abort();
|
||||
event.target.transaction.oncomplete = unexpectedSuccessHandler;
|
||||
event.target.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.target.transaction.abort();
|
||||
|
||||
event = yield;
|
||||
|
||||
|
|
|
@ -24,12 +24,13 @@
|
|||
let versionChangeEventCount = 0;
|
||||
let db1, db2, db3;
|
||||
|
||||
db1 = event.result;
|
||||
db1 = event.target.result;
|
||||
db1.addEventListener("versionchange", function(event) {
|
||||
ok(true, "Got version change event");
|
||||
is(event.source, null, "Correct source");
|
||||
is(event.target.source, null, "Correct source");
|
||||
is(event.target, db1, "Correct target");
|
||||
is(event.version, "1", "Correct version");
|
||||
is(event.target.version, "", "Correct db version");
|
||||
is(event.version, "1", "Correct event version");
|
||||
is(versionChangeEventCount++, 0, "Correct count");
|
||||
db1.close();
|
||||
}, false);
|
||||
|
@ -39,52 +40,52 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
db2 = event.result;
|
||||
db2 = event.target.result;
|
||||
db2.addEventListener("versionchange", function(event) {
|
||||
ok(true, "Got version change event");
|
||||
is(event.source, null, "Correct source");
|
||||
is(event.target.source, null, "Correct source");
|
||||
is(event.target, db2, "Correct target");
|
||||
is(event.version, "2", "Correct version");
|
||||
is(event.target.version, "1", "Correct db version");
|
||||
is(event.version, "2", "Correct event version");
|
||||
is(versionChangeEventCount++, 1, "Correct count");
|
||||
}, false);
|
||||
|
||||
request = db2.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
request.onblocked = function(event) {
|
||||
ok(true, "Got version change blocked event");
|
||||
is(event.source, db2, "Correct source");
|
||||
is(event.target, request, "Correct target");
|
||||
is(event.version, "1", "Correct version");
|
||||
is(versionChangeEventCount++, 2, "Correct count");
|
||||
};
|
||||
|
||||
request.onblocked = errorHandler;
|
||||
event = yield;
|
||||
ok(event.result === event.transaction, "Good result");
|
||||
is(event.transaction.mode, IDBTransaction.VERSION_CHANGE, "Correct mode");
|
||||
|
||||
ok(event.target.result === event.target.transaction, "Good result");
|
||||
is(event.target.transaction.mode, IDBTransaction.VERSION_CHANGE,
|
||||
"Correct mode");
|
||||
is(db2.version, "1", "Correct db version");
|
||||
|
||||
request = mozIndexedDB.open(name, description);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
db3 = event.result;
|
||||
db3 = event.target.result;
|
||||
|
||||
request = db3.setVersion("2");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
request.onblocked = function(event) {
|
||||
ok(true, "Got version change blocked event");
|
||||
is(event.source, db3, "Correct source");
|
||||
is(event.target.source, db3, "Correct source");
|
||||
is(event.target, request, "Correct target");
|
||||
is(event.version, "2", "Correct version");
|
||||
is(event.target.source.version, "1", "Correct db version");
|
||||
is(event.version, "2", "Correct event version");
|
||||
versionChangeEventCount++;
|
||||
db2.close();
|
||||
};
|
||||
|
||||
event = yield;
|
||||
ok(event.result === event.transaction, "Good result");
|
||||
is(event.transaction.mode, IDBTransaction.VERSION_CHANGE, "Correct mode");
|
||||
|
||||
ok(event.target.result === event.target.transaction, "Good result");
|
||||
is(event.target.transaction.mode, IDBTransaction.VERSION_CHANGE,
|
||||
"Correct mode");
|
||||
is(db3.version, "2", "Correct db version");
|
||||
|
||||
is(versionChangeEventCount, 3, "Saw all expected events");
|
||||
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
let request = db.setVersion("1");
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
request.onerror = errorHandler;
|
||||
event = yield;
|
||||
|
||||
event.result.oncomplete = continueToNextStep;
|
||||
event.target.result.oncomplete = continueToNextStep;
|
||||
|
||||
let objectStore = db.createObjectStore("foo");
|
||||
objectStore.add({}, 1).onerror = errorHandler;
|
||||
|
@ -43,7 +43,7 @@
|
|||
request = objectStore.get(1);
|
||||
request.onsuccess = unexpectedSuccessHandler;
|
||||
request.onerror = function(event) {
|
||||
is(event.code, IDBDatabaseException.ABORT_ERR, "Good code");
|
||||
is(event.target.errorCode, IDBDatabaseException.ABORT_ERR, "Good code");
|
||||
sawError = true;
|
||||
event.preventDefault();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
let transaction;
|
||||
let objectStore;
|
||||
|
@ -40,7 +40,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
transaction = event.transaction;
|
||||
transaction = event.target.transaction;
|
||||
objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
is(transaction.db, db, "Correct database");
|
||||
|
@ -166,10 +166,10 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
event.transaction.onabort = function(event) {
|
||||
event.target.transaction.onabort = function(event) {
|
||||
ok(false, "Shouldn't see an abort event!");
|
||||
};
|
||||
event.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event.target.transaction.oncomplete = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.type, "complete", "Right kind of event");
|
||||
|
@ -181,16 +181,16 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
key = event.result;
|
||||
key = event.target.result;
|
||||
|
||||
event.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.transaction.oncomplete = function(event) {
|
||||
event.target.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.target.transaction.oncomplete = function(event) {
|
||||
ok(false, "Shouldn't see a complete event here!");
|
||||
};
|
||||
|
||||
is(event.transaction.readyState, LOADING, "Correct readyState");
|
||||
event.transaction.abort();
|
||||
is(event.transaction.readyState, DONE, "Correct readyState");
|
||||
is(event.target.transaction.readyState, LOADING, "Correct readyState");
|
||||
event.target.transaction.abort();
|
||||
is(event.target.transaction.readyState, DONE, "Correct readyState");
|
||||
|
||||
event = yield;
|
||||
|
||||
|
@ -201,7 +201,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, undefined, "Object was removed");
|
||||
is(event.target.result, undefined, "Object was removed");
|
||||
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
yield;
|
||||
|
@ -213,15 +213,16 @@
|
|||
for (let i = 0; i < 10; i++) {
|
||||
request = objectStore.add({});
|
||||
request.onerror = function(event) {
|
||||
is(event.code, IDBDatabaseException.ABORT_ERR, "Good code");
|
||||
is(event.target.errorCode, IDBDatabaseException.ABORT_ERR,
|
||||
"Good code");
|
||||
abortEventCount++;
|
||||
event.preventDefault();
|
||||
};
|
||||
request.onsuccess = function(event) {
|
||||
keys.push(event.result);
|
||||
keys.push(event.target.result);
|
||||
if (keys.length == 5) {
|
||||
event.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.transaction.abort();
|
||||
event.target.transaction.onabort = grabEventAndContinueHandler;
|
||||
event.target.transaction.abort();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -237,7 +238,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
is(event.result, undefined, "Object was removed by abort");
|
||||
is(event.target.result, undefined, "Object was removed by abort");
|
||||
}
|
||||
|
||||
finishTest();
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
db.setVersion("1").onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
event.transaction.oncomplete = continueToNextStep;
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
|
||||
db.createObjectStore("foo", { autoIncrement: true });
|
||||
yield;
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
db.onerror = errorHandler;
|
||||
|
||||
db.setVersion("1").onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
event.transaction.oncomplete = continueToNextStep;
|
||||
event.target.transaction.oncomplete = continueToNextStep;
|
||||
db.createObjectStore("foo");
|
||||
yield;
|
||||
|
||||
|
|
|
@ -26,14 +26,14 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
let db = event.result;
|
||||
let db = event.target.result;
|
||||
|
||||
request = db.setVersion("1");
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = grabEventAndContinueHandler;
|
||||
let event = yield;
|
||||
|
||||
is(event.transaction.mode, VERSION_CHANGE, "Correct mode");
|
||||
is(event.target.transaction.mode, VERSION_CHANGE, "Correct mode");
|
||||
|
||||
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
|||
request.onsuccess = grabEventAndContinueHandler;
|
||||
event = yield;
|
||||
|
||||
let key = event.result;
|
||||
let key = event.target.result;
|
||||
ok(key, "Got a key");
|
||||
|
||||
SimpleTest.executeSoon(function() { testGenerator.next(); });
|
||||
|
@ -69,7 +69,7 @@
|
|||
request = db.transaction("foo").objectStore("foo").get(key);
|
||||
request.onerror = errorHandler;
|
||||
request.onsuccess = function(event) {
|
||||
is(event.transaction.mode, READ_ONLY, "Correct mode");
|
||||
is(event.target.transaction.mode, READ_ONLY, "Correct mode");
|
||||
callbackCount++;
|
||||
if (callbackCount == 100) {
|
||||
request = db.transaction("foo", READ_WRITE)
|
||||
|
@ -79,7 +79,7 @@
|
|||
request.onsuccess = function(event) {
|
||||
continueReading = false;
|
||||
finalCallbackCount = callbackCount;
|
||||
is(event.result, callbackCount,
|
||||
is(event.target.result, callbackCount,
|
||||
"write callback came before later reads");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
try {
|
||||
let request = mozIndexedDB.open(window.location.pathname);
|
||||
request.onsuccess = function(event) {
|
||||
report(!!(event.result instanceof IDBDatabase));
|
||||
report(!!(event.target.result instanceof IDBDatabase));
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
|
|
@ -468,15 +468,11 @@ members = [
|
|||
'nsIIDBCursor.*',
|
||||
'nsIIDBDatabase.*',
|
||||
'nsIIDBDatabaseException.*',
|
||||
'nsIIDBEvent.*',
|
||||
'nsIIDBErrorEvent.*',
|
||||
'nsIIDBIndex.*',
|
||||
'nsIIDBKeyRange.*',
|
||||
'nsIIDBObjectStore.*',
|
||||
'nsIIDBRequest.*',
|
||||
'nsIIDBSuccessEvent.*',
|
||||
'nsIIDBTransaction.*',
|
||||
'nsIIDBTransactionEvent.*',
|
||||
'nsIIDBFactory.*',
|
||||
'nsIIDBVersionChangeEvent.*',
|
||||
'nsIIDBVersionChangeRequest.*',
|
||||
|
|
Загрузка…
Ссылка в новой задаче