diff --git a/test/harness/assert.js b/test/harness/assert.js new file mode 100644 index 0000000000000000000000000000000000000000..1d9d4a48f22903be816e05fba896b8a07dcb3555 --- /dev/null +++ b/test/harness/assert.js @@ -0,0 +1,42 @@ +function assert(mustBeTrue, message) { + if (mustBeTrue === true) { + return; + } + + if (message === undefined) { + message = 'Expected true but got ' + String(truthy); + } + $ERROR(message); +} + +assert._isSameValue = function (a, b) { + if (a === b) { + // Handle +/-0 vs. -/+0 + return a !== 0 || 1 / a === 1 / b; + } + + // Handle NaN vs. NaN + return a !== a && b !== b; +}; + +assert.sameValue = function (actual, expected, message) { + if (assert._isSameValue(actual, expected)) { + return; + } + + if (message === undefined) { + message = 'Expected SameValue(' + String(actual) + ', ' + String(expected) + ') to be true'; + } + $ERROR(message); +}; + +assert.notSameValue = function (actual, unexpected, message) { + if (!assert._isSameValue(actual, unexpected)) { + return; + } + + if (message === undefined) { + message = 'Expected SameValue(' + String(actual) + ', ' + String(unexpected) + ') to be false'; + } + $ERROR(message); +}; diff --git a/test/suite/es6/Array.prototype.find/Array.prototype.find_this-defined.js b/test/suite/es6/Array.prototype.find/Array.prototype.find_this-defined.js index 88bf029cde9778f8339aab59c290bf5a811a8363..6d25211d396711837c19e9e7b9d28a96e28c0fcb 100644 --- a/test/suite/es6/Array.prototype.find/Array.prototype.find_this-defined.js +++ b/test/suite/es6/Array.prototype.find/Array.prototype.find_this-defined.js @@ -8,10 +8,6 @@ description: thisArg should be bound to this if provided var globalThis = this; [1].find(function () { - if (this !== Array) { - $ERROR('#1: this !== Array'); - } - if (this === globalThis) { - $ERROR('#2: this === globalThis. Should be Array'); - } + assert.sameValue(this, Array, 'this should equal Array'); + assert.notSameValue(this, globalThis, 'this should not equal globalThis'); }, Array);