Index: test/mjsunit/substr.js |
diff --git a/test/mjsunit/substr.js b/test/mjsunit/substr.js |
index 83929362a0036c01ddf28e46f8f10606fc301819..ff9d777dbb44200aa84cef92def064150f02eee4 100644 |
--- a/test/mjsunit/substr.js |
+++ b/test/mjsunit/substr.js |
@@ -171,3 +171,57 @@ for (var i = 63; i >= 0; i--) { |
assertEquals("", String.prototype.substr.call(string, start, length)); |
assertEquals(["this", "start", "length"], log); |
} |
+ |
+// Bounds edge cases. |
+{ |
+ const str = "abc"; |
+ const negativeHeapNumber = -1 * 2**32; |
+ const positiveHeapNumber = 2**32; |
+ |
+ assertEquals("abc", str.substr(negativeHeapNumber)); |
+ assertEquals("abc", str.substr(negativeHeapNumber, str.length)); |
+ assertEquals("abc", str.substr(-str.length, str.length)); |
+ assertEquals("abc", str.substr(0, str.length)); |
+ assertEquals("bc", str.substr(-2, str.length)); |
+ assertEquals("c", str.substr(-1, str.length)); |
+ |
+ assertEquals("", str.substr(str.length)); |
+ assertEquals("", str.substr(4)); |
+ assertEquals("", str.substr(positiveHeapNumber)); |
+ |
+ assertEquals("abc", str.substr(negativeHeapNumber, positiveHeapNumber)); |
+ assertEquals("abc", str.substr(negativeHeapNumber, positiveHeapNumber)); |
+ assertEquals("abc", str.substr(-str.length, positiveHeapNumber)); |
+ assertEquals("abc", str.substr(0, positiveHeapNumber)); |
+ assertEquals("bc", str.substr(-2, positiveHeapNumber)); |
+ assertEquals("c", str.substr(-1, positiveHeapNumber)); |
+ |
+ assertEquals("", str.substr(str.length, positiveHeapNumber)); |
+ assertEquals("", str.substr(4, positiveHeapNumber)); |
+ assertEquals("", str.substr(positiveHeapNumber, positiveHeapNumber)); |
+ |
+ assertEquals("", str.substr(negativeHeapNumber, negativeHeapNumber)); |
+ assertEquals("", str.substr(negativeHeapNumber, negativeHeapNumber)); |
+ assertEquals("", str.substr(-str.length, negativeHeapNumber)); |
+ assertEquals("", str.substr(0, negativeHeapNumber)); |
+ assertEquals("", str.substr(-2, negativeHeapNumber)); |
+ assertEquals("", str.substr(-1, negativeHeapNumber)); |
+ |
+ assertEquals("", str.substr(str.length, negativeHeapNumber)); |
+ assertEquals("", str.substr(4, negativeHeapNumber)); |
+ assertEquals("", str.substr(positiveHeapNumber, negativeHeapNumber)); |
+ |
+ assertEquals("", str.substr(negativeHeapNumber, -1)); |
+ assertEquals("", str.substr(negativeHeapNumber, -1)); |
+ assertEquals("", str.substr(-str.length, -1)); |
+ assertEquals("", str.substr(0, -1)); |
+ assertEquals("", str.substr(-2, -1)); |
+ assertEquals("", str.substr(-1, -1)); |
+ |
+ assertEquals("", str.substr(str.length, -1)); |
+ assertEquals("", str.substr(4, -1)); |
+ assertEquals("", str.substr(positiveHeapNumber, -1)); |
+ |
+ assertEquals("abc", str.substr(undefined)); |
+ assertEquals("abc", str.substr(undefined, undefined)); |
+} |