| 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 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
| 8 | 8 |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 // Imports | 10 // Imports |
| 11 | 11 |
| 12 var ArrayIndexOf; | 12 var ArrayIndexOf; |
| 13 var ArrayJoin; | 13 var ArrayJoin; |
| 14 var GlobalRegExp = global.RegExp; | 14 var GlobalRegExp = global.RegExp; |
| 15 var GlobalString = global.String; | 15 var GlobalString = global.String; |
| 16 var InternalArray = utils.InternalArray; | 16 var InternalArray = utils.InternalArray; |
| 17 var InternalPackedArray = utils.InternalPackedArray; | 17 var InternalPackedArray = utils.InternalPackedArray; |
| 18 var MakeRangeError; | 18 var MakeRangeError; |
| 19 var MakeTypeError; | 19 var MakeTypeError; |
| 20 var RegExpExec; | 20 var RegExpExec; |
| 21 var RegExpExecNoTests; | 21 var RegExpExecNoTests; |
| 22 var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol"); |
| 22 var RegExpLastMatchInfo; | 23 var RegExpLastMatchInfo; |
| 23 | 24 |
| 24 utils.Import(function(from) { | 25 utils.Import(function(from) { |
| 25 ArrayIndexOf = from.ArrayIndexOf; | 26 ArrayIndexOf = from.ArrayIndexOf; |
| 26 ArrayJoin = from.ArrayJoin; | 27 ArrayJoin = from.ArrayJoin; |
| 27 MakeRangeError = from.MakeRangeError; | 28 MakeRangeError = from.MakeRangeError; |
| 28 MakeTypeError = from.MakeTypeError; | 29 MakeTypeError = from.MakeTypeError; |
| 29 RegExpExec = from.RegExpExec; | 30 RegExpExec = from.RegExpExec; |
| 30 RegExpExecNoTests = from.RegExpExecNoTests; | 31 RegExpExecNoTests = from.RegExpExecNoTests; |
| 31 RegExpLastMatchInfo = from.RegExpLastMatchInfo; | 32 RegExpLastMatchInfo = from.RegExpLastMatchInfo; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return %StringLocaleCompare(TO_STRING(this), TO_STRING(other)); | 149 return %StringLocaleCompare(TO_STRING(this), TO_STRING(other)); |
| 149 } | 150 } |
| 150 | 151 |
| 151 | 152 |
| 152 // ECMA-262 section 15.5.4.10 | 153 // ECMA-262 section 15.5.4.10 |
| 153 function StringMatchJS(regexp) { | 154 function StringMatchJS(regexp) { |
| 154 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); | 155 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); |
| 155 | 156 |
| 156 var subject = TO_STRING(this); | 157 var subject = TO_STRING(this); |
| 157 if (IS_REGEXP(regexp)) { | 158 if (IS_REGEXP(regexp)) { |
| 158 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); | 159 if (!REGEXP_GLOBAL(regexp)) return RegExpExecNoTests(regexp, subject, 0); |
| 159 var result = %StringMatch(subject, regexp, RegExpLastMatchInfo); | 160 var result = %StringMatch(subject, regexp, RegExpLastMatchInfo); |
| 160 regexp.lastIndex = 0; | 161 regexp.lastIndex = 0; |
| 161 return result; | 162 return result; |
| 162 } | 163 } |
| 163 // Non-regexp argument. | 164 // Non-regexp argument. |
| 164 regexp = new GlobalRegExp(regexp); | 165 regexp = new GlobalRegExp(regexp); |
| 165 return RegExpExecNoTests(regexp, subject, 0); | 166 return RegExpExecNoTests(regexp, subject, 0); |
| 166 } | 167 } |
| 167 | 168 |
| 168 | 169 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // ...... non-global search | 219 // ...... non-global search |
| 219 // .. string search | 220 // .. string search |
| 220 // .... special case that replaces with one single character | 221 // .... special case that replaces with one single character |
| 221 // ...... function replace | 222 // ...... function replace |
| 222 // ...... string replace (with $-expansion) | 223 // ...... string replace (with $-expansion) |
| 223 | 224 |
| 224 if (IS_REGEXP(search)) { | 225 if (IS_REGEXP(search)) { |
| 225 if (!IS_CALLABLE(replace)) { | 226 if (!IS_CALLABLE(replace)) { |
| 226 replace = TO_STRING(replace); | 227 replace = TO_STRING(replace); |
| 227 | 228 |
| 228 if (!search.global) { | 229 if (!REGEXP_GLOBAL(search)) { |
| 229 // Non-global regexp search, string replace. | 230 // Non-global regexp search, string replace. |
| 230 var match = RegExpExec(search, subject, 0); | 231 var match = RegExpExec(search, subject, 0); |
| 231 if (match == null) { | 232 if (match == null) { |
| 232 search.lastIndex = 0 | 233 search.lastIndex = 0 |
| 233 return subject; | 234 return subject; |
| 234 } | 235 } |
| 235 if (replace.length == 0) { | 236 if (replace.length == 0) { |
| 236 return %_SubString(subject, 0, match[CAPTURE0]) + | 237 return %_SubString(subject, 0, match[CAPTURE0]) + |
| 237 %_SubString(subject, match[CAPTURE1], subject.length) | 238 %_SubString(subject, match[CAPTURE1], subject.length) |
| 238 } | 239 } |
| 239 return ExpandReplacement(replace, subject, RegExpLastMatchInfo, | 240 return ExpandReplacement(replace, subject, RegExpLastMatchInfo, |
| 240 %_SubString(subject, 0, match[CAPTURE0])) + | 241 %_SubString(subject, 0, match[CAPTURE0])) + |
| 241 %_SubString(subject, match[CAPTURE1], subject.length); | 242 %_SubString(subject, match[CAPTURE1], subject.length); |
| 242 } | 243 } |
| 243 | 244 |
| 244 // Global regexp search, string replace. | 245 // Global regexp search, string replace. |
| 245 search.lastIndex = 0; | 246 search.lastIndex = 0; |
| 246 return %StringReplaceGlobalRegExpWithString( | 247 return %StringReplaceGlobalRegExpWithString( |
| 247 subject, search, replace, RegExpLastMatchInfo); | 248 subject, search, replace, RegExpLastMatchInfo); |
| 248 } | 249 } |
| 249 | 250 |
| 250 if (search.global) { | 251 if (REGEXP_GLOBAL(search)) { |
| 251 // Global regexp search, function replace. | 252 // Global regexp search, function replace. |
| 252 return StringReplaceGlobalRegExpWithFunction(subject, search, replace); | 253 return StringReplaceGlobalRegExpWithFunction(subject, search, replace); |
| 253 } | 254 } |
| 254 // Non-global regexp search, function replace. | 255 // Non-global regexp search, function replace. |
| 255 return StringReplaceNonGlobalRegExpWithFunction(subject, search, replace); | 256 return StringReplaceNonGlobalRegExpWithFunction(subject, search, replace); |
| 256 } | 257 } |
| 257 | 258 |
| 258 search = TO_STRING(search); | 259 search = TO_STRING(search); |
| 259 | 260 |
| 260 if (search.length == 1 && | 261 if (search.length == 1 && |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 to.StringLastIndexOf = StringLastIndexOfJS; | 1171 to.StringLastIndexOf = StringLastIndexOfJS; |
| 1171 to.StringMatch = StringMatchJS; | 1172 to.StringMatch = StringMatchJS; |
| 1172 to.StringReplace = StringReplace; | 1173 to.StringReplace = StringReplace; |
| 1173 to.StringSlice = StringSlice; | 1174 to.StringSlice = StringSlice; |
| 1174 to.StringSplit = StringSplitJS; | 1175 to.StringSplit = StringSplitJS; |
| 1175 to.StringSubstr = StringSubstr; | 1176 to.StringSubstr = StringSubstr; |
| 1176 to.StringSubstring = StringSubstring; | 1177 to.StringSubstring = StringSubstring; |
| 1177 }); | 1178 }); |
| 1178 | 1179 |
| 1179 }) | 1180 }) |
| OLD | NEW |