11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { MessageChannel, markAsUntransferable } = require('worker_threads');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci{
71cb0ef41Sopenharmony_ci  const ab = new ArrayBuffer(8);
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci  markAsUntransferable(ab);
101cb0ef41Sopenharmony_ci  assert.strictEqual(ab.byteLength, 8);
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci  const { port1, port2 } = new MessageChannel();
131cb0ef41Sopenharmony_ci  port1.postMessage(ab, [ ab ]);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  assert.strictEqual(ab.byteLength, 8);  // The AB is not detached.
161cb0ef41Sopenharmony_ci  port2.once('message', common.mustCall());
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci{
201cb0ef41Sopenharmony_ci  const channel1 = new MessageChannel();
211cb0ef41Sopenharmony_ci  const channel2 = new MessageChannel();
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  markAsUntransferable(channel2.port1);
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  assert.throws(() => {
261cb0ef41Sopenharmony_ci    channel1.port1.postMessage(channel2.port1, [ channel2.port1 ]);
271cb0ef41Sopenharmony_ci  }, /was found in message but not listed in transferList/);
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  channel2.port1.postMessage('still works, not closed/transferred');
301cb0ef41Sopenharmony_ci  channel2.port2.once('message', common.mustCall());
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci{
341cb0ef41Sopenharmony_ci  for (const value of [0, null, false, true, undefined, [], {}]) {
351cb0ef41Sopenharmony_ci    markAsUntransferable(value);  // Has no visible effect.
361cb0ef41Sopenharmony_ci  }
371cb0ef41Sopenharmony_ci}
38