Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../../resources/js-test.js"></script> | 2 <script src="../../resources/js-test.js"></script> |
| 3 <script src="resources/shared.js"></script> | 3 <script src="resources/shared.js"></script> |
| 4 <script> | 4 <script> |
| 5 | 5 |
| 6 description("Verify that that cursors weakly hold script value properties"); | 6 description("Verify that that cursors weakly hold script value properties"); |
| 7 | 7 |
| 8 if (window.internals) { | 8 if (window.internals) { |
| 9 indexedDBTest(prepareDatabase, onOpen); | 9 indexedDBTest(prepareDatabase, onOpen); |
| 10 } else { | 10 } else { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 db = evt.target.result; | 26 db = evt.target.result; |
| 27 tx = db.transaction('store'); | 27 tx = db.transaction('store'); |
| 28 store = tx.objectStore('store'); | 28 store = tx.objectStore('store'); |
| 29 cursorRequest = store.openCursor(); | 29 cursorRequest = store.openCursor(); |
| 30 cursorRequest.onsuccess = function() { | 30 cursorRequest.onsuccess = function() { |
| 31 cursor = cursorRequest.result; | 31 cursor = cursorRequest.result; |
| 32 }; | 32 }; |
| 33 tx.oncomplete = function() { | 33 tx.oncomplete = function() { |
| 34 db.close(); | 34 db.close(); |
| 35 | |
| 36 // Do initialization work in an inner function to avoid references to | |
| 37 // objects remaining live on this function's stack frame | |
| 38 // (http://crbug.com/595672/). | |
| 39 function initialize() { | |
| 40 // Try and induce a leak by a reference cycle from DOM to V8 and | |
| 41 // back. If the v8 value of cursor.key (etc) is only held by the | |
| 42 // cursor's V8 wrapper then there will be no leak. | |
| 43 cursor.key.cursor = cursor; | |
| 44 cursor.primaryKey.cursor = cursor; | |
| 45 cursor.value.cursor = cursor; | |
| 46 cursorObserver = internals.observeGC(cursor); | |
| 47 } | |
| 35 | 48 |
| 36 // Try and induce a leak by a reference cycle from DOM to V8 and back. | 49 initialize(); |
| 37 // If the v8 value of cursor.key (etc) is only held by the cursor's | |
| 38 // V8 wrapper then there will be no leak. | |
| 39 cursor.key.cursor = cursor; | |
| 40 cursor.primaryKey.cursor = cursor; | |
| 41 cursor.value.cursor = cursor; | |
| 42 | |
| 43 // Do not pass the object directly to observeGC function. This may | |
| 44 // remain live on this function's stack preventing GC from collecting | |
| 45 // it. Accessing the object inside an inner function will prevent any | |
| 46 // unneeded references on this function's stack. | |
| 47 cursorObserver = internals.observeGC((() => {return cursor;})()); | |
| 48 | 50 |
| 49 cursorRequest = null; | 51 cursorRequest = null; |
| 50 cursor = null; | 52 cursor = null; |
|
rmcilroy
2016/05/20 14:53:39
Ditto with cursorRequest and cursor
mythria
2016/05/23 10:35:45
We can't do this with cursorRequest or cursor. The
| |
| 51 | 53 |
| 52 gc(); | 54 gc(); |
| 53 | 55 |
| 54 shouldBeTrue("cursorObserver.wasCollected"); | 56 shouldBeTrue("cursorObserver.wasCollected"); |
| 55 finishJSTest(); | 57 finishJSTest(); |
| 56 }; | 58 }; |
| 57 } | 59 } |
| 58 | 60 |
| 59 | 61 |
| 60 </script> | 62 </script> |
| OLD | NEW |