| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 | 156 |
| 157 function RegExpExecNoTests(regexp, string, start) { | 157 function RegExpExecNoTests(regexp, string, start) { |
| 158 // Must be called with RegExp, string and positive integer as arguments. | 158 // Must be called with RegExp, string and positive integer as arguments. |
| 159 var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); | 159 var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); |
| 160 if (matchInfo !== null) { | 160 if (matchInfo !== null) { |
| 161 lastMatchInfoOverride = null; | 161 lastMatchInfoOverride = null; |
| 162 return BuildResultFromMatchInfo(matchInfo, string); | 162 return BuildResultFromMatchInfo(matchInfo, string); |
| 163 } | 163 } |
| 164 regexp.lastIndex = 0; |
| 164 return null; | 165 return null; |
| 165 } | 166 } |
| 166 | 167 |
| 167 | 168 |
| 168 function RegExpExec(string) { | 169 function RegExpExec(string) { |
| 169 if (!IS_REGEXP(this)) { | 170 if (!IS_REGEXP(this)) { |
| 170 throw MakeTypeError('incompatible_method_receiver', | 171 throw MakeTypeError('incompatible_method_receiver', |
| 171 ['RegExp.prototype.exec', this]); | 172 ['RegExp.prototype.exec', this]); |
| 172 } | 173 } |
| 173 | 174 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 186 } | 187 } |
| 187 } else { | 188 } else { |
| 188 i = 0; | 189 i = 0; |
| 189 } | 190 } |
| 190 | 191 |
| 191 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); | 192 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); |
| 192 // matchIndices is either null or the lastMatchInfo array. | 193 // matchIndices is either null or the lastMatchInfo array. |
| 193 var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo); | 194 var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo); |
| 194 | 195 |
| 195 if (matchIndices === null) { | 196 if (matchIndices === null) { |
| 196 if (global) this.lastIndex = 0; | 197 this.lastIndex = 0; |
| 197 return null; | 198 return null; |
| 198 } | 199 } |
| 199 | 200 |
| 200 // Successful match. | 201 // Successful match. |
| 201 lastMatchInfoOverride = null; | 202 lastMatchInfoOverride = null; |
| 202 if (global) { | 203 if (global) { |
| 203 this.lastIndex = lastMatchInfo[CAPTURE1]; | 204 this.lastIndex = lastMatchInfo[CAPTURE1]; |
| 204 } | 205 } |
| 205 return BuildResultFromMatchInfo(matchIndices, string); | 206 return BuildResultFromMatchInfo(matchIndices, string); |
| 206 } | 207 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // that the third char is not a '?'. | 250 // that the third char is not a '?'. |
| 250 var regexp = this; | 251 var regexp = this; |
| 251 if (%_StringCharCodeAt(regexp.source, 0) == 46 && // '.' | 252 if (%_StringCharCodeAt(regexp.source, 0) == 46 && // '.' |
| 252 %_StringCharCodeAt(regexp.source, 1) == 42 && // '*' | 253 %_StringCharCodeAt(regexp.source, 1) == 42 && // '*' |
| 253 %_StringCharCodeAt(regexp.source, 2) != 63) { // '?' | 254 %_StringCharCodeAt(regexp.source, 2) != 63) { // '?' |
| 254 regexp = TrimRegExp(regexp); | 255 regexp = TrimRegExp(regexp); |
| 255 } | 256 } |
| 256 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [regexp, string, lastIndex]); | 257 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [regexp, string, lastIndex]); |
| 257 // matchIndices is either null or the lastMatchInfo array. | 258 // matchIndices is either null or the lastMatchInfo array. |
| 258 var matchIndices = %_RegExpExec(regexp, string, 0, lastMatchInfo); | 259 var matchIndices = %_RegExpExec(regexp, string, 0, lastMatchInfo); |
| 259 if (matchIndices === null) return false; | 260 if (matchIndices === null) { |
| 261 this.lastIndex = 0; |
| 262 return false; |
| 263 } |
| 260 lastMatchInfoOverride = null; | 264 lastMatchInfoOverride = null; |
| 261 return true; | 265 return true; |
| 262 } | 266 } |
| 263 } | 267 } |
| 264 | 268 |
| 265 function TrimRegExp(regexp) { | 269 function TrimRegExp(regexp) { |
| 266 if (!%_ObjectEquals(regexp_key, regexp)) { | 270 if (!%_ObjectEquals(regexp_key, regexp)) { |
| 267 regexp_key = regexp; | 271 regexp_key = regexp; |
| 268 regexp_val = | 272 regexp_val = |
| 269 new $RegExp(SubString(regexp.source, 2, regexp.source.length), | 273 new $RegExp(SubString(regexp.source, 2, regexp.source.length), |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 480 |
| 477 for (var i = 1; i < 10; ++i) { | 481 for (var i = 1; i < 10; ++i) { |
| 478 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, | 482 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, |
| 479 RegExpMakeCaptureGetter(i), NoOpSetter, | 483 RegExpMakeCaptureGetter(i), NoOpSetter, |
| 480 DONT_DELETE); | 484 DONT_DELETE); |
| 481 } | 485 } |
| 482 %ToFastProperties($RegExp); | 486 %ToFastProperties($RegExp); |
| 483 } | 487 } |
| 484 | 488 |
| 485 SetUpRegExp(); | 489 SetUpRegExp(); |
| OLD | NEW |