OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 assertEquals("", "".repeat(5)); | 58 assertEquals("", "".repeat(5)); |
59 assertEquals("", "abc".repeat(0)); | 59 assertEquals("", "abc".repeat(0)); |
60 assertEquals("abcabc", "abc".repeat(2.0)); | 60 assertEquals("abcabc", "abc".repeat(2.0)); |
61 | 61 |
62 assertEquals("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a".repeat(37)); | 62 assertEquals("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a".repeat(37)); |
63 assertThrows('"a".repeat(-1)', RangeError); | 63 assertThrows('"a".repeat(-1)', RangeError); |
64 assertThrows('"a".repeat(Number.POSITIVE_INFINITY)', RangeError); | 64 assertThrows('"a".repeat(Number.POSITIVE_INFINITY)', RangeError); |
65 assertThrows('"a".repeat(Math.pow(2, 30))', RangeError); | 65 assertThrows('"a".repeat(Math.pow(2, 30))', RangeError); |
66 assertThrows('"a".repeat(Math.pow(2, 40))', RangeError); | 66 assertThrows('"a".repeat(Math.pow(2, 40))', RangeError); |
67 | 67 |
| 68 // Handling empty strings |
| 69 assertThrows('"".repeat(-1)', RangeError); |
| 70 assertThrows('"".repeat(Number.POSITIVE_INFINITY)', RangeError); |
| 71 assertEquals("", "".repeat(Math.pow(2, 30))); |
| 72 assertEquals("", "".repeat(Math.pow(2, 40))); |
| 73 |
68 var myobj = { | 74 var myobj = { |
69 toString: function() { | 75 toString: function() { |
70 return "abc"; | 76 return "abc"; |
71 }, | 77 }, |
72 repeat : String.prototype.repeat | 78 repeat : String.prototype.repeat |
73 }; | 79 }; |
74 assertEquals("abc", myobj.repeat(1)); | 80 assertEquals("abc", myobj.repeat(1)); |
75 assertEquals("abcabc", myobj.repeat(2)); | 81 assertEquals("abcabc", myobj.repeat(2)); |
OLD | NEW |