structured-cloning-error-extra.html (1387B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Structured cloning of Error objects: extra tests</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <!-- Most tests are in the general framework in structuredclone_0.html. 8 This contains specialty tests that don't fit into that framework. --> 9 10 <body> 11 12 <script> 13 "use strict"; 14 test(t => { 15 const exceptionToThrow = new Error("throw me!"); 16 17 const badError = new Error(); 18 Object.defineProperty(badError, "name", { get() { throw exceptionToThrow; } }); 19 20 const worker = new Worker("./resources/echo-worker.js"); 21 t.add_cleanup(() => worker.terminate()); 22 23 assert_throws_exactly(exceptionToThrow, () => { 24 worker.postMessage(badError); 25 }); 26 }, "Throwing name getter fails serialization"); 27 28 // https://bugs.chromium.org/p/chromium/issues/detail?id=1030086 29 // https://github.com/whatwg/html/pull/5150 30 async_test(t => { 31 window.onmessage = t.step_func_done(e => { 32 assert_equals(e.data.name, "TypeError"); 33 }); 34 35 const iframe = document.createElement("iframe"); 36 iframe.onload = () => { 37 if (iframe.contentWindow.location === "about:blank") { 38 return; 39 } 40 41 iframe.contentWindow.doIt(); 42 }; 43 iframe.src = "resources/post-parent-type-error.html"; 44 document.body.append(iframe); 45 }, "Errors sent across realms should preserve their type"); 46 </script>