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