| <!DOCTYPE html> |
| <body> |
| <script src="../resources/js-test-pre.js"></script> |
| <script> |
| description("Streams should not directly use array public APIs"); |
| jsTestIsAsync = true; |
| |
| const ArrayPushBackup = Array.prototype.push; |
| const ArrayShiftBackup = Array.prototype.shift; |
| |
| Array.prototype.push = function() { |
| testFailed("Array.prototype.push called"); |
| } |
| |
| Array.prototype.shift = function() { |
| testFailed("Array.prototype.shift called"); |
| } |
| |
| function cleanAndFinishTest() { |
| Array.prototype.push = ArrayPushBackup; |
| Array.prototype.shift = ArrayShiftBackup; |
| finishJSTest(); |
| } |
| |
| try { |
| let _controller; |
| const reader = new ReadableStream({ |
| start: function(controller) { |
| _controller = controller; |
| } |
| }).getReader(); |
| |
| // checking whether pushing/shifting pending read promises is shielded. |
| const readPromise = reader.read().then(function(_result) { |
| result = _result; |
| shouldBeEqualToString("result.value", "half baked potato"); |
| // checking whether pushing/shifting enqueued values is shielded. |
| _controller.enqueue("fully baked potato"); |
| return reader.read().then(function(_result) { |
| result = _result; |
| shouldBeEqualToString("result.value", "fully baked potato"); |
| cleanAndFinishTest(); |
| }, cleanAndFinishTest); |
| }, cleanAndFinishTest); |
| _controller.enqueue("half baked potato"); |
| } catch (error) { |
| testFailed("Exception thrown: " + error); |
| cleanAndFinishTest(); |
| } |
| </script> |
| <script src="../resources/js-test-post.js"></script> |
| </body> |