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 <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: David Carlier <[email protected]>
  • Loading branch information
addaleax authored and MylesBorins committed Nov 17, 2019
1 parent 2ec40c2 commit 9b11bdb
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 9b11bdb

Please sign in to comment.