Permalink
Browse files

IndexedDB: Disallow continuePrimaryKey on unique cursors

The experimental 'continuePrimaryKey()' method had undefined behavior
when the cursor was a 'unique' cursor (skipping over duplicate
primary keys). After some spec discussion[1], it seems like forbidding
the use of the method on such cursors is the safest approach.

[1] w3c/IndexedDB#14

R=cmumford@chromium.org
BUG=497454

Review URL: https://codereview.chromium.org/1188343002

git-svn-id: svn://svn.chromium.org/blink/trunk@197309 bbb929c8-8fbe-4397-9dbb-9b2b20218538
  • Loading branch information...
inexorabletash committed Jun 18, 2015
1 parent 560bd94 commit bf7ff4ddec49b06a33344199e1c0aa6831cbd245
@@ -17,15 +17,15 @@
store.put('a', 1).onerror = t.unreached_func('put should not fail');
var request = store.openCursor();
request.onerror = t.unreached_func('openCursor should not fail');
request.onsuccess = function() {
request.onsuccess = t.step_func(function() {
var cursor = request.result;
assert_class_string(cursor, 'IDBCursorWithValue',
'result should be a cursor');
assert_throws('InvalidAccessError', function() {
cursor.continuePrimaryKey(2, 2);
}, 'continuePrimaryKey() should throw if source is not an index');
};
});
});
open.onsuccess = t.step_func(function() {
@@ -36,4 +36,61 @@
}, 'IDBCursor continuePrimaryKey() on object store cursor');
[
{
direction: 'nextunique',
expected_key: 1, expected_primaryKey: 'a',
continue_key: 2, continue_primaryKey: 'a'
},
{
direction: 'prevunique',
expected_key: 3, expected_primaryKey: 'a',
continue_key: 2, continue_primaryKey: 'a'
}
].forEach(function(testcase) {
async_test(function(t) {
var dbname = document.location + '-' + t.name;
var del = indexedDB.deleteDatabase(dbname);
del.onerror = t.unreached_func('deleteDatabase should succeed');
var open = indexedDB.open(dbname);
open.onerror = t.unreached_func('open should succeed');
open.onupgradeneeded = t.step_func(function() {
var db = open.result;
var store = db.createObjectStore('store', {keyPath: 'pk'});
var index = store.createIndex('index', 'ik', {multiEntry: true});
store.put({pk: 'a', ik: [1,2,3]}).onerror =
t.unreached_func('put should not fail');
store.put({pk: 'b', ik: [1,2,3]}).onerror =
t.unreached_func('put should not fail');
var request = index.openKeyCursor(null, testcase.direction);
request.onerror = t.unreached_func('openCursor should not fail');
request.onsuccess = t.step_func(function() {
var cursor = request.result;
assert_class_string(cursor, 'IDBCursor',
'result should be a cursor');
assert_equals(cursor.direction, testcase.direction,
'direction should be as specified');
assert_equals(cursor.key, testcase.expected_key,
'key should match');
assert_equals(cursor.primaryKey, testcase.expected_primaryKey,
'primaryKey should match');
assert_throws('InvalidAccessError', function() {
cursor.continuePrimaryKey(
testcase.continue_key,
testcase.continue_primaryKey);
}, 'continuePrimaryKey() should throw if direction is unique');
});
});
open.onsuccess = t.step_func(function() {
var db = open.result;
db.close();
t.done();
});
}, 'IDBCursor continuePrimaryKey() on "' + testcase.direction + '" cursor');
});
</script>
@@ -166,6 +166,10 @@ void IDBCursor::continuePrimaryKey(ScriptState* scriptState, const ScriptValue&
exceptionState.throwDOMException(InvalidAccessError, "The cursor's source is not an index.");
return;
}
if (m_direction != WebIDBCursorDirectionNext && m_direction != WebIDBCursorDirectionPrev) {
exceptionState.throwDOMException(InvalidAccessError, "The cursor's direction is not 'next' or 'prev'.");
return;
}
IDBKey* key = ScriptValue::to<IDBKey*>(scriptState->isolate(), keyValue, exceptionState);
if (exceptionState.hadException())

0 comments on commit bf7ff4d

Please sign in to comment.