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 23 matching lines...) Expand all Loading... |
34 function basicTest() { | 34 function basicTest() { |
35 assertEquals("t", s.charAt()); | 35 assertEquals("t", s.charAt()); |
36 assertEquals("t", s.charAt("string")); | 36 assertEquals("t", s.charAt("string")); |
37 assertEquals("t", s.charAt(null)); | 37 assertEquals("t", s.charAt(null)); |
38 assertEquals("t", s.charAt(void 0)); | 38 assertEquals("t", s.charAt(void 0)); |
39 assertEquals("t", s.charAt(false)); | 39 assertEquals("t", s.charAt(false)); |
40 assertEquals("e", s.charAt(true)); | 40 assertEquals("e", s.charAt(true)); |
41 assertEquals("", s.charAt(-1)); | 41 assertEquals("", s.charAt(-1)); |
42 assertEquals("", s.charAt(4)); | 42 assertEquals("", s.charAt(4)); |
43 assertEquals("", s.charAt(slowIndexOutOfRange)); | 43 assertEquals("", s.charAt(slowIndexOutOfRange)); |
| 44 assertEquals("", s.charAt(1/0)); |
| 45 assertEquals("", s.charAt(-1/0)); |
44 assertEquals("t", s.charAt(0)); | 46 assertEquals("t", s.charAt(0)); |
45 assertEquals("t", s.charAt(-0.0)); | 47 assertEquals("t", s.charAt(-0.0)); |
46 assertEquals("t", s.charAt(0.4)); | 48 assertEquals("t", s.charAt(0.4)); |
47 assertEquals("e", s.charAt(slowIndex1)); | 49 assertEquals("e", s.charAt(slowIndex1)); |
48 assertEquals("s", s.charAt(slowIndex2)); | 50 assertEquals("s", s.charAt(slowIndex2)); |
49 assertEquals("t", s.charAt(3)); | 51 assertEquals("t", s.charAt(3)); |
50 assertEquals("t", s.charAt(3.4)); | 52 assertEquals("t", s.charAt(3.4)); |
51 assertEquals("t", s.charAt(NaN)); | 53 assertEquals("t", s.charAt(NaN)); |
52 | 54 |
53 assertEquals(116, s.charCodeAt()); | 55 assertEquals(116, s.charCodeAt()); |
54 assertEquals(116, s.charCodeAt("string")); | 56 assertEquals(116, s.charCodeAt("string")); |
55 assertEquals(116, s.charCodeAt(null)); | 57 assertEquals(116, s.charCodeAt(null)); |
56 assertEquals(116, s.charCodeAt(void 0)); | 58 assertEquals(116, s.charCodeAt(void 0)); |
57 assertEquals(116, s.charCodeAt(false)); | 59 assertEquals(116, s.charCodeAt(false)); |
58 assertEquals(101, s.charCodeAt(true)); | 60 assertEquals(101, s.charCodeAt(true)); |
59 assertEquals(116, s.charCodeAt(0)); | 61 assertEquals(116, s.charCodeAt(0)); |
60 assertEquals(116, s.charCodeAt(-0.0)); | 62 assertEquals(116, s.charCodeAt(-0.0)); |
61 assertEquals(116, s.charCodeAt(0.4)); | 63 assertEquals(116, s.charCodeAt(0.4)); |
62 assertEquals(101, s.charCodeAt(slowIndex1)); | 64 assertEquals(101, s.charCodeAt(slowIndex1)); |
63 assertEquals(115, s.charCodeAt(slowIndex2)); | 65 assertEquals(115, s.charCodeAt(slowIndex2)); |
64 assertEquals(116, s.charCodeAt(3)); | 66 assertEquals(116, s.charCodeAt(3)); |
65 assertEquals(116, s.charCodeAt(3.4)); | 67 assertEquals(116, s.charCodeAt(3.4)); |
66 assertEquals(116, s.charCodeAt(NaN)); | 68 assertEquals(116, s.charCodeAt(NaN)); |
67 assertTrue(isNaN(s.charCodeAt(-1))); | 69 assertTrue(isNaN(s.charCodeAt(-1))); |
68 assertTrue(isNaN(s.charCodeAt(4))); | 70 assertTrue(isNaN(s.charCodeAt(4))); |
69 assertTrue(isNaN(s.charCodeAt(slowIndexOutOfRange))); | 71 assertTrue(isNaN(s.charCodeAt(slowIndexOutOfRange))); |
| 72 assertTrue(isNaN(s.charCodeAt(1/0))); |
| 73 assertTrue(isNaN(s.charCodeAt(-1/0))); |
70 } | 74 } |
71 basicTest(); | 75 basicTest(); |
72 | 76 |
73 // Make sure enough of the one-char string cache is filled. | 77 // Make sure enough of the one-char string cache is filled. |
74 var alpha = ['@']; | 78 var alpha = ['@']; |
75 for (var i = 1; i < 128; i++) { | 79 for (var i = 1; i < 128; i++) { |
76 var c = String.fromCharCode(i); | 80 var c = String.fromCharCode(i); |
77 alpha[i] = c.charAt(0); | 81 alpha[i] = c.charAt(0); |
78 } | 82 } |
79 var alphaStr = alpha.join(""); | 83 var alphaStr = alpha.join(""); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 oldResult = result; | 239 oldResult = result; |
236 String.prototype.charCodeAt = function() { return 42; }; | 240 String.prototype.charCodeAt = function() { return 42; }; |
237 } | 241 } |
238 result = s.charCodeAt(1); | 242 result = s.charCodeAt(1); |
239 } | 243 } |
240 assertEquals(42, result); | 244 assertEquals(42, result); |
241 assertEquals(101, oldResult); | 245 assertEquals(101, oldResult); |
242 delete String.prototype.charCodeAt; // Restore the default. | 246 delete String.prototype.charCodeAt; // Restore the default. |
243 } | 247 } |
244 testPrototypeChange_charCodeAt(); | 248 testPrototypeChange_charCodeAt(); |
OLD | NEW |