OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file relies on the fact that the following declaration has been made | 5 // This file relies on the fact that the following declaration has been made |
6 // in runtime.js: | 6 // in runtime.js: |
7 // var $Object = global.Object; | 7 // var $Object = global.Object; |
8 // var $Array = global.Array; | 8 // var $Array = global.Array; |
9 | 9 |
10 var $RegExp = global.RegExp; | 10 var $RegExp = global.RegExp; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 var result = %_RegExpExec(regexp, string, index, lastMatchInfo); | 105 var result = %_RegExpExec(regexp, string, index, lastMatchInfo); |
106 if (result !== null) lastMatchInfoOverride = null; | 106 if (result !== null) lastMatchInfoOverride = null; |
107 return result; | 107 return result; |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 function BuildResultFromMatchInfo(lastMatchInfo, s) { | 111 function BuildResultFromMatchInfo(lastMatchInfo, s) { |
112 var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; | 112 var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; |
113 var start = lastMatchInfo[CAPTURE0]; | 113 var start = lastMatchInfo[CAPTURE0]; |
114 var end = lastMatchInfo[CAPTURE1]; | 114 var end = lastMatchInfo[CAPTURE1]; |
115 var first_match = %_SubString(s, start, end); | |
115 var result = %_RegExpConstructResult(numResults, start, s); | 116 var result = %_RegExpConstructResult(numResults, start, s); |
116 result[0] = %_SubString(s, start, end); | 117 result[0] = first_match; |
Yang
2014/05/14 13:25:23
Is this change necessary?
| |
118 if (numResults == 1) return result; | |
117 var j = REGEXP_FIRST_CAPTURE + 2; | 119 var j = REGEXP_FIRST_CAPTURE + 2; |
118 for (var i = 1; i < numResults; i++) { | 120 for (var i = 1; i < numResults; i++) { |
119 start = lastMatchInfo[j++]; | 121 start = lastMatchInfo[j++]; |
120 if (start != -1) { | 122 if (start != -1) { |
121 end = lastMatchInfo[j]; | 123 end = lastMatchInfo[j]; |
122 result[i] = %_SubString(s, start, end); | 124 result[i] = %_SubString(s, start, end); |
123 } | 125 } |
124 j++; | 126 j++; |
125 } | 127 } |
126 return result; | 128 return result; |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 | 452 |
451 for (var i = 1; i < 10; ++i) { | 453 for (var i = 1; i < 10; ++i) { |
452 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, | 454 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, |
453 RegExpMakeCaptureGetter(i), NoOpSetter, | 455 RegExpMakeCaptureGetter(i), NoOpSetter, |
454 DONT_DELETE); | 456 DONT_DELETE); |
455 } | 457 } |
456 %ToFastProperties($RegExp); | 458 %ToFastProperties($RegExp); |
457 } | 459 } |
458 | 460 |
459 SetUpRegExp(); | 461 SetUpRegExp(); |
OLD | NEW |