11cb0ef41Sopenharmony_ci// Flags: --expose-internals --no-warnings
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst {
61cb0ef41Sopenharmony_ci  JSTransferable, kTransfer, kTransferList
71cb0ef41Sopenharmony_ci} = require('internal/worker/js_transferable');
81cb0ef41Sopenharmony_ciconst { MessageChannel } = require('worker_threads');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci// Transferring a JSTransferable that refers to another, untransferable, value
111cb0ef41Sopenharmony_ci// in its transfer list should not crash hard.
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciclass OuterTransferable extends JSTransferable {
141cb0ef41Sopenharmony_ci  constructor() {
151cb0ef41Sopenharmony_ci    super();
161cb0ef41Sopenharmony_ci    // Create a detached MessagePort at this.inner
171cb0ef41Sopenharmony_ci    const c = new MessageChannel();
181cb0ef41Sopenharmony_ci    this.inner = c.port1;
191cb0ef41Sopenharmony_ci    c.port2.postMessage(this.inner, [ this.inner ]);
201cb0ef41Sopenharmony_ci  }
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  [kTransferList] = common.mustCall(() => {
231cb0ef41Sopenharmony_ci    return [ this.inner ];
241cb0ef41Sopenharmony_ci  });
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  [kTransfer] = common.mustCall(() => {
271cb0ef41Sopenharmony_ci    return {
281cb0ef41Sopenharmony_ci      data: { inner: this.inner },
291cb0ef41Sopenharmony_ci      deserializeInfo: 'does-not:matter'
301cb0ef41Sopenharmony_ci    };
311cb0ef41Sopenharmony_ci  });
321cb0ef41Sopenharmony_ci}
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ciconst { port1 } = new MessageChannel();
351cb0ef41Sopenharmony_ciconst ot = new OuterTransferable();
361cb0ef41Sopenharmony_ciassert.throws(() => {
371cb0ef41Sopenharmony_ci  port1.postMessage(ot, [ot]);
381cb0ef41Sopenharmony_ci}, { name: 'DataCloneError' });
39