Update LayoutTests/resources/testharness.js
[WebKit-https.git] / LayoutTests / streams / streams-public-array-api.html
1 <!DOCTYPE html>
2 <body>
3 <script src="../resources/js-test-pre.js"></script>
4 <script>
5     description("Streams should not directly use array public APIs");
6     jsTestIsAsync = true;
7
8     const ArrayPushBackup = Array.prototype.push;
9     const ArrayShiftBackup = Array.prototype.shift;
10
11     Array.prototype.push = function() {
12         testFailed("Array.prototype.push called");
13     }
14
15     Array.prototype.shift = function() {
16         testFailed("Array.prototype.shift called");
17     }
18
19     function cleanAndFinishTest() {
20         Array.prototype.push = ArrayPushBackup;
21         Array.prototype.shift = ArrayShiftBackup;
22         finishJSTest();
23     }
24
25     try {
26         let _controller;
27         const reader = new ReadableStream({
28             start: function(controller) {
29                 _controller = controller;
30             }
31         }).getReader();
32
33         // checking whether pushing/shifting pending read promises is shielded.
34         const readPromise = reader.read().then(function(_result) {
35             result = _result;
36             shouldBeEqualToString("result.value", "half baked potato");
37             // checking whether pushing/shifting enqueued values is shielded.
38             _controller.enqueue("fully baked potato");
39             return reader.read().then(function(_result) {
40                 result = _result;
41                 shouldBeEqualToString("result.value", "fully baked potato");
42                 cleanAndFinishTest();
43             }, cleanAndFinishTest);
44         }, cleanAndFinishTest);
45         _controller.enqueue("half baked potato");
46     } catch (error) {
47         testFailed("Exception thrown: " + error);
48         cleanAndFinishTest();
49     }
50 </script>
51 <script src="../resources/js-test-post.js"></script>
52 </body>