| Index: src/string.js
|
| diff --git a/src/string.js b/src/string.js
|
| index 0d5ed0fc4297c49b0f79917de5a9e6b6a2758c4d..04688bda49401d766834132162edfddbe4104d9c 100644
|
| --- a/src/string.js
|
| +++ b/src/string.js
|
| @@ -711,12 +711,13 @@ function StringSubstr(start, n) {
|
| CHECK_OBJECT_COERCIBLE(this, "String.prototype.substr");
|
|
|
| var s = TO_STRING_INLINE(this);
|
| + var s_len = s.length;
|
| var len;
|
|
|
| // Correct n: If not given, set to string length; if explicitly
|
| // set to undefined, zero, or negative, returns empty string.
|
| if (IS_UNDEFINED(n)) {
|
| - len = s.length;
|
| + len = s_len;
|
| } else {
|
| len = TO_INTEGER(n);
|
| if (len <= 0) return '';
|
| @@ -730,17 +731,17 @@ function StringSubstr(start, n) {
|
| start = TO_INTEGER(start);
|
| // If positive, and greater than or equal to the string length,
|
| // return empty string.
|
| - if (start >= s.length) return '';
|
| + if (start >= s_len) return '';
|
| // If negative and absolute value is larger than the string length,
|
| // use zero.
|
| if (start < 0) {
|
| - start += s.length;
|
| + start += s_len;
|
| if (start < 0) start = 0;
|
| }
|
| }
|
|
|
| var end = start + len;
|
| - if (end > s.length) end = s.length;
|
| + if (end > s_len) end = s_len;
|
|
|
| return %_SubString(s, start, end);
|
| }
|
|
|