diff --git a/lib/v8.js b/lib/v8.js index 7334a372a80ae7..7790f9b3343087 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -140,7 +140,12 @@ class DefaultSerializer extends Serializer { if (abView.constructor === Buffer) { i = bufferConstructorIndex; } else { - i = arrayBufferViewTypeToIndex.get(objectToString(abView)); + const tag = objectToString(abView); + i = arrayBufferViewTypeToIndex.get(tag); + + if (i === undefined) { + throw this._getDataCloneError(`Unknown host object type: ${tag}`); + } } this.writeUint32(i); this.writeUint32(abView.byteLength); diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 428883bb300a83..84037b6f8c8f6f 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -99,6 +99,11 @@ const objects = [ }, /foobar/); } +{ + assert.throws(() => v8.serialize(process.stdin._handle), + /^Error: Unknown host object type: \[object .*\]$/); +} + { const buf = Buffer.from('ff0d6f2203666f6f5e007b01', 'hex');