| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file relies on the fact that the following declaration has been made | 5 // This file relies on the fact that the following declaration has been made |
| 6 // in runtime.js: | 6 // in runtime.js: |
| 7 // var $String = global.String; | 7 // var $String = global.String; |
| 8 | 8 |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 | 10 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 function StringMatch(regexp) { | 143 function StringMatch(regexp) { |
| 144 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); | 144 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); |
| 145 | 145 |
| 146 var subject = TO_STRING_INLINE(this); | 146 var subject = TO_STRING_INLINE(this); |
| 147 if (IS_REGEXP(regexp)) { | 147 if (IS_REGEXP(regexp)) { |
| 148 // Emulate RegExp.prototype.exec's side effect in step 5, even though | 148 // Emulate RegExp.prototype.exec's side effect in step 5, even though |
| 149 // value is discarded. | 149 // value is discarded. |
| 150 var lastIndex = regexp.lastIndex; | 150 var lastIndex = regexp.lastIndex; |
| 151 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); | 151 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); |
| 152 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); | 152 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); |
| 153 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); | |
| 154 // lastMatchInfo is defined in regexp.js. | 153 // lastMatchInfo is defined in regexp.js. |
| 155 var result = %StringMatch(subject, regexp, lastMatchInfo); | 154 var result = %StringMatch(subject, regexp, lastMatchInfo); |
| 156 if (result !== null) lastMatchInfoOverride = null; | 155 if (result !== null) lastMatchInfoOverride = null; |
| 157 regexp.lastIndex = 0; | 156 regexp.lastIndex = 0; |
| 158 return result; | 157 return result; |
| 159 } | 158 } |
| 160 // Non-regexp argument. | 159 // Non-regexp argument. |
| 161 regexp = new $RegExp(regexp); | 160 regexp = new $RegExp(regexp); |
| 162 return RegExpExecNoTests(regexp, subject, 0); | 161 return RegExpExecNoTests(regexp, subject, 0); |
| 163 } | 162 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // .. string search | 213 // .. string search |
| 215 // .... special case that replaces with one single character | 214 // .... special case that replaces with one single character |
| 216 // ...... function replace | 215 // ...... function replace |
| 217 // ...... string replace (with $-expansion) | 216 // ...... string replace (with $-expansion) |
| 218 | 217 |
| 219 if (IS_REGEXP(search)) { | 218 if (IS_REGEXP(search)) { |
| 220 // Emulate RegExp.prototype.exec's side effect in step 5, even if | 219 // Emulate RegExp.prototype.exec's side effect in step 5, even if |
| 221 // value is discarded. | 220 // value is discarded. |
| 222 var lastIndex = search.lastIndex; | 221 var lastIndex = search.lastIndex; |
| 223 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); | 222 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex); |
| 224 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); | |
| 225 | 223 |
| 226 if (!IS_SPEC_FUNCTION(replace)) { | 224 if (!IS_SPEC_FUNCTION(replace)) { |
| 227 replace = TO_STRING_INLINE(replace); | 225 replace = TO_STRING_INLINE(replace); |
| 228 | 226 |
| 229 if (!search.global) { | 227 if (!search.global) { |
| 230 // Non-global regexp search, string replace. | 228 // Non-global regexp search, string replace. |
| 231 var match = DoRegExpExec(search, subject, 0); | 229 var match = DoRegExpExec(search, subject, 0); |
| 232 if (match == null) { | 230 if (match == null) { |
| 233 search.lastIndex = 0 | 231 search.lastIndex = 0 |
| 234 return subject; | 232 return subject; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 if (limit === 0) return []; | 614 if (limit === 0) return []; |
| 617 | 615 |
| 618 // Separator is a regular expression. | 616 // Separator is a regular expression. |
| 619 return StringSplitOnRegExp(subject, separator, limit, length); | 617 return StringSplitOnRegExp(subject, separator, limit, length); |
| 620 } | 618 } |
| 621 | 619 |
| 622 | 620 |
| 623 var ArrayPushBuiltin = $Array.prototype.push; | 621 var ArrayPushBuiltin = $Array.prototype.push; |
| 624 | 622 |
| 625 function StringSplitOnRegExp(subject, separator, limit, length) { | 623 function StringSplitOnRegExp(subject, separator, limit, length) { |
| 626 %_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]); | |
| 627 | |
| 628 if (length === 0) { | 624 if (length === 0) { |
| 629 if (DoRegExpExec(separator, subject, 0, 0) != null) { | 625 if (DoRegExpExec(separator, subject, 0, 0) != null) { |
| 630 return []; | 626 return []; |
| 631 } | 627 } |
| 632 return [subject]; | 628 return [subject]; |
| 633 } | 629 } |
| 634 | 630 |
| 635 var currentIndex = 0; | 631 var currentIndex = 0; |
| 636 var startIndex = 0; | 632 var startIndex = 0; |
| 637 var startMatch = 0; | 633 var startMatch = 0; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 "fixed", StringFixed, | 963 "fixed", StringFixed, |
| 968 "italics", StringItalics, | 964 "italics", StringItalics, |
| 969 "small", StringSmall, | 965 "small", StringSmall, |
| 970 "strike", StringStrike, | 966 "strike", StringStrike, |
| 971 "sub", StringSub, | 967 "sub", StringSub, |
| 972 "sup", StringSup | 968 "sup", StringSup |
| 973 )); | 969 )); |
| 974 } | 970 } |
| 975 | 971 |
| 976 SetUpString(); | 972 SetUpString(); |
| OLD | NEW |