tests/auto/qml/ecmascripttests/test262/test/language/expressions/addition/coerce-symbol-to-prim-err.js
raw symbols SCIP| 1 | // Copyright (C) 2016 the V8 project authors. 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 | es6id: 12.7.3.1 |
| 6 | description: > |
| 7 | Behavior when error thrown by invocation of `Symbol.toPrimitive` method |
| 8 | during coercion |
| 9 | info: | |
| 10 | [...] |
| 11 | 5. Let lprim be ? ToPrimitive(lval). |
| 12 | 6. Let rprim be ? ToPrimitive(rval). |
| 13 | [...] |
| 14 | |
| 15 | ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] ) |
| 16 | |
| 17 | [...] |
| 18 | 4. Let exoticToPrim be GetMethod(input, @@toPrimitive). |
| 19 | 5. ReturnIfAbrupt(exoticToPrim). |
| 20 | 6. If exoticToPrim is not undefined, then |
| 21 | a. Let result be Call(exoticToPrim, input, «hint»). |
| 22 | b. ReturnIfAbrupt(result). |
| 23 | features: [Symbol.toPrimitive] |
| 24 | ---*/ |
| 25 | |
| 26 | var thrower = {}; |
| 27 | var counter = {}; |
| 28 | var log; |
| 29 | |
| 30 | Object.defineProperty(thrower, Symbol.toPrimitive, { |
| 31 | get: function() { |
| 32 | log += 'accessThrower'; |
| 33 | return function() { throw new Test262Error(); }; |
| 34 | } |
| 35 | }); |
| 36 | Object.defineProperty(counter, Symbol.toPrimitive, { |
| 37 | get: function() { |
| 38 | log += 'accessCounter'; |
| 39 | return function() { log += 'callCounter'; }; |
| 40 | } |
| 41 | }); |
| 42 | |
| 43 | log = ''; |
| 44 | |
| 45 | assert.throws(Test262Error, function() { |
| 46 | thrower + counter; |
| 47 | }, 'error thrown by left-hand side'); |
| 48 | assert.sameValue(log, 'accessThrower'); |
| 49 | |
| 50 | log = ''; |
| 51 | |
| 52 | assert.throws(Test262Error, function() { |
| 53 | counter + thrower; |
| 54 | }, 'error thrown by right-hand side'); |
| 55 | assert.sameValue(log, 'accessCountercallCounteraccessThrower'); |