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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 var end = lastMatchInfo[CAPTURE1]; | 133 var end = lastMatchInfo[CAPTURE1]; |
134 var result = %_RegExpConstructResult(numResults, start, s); | 134 var result = %_RegExpConstructResult(numResults, start, s); |
135 if (start + 1 == end) { | 135 if (start + 1 == end) { |
136 result[0] = %_StringCharAt(s, start); | 136 result[0] = %_StringCharAt(s, start); |
137 } else { | 137 } else { |
138 result[0] = %_SubString(s, start, end); | 138 result[0] = %_SubString(s, start, end); |
139 } | 139 } |
140 var j = REGEXP_FIRST_CAPTURE + 2; | 140 var j = REGEXP_FIRST_CAPTURE + 2; |
141 for (var i = 1; i < numResults; i++) { | 141 for (var i = 1; i < numResults; i++) { |
142 start = lastMatchInfo[j++]; | 142 start = lastMatchInfo[j++]; |
143 end = lastMatchInfo[j++]; | 143 if (start != -1) { |
144 if (end != -1) { | 144 end = lastMatchInfo[j]; |
145 if (start + 1 == end) { | 145 if (start + 1 == end) { |
146 result[i] = %_StringCharAt(s, start); | 146 result[i] = %_StringCharAt(s, start); |
147 } else { | 147 } else { |
148 result[i] = %_SubString(s, start, end); | 148 result[i] = %_SubString(s, start, end); |
149 } | 149 } |
150 } else { | |
151 // Make sure the element is present. Avoid reading the undefined | |
152 // property from the global object since this may change. | |
153 result[i] = void 0; | |
154 } | 150 } |
| 151 j++; |
155 } | 152 } |
156 return result; | 153 return result; |
157 } | 154 } |
158 | 155 |
159 | 156 |
160 function RegExpExecNoTests(regexp, string, start) { | 157 function RegExpExecNoTests(regexp, string, start) { |
161 // Must be called with RegExp, string and positive integer as arguments. | 158 // Must be called with RegExp, string and positive integer as arguments. |
162 var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); | 159 var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); |
163 if (matchInfo !== null) { | 160 if (matchInfo !== null) { |
164 lastMatchInfoOverride = null; | 161 lastMatchInfoOverride = null; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 476 |
480 for (var i = 1; i < 10; ++i) { | 477 for (var i = 1; i < 10; ++i) { |
481 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, | 478 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, |
482 RegExpMakeCaptureGetter(i), NoOpSetter, | 479 RegExpMakeCaptureGetter(i), NoOpSetter, |
483 DONT_DELETE); | 480 DONT_DELETE); |
484 } | 481 } |
485 %ToFastProperties($RegExp); | 482 %ToFastProperties($RegExp); |
486 } | 483 } |
487 | 484 |
488 SetUpRegExp(); | 485 SetUpRegExp(); |
OLD | NEW |