Debian Codegraph @

js/src/tests/test262/built-ins/isNaN/toprimitive-result-is-object-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 the result of calling number.@@toPrimitive is an Object
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 5. If exoticToPrim is not undefined, then
18 a. Let result be ? Call(exoticToPrim, input, « hint »).
19 b. If Type(result) is not Object, return result.
20 c. Throw a TypeError exception.
21 features: [Symbol.toPrimitive]
22 ---*/
23
24 var obj = {};
25 obj[Symbol.toPrimitive] = function() {
26 return [42];
27 };
28
29 assert.throws(TypeError, function() {
30 isNaN(obj);
31 });
32
33 reportCompare(0, 0);