0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 20:29:23 +01:00
nodejs/test/parallel/test-worker-message-port-jstransferable-nested-untransferable.js
Chengzhong Wu 38dee8a1c0
src: distinguish HTML transferable and cloneable
The HTML structured serialize algorithm treats transferable and
serializable as two different bits. A web platform interface can be
both transferable and serializable.

Splits BaseObject::TransferMode to be able to compose the two bits
and distinguishes the transferable and cloneable.

PR-URL: https://github.com/nodejs/node/pull/47956
Refs: cf13b9b465
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
2023-07-07 17:00:00 +00:00

39 lines
1.0 KiB
JavaScript

// Flags: --expose-internals --no-warnings
'use strict';
const common = require('../common');
const assert = require('assert');
const {
markTransferMode, kTransfer, kTransferList
} = require('internal/worker/js_transferable');
const { MessageChannel } = require('worker_threads');
// Transferring a JSTransferable that refers to another, untransferable, value
// in its transfer list should not crash hard.
class OuterTransferable {
constructor() {
markTransferMode(this, false, true);
// Create a detached MessagePort at this.inner
const c = new MessageChannel();
this.inner = c.port1;
c.port2.postMessage(this.inner, [ this.inner ]);
}
[kTransferList] = common.mustCall(() => {
return [ this.inner ];
});
[kTransfer] = common.mustCall(() => {
return {
data: { inner: this.inner },
deserializeInfo: 'does-not:matter'
};
});
}
const { port1 } = new MessageChannel();
const ot = new OuterTransferable();
assert.throws(() => {
port1.postMessage(ot, [ot]);
}, { name: 'DataCloneError' });