• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals --no-warnings
2'use strict';
3const common = require('../common');
4const assert = require('assert');
5const {
6  JSTransferable, kTransfer, kTransferList
7} = require('internal/worker/js_transferable');
8const { MessageChannel } = require('worker_threads');
9
10// Transferring a JSTransferable that refers to another, untransferable, value
11// in its transfer list should not crash hard.
12
13class OuterTransferable extends JSTransferable {
14  constructor() {
15    super();
16    // Create a detached MessagePort at this.inner
17    const c = new MessageChannel();
18    this.inner = c.port1;
19    c.port2.postMessage(this.inner, [ this.inner ]);
20  }
21
22  [kTransferList] = common.mustCall(() => {
23    return [ this.inner ];
24  });
25
26  [kTransfer] = common.mustCall(() => {
27    return {
28      data: { inner: this.inner },
29      deserializeInfo: 'does-not:matter'
30    };
31  });
32}
33
34const { port1 } = new MessageChannel();
35const ot = new OuterTransferable();
36assert.throws(() => {
37  port1.postMessage(ot, [ot]);
38}, { name: 'DataCloneError' });
39