Bug 1265973 - Throw InvalidStateError at IDBCursor.update() if IDBCursor.continue() is in progress. r=khuey

This commit is contained in:
Bevis Tseng 2016-04-20 14:36:19 +08:00
parent a516550b03
commit 99314e7542
4 changed files with 100 additions and 1 deletions

View File

@ -593,7 +593,8 @@ IDBCursor::Update(JSContext* aCx, JS::Handle<JS::Value> aValue,
IsSourceDeleted() ||
!mHaveValue ||
mType == Type_ObjectStoreKey ||
mType == Type_IndexKey) {
mType == Type_IndexKey ||
mContinueCalled) {
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
return nullptr;
}

View File

@ -11489,6 +11489,10 @@
"path": "IndexedDB/idbcursor_update_index7.htm",
"url": "/IndexedDB/idbcursor_update_index7.htm"
},
{
"path": "IndexedDB/idbcursor_update_index8.htm",
"url": "/IndexedDB/idbcursor_update_index8.htm"
},
{
"path": "IndexedDB/idbcursor_update_objectstore.htm",
"url": "/IndexedDB/idbcursor_update_objectstore.htm"
@ -11521,6 +11525,10 @@
"path": "IndexedDB/idbcursor_update_objectstore8.htm",
"url": "/IndexedDB/idbcursor_update_objectstore8.htm"
},
{
"path": "IndexedDB/idbcursor_update_objectstore9.htm",
"url": "/IndexedDB/idbcursor_update_objectstore9.htm"
},
{
"path": "IndexedDB/idbdatabase_close.htm",
"url": "/IndexedDB/idbdatabase_close.htm"

View File

@ -0,0 +1,45 @@
<!DOCTYPE html>
<title>IDBCursor.update() - index - throw InvalidStateError when the cursor is being iterated</title>
<link rel="author" title="Mozilla" href="https://www.mozilla.org">
<link rel="help" href="https://www.w3.org/TR/IndexedDB/#widl-IDBCursor-update-IDBRequest-any-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
{ pKey: "primaryKey_1", iKey: "indexKey_1" } ];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function(e) {
db = e.target.result;
var objStore = db.createObjectStore("store", { keyPath: "pKey" });
objStore.createIndex("index", "iKey");
for (var i = 0; i < records.length; i++)
objStore.add(records[i]);
};
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("store", "readwrite")
.objectStore("store")
.index("index")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(e) {
var cursor = e.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exists");
cursor.continue();
assert_throws("InvalidStateError", function() {
cursor.update({ pKey: "primaryKey_0", iKey: "indexKey_0_updated" });
});
t.done();
});
}
</script>

View File

@ -0,0 +1,45 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBCursor.update() - object store - throw InvalidStateError when the cursor is being iterated</title>
<link rel="author" title="Mozilla" href="https://www.mozilla.org">
<link rel="help" href="https://www.w3.org/TR/IndexedDB/#widl-IDBCursor-update-IDBRequest-any-value">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<div id="log"></div>
<script>
var db,
t = async_test(),
records = [{ pKey: "primaryKey_0", value: "value_0" },
{ pKey: "primaryKey_1", value: "value_1" }];
var open_rq = createdb(t);
open_rq.onupgradeneeded = function (event) {
db = event.target.result;
var objStore = db.createObjectStore("store", {keyPath : "pKey"});
for (var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
}
open_rq.onsuccess = function(e) {
var cursor_rq = db.transaction("store", "readwrite")
.objectStore("store")
.openCursor();
cursor_rq.onsuccess = t.step_func(function(event) {
var cursor = event.target.result;
assert_true(cursor instanceof IDBCursor, "cursor exists");
cursor.continue();
assert_throws("InvalidStateError", function() {
cursor.update({ pKey: "primaryKey_0", value: "value_0_updated" });
});
t.done();
});
}
</script>