Bug 1265973 - Throw InvalidStateError at IDBCursor.update() if IDBCursor.continue() is in progress. r=khuey
authorBevis Tseng <btseng@mozilla.com>
Wed, 20 Apr 2016 14:36:19 +0800
changeset 332158 5f04a61564c8c6979ba9d3cf7339846301b3f7f6
parent 332157 c6b548af3126ba9e95aa9d2f840d14785e396a37
child 332159 173a441d7bb1be25728c5348135d3935ab20195a
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1265973
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1265973 - Throw InvalidStateError at IDBCursor.update() if IDBCursor.continue() is in progress. r=khuey
dom/indexedDB/IDBCursor.cpp
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/IndexedDB/idbcursor_update_index8.htm
testing/web-platform/tests/IndexedDB/idbcursor_update_objectstore9.htm
--- a/dom/indexedDB/IDBCursor.cpp
+++ b/dom/indexedDB/IDBCursor.cpp
@@ -588,17 +588,18 @@ IDBCursor::Update(JSContext* aCx, JS::Ha
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR);
     return nullptr;
   }
 
   if (mTransaction->GetMode() == IDBTransaction::CLEANUP ||
       IsSourceDeleted() ||
       !mHaveValue ||
       mType == Type_ObjectStoreKey ||
-      mType == Type_IndexKey) {
+      mType == Type_IndexKey ||
+      mContinueCalled) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
   MOZ_ASSERT(mType == Type_ObjectStore || mType == Type_Index);
   MOZ_ASSERT(!mKey.IsUnset());
   MOZ_ASSERT_IF(mType == Type_Index, !mPrimaryKey.IsUnset());
 
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -11485,16 +11485,20 @@
         "path": "IndexedDB/idbcursor_update_index6.htm",
         "url": "/IndexedDB/idbcursor_update_index6.htm"
       },
       {
         "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"
       },
       {
         "path": "IndexedDB/idbcursor_update_objectstore2.htm",
         "url": "/IndexedDB/idbcursor_update_objectstore2.htm"
       },
       {
@@ -11517,16 +11521,20 @@
         "path": "IndexedDB/idbcursor_update_objectstore7.htm",
         "url": "/IndexedDB/idbcursor_update_objectstore7.htm"
       },
       {
         "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"
       },
       {
         "path": "IndexedDB/idbdatabase_close2.htm",
         "url": "/IndexedDB/idbdatabase_close2.htm"
       },
       {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/IndexedDB/idbcursor_update_index8.htm
@@ -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>
+
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/IndexedDB/idbcursor_update_objectstore9.htm
@@ -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>
+