Bug 618141 - 'IndexedDB: createObjectStore and createIndex should accept an optional object argument'. r=sicking, a=blocking.

This commit is contained in:
Ben Turner 2010-12-21 11:02:01 -05:00
Родитель e6f0c4526c
Коммит 60f0977f47
45 изменённых файлов: 304 добавлений и 153 удалений

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

@ -1636,6 +1636,9 @@ jsid nsDOMClassInfo::sOnbeforescriptexecute_id = JSID_VOID;
jsid nsDOMClassInfo::sOnafterscriptexecute_id = JSID_VOID;
jsid nsDOMClassInfo::sWrappedJSObject_id = JSID_VOID;
jsid nsDOMClassInfo::sURL_id = JSID_VOID;
jsid nsDOMClassInfo::sKeyPath_id = JSID_VOID;
jsid nsDOMClassInfo::sAutoIncrement_id = JSID_VOID;
jsid nsDOMClassInfo::sUnique_id = JSID_VOID;
static const JSClass *sObjectClass = nsnull;
@ -1866,6 +1869,9 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
#endif // MOZ_MEDIA
SET_JSID_TO_STRING(sWrappedJSObject_id, cx, "wrappedJSObject");
SET_JSID_TO_STRING(sURL_id, cx, "URL");
SET_JSID_TO_STRING(sKeyPath_id, cx, "keyPath");
SET_JSID_TO_STRING(sAutoIncrement_id, cx, "autoIncrement");
SET_JSID_TO_STRING(sUnique_id, cx, "unique");
return NS_OK;
}
@ -4927,6 +4933,9 @@ nsDOMClassInfo::ShutDown()
sOnbeforescriptexecute_id = JSID_VOID;
sOnafterscriptexecute_id = JSID_VOID;
sWrappedJSObject_id = JSID_VOID;
sKeyPath_id = JSID_VOID;
sAutoIncrement_id = JSID_VOID;
sUnique_id = JSID_VOID;
NS_IF_RELEASE(sXPConnect);
NS_IF_RELEASE(sSecMan);

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

@ -282,6 +282,7 @@ protected:
static PRBool sDisableDocumentAllSupport;
static PRBool sDisableGlobalScopePollutionSupport;
public:
static jsid sTop_id;
static jsid sParent_id;
static jsid sScrollbars_id;
@ -391,7 +392,11 @@ protected:
static jsid sOnafterscriptexecute_id;
static jsid sWrappedJSObject_id;
static jsid sURL_id;
static jsid sKeyPath_id;
static jsid sAutoIncrement_id;
static jsid sUnique_id;
protected:
static JSPropertyOp sXPCNativeWrapperGetPropertyOp;
static JSPropertyOp sXrayWrapperPropertyHolderGetPropertyOp;
};

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

