зеркало из https://github.com/mozilla/pjs.git
Bug 710380 - IndexedDB could use the dictionary reader, r=khuey
This commit is contained in:
Родитель
5176f15c93
Коммит
20ec9c27ca
|
@ -60,6 +60,7 @@
|
|||
#include "IndexedDatabaseManager.h"
|
||||
#include "LazyIdleThread.h"
|
||||
#include "TransactionThreadPool.h"
|
||||
#include "DictionaryHelpers.h"
|
||||
|
||||
USING_INDEXEDDB_NAMESPACE
|
||||
|
||||
|
@ -386,27 +387,17 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
|
|||
|
||||
DatabaseInfo* databaseInfo = transaction->DBInfo();
|
||||
|
||||
mozilla::dom::IDBObjectStoreParameters params;
|
||||
nsString keyPath;
|
||||
keyPath.SetIsVoid(true);
|
||||
nsTArray<nsString> keyPathArray;
|
||||
bool autoIncrement = false;
|
||||
|
||||
if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
|
||||
if (JSVAL_IS_PRIMITIVE(aOptions)) {
|
||||
// XXX This isn't the right error
|
||||
return NS_ERROR_DOM_TYPE_ERR;
|
||||
}
|
||||
|
||||
NS_ASSERTION(JSVAL_IS_OBJECT(aOptions), "Huh?!");
|
||||
JSObject* options = JSVAL_TO_OBJECT(aOptions);
|
||||
nsresult rv = params.Init(aCx, &aOptions);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Get keyPath
|
||||
jsval val;
|
||||
if (!JS_GetPropertyById(aCx, options, nsDOMClassInfo::sKeyPath_id, &val)) {
|
||||
NS_WARNING("JS_GetPropertyById failed!");
|
||||
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
||||
}
|
||||
|
||||
jsval val = params.keyPath;
|
||||
if (!JSVAL_IS_VOID(val) && !JSVAL_IS_NULL(val)) {
|
||||
if (!JSVAL_IS_PRIMITIVE(val) &&
|
||||
JS_IsArrayObject(aCx, JSVAL_TO_OBJECT(val))) {
|
||||
|
@ -458,26 +449,13 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
|
|||
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)) {
|
||||
return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
|
||||
}
|
||||
|
||||
if (autoIncrement &&
|
||||
if (params.autoIncrement &&
|
||||
((!keyPath.IsVoid() && keyPath.IsEmpty()) || !keyPathArray.IsEmpty())) {
|
||||
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
||||
}
|
||||
|
@ -488,7 +466,7 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
|
|||
newInfo->id = databaseInfo->nextObjectStoreId++;
|
||||
newInfo->keyPath = keyPath;
|
||||
newInfo->keyPathArray = keyPathArray;
|
||||
newInfo->nextAutoIncrementId = autoIncrement ? 1 : 0;
|
||||
newInfo->nextAutoIncrementId = params.autoIncrement ? 1 : 0;
|
||||
newInfo->comittedAutoIncrementId = newInfo->nextAutoIncrementId;
|
||||
|
||||
if (!databaseInfo->PutObjectStore(newInfo)) {
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#include "IDBKeyRange.h"
|
||||
#include "IDBTransaction.h"
|
||||
#include "DatabaseInfo.h"
|
||||
#include "DictionaryHelpers.h"
|
||||
|
||||
#define FILE_COPY_BUFFER_SIZE 32768
|
||||
|
||||
|
@ -1775,45 +1776,15 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
|
|||
|
||||
NS_ASSERTION(mTransaction->IsOpen(), "Impossible!");
|
||||
|
||||
bool unique = false;
|
||||
bool multiEntry = false;
|
||||
mozilla::dom::IDBIndexParameters params;
|
||||
|
||||
// Get optional arguments.
|
||||
if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
|
||||
if (JSVAL_IS_PRIMITIVE(aOptions)) {
|
||||
// XXX Update spec for a real code here
|
||||
return NS_ERROR_DOM_TYPE_ERR;
|
||||
nsresult rv = params.Init(aCx, &aOptions);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1824,8 +1795,8 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
|
|||
indexInfo->name = aName;
|
||||
indexInfo->keyPath = keyPath;
|
||||
indexInfo->keyPathArray.SwapElements(keyPathArray);
|
||||
indexInfo->unique = unique;
|
||||
indexInfo->multiEntry = multiEntry;
|
||||
indexInfo->unique = params.unique;
|
||||
indexInfo->multiEntry = params.multiEntry;
|
||||
|
||||
// Don't leave this in the list if we fail below!
|
||||
AutoRemoveIndex autoRemove(mInfo, aName);
|
||||
|
|
|
@ -45,6 +45,13 @@ interface nsIIDBTransaction;
|
|||
interface nsIDOMDOMStringList;
|
||||
interface nsIDOMEventListener;
|
||||
|
||||
[scriptable, uuid(fb143548-08d1-43b4-95f2-a1cd58f8db76)]
|
||||
interface nsIIDBObjectStoreParameters : nsISupports
|
||||
{
|
||||
attribute jsval keyPath;
|
||||
attribute boolean autoIncrement;
|
||||
};
|
||||
|
||||
/**
|
||||
* IDBDatabase interface. See
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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]
|
||||
nsIIDBObjectStore
|
||||
createObjectStore([Null(Stringify)] in DOMString name,
|
||||
/* nsIIDBObjectStoreParameters */
|
||||
[optional /* none */] in jsval options);
|
||||
|
||||
void
|
||||
|
|
|
@ -45,6 +45,13 @@ interface nsIIDBRequest;
|
|||
interface nsIIDBTransaction;
|
||||
interface nsIDOMDOMStringList;
|
||||
|
||||
[scriptable, uuid(450e02fd-a87a-47d4-beaf-321417dad781)]
|
||||
interface nsIIDBIndexParameters : nsISupports
|
||||
{
|
||||
attribute boolean unique;
|
||||
attribute boolean multiEntry;
|
||||
};
|
||||
|
||||
/**
|
||||
* nsIIDBObjectStore interface. See
|
||||
* http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-nsIIDBObjectStore
|
||||
|
@ -103,16 +110,11 @@ interface nsIIDBObjectStore : nsISupports
|
|||
openCursor([optional /* null */] in jsval range,
|
||||
[optional /* NEXT */] in unsigned short direction);
|
||||
|
||||
/**
|
||||
* Optional arguments:
|
||||
* - unique (boolean):
|
||||
* Specifies whether values in the index must be unique. Defaults to
|
||||
* false.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
nsIIDBIndex
|
||||
createIndex([Null(Stringify)] in DOMString name,
|
||||
in jsval keyPath,
|
||||
/* nsIIDBIndexParameters */
|
||||
[optional /* none */] in jsval options);
|
||||
|
||||
// Returns object immediately
|
||||
|
|
|
@ -7,7 +7,9 @@ dictionaries = [
|
|||
[ 'nsIPageTransitionEventInit', 'nsIDOMPageTransitionEvent.idl' ],
|
||||
[ 'nsICloseEventInit', 'nsIDOMCloseEvent.idl' ],
|
||||
[ 'nsIUIEventInit', 'nsIDOMUIEvent.idl' ],
|
||||
[ 'nsIMouseEventInit', 'nsIDOMMouseEvent.idl' ]
|
||||
[ 'nsIMouseEventInit', 'nsIDOMMouseEvent.idl' ],
|
||||
[ 'nsIIDBObjectStoreParameters', 'nsIIDBDatabase.idl' ],
|
||||
[ 'nsIIDBIndexParameters', 'nsIIDBObjectStore.idl' ]
|
||||
]
|
||||
|
||||
# include file names
|
||||
|
|
Загрузка…
Ссылка в новой задаче