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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 function DoRegExpExec(regexp, string, index) { | 104 function DoRegExpExec(regexp, string, index) { |
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 // This is kind of performance sensitive, so we want to avoid unnecessary |
112 var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; | 112 // type checks on inputs. But we also don't want to inline it several times |
113 var start = lastMatchInfo[CAPTURE0]; | 113 // manually, so we use a macro :-) |
114 var end = lastMatchInfo[CAPTURE1]; | 114 macro BuildResultFromMatchInfo(MATCHINFO, STRING) |
Yang
2014/05/16 13:39:09
I would use capital naming for the macro to make i
Jakob Kummerow
2014/05/16 13:43:04
Done.
| |
115 var result = %_RegExpConstructResult(numResults, start, s); | 115 var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1; |
116 result[0] = %_SubString(s, start, end); | 116 var start = MATCHINFO[CAPTURE0]; |
117 var end = MATCHINFO[CAPTURE1]; | |
118 var result = %_RegExpConstructResult(numResults, start, STRING); | |
119 result[0] = %_SubString(STRING, start, end); | |
117 var j = REGEXP_FIRST_CAPTURE + 2; | 120 var j = REGEXP_FIRST_CAPTURE + 2; |
118 for (var i = 1; i < numResults; i++) { | 121 for (var i = 1; i < numResults; i++) { |
119 start = lastMatchInfo[j++]; | 122 start = MATCHINFO[j++]; |
120 if (start != -1) { | 123 if (start != -1) { |
121 end = lastMatchInfo[j]; | 124 end = MATCHINFO[j]; |
122 result[i] = %_SubString(s, start, end); | 125 result[i] = %_SubString(STRING, start, end); |
123 } | 126 } |
124 j++; | 127 j++; |
125 } | 128 } |
126 return result; | 129 endmacro |
127 } | |
128 | 130 |
129 | 131 |
130 function RegExpExecNoTests(regexp, string, start) { | 132 function RegExpExecNoTests(regexp, string, start) { |
131 // Must be called with RegExp, string and positive integer as arguments. | 133 // Must be called with RegExp, string and positive integer as arguments. |
132 var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); | 134 var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); |
133 if (matchInfo !== null) { | 135 if (matchInfo !== null) { |
134 lastMatchInfoOverride = null; | 136 lastMatchInfoOverride = null; |
135 return BuildResultFromMatchInfo(matchInfo, string); | 137 BuildResultFromMatchInfo(matchInfo, string); |
138 return result; | |
Yang
2014/05/16 13:39:09
Why not make this part of the macro and call it so
Jakob Kummerow
2014/05/16 13:43:04
Done.
| |
136 } | 139 } |
137 regexp.lastIndex = 0; | 140 regexp.lastIndex = 0; |
138 return null; | 141 return null; |
139 } | 142 } |
140 | 143 |
141 | 144 |
142 function RegExpExec(string) { | 145 function RegExpExec(string) { |
143 if (!IS_REGEXP(this)) { | 146 if (!IS_REGEXP(this)) { |
144 throw MakeTypeError('incompatible_method_receiver', | 147 throw MakeTypeError('incompatible_method_receiver', |
145 ['RegExp.prototype.exec', this]); | 148 ['RegExp.prototype.exec', this]); |
(...skipping 22 matching lines...) Expand all Loading... | |
168 if (IS_NULL(matchIndices)) { | 171 if (IS_NULL(matchIndices)) { |
169 this.lastIndex = 0; | 172 this.lastIndex = 0; |
170 return null; | 173 return null; |
171 } | 174 } |
172 | 175 |
173 // Successful match. | 176 // Successful match. |
174 lastMatchInfoOverride = null; | 177 lastMatchInfoOverride = null; |
175 if (global) { | 178 if (global) { |
176 this.lastIndex = lastMatchInfo[CAPTURE1]; | 179 this.lastIndex = lastMatchInfo[CAPTURE1]; |
177 } | 180 } |
178 return BuildResultFromMatchInfo(matchIndices, string); | 181 BuildResultFromMatchInfo(matchIndices, string); |
182 return result; | |
179 } | 183 } |
180 | 184 |
181 | 185 |
182 // One-element cache for the simplified test regexp. | 186 // One-element cache for the simplified test regexp. |
183 var regexp_key; | 187 var regexp_key; |
184 var regexp_val; | 188 var regexp_val; |
185 | 189 |
186 // Section 15.10.6.3 doesn't actually make sense, but the intention seems to be | 190 // Section 15.10.6.3 doesn't actually make sense, but the intention seems to be |
187 // that test is defined in terms of String.prototype.exec. However, it probably | 191 // that test is defined in terms of String.prototype.exec. However, it probably |
188 // means the original value of String.prototype.exec, which is what everybody | 192 // means the original value of String.prototype.exec, which is what everybody |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 | 454 |
451 for (var i = 1; i < 10; ++i) { | 455 for (var i = 1; i < 10; ++i) { |
452 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, | 456 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, |
453 RegExpMakeCaptureGetter(i), NoOpSetter, | 457 RegExpMakeCaptureGetter(i), NoOpSetter, |
454 DONT_DELETE); | 458 DONT_DELETE); |
455 } | 459 } |
456 %ToFastProperties($RegExp); | 460 %ToFastProperties($RegExp); |
457 } | 461 } |
458 | 462 |
459 SetUpRegExp(); | 463 SetUpRegExp(); |
OLD | NEW |