@ -39,10 +39,12 @@
#include "IDBDatabase.h"
#include "jscntxt.h"
#include "mozilla/Mutex.h"
#include "mozilla/storage.h"
#include "nsDOMClassInfo.h"
#include "nsEventDispatcher.h"
#include "nsJSUtils.h"
#include "nsProxyRelease.h"
#include "nsThreadUtils.h"
@ -523,8 +525,8 @@ IDBDatabase::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores)
NS_IMETHODIMP
IDBDatabase::CreateObjectStore(const nsAString& aName,
const nsAString& aKeyPath,
PRBool aAutoIncrement,
const jsval& aOptions,
JSContext* aCx,
nsIIDBObjectStore** _retval)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@ -534,12 +536,6 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR;
}
// XPConnect makes "null" into a void string, we need an empty string.
nsString keyPath(aKeyPath);
if (keyPath.IsVoid()) {
keyPath.Truncate();
}
IDBTransaction* transaction = AsyncConnectionHelper::GetCurrentTransaction();
if (!transaction ||
@ -556,12 +552,66 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
}
nsString keyPath;
bool autoIncrement = false;
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_INDEXEDDB_NON_TRANSIENT_ERR;
}
NS_ASSERTION(JSVAL_IS_OBJECT(aOptions), "Huh?!");
JSObject* options = JSVAL_TO_OBJECT(aOptions);
js::AutoIdArray ids(aCx, JS_Enumerate(aCx, options));
if (!ids) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
for (size_t index = 0; index < ids.length(); index++) {
jsid id = ids[index];
if (id != nsDOMClassInfo::sKeyPath_id &&
id != nsDOMClassInfo::sAutoIncrement_id) {
// XXX Update spec for a real code here
return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR;
}
jsval val;
if (!JS_GetPropertyById(aCx, options, id, &val)) {
NS_WARNING("JS_GetPropertyById failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
if (id == nsDOMClassInfo::sKeyPath_id) {
JSString* str = JS_ValueToString(aCx, val);
if (!str) {
NS_WARNING("JS_ValueToString failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
keyPath = nsDependentJSString(str);
}
else if (id == nsDOMClassInfo::sAutoIncrement_id) {
JSBool boolVal;
if (!JS_ValueToBoolean(aCx, val, &boolVal)) {
NS_WARNING("JS_ValueToBoolean failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
autoIncrement = !!boolVal;
}
else {
NS_NOTREACHED("Shouldn't be able to get here!");
}
}
}
nsAutoPtr<ObjectStoreInfo> newInfo(new ObjectStoreInfo());
newInfo->name = aName;
newInfo->id = databaseInfo->nextObjectStoreId++;
newInfo->keyPath = keyPath;
newInfo->autoIncrement = aAutoIncrement;
newInfo->autoIncrement = autoIncrement;
newInfo->databaseId = mDatabaseId;
if (!ObjectStoreInfo::Put(newInfo)) {

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

@ -1192,7 +1192,8 @@ IDBObjectStore::OpenCursor(nsIIDBKeyRange* aKeyRange,
NS_IMETHODIMP
IDBObjectStore::CreateIndex(const nsAString& aName,
const nsAString& aKeyPath,
PRBool aUnique,
const jsval& aOptions,
JSContext* aCx,
nsIIDBIndex** _retval)
{
NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!");
@ -1229,6 +1230,51 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
NS_ASSERTION(mTransaction->IsOpen(), "Impossible!");
bool unique = false;
// 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_INDEXEDDB_NON_TRANSIENT_ERR;
}
NS_ASSERTION(JSVAL_IS_OBJECT(aOptions), "Huh?!");
JSObject* options = JSVAL_TO_OBJECT(aOptions);
js::AutoIdArray ids(aCx, JS_Enumerate(aCx, options));
if (!ids) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
for (size_t index = 0; index < ids.length(); index++) {
jsid id = ids[index];
if (id != nsDOMClassInfo::sUnique_id) {
// XXX Update spec for a real code here
return NS_ERROR_DOM_INDEXEDDB_NON_TRANSIENT_ERR;
}
jsval val;
if (!JS_GetPropertyById(aCx, options, id, &val)) {
NS_WARNING("JS_GetPropertyById failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
if (id == nsDOMClassInfo::sUnique_id) {
JSBool boolVal;
if (!JS_ValueToBoolean(aCx, val, &boolVal)) {
NS_WARNING("JS_ValueToBoolean failed!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
unique = !!boolVal;
}
else {
NS_NOTREACHED("Shouldn't be able to get here!");
}
}
}
DatabaseInfo* databaseInfo;
if (!DatabaseInfo::Get(mTransaction->Database()->Id(), &databaseInfo)) {
NS_ERROR("This should never fail!");
@ -1243,7 +1289,7 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
indexInfo->id = databaseInfo->nextIndexId++;
indexInfo->name = aName;
indexInfo->keyPath = aKeyPath;
indexInfo->unique = aUnique;
indexInfo->unique = unique;
indexInfo->autoIncrement = mAutoIncrement;
// Don't leave this in the list if we fail below!

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

@ -55,7 +55,7 @@ interface nsIDOMEventListener;
* http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBDatabase
* for more information.
*/
[scriptable, uuid(6563ebdc-4509-4aeb-ac14-7e78ad74e2d3)]
[scriptable, uuid(42b38d02-1a29-45f0-99ef-04fd5b441270)]
interface nsIIDBDatabase : nsISupports
{
readonly attribute DOMString name;
@ -64,10 +64,18 @@ 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(in AString name,
[optional /* none */] in AString keyPath,
[optional /* false */] in boolean autoIncrement);
[optional /* none */] in jsval options);
void
deleteObjectStore(in AString name);

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

@ -55,7 +55,7 @@ interface nsIDOMDOMStringList;
* http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-nsIIDBObjectStore
* for more information.
*/
[scriptable, uuid(64f34805-d3e3-4305-91f8-b2cafac3d33c)]
[scriptable, uuid(6a65dc92-66e3-407a-a370-590a6c54664a)]
interface nsIIDBObjectStore : nsISupports
{
readonly attribute DOMString name;
@ -104,11 +104,17 @@ interface nsIIDBObjectStore : nsISupports
openCursor([optional /* null */] in nsIIDBKeyRange range,
[optional /* NEXT */] in unsigned short direction);
// Returns object immediately
/**
* Optional arguments:
* - unique (boolean):
* Specifies whether values in the index must be unique. Defaults to
* false.
*/
[implicit_jscontext]
nsIIDBIndex
createIndex(in AString name,
in AString keyPath,
[optional /* false */] in boolean unique);
[optional /* none */] in jsval options);
// Returns object immediately
nsIIDBIndex

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

@ -13,7 +13,7 @@ moz_indexedDB.open(parent.location).onsuccess = function(e) {
if (db.objectStoreNames.contains("mystore")) {
db.deleteObjectStore("mystore");
}
var store = db.createObjectStore("mystore", "");
var store = db.createObjectStore("mystore");
store.add({ hello: "world" }, 42);
trans.oncomplete = function() {
parent.postMessage("go", "http://mochi.test:8888");

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

@ -67,7 +67,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
db.createObjectStore("foo", "", true);
db.createObjectStore("foo", { autoIncrement: true });
setTimeout(testFinishedCallback, 0, "ready");
yield;

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

@ -77,7 +77,7 @@
is(db.version, "1", "Correct version");
is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
let objectStore = db.createObjectStore("foo", "");
let objectStore = db.createObjectStore("foo");
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
ok(db.objectStoreNames.contains("foo"), "Has correct objectStore");
@ -110,7 +110,7 @@
is(db.version, "1", "Correct version");
is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
let objectStore = db.createObjectStore("foo", "");
let objectStore = db.createObjectStore("foo");
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
ok(db.objectStoreNames.contains("foo"), "Has correct objectStore");

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

@ -111,7 +111,7 @@
event.transaction.oncomplete = grabEventAndContinueHandler;
db.createObjectStore("foo", "", true);
db.createObjectStore("foo", { autoIncrement: true });
yield;
let transaction = db.transaction("foo", IDBTransaction.READ_WRITE);

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

@ -82,7 +82,7 @@
is(db.version, "1", "Correct version");
is(db.objectStoreNames.length, 0, "Correct objectStoreNames length");
let objectStore = db.createObjectStore("foo", "");
let objectStore = db.createObjectStore("foo");
is(db.objectStoreNames.length, 1, "Correct objectStoreNames length");
ok(db.objectStoreNames.contains("foo"), "Has correct objectStore");

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

@ -28,7 +28,7 @@
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let objectStore = db.createObjectStore("foo", "");
let objectStore = db.createObjectStore("foo", { keyPath: "" });
let key = 10;
request = objectStore.add({}, key);

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

@ -28,7 +28,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore("foo", "keyPath");
let objectStore = db.createObjectStore("foo", { keyPath: "keyPath" });
request = objectStore.add({keyPath:"foo"});
request.onerror = errorHandler;

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

@ -33,7 +33,7 @@
event.transaction.oncomplete = continueToNextStep;
let objectStore = db.createObjectStore("foo", "", true);
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
let firstKey;
for (let i = 0; i < entryCount; i++) {

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

@ -19,13 +19,13 @@
const name = window.location.pathname;
const description = "My Test Database";
const objectStoreInfo = [
{ name: "a", keyPath: "id", autoIncrement: true },
{ name: "b", keyPath: "id", autoIncrement: false },
{ name: "a", options: { keyPath: "id", autoIncrement: true } },
{ name: "b", options: { keyPath: "id", autoIncrement: false } },
];
const indexInfo = [
{ name: "1", keyPath: "unique_value", unique: true },
{ name: "2", keyPath: "value", unique: false },
{ name: "3", keyPath: "value" },
{ name: "1", keyPath: "unique_value", options: { unique: true } },
{ name: "2", keyPath: "value", options: { unique: false } },
{ name: "3", keyPath: "value", options: { unique: false } },
];
let request = moz_indexedDB.open(name, description);
@ -41,10 +41,9 @@
for (let i = 0; i < objectStoreInfo.length; i++) {
let info = objectStoreInfo[i];
let objectStore = info.hasOwnProperty("autoIncrement") ?
db.createObjectStore(info.name, info.keyPath,
info.autoIncrement) :
db.createObjectStore(info.name, info.keyPath);
let objectStore = info.hasOwnProperty("options") ?
db.createObjectStore(info.name, info.options) :
db.createObjectStore(info.name);
// Test basic failure conditions.
try {
@ -71,19 +70,35 @@
ok(true, "createIndex with no keyPath should throw");
}
try {
request = objectStore.createIndex("foo", "bar", 10);
ok(false, "createIndex with bad options should throw");
}
catch(e) {
ok(true, "createIndex with bad options threw");
}
try {
request = objectStore.createIndex("foo", "bar", { foo: "" });
ok(false, "createIndex with bad options should throw");
}
catch(e) {
ok(true, "createIndex with bad options threw");
}
// Test index creation, and that it ends up in indexNames.
let objectStoreName = info.name;
for (let j = 0; j < indexInfo.length; j++) {
let info = indexInfo[j];
let count = objectStore.indexNames.length;
let index = info.hasOwnProperty("unique") ?
let index = info.hasOwnProperty("options") ?
objectStore.createIndex(info.name, info.keyPath,
info.unique) :
info.options) :
objectStore.createIndex(info.name, info.keyPath);
is(index.name, info.name, "correct name");
is(index.keyPath, info.keyPath, "correct keyPath");
is(index.unique, !!info.unique, "correct uniqueness");
is(index.unique, info.options.unique, "correct uniqueness");
is(objectStore.indexNames.length, count + 1,
"indexNames grew in size");

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

@ -19,15 +19,17 @@
const name = window.location.pathname;
const description = "My Test Database";
const objectStoreInfo = [
{ name: "1", keyPath: "" },
{ name: "2", keyPath: "", autoIncrement: true },
{ name: "3", keyPath: "", autoIncrement: false },
{ name: "4", keyPath: "" },
{ name: "5", keyPath: null },
{ name: "6", keyPath: "foo" },
{ name: "7" },
{ name: "8", autoIncrement: true },
{ name: "9", autoIncrement: false }
{ name: "1", options: { keyPath: "" } },
{ name: "2", options: { keyPath: "", autoIncrement: true } },
{ name: "3", options: { keyPath: "", autoIncrement: false } },
{ name: "4", options: { keyPath: "" } },
{ name: "5", options: { keyPath: "foo" } },
{ name: "6" },
{ name: "7", options: null },
{ name: "8", options: { autoIncrement: true } },
{ name: "9", options: { autoIncrement: false } },
{ name: "10", options: { keyPath: "foo", autoIncrement: false } },
{ name: "11", options: { keyPath: "foo", autoIncrement: true } }
];
let request = moz_indexedDB.open(name, description);
@ -64,29 +66,29 @@
ok(true, "createObjectStore with empty name should throw");
}
try {
db.createObjectStore("foo", "bar");
ok(false, "createObjectStore with bad options should throw");
}
catch(e) {
ok(true, "createObjectStore with bad options");
}
try {
db.createObjectStore("foo", { foo: "" });
ok(false, "createObjectStore with bad options should throw");
}
catch(e) {
ok(true, "createObjectStore with bad options");
}
for (let index in objectStoreInfo) {
index = parseInt(index);
const info = objectStoreInfo[index];
let objectStore;
if (info.hasOwnProperty("keyPath")) {
if (info.hasOwnProperty("autoIncrement")) {
objectStore = db.createObjectStore(info.name, info.keyPath,
info.autoIncrement);
}
else {
objectStore = db.createObjectStore(info.name, info.keyPath);
}
}
else {
if (info.hasOwnProperty("autoIncrement")) {
objectStore = db.createObjectStore(info.name, null,
info.autoIncrement);
}
else {
objectStore = db.createObjectStore(info.name);
}
}
let objectStore = info.hasOwnProperty("options") ?
db.createObjectStore(info.name, info.options) :
db.createObjectStore(info.name);
is(db.objectStoreNames.length, index + 1,
"updated objectStoreNames list");
@ -101,7 +103,8 @@
is(found, true, "objectStoreNames contains name");
is(objectStore.name, info.name, "Bad name");
is(objectStore.keyPath, info.keyPath ? info.keyPath : "",
is(objectStore.keyPath, info.options && info.options.keyPath ?
info.options.keyPath : "",
"Bad keyPath");
if(objectStore.indexNames.length, 0, "Bad indexNames");

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

@ -42,8 +42,8 @@
event.transaction.oncomplete = continueToNextStep;
let objectStore = db.createObjectStore("foo", "ss");
objectStore.createIndex("name", "name", true);
let objectStore = db.createObjectStore("foo", { keyPath: "ss" });
objectStore.createIndex("name", "name", { unique: true });
for (let i = 0; i < objectStoreData.length - 1; i++) {
objectStore.add(objectStoreData[i]);

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

@ -21,13 +21,13 @@
const START_DATA = "hi";
const END_DATA = "bye";
const objectStoreInfo = [
{ name: "1", keyPath: "", key: 1,
{ name: "1", options: { keyPath: "" }, key: 1,
entry: { data: START_DATA } },
{ name: "2", keyPath: "foo",
{ name: "2", options: { keyPath: "foo" },
entry: { foo: 1, data: START_DATA } },
{ name: "3", keyPath: "", autoIncrement: true,
{ name: "3", options: { keyPath: "", autoIncrement: true },
entry: { data: START_DATA } },
{ name: "4", keyPath: "foo", autoIncrement: true,
{ name: "4", options: { keyPath: "foo", autoIncrement: true },
entry: { data: START_DATA } },
];
@ -49,14 +49,15 @@
event = yield;
ok(true, "2");
let objectStore = info.hasOwnProperty("autoIncrement") ?
db.createObjectStore(info.name, info.keyPath,
info.autoIncrement) :
db.createObjectStore(info.name, info.keyPath);
let objectStore = info.hasOwnProperty("options") ?
db.createObjectStore(info.name, info.options) :
db.createObjectStore(info.name);
// Create the indexes on 'data' on the object store.
let index = objectStore.createIndex("data_index", "data", false);
let uniqueIndex = objectStore.createIndex("unique_data_index", "data", true);
let index = objectStore.createIndex("data_index", "data",
{ 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") ?

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

@ -32,7 +32,8 @@
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let objectStore = db.createObjectStore("autoIncrement", "", true);
let objectStore = db.createObjectStore("autoIncrement",
{ autoIncrement: true });
request = objectStore.openCursor();
request.onerror = errorHandler;
@ -42,7 +43,9 @@
}
yield;
objectStore = db.createObjectStore("autoIncrementKeyPath", "foo", true);
objectStore = db.createObjectStore("autoIncrementKeyPath",
{ keyPath: "foo",
autoIncrement: true });
request = objectStore.openCursor();
request.onerror = errorHandler;
@ -52,7 +55,7 @@
}
yield;
objectStore = db.createObjectStore("keyPath", "foo");
objectStore = db.createObjectStore("keyPath", { keyPath: "foo" });
request = objectStore.openCursor();
request.onerror = errorHandler;
@ -62,7 +65,7 @@
}
yield;
objectStore = db.createObjectStore("foo", "");
objectStore = db.createObjectStore("foo");
request = objectStore.openCursor();
request.onerror = errorHandler;

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

@ -33,7 +33,8 @@
ok(event.source === db, "correct event.source");
var objectStore = db.createObjectStore(objectStoreName, null, true);
var objectStore = db.createObjectStore(objectStoreName,
{ autoIncrement: true });
request = objectStore.add({});
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;

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

@ -30,7 +30,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore("foo", "", true);
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
request = objectStore.getAll();
request.onerror = errorHandler;

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

@ -15,7 +15,8 @@
{
const name = window.location.pathname;
const description = "My Test Database";
const objectStore = { name: "Objects", keyPath: "id", autoIncr: true };
const objectStore = { name: "Objects",
options: { keyPath: "id", autoIncrement: true } };
let request = moz_indexedDB.open(name, description);
request.onerror = errorHandler;
@ -31,8 +32,7 @@
is(db1.objectStoreNames.length, 0, "No objectStores in db1");
db1.createObjectStore(objectStore.name, objectStore.keyPath,
objectStore.autoIncr);
db1.createObjectStore(objectStore.name, objectStore.options);
continueToNextStep();
yield;
@ -55,9 +55,7 @@
let objectStore1 = db1.transaction(objectStore.name)
.objectStore(objectStore.name);
is(objectStore1.name, objectStore.name, "Same name");
is(objectStore1.keyPath, objectStore.keyPath, "Same keyPath");
is(objectStore1.autoIncrement, objectStore.autoIncrement,
"Same value for autoIncrement");
is(objectStore1.keyPath, objectStore.options.keyPath, "Same keyPath");
let objectStore2 = db2.transaction(objectStore.name)
.objectStore(objectStore.name);
@ -65,8 +63,6 @@
ok(objectStore1 !== objectStore2, "Different objectStores");
is(objectStore1.name, objectStore2.name, "Same name");
is(objectStore1.keyPath, objectStore2.keyPath, "Same keyPath");
is(objectStore1.autoIncrement, objectStore2.autoIncrement,
"Same value for autoIncrement");
finishTest();
yield;

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

@ -27,9 +27,9 @@
];
const indexData = [
{ name: "name", keyPath: "name", unique: true },
{ name: "height", keyPath: "height", unique: false },
{ name: "weight", keyPath: "weight", unique: false }
{ name: "name", keyPath: "name", options: { unique: true } },
{ name: "height", keyPath: "height", options: { unique: false } },
{ name: "weight", keyPath: "weight", options: { unique: false } }
];
const objectStoreDataNameSort = [
@ -70,7 +70,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore(objectStoreName, "");
let objectStore = db.createObjectStore(objectStoreName);
// First, add all our data to the object store.
let addedData = 0;
@ -90,7 +90,7 @@
// Now create the indexes.
for (let i in indexData) {
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
indexData[i].unique);
indexData[i].options);
}
is(objectStore.indexNames.length, indexData.length, "Good index count");

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

@ -27,9 +27,9 @@
];
const indexData = [
{ name: "name", keyPath: "name", unique: true },
{ name: "height", keyPath: "height", unique: false },
{ name: "weight", keyPath: "weight", unique: false }
{ name: "name", keyPath: "name", options: { unique: true } },
{ name: "height", keyPath: "height", options: { unique: false } },
{ name: "weight", keyPath: "weight", options: { unique: false } }
];
const objectStoreDataNameSort = [
@ -70,7 +70,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore(objectStoreName, "");
let objectStore = db.createObjectStore(objectStoreName, {});
// First, add all our data to the object store.
let addedData = 0;
@ -89,7 +89,7 @@
// Now create the indexes.
for (let i in indexData) {
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
indexData[i].unique);
indexData[i].options);
}
is(objectStore.indexNames.length, indexData.length, "Good index count");

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

@ -14,15 +14,15 @@
function testSteps()
{
const objectStoreData = [
{ name: "3", keyPath: "id", autoIncrement: true },
{ name: "1", keyPath: "ss", autoIncrement: false },
{ name: "2", keyPath: "", autoIncrement: false },
{ name: "4", keyPath: "", autoIncrement: true },
{ name: "3", options: { keyPath: "id", autoIncrement: true } },
{ name: "1", options: { keyPath: "ss" } },
{ name: "2", options: { } },
{ name: "4", options: { autoIncrement: true } },
];
const indexData = [
{ name: "name", keyPath: "name", unique: true },
{ name: "height", keyPath: "height", unique: false }
{ name: "name", keyPath: "name", options: { unique: true } },
{ name: "height", keyPath: "height", options: { } }
];
const data = [
@ -46,13 +46,12 @@
for (let objectStoreIndex in objectStoreData) {
const objectStoreInfo = objectStoreData[objectStoreIndex];
let objectStore = db.createObjectStore(objectStoreInfo.name,
objectStoreInfo.keyPath,
objectStoreInfo.autoIncrement);
objectStoreInfo.options);
for (let indexIndex in indexData) {
const indexInfo = indexData[indexIndex];
let index = objectStore.createIndex(indexInfo.name,
indexInfo.keyPath,
indexInfo.unique);
indexInfo.options);
}
}
yield;
@ -74,7 +73,7 @@
for (let dataIndex in data) {
const obj = data[dataIndex];
let key;
if (!info.keyPath && !info.autoIncrement) {
if (!info.options.keyPath && !info.options.autoIncrement) {
key = obj.ss;
}
objectStore.add(obj, key);

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

@ -38,9 +38,9 @@
];
const indexData = [
{ name: "name", keyPath: "name", unique: true },
{ name: "height", keyPath: "height", unique: false },
{ name: "weight", keyPath: "weight", unique: false }
{ name: "name", keyPath: "name", options: { unique: true } },
{ name: "height", keyPath: "height", options: { } },
{ name: "weight", keyPath: "weight", options: { unique: false } }
];
const objectStoreDataNameSort = [
@ -81,7 +81,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore(objectStoreName, "");
let objectStore = db.createObjectStore(objectStoreName, { keyPath: "" });
// First, add all our data to the object store.
let addedData = 0;
@ -100,7 +100,7 @@
// Now create the indexes.
for (let i in indexData) {
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
indexData[i].unique);
indexData[i].options);
}
is(objectStore.indexNames.length, indexData.length, "Good index count");
continueToNextStep();
@ -124,7 +124,8 @@
is(index.name, indexData[i].name, "Correct name");
is(index.storeName, objectStore.name, "Correct store name");
is(index.keyPath, indexData[i].keyPath, "Correct keyPath");
is(index.unique, indexData[i].unique, "Correct keyPath");
is(index.unique, indexData[i].options.unique ? true : false,
"Correct unique value");
}
request = objectStore.index("name").getKey("Bob");

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

@ -38,7 +38,7 @@
];
const indexData = [
{ name: "weight", keyPath: "weight", unique: false }
{ name: "weight", keyPath: "weight", options: { unique: false } }
];
const objectStoreDataWeightSort = [
@ -61,7 +61,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore(objectStoreName, "");
let objectStore = db.createObjectStore(objectStoreName, { } );
let addedData = 0;
for (let i in objectStoreData) {
@ -78,7 +78,7 @@
for (let i in indexData) {
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
indexData[i].unique);
indexData[i].options);
}
addedData = 0;

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

@ -31,7 +31,7 @@
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let objectStore = db.createObjectStore("foo", "", true);
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
request = objectStore.add({});
request.onerror = errorHandler;
@ -89,7 +89,7 @@
ok(true, "remove with no key threw");
}
objectStore = db.createObjectStore("bar", "", false);
objectStore = db.createObjectStore("bar");
try {
objectStore.add({});
@ -123,7 +123,7 @@
ok(true, "remove with no key threw");
}
objectStore = db.createObjectStore("baz", "id", false);
objectStore = db.createObjectStore("baz", { keyPath: "id" });
try {
objectStore.add({});
@ -225,7 +225,8 @@
ok(true, "remove with null key threw");
}
objectStore = db.createObjectStore("bazing", "id", true);
objectStore = db.createObjectStore("bazing", { keyPath: "id",
autoIncrement: true });
request = objectStore.add({});
request.onerror = errorHandler;

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

@ -22,8 +22,8 @@
];
const indexes = [
{ name: "a", unique: false },
{ name: "b", unique: true }
{ name: "a", options: { } },
{ name: "b", options: { unique: true } }
];
let request = moz_indexedDB.open(name, description);
@ -40,11 +40,12 @@
let event = yield;
let objectStore =
db.createObjectStore(objectStores[i].name, "id",
objectStores[i].autoIncrement);
db.createObjectStore(objectStores[i].name,
{ keyPath: "id",
autoIncrement: objectStores[i].autoIncrement });
for (let j in indexes) {
objectStore.createIndex(indexes[j].name, "name", indexes[j].unique);
objectStore.createIndex(indexes[j].name, "name", indexes[j].options);
}
let data = { name: "Ben" };

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

@ -38,8 +38,9 @@ function testSteps()
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore(test.name, test.keyName,
test.autoIncrement);
let objectStore = db.createObjectStore(test.name,
{ keyPath: test.keyName,
autoIncrement: test.autoIncrement });
request = objectStore.add(test.storedObject);
request.onerror = errorHandler;

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

@ -42,13 +42,13 @@ function testSteps()
{ name: "out of line key; key generator",
autoIncrement: true,
storedObject: {name: "Lincoln"},
keyName: null,
keyName: undefined,
keyValue: undefined,
},
{ name: "out of line key; no key generator",
autoIncrement: false,
storedObject: {name: "Lincoln"},
keyName: null,
keyName: "",
keyValue: 1,
}
];
@ -62,8 +62,9 @@ function testSteps()
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore(test.name, test.keyName,
test.autoIncrement);
let objectStore = db.createObjectStore(test.name,
{ keyPath: test.keyName,
autoIncrement: test.autoIncrement });
request = objectStore.add(test.storedObject, test.keyValue);
request.onerror = errorHandler;

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

@ -27,7 +27,7 @@
let transaction = event.transaction;
let objectStore1 = db.createObjectStore("foo", "");
let objectStore1 = db.createObjectStore("foo");
let objectStore2 = transaction.objectStore("foo");
ok(objectStore1 === objectStore2, "Got same objectStores");

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

@ -33,7 +33,8 @@
is(db.objectStoreNames.length, 0, "Bad objectStores list");
let objectStore = db.createObjectStore(objectStoreName, "foo");
let objectStore = db.createObjectStore(objectStoreName,
{ keyPath: "foo" });
is(db.objectStoreNames.length, 1, "Bad objectStores list");
is(db.objectStoreNames.item(0), objectStoreName, "Bad name");

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

@ -32,7 +32,7 @@
request.onsuccess = function(event) {
event.transaction.oncomplete = grabEventAndContinueHandler;
for (let i in objectStores) {
db.createObjectStore(objectStores[i], "", true);
db.createObjectStore(objectStores[i], { autoIncrement: true });
}
};
yield;

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

@ -32,7 +32,8 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore(objectStoreName, "", false);
let objectStore = db.createObjectStore(objectStoreName,
{ autoIncrement: 0 });
request = objectStore.add(testString.value, testString.key);
request.onerror = errorHandler;

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

@ -32,7 +32,8 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore(objectStoreName, "", true);
let objectStore = db.createObjectStore(objectStoreName,
{ autoIncrement: 1 });
request = objectStore.add(testString.value);
request.onerror = errorHandler;

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

@ -33,7 +33,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
db.createObjectStore(osName, "", true);
db.createObjectStore(osName, { autoIncrement: "true" });
let key1, key2;

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

@ -32,7 +32,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore("test store", "foo");
let objectStore = db.createObjectStore("test store", { keyPath: "foo" });
is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
is(db.objectStoreNames.item(0), objectStore.name, "Correct name");

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

@ -34,7 +34,8 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore(objectStoreName, "foo");
let objectStore = db.createObjectStore(objectStoreName,
{ keyPath: "foo" });
let addedCount = 0;
@ -60,7 +61,7 @@
db.deleteObjectStore(objectStore.name);
is(db.objectStoreNames.length, 0, "Correct objectStores list");
objectStore = db.createObjectStore(objectStoreName, "foo");
objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
is(db.objectStoreNames.length, 1, "Correct objectStoreNames list");
is(db.objectStoreNames.item(0), objectStoreName, "Correct name");
@ -83,7 +84,7 @@
request.onsuccess = grabEventAndContinueHandler;
event = yield;
objectStore = db.createObjectStore(objectStoreName, "foo");
objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" });
request = objectStore.add({foo:"bar"});
request.onerror = errorHandler;

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

@ -39,7 +39,7 @@
is(request.readyState, DONE, "Correct readyState");
let objectStore = db.createObjectStore("foo", "");
let objectStore = db.createObjectStore("foo");
let key = 10;
request = objectStore.add({}, key);

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

@ -32,7 +32,7 @@ function testSteps()
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore("foo", "");
let objectStore = db.createObjectStore("foo");
let index = objectStore.createIndex("bar", "baz");
is(db.version, "1", "Correct version");

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

@ -41,7 +41,7 @@
event = yield;
transaction = event.transaction;
objectStore = db.createObjectStore("foo", "", true);
objectStore = db.createObjectStore("foo", { autoIncrement: true });
is(transaction.db, db, "Correct database");
is(transaction.readyState, LOADING, "Correct readyState");

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

@ -26,7 +26,7 @@
event.transaction.oncomplete = continueToNextStep;
db.createObjectStore("foo", "", true);
db.createObjectStore("foo", { autoIncrement: true });
yield;
let transaction = db.transaction("foo");

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

@ -25,7 +25,7 @@
event = yield;
event.transaction.oncomplete = continueToNextStep;
db.createObjectStore("foo", "");
db.createObjectStore("foo");
yield;
let transaction1 = db.transaction("foo");

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

@ -35,7 +35,7 @@
is(event.transaction.mode, VERSION_CHANGE, "Correct mode");
let objectStore = db.createObjectStore("foo", "", true);
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
request = objectStore.add({});
request.onerror = errorHandler;