| 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 (function(global, utils) { | 5 (function(global, utils) { |
| 6 | 6 |
| 7 %CheckIsBootstrapping(); | 7 %CheckIsBootstrapping(); |
| 8 | 8 |
| 9 // ------------------------------------------------------------------- | 9 // ------------------------------------------------------------------- |
| 10 // Imports | 10 // Imports |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 // ES#sec-regexp.prototype.exec | 179 // ES#sec-regexp.prototype.exec |
| 180 // RegExp.prototype.exec ( string ) | 180 // RegExp.prototype.exec ( string ) |
| 181 function RegExpSubclassExecJS(string) { | 181 function RegExpSubclassExecJS(string) { |
| 182 if (!IS_REGEXP(this)) { | 182 if (!IS_REGEXP(this)) { |
| 183 throw %make_type_error(kIncompatibleMethodReceiver, | 183 throw %make_type_error(kIncompatibleMethodReceiver, |
| 184 'RegExp.prototype.exec', this); | 184 'RegExp.prototype.exec', this); |
| 185 } | 185 } |
| 186 | 186 |
| 187 string = TO_STRING(string); | 187 string = TO_STRING(string); |
| 188 var lastIndex = this.lastIndex; | |
| 189 | 188 |
| 190 // Conversion is required by the ES2015 specification (RegExpBuiltinExec | 189 var lastIndex; |
| 191 // algorithm, step 4) even if the value is discarded for non-global RegExps. | |
| 192 var i = TO_LENGTH(lastIndex); | |
| 193 | |
| 194 var global = TO_BOOLEAN(REGEXP_GLOBAL(this)); | 190 var global = TO_BOOLEAN(REGEXP_GLOBAL(this)); |
| 195 var sticky = TO_BOOLEAN(REGEXP_STICKY(this)); | 191 var sticky = TO_BOOLEAN(REGEXP_STICKY(this)); |
| 196 var updateLastIndex = global || sticky; | 192 var updateLastIndex = global || sticky; |
| 197 if (updateLastIndex) { | 193 if (updateLastIndex) { |
| 198 if (i > string.length) { | 194 lastIndex = TO_LENGTH(this.lastIndex); |
| 195 if (lastIndex > string.length) { |
| 199 this.lastIndex = 0; | 196 this.lastIndex = 0; |
| 200 return null; | 197 return null; |
| 201 } | 198 } |
| 202 } else { | 199 } else { |
| 203 i = 0; | 200 lastIndex = 0; |
| 204 } | 201 } |
| 205 | 202 |
| 206 // matchIndices is either null or the RegExpLastMatchInfo array. | 203 // matchIndices is either null or the RegExpLastMatchInfo array. |
| 207 var matchIndices = %_RegExpExec(this, string, i, RegExpLastMatchInfo); | 204 var matchIndices = %_RegExpExec(this, string, lastIndex, RegExpLastMatchInfo); |
| 208 | 205 |
| 209 if (IS_NULL(matchIndices)) { | 206 if (IS_NULL(matchIndices)) { |
| 210 this.lastIndex = 0; | 207 if (updateLastIndex) this.lastIndex = 0; |
| 211 return null; | 208 return null; |
| 212 } | 209 } |
| 213 | 210 |
| 214 // Successful match. | 211 // Successful match. |
| 215 if (updateLastIndex) { | 212 if (updateLastIndex) { |
| 216 this.lastIndex = RegExpLastMatchInfo[CAPTURE1]; | 213 this.lastIndex = RegExpLastMatchInfo[CAPTURE1]; |
| 217 } | 214 } |
| 218 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string); | 215 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string); |
| 219 } | 216 } |
| 220 %FunctionRemovePrototype(RegExpSubclassExecJS); | 217 %FunctionRemovePrototype(RegExpSubclassExecJS); |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 | 925 |
| 929 // ES#sec-regexp.prototype-@@search | 926 // ES#sec-regexp.prototype-@@search |
| 930 // RegExp.prototype [ @@search ] ( string ) | 927 // RegExp.prototype [ @@search ] ( string ) |
| 931 function RegExpSubclassSearch(string) { | 928 function RegExpSubclassSearch(string) { |
| 932 if (!IS_RECEIVER(this)) { | 929 if (!IS_RECEIVER(this)) { |
| 933 throw %make_type_error(kIncompatibleMethodReceiver, | 930 throw %make_type_error(kIncompatibleMethodReceiver, |
| 934 "RegExp.prototype.@@search", this); | 931 "RegExp.prototype.@@search", this); |
| 935 } | 932 } |
| 936 string = TO_STRING(string); | 933 string = TO_STRING(string); |
| 937 var previousLastIndex = this.lastIndex; | 934 var previousLastIndex = this.lastIndex; |
| 938 this.lastIndex = 0; | 935 if (previousLastIndex != 0) this.lastIndex = 0; |
| 939 var result = RegExpSubclassExec(this, string); | 936 var result = RegExpSubclassExec(this, string); |
| 940 this.lastIndex = previousLastIndex; | 937 var currentLastIndex = this.lastIndex; |
| 938 if (currentLastIndex != previousLastIndex) this.lastIndex = previousLastIndex; |
| 941 if (IS_NULL(result)) return -1; | 939 if (IS_NULL(result)) return -1; |
| 942 return result.index; | 940 return result.index; |
| 943 } | 941 } |
| 944 %FunctionRemovePrototype(RegExpSubclassSearch); | 942 %FunctionRemovePrototype(RegExpSubclassSearch); |
| 945 | 943 |
| 946 | 944 |
| 947 // Getters for the static properties lastMatch, lastParen, leftContext, and | 945 // Getters for the static properties lastMatch, lastParen, leftContext, and |
| 948 // rightContext of the RegExp constructor. The properties are computed based | 946 // rightContext of the RegExp constructor. The properties are computed based |
| 949 // on the captures array of the last successful match and the subject string | 947 // on the captures array of the last successful match and the subject string |
| 950 // of the last successful match. | 948 // of the last successful match. |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 to.InternalRegExpMatch = InternalRegExpMatch; | 1220 to.InternalRegExpMatch = InternalRegExpMatch; |
| 1223 to.InternalRegExpReplace = InternalRegExpReplace; | 1221 to.InternalRegExpReplace = InternalRegExpReplace; |
| 1224 to.IsRegExp = IsRegExp; | 1222 to.IsRegExp = IsRegExp; |
| 1225 to.RegExpExec = DoRegExpExec; | 1223 to.RegExpExec = DoRegExpExec; |
| 1226 to.RegExpInitialize = RegExpInitialize; | 1224 to.RegExpInitialize = RegExpInitialize; |
| 1227 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 1225 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
| 1228 to.RegExpTest = RegExpTest; | 1226 to.RegExpTest = RegExpTest; |
| 1229 }); | 1227 }); |
| 1230 | 1228 |
| 1231 }) | 1229 }) |
| OLD | NEW |