Chromium Code Reviews| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 result[i] = %_SubString(STRING, start, end); | 158 result[i] = %_SubString(STRING, start, end); |
| 159 } | 159 } |
| 160 j++; | 160 j++; |
| 161 } | 161 } |
| 162 return result; | 162 return result; |
| 163 endmacro | 163 endmacro |
| 164 | 164 |
| 165 | 165 |
| 166 // ES#sec-regexp.prototype.exec | 166 // ES#sec-regexp.prototype.exec |
| 167 // RegExp.prototype.exec ( string ) | 167 // RegExp.prototype.exec ( string ) |
| 168 function RegExpSubclassExecJS(string) { | 168 function RegExpSubclassExecJS(string) { |
|
Dan Ehrenberg
2016/09/13 17:12:43
Rename to RegExpExecJS?
jgruber
2016/09/14 11:27:29
Done.
| |
| 169 if (!IS_REGEXP(this)) { | 169 if (!IS_REGEXP(this)) { |
| 170 throw %make_type_error(kIncompatibleMethodReceiver, | 170 throw %make_type_error(kIncompatibleMethodReceiver, |
| 171 'RegExp.prototype.exec', this); | 171 'RegExp.prototype.exec', this); |
| 172 } | 172 } |
| 173 | 173 |
| 174 string = TO_STRING(string); | 174 string = TO_STRING(string); |
| 175 var lastIndex = this.lastIndex; | 175 var lastIndex = this.lastIndex; |
| 176 | 176 |
| 177 // Conversion is required by the ES2015 specification (RegExpBuiltinExec | 177 // Conversion is required by the ES2015 specification (RegExpBuiltinExec |
| 178 // algorithm, step 4) even if the value is discarded for non-global RegExps. | 178 // algorithm, step 4) even if the value is discarded for non-global RegExps. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 200 | 200 |
| 201 // Successful match. | 201 // Successful match. |
| 202 if (updateLastIndex) { | 202 if (updateLastIndex) { |
| 203 this.lastIndex = RegExpLastMatchInfo[CAPTURE1]; | 203 this.lastIndex = RegExpLastMatchInfo[CAPTURE1]; |
| 204 } | 204 } |
| 205 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string); | 205 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string); |
| 206 } | 206 } |
| 207 %FunctionRemovePrototype(RegExpSubclassExecJS); | 207 %FunctionRemovePrototype(RegExpSubclassExecJS); |
| 208 | 208 |
| 209 | 209 |
| 210 // Legacy implementation of RegExp.prototype.exec | |
| 211 function RegExpExecJS(string) { | |
| 212 if (!IS_REGEXP(this)) { | |
| 213 throw %make_type_error(kIncompatibleMethodReceiver, | |
| 214 'RegExp.prototype.exec', this); | |
| 215 } | |
| 216 | |
| 217 string = TO_STRING(string); | |
| 218 var lastIndex = this.lastIndex; | |
| 219 | |
| 220 // Conversion is required by the ES2015 specification (RegExpBuiltinExec | |
| 221 // algorithm, step 4) even if the value is discarded for non-global RegExps. | |
| 222 var i = TO_LENGTH(lastIndex); | |
| 223 | |
| 224 var updateLastIndex = REGEXP_GLOBAL(this) || REGEXP_STICKY(this); | |
| 225 if (updateLastIndex) { | |
| 226 if (i < 0 || i > string.length) { | |
| 227 this.lastIndex = 0; | |
| 228 return null; | |
| 229 } | |
| 230 } else { | |
| 231 i = 0; | |
| 232 } | |
| 233 | |
| 234 // matchIndices is either null or the RegExpLastMatchInfo array. | |
| 235 var matchIndices = %_RegExpExec(this, string, i, RegExpLastMatchInfo); | |
| 236 | |
| 237 if (IS_NULL(matchIndices)) { | |
| 238 this.lastIndex = 0; | |
| 239 return null; | |
| 240 } | |
| 241 | |
| 242 // Successful match. | |
| 243 if (updateLastIndex) { | |
| 244 this.lastIndex = RegExpLastMatchInfo[CAPTURE1]; | |
| 245 } | |
| 246 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string); | |
| 247 } | |
| 248 | |
| 249 | |
| 250 // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S ) | 210 // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S ) |
| 251 // Also takes an optional exec method in case our caller | 211 // Also takes an optional exec method in case our caller |
| 252 // has already fetched exec. | 212 // has already fetched exec. |
| 253 function RegExpSubclassExec(regexp, string, exec) { | 213 function RegExpSubclassExec(regexp, string, exec) { |
| 254 if (IS_UNDEFINED(exec)) { | 214 if (IS_UNDEFINED(exec)) { |
| 255 exec = regexp.exec; | 215 exec = regexp.exec; |
| 256 } | 216 } |
| 257 if (IS_CALLABLE(exec)) { | 217 if (IS_CALLABLE(exec)) { |
| 258 var result = %_Call(exec, regexp, string); | 218 var result = %_Call(exec, regexp, string); |
| 259 if (!IS_RECEIVER(result) && !IS_NULL(result)) { | 219 if (!IS_RECEIVER(result) && !IS_NULL(result)) { |
| 260 throw %make_type_error(kInvalidRegExpExecResult); | 220 throw %make_type_error(kInvalidRegExpExecResult); |
| 261 } | 221 } |
| 262 return result; | 222 return result; |
| 263 } | 223 } |
| 264 return %_Call(RegExpExecJS, regexp, string); | 224 return %_Call(RegExpSubclassExecJS, regexp, string); |
| 265 } | 225 } |
| 266 %SetForceInlineFlag(RegExpSubclassExec); | 226 %SetForceInlineFlag(RegExpSubclassExec); |
| 267 | 227 |
| 268 | 228 |
| 269 // ES#sec-regexp.prototype.test RegExp.prototype.test ( S ) | 229 // ES#sec-regexp.prototype.test RegExp.prototype.test ( S ) |
| 270 function RegExpSubclassTest(string) { | 230 function RegExpSubclassTest(string) { |
| 271 if (!IS_RECEIVER(this)) { | 231 if (!IS_RECEIVER(this)) { |
| 272 throw %make_type_error(kIncompatibleMethodReceiver, | 232 throw %make_type_error(kIncompatibleMethodReceiver, |
| 273 'RegExp.prototype.test', this); | 233 'RegExp.prototype.test', this); |
| 274 } | 234 } |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1137 utils.Export(function(to) { | 1097 utils.Export(function(to) { |
| 1138 to.InternalRegExpMatch = InternalRegExpMatch; | 1098 to.InternalRegExpMatch = InternalRegExpMatch; |
| 1139 to.InternalRegExpReplace = InternalRegExpReplace; | 1099 to.InternalRegExpReplace = InternalRegExpReplace; |
| 1140 to.IsRegExp = IsRegExp; | 1100 to.IsRegExp = IsRegExp; |
| 1141 to.RegExpExec = DoRegExpExec; | 1101 to.RegExpExec = DoRegExpExec; |
| 1142 to.RegExpInitialize = RegExpInitialize; | 1102 to.RegExpInitialize = RegExpInitialize; |
| 1143 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 1103 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
| 1144 }); | 1104 }); |
| 1145 | 1105 |
| 1146 }) | 1106 }) |
| OLD | NEW |