Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / indexedDB / test / blob_worker_crash_iframe.html
blob15d8277515c9b8c7001fefacc004940dd5cd7b8d
1 <!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
5 <html>
6 <head>
7 <title>Indexed Database Test</title>
9 <script type="text/javascript">
10 function report(result) {
11 var message = { source: "iframe" };
12 message.result = result;
13 window.parent.postMessage(message, "*");
16 function runIndexedDBTest() {
17 var db = null;
19 // Create the data-store
20 function createDatastore() {
21 try {
22 var request = indexedDB.open(window.location.pathname, 1);
23 request.onupgradeneeded = function(event) {
24 event.target.result.createObjectStore("foo");
26 request.onsuccess = function(event) {
27 db = event.target.result;
28 createAndStoreBlob();
31 catch (e) {
32 dump("EXCEPTION IN CREATION: " + e + "\n " + e.stack + "\n");
33 report(false);
37 function createAndStoreBlob() {
38 const BLOB_DATA = ["fun ", "times ", "all ", "around!"];
39 var blob = new Blob(BLOB_DATA, { type: "text/plain" });
40 var objectStore = db.transaction("foo", "readwrite").objectStore("foo");
41 objectStore.add({ blob }, 42).onsuccess = refetchBlob;
44 function refetchBlob() {
45 var foo = db.transaction("foo").objectStore("foo");
46 foo.get(42).onsuccess = fetchedBlobCreateWorkerAndSendBlob;
49 function fetchedBlobCreateWorkerAndSendBlob(event) {
50 var idbBlob = event.target.result.blob;
51 var compositeBlob = new Blob(["I like the following blob: ", idbBlob],
52 { type: "text/fancy" });
54 function workerScript() {
55 /* eslint-env worker */
56 onmessage = function(event) {
57 // Save the Blob to the worker's global scope.
58 self.holdOntoBlob = event.data;
59 // Send any message so we can serialize and keep our runtime behaviour
60 // consistent.
61 postMessage("kung fu death grip established");
65 var url =
66 URL.createObjectURL(new Blob(["(", workerScript.toString(), ")()"]));
68 // Keep a reference to the worker on the window.
69 var worker = window.worker = new Worker(url);
70 worker.postMessage(compositeBlob);
71 worker.onmessage = workerLatchedBlobDeleteFromDB;
74 function workerLatchedBlobDeleteFromDB() {
75 // Delete the reference to the Blob from the database leaving the worker
76 // thread reference as the only live reference once a GC has cleaned
77 // out our references that we sent to the worker. The page that owns
78 // us triggers a GC just for that reason.
79 var objectStore = db.transaction("foo", "readwrite").objectStore("foo");
80 objectStore.delete(42).onsuccess = closeDBTellOwningThread;
83 function closeDBTellOwningThread(event) {
84 // Now that worker has latched the blob, clean up the database.
85 db.close();
86 db = null;
87 report("ready");
90 createDatastore();
92 </script>
94 </head>
96 <body onload="runIndexedDBTest();">
97 </body>
99 </html>