11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst fs = require('fs').promises;
51cb0ef41Sopenharmony_ciconst { MessageChannel } = require('worker_threads');
61cb0ef41Sopenharmony_ciconst { once } = require('events');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// Test that overriding the internal kTransfer method of a JSTransferable does
91cb0ef41Sopenharmony_ci// not enable loading arbitrary code from the disk.
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cimodule.exports = {
121cb0ef41Sopenharmony_ci  NotARealClass: common.mustNotCall()
131cb0ef41Sopenharmony_ci};
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci(async function() {
161cb0ef41Sopenharmony_ci  const fh = await fs.open(__filename);
171cb0ef41Sopenharmony_ci  assert.strictEqual(fh.constructor.name, 'FileHandle');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  const kTransfer = Object.getOwnPropertySymbols(Object.getPrototypeOf(fh))
201cb0ef41Sopenharmony_ci    .filter((symbol) => symbol.description === 'messaging_transfer_symbol')[0];
211cb0ef41Sopenharmony_ci  assert.strictEqual(typeof kTransfer, 'symbol');
221cb0ef41Sopenharmony_ci  fh[kTransfer] = () => {
231cb0ef41Sopenharmony_ci    return {
241cb0ef41Sopenharmony_ci      data: '✨',
251cb0ef41Sopenharmony_ci      deserializeInfo: `${__filename}:NotARealClass`
261cb0ef41Sopenharmony_ci    };
271cb0ef41Sopenharmony_ci  };
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  const { port1, port2 } = new MessageChannel();
301cb0ef41Sopenharmony_ci  port1.postMessage(fh, [ fh ]);
311cb0ef41Sopenharmony_ci  port2.on('message', common.mustNotCall());
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  const [ exception ] = await once(port2, 'messageerror');
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  assert.match(exception.message, /Missing internal module/);
361cb0ef41Sopenharmony_ci  port2.close();
371cb0ef41Sopenharmony_ci})().then(common.mustCall());
38