Skip to content

Commit

Permalink
v8: inspect unserializable objects
Browse files Browse the repository at this point in the history
This would otherwise sometimes just print relatively useless
information about the value in question, such as `[object Object]`.

PR-URL: #30167
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
addaleax authored and targos committed Dec 1, 2019
1 parent b1f4507 commit 2b162a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/v8.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-v8-serdes.js
Expand Up @@ -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 {}'
});
}

{
Expand Down

0 comments on commit 2b162a8

Please sign in to comment.