Bug 1556663 [wpt PR 17159] - Add optional test for cloning of error stacks, a=testonly
[gecko.git] / testing / web-platform / tests / html / infrastructure / safe-passing-of-structured-data / structured_clone_bigint.html
blob995edac8da9d95ac6f151863b5cd48994941a347
1 <!doctype html>
2 <html>
3 <head>
4 <meta content="text/html; charset=utf-8" http-equiv="content-type" />
5 <title>2.7 Safe passing of structured data</title>
6 <link rel="help" href="https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data" />
7 <script src="/resources/testharness.js"></script>
8 <script src="/resources/testharnessreport.js"></script>
9 </head>
10 <body>
11 <div id="log"></div>
13 <script type="text/javascript">
14 // Note, this test is designed to be in a similar style to
15 // html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html
16 // It is in a separate file to avoid causing a syntax error on UAs which
17 // do not yet support BigInt, so the rest of the test can continue running.
19 var worker;
20 var testCollection;
21 setup(function()
23 //the worker is used for each test in sequence
24 //worker's callback will be set for each test
25 //worker's internal onmessage echoes the data back to this thread through postMessage
26 worker = new Worker("./resources/echo-worker.js");
27 testCollection = [
28 function() {
29 var t = async_test("Primitive BigInt is cloned");
30 t.id = 0;
31 worker.onmessage = t.step_func(function(e) {assert_equals(1n, e.data, "1n === event.data"); t.done(); });
32 t.step(function() { worker.postMessage(1n);});
34 function() {
35 var t = async_test("Instance of BigInt is cloned");
36 t.id = 1;
37 var obj;
38 t.step(function() {obj = Object(1n);});
39 worker.onmessage = t.step_func(function(e) {
40 assert_equals(obj.constructor, e.data.constructor, "BigInt === event.data.constructor");
41 assert_equals(obj.valueOf(), e.data.valueOf(), "(BigInt(1n)).valueOf() === event.data.valueOf()");
42 t.done();
43 });
44 t.step(function() { worker.postMessage(obj);});
47 }, {explicit_done:true});
49 //Callback for result_callback
50 //queues the next test in the array testCollection
51 //serves to make test execution sequential from the async worker callbacks
52 //alternatively, we would have to create a worker for each test
53 function testFinished(test) {
54 if(test.id < testCollection.length - 1) {
55 //queue the function so that stack remains shallow
56 queue(testCollection[test.id+1]);
57 } else {
58 //when the last test has run, explicitly end test suite
59 done();
62 function queue(func) {
63 step_timeout(func, 10);
66 add_result_callback(testFinished);
67 //start the first test manually
68 queue(testCollection[0]);
73 </script>
74 </body>
75 </html>