diff --git a/components/serialization/default/index.mjs b/components/serialization/default/index.mjs index 232907269..05dd7574f 100644 --- a/components/serialization/default/index.mjs +++ b/components/serialization/default/index.mjs @@ -124,6 +124,10 @@ export default (dependencies) => { logDebug("%o.toString() failure >> %O", value, error); serial.print = apply(toString, value, noargs); } + if (typeof serial.print !== "string") { + logDebug("%o.toString() returned a non-string result"); + serial.print = apply(toString, value, noargs); + } } else { serial.print = apply(toString, value, noargs); } diff --git a/components/serialization/default/index.test.mjs b/components/serialization/default/index.test.mjs index 408e7b3b2..47d8b68d0 100644 --- a/components/serialization/default/index.test.mjs +++ b/components/serialization/default/index.test.mjs @@ -150,6 +150,22 @@ assertDeepEqual( print: "[object Object]", }, ); +assertDeepEqual( + testSerialize( + { + method: "toString", + "include-constructor-name": false, + }, + { + toString: () => 123, + }, + ), + { + type: "object", + index: 1, + print: "[object Object]", + }, +); // function (toString) assertDeepEqual( testSerialize(