-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IndexedDB: Have IDBCursor and IDBRequest explicitly break ref cycles
Until (1) a transaction ends or (2) a cursor hits the end of its range, an IDBRequest holds on to an IDBCursor as its result. Per spec, calling continue() or advance() on the cursor re-uses the same IDBRequest, requiring a reference cycle. Previously, the cycle was broken explicitly on either of those two conditions, but until that time a cursor-request pair would "leak", holding on to potentially large script value results. This patch makes both classes RefCountedBase::deref() and check to see if they have a partner object and both refcounts are 1. If so, the cycle is broken. Special case cruft for condition #1 is removed to simplify the code - just rely on GC to reclaim the objects if necessary. R=alecflett@chromium.org,dgrogan@chromium.org BUG=225860 Review URL: https://chromiumcodereview.appspot.com/23653024 git-svn-id: svn://svn.chromium.org/blink/trunk@157382 bbb929c8-8fbe-4397-9dbb-9b2b20218538
- Loading branch information
jsbell@chromium.org
committed
Sep 6, 2013
1 parent
0e53aff
commit 4b8ab16
Showing
11 changed files
with
187 additions
and
103 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
LayoutTests/storage/indexeddb/cursor-request-cycle-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Verify that that cursors weakly hold request, and work if request is GC'd | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB; | ||
|
||
dbname = "cursor-request-cycle.html" | ||
indexedDB.deleteDatabase(dbname) | ||
indexedDB.open(dbname) | ||
|
||
prepareDatabase(): | ||
db = event.target.result | ||
store = db.createObjectStore('store') | ||
|
||
onOpen(): | ||
db = event.target.result | ||
tx = db.transaction('store') | ||
store = tx.objectStore('store') | ||
cursorRequest = store.openCursor() | ||
otherRequest = store.get(0) | ||
|
||
openCursorRequest(): | ||
cursor = cursorRequest.result | ||
PASS cursor is non-null. | ||
PASS cursor.key is "key1" | ||
PASS cursor.value is "value1" | ||
|
||
otherRequestSuccess(): | ||
PASS afterCount is beforeCount | ||
cursor.continue() | ||
finalRequest = store.get(0) | ||
|
||
finalRequestSuccess(): | ||
PASS cursor.key is "key2" | ||
PASS cursor.value is "value2" | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!DOCTYPE html> | ||
<script src="../../fast/js/resources/js-test-pre.js"></script> | ||
<script src="resources/shared.js"></script> | ||
<script> | ||
|
||
description("Verify that that cursors weakly hold request, and work if request is GC'd"); | ||
|
||
indexedDBTest(prepareDatabase, onOpen); | ||
|
||
function prepareDatabase(evt) | ||
{ | ||
preamble(evt); | ||
evalAndLog("db = event.target.result"); | ||
evalAndLog("store = db.createObjectStore('store')"); | ||
store.put("value1", "key1"); | ||
store.put("value2", "key2"); | ||
} | ||
|
||
function onOpen(evt) | ||
{ | ||
preamble(evt); | ||
evalAndLog("db = event.target.result"); | ||
evalAndLog("tx = db.transaction('store')"); | ||
evalAndLog("store = tx.objectStore('store')"); | ||
|
||
evalAndLog("cursorRequest = store.openCursor()"); | ||
cursorRequest.onsuccess = function openCursorRequest(evt) { | ||
preamble(evt); | ||
evalAndLog("cursor = cursorRequest.result"); | ||
shouldBeNonNull("cursor"); | ||
shouldBeEqualToString("cursor.key", "key1"); | ||
shouldBeEqualToString("cursor.value", "value1"); | ||
}; | ||
|
||
evalAndLog("otherRequest = store.get(0)"); | ||
|
||
otherRequest.onsuccess = function otherRequestSuccess(evt) { | ||
preamble(evt); | ||
|
||
gc(); | ||
gc(); // FIXME: Why is this second call necessary? | ||
beforeCount = window.internals.numberOfLiveNodes(); | ||
|
||
cursorRequest.canary = document.createElement('canary'); | ||
cursorRequest = null; | ||
|
||
gc(); | ||
gc(); // FIXME: Why is this second call necessary? | ||
afterCount = window.internals.numberOfLiveNodes(); | ||
shouldBe("afterCount", "beforeCount"); | ||
|
||
// The following call should generate a scratch request, invisible to script: | ||
evalAndLog("cursor.continue()"); | ||
|
||
evalAndLog("finalRequest = store.get(0)"); | ||
finalRequest.onsuccess = function finalRequestSuccess(evt) { | ||
preamble(evt); | ||
shouldBeEqualToString("cursor.key", "key2"); | ||
shouldBeEqualToString("cursor.value", "value2"); | ||
}; | ||
}; | ||
|
||
tx.oncomplete = finishJSTest; | ||
} | ||
|
||
|
||
</script> | ||
<script src="../../fast/js/resources/js-test-post.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.