Chromium Code Reviews| Index: src/string.js |
| diff --git a/src/string.js b/src/string.js |
| index cb82c166346fc7ba5491a1e9e5d28e0e9b5a5108..8a249e36ec2f70c285c96928cd7798681e14c35b 100644 |
| --- a/src/string.js |
| +++ b/src/string.js |
| @@ -890,6 +890,39 @@ function HtmlEscape(str) { |
| .replace(/'/g, "'"); |
| } |
| +// ES6 draft 07-15-13, section 15.5.3.23 |
| +function StringEndsWith(searchString /* position */) { // length == 1 |
|
Michael Starzinger
2013/07/29 13:16:27
nit: Two white-spaces before comment at end of lin
|
| + if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| + throw MakeTypeError("called_on_null_or_undefined", |
| + ["String.prototype.endsWith"]); |
| + } |
| + |
| + var s = TO_STRING_INLINE(this); |
| + var s_len = s.length; |
| + var ss = TO_STRING_INLINE(searchString); |
| + var ss_len = ss.length; |
| + |
| + if (ss_len > 0) { |
| + var pos = s_len; |
| + if (%_ArgumentsLength() > 1) { |
|
Michael Starzinger
2013/07/29 13:16:27
There is a missing check as to whether "position"
|
| + var arg = ToNumber(%_Arguments(1)); // position |
| + if (!NUMBER_IS_NAN(arg)) { |
|
Michael Starzinger
2013/07/29 13:16:27
In case ToNumber(position) yields NaN, then "pos"
|
| + pos = TO_INTEGER(arg); |
| + } |
| + } |
| + |
| + var end = $Math.min($Math.max(pos, 0), s_len); |
|
Michael Starzinger
2013/07/29 13:16:27
This calls potentially monkey-patched versions of
|
| + var start = end - ss_len; |
| + if (start < 0) { |
| + return false; |
| + } |
| + |
| + return %StringLastIndexOf(s, ss, start) === end - ss_len; |
| + } |
| + |
| + return true; |
| +} |
| + |
| // Compatibility support for KJS. |
| // Tested by mozilla/js/tests/js1_5/Regress/regress-276103.js. |
| @@ -1010,7 +1043,8 @@ function SetUpString() { |
| "small", StringSmall, |
| "strike", StringStrike, |
| "sub", StringSub, |
| - "sup", StringSup |
| + "sup", StringSup, |
| + "endsWith", StringEndsWith |
| )); |
| } |