| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return %StringBuilderConcat(parts, len + 1, ""); | 96 return %StringBuilderConcat(parts, len + 1, ""); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Match ES3 and Safari | 99 // Match ES3 and Safari |
| 100 %FunctionSetLength(StringConcat, 1); | 100 %FunctionSetLength(StringConcat, 1); |
| 101 | 101 |
| 102 | 102 |
| 103 // ECMA-262 section 15.5.4.7 | 103 // ECMA-262 section 15.5.4.7 |
| 104 function StringIndexOf(pattern /* position */) { // length == 1 | 104 function StringIndexOf(pattern /* position */) { // length == 1 |
| 105 var subject = TO_STRING_INLINE(this); | 105 var subject = TO_STRING_INLINE(this); |
| 106 pattern = TO_STRING_INLINE(pattern); |
| 106 var index = 0; | 107 var index = 0; |
| 107 if (%_ArgumentsLength() > 1) { | 108 if (%_ArgumentsLength() > 1) { |
| 108 index = %_Arguments(1); // position | 109 index = %_Arguments(1); // position |
| 109 index = TO_INTEGER(index); | 110 index = TO_INTEGER(index); |
| 110 if (index < 0) index = 0; | 111 if (index < 0) index = 0; |
| 111 if (index > subject.length) index = subject.length; | 112 if (index > subject.length) index = subject.length; |
| 112 } | 113 } |
| 113 return %StringIndexOf(subject, TO_STRING_INLINE(pattern), index); | 114 return %StringIndexOf(subject, pattern, index); |
| 114 } | 115 } |
| 115 | 116 |
| 116 | 117 |
| 117 // ECMA-262 section 15.5.4.8 | 118 // ECMA-262 section 15.5.4.8 |
| 118 function StringLastIndexOf(pat /* position */) { // length == 1 | 119 function StringLastIndexOf(pat /* position */) { // length == 1 |
| 119 var sub = TO_STRING_INLINE(this); | 120 var sub = TO_STRING_INLINE(this); |
| 120 var subLength = sub.length; | 121 var subLength = sub.length; |
| 121 var pat = TO_STRING_INLINE(pat); | 122 var pat = TO_STRING_INLINE(pat); |
| 122 var patLength = pat.length; | 123 var patLength = pat.length; |
| 123 var index = subLength - patLength; | 124 var index = subLength - patLength; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 match_start = (elem >> 11) + (elem & 0x7ff); | 395 match_start = (elem >> 11) + (elem & 0x7ff); |
| 395 } else { | 396 } else { |
| 396 match_start = res[++i] - elem; | 397 match_start = res[++i] - elem; |
| 397 } | 398 } |
| 398 } else { | 399 } else { |
| 399 override[0] = elem; | 400 override[0] = elem; |
| 400 override[1] = match_start; | 401 override[1] = match_start; |
| 401 lastMatchInfoOverride = override; | 402 lastMatchInfoOverride = override; |
| 402 var func_result = | 403 var func_result = |
| 403 %_CallFunction(receiver, elem, match_start, subject, replace); | 404 %_CallFunction(receiver, elem, match_start, subject, replace); |
| 404 func_result = TO_STRING_INLINE(func_result); | 405 res[i] = TO_STRING_INLINE(func_result); |
| 405 res[i] = func_result; | |
| 406 match_start += elem.length; | 406 match_start += elem.length; |
| 407 } | 407 } |
| 408 i++; | 408 i++; |
| 409 } | 409 } |
| 410 } else { | 410 } else { |
| 411 while (i < len) { | 411 while (i < len) { |
| 412 var elem = res[i]; | 412 var elem = res[i]; |
| 413 if (!%_IsSmi(elem)) { | 413 if (!%_IsSmi(elem)) { |
| 414 // elem must be an Array. | 414 // elem must be an Array. |
| 415 // Use the apply argument as backing for global RegExp properties. | 415 // Use the apply argument as backing for global RegExp properties. |
| 416 lastMatchInfoOverride = elem; | 416 lastMatchInfoOverride = elem; |
| 417 var func_result = replace.apply(null, elem); | 417 var func_result = replace.apply(null, elem); |
| 418 func_result = TO_STRING_INLINE(func_result); | 418 res[i] = TO_STRING_INLINE(func_result); |
| 419 res[i] = func_result; | |
| 420 } | 419 } |
| 421 i++; | 420 i++; |
| 422 } | 421 } |
| 423 } | 422 } |
| 424 var resultBuilder = new ReplaceResultBuilder(subject, res); | 423 var resultBuilder = new ReplaceResultBuilder(subject, res); |
| 425 var result = resultBuilder.generate(); | 424 var result = resultBuilder.generate(); |
| 426 resultArray.length = 0; | 425 resultArray.length = 0; |
| 427 reusableReplaceArray = resultArray; | 426 reusableReplaceArray = resultArray; |
| 428 return result; | 427 return result; |
| 429 } | 428 } |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 "italics", StringItalics, | 906 "italics", StringItalics, |
| 908 "small", StringSmall, | 907 "small", StringSmall, |
| 909 "strike", StringStrike, | 908 "strike", StringStrike, |
| 910 "sub", StringSub, | 909 "sub", StringSub, |
| 911 "sup", StringSup | 910 "sup", StringSup |
| 912 )); | 911 )); |
| 913 } | 912 } |
| 914 | 913 |
| 915 | 914 |
| 916 SetupString(); | 915 SetupString(); |
| OLD | NEW |