| 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 RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING) |
| 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 return result; |
| 127 } | 130 endmacro |
| 128 | 131 |
| 129 | 132 |
| 130 function RegExpExecNoTests(regexp, string, start) { | 133 function RegExpExecNoTests(regexp, string, start) { |
| 131 // Must be called with RegExp, string and positive integer as arguments. | 134 // Must be called with RegExp, string and positive integer as arguments. |
| 132 var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); | 135 var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); |
| 133 if (matchInfo !== null) { | 136 if (matchInfo !== null) { |
| 134 lastMatchInfoOverride = null; | 137 lastMatchInfoOverride = null; |
| 135 return BuildResultFromMatchInfo(matchInfo, string); | 138 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchInfo, string); |
| 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 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string); |
| 179 } | 182 } |
| 180 | 183 |
| 181 | 184 |
| 182 // One-element cache for the simplified test regexp. | 185 // One-element cache for the simplified test regexp. |
| 183 var regexp_key; | 186 var regexp_key; |
| 184 var regexp_val; | 187 var regexp_val; |
| 185 | 188 |
| 186 // Section 15.10.6.3 doesn't actually make sense, but the intention seems to be | 189 // 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 | 190 // 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 | 191 // 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 | 453 |
| 451 for (var i = 1; i < 10; ++i) { | 454 for (var i = 1; i < 10; ++i) { |
| 452 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, | 455 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, |
| 453 RegExpMakeCaptureGetter(i), NoOpSetter, | 456 RegExpMakeCaptureGetter(i), NoOpSetter, |
| 454 DONT_DELETE); | 457 DONT_DELETE); |
| 455 } | 458 } |
| 456 %ToFastProperties($RegExp); | 459 %ToFastProperties($RegExp); |
| 457 } | 460 } |
| 458 | 461 |
| 459 SetUpRegExp(); | 462 SetUpRegExp(); |
| OLD | NEW |