Debian Codegraph @

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