2 <script src=
"../../resources/js-test.js"></script>
3 <script src=
"resources/shared.js"></script>
6 description("Verify that that cursors weakly hold request, and work if request is GC'd");
8 indexedDBTest(prepareDatabase
, onOpen
);
10 function prepareDatabase(evt
)
13 evalAndLog("db = event.target.result");
14 evalAndLog("store = db.createObjectStore('store')");
15 store
.put("value1", "key1");
16 store
.put("value2", "key2");
22 evalAndLog("db = event.target.result");
23 evalAndLog("tx = db.transaction('store')");
24 evalAndLog("store = tx.objectStore('store')");
26 evalAndLog("cursorRequest = store.openCursor()");
27 cursorRequest
.onsuccess
= function openCursorRequestSuccess(evt
) {
29 debug("Result will be checked later, to ensure that lazy access is safe");
32 evalAndLog("otherRequest = store.get(0)");
33 otherRequest
.onsuccess
= function otherRequestSuccess(evt
) {
36 debug("Verify that the request's result can be accessed lazily:");
39 evalAndLog("cursor = cursorRequest.result");
40 shouldBeNonNull("cursor");
41 shouldBeEqualToString("cursor.key", "key1");
42 shouldBeEqualToString("cursor.value", "value1");
43 evalAndLog("cursorRequest.extra = 123");
44 evalAndLog("cursor.extra = 456");
46 // Assign a new handler to inspect the request and cursor indirectly.
47 cursorRequest
.onsuccess
= function cursorContinueSuccess(evt
) {
49 evalAndLog("cursor = event.target.result");
50 shouldBeNonNull("cursor");
51 shouldBeEqualToString("cursor.key", "key2");
52 shouldBeEqualToString("cursor.value", "value2");
53 shouldBe("event.target.extra", "123");
54 shouldBe("cursor.extra", "456");
57 debug("Ensure request is not released if cursor is still around.");
58 cursorRequestObservation
= internals
.observeGC(cursorRequest
);
59 evalAndLog("cursorRequest = null");
61 shouldBeFalse("cursorRequestObservation.wasCollected");
63 evalAndLog("cursor.continue()");
65 cursorObservation
= internals
.observeGC(cursor
);
66 evalAndLog("cursor = null");
68 shouldBeFalse("cursorObservation.wasCollected");
70 evalAndLog("finalRequest = store.get(0)");
71 finalRequest
.onsuccess
= function finalRequestSuccess(evt
) {
73 shouldBeEqualToString("cursor.key", "key2");
74 shouldBeEqualToString("cursor.value", "value2");
76 cursorObservation
= internals
.observeGC(cursor
);
77 evalAndLog("cursor = null");
79 shouldBeTrue("cursorRequestObservation.wasCollected");
80 shouldBeTrue("cursorObservation.wasCollected");
84 tx
.oncomplete
= finishJSTest
;