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

Unified Diff: src/js/string.js

Issue 2369003002: Revert of [stubs] Port String.prototype.substring to TurboFan (Closed)
Patch Set: Created 4 years, 3 months 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 | « src/js/i18n.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/string.js
diff --git a/src/js/string.js b/src/js/string.js
index b5d3eef3852f25a7258086ec03eb7447c7650d11..a6dc2f082d3d6c04c8c718eac688790f2de90791 100644
--- a/src/js/string.js
+++ b/src/js/string.js
@@ -237,6 +237,40 @@
return %StringSplit(subject, separator_string, limit);
}
+
+// ECMA-262 section 15.5.4.15
+function StringSubstring(start, end) {
+ CHECK_OBJECT_COERCIBLE(this, "String.prototype.subString");
+
+ var s = TO_STRING(this);
+ var s_len = s.length;
+
+ var start_i = TO_INTEGER(start);
+ if (start_i < 0) {
+ start_i = 0;
+ } else if (start_i > s_len) {
+ start_i = s_len;
+ }
+
+ var end_i = s_len;
+ if (!IS_UNDEFINED(end)) {
+ end_i = TO_INTEGER(end);
+ if (end_i > s_len) {
+ end_i = s_len;
+ } else {
+ if (end_i < 0) end_i = 0;
+ if (start_i > end_i) {
+ var tmp = end_i;
+ end_i = start_i;
+ start_i = tmp;
+ }
+ }
+ }
+
+ return %_SubString(s, start_i, end_i);
+}
+
+
// ecma262/#sec-string.prototype.substr
function StringSubstr(start, length) {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr");
@@ -557,6 +591,7 @@
"search", StringSearch,
"slice", StringSlice,
"split", StringSplitJS,
+ "substring", StringSubstring,
"substr", StringSubstr,
"startsWith", StringStartsWith,
"toLowerCase", StringToLowerCaseJS,
@@ -589,6 +624,7 @@
to.StringSlice = StringSlice;
to.StringSplit = StringSplitJS;
to.StringSubstr = StringSubstr;
+ to.StringSubstring = StringSubstring;
});
})
« no previous file with comments | « src/js/i18n.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698