| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (result !== null) lastMatchInfoOverride = null; | 119 if (result !== null) lastMatchInfoOverride = null; |
| 120 return result; | 120 return result; |
| 121 } | 121 } |
| 122 | 122 |
| 123 | 123 |
| 124 function RegExpCache() { | 124 function RegExpCache() { |
| 125 this.type = 'none'; | 125 this.type = 'none'; |
| 126 this.regExp = 0; | 126 this.regExp = 0; |
| 127 this.subject = 0; | 127 this.subject = 0; |
| 128 this.replaceString = 0; | 128 this.replaceString = 0; |
| 129 this.lastIndex = 0; | 129 this.lastIndex = 0; // Also used for splitLimit when type is "split" |
| 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 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 if (!IS_REGEXP(this)) { | 187 if (!IS_REGEXP(this)) { |
| 188 throw MakeTypeError('incompatible_method_receiver', | 188 throw MakeTypeError('incompatible_method_receiver', |
| 189 ['RegExp.prototype.exec', this]); | 189 ['RegExp.prototype.exec', this]); |
| 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 %_IsRegExpEquivalent(cache.regExp, this) && |
| 198 %_ObjectEquals(cache.subject, string)) { | 198 %_ObjectEquals(cache.subject, string)) { |
| 199 if (cache.answerSaved) { | 199 if (cache.answerSaved) { |
| 200 return CloneRegExpResult(cache.answer); | 200 return CloneRegExpResult(cache.answer); |
| 201 } else { | 201 } else { |
| 202 saveAnswer = true; | 202 saveAnswer = true; |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 if (%_ArgumentsLength() == 0) { | 206 if (%_ArgumentsLength() == 0) { |
| 207 var regExpInput = LAST_INPUT(lastMatchInfo); | 207 var regExpInput = LAST_INPUT(lastMatchInfo); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 var s; | 283 var s; |
| 284 if (IS_STRING(string)) { | 284 if (IS_STRING(string)) { |
| 285 s = string; | 285 s = string; |
| 286 } else { | 286 } else { |
| 287 s = ToString(string); | 287 s = ToString(string); |
| 288 } | 288 } |
| 289 | 289 |
| 290 var lastIndex = this.lastIndex; | 290 var lastIndex = this.lastIndex; |
| 291 var cache = regExpCache; | 291 var cache = regExpCache; |
| 292 if (%_ObjectEquals(cache.type, 'test') && | 292 if (%_ObjectEquals(cache.type, 'test') && |
| 293 %_ObjectEquals(cache.regExp, this) && | 293 %_IsRegExpEquivalent(cache.regExp, this) && |
| 294 %_ObjectEquals(cache.subject, string) && | 294 %_ObjectEquals(cache.subject, string) && |
| 295 %_ObjectEquals(cache.lastIndex, lastIndex)) { | 295 %_ObjectEquals(cache.lastIndex, lastIndex)) { |
| 296 return cache.answer; | 296 return cache.answer; |
| 297 } | 297 } |
| 298 | 298 |
| 299 // Remove irrelevant preceeding '.*' in a test regexp. The expression | 299 // Remove irrelevant preceeding '.*' in a test regexp. The expression |
| 300 // checks whether this.source starts with '.*' and that the third | 300 // checks whether this.source starts with '.*' and that the third |
| 301 // char is not a '?' | 301 // char is not a '?' |
| 302 if (%_StringCharCodeAt(this.source,0) == 46 && // '.' | 302 if (%_StringCharCodeAt(this.source,0) == 46 && // '.' |
| 303 %_StringCharCodeAt(this.source,1) == 42 && // '*' | 303 %_StringCharCodeAt(this.source,1) == 42 && // '*' |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 540 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 541 | 541 |
| 542 for (var i = 1; i < 10; ++i) { | 542 for (var i = 1; i < 10; ++i) { |
| 543 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); | 543 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D
ELETE); |
| 544 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); | 544 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); |
| 545 } | 545 } |
| 546 } | 546 } |
| 547 | 547 |
| 548 | 548 |
| 549 SetupRegExp(); | 549 SetupRegExp(); |
| OLD | NEW |