summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-throw-onmessage.https.html
blob: 3a480464e9d8ff9b8747eb02ada05c52f4d118e0 (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
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>
      Test the behaviour of AudioWorkletProcessor when an `onmessage` handler
      throws.
    </title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/webaudio/js/helpers.js"></script>
  </head>

  <body>
    <script id="processor" type="worklet">
      registerProcessor("test-throw", class param extends AudioWorkletProcessor {
        constructor() {
          super()
          this.i = 0;
          this.port.onmessage = function(arg) {
            throw "asdasd";
          }
        }
        process(input, output, parameters) {
          this.i++;
          this.port.postMessage(this.i);
          return true;
        }
      });
    </script>
    <script>
      var latestIndexReceived = 0;
      var node = null;
      var ac = null;
      promise_setup(function() {
        ac = new AudioContext();
        var url = URLFromScriptsElements(["processor"]);
        return ac.audioWorklet.addModule(url).then(function() {
          node = new AudioWorkletNode(ac, "test-throw");
          node.port.onmessage = function(e) {
            latestIndexReceived = parseInt(e.data);
          };
        });
      });
      promise_test(async t => {
        var currentIndex = latestIndexReceived;
        await t.step_wait(() => {
          return latestIndexReceived > currentIndex;
        }, "Process is still being called");

        node.port.postMessage("asdasd"); // This throws on the processor side.
        node.onprocessorerror = function() {
          assert_true(false, "onprocessorerror must not be called.");
        };
        currentIndex = latestIndexReceived;
        await t.step_wait(() => {
          return latestIndexReceived > currentIndex + 2;
        }, "Process is still being called");
      }, `Throwing in an onmessage handler in the AudioWorkletGlobalScope shouldn't stop AudioWorkletProcessor`);
    </script>
  </body>
</html>