order-of-evaluation.js (3050B)
1 // Copyright (C) 2018 Igalia, S.L. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-signed-right-shift-operator-runtime-semantics-evaluation 5 description: Type coercion order of operations for right-shift operator 6 features: [Symbol] 7 info: | 8 Evaluate lhs 9 Evaluate rhs 10 ToNumeric(lhs) 11 ToNumeric(rhs) 12 ---*/ 13 14 function MyError() {} 15 var trace; 16 17 // ?GetValue(lhs) throws. 18 trace = ""; 19 assert.throws(MyError, function() { 20 (function() { 21 trace += "1"; 22 throw new MyError(); 23 })() >> (function() { 24 trace += "2"; 25 throw new Test262Error("should not be evaluated"); 26 })(); 27 }, "?GetValue(lhs) throws."); 28 assert.sameValue(trace, "1", "?GetValue(lhs) throws."); 29 30 // ?GetValue(rhs) throws. 31 trace = ""; 32 assert.throws(MyError, function() { 33 (function() { 34 trace += "1"; 35 return { 36 valueOf: function() { 37 trace += "3"; 38 throw new Test262Error("should not be evaluated"); 39 } 40 }; 41 })() >> (function() { 42 trace += "2"; 43 throw new MyError(); 44 })(); 45 }, "?GetValue(rhs) throws."); 46 assert.sameValue(trace, "12", "?GetValue(rhs) throws."); 47 48 // ?ToPrimive(lhs) throws. 49 trace = ""; 50 assert.throws(MyError, function() { 51 (function() { 52 trace += "1"; 53 return { 54 valueOf: function() { 55 trace += "3"; 56 throw new MyError(); 57 } 58 }; 59 })() >> (function() { 60 trace += "2"; 61 return { 62 valueOf: function() { 63 trace += "4"; 64 throw new Test262Error("should not be evaluated"); 65 } 66 }; 67 })(); 68 }, "?ToPrimive(lhs) throws."); 69 assert.sameValue(trace, "123", "?ToPrimive(lhs) throws."); 70 71 // ?ToPrimive(rhs) throws. 72 trace = ""; 73 assert.throws(MyError, function() { 74 (function() { 75 trace += "1"; 76 return { 77 valueOf: function() { 78 trace += "3"; 79 return 1; 80 } 81 }; 82 })() >> (function() { 83 trace += "2"; 84 return { 85 valueOf: function() { 86 trace += "4"; 87 throw new MyError(); 88 } 89 }; 90 })(); 91 }, "?ToPrimive(rhs) throws."); 92 assert.sameValue(trace, "1234", "?ToPrimive(rhs) throws."); 93 94 // ?ToNumeric(lhs) throws. 95 trace = ""; 96 assert.throws(TypeError, function() { 97 (function() { 98 trace += "1"; 99 return { 100 valueOf: function() { 101 trace += "3"; 102 return Symbol("1"); 103 } 104 }; 105 })() >> (function() { 106 trace += "2"; 107 return { 108 valueOf: function() { 109 trace += "4"; 110 throw new Test262Error("should not be evaluated"); 111 } 112 }; 113 })(); 114 }, "?ToNumeric(lhs) throws."); 115 assert.sameValue(trace, "123", "?ToNumeric(lhs) throws."); 116 117 // GetValue(lhs) throws. 118 trace = ""; 119 assert.throws(TypeError, function() { 120 (function() { 121 trace += "1"; 122 return { 123 valueOf: function() { 124 trace += "3"; 125 return 1; 126 } 127 }; 128 })() >> (function() { 129 trace += "2"; 130 return { 131 valueOf: function() { 132 trace += "4"; 133 return Symbol("1"); 134 } 135 }; 136 })(); 137 }, "GetValue(lhs) throws."); 138 assert.sameValue(trace, "1234", "GetValue(lhs) throws."); 139 140 reportCompare(0, 0);