Chromium Code Reviews| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 | 113 |
| 114 function DoRegExpExec(regexp, string, index) { | 114 function DoRegExpExec(regexp, string, index) { |
| 115 var result = %_RegExpExec(regexp, string, index, lastMatchInfo); | 115 var result = %_RegExpExec(regexp, string, index, lastMatchInfo); |
| 116 if (result !== null) lastMatchInfoOverride = null; | 116 if (result !== null) lastMatchInfoOverride = null; |
| 117 return result; | 117 return result; |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 function BuildResultFromMatchInfo(lastMatchInfo, s) { | 121 function BuildResultFromMatchInfo(lastMatchInfo, s) { |
| 122 var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; | 122 var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; |
| 123 var result = %_RegExpConstructResult(numResults, lastMatchInfo[CAPTURE0], s); | 123 var start = lastMatchInfo[CAPTURE0]; |
| 124 if (numResults === 1) { | 124 var end = lastMatchInfo[CAPTURE1]; |
| 125 var matchStart = lastMatchInfo[CAPTURE(0)]; | 125 var result = %_RegExpConstructResult(numResults, start, s); |
| 126 var matchEnd = lastMatchInfo[CAPTURE(1)]; | 126 if (start + 1 == end) { |
|
Lasse Reichstein
2010/12/13 09:29:13
Why not just lop from match 0/j = 3 instead of spe
sandholm
2010/12/13 12:03:35
The array lookup for start is re-used in the RegEx
| |
| 127 result[0] = SubString(s, matchStart, matchEnd); | 127 result[0] = %_StringCharAt(s, start); |
| 128 } else { | 128 } else { |
| 129 for (var i = 0; i < numResults; i++) { | 129 result[0] = %_SubString(s, start, end); |
| 130 var matchStart = lastMatchInfo[CAPTURE(i << 1)]; | 130 } |
| 131 var matchEnd = lastMatchInfo[CAPTURE((i << 1) + 1)]; | 131 var j = 5; |
|
Lasse Reichstein
2010/12/13 09:29:13
var j = REGEXP_FIRST_CAPTURE + 2;
sandholm
2010/12/13 12:03:35
Done.
| |
| 132 if (matchStart != -1 && matchEnd != -1) { | 132 for (var i = 1; i < numResults; i++) { |
| 133 result[i] = SubString(s, matchStart, matchEnd); | 133 start = lastMatchInfo[j++]; |
| 134 end = lastMatchInfo[j++]; | |
| 135 if (end != -1) { | |
| 136 if (start + 1 == end) { | |
| 137 result[i] = %_StringCharAt(s, start); | |
| 134 } else { | 138 } else { |
| 135 // Make sure the element is present. Avoid reading the undefined | 139 result[i] = %_SubString(s, start, end); |
| 136 // property from the global object since this may change. | |
| 137 result[i] = void 0; | |
| 138 } | 140 } |
| 141 } else { | |
| 142 // Make sure the element is present. Avoid reading the undefined | |
| 143 // property from the global object since this may change. | |
| 144 result[i] = void 0; | |
| 139 } | 145 } |
| 140 } | 146 } |
| 141 return result; | 147 return result; |
| 142 } | 148 } |
| 143 | 149 |
| 144 | 150 |
| 145 function RegExpExecNoTests(regexp, string, start) { | 151 function RegExpExecNoTests(regexp, string, start) { |
| 146 // Must be called with RegExp, string and positive integer as arguments. | 152 // Must be called with RegExp, string and positive integer as arguments. |
| 147 var matchInfo = DoRegExpExec(regexp, string, start); | 153 var matchInfo = DoRegExpExec(regexp, string, start); |
| 148 var result = null; | 154 var result = null; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); | 481 %DefineAccessor($RegExp, "$'", SETTER, NoOpSetter, DONT_ENUM | DONT_DELETE); |
| 476 | 482 |
| 477 for (var i = 1; i < 10; ++i) { | 483 for (var i = 1; i < 10; ++i) { |
| 478 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D ELETE); | 484 %DefineAccessor($RegExp, '$' + i, GETTER, RegExpMakeCaptureGetter(i), DONT_D ELETE); |
| 479 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); | 485 %DefineAccessor($RegExp, '$' + i, SETTER, NoOpSetter, DONT_DELETE); |
| 480 } | 486 } |
| 481 } | 487 } |
| 482 | 488 |
| 483 | 489 |
| 484 SetupRegExp(); | 490 SetupRegExp(); |
| OLD | NEW |