diff --git a/harness/assert.js b/harness/assert.js index 34eed55eef..78000e3900 100644 --- a/harness/assert.js +++ b/harness/assert.js @@ -101,18 +101,30 @@ assert.throws = function (expectedErrorConstructor, func, message) { throw new Test262Error(message); }; +assert._formatIdentityFreeValue = function formatIdentityFreeValue(value) { + switch (typeof value) { + case 'string': + return typeof JSON !== "undefined" ? JSON.stringify(value) : `"${value}"`; + case 'bigint': + return `${value}n`; + case 'boolean': + case 'undefined': + case 'number': + return value === 0 && 1 / value === -Infinity ? '-0' : String(value); + default: + if (value === null) return 'null'; + } +}; + assert._toString = function (value) { + var basic = assert._formatIdentityFreeValue(value); + if (basic) return basic; try { - if (value === 0 && 1 / value === -Infinity) { - return '-0'; - } - return String(value); } catch (err) { if (err.name === 'TypeError') { return Object.prototype.toString.call(value); } - throw err; } }; diff --git a/harness/deepEqual.js b/harness/deepEqual.js index 0dd3bcbe4d..674b461aa3 100644 --- a/harness/deepEqual.js +++ b/harness/deepEqual.js @@ -28,15 +28,15 @@ assert.deepEqual.format = (function () { let renderUsage = usage => usage.used ? ` as #${usage.id}` : ''; return function format(value, seen) { + let basic = assert._formatIdentityFreeValue(value); + if (basic) return basic; switch (typeof value) { case 'string': - return typeof JSON !== "undefined" ? JSON.stringify(value) : `"${value}"`; case 'bigint': - return `${value}n`; case 'boolean': case 'undefined': case 'number': - return value === 0 && 1 / value === -Infinity ? '-0' : String(value); + assert(false, 'values without identity should use basic formatting'); case 'symbol': case 'function': case 'object':