v8: inspect unserializable objects

This would otherwise sometimes just print relatively useless
information about the value in question, such as `[object Object]`.

PR-URL: https://github.com/nodejs/node/pull/30167
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
This commit is contained in:
Anna Henningsen 2019-10-29 21:24:23 +01:00
parent d855904ef6
commit afd29c9502
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 7 additions and 3 deletions

View File

@ -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);

View File

@ -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 {}'
});
}
{