OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 assertTrue(mirror.isNumber()); | 43 assertTrue(mirror.isNumber()); |
44 assertEquals('number', mirror.type()); | 44 assertEquals('number', mirror.type()); |
45 assertTrue(mirror.isPrimitive()); | 45 assertTrue(mirror.isPrimitive()); |
46 | 46 |
47 // Test text representation | 47 // Test text representation |
48 assertEquals(String(n), mirror.toText()); | 48 assertEquals(String(n), mirror.toText()); |
49 | 49 |
50 // Parse JSON representation and check. | 50 // Parse JSON representation and check. |
51 var fromJSON = eval('(' + json + ')'); | 51 var fromJSON = eval('(' + json + ')'); |
52 assertEquals('number', fromJSON.type); | 52 assertEquals('number', fromJSON.type); |
53 if (!isNaN(n)) { | 53 if (isFinite(n)) { |
54 assertEquals(n, fromJSON.value); | 54 assertEquals(n, fromJSON.value); |
55 } else { | 55 } else { |
56 // NaN values are encoded as strings. | 56 // NaN and Infinity values are encoded as strings. |
57 assertTrue(typeof fromJSON.value == 'string'); | 57 assertTrue(typeof fromJSON.value == 'string'); |
58 if (n === Infinity) { | 58 if (n === Infinity) { |
59 assertEquals('Infinity', fromJSON.value); | 59 assertEquals('Infinity', fromJSON.value); |
60 } else if (n === -Infinity) { | 60 } else if (n === -Infinity) { |
61 assertEquals('-Infinity', fromJSON.value); | 61 assertEquals('-Infinity', fromJSON.value); |
62 } else { | 62 } else { |
63 assertEquals('NaN', fromJSON.value); | 63 assertEquals('NaN', fromJSON.value); |
64 } | 64 } |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 | 68 |
69 // Test a number of different numbers. | 69 // Test a number of different numbers. |
70 testNumberMirror(-7); | 70 testNumberMirror(-7); |
71 testNumberMirror(-6.5); | 71 testNumberMirror(-6.5); |
72 testNumberMirror(0); | 72 testNumberMirror(0); |
73 testNumberMirror(42); | 73 testNumberMirror(42); |
74 testNumberMirror(100.0002); | 74 testNumberMirror(100.0002); |
75 testNumberMirror(Infinity); | 75 testNumberMirror(Infinity); |
76 testNumberMirror(-Infinity); | 76 testNumberMirror(-Infinity); |
77 testNumberMirror(NaN); | 77 testNumberMirror(NaN); |
OLD | NEW |