From f36e8593dd46295237da94b28714dc11ec3c603b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 29 Oct 2019 21:24:23 +0100 Subject: [PATCH 1/2] v8: inspect unserializable objects This would otherwise sometimes just print relatively useless information about the value in question, such as `[object Object]`. --- lib/v8.js | 4 +++- test/parallel/test-v8-serdes.js | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/v8.js b/lib/v8.js index 1a8c70c6d75d3f..5be59cb935cfcf 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -24,6 +24,7 @@ const { } = internalBinding('serdes'); const assert = require('internal/assert'); const { copy } = internalBinding('buffer'); +const { inspect } = require('internal/util/inspect'); const { FastBuffer } = require('internal/buffer'); const { getValidatedPath } = require('internal/fs/utils'); const { toNamespacedPath } = require('path'); @@ -242,7 +243,8 @@ class DefaultSerializer extends Serializer { i = arrayBufferViewTypeToIndex.get(tag); if (i === undefined) { - throw new this._getDataCloneError(`Unknown host object type: ${tag}`); + throw new this._getDataCloneError( + `Unserializable host object: ${inspect(abView)}`); } } this.writeUint32(i); diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 58b919066ea990..8be5aed22df6bc 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -156,8 +156,10 @@ const deserializerTypeError = } { - assert.throws(() => v8.serialize(hostObject), - /^Error: Unknown host object type: \[object .*\]$/); + assert.throws(() => v8.serialize(hostObject), { + constructor: Error, + message: 'Unserializable host object: JSStream {}' + }); } { From 001ae3459572e79a18787707911136dfe9f5a031 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 1 Nov 2019 20:16:47 +0100 Subject: [PATCH 2/2] fixup! v8: inspect unserializable objects --- test/parallel/test-v8-serdes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-v8-serdes.js b/test/parallel/test-v8-serdes.js index 8be5aed22df6bc..a992ba42ce46bf 100644 --- a/test/parallel/test-v8-serdes.js +++ b/test/parallel/test-v8-serdes.js @@ -157,9 +157,9 @@ const deserializerTypeError = { assert.throws(() => v8.serialize(hostObject), { - constructor: Error, - message: 'Unserializable host object: JSStream {}' - }); + constructor: Error, + message: 'Unserializable host object: JSStream {}' + }); } {