2 <script src=
"../../resources/js-test.js"></script>
3 <script src=
"resources/shared.js"></script>
6 description("Verify that that key 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.openKeyCursor()");
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 evalAndLog("cursorRequest.extra = 123");
43 evalAndLog("cursor.extra = 456");
45 // Assign a new handler to inspect the request and cursor indirectly.
46 cursorRequest
.onsuccess
= function cursorContinueSuccess(evt
) {
48 evalAndLog("cursor = event.target.result");
49 shouldBeNonNull("cursor");
50 shouldBeEqualToString("cursor.key", "key2");
51 shouldBe("event.target.extra", "123");
52 shouldBe("cursor.extra", "456");
55 debug("Ensure request is not released if cursor is still around.");
56 cursorRequestObservation
= internals
.observeGC(cursorRequest
);
57 evalAndLog("cursorRequest = null");
59 shouldBeFalse("cursorRequestObservation.wasCollected");
61 evalAndLog("cursor.continue()");
63 cursorObservation
= internals
.observeGC(cursor
);
64 evalAndLog("cursor = null");
66 shouldBeFalse("cursorObservation.wasCollected");
68 evalAndLog("finalRequest = store.get(0)");
69 finalRequest
.onsuccess
= function finalRequestSuccess(evt
) {
71 shouldBeEqualToString("cursor.key", "key2");
73 cursorObservation
= internals
.observeGC(cursor
);
74 evalAndLog("cursor = null");
76 shouldBeTrue("cursorRequestObservation.wasCollected");
77 shouldBeTrue("cursorObservation.wasCollected");
81 tx
.oncomplete
= finishJSTest
;