summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html
blob: c8a6d38393c0217447992d47c994942e873e70ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
<!doctype html>
<html>
 <head>
  <meta content="text/html; charset=utf-8" http-equiv="content-type" />
  <title>2.8 Common DOM interfaces - Structured Clone Algorithm </title>
  <link rel="help" href="http://www.w3.org/TR/html5/common-dom-interfaces.html#safe-passing-of-structured-data" />
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
 <div id="log"></div>
 <iframe></iframe> <!-- used for grabbing an URIError from another realm -->

<script type="text/javascript">
    var worker;
    var testCollection;
    setup(function()
    {
        //the worker is used for each test in sequence
        //worker's callback will be set for each test
        //worker's internal onmessage echoes the data back to this thread through postMessage
        worker = new Worker("./resources/echo-worker.js");
        testCollection = [
            function() {
                var t = async_test("Primitive string is cloned");
                t.id = 0;
                worker.onmessage = t.step_func(function(e) {assert_equals("primitive string", e.data, "\"primitive string\" === event.data"); t.done(); });
                t.step(function() { worker.postMessage("primitive string");});
            },
            function() {
                var t = async_test("Primitive integer is cloned");
                t.id = 1;
                worker.onmessage = t.step_func(function(e) {assert_equals(2000, e.data, "2000 === event.data"); t.done(); });
                t.step(function() { worker.postMessage(2000);});
            },
            function() {
                var t = async_test("Primitive floating point is cloned");
                t.id = 2;
                worker.onmessage = t.step_func(function(e) {assert_equals(111.456, e.data, "111.456 === event.data"); t.done(); });
                t.step(function() { worker.postMessage(111.456);});
            },
            function() {
                var t = async_test("Primitive floating point (negative) is cloned");
                t.id = 3;
                worker.onmessage = t.step_func(function(e) {assert_equals(-111.456, e.data, "-111.456 === event.data"); t.done(); });
                t.step(function() { worker.postMessage(-111.456);});
            },
            function() {
                var t = async_test("Primitive number (hex) is cloned");
                t.id = 4;
                worker.onmessage = t.step_func(function(e) {assert_equals(0xAB25, e.data, "0xAB25 === event.data"); t.done(); });
                t.step(function() { worker.postMessage(0xAB25);});
            },
            function() {
                var t = async_test("Primitive number (scientific) is cloned");
                t.id = 5;
                worker.onmessage = t.step_func(function(e) {assert_equals(15e2, e.data, "15e2 === event.data"); t.done(); });
                t.step(function() { worker.postMessage(15e2);});
            },
            function() {
                var t = async_test("Primitive boolean is cloned");
                t.id = 6;
                worker.onmessage = t.step_func(function(e) {assert_equals(false, e.data, "false === event.data"); t.done(); });
                t.step(function() { worker.postMessage(false);});
            },
            function() {
                var t = async_test("Instance of Boolean is cloned");
                t.id = 7;
                var obj;
                t.step(function() {obj = new Boolean(false);});
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "Boolean === event.data.constructor");
                    assert_equals(obj.valueOf(), e.data.valueOf(), "(new Boolean(false)).valueof() === event.data.valueOf()");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },function() {
                var t = async_test("Instance of Number is cloned");
                t.id = 8;
                var obj;
                t.step(function() {obj = new Number(2000);});
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "Number === event.data.constructor");
                    assert_equals(obj.valueOf(), e.data.valueOf(), "(new Number(2000)).valueof() === event.data.valueOf()");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Instance of String is cloned");
                t.id = 9;
                var obj;
                t.step(function() { obj = new String("String Object");});
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "String === event.data.constructor");
                    assert_equals(obj.valueOf(), e.data.valueOf(), "(new String(\"String Object\")).valueof() === event.data.valueOf()");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Instance of Date is cloned");
                t.id = 10;
                var obj;
                t.step(function() { obj= new Date(2011,1,1);});
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "Date === event.data.constructor");
                    assert_equals(obj.valueOf(), e.data.valueOf(), "(new Date(2011,1,1)).valueof() === event.data.valueOf()");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Instance of RegExp is cloned");
                t.id = 11;
                var obj;
                t.step(function() {obj = new RegExp("w3+c","g","i");});
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "RegExp === event.data.constructor");
                    assert_equals(obj.source, e.data.source, "canon.source === event.data.source");
                    assert_equals(obj.multiline, e.data.multiline, "canon.multiline === event.data.multiline");
                    assert_equals(obj.global, e.data.global, "canon.global === event.data.global");
                    assert_equals(obj.ignoreCase, e.data.ignoreCase, "canon.ignoreCase === event.data.ignoreCase");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Value 'null' is cloned");
                t.id = 12;
                worker.onmessage = t.step_func(function(e) {assert_equals(null, e.data, "null === event.data"); t.done(); });
                t.step(function() { worker.postMessage(null);});
            },
            function() {
                var t = async_test("Value 'undefined' is cloned");
                t.id = 13;
                worker.onmessage = t.step_func(function(e) {assert_equals(undefined, e.data, "undefined === event.data"); t.done(); });
                t.step(function() { worker.postMessage(undefined);});
            },
            function() {
                var t = async_test("Object properties are cloned");
                t.id = 14;
                var obj;
                t.step(function() {
                    obj= {};
                    obj.a = "test";
                    obj.b = 2;
                    obj["child"] = 3;
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    assert_equals(obj.a, e.data.a, "canon.a === event.data.a");
                    assert_equals(obj.b, e.data.b, "canon.b === event.data.b");
                    assert_equals(obj.child, e.data.child, "canon.child === e.data.child");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Prototype chains are not walked.");
                t.id = 15;
                function Custom() {
                    this.a = "hello";
                }

                var obj;
                t.step(function() {
                    Object.defineProperty(Custom.prototype, "b", { enumerable: true, value: 100 });
                    obj = new Custom();
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_not_equals(obj.constructor, e.data.constructor, "canon.constructor !== event.data.constructor");
                    assert_equals(Object, e.data.constructor, "Object === e.data.constructor");
                    assert_equals(obj.a, e.data.a, "canon.a === e.data.a");
                    assert_equals(undefined, e.data.b, "undefined === e.data.b");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Property descriptors of Objects are not cloned");
                t.id = 16;
                var obj;
                t.step(function() {
                    obj = {};
                    Object.defineProperty(obj, "a", { enumerable: true, writable: false, value: 100 });
                });
                worker.onmessage = t.step_func(function(e) {
                    var des = Object.getOwnPropertyDescriptor(e.data, "a");
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    assert_true(des.writable, "Descriptor is writable");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Cycles are preserved in Objects");
                t.id = 17;
                var obj;
                t.step(function() {
                    obj = {};
                    obj.a = obj;
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    assert_equals(e.data, e.data.a, "cycle is preserved");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Identity of duplicates is preserved");
                t.id = 18;
                var ref;
                var obj;
                t.step(function() {
                    ref = {};
                    ref.called = 0;
                    Object.defineProperty(ref, "child", {get: function(){this.called++;}, enumerable: true});

                    obj = {a:ref, b:ref};
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    assert_equals(e.data.b.called, 0, "e.data.b.called === 0");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Property order is preserved");
                t.id = 19;
                var obj;
                t.step(function() {
                    obj = { "a": "hello", "b": "w3c", "c": "and world" };
                    obj["a"] = "named1";
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    var canonNames = Object.getOwnPropertyNames(obj);
                    var testNames = Object.getOwnPropertyNames(e.data);
                    for (var i in canonNames) {
                        assert_equals(canonNames[i], testNames[i], "canonProperty["+i+"] === dataProperty["+i+"]");
                    }
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Enumerable properties of Arrays are cloned");
                t.id = 20;
                var obj;
                t.step(function() {
                    obj = [0,1];
                    obj["a"] = "named1";
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    assert_equals(e.data["a"], "named1", "e.data[\"a\"] === \"named1\"");
                    assert_equals(e.data[0], 0, "e.data[0] === 0");
                    assert_equals(e.data[1], 1, "e.data[1] === 1");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Property descriptors of Arrays are not cloned");
                t.id = 21;
                var obj;
                t.step(function() {
                    obj = [0, 1];
                    Object.defineProperty(obj, "2", { enumerable: true, writable: false, value: 100 });
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    assert_equals(e.data[0], 0, "e.data[0] === 0");
                    assert_equals(e.data[1], 1, "e.data[1] === 1");
                    var des = Object.getOwnPropertyDescriptor(e.data, "2");
                    assert_true(des.writable, "Descriptor is writable");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Cycles are preserved in Arrays");
                t.id = 22;
                var obj;
                t.step(function() {
                    obj = [0,1];
                    obj[2] = obj;
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    assert_equals(e.data[0], 0, "e.data[0] === 0");
                    assert_equals(e.data[1], 1, "e.data[1] === 1");
                    assert_equals(e.data[2], e.data, "e.data[2] === e.data");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },

            function() {
                var t = async_test("ImageData object can be cloned");
                t.id = 23;
                var obj;
                t.step(function() {
                    var canvas = document.createElement("canvas");
                    canvas.width = 40;
                    canvas.height = 40;
                    var context = canvas.getContext('2d');
                    obj = context.createImageData(40, 40);
                    assert_true(window.hasOwnProperty("ImageData"), "ImageData constructor must be present");
                    assert_true(obj instanceof ImageData, "ImageData must be returned by .createImageData");
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    assert_not_equals(obj, e.data, "cloned object should be a new instance of ImageData");
                    assert_equals(obj.width, e.data.width, "canon.width === e.data.width");
                    assert_equals(obj.height, e.data.height, "canon.height === e.data.height");
                    assert_array_equals(obj.data, e.data.data, "data arrays are the same");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("ImageData expandos are not cloned");
                t.id = 24;
                var obj;
                t.step(function() {
                    var canvas = document.createElement("canvas");
                    canvas.width = 40;
                    canvas.height = 40;
                    var context = canvas.getContext('2d');
                    obj = context.createImageData(40, 40);
                    assert_true(window.hasOwnProperty("ImageData"), "ImageData constructor must be present");
                    assert_true(obj instanceof ImageData, "ImageData must be returned by .createImageData");
                    obj.foo = "bar";
                });
                worker.onmessage = t.step_func(function(e) {
                    assert_equals(obj.constructor, e.data.constructor, "canon.constructor === event.data.constructor");
                    assert_not_equals(obj, e.data, "cloned object should be a new instance of ImageData");
                    assert_equals(obj.width, e.data.width, "canon.width === e.data.width");
                    assert_equals(obj.height, e.data.height, "canon.height === e.data.height");
                    assert_array_equals(obj.data, e.data.data, "data arrays are the same");
                    assert_equals(undefined, e.data.foo, "Expando is lost (undefined === e.data.foo)");
                    t.done();
                });
                t.step(function() { worker.postMessage(obj);});
            },
            function() {
                var t = async_test("Window objects cannot be cloned");
                t.id = 25;
                worker.onmessage = function() {}; //no op because exception should be thrown.
                t.step(function() {
                    assert_true(DOMException.hasOwnProperty('DATA_CLONE_ERR'), "DOMException.DATA_CLONE_ERR is present");
                    assert_equals(DOMException.DATA_CLONE_ERR, 25, "DOMException.DATA_CLONE_ERR === 25");
                    assert_throws_dom('DATA_CLONE_ERR', function() {worker.postMessage(window)});
                });
                t.done();
            },
            function() {
                var t = async_test("Document objects cannot be cloned");
                t.id = 26;
                worker.onmessage = function() {}; //no op because exception should be thrown.
                t.step(function() {
                    assert_true(DOMException.hasOwnProperty('DATA_CLONE_ERR'), "DOMException.DATA_CLONE_ERR is present");
                    assert_equals(DOMException.DATA_CLONE_ERR, 25, "DOMException.DATA_CLONE_ERR === 25");
                    assert_throws_dom('DATA_CLONE_ERR', function() {worker.postMessage(document)});
                });
                t.done();
            },
            function() {
                var t = async_test("Empty Error objects can be cloned");
                t.id = 27;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, Error, "Checking constructor");
                    assert_equals(e.data.name, "Error", "Checking name");
                    assert_false(e.data.hasOwnProperty("message"), "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = Error();
                    assert_false(error.hasOwnProperty("message"), "Checking message on the source realm");
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("Error objects can be cloned");
                t.id = 28;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, Error, "Checking constructor");
                    assert_equals(e.data.name, "Error", "Checking name");
                    assert_equals(e.data.message, "some message", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = Error("some message");
                    error.foo = "bar";
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("EvalError objects can be cloned");
                t.id = 29;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), EvalError.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, EvalError, "Checking constructor");
                    assert_equals(e.data.name, "EvalError", "Checking name");
                    assert_equals(e.data.message, "some message", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = EvalError("some message");
                    error.foo = "bar";
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("RangeError objects can be cloned");
                t.id = 30;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), RangeError.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, RangeError, "Checking constructor");
                    assert_equals(e.data.name, "RangeError", "Checking name");
                    assert_equals(e.data.message, "some message", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = RangeError("some message");
                    error.foo = "bar";
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("ReferenceError objects can be cloned");
                t.id = 31;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), ReferenceError.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, ReferenceError, "Checking constructor");
                    assert_equals(e.data.name, "ReferenceError", "Checking name");
                    assert_equals(e.data.message, "some message", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = ReferenceError("some message");
                    error.foo = "bar";
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("SyntaxError objects can be cloned");
                t.id = 32;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), SyntaxError.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, SyntaxError, "Checking constructor");
                    assert_equals(e.data.name, "SyntaxError", "Checking name");
                    assert_equals(e.data.message, "some message", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = SyntaxError("some message");
                    error.foo = "bar";
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("TypeError objects can be cloned");
                t.id = 33;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), TypeError.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, TypeError, "Checking constructor");
                    assert_equals(e.data.name, "TypeError", "Checking name");
                    assert_equals(e.data.message, "some message", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = TypeError("some message");
                    error.foo = "bar";
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("URIError objects can be cloned");
                t.id = 34;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), URIError.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, URIError, "Checking constructor");
                    assert_equals(e.data.name, "URIError", "Checking name");
                    assert_equals(e.data.message, "some message", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = URIError("some message");
                    error.foo = "bar";
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("URIError objects from other realms are treated as URIError");
                t.id = 35;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), URIError.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, URIError, "Checking constructor");
                    assert_equals(e.data.name, "URIError", "Checking name");
                    assert_equals(e.data.message, "some message", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = frames[0].URIError("some message");
                    assert_equals(Object.getPrototypeOf(error), frames[0].URIError.prototype, "Checking prototype before cloning");
                    assert_equals(error.constructor, frames[0].URIError, "Checking constructor before cloning");
                    assert_equals(error.name, "URIError", "Checking name before cloning");
                    error.foo = "bar";
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("Cloning a modified Error");
                t.id = 36;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), TypeError.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, TypeError, "Checking constructor");
                    assert_equals(e.data.name, "TypeError", "Checking name");
                    assert_equals(e.data.message, "another message", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = URIError("some message");
                    Object.setPrototypeOf(error, SyntaxError.prototype);
                    error.message = {toString: () => "another message" }
                    error.constructor = RangeError;
                    error.name = "TypeError";
                    error.foo = "bar";
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("Error.message: getter is ignored when cloning");
                t.id = 37;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, Error, "Checking constructor");
                    assert_equals(e.data.name, "Error", "Checking name");
                    assert_false(e.data.hasOwnProperty("message"), "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = Error();
                    Object.defineProperty(error, "message", { get: () => "hello" });
                    assert_equals(error.message, "hello", "Checking message on the source realm");
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("Error.message: undefined property is stringified");
                t.id = 38;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, Error, "Checking constructor");
                    assert_equals(e.data.name, "Error", "Checking name");
                    assert_equals(e.data.message, "undefined", "Checking message");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = Error();
                    error.message = undefined;
                    assert_equals(error.message, undefined, "Checking message on the source realm");
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("DOMException objects can be cloned");
                t.id = 39;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), DOMException.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, DOMException, "Checking constructor");
                    assert_equals(e.data.name, "IndexSizeError", "Checking name");
                    assert_equals(e.data.message, "some message", "Checking message");
                    assert_equals(e.data.code, DOMException.INDEX_SIZE_ERR, "Checking code");
                    assert_equals(e.data.foo, undefined, "Checking custom property");
                });
                t.step(function() {
                    const error = new DOMException("some message", "IndexSizeError");
                    worker.postMessage(error);
                });
            },
            function() {
                var t = async_test("DOMException objects created by the UA can be cloned");
                t.id = 40;
                worker.onmessage = t.step_func_done(function(e) {
                    assert_equals(Object.getPrototypeOf(e.data), DOMException.prototype, "Checking prototype");
                    assert_equals(e.data.constructor, DOMException, "Checking constructor");
                    assert_equals(e.data.code, DOMException.DATA_CLONE_ERR, "Checking code");
                    assert_equals(e.data.name, "DataCloneError", "Checking name");
                });
                t.step(function() {
                    try {
                        worker.postMessage(window);
                    } catch (error) {
                        worker.postMessage(error);
                        return;
                    }
                    assert_unreached("Window must not be clonable");
                });
            },
        ];
    }, {explicit_done:true});

    //Callback for result_callback
    //queues the next test in the array testCollection
    //serves to make test execution sequential from the async worker callbacks
    //alternatively, we would have to create a worker for each test
    function testFinished(test) {
        if(test.id < testCollection.length - 1) {
            //queue the function so that stack remains shallow
            queue(testCollection[test.id+1]);
        } else {
            //when the last test has run, explicitly end test suite
            done();
        }
    }
    function queue(func) {
        step_timeout(func, 10);
    }

    add_result_callback(testFinished);
    //start the first test manually
    queue(testCollection[0]);




 </script>
</body>
</html>