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 var $regexpLastMatchInfoOverride; | 5 var $regexpLastMatchInfoOverride; |
6 | 6 |
7 (function(global, utils) { | 7 (function(global, utils) { |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 156 |
157 function RegExpExecJS(string) { | 157 function RegExpExecJS(string) { |
158 if (!IS_REGEXP(this)) { | 158 if (!IS_REGEXP(this)) { |
159 throw MakeTypeError(kIncompatibleMethodReceiver, | 159 throw MakeTypeError(kIncompatibleMethodReceiver, |
160 'RegExp.prototype.exec', this); | 160 'RegExp.prototype.exec', this); |
161 } | 161 } |
162 | 162 |
163 string = TO_STRING(string); | 163 string = TO_STRING(string); |
164 var lastIndex = this.lastIndex; | 164 var lastIndex = this.lastIndex; |
165 | 165 |
166 // Conversion is required by the ES5 specification (RegExp.prototype.exec | 166 // Conversion is required by the ES2015 specification (RegExpBuiltinExec |
167 // algorithm, step 5) even if the value is discarded for non-global RegExps. | 167 // algorithm, step 4) even if the value is discarded for non-global RegExps. |
168 var i = TO_INTEGER(lastIndex); | 168 var i = TO_LENGTH_OR_INTEGER(lastIndex); |
169 | 169 |
170 var updateLastIndex = this.global || (FLAG_harmony_regexps && this.sticky); | 170 var updateLastIndex = this.global || (FLAG_harmony_regexps && this.sticky); |
171 if (updateLastIndex) { | 171 if (updateLastIndex) { |
172 if (i < 0 || i > string.length) { | 172 if (i < 0 || i > string.length) { |
173 this.lastIndex = 0; | 173 this.lastIndex = 0; |
174 return null; | 174 return null; |
175 } | 175 } |
176 } else { | 176 } else { |
177 i = 0; | 177 i = 0; |
178 } | 178 } |
(...skipping 25 matching lines...) Expand all Loading... |
204 // else implements. | 204 // else implements. |
205 function RegExpTest(string) { | 205 function RegExpTest(string) { |
206 if (!IS_REGEXP(this)) { | 206 if (!IS_REGEXP(this)) { |
207 throw MakeTypeError(kIncompatibleMethodReceiver, | 207 throw MakeTypeError(kIncompatibleMethodReceiver, |
208 'RegExp.prototype.test', this); | 208 'RegExp.prototype.test', this); |
209 } | 209 } |
210 string = TO_STRING(string); | 210 string = TO_STRING(string); |
211 | 211 |
212 var lastIndex = this.lastIndex; | 212 var lastIndex = this.lastIndex; |
213 | 213 |
214 // Conversion is required by the ES5 specification (RegExp.prototype.exec | 214 // Conversion is required by the ES2015 specification (RegExpBuiltinExec |
215 // algorithm, step 5) even if the value is discarded for non-global RegExps. | 215 // algorithm, step 4) even if the value is discarded for non-global RegExps. |
216 var i = TO_INTEGER(lastIndex); | 216 var i = TO_LENGTH_OR_INTEGER(lastIndex); |
217 | 217 |
218 if (this.global || (FLAG_harmony_regexps && this.sticky)) { | 218 if (this.global || (FLAG_harmony_regexps && this.sticky)) { |
219 if (i < 0 || i > string.length) { | 219 if (i < 0 || i > string.length) { |
220 this.lastIndex = 0; | 220 this.lastIndex = 0; |
221 return false; | 221 return false; |
222 } | 222 } |
223 // matchIndices is either null or the RegExpLastMatchInfo array. | 223 // matchIndices is either null or the RegExpLastMatchInfo array. |
224 var matchIndices = %_RegExpExec(this, string, i, RegExpLastMatchInfo); | 224 var matchIndices = %_RegExpExec(this, string, i, RegExpLastMatchInfo); |
225 if (IS_NULL(matchIndices)) { | 225 if (IS_NULL(matchIndices)) { |
226 this.lastIndex = 0; | 226 this.lastIndex = 0; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 // Exports | 453 // Exports |
454 | 454 |
455 utils.Export(function(to) { | 455 utils.Export(function(to) { |
456 to.RegExpExec = DoRegExpExec; | 456 to.RegExpExec = DoRegExpExec; |
457 to.RegExpExecNoTests = RegExpExecNoTests; | 457 to.RegExpExecNoTests = RegExpExecNoTests; |
458 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 458 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
459 to.RegExpTest = RegExpTest; | 459 to.RegExpTest = RegExpTest; |
460 }); | 460 }); |
461 | 461 |
462 }) | 462 }) |
OLD | NEW |