summaryrefslogtreecommitdiff
path: root/test/parallel/test-async-wrap-missing-method.js
blob: 038a77fba659645cf8e59d50a00995d25ddecb4f (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
'use strict';
const common = require('../common');
const assert = require('assert');

const { MessageChannel } = require('worker_threads');

{
  const { port1, port2 } = new MessageChannel();

  // Returning a non-function in the getter should not crash.
  Object.defineProperty(port1, 'onmessage', {
    get() {
      port1.unref();
      return 42;
    }
  });

  port2.postMessage({ foo: 'bar' });

  // We need to start the port manually because .onmessage assignment tracking
  // has been overridden.
  port1.start();
  port1.ref();
}

{
  const err = new Error('eyecatcher');
  process.on('uncaughtException', common.mustCall((exception) => {
    port1.unref();
    assert.strictEqual(exception, err);
  }));

  const { port1, port2 } = new MessageChannel();

  // Throwing in the getter should not crash.
  Object.defineProperty(port1, 'onmessage', {
    get() {
      throw err;
    }
  });

  port2.postMessage({ foo: 'bar' });

  // We need to start the port manually because .onmessage assignment tracking
  // has been overridden.
  port1.start();
  port1.ref();
}