Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/isFinite/toprimitive-not-callable-throws.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 /*---
5 es6id: 18.2.2
6 esid: sec-isfinite-number
7 description: >
8 Throws a TypeError if number.@@toPrimitive is not null, undefined, or callable
9 info: |
10 isFinite (number)
11
12 1. Let num be ? ToNumber(number).
13
14 ToPrimitive ( input [ , PreferredType ] )
15
16 [...]
17 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
18
19 GetMethod (V, P)
20
21 [...]
22 2. Let func be ? GetV(V, P).
23 3. If func is either undefined or null, return undefined.
24 4. If IsCallable(func) is false, throw a TypeError exception.
25 features: [Symbol.toPrimitive]
26 ---*/
27
28 var obj = {};
29
30 obj[Symbol.toPrimitive] = 42;
31 assert.throws(TypeError, function() {
32 isFinite(obj);
33 }, "number");
34
35 obj[Symbol.toPrimitive] = "";
36 assert.throws(TypeError, function() {
37 isFinite(obj);
38 }, "string");
39
40 obj[Symbol.toPrimitive] = true;
41 assert.throws(TypeError, function() {
42 isFinite(obj);
43 }, "boolean");
44
45 obj[Symbol.toPrimitive] = Symbol.toPrimitive;
46 assert.throws(TypeError, function() {
47 isFinite(obj);
48 }, "symbol");
49
50 obj[Symbol.toPrimitive] = {};
51 assert.throws(TypeError, function() {
52 isFinite(obj);
53 }, "object");