| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 190 } |
| 191 | 191 |
| 192 var cache = regExpCache; | 192 var cache = regExpCache; |
| 193 var saveAnswer = false; | 193 var saveAnswer = false; |
| 194 | 194 |
| 195 if (%_ObjectEquals(cache.type, 'exec') && | 195 if (%_ObjectEquals(cache.type, 'exec') && |
| 196 %_ObjectEquals(cache.lastIndex, this.lastIndex) && | 196 %_ObjectEquals(cache.lastIndex, this.lastIndex) && |
| 197 %_ObjectEquals(cache.regExp, this) && | 197 %_ObjectEquals(cache.regExp, this) && |
| 198 %_ObjectEquals(cache.subject, string)) { | 198 %_ObjectEquals(cache.subject, string)) { |
| 199 if (cache.answerSaved) { | 199 if (cache.answerSaved) { |
| 200 if (this.global) this.lastIndex = 0; | |
| 201 return CloneRegExpResult(cache.answer); | 200 return CloneRegExpResult(cache.answer); |
| 202 } else { | 201 } else { |
| 203 saveAnswer = true; | 202 saveAnswer = true; |
| 204 } | 203 } |
| 205 } | 204 } |
| 206 | 205 |
| 207 if (%_ArgumentsLength() == 0) { | 206 if (%_ArgumentsLength() == 0) { |
| 208 var regExpInput = LAST_INPUT(lastMatchInfo); | 207 var regExpInput = LAST_INPUT(lastMatchInfo); |
| 209 if (IS_UNDEFINED(regExpInput)) { | 208 if (IS_UNDEFINED(regExpInput)) { |
| 210 throw MakeError('no_input_to_regexp', [this]); | 209 throw MakeError('no_input_to_regexp', [this]); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 224 if (i < 0 || i > s.length) { | 223 if (i < 0 || i > s.length) { |
| 225 this.lastIndex = 0; | 224 this.lastIndex = 0; |
| 226 return null; | 225 return null; |
| 227 } | 226 } |
| 228 | 227 |
| 229 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, s, lastIndex]); | 228 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, s, lastIndex]); |
| 230 // matchIndices is either null or the lastMatchInfo array. | 229 // matchIndices is either null or the lastMatchInfo array. |
| 231 var matchIndices = %_RegExpExec(this, s, i, lastMatchInfo); | 230 var matchIndices = %_RegExpExec(this, s, i, lastMatchInfo); |
| 232 | 231 |
| 233 if (matchIndices == null) { | 232 if (matchIndices == null) { |
| 234 if (this.global) this.lastIndex = 0; | 233 if (this.global) { |
| 234 this.lastIndex = 0; |
| 235 if (lastIndex != 0) return matchIndices; |
| 236 } |
| 235 cache.lastIndex = lastIndex; | 237 cache.lastIndex = lastIndex; |
| 236 cache.regExp = this; | 238 cache.regExp = this; |
| 237 cache.subject = s; | 239 cache.subject = s; |
| 238 cache.answer = matchIndices; // Null. | 240 cache.answer = matchIndices; // Null. |
| 239 cache.answerSaved = true; // Safe since no cloning is needed. | 241 cache.answerSaved = true; // Safe since no cloning is needed. |
| 240 cache.type = 'exec'; | 242 cache.type = 'exec'; |
| 241 return matchIndices; // No match. | 243 return matchIndices; // No match. |
| 242 } | 244 } |
| 243 lastMatchInfoOverride = null; | 245 lastMatchInfoOverride = null; |
| 244 var result = BuildResultFromMatchInfo(matchIndices, s); | 246 var result = BuildResultFromMatchInfo(matchIndices, s); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 540 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 539 | 541 |
| 540 for (var i = 1; i < 10; ++i) { | 542 for (var i = 1; i < 10; ++i) { |
| 541 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); | 543 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); |
| 542 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); | 544 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); |
| 543 } | 545 } |
| 544 } | 546 } |
| 545 | 547 |
| 546 | 548 |
| 547 SetupRegExp(); | 549 SetupRegExp(); |
| OLD | NEW |