| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 this.answer = 0; | 130 this.answer = 0; |
| 131 // answerSaved marks whether the contents of answer is valid for a cache | 131 // answerSaved marks whether the contents of answer is valid for a cache |
| 132 // hit in RegExpExec, StringMatch and StringSplit. | 132 // hit in RegExpExec, StringMatch and StringSplit. |
| 133 this.answerSaved = false; | 133 this.answerSaved = false; |
| 134 } | 134 } |
| 135 | 135 |
| 136 | 136 |
| 137 var regExpCache = new RegExpCache(); | 137 var regExpCache = new RegExpCache(); |
| 138 | 138 |
| 139 | 139 |
| 140 function CloneRegExpResult(array) { | |
| 141 if (array == null) return null; | |
| 142 var length = array.length; | |
| 143 var answer = %_RegExpConstructResult(length, array.index, array.input); | |
| 144 for (var i = 0; i < length; i++) { | |
| 145 answer[i] = array[i]; | |
| 146 } | |
| 147 return answer; | |
| 148 } | |
| 149 | |
| 150 | |
| 151 function BuildResultFromMatchInfo(lastMatchInfo, s) { | 140 function BuildResultFromMatchInfo(lastMatchInfo, s) { |
| 152 var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; | 141 var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; |
| 153 var result = %_RegExpConstructResult(numResults, lastMatchInfo[CAPTURE0], s); | 142 var result = %_RegExpConstructResult(numResults, lastMatchInfo[CAPTURE0], s); |
| 154 if (numResults === 1) { | 143 if (numResults === 1) { |
| 155 var matchStart = lastMatchInfo[CAPTURE(0)]; | 144 var matchStart = lastMatchInfo[CAPTURE(0)]; |
| 156 var matchEnd = lastMatchInfo[CAPTURE(1)]; | 145 var matchEnd = lastMatchInfo[CAPTURE(1)]; |
| 157 result[0] = SubString(s, matchStart, matchEnd); | 146 result[0] = SubString(s, matchStart, matchEnd); |
| 158 } else { | 147 } else { |
| 159 for (var i = 0; i < numResults; i++) { | 148 for (var i = 0; i < numResults; i++) { |
| 160 var matchStart = lastMatchInfo[CAPTURE(i << 1)]; | 149 var matchStart = lastMatchInfo[CAPTURE(i << 1)]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 190 } | 179 } |
| 191 | 180 |
| 192 var cache = regExpCache; | 181 var cache = regExpCache; |
| 193 var saveAnswer = false; | 182 var saveAnswer = false; |
| 194 | 183 |
| 195 if (%_ObjectEquals(cache.type, 'exec') && | 184 if (%_ObjectEquals(cache.type, 'exec') && |
| 196 %_ObjectEquals(cache.lastIndex, this.lastIndex) && | 185 %_ObjectEquals(cache.lastIndex, this.lastIndex) && |
| 197 %_IsRegExpEquivalent(cache.regExp, this) && | 186 %_IsRegExpEquivalent(cache.regExp, this) && |
| 198 %_ObjectEquals(cache.subject, string)) { | 187 %_ObjectEquals(cache.subject, string)) { |
| 199 if (cache.answerSaved) { | 188 if (cache.answerSaved) { |
| 200 return CloneRegExpResult(cache.answer); | 189 return %_RegExpCloneResult(cache.answer); |
| 201 } else { | 190 } else { |
| 202 saveAnswer = true; | 191 saveAnswer = true; |
| 203 } | 192 } |
| 204 } | 193 } |
| 205 | 194 |
| 206 if (%_ArgumentsLength() == 0) { | 195 if (%_ArgumentsLength() == 0) { |
| 207 var regExpInput = LAST_INPUT(lastMatchInfo); | 196 var regExpInput = LAST_INPUT(lastMatchInfo); |
| 208 if (IS_UNDEFINED(regExpInput)) { | 197 if (IS_UNDEFINED(regExpInput)) { |
| 209 throw MakeError('no_input_to_regexp', [this]); | 198 throw MakeError('no_input_to_regexp', [this]); |
| 210 } | 199 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 233 } |
| 245 lastMatchInfoOverride = null; | 234 lastMatchInfoOverride = null; |
| 246 var result = BuildResultFromMatchInfo(matchIndices, s); | 235 var result = BuildResultFromMatchInfo(matchIndices, s); |
| 247 | 236 |
| 248 if (this.global) { | 237 if (this.global) { |
| 249 this.lastIndex = lastMatchInfo[CAPTURE1]; | 238 this.lastIndex = lastMatchInfo[CAPTURE1]; |
| 250 } else { | 239 } else { |
| 251 cache.regExp = this; | 240 cache.regExp = this; |
| 252 cache.subject = s; | 241 cache.subject = s; |
| 253 cache.lastIndex = lastIndex; | 242 cache.lastIndex = lastIndex; |
| 254 if (saveAnswer) cache.answer = CloneRegExpResult(result); | 243 if (saveAnswer) cache.answer = %_RegExpCloneResult(result); |
| 255 cache.answerSaved = saveAnswer; | 244 cache.answerSaved = saveAnswer; |
| 256 cache.type = 'exec'; | 245 cache.type = 'exec'; |
| 257 } | 246 } |
| 258 return result; | 247 return result; |
| 259 | 248 |
| 260 } | 249 } |
| 261 | 250 |
| 262 | 251 |
| 263 // One-element cache for the simplified test regexp. | 252 // One-element cache for the simplified test regexp. |
| 264 var regexp_key; | 253 var regexp_key; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 529 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 541 | 530 |
| 542 for (var i = 1; i < 10; ++i) { | 531 for (var i = 1; i < 10; ++i) { |
| 543 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); | 532 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); |
| 544 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); | 533 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); |
| 545 } | 534 } |
| 546 } | 535 } |
| 547 | 536 |
| 548 | 537 |
| 549 SetupRegExp(); | 538 SetupRegExp(); |
| OLD | NEW |