From 21e627b35daa98ba7f725a3565cf54f31ab57b5e Mon Sep 17 00:00:00 2001 From: rwaldron Date: Wed, 11 Aug 2021 10:42:40 -0400 Subject: [PATCH] Transform legacy format to harness assertions --- .../Array/prototype/join/S15.4.4.5_A2_T4.js | 98 +++++--------- .../Array/prototype/join/S15.4.4.5_A3.1_T2.js | 107 ++++++++------- .../Array/prototype/join/S15.4.4.5_A3.2_T2.js | 42 ++---- .../Array/prototype/join/S15.4.4.5_A6.7.js | 11 +- .../Array/prototype/pop/S15.4.4.6_A2_T4.js | 74 ++++------- .../Array/prototype/pop/S15.4.4.6_A5.7.js | 11 +- .../Array/prototype/push/S15.4.4.7_A2_T3.js | 75 ++++------- .../Array/prototype/push/S15.4.4.7_A3.js | 21 ++- .../Array/prototype/push/S15.4.4.7_A6.7.js | 11 +- .../Array/prototype/reverse/S15.4.4.8_A5.7.js | 11 +- .../Array/prototype/shift/S15.4.4.9_A2_T5.js | 74 ++++------- .../Array/prototype/shift/S15.4.4.9_A5.7.js | 11 +- .../Array/prototype/slice/S15.4.4.10_A3_T1.js | 24 ++-- .../Array/prototype/slice/S15.4.4.10_A3_T2.js | 23 ++-- .../Array/prototype/slice/S15.4.4.10_A5.7.js | 11 +- .../Array/prototype/sort/S15.4.4.11_A5_T1.js | 17 +-- .../Array/prototype/sort/S15.4.4.11_A7.7.js | 11 +- .../Array/prototype/splice/S15.4.4.12_A5.7.js | 11 +- .../toLocaleString/S15.4.4.3_A4.7.js | 11 +- .../prototype/toString/S15.4.4.2_A1_T4.js | 125 +++++------------- .../prototype/toString/S15.4.4.2_A4.7.js | 11 +- .../prototype/unshift/S15.4.4.13_A2_T3.js | 74 ++++------- .../prototype/unshift/S15.4.4.13_A5.7.js | 11 +- 23 files changed, 320 insertions(+), 555 deletions(-) diff --git a/test/built-ins/Array/prototype/join/S15.4.4.5_A2_T4.js b/test/built-ins/Array/prototype/join/S15.4.4.5_A2_T4.js index 3c1fa2d431..b84d697950 100644 --- a/test/built-ins/Array/prototype/join/S15.4.4.5_A2_T4.js +++ b/test/built-ins/Array/prototype/join/S15.4.4.5_A2_T4.js @@ -15,112 +15,80 @@ var obj = {}; obj.join = Array.prototype.join; obj.length = { - valueOf: function() { + valueOf() { return 3 } }; -if (obj.join() !== ",,") { - throw new Test262Error('#1: obj.length = {valueOf: function() {return 3}} obj.join() === ",,". Actual: ' + (obj.join())); -} +assert.sameValue(obj.join(), ",,", 'obj.join() must return ",,"'); obj.length = { - valueOf: function() { + valueOf() { return 3 }, - toString: function() { + toString() { return 2 } }; -if (obj.join() !== ",,") { - throw new Test262Error('#2: obj.length = {valueOf: function() {return 3}, toString: function() {return 2}} obj.join() === ",,". Actual: ' + (obj.join())); -} +assert.sameValue(obj.join(), ",,", 'obj.join() must return ",,"'); obj.length = { - valueOf: function() { + valueOf() { return 3 }, - toString: function() { + toString() { return {} } }; -if (obj.join() !== ",,") { - throw new Test262Error('#3: obj.length = {valueOf: function() {return 3}, toString: function() {return {}}} obj.join() === ",,". Actual: ' + (obj.join())); -} - -try { - obj.length = { - valueOf: function() { - return 3 - }, - toString: function() { - throw "error" - } - }; - if (obj.join() !== ",,") { - throw new Test262Error('#4.1: obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.join() === ",". Actual: ' + (obj.join())); - } -} -catch (e) { - if (e === "error") { - throw new Test262Error('#4.2: obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.join() not throw "error"'); - } else { - throw new Test262Error('#4.3: obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.join() not throw Error. Actual: ' + (e)); - } -} +assert.sameValue(obj.join(), ",,", 'obj.join() must return ",,"'); obj.length = { - toString: function() { + valueOf() { + return 3 + }, + toString() { + throw new Test262Error(); + } +}; +assert.sameValue(obj.join(), ",,", 'obj.join() must return ",,"'); + +obj.length = { + toString() { return 2 } }; -if (obj.join() !== ",") { - throw new Test262Error('#5: obj.length = {toString: function() {return 2}} obj.join() === ",". Actual: ' + (obj.join())); -} +assert.sameValue(obj.join(), ",", 'obj.join() must return ","'); obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return 2 } } -if (obj.join() !== ",") { - throw new Test262Error('#6: obj.length = {valueOf: function() {return {}}, toString: function() {return 2}} obj.join() === ",". Actual: ' + (obj.join())); -} +assert.sameValue(obj.join(), ",", 'obj.join() must return ","'); -try { +assert.throws(Test262Error, () => { obj.length = { - valueOf: function() { - throw "error" + valueOf() { + throw new Test262Error(); }, - toString: function() { + toString() { return 2 } }; obj.join(); - throw new Test262Error('#7.1: obj.length = {valueOf: function() {throw "error"}, toString: function() {return 2}}; obj.join() throw "error". Actual: ' + (obj.join())); -} -catch (e) { - if (e !== "error") { - throw new Test262Error('#7.2: obj.length = {valueOf: function() {throw "error"}, toString: function() {return 2}}; obj.join() throw "error". Actual: ' + (e)); - } -} +}); -try { +assert.throws(TypeError, () => { obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return {} } }; obj.join(); - throw new Test262Error('#8.1: obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.join() throw TypeError. Actual: ' + (obj.join())); -} -catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#8,2: obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.join() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/join/S15.4.4.5_A3.1_T2.js b/test/built-ins/Array/prototype/join/S15.4.4.5_A3.1_T2.js index c7ee77ad80..213011db07 100644 --- a/test/built-ins/Array/prototype/join/S15.4.4.5_A3.1_T2.js +++ b/test/built-ins/Array/prototype/join/S15.4.4.5_A3.1_T2.js @@ -11,127 +11,134 @@ description: > var x = new Array(0, 1, 2, 3); var object = { - valueOf: function() { + valueOf() { return "+" } }; -if (x.join(object) !== "0[object Object]1[object Object]2[object Object]3") { - throw new Test262Error('#1: var object = {valueOf: function() {return "+"}}; x.join(object) === "0[object Object]1[object Object]2[object Object]3". Actual: ' + (x.join(object))); -} + +assert.sameValue( + x.join(object), + "0[object Object]1[object Object]2[object Object]3", + 'x.join({valueOf() {return "+"}}) must return "0[object Object]1[object Object]2[object Object]3"' +); var object = { - valueOf: function() { + valueOf() { return "+" }, - toString: function() { + toString() { return "*" } }; -if (x.join(object) !== "0*1*2*3") { - throw new Test262Error('#2: var object = {valueOf: function() {return "+"}, toString: function() {return "*"}}; x.join(object) === "0*1*2*3". Actual: ' + (x.join(object))); -} + +assert.sameValue( + x.join(object), + "0*1*2*3", + 'x.join("{valueOf() {return "+"}, toString() {return "*"}}) must return "0*1*2*3"' +); var object = { - valueOf: function() { + valueOf() { return "+" }, - toString: function() { + toString() { return {} } }; -if (x.join(object) !== "0+1+2+3") { - throw new Test262Error('#3: var object = {valueOf: function() {return "+"}, toString: function() {return {}}}; x.join(object) === "0+1+2+3". Actual: ' + (x.join(object))); -} + +assert.sameValue( + x.join(object), + "0+1+2+3", + 'x.join({valueOf() {return "+"}, toString() {return {}}}) must return "0+1+2+3"' +); try { var object = { - valueOf: function() { + valueOf() { throw "error" }, - toString: function() { + toString() { return "*" } }; - if (x.join(object) !== "0*1*2*3") { - throw new Test262Error('#4.1: var object = {valueOf: function() {throw "error"}, toString: function() {return "*"}}; x.join(object) === "0*1*2*3". Actual: ' + (x.join(object))); - } + + assert.sameValue( + x.join(object), + "0*1*2*3", + 'x.join("{valueOf() {throw "error"}, toString() {return "*"}}) must return "0*1*2*3"' + ); } catch (e) { - if (e === "error") { - throw new Test262Error('#4.2: var object = {valueOf: function() {throw "error"}, toString: function() {return "*"}}; x.join(object) not throw "error"'); - } else { - throw new Test262Error('#4.3: var object = {valueOf: function() {throw "error"}, toString: function() {return "*"}}; x.join(object) not throw Error. Actual: ' + (e)); - } + assert.notSameValue(e, "error", 'The value of e is not "error"'); } var object = { - toString: function() { + toString() { return "*" } }; -if (x.join(object) !== "0*1*2*3") { - throw new Test262Error('#5: var object = {toString: function() {return "*"}}; x.join(object) === "0*1*2*3". Actual: ' + (x.join(object))); -} +assert.sameValue(x.join(object), "0*1*2*3", 'x.join({toString() {return "*"}}) must return "0*1*2*3"'); var object = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return "*" } } -if (x.join(object) !== "0*1*2*3") { - throw new Test262Error('#6: var object = {valueOf: function() {return {}}, toString: function() {return "*"}}; x.join(object) === "0*1*2*3". Actual: ' + (x.join(object))); -} + +assert.sameValue( + x.join(object), + "0*1*2*3", + 'x.join({valueOf() {return {}}, toString() {return "*"}}) must return "0*1*2*3"' +); try { var object = { - valueOf: function() { + valueOf() { return "+" }, - toString: function() { + toString() { throw "error" } }; x.join(object); - throw new Test262Error('#7.1: var object = {valueOf: function() {return "+"}, toString: function() {throw "error"}}; x.join(object) throw "error". Actual: ' + (x.join(object))); + throw new Test262Error('#7.1: var object = {valueOf() {return "+"}, toString() {throw "error"}}; x.join(object) throw "error". Actual: ' + (x.join(object))); } catch (e) { - if (e !== "error") { - throw new Test262Error('#7.2: var object = {valueOf: function() {return "+"}, toString: function() {throw "error"}}; x.join(object) throw "error". Actual: ' + (e)); - } + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); } try { var object = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return {} } }; x.join(object); - throw new Test262Error('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; x.join(object) throw TypeError. Actual: ' + (x.join(object))); + throw new Test262Error('#8.1: var object = {valueOf() {return {}}, toString() {return {}}}; x.join(object) throw TypeError. Actual: ' + (x.join(object))); } catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; x.join(object) throw TypeError. Actual: ' + (e)); - } + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); } try { var object = { - toString: function() { + toString() { throw "error" } }; [].join(object); - throw new Test262Error('#9.1: var object = {toString: function() {throw "error"}}; [].join(object) throw "error". Actual: ' + ([].join(object))); + throw new Test262Error('#9.1: var object = {toString() {throw "error"}}; [].join(object) throw "error". Actual: ' + ([].join(object))); } catch (e) { - if (e !== "error") { - throw new Test262Error('#9.2: var object = {toString: function() {throw "error"}}; [].join(object) throw "error". Actual: ' + (e)); - } + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); } diff --git a/test/built-ins/Array/prototype/join/S15.4.4.5_A3.2_T2.js b/test/built-ins/Array/prototype/join/S15.4.4.5_A3.2_T2.js index 2ea887456b..b6575d611d 100644 --- a/test/built-ins/Array/prototype/join/S15.4.4.5_A3.2_T2.js +++ b/test/built-ins/Array/prototype/join/S15.4.4.5_A3.2_T2.js @@ -13,9 +13,7 @@ var object = { } }; var x = new Array(object); -if (x.join() !== "[object Object]") { - throw new Test262Error('#1: var object = {valueOf: function() {return "+"}} var x = new Array(object); x.join() === "[object Object]". Actual: ' + (x.join())); -} +assert.sameValue(x.join(), "[object Object]", 'x.join() must return "[object Object]"'); var object = { valueOf: function() { @@ -26,9 +24,7 @@ var object = { } }; var x = new Array(object); -if (x.join() !== "*") { - throw new Test262Error('#2: var object = {valueOf: function() {return "+"}, toString: function() {return "*"}} var x = new Array(object); x.join() === "*". Actual: ' + (x.join())); -} +assert.sameValue(x.join(), "*", 'x.join() must return "*"'); var object = { valueOf: function() { @@ -39,9 +35,7 @@ var object = { } }; var x = new Array(object); -if (x.join() !== "+") { - throw new Test262Error('#3: var object = {valueOf: function() {return "+"}, toString: function() {return {}}} var x = new Array(object); x.join() === "+". Actual: ' + (x.join())); -} +assert.sameValue(x.join(), "+", 'x.join() must return "+"'); try { var object = { @@ -53,16 +47,10 @@ try { } }; var x = new Array(object); - if (x.join() !== "*") { - throw new Test262Error('#4.1: var object = {valueOf: function() {throw "error"}, toString: function() {return "*"}} var x = new Array(object); x.join() === "*". Actual: ' + (x.join())); - } + assert.sameValue(x.join(), "*", 'x.join() must return "*"'); } catch (e) { - if (e === "error") { - throw new Test262Error('#4.2: var object = {valueOf: function() {throw "error"}, toString: function() {return "*"}} var x = new Array(object); x.join() not throw "error"'); - } else { - throw new Test262Error('#4.3: var object = {valueOf: function() {throw "error"}, toString: function() {return "*"}} var x = new Array(object); x.join() not throw Error. Actual: ' + (e)); - } + assert.notSameValue(e, "error", 'The value of e is not "error"'); } var object = { @@ -71,9 +59,7 @@ var object = { } }; var x = new Array(object); -if (x.join() !== "*") { - throw new Test262Error('#5: var object = {toString: function() {return "*"}} var x = new Array(object); x.join() === "*". Actual: ' + (x.join())); -} +assert.sameValue(x.join(), "*", 'x.join() must return "*"'); var object = { valueOf: function() { @@ -84,9 +70,7 @@ var object = { } } var x = new Array(object); -if (x.join() !== "*") { - throw new Test262Error('#6: var object = {valueOf: function() {return {}}, toString: function() {return "*"}} var x = new Array(object); x.join() === "*". Actual: ' + (x.join())); -} +assert.sameValue(x.join(), "*", 'x.join() must return "*"'); try { var object = { @@ -102,9 +86,7 @@ try { throw new Test262Error('#7.1: var object = {valueOf: function() {return "+"}, toString: function() {throw "error"}} var x = new Array(object); x.join() throw "error". Actual: ' + (x.join())); } catch (e) { - if (e !== "error") { - throw new Test262Error('#7.2: var object = {valueOf: function() {return "+"}, toString: function() {throw "error"}} var x = new Array(object); x.join() throw "error". Actual: ' + (e)); - } + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); } try { @@ -121,7 +103,9 @@ try { throw new Test262Error('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}} var x = new Array(object); x.join() throw TypeError. Actual: ' + (x.join())); } catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}} var x = new Array(object); x.join() throw TypeError. Actual: ' + (e)); - } + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); } diff --git a/test/built-ins/Array/prototype/join/S15.4.4.5_A6.7.js b/test/built-ins/Array/prototype/join/S15.4.4.5_A6.7.js index 8559cbec7b..8ff58d4dfb 100644 --- a/test/built-ins/Array/prototype/join/S15.4.4.5_A6.7.js +++ b/test/built-ins/Array/prototype/join/S15.4.4.5_A6.7.js @@ -9,12 +9,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.join(); - throw new Test262Error('#1.1: new Array.prototype.join() throw TypeError. Actual: ' + (new Array.prototype.join())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.join() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/pop/S15.4.4.6_A2_T4.js b/test/built-ins/Array/prototype/pop/S15.4.4.6_A2_T4.js index 82b7c4dbd7..e372029475 100644 --- a/test/built-ins/Array/prototype/pop/S15.4.4.6_A2_T4.js +++ b/test/built-ins/Array/prototype/pop/S15.4.4.6_A2_T4.js @@ -16,125 +16,109 @@ obj.pop = Array.prototype.pop; obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return 1 } }; var pop = obj.pop(); -if (pop !== -1) { - throw new Test262Error('#1: obj[0] = -1; obj.length = {valueOf: function() {return 1}} obj.pop() === -1. Actual: ' + (pop)); -} +assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return 1 }, - toString: function() { + toString() { return 0 } }; var pop = obj.pop(); -if (pop !== -1) { - throw new Test262Error('#0: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {return 0}} obj.pop() === -1. Actual: ' + (pop)); -} +assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return 1 }, - toString: function() { + toString() { return {} } }; var pop = obj.pop(); -if (pop !== -1) { - throw new Test262Error('#3: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {return {}}} obj.pop() === -1. Actual: ' + (pop)); -} +assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); try { obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return 1 }, - toString: function() { + toString() { throw "error" } }; var pop = obj.pop(); - if (pop !== -1) { - throw new Test262Error('#4.1: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {throw "error"}}; obj.pop() === ",". Actual: ' + (pop)); - } + assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); } catch (e) { - if (e === "error") { - throw new Test262Error('#4.2: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {throw "error"}}; obj.pop() not throw "error"'); - } else { - throw new Test262Error('#4.3: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {throw "error"}}; obj.pop() not throw Error. Actual: ' + (e)); - } + assert.notSameValue(e, "error", 'The value of e is not "error"'); } obj[0] = -1; obj.length = { - toString: function() { + toString() { return 0 } }; var pop = obj.pop(); -if (pop !== undefined) { - throw new Test262Error('#5: obj[0] = -1; obj.length = {toString: function() {return 0}} obj.pop() === undefined. Actual: ' + (pop)); -} +assert.sameValue(pop, undefined, 'The value of pop is expected to equal undefined'); obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return 0 } } var pop = obj.pop(); -if (pop !== undefined) { - throw new Test262Error('#6: obj[0] = -1; obj.length = {valueOf: function() {return {}}, toString: function() {return 0}} obj.pop() === undefined. Actual: ' + (pop)); -} +assert.sameValue(pop, undefined, 'The value of pop is expected to equal undefined'); try { obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { throw "error" }, - toString: function() { + toString() { return 0 } }; var pop = obj.pop(); - throw new Test262Error('#7.1: obj[0] = -1; obj.length = {valueOf: function() {throw "error"}, toString: function() {return 0}}; obj.pop() throw "error". Actual: ' + (pop)); + throw new Test262Error('#7.1: obj[0] = -1; obj.length = {valueOf() {throw "error"}, toString() {return 0}}; obj.pop() throw "error". Actual: ' + (pop)); } catch (e) { - if (e !== "error") { - throw new Test262Error('#7.2: obj[0] = -1; obj.length = {valueOf: function() {throw "error"}, toString: function() {return 0}}; obj.pop() throw "error". Actual: ' + (e)); - } + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); } try { obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return {} } }; var pop = obj.pop(); - throw new Test262Error('#8.1: obj[0] = -1; obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.pop() throw TypeError. Actual: ' + (pop)); + throw new Test262Error('#8.1: obj[0] = -1; obj.length = {valueOf() {return {}}, toString() {return {}}} obj.pop() throw TypeError. Actual: ' + (pop)); } catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#8.2: obj[0] = -1; obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.pop() throw TypeError. Actual: ' + (e)); - } + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); } diff --git a/test/built-ins/Array/prototype/pop/S15.4.4.6_A5.7.js b/test/built-ins/Array/prototype/pop/S15.4.4.6_A5.7.js index cd7b3967bc..e1cb815a31 100644 --- a/test/built-ins/Array/prototype/pop/S15.4.4.6_A5.7.js +++ b/test/built-ins/Array/prototype/pop/S15.4.4.6_A5.7.js @@ -9,12 +9,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.pop(); - throw new Test262Error('#1.1: new Array.prototype.pop() throw TypeError. Actual: ' + (new Array.prototype.pop())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.pop() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/push/S15.4.4.7_A2_T3.js b/test/built-ins/Array/prototype/push/S15.4.4.7_A2_T3.js index 8e87c8bf67..b4183bb05d 100644 --- a/test/built-ins/Array/prototype/push/S15.4.4.7_A2_T3.js +++ b/test/built-ins/Array/prototype/push/S15.4.4.7_A2_T3.js @@ -15,121 +15,104 @@ var obj = {}; obj.push = Array.prototype.push; obj.length = { - valueOf: function() { + valueOf() { return 3 } }; var push = obj.push(); -if (push !== 3) { - throw new Test262Error('#1: obj.length = {valueOf: function() {return 3}} obj.push() === 3. Actual: ' + (push)); -} +assert.sameValue(push, 3, 'The value of push is expected to be 3'); obj.length = { - valueOf: function() { + valueOf() { return 3 }, - toString: function() { + toString() { return 1 } }; var push = obj.push(); -if (push !== 3) { - throw new Test262Error('#0: obj.length = {valueOf: function() {return 3}, toString: function() {return 1}} obj.push() === 3. Actual: ' + (push)); -} +assert.sameValue(push, 3, 'The value of push is expected to be 3'); obj.length = { - valueOf: function() { + valueOf() { return 3 }, - toString: function() { + toString() { return {} } }; var push = obj.push(); -if (push !== 3) { - throw new Test262Error('#1: obj.length = {valueOf: function() {return 3}, toString: function() {return {}}} obj.push() === 3. Actual: ' + (push)); -} +assert.sameValue(push, 3, 'The value of push is expected to be 3'); try { - obj.length = { - valueOf: function() { + valueOf() { return 3 }, - toString: function() { + toString() { throw "error" } }; var push = obj.push(); - if (push !== 3) { - throw new Test262Error('#4.1: obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.push() === ",". Actual: ' + (push)); - } + assert.sameValue(push, 3, 'The value of push is expected to be 3'); } catch (e) { - if (e === "error") { - throw new Test262Error('#4.2: obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.push() not throw "error"'); - } else { - throw new Test262Error('#4.3: obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.push() not throw Error. Actual: ' + (e)); - } + assert.notSameValue(e, "error", 'The value of e is not "error"'); } obj.length = { - toString: function() { + toString() { return 1 } }; var push = obj.push(); -if (push !== 1) { - throw new Test262Error('#5: obj.length = {toString: function() {return 1}} obj.push() === 1. Actual: ' + (push)); -} +assert.sameValue(push, 1, 'The value of push is expected to be 1'); obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return 1 } } var push = obj.push(); -if (push !== 1) { - throw new Test262Error('#6: obj.length = {valueOf: function() {return {}}, toString: function() {return 1}} obj.push() === 1. Actual: ' + (push)); -} +assert.sameValue(push, 1, 'The value of push is expected to be 1'); try { obj.length = { - valueOf: function() { + valueOf() { throw "error" }, - toString: function() { + toString() { return 1 } }; var push = obj.push(); - throw new Test262Error('#7.1: obj.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; obj.push() throw "error". Actual: ' + (push)); + throw new Test262Error('#7.1: obj.length = {valueOf() {throw "error"}, toString() {return 1}}; obj.push() throw "error". Actual: ' + (push)); } catch (e) { - if (e !== "error") { - throw new Test262Error('#7.2: obj.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; obj.push() throw "error". Actual: ' + (e)); - } + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); } try { obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return {} } }; var push = obj.push(); - throw new Test262Error('#8.1: obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.push() throw TypeError. Actual: ' + (push)); + throw new Test262Error('#8.1: obj.length = {valueOf() {return {}}, toString() {return {}}} obj.push() throw TypeError. Actual: ' + (push)); } catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#8.2: obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.push() throw TypeError. Actual: ' + (e)); - } + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); } diff --git a/test/built-ins/Array/prototype/push/S15.4.4.7_A3.js b/test/built-ins/Array/prototype/push/S15.4.4.7_A3.js index 1d8f4f29a6..1bcd57ef0c 100644 --- a/test/built-ins/Array/prototype/push/S15.4.4.7_A3.js +++ b/test/built-ins/Array/prototype/push/S15.4.4.7_A3.js @@ -11,23 +11,18 @@ var x = []; x.length = 4294967295; var push = x.push(); -if (push !== 4294967295) { - throw new Test262Error('#1: x = []; x.length = 4294967295; x.push() === 4294967295. Actual: ' + (push)); -} +assert.sameValue(push, 4294967295, 'The value of push is expected to be 4294967295'); try { x.push("x"); throw new Test262Error('#2.1: x = []; x.length = 4294967295; x.push("x") throw RangeError. Actual: ' + (push)); } catch (e) { - if ((e instanceof RangeError) !== true) { - throw new Test262Error('#2.2: x = []; x.length = 4294967295; x.push("x") throw RangeError. Actual: ' + (e)); - } + assert.sameValue( + e instanceof RangeError, + true, + 'The result of evaluating (e instanceof RangeError) is expected to be true' + ); } -if (x[4294967295] !== "x") { - throw new Test262Error('#3: x = []; x.length = 4294967295; try {x.push("x")}catch(e){}; x[4294967295] === "x". Actual: ' + (x[4294967295])); -} - -if (x.length !== 4294967295) { - throw new Test262Error('#4: x = []; x.length = 4294967295; try {x.push("x")}catch(e){}; x.length === 4294967295. Actual: ' + (x.length)); -} +assert.sameValue(x[4294967295], "x", 'The value of x[4294967295] is expected to be "x"'); +assert.sameValue(x.length, 4294967295, 'The value of x.length is expected to be 4294967295'); diff --git a/test/built-ins/Array/prototype/push/S15.4.4.7_A6.7.js b/test/built-ins/Array/prototype/push/S15.4.4.7_A6.7.js index 4bb5f526fd..3eacb84df3 100644 --- a/test/built-ins/Array/prototype/push/S15.4.4.7_A6.7.js +++ b/test/built-ins/Array/prototype/push/S15.4.4.7_A6.7.js @@ -9,12 +9,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.push(); - throw new Test262Error('#1.1: new Array.prototype.push() throw TypeError. Actual: ' + (new Array.prototype.push())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.push() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/reverse/S15.4.4.8_A5.7.js b/test/built-ins/Array/prototype/reverse/S15.4.4.8_A5.7.js index d1ac302439..e17bc4d5c8 100644 --- a/test/built-ins/Array/prototype/reverse/S15.4.4.8_A5.7.js +++ b/test/built-ins/Array/prototype/reverse/S15.4.4.8_A5.7.js @@ -9,12 +9,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.reverse(); - throw new Test262Error('#1.1: new Array.prototype.reverse() throw TypeError. Actual: ' + (new Array.prototype.reverse())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.reverse() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/shift/S15.4.4.9_A2_T5.js b/test/built-ins/Array/prototype/shift/S15.4.4.9_A2_T5.js index 3597f2c6ef..9a5fa3eb4d 100644 --- a/test/built-ins/Array/prototype/shift/S15.4.4.9_A2_T5.js +++ b/test/built-ins/Array/prototype/shift/S15.4.4.9_A2_T5.js @@ -16,125 +16,109 @@ obj.shift = Array.prototype.shift; obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return 1 } }; var shift = obj.shift(); -if (shift !== -1) { - throw new Test262Error('#1: obj[0] = -1; obj.length = {valueOf: function() {return 1}} obj.shift() === -1. Actual: ' + (shift)); -} +assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return 1 }, - toString: function() { + toString() { return 0 } }; var shift = obj.shift(); -if (shift !== -1) { - throw new Test262Error('#0: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {return 0}} obj.shift() === -1. Actual: ' + (shift)); -} +assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return 1 }, - toString: function() { + toString() { return {} } }; var shift = obj.shift(); -if (shift !== -1) { - throw new Test262Error('#3: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {return {}}} obj.shift() === -1. Actual: ' + (shift)); -} +assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); try { obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return 1 }, - toString: function() { + toString() { throw "error" } }; var shift = obj.shift(); - if (shift !== -1) { - throw new Test262Error('#4.1: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {throw "error"}}; obj.shift() === ",". Actual: ' + (shift)); - } + assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); } catch (e) { - if (e === "error") { - throw new Test262Error('#4.2: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {throw "error"}}; obj.shift() not throw "error"'); - } else { - throw new Test262Error('#4.3: obj[0] = -1; obj.length = {valueOf: function() {return 1}, toString: function() {throw "error"}}; obj.shift() not throw Error. Actual: ' + (e)); - } + assert.notSameValue(e, "error", 'The value of e is not "error"'); } obj[0] = -1; obj.length = { - toString: function() { + toString() { return 0 } }; var shift = obj.shift(); -if (shift !== undefined) { - throw new Test262Error('#5: obj[0] = -1; obj.length = {toString: function() {return 0}} obj.shift() === undefined. Actual: ' + (shift)); -} +assert.sameValue(shift, undefined, 'The value of shift is expected to equal undefined'); obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return 0 } } var shift = obj.shift(); -if (shift !== undefined) { - throw new Test262Error('#6: obj[0] = -1; obj.length = {valueOf: function() {return {}}, toString: function() {return 0}} obj.shift() === undefined. Actual: ' + (shift)); -} +assert.sameValue(shift, undefined, 'The value of shift is expected to equal undefined'); try { obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { throw "error" }, - toString: function() { + toString() { return 0 } }; var shift = obj.shift(); - throw new Test262Error('#7.1: obj[0] = -1; obj.length = {valueOf: function() {throw "error"}, toString: function() {return 0}}; obj.shift() throw "error". Actual: ' + (shift)); + throw new Test262Error('#7.1: obj[0] = -1; obj.length = {valueOf() {throw "error"}, toString() {return 0}}; obj.shift() throw "error". Actual: ' + (shift)); } catch (e) { - if (e !== "error") { - throw new Test262Error('#7.2: obj[0] = -1; obj.length = {valueOf: function() {throw "error"}, toString: function() {return 0}}; obj.shift() throw "error". Actual: ' + (e)); - } + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); } try { obj[0] = -1; obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return {} } }; var shift = obj.shift(); - throw new Test262Error('#8.1: obj[0] = -1; obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.shift() throw TypeError. Actual: ' + (shift)); + throw new Test262Error('#8.1: obj[0] = -1; obj.length = {valueOf() {return {}}, toString() {return {}}} obj.shift() throw TypeError. Actual: ' + (shift)); } catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#8.2: obj[0] = -1; obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.shift() throw TypeError. Actual: ' + (e)); - } + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); } diff --git a/test/built-ins/Array/prototype/shift/S15.4.4.9_A5.7.js b/test/built-ins/Array/prototype/shift/S15.4.4.9_A5.7.js index 7b658bd2d8..ca94cddd2d 100644 --- a/test/built-ins/Array/prototype/shift/S15.4.4.9_A5.7.js +++ b/test/built-ins/Array/prototype/shift/S15.4.4.9_A5.7.js @@ -9,12 +9,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.shift(); - throw new Test262Error('#1.1: new Array.prototype.shift() throw TypeError. Actual: ' + (new Array.prototype.shift())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.shift() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/slice/S15.4.4.10_A3_T1.js b/test/built-ins/Array/prototype/slice/S15.4.4.10_A3_T1.js index 98d72af7a7..41df4336fd 100644 --- a/test/built-ins/Array/prototype/slice/S15.4.4.10_A3_T1.js +++ b/test/built-ins/Array/prototype/slice/S15.4.4.10_A3_T1.js @@ -7,17 +7,13 @@ esid: sec-array.prototype.slice description: length = 4294967296 ---*/ -var obj = {}; -obj.slice = Array.prototype.slice; -obj[0] = "x"; -obj[4294967295] = "y"; -obj.length = 4294967296; - -try { - var arr = obj.slice(0, 4294967296); - throw new Test262Error('#1: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; var arr = obj.slice(0,4294967296); lead to throwing exception.'); -} catch (e) { - if (!(e instanceof RangeError)) { - throw new Test262Error('#1.1: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; var arr = obj.slice(0,4294967296); lead to throwing exception. Exception is instance of RangeError. Actual: exception is ' + e); - } -} +assert.throws(RangeError, () => { + var obj = {}; + obj.slice = Array.prototype.slice; + obj[0] = "x"; + obj[4294967295] = "y"; + obj.length = 4294967296; + obj.slice(0, 4294967296); + new Array.prototype.toLocaleString(); + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/slice/S15.4.4.10_A3_T2.js b/test/built-ins/Array/prototype/slice/S15.4.4.10_A3_T2.js index 0358fd0e1d..ac5d83ba18 100644 --- a/test/built-ins/Array/prototype/slice/S15.4.4.10_A3_T2.js +++ b/test/built-ins/Array/prototype/slice/S15.4.4.10_A3_T2.js @@ -7,17 +7,12 @@ esid: sec-array.prototype.slice description: length = 4294967297 ---*/ -var obj = {}; -obj.slice = Array.prototype.slice; -obj[0] = "x"; -obj[4294967296] = "y"; -obj.length = 4294967297; - -try { - var arr = obj.slice(0, 4294967297); - throw new Test262Error('#1: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; var arr = obj.slice(0,4294967297); lead to throwing exception.'); -} catch (e) { - if (!(e instanceof RangeError)) { - throw new Test262Error('#1.1: var obj = {}; obj.slice = Array.prototype.slice; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; var arr = obj.slice(0,4294967297); lead to throwing exception. Exception is instance of RangeError. Actual: exception is ' + e); - } -} +assert.throws(RangeError, () => { + var obj = {}; + obj.slice = Array.prototype.slice; + obj[0] = "x"; + obj[4294967296] = "y"; + obj.length = 4294967297; + obj.slice(0, 4294967297); + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/slice/S15.4.4.10_A5.7.js b/test/built-ins/Array/prototype/slice/S15.4.4.10_A5.7.js index a3c7162296..2e65c0c075 100644 --- a/test/built-ins/Array/prototype/slice/S15.4.4.10_A5.7.js +++ b/test/built-ins/Array/prototype/slice/S15.4.4.10_A5.7.js @@ -9,12 +9,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.slice(); - throw new Test262Error('#1.1: new Array.prototype.slice() throw TypeError. Actual: ' + (new Array.prototype.slice())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.slice() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/sort/S15.4.4.11_A5_T1.js b/test/built-ins/Array/prototype/sort/S15.4.4.11_A5_T1.js index 1c164af479..8e0a401de1 100644 --- a/test/built-ins/Array/prototype/sort/S15.4.4.11_A5_T1.js +++ b/test/built-ins/Array/prototype/sort/S15.4.4.11_A5_T1.js @@ -7,15 +7,10 @@ esid: sec-array.prototype.sort description: comparefn function throw "error" ---*/ -var myComparefn = function(x, y) { - throw "error"; -} -var x = [1, 0]; -try { - x.sort(myComparefn) - throw new Test262Error('#1.1: Array.sort should not eat exceptions'); -} catch (e) { - if (e !== "error") { - throw new Test262Error('#1.2: Array.sort should not eat exceptions'); +assert.throws(Test262Error, () => { + var myComparefn = function(x, y) { + throw new Test262Error(); } -} + var x = [1, 0]; + x.sort(myComparefn); +}); diff --git a/test/built-ins/Array/prototype/sort/S15.4.4.11_A7.7.js b/test/built-ins/Array/prototype/sort/S15.4.4.11_A7.7.js index 7c7c3700a9..91b1d21453 100644 --- a/test/built-ins/Array/prototype/sort/S15.4.4.11_A7.7.js +++ b/test/built-ins/Array/prototype/sort/S15.4.4.11_A7.7.js @@ -9,12 +9,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.sort(); - throw new Test262Error('#1.1: new Array.prototype.sort() throw TypeError. Actual: ' + (new Array.prototype.sort())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.sort() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/splice/S15.4.4.12_A5.7.js b/test/built-ins/Array/prototype/splice/S15.4.4.12_A5.7.js index 9ab2d60c68..f4ab5911b5 100644 --- a/test/built-ins/Array/prototype/splice/S15.4.4.12_A5.7.js +++ b/test/built-ins/Array/prototype/splice/S15.4.4.12_A5.7.js @@ -9,12 +9,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.splice(); - throw new Test262Error('#1.1: new Array.prototype.splice() throw TypeError. Actual: ' + (new Array.prototype.splice())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.splice() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/toLocaleString/S15.4.4.3_A4.7.js b/test/built-ins/Array/prototype/toLocaleString/S15.4.4.3_A4.7.js index 41957c8ab0..1354e95aa9 100644 --- a/test/built-ins/Array/prototype/toLocaleString/S15.4.4.3_A4.7.js +++ b/test/built-ins/Array/prototype/toLocaleString/S15.4.4.3_A4.7.js @@ -10,12 +10,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.toLocaleString(); - throw new Test262Error('#1.1: new Array.prototype.toLocaleString() throw TypeError. Actual: ' + (new Array.prototype.toLocaleString())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.toLocaleString() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/toString/S15.4.4.2_A1_T4.js b/test/built-ins/Array/prototype/toString/S15.4.4.2_A1_T4.js index dc564c901e..661499cec4 100644 --- a/test/built-ins/Array/prototype/toString/S15.4.4.2_A1_T4.js +++ b/test/built-ins/Array/prototype/toString/S15.4.4.2_A1_T4.js @@ -11,144 +11,89 @@ description: If Type(value) is Object, evaluate ToPrimitive(value, String) ---*/ var object = { - valueOf: function() { + valueOf() { return "+" } }; var x = new Array(object); -if (x.toString() !== x.join()) { - throw new Test262Error('#1.1: var object = {valueOf: function() {return "+"}} var x = new Array(object); x.toString() === x.join(). Actual: ' + (x.toString())); -} else { - if (x.toString() !== "[object Object]") { - throw new Test262Error('#1.2: var object = {valueOf: function() {return "+"}} var x = new Array(object); x.toString() === "[object Object]". Actual: ' + (x.toString())); - } -} +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); var object = { - valueOf: function() { + valueOf() { return "+" }, - toString: function() { + toString() { return "*" } }; var x = new Array(object); -if (x.toString() !== x.join()) { - throw new Test262Error('#2.1: var object = {valueOf: function() {return "+"}, toString: function() {return x.join()}} var x = new Array(object); x.toString() === "*". Actual: ' + (x.toString())); -} else { - if (x.toString() !== "*") { - throw new Test262Error('#2.2: var object = {valueOf: function() {return "+"}, toString: function() {return "*"}} var x = new Array(object); x.toString() === "*". Actual: ' + (x.toString())); - } -} +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); var object = { - valueOf: function() { + valueOf() { return "+" }, - toString: function() { + toString() { return {} } }; var x = new Array(object); -if (x.toString() !== x.join()) { - throw new Test262Error('#3.1: var object = {valueOf: function() {return x.join()}, toString: function() {return {}}} var x = new Array(object); x.toString() === "+". Actual: ' + (x.toString())); -} else { - if (x.toString() !== "+") { - throw new Test262Error('#3.2: var object = {valueOf: function() {return "+"}, toString: function() {return {}}} var x = new Array(object); x.toString() === "+". Actual: ' + (x.toString())); - } -} - -try { - var object = { - valueOf: function() { - throw "error" - }, - toString: function() { - return "*" - } - }; - var x = new Array(object); - if (x.toString() !== x.join()) { - throw new Test262Error('#4.1: var object = {valueOf: function() {throw "error"}, toString: function() {return x.join()}} var x = new Array(object); x.toString() === "*". Actual: ' + (x.toString())); - } else { - if (x.toString() !== "*") { - throw new Test262Error('#4.2: var object = {valueOf: function() {throw "error"}, toString: function() {return "*"}} var x = new Array(object); x.toString() === "*". Actual: ' + (x.toString())); - } - } -} -catch (e) { - if (e === "error") { - throw new Test262Error('#4.3: var object = {valueOf: function() {throw "error"}, toString: function() {return "*"}} var x = new Array(object); x.toString() not throw "error"'); - } else { - throw new Test262Error('#4.4: var object = {valueOf: function() {throw "error"}, toString: function() {return "*"}} var x = new Array(object); x.toString() not throw Error. Actual: ' + (e)); - } -} +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); var object = { - toString: function() { + valueOf() { + throw "error" + }, + toString() { return "*" } }; var x = new Array(object); -if (x.toString() !== x.join()) { - throw new Test262Error('#5.1: var object = {toString: function() {return x.join()}} var x = new Array(object); x.toString() === "*". Actual: ' + (x.toString())); -} else { - if (x.toString() !== "*") { - throw new Test262Error('#5.2: var object = {toString: function() {return "*"}} var x = new Array(object); x.toString() === "*". Actual: ' + (x.toString())); - } -} +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); + var object = { - valueOf: function() { + toString() { + return "*" + } +}; +var x = new Array(object); +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); + +var object = { + valueOf() { return {} }, - toString: function() { + toString() { return "*" } } var x = new Array(object); -if (x.toString() !== x.join()) { - throw new Test262Error('#6.1: var object = {valueOf: function() {return {}}, toString: function() {return x.join()}} var x = new Array(object); x.toString() === "*". Actual: ' + (x.toString())); -} else { - if (x.toString() !== "*") { - throw new Test262Error('#6.2: var object = {valueOf: function() {return {}}, toString: function() {return "*"}} var x = new Array(object); x.toString() === "*". Actual: ' + (x.toString())); - } -} +assert.sameValue(x.toString(), x.join(), 'x.toString() must return the same value returned by x.join()'); -try { +assert.throws(Test262Error, () => { var object = { - valueOf: function() { + valueOf() { return "+" }, - toString: function() { - throw "error" + toString() { + throw new Test262Error(); } }; var x = new Array(object); x.toString(); - throw new Test262Error('#7.1: var object = {valueOf: function() {return "+"}, toString: function() {throw "error"}} var x = new Array(object); x.toString() throw "error". Actual: ' + (x.toString())); -} -catch (e) { - if (e !== "error") { - throw new Test262Error('#7.2: var object = {valueOf: function() {return "+"}, toString: function() {throw "error"}} var x = new Array(object); x.toString() throw "error". Actual: ' + (e)); - } -} +}); -try { +assert.throws(TypeError, () => { var object = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return {} } }; var x = new Array(object); x.toString(); - throw new Test262Error('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}} var x = new Array(object); x.toString() throw TypeError. Actual: ' + (x.toString())); -} -catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}} var x = new Array(object); x.toString() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/toString/S15.4.4.2_A4.7.js b/test/built-ins/Array/prototype/toString/S15.4.4.2_A4.7.js index 8922c434fd..4cb290b049 100644 --- a/test/built-ins/Array/prototype/toString/S15.4.4.2_A4.7.js +++ b/test/built-ins/Array/prototype/toString/S15.4.4.2_A4.7.js @@ -10,12 +10,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.toString(); - throw new Test262Error('#1.1: new Array.prototype.toString() throw TypeError. Actual: ' + (new Array.prototype.toString())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.toString() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +}); diff --git a/test/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T3.js b/test/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T3.js index 7a1da8898f..7f9ed4e247 100644 --- a/test/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T3.js +++ b/test/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T3.js @@ -15,120 +15,104 @@ var obj = {}; obj.unshift = Array.prototype.unshift; obj.length = { - valueOf: function() { + valueOf() { return 3 } }; var unshift = obj.unshift(); -if (unshift !== 3) { - throw new Test262Error('#1: obj.length = {valueOf: function() {return 3}} obj.unshift() === 3. Actual: ' + (unshift)); -} +assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); obj.length = { - valueOf: function() { + valueOf() { return 3 }, - toString: function() { + toString() { return 1 } }; var unshift = obj.unshift(); -if (unshift !== 3) { - throw new Test262Error('#0: obj.length = {valueOf: function() {return 3}, toString: function() {return 1}} obj.unshift() === 3. Actual: ' + (unshift)); -} +assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); obj.length = { - valueOf: function() { + valueOf() { return 3 }, - toString: function() { + toString() { return {} } }; var unshift = obj.unshift(); -if (unshift !== 3) { - throw new Test262Error('#1: obj.length = {valueOf: function() {return 3}, toString: function() {return {}}} obj.unshift() === 3. Actual: ' + (unshift)); -} +assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); try { obj.length = { - valueOf: function() { + valueOf() { return 3 }, - toString: function() { + toString() { throw "error" } }; var unshift = obj.unshift(); - if (unshift !== 3) { - throw new Test262Error('#4.1: obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.unshift() === ",". Actual: ' + (unshift)); - } + assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); } catch (e) { - if (e === "error") { - throw new Test262Error('#4.2: obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.unshift() not throw "error"'); - } else { - throw new Test262Error('#4.3: obj.length = {valueOf: function() {return 3}, toString: function() {throw "error"}}; obj.unshift() not throw Error. Actual: ' + (e)); - } + assert.notSameValue(e, "error", 'The value of e is not "error"'); } obj.length = { - toString: function() { + toString() { return 1 } }; var unshift = obj.unshift(); -if (unshift !== 1) { - throw new Test262Error('#5: obj.length = {toString: function() {return 1}} obj.unshift() === 1. Actual: ' + (unshift)); -} +assert.sameValue(unshift, 1, 'The value of unshift is expected to be 1'); obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return 1 } } var unshift = obj.unshift(); -if (unshift !== 1) { - throw new Test262Error('#6: obj.length = {valueOf: function() {return {}}, toString: function() {return 1}} obj.unshift() === 1. Actual: ' + (unshift)); -} +assert.sameValue(unshift, 1, 'The value of unshift is expected to be 1'); try { obj.length = { - valueOf: function() { + valueOf() { throw "error" }, - toString: function() { + toString() { return 1 } }; var unshift = obj.unshift(); - throw new Test262Error('#7.1: obj.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; obj.unshift() throw "error". Actual: ' + (unshift)); + throw new Test262Error('#7.1: obj.length = {valueOf() {throw "error"}, toString() {return 1}}; obj.unshift() throw "error". Actual: ' + (unshift)); } catch (e) { - if (e !== "error") { - throw new Test262Error('#7.2: obj.length = {valueOf: function() {throw "error"}, toString: function() {return 1}}; obj.unshift() throw "error". Actual: ' + (e)); - } + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); } try { obj.length = { - valueOf: function() { + valueOf() { return {} }, - toString: function() { + toString() { return {} } }; var unshift = obj.unshift(); - throw new Test262Error('#8.1: obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.unshift() throw TypeError. Actual: ' + (unshift)); + throw new Test262Error('#8.1: obj.length = {valueOf() {return {}}, toString() {return {}}} obj.unshift() throw TypeError. Actual: ' + (unshift)); } catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#8.2: obj.length = {valueOf: function() {return {}}, toString: function() {return {}}} obj.unshift() throw TypeError. Actual: ' + (e)); - } + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); } diff --git a/test/built-ins/Array/prototype/unshift/S15.4.4.13_A5.7.js b/test/built-ins/Array/prototype/unshift/S15.4.4.13_A5.7.js index ed3bf22d78..b133386118 100644 --- a/test/built-ins/Array/prototype/unshift/S15.4.4.13_A5.7.js +++ b/test/built-ins/Array/prototype/unshift/S15.4.4.13_A5.7.js @@ -9,12 +9,7 @@ description: > throw a TypeError exception ---*/ - -try { +assert.throws(TypeError, () => { new Array.prototype.unshift(); - throw new Test262Error('#1.1: new Array.prototype.unshift() throw TypeError. Actual: ' + (new Array.prototype.unshift())); -} catch (e) { - if ((e instanceof TypeError) !== true) { - throw new Test262Error('#1.2: new Array.prototype.unshift() throw TypeError. Actual: ' + (e)); - } -} + throw new Test262Error(); +});