Bug 710380 - IndexedDB could use the dictionary reader, r=khuey

This commit is contained in:
Olli Pettay 2011-12-27 20:01:28 +02:00
Родитель 5176f15c93
Коммит 20ec9c27ca
5 изменённых файлов: 33 добавлений и 80 удалений

Просмотреть файл

@ -60,6 +60,7 @@
#include "IndexedDatabaseManager.h" #include "IndexedDatabaseManager.h"
#include "LazyIdleThread.h" #include "LazyIdleThread.h"
#include "TransactionThreadPool.h" #include "TransactionThreadPool.h"
#include "DictionaryHelpers.h"
USING_INDEXEDDB_NAMESPACE USING_INDEXEDDB_NAMESPACE
@ -386,27 +387,17 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
DatabaseInfo* databaseInfo = transaction->DBInfo(); DatabaseInfo* databaseInfo = transaction->DBInfo();
mozilla::dom::IDBObjectStoreParameters params;
nsString keyPath; nsString keyPath;
keyPath.SetIsVoid(true); keyPath.SetIsVoid(true);
nsTArray<nsString> keyPathArray; nsTArray<nsString> keyPathArray;
bool autoIncrement = false;
if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) { if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
if (JSVAL_IS_PRIMITIVE(aOptions)) { nsresult rv = params.Init(aCx, &aOptions);
// XXX This isn't the right error NS_ENSURE_SUCCESS(rv, rv);
return NS_ERROR_DOM_TYPE_ERR;
}
NS_ASSERTION(JSVAL_IS_OBJECT(aOptions), "Huh?!");
JSObject* options = JSVAL_TO_OBJECT(aOptions);
// Get keyPath // Get keyPath
jsval val; jsval val = params.keyPath;
if (!JS_GetPropertyById(aCx, options, nsDOMClassInfo::sKeyPath_id, &val)) {
NS_WARNING("JS_GetPropertyById failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
if (!JSVAL_IS_VOID(val) && !JSVAL_IS_NULL(val)) { if (!JSVAL_IS_VOID(val) && !JSVAL_IS_NULL(val)) {
if (!JSVAL_IS_PRIMITIVE(val) && if (!JSVAL_IS_PRIMITIVE(val) &&
JS_IsArrayObject(aCx, JSVAL_TO_OBJECT(val))) { JS_IsArrayObject(aCx, JSVAL_TO_OBJECT(val))) {
@ -458,26 +449,13 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
keyPath = str; keyPath = str;
} }
} }
if (!JS_GetPropertyById(aCx, options, nsDOMClassInfo::sAutoIncrement_id,
&val)) {
NS_WARNING("JS_GetPropertyById failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
JSBool boolVal;
if (!JS_ValueToBoolean(aCx, val, &boolVal)) {
NS_WARNING("JS_ValueToBoolean failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
autoIncrement = !!boolVal;
} }
if (databaseInfo->ContainsStoreName(aName)) { if (databaseInfo->ContainsStoreName(aName)) {
return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR; return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
} }
if (autoIncrement && if (params.autoIncrement &&
((!keyPath.IsVoid() && keyPath.IsEmpty()) || !keyPathArray.IsEmpty())) { ((!keyPath.IsVoid() && keyPath.IsEmpty()) || !keyPathArray.IsEmpty())) {
return NS_ERROR_DOM_INVALID_ACCESS_ERR; return NS_ERROR_DOM_INVALID_ACCESS_ERR;
} }
@ -488,7 +466,7 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
newInfo->id = databaseInfo->nextObjectStoreId++; newInfo->id = databaseInfo->nextObjectStoreId++;
newInfo->keyPath = keyPath; newInfo->keyPath = keyPath;
newInfo->keyPathArray = keyPathArray; newInfo->keyPathArray = keyPathArray;
newInfo->nextAutoIncrementId = autoIncrement ? 1 : 0; newInfo->nextAutoIncrementId = params.autoIncrement ? 1 : 0;
newInfo->comittedAutoIncrementId = newInfo->nextAutoIncrementId; newInfo->comittedAutoIncrementId = newInfo->nextAutoIncrementId;
if (!databaseInfo->PutObjectStore(newInfo)) { if (!databaseInfo->PutObjectStore(newInfo)) {

Просмотреть файл

@ -64,6 +64,7 @@
#include "IDBKeyRange.h" #include "IDBKeyRange.h"
#include "IDBTransaction.h" #include "IDBTransaction.h"
#include "DatabaseInfo.h" #include "DatabaseInfo.h"
#include "DictionaryHelpers.h"
#define FILE_COPY_BUFFER_SIZE 32768 #define FILE_COPY_BUFFER_SIZE 32768
@ -1775,45 +1776,15 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
NS_ASSERTION(mTransaction->IsOpen(), "Impossible!"); NS_ASSERTION(mTransaction->IsOpen(), "Impossible!");
bool unique = false; mozilla::dom::IDBIndexParameters params;
bool multiEntry = false;
// Get optional arguments. // Get optional arguments.
if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) { if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
if (JSVAL_IS_PRIMITIVE(aOptions)) { nsresult rv = params.Init(aCx, &aOptions);
// XXX Update spec for a real code here NS_ENSURE_SUCCESS(rv, rv);
return NS_ERROR_DOM_TYPE_ERR;
}
NS_ASSERTION(JSVAL_IS_OBJECT(aOptions), "Huh?!");
JSObject* options = JSVAL_TO_OBJECT(aOptions);
jsval val;
if (!JS_GetPropertyById(aCx, options, nsDOMClassInfo::sUnique_id, &val)) {
NS_WARNING("JS_GetPropertyById failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
JSBool boolVal;
if (!JS_ValueToBoolean(aCx, val, &boolVal)) {
NS_WARNING("JS_ValueToBoolean failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
unique = !!boolVal;
if (!JS_GetPropertyById(aCx, options, nsDOMClassInfo::sMultiEntry_id, &val)) {
NS_WARNING("JS_GetPropertyById failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
if (!JS_ValueToBoolean(aCx, val, &boolVal)) {
NS_WARNING("JS_ValueToBoolean failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
multiEntry = !!boolVal;
} }
if (multiEntry && !keyPathArray.IsEmpty()) { if (params.multiEntry && !keyPathArray.IsEmpty()) {
return NS_ERROR_DOM_NOT_SUPPORTED_ERR; return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
} }
@ -1824,8 +1795,8 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
indexInfo->name = aName; indexInfo->name = aName;
indexInfo->keyPath = keyPath; indexInfo->keyPath = keyPath;
indexInfo->keyPathArray.SwapElements(keyPathArray); indexInfo->keyPathArray.SwapElements(keyPathArray);
indexInfo->unique = unique; indexInfo->unique = params.unique;
indexInfo->multiEntry = multiEntry; indexInfo->multiEntry = params.multiEntry;
// Don't leave this in the list if we fail below! // Don't leave this in the list if we fail below!
AutoRemoveIndex autoRemove(mInfo, aName); AutoRemoveIndex autoRemove(mInfo, aName);

Просмотреть файл

@ -45,6 +45,13 @@ interface nsIIDBTransaction;
interface nsIDOMDOMStringList; interface nsIDOMDOMStringList;
interface nsIDOMEventListener; interface nsIDOMEventListener;
[scriptable, uuid(fb143548-08d1-43b4-95f2-a1cd58f8db76)]
interface nsIIDBObjectStoreParameters : nsISupports
{
attribute jsval keyPath;
attribute boolean autoIncrement;
};
/** /**
* IDBDatabase interface. See * IDBDatabase interface. See
* http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBDatabase * http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBDatabase
@ -59,17 +66,10 @@ interface nsIIDBDatabase : nsISupports
readonly attribute nsIDOMDOMStringList objectStoreNames; readonly attribute nsIDOMDOMStringList objectStoreNames;
/**
* Optional arguments:
* - keyPath (string):
* Specifies key path on objects in the objectStore. Defaults to no key
* path.
* - autoIncrement (boolean):
* Specifies if the objectStore has a key generator. Defaults to false.
*/
[implicit_jscontext] [implicit_jscontext]
nsIIDBObjectStore nsIIDBObjectStore
createObjectStore([Null(Stringify)] in DOMString name, createObjectStore([Null(Stringify)] in DOMString name,
/* nsIIDBObjectStoreParameters */
[optional /* none */] in jsval options); [optional /* none */] in jsval options);
void void

Просмотреть файл

@ -45,6 +45,13 @@ interface nsIIDBRequest;
interface nsIIDBTransaction; interface nsIIDBTransaction;
interface nsIDOMDOMStringList; interface nsIDOMDOMStringList;
[scriptable, uuid(450e02fd-a87a-47d4-beaf-321417dad781)]
interface nsIIDBIndexParameters : nsISupports
{
attribute boolean unique;
attribute boolean multiEntry;
};
/** /**
* nsIIDBObjectStore interface. See * nsIIDBObjectStore interface. See
* http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-nsIIDBObjectStore * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-nsIIDBObjectStore
@ -103,16 +110,11 @@ interface nsIIDBObjectStore : nsISupports
openCursor([optional /* null */] in jsval range, openCursor([optional /* null */] in jsval range,
[optional /* NEXT */] in unsigned short direction); [optional /* NEXT */] in unsigned short direction);
/**
* Optional arguments:
* - unique (boolean):
* Specifies whether values in the index must be unique. Defaults to
* false.
*/
[implicit_jscontext] [implicit_jscontext]
nsIIDBIndex nsIIDBIndex
createIndex([Null(Stringify)] in DOMString name, createIndex([Null(Stringify)] in DOMString name,
in jsval keyPath, in jsval keyPath,
/* nsIIDBIndexParameters */
[optional /* none */] in jsval options); [optional /* none */] in jsval options);
// Returns object immediately // Returns object immediately

Просмотреть файл

@ -7,7 +7,9 @@ dictionaries = [
[ 'nsIPageTransitionEventInit', 'nsIDOMPageTransitionEvent.idl' ], [ 'nsIPageTransitionEventInit', 'nsIDOMPageTransitionEvent.idl' ],
[ 'nsICloseEventInit', 'nsIDOMCloseEvent.idl' ], [ 'nsICloseEventInit', 'nsIDOMCloseEvent.idl' ],
[ 'nsIUIEventInit', 'nsIDOMUIEvent.idl' ], [ 'nsIUIEventInit', 'nsIDOMUIEvent.idl' ],
[ 'nsIMouseEventInit', 'nsIDOMMouseEvent.idl' ] [ 'nsIMouseEventInit', 'nsIDOMMouseEvent.idl' ],
[ 'nsIIDBObjectStoreParameters', 'nsIIDBDatabase.idl' ],
[ 'nsIIDBIndexParameters', 'nsIIDBObjectStore.idl' ]
] ]
# include file names # include file names