| Index: src/string.js
|
| diff --git a/src/string.js b/src/string.js
|
| index 4ac6089f3b0c3bfebcaf5209c40aaf8f48c5805d..3608bac8facc279b0d0c31cd299cec641e58d714 100644
|
| --- a/src/string.js
|
| +++ b/src/string.js
|
| @@ -46,16 +46,18 @@
|
|
|
| // ECMA-262 section 15.5.4.2
|
| function StringToString() {
|
| - if (!IS_STRING(this) && !IS_STRING_WRAPPER(this))
|
| + if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
|
| throw new $TypeError('String.prototype.toString is not generic');
|
| + }
|
| return %_ValueOf(this);
|
| }
|
|
|
|
|
| // ECMA-262 section 15.5.4.3
|
| function StringValueOf() {
|
| - if (!IS_STRING(this) && !IS_STRING_WRAPPER(this))
|
| + if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
|
| throw new $TypeError('String.prototype.valueOf is not generic');
|
| + }
|
| return %_ValueOf(this);
|
| }
|
|
|
| @@ -91,7 +93,8 @@ function StringCharCodeAt(pos) {
|
| // ECMA-262, section 15.5.4.6
|
| function StringConcat() {
|
| if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
|
| - throw MakeTypeError("called_on_null_or_undefined", ["String.prototype.concat"]);
|
| + throw MakeTypeError("called_on_null_or_undefined",
|
| + ["String.prototype.concat"]);
|
| }
|
| var len = %_ArgumentsLength();
|
| var this_as_string = TO_STRING_INLINE(this);
|
| @@ -358,7 +361,7 @@ function ExpandReplacement(string, subject, matchInfo, builder) {
|
| builder_elements.push(SubString(string, position, next));
|
| }
|
| }
|
| -};
|
| +}
|
|
|
|
|
| // Compute the string of a given regular expression capture.
|
| @@ -371,7 +374,7 @@ function CaptureString(string, lastCaptureInfo, index) {
|
| if (start < 0) return;
|
| var end = lastCaptureInfo[CAPTURE(scaled + 1)];
|
| return SubString(string, start, end);
|
| -};
|
| +}
|
|
|
|
|
| // Add the string of a given regular expression capture to the
|
| @@ -384,7 +387,7 @@ function addCaptureString(builder, matchInfo, index) {
|
| if (start < 0) return;
|
| var end = matchInfo[CAPTURE(scaled + 1)];
|
| builder.addSpecialSlice(start, end);
|
| -};
|
| +}
|
|
|
| // TODO(lrn): This array will survive indefinitely if replace is never
|
| // called again. However, it will be empty, since the contents are cleared
|
| @@ -531,30 +534,36 @@ function StringSlice(start, end) {
|
| var s_len = s.length;
|
| var start_i = TO_INTEGER(start);
|
| var end_i = s_len;
|
| - if (end !== void 0)
|
| + if (end !== void 0) {
|
| end_i = TO_INTEGER(end);
|
| + }
|
|
|
| if (start_i < 0) {
|
| start_i += s_len;
|
| - if (start_i < 0)
|
| + if (start_i < 0) {
|
| start_i = 0;
|
| + }
|
| } else {
|
| - if (start_i > s_len)
|
| + if (start_i > s_len) {
|
| start_i = s_len;
|
| + }
|
| }
|
|
|
| if (end_i < 0) {
|
| end_i += s_len;
|
| - if (end_i < 0)
|
| + if (end_i < 0) {
|
| end_i = 0;
|
| + }
|
| } else {
|
| - if (end_i > s_len)
|
| + if (end_i > s_len) {
|
| end_i = s_len;
|
| + }
|
| }
|
|
|
| var num_c = end_i - start_i;
|
| - if (num_c < 0)
|
| + if (num_c < 0) {
|
| num_c = 0;
|
| + }
|
|
|
| return SubString(s, start_i, start_i + num_c);
|
| }
|
| @@ -692,7 +701,7 @@ function StringSubstring(start, end) {
|
| }
|
| }
|
|
|
| - return (start_i + 1 == end_i
|
| + return ((start_i + 1 == end_i)
|
| ? %_StringCharAt(s, start_i)
|
| : %_SubString(s, start_i, end_i));
|
| }
|
| @@ -736,7 +745,7 @@ function StringSubstr(start, n) {
|
| var end = start + len;
|
| if (end > s.length) end = s.length;
|
|
|
| - return (start + 1 == end
|
| + return ((start + 1 == end)
|
| ? %_StringCharAt(s, start)
|
| : %_SubString(s, start, end));
|
| }
|
| @@ -836,7 +845,7 @@ function HtmlEscape(str) {
|
| .replace(/>/g, ">")
|
| .replace(/"/g, """)
|
| .replace(/'/g, "'");
|
| -};
|
| +}
|
|
|
|
|
| // Compatibility support for KJS.
|
|
|