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>
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.
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");
29 var t
= async_test("Primitive BigInt is cloned");
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
);});
35 var t
= async_test("Instance of BigInt is cloned");
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()");
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]);
58 //when the last test has run, explicitly end test suite
62 function queue(func
) {
63 step_timeout(func
, 10);
66 add_result_callback(testFinished
);
67 //start the first test manually
68 queue(testCollection
[0]);