| Index: src/string.js
|
| ===================================================================
|
| --- src/string.js (revision 12582)
|
| +++ src/string.js (working copy)
|
| @@ -199,6 +199,37 @@
|
| }
|
|
|
|
|
| +function StringMatchNoResult(regexp) {
|
| + if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
|
| + throw MakeTypeError("called_on_null_or_undefined",
|
| + ["String.prototype.match"]);
|
| + }
|
| + var subject = TO_STRING_INLINE(this);
|
| + if (!IS_REGEXP(regexp))
|
| + regexp = new $RegExp(regexp);
|
| + if (!regexp.global) {
|
| + %_CallFunction(regexp, subject, RegExpExecNoResult);
|
| + } else {
|
| + regexp.lastIndex = 0;
|
| + var previousLastIndex = 0;
|
| + var lastMatch = true;
|
| + while (lastMatch) {
|
| + var result = %_CallFunction(regexp, subject, RegExpExecNoResult);
|
| + if (result == null)
|
| + lastMatch = false;
|
| + else {
|
| + var thisIndex = regexp.lastIndex;
|
| + if (thisIndex == previousLastIndex) {
|
| + regexp.lastIndex += 1;
|
| + previousLastIndex += 1;
|
| + } else {
|
| + previousLastIndex = thisIndex;
|
| + }
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| // SubString is an internal function that returns the sub string of 'string'.
|
| // If resulting string is of length 1, we use the one character cache
|
| // otherwise we call the runtime system.
|
| @@ -294,6 +325,28 @@
|
| }
|
|
|
|
|
| +function StringReplaceNoResult(search, replace) {
|
| + if (IS_FUNCTION(replace)) {
|
| + // The function may have side effects, so we punt to the real method
|
| + return %_CallFunction(this, search, replace, StringReplace);
|
| + }
|
| +
|
| + if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
|
| + throw MakeTypeError("called_on_null_or_undefined",
|
| + ["String.prototype.replace"]);
|
| + }
|
| +
|
| + var subject = TO_STRING_INLINE(this);
|
| +
|
| + if (IS_REGEXP(search)) {
|
| + %_CallFunction(subject, search, StringMatchNoResult);
|
| + } else {
|
| + TO_STRING_INLINE(search);
|
| + }
|
| + TO_STRING_INLINE(replace);
|
| +}
|
| +
|
| +
|
| // Expand the $-expressions in the string and return a new string with
|
| // the result.
|
| function ExpandReplacement(string, subject, matchInfo, result) {
|
| @@ -654,6 +707,29 @@
|
| }
|
|
|
|
|
| +function StringSplitNoResult(separator, limit) {
|
| + if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
|
| + throw MakeTypeError("called_on_null_or_undefined",
|
| + ["String.prototype.split"]);
|
| + }
|
| + TO_STRING_INLINE(this);
|
| + limit = (IS_UNDEFINED(limit)) ? 0xffffffff : TO_UINT32(limit);
|
| + if (limit === 0) return;
|
| +
|
| + // ECMA-262 says that if separator is undefined, the result should
|
| + // be an array of size 1 containing the entire string. SpiderMonkey
|
| + // and KJS have this behavior only when no separator is given. If
|
| + // undefined is explicitly given, they convert it to a string and
|
| + // use that. We do as SpiderMonkey and KJS.
|
| + if (%_ArgumentsLength() === 0) {
|
| + return;
|
| + }
|
| +
|
| + if (!IS_REGEXP(separator))
|
| + TO_STRING_INLINE(separator);
|
| +}
|
| +
|
| +
|
| // ECMA-262 section 15.5.4.15
|
| function StringSubstring(start, end) {
|
| if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
|
|
|