From a3decc4cb9515ea36aed3df7392a0aaf7467a27f Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 27 Mar 2017 20:57:22 +0200 Subject: [PATCH] =?UTF-8?q?[squash]=20fix=20bug=20from=20targos=E2=80=99?= =?UTF-8?q?=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v8.js | 7 ++++++- test/parallel/test-v8-serdes.js | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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');