| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 string = regExpInput; | 228 string = regExpInput; |
| 229 } | 229 } |
| 230 | 230 |
| 231 string = TO_STRING_INLINE(string); | 231 string = TO_STRING_INLINE(string); |
| 232 | 232 |
| 233 var lastIndex = this.lastIndex; | 233 var lastIndex = this.lastIndex; |
| 234 | 234 |
| 235 // Conversion is required by the ES5 specification (RegExp.prototype.exec | 235 // Conversion is required by the ES5 specification (RegExp.prototype.exec |
| 236 // algorithm, step 5) even if the value is discarded for non-global RegExps. | 236 // algorithm, step 5) even if the value is discarded for non-global RegExps. |
| 237 var i = TO_INTEGER(lastIndex); | 237 var i = TO_INTEGER(lastIndex); |
| 238 | 238 |
| 239 if (this.global) { | 239 if (this.global) { |
| 240 if (i < 0 || i > string.length) { | 240 if (i < 0 || i > string.length) { |
| 241 this.lastIndex = 0; | 241 this.lastIndex = 0; |
| 242 return false; | 242 return false; |
| 243 } | 243 } |
| 244 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); | 244 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); |
| 245 // matchIndices is either null or the lastMatchInfo array. | 245 // matchIndices is either null or the lastMatchInfo array. |
| 246 var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo); | 246 var matchIndices = %_RegExpExec(this, string, i, lastMatchInfo); |
| 247 if (matchIndices === null) { | 247 if (matchIndices === null) { |
| 248 this.lastIndex = 0; | 248 this.lastIndex = 0; |
| 249 return false; | 249 return false; |
| 250 } | 250 } |
| 251 lastMatchInfoOverride = null; | 251 lastMatchInfoOverride = null; |
| 252 this.lastIndex = lastMatchInfo[CAPTURE1]; | 252 this.lastIndex = lastMatchInfo[CAPTURE1]; |
| 253 return true; | 253 return true; |
| 254 } else { | 254 } else { |
| 255 // Non-global regexp. | 255 // Non-global regexp. |
| 256 // Remove irrelevant preceeding '.*' in a non-global test regexp. | 256 // Remove irrelevant preceeding '.*' in a non-global test regexp. |
| 257 // The expression checks whether this.source starts with '.*' and | 257 // The expression checks whether this.source starts with '.*' and |
| 258 // that the third char is not a '?'. | 258 // that the third char is not a '?'. |
| 259 if (%_StringCharCodeAt(this.source, 0) == 46 && // '.' | 259 if (%_StringCharCodeAt(this.source, 0) == 46 && // '.' |
| 260 %_StringCharCodeAt(this.source, 1) == 42 && // '*' | 260 %_StringCharCodeAt(this.source, 1) == 42 && // '*' |
| 261 %_StringCharCodeAt(this.source, 2) != 63) { // '?' | 261 %_StringCharCodeAt(this.source, 2) != 63) { // '?' |
| 262 if (!%_ObjectEquals(regexp_key, this)) { | 262 if (!%_ObjectEquals(regexp_key, this)) { |
| 263 regexp_key = this; | 263 regexp_key = this; |
| 264 regexp_val = new $RegExp(SubString(this.source, 2, this.source.length), | 264 regexp_val = new $RegExp(SubString(this.source, 2, this.source.length), |
| 265 (!this.ignoreCase | 265 (!this.ignoreCase |
| 266 ? !this.multiline ? "" : "m" | 266 ? !this.multiline ? "" : "m" |
| 267 : !this.multiline ? "i" : "im")); | 267 : !this.multiline ? "i" : "im")); |
| 268 } | 268 } |
| 269 if (%_RegExpExec(regexp_val, string, 0, lastMatchInfo) === null) { | 269 if (%_RegExpExec(regexp_val, string, 0, lastMatchInfo) === null) { |
| 270 return false; | 270 return false; |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); | 273 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); |
| 274 // matchIndices is either null or the lastMatchInfo array. | 274 // matchIndices is either null or the lastMatchInfo array. |
| 275 var matchIndices = %_RegExpExec(this, string, 0, lastMatchInfo); | 275 var matchIndices = %_RegExpExec(this, string, 0, lastMatchInfo); |
| 276 if (matchIndices === null) return false; | 276 if (matchIndices === null) return false; |
| 277 lastMatchInfoOverride = null; | 277 lastMatchInfoOverride = null; |
| 278 return true; | 278 return true; |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 | 282 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 474 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 475 | 475 |
| 476 for (var i = 1; i < 10; ++i) { | 476 for (var i = 1; i < 10; ++i) { |
| 477 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); | 477 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); |
| 478 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); | 478 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); |
| 479 } | 479 } |
| 480 } | 480 } |
| 481 | 481 |
| 482 | 482 |
| 483 SetupRegExp(); | 483 SetupRegExp(); |
| OLD | NEW |