diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /dom/indexedDB/test/blob_worker_crash_iframe.html | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream/1%115.7.0.tar.xz thunderbird-upstream/1%115.7.0.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/indexedDB/test/blob_worker_crash_iframe.html')
-rw-r--r-- | dom/indexedDB/test/blob_worker_crash_iframe.html | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/dom/indexedDB/test/blob_worker_crash_iframe.html b/dom/indexedDB/test/blob_worker_crash_iframe.html new file mode 100644 index 0000000000..15d8277515 --- /dev/null +++ b/dom/indexedDB/test/blob_worker_crash_iframe.html @@ -0,0 +1,99 @@ +<!-- + Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +--> +<html> +<head> + <title>Indexed Database Test</title> + + <script type="text/javascript"> + function report(result) { + var message = { source: "iframe" }; + message.result = result; + window.parent.postMessage(message, "*"); + } + + function runIndexedDBTest() { + var db = null; + + // Create the data-store + function createDatastore() { + try { + var request = indexedDB.open(window.location.pathname, 1); + request.onupgradeneeded = function(event) { + event.target.result.createObjectStore("foo"); + }; + request.onsuccess = function(event) { + db = event.target.result; + createAndStoreBlob(); + }; + } + catch (e) { +dump("EXCEPTION IN CREATION: " + e + "\n " + e.stack + "\n"); + report(false); + } + } + + function createAndStoreBlob() { + const BLOB_DATA = ["fun ", "times ", "all ", "around!"]; + var blob = new Blob(BLOB_DATA, { type: "text/plain" }); + var objectStore = db.transaction("foo", "readwrite").objectStore("foo"); + objectStore.add({ blob }, 42).onsuccess = refetchBlob; + } + + function refetchBlob() { + var foo = db.transaction("foo").objectStore("foo"); + foo.get(42).onsuccess = fetchedBlobCreateWorkerAndSendBlob; + } + + function fetchedBlobCreateWorkerAndSendBlob(event) { + var idbBlob = event.target.result.blob; + var compositeBlob = new Blob(["I like the following blob: ", idbBlob], + { type: "text/fancy" }); + + function workerScript() { + /* eslint-env worker */ + onmessage = function(event) { + // Save the Blob to the worker's global scope. + self.holdOntoBlob = event.data; + // Send any message so we can serialize and keep our runtime behaviour + // consistent. + postMessage("kung fu death grip established"); + }; + } + + var url = + URL.createObjectURL(new Blob(["(", workerScript.toString(), ")()"])); + + // Keep a reference to the worker on the window. + var worker = window.worker = new Worker(url); + worker.postMessage(compositeBlob); + worker.onmessage = workerLatchedBlobDeleteFromDB; + } + + function workerLatchedBlobDeleteFromDB() { + // Delete the reference to the Blob from the database leaving the worker + // thread reference as the only live reference once a GC has cleaned + // out our references that we sent to the worker. The page that owns + // us triggers a GC just for that reason. + var objectStore = db.transaction("foo", "readwrite").objectStore("foo"); + objectStore.delete(42).onsuccess = closeDBTellOwningThread; + } + + function closeDBTellOwningThread(event) { + // Now that worker has latched the blob, clean up the database. + db.close(); + db = null; + report("ready"); + } + + createDatastore(); + } + </script> + +</head> + +<body onload="runIndexedDBTest();"> +</body> + +</html> |