Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/addition/get-symbol-to-prim-err.js

raw
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 is thrown while accessing `Symbol.toPrimitive` property
8 info: |
9 [...]
10 5. Let lprim be ? ToPrimitive(lval).
11 6. Let rprim be ? ToPrimitive(rval).
12 [...]
13
14 ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] )
15
16 1. If PreferredType was not passed, let hint be "default".
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 [...]
23 features: [Symbol.toPrimitive]
24 ---*/
25
26 var thrower = {};
27 var counter = {};
28 var callCount = 0;
29
30 Object.defineProperty(thrower, Symbol.toPrimitive, {
31 get: function() {
32 throw new Test262Error();
33 }
34 });
35 Object.defineProperty(counter, Symbol.toPrimitive, {
36 get: function() {
37 callCount += 1;
38 }
39 });
40
41 assert.throws(Test262Error, function() {
42 thrower + counter;
43 }, 'error from property access of left-hand side');
44
45 assert.sameValue(callCount, 0);
46
47 assert.throws(Test262Error, function() {
48 counter + thrower;
49 }, 'error from property access of right-hand side');
50
51 assert.sameValue(callCount, 1);