Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(973)

Unified Diff: test/mjsunit/string-indexof-1.js

Issue 2539093002: [runtime] Port simple String.prototype.indexOf cases to TF Builtin (Closed)
Patch Set: merging with master Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-strings.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/string-indexof-1.js
diff --git a/test/mjsunit/string-indexof-1.js b/test/mjsunit/string-indexof-1.js
index b9dad46d3dd8ea4383930f75fd167bf476087638..d626c223822f1d8d11a7026907f196077c93fcc8 100644
--- a/test/mjsunit/string-indexof-1.js
+++ b/test/mjsunit/string-indexof-1.js
@@ -137,3 +137,60 @@ for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
assertEquals(index, allCharsString.indexOf(pattern));
}
}
+
+(function nonStringReceivers() {
+ let indexOf = String.prototype.indexOf;
+ assertThrows(() => indexOf.call(null), TypeError);
+ assertThrows(() => indexOf.call(undefined), TypeError);
+
+ assertEquals(-1, indexOf.call(1));
+ assertEquals(0, indexOf.call(1, "1"));
+
+ assertEquals(-1, indexOf.call(1.2));
+ assertEquals(0, indexOf.call(1.2, "1"));
+ assertEquals(1, indexOf.call(1.2, "."));
+ assertEquals(2, indexOf.call(1.2, "2"));
+ assertEquals(-1, indexOf.call(1.2, "1", 2));
+
+ assertEquals(-1, indexOf.call({}));
+ assertEquals(0, indexOf.call({}, "[object Object]"));
+ assertEquals(-1, indexOf.call({}, "[object", 1));
+
+ assertEquals(-1, indexOf.call([]));
+ assertEquals(0, indexOf.call([1,2], "1,2"));
+
+ assertEquals(-1, indexOf.call(this));
+})();
+
+(function nonStringSearchString() {
+
+ assertEquals(-1, "".indexOf(1));
+ assertEquals(2, "_0123".indexOf(1));
+
+ assertEquals(-1, "".indexOf(1.2));
+ assertEquals(1, "01.2".indexOf(1.2));
+ assertEquals(1, "01.2".indexOf(1.2, 1));
+ assertEquals(-1, "01.2".indexOf(1.2, 2));
+
+ assertEquals(-1, "".indexOf(null));
+ assertEquals(0, "null".indexOf(null));
+
+ assertEquals(-1, "".indexOf(undefined));
+ assertEquals(1, "_undefined_".indexOf(undefined));
+
+ assertEquals(0, "".indexOf([]));
+ assertEquals(0, "123".indexOf([]));
+ assertEquals(2, "1,2,3".indexOf([2,3]));
+
+ assertEquals(-1, "".indexOf({}));
+ assertEquals(-1, "".indexOf(this));
+})();
+
+(function nonStringPosition() {
+ assertEquals(0, "aba".indexOf("a", false));
+ assertEquals(2, "aba".indexOf("a", true));
+ assertEquals(2, "aba".indexOf("a", "1"));
+ assertEquals(2, "aba".indexOf("a", "1.00000"));
+ assertEquals(2, "aba".indexOf("a", "2.00000"));
+ assertEquals(-1, "aba".indexOf("a", "3.00000"));
+})();
« no previous file with comments | « test/cctest/test-strings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698