Bug 83492 - IndexedDB: Attributes for a cursor "run past the end" should be undefined.
Summary: IndexedDB: Attributes for a cursor "run past the end" should be undefined.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alec Flett
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-09 11:47 PDT by Alec Flett
Modified: 2012-04-12 13:01 PDT (History)
5 users (show)

See Also:


Attachments
Patch (41.22 KB, patch)
2012-04-09 12:05 PDT, Alec Flett
no flags Details | Formatted Diff | Diff
Patch (41.20 KB, patch)
2012-04-09 12:13 PDT, Alec Flett
no flags Details | Formatted Diff | Diff
Patch (40.16 KB, patch)
2012-04-09 15:36 PDT, Alec Flett
no flags Details | Formatted Diff | Diff
Patch (40.17 KB, patch)
2012-04-09 15:49 PDT, Alec Flett
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ec2-cr-linux-04 (6.43 MB, application/zip)
2012-04-09 19:42 PDT, WebKit Review Bot
no flags Details
Patch (44.58 KB, patch)
2012-04-10 11:57 PDT, Alec Flett
no flags Details | Formatted Diff | Diff
Patch (44.56 KB, patch)
2012-04-10 14:07 PDT, Alec Flett
no flags Details | Formatted Diff | Diff
Patch (44.63 KB, patch)
2012-04-12 11:37 PDT, Alec Flett
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alec Flett 2012-04-09 11:47:29 PDT
IndexedDB: Attributes for a cursor "run past the end" should be undefined.
Comment 1 Alec Flett 2012-04-09 12:05:04 PDT
Created attachment 136281 [details]
Patch
Comment 2 Alec Flett 2012-04-09 12:13:04 PDT
Created attachment 136282 [details]
Patch
Comment 3 Alec Flett 2012-04-09 12:15:08 PDT
jsbell@ - mind taking a look? in particular I want to make sure I have the RefPtr stuff right for m_currentValue, since I'm storing a SerializedScriptValue() and converting it to an IDBAny on demand in IDBCursor::value()
Comment 4 Joshua Bell 2012-04-09 13:54:49 PDT
Comment on attachment 136282 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=136282&action=review

> Source/WebCore/ChangeLog:18
> +        update and delete can be called before continue, but not afterwards.

Nit: For consistency, should be update() and delete() and reword to start the sentence with a capital.

> Source/WebCore/Modules/indexeddb/IDBCursor.cpp:87
> +    return IDBAny::create(m_currentValue.get());

As an aside, the spec includes "if this property returns an object, it returns the same object instance every time it is inspected, until the cursor's value is changed. This means that if the object is modified, those modifications will be seen by anyone inspecting the value of the cursor." - do we implement that? Would returning the same IDBAny instance on each call affect that behavior? My guess is no and no. Implementing that part of the spec may be problematic. (This change doesn't affect it either way.)

> Source/WebCore/Modules/indexeddb/IDBCursor.cpp:100
> +        ec = IDBDatabaseException::TRANSACTION_INACTIVE_ERR;

Spec says this should be InvalidStateError (DOM4-style) - can you make it INVALID_STATE_ERR (not part of the IDBDatabaseException enum)

> Source/WebCore/Modules/indexeddb/IDBCursor.cpp:123
> +        ec = IDBDatabaseException::TRANSACTION_INACTIVE_ERR;

ditto

> Source/WebCore/Modules/indexeddb/IDBCursor.cpp:150
> +        ec = IDBDatabaseException::TRANSACTION_INACTIVE_ERR;

ditto

> Source/WebCore/Modules/indexeddb/IDBCursor.h:87
> +    RefPtr<IDBKey> m_currentKey;

Does "current" add anything here? Can it just be m_key etc?

> Source/WebCore/Modules/indexeddb/IDBCursor.h:89
> +    RefPtr<SerializedScriptValue> m_currentValue;

Although I believe this code is correct, I would have this be a RefPtr<IDBAny> and re-use the IDBAny across calls so that we minimize the number of places IDB objects hold SSV pointers. It shouldn't make any practical difference, though.

> LayoutTests/storage/indexeddb/resources/cursor-continue-validity.js:52
> +    result = evalAndLog("objectStore.add({'x': " + nextToAdd + " }, " + nextToAdd + ")");

Multiple add calls can be done w/o waiting for the success callback of the previous one. Just use a for a loop here.

> LayoutTests/storage/indexeddb/resources/cursor-continue-validity.js:148
> +        // behavior against pre-caching. Make sure to use prime

Nit: "pre-fetching" (so readers know what to search on)

> LayoutTests/storage/indexeddb/resources/cursor-continue-validity.js:173
> +        onTransactionComplete();

The transaction is not actually complete here, the cursor has just run to the end...

> LayoutTests/storage/indexeddb/resources/cursor-continue-validity.js:179
> +    evalAndExpectException("cursor.continue()", "");

I'd move this inline since it's part of the consistency checks...

> LayoutTests/storage/indexeddb/resources/cursor-continue-validity.js:180
> +    finishJSTest();

And either call this directly, or hang it off he actual transaction oncomplete callback.
Comment 5 Joshua Bell 2012-04-09 13:57:56 PDT
Comment on attachment 136282 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=136282&action=review

> Source/WebCore/Modules/indexeddb/IDBCursor.cpp:88
>  }

Since m_currentValue is a RefPtr<SerializedScriptValue> this should just be: return IDBAny::create(m_currentValue)
Comment 6 Alec Flett 2012-04-09 15:36:40 PDT
Created attachment 136319 [details]
Patch
Comment 7 Alec Flett 2012-04-09 15:49:35 PDT
Created attachment 136325 [details]
Patch
Comment 8 Alec Flett 2012-04-09 15:49:38 PDT
Comment on attachment 136282 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=136282&action=review

>> Source/WebCore/Modules/indexeddb/IDBCursor.cpp:87
>> +    return IDBAny::create(m_currentValue.get());
> 
> As an aside, the spec includes "if this property returns an object, it returns the same object instance every time it is inspected, until the cursor's value is changed. This means that if the object is modified, those modifications will be seen by anyone inspecting the value of the cursor." - do we implement that? Would returning the same IDBAny instance on each call affect that behavior? My guess is no and no. Implementing that part of the spec may be problematic. (This change doesn't affect it either way.)

changed to be an IDBAny, and sadly you're correct: the obj does change each time.

>> Source/WebCore/Modules/indexeddb/IDBCursor.h:87
>> +    RefPtr<IDBKey> m_currentKey;
> 
> Does "current" add anything here? Can it just be m_key etc?

I personally think it does because m_backend can get out of sync with m_current*

>> Source/WebCore/Modules/indexeddb/IDBCursor.h:89
>> +    RefPtr<SerializedScriptValue> m_currentValue;
> 
> Although I believe this code is correct, I would have this be a RefPtr<IDBAny> and re-use the IDBAny across calls so that we minimize the number of places IDB objects hold SSV pointers. It shouldn't make any practical difference, though.

Done.

>> LayoutTests/storage/indexeddb/resources/cursor-continue-validity.js:52
>> +    result = evalAndLog("objectStore.add({'x': " + nextToAdd + " }, " + nextToAdd + ")");
> 
> Multiple add calls can be done w/o waiting for the success callback of the previous one. Just use a for a loop here.

this was copied from another test, and I thought the same until I realized that you don't have a final onsuccess to fire if you do it like that - you could attach to the last-added value, but there's no guarantee that the other values have been written by then. (at least that I could see...)
Comment 9 Alec Flett 2012-04-09 15:50:09 PDT
jsbell@ - comments addressed...
Comment 10 WebKit Review Bot 2012-04-09 19:42:28 PDT
Comment on attachment 136325 [details]
Patch

Attachment 136325 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/12371585

New failing tests:
storage/indexeddb/cursor-continue.html
storage/indexeddb/mozilla/cursors.html
Comment 11 WebKit Review Bot 2012-04-09 19:42:33 PDT
Created attachment 136379 [details]
Archive of layout-test-results from ec2-cr-linux-04

The attached test failures were seen while running run-webkit-tests on the chromium-ews.
Bot: ec2-cr-linux-04  Port: <class 'webkitpy.common.config.ports.ChromiumXVFBPort'>  Platform: Linux-2.6.35-28-virtual-x86_64-with-Ubuntu-10.10-maverick
Comment 12 Alec Flett 2012-04-10 11:57:46 PDT
Created attachment 136498 [details]
Patch
Comment 13 Alec Flett 2012-04-10 12:00:42 PDT
jsbell@ - ok, one more try, the other tests pass this time! (one mozilla test had to be altered because the new behavior is correct)
Comment 14 Joshua Bell 2012-04-10 12:23:43 PDT
(In reply to comment #8)
> changed to be an IDBAny, and sadly you're correct: the obj does change each time.

I filed https://bugs.webkit.org/show_bug.cgi?id=83526 to track this.

> this was copied from another test, and I thought the same until I realized that you don't have a final onsuccess to fire if you do it like that - you could attach to the last-added value, but there's no guarantee that the other values have been written by then. (at least that I could see...)

Within a transaction, tasks a guaranteed to execute in the order they are requested, so if you run:

req1 = store.put(1, "key");
req2 = store.get("key");

then req2.result will eventually be 1, even though you're not waiting for req1 to succeed before you issue the get() call.
Comment 15 Joshua Bell 2012-04-10 12:32:18 PDT
Comment on attachment 136498 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=136498&action=review

The cursor-continue.html test failed (exception code changed) - did its expected file need to be updated as well?

> LayoutTests/ChangeLog:11
> +        * storage/indexeddb/resources/shared.js:

Should add storage/indexeddb/mozilla/cursors-expected.txt to the list

(Sadly, the list is not automagically updated if you revise a patch)
Comment 16 Alec Flett 2012-04-10 14:07:49 PDT
Created attachment 136538 [details]
Patch
Comment 17 Joshua Bell 2012-04-10 14:09:42 PDT
Comment on attachment 136538 [details]
Patch

lgtm
Comment 18 Alec Flett 2012-04-10 15:22:23 PDT
ojan@ - one more for today - r? cq?
Comment 19 Ojan Vafai 2012-04-11 13:23:04 PDT
Comment on attachment 136538 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=136538&action=review

> Source/WebCore/Modules/indexeddb/IDBCursor.cpp:175
> +void IDBCursor::setGotValue()

This does more than just set m_gotValue. Maybe this should be called something like syncToBackendValues?

> LayoutTests/storage/indexeddb/cursor-continue-validity.html:1
> +<html>

New tests should all be in standards mode unless they're explicitly testing quirks behavior. So, this should start with:
<!DOCTYPE html>

> LayoutTests/storage/indexeddb/cursor-continue-validity.html:7
> +<script src="resources/cursor-continue-validity.js"></script>

We've been moving away from using a separate script file for tests that are not pure JS tests (i.e. test that can be run without a browser context). Instead, just inline cursor-continue-validity.js. It makes maintaining the tests much easier when the whole test is contained in one file (with the test harness code still in external files of course).

> LayoutTests/storage/indexeddb/resources/cursor-continue-validity.js:132
> +function testModifyContinueOrder() {

Here and below, opening curly brace should be on the next line.
Comment 20 Joshua Bell 2012-04-11 13:36:03 PDT
(In reply to comment #19)
> 
> > LayoutTests/storage/indexeddb/cursor-continue-validity.html:7
> > +<script src="resources/cursor-continue-validity.js"></script>
> 
> We've been moving away from using a separate script file for tests that are not pure JS tests (i.e. test that can be run without a browser context). Instead, just inline cursor-continue-validity.js. It makes maintaining the tests much easier when the whole test is contained in one file (with the test harness code still in external files of course).

dgrogan@ just moved most of the IDB test logic from .html into .js files so we can run them both in a Window context and in a Worker (or SharedWorker) context. The only exceptions are tests than span Window+Worker or places where the APIs differ.
Comment 21 Ojan Vafai 2012-04-11 13:41:42 PDT
(In reply to comment #20)
> (In reply to comment #19)
> > 
> > > LayoutTests/storage/indexeddb/cursor-continue-validity.html:7
> > > +<script src="resources/cursor-continue-validity.js"></script>
> > 
> > We've been moving away from using a separate script file for tests that are not pure JS tests (i.e. test that can be run without a browser context). Instead, just inline cursor-continue-validity.js. It makes maintaining the tests much easier when the whole test is contained in one file (with the test harness code still in external files of course).
> 
> dgrogan@ just moved most of the IDB test logic from .html into .js files so we can run them both in a Window context and in a Worker (or SharedWorker) context. The only exceptions are tests than span Window+Worker or places where the APIs differ.

oic. That makes sense then.
Comment 22 Alec Flett 2012-04-12 11:37:20 PDT
Created attachment 136941 [details]
Patch
Comment 23 Alec Flett 2012-04-12 11:39:06 PDT
Comment on attachment 136538 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=136538&action=review

>> Source/WebCore/Modules/indexeddb/IDBCursor.cpp:175
>> +void IDBCursor::setGotValue()
> 
> This does more than just set m_gotValue. Maybe this should be called something like syncToBackendValues?

renamed to setValueReady

All other comments addressed.
Comment 24 Ojan Vafai 2012-04-12 12:25:24 PDT
Comment on attachment 136941 [details]
Patch

FYI, I believe if you get an r+ then the next patch you upload you can do with "webkit-patch land-safely" and it should add it to the commit queue and use the previous r+. Not 100% sure if that works for people without commit access though.
Comment 25 WebKit Review Bot 2012-04-12 13:01:39 PDT
Comment on attachment 136941 [details]
Patch

Clearing flags on attachment: 136941

Committed r114022: <http://trac.webkit.org/changeset/114022>
Comment 26 WebKit Review Bot 2012-04-12 13:01:53 PDT
All reviewed patches have been landed.  Closing bug.