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 |
11 | 11 |
12 var ExpandReplacement; | 12 var ExpandReplacement; |
13 var FLAG_harmony_tolength; | |
14 var GlobalObject = global.Object; | 13 var GlobalObject = global.Object; |
15 var GlobalRegExp = global.RegExp; | 14 var GlobalRegExp = global.RegExp; |
16 var GlobalRegExpPrototype; | 15 var GlobalRegExpPrototype; |
17 var InternalArray = utils.InternalArray; | 16 var InternalArray = utils.InternalArray; |
18 var InternalPackedArray = utils.InternalPackedArray; | 17 var InternalPackedArray = utils.InternalPackedArray; |
19 var MakeTypeError; | 18 var MakeTypeError; |
20 var matchSymbol = utils.ImportNow("match_symbol"); | 19 var matchSymbol = utils.ImportNow("match_symbol"); |
21 var replaceSymbol = utils.ImportNow("replace_symbol"); | 20 var replaceSymbol = utils.ImportNow("replace_symbol"); |
22 var searchSymbol = utils.ImportNow("search_symbol"); | 21 var searchSymbol = utils.ImportNow("search_symbol"); |
23 var splitSymbol = utils.ImportNow("split_symbol"); | 22 var splitSymbol = utils.ImportNow("split_symbol"); |
24 | 23 |
25 utils.ImportFromExperimental(function(from) { | |
26 FLAG_harmony_tolength = from.FLAG_harmony_tolength; | |
27 }); | |
28 | |
29 utils.Import(function(from) { | 24 utils.Import(function(from) { |
30 ExpandReplacement = from.ExpandReplacement; | 25 ExpandReplacement = from.ExpandReplacement; |
31 MakeTypeError = from.MakeTypeError; | 26 MakeTypeError = from.MakeTypeError; |
32 }); | 27 }); |
33 | 28 |
34 // ------------------------------------------------------------------- | 29 // ------------------------------------------------------------------- |
35 | 30 |
36 // Property of the builtins object for recording the result of the last | 31 // Property of the builtins object for recording the result of the last |
37 // regexp match. The property RegExpLastMatchInfo includes the matchIndices | 32 // regexp match. The property RegExpLastMatchInfo includes the matchIndices |
38 // array of the last successful regexp match (an array of start/end index | 33 // array of the last successful regexp match (an array of start/end index |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 if (!IS_REGEXP(this)) { | 164 if (!IS_REGEXP(this)) { |
170 throw MakeTypeError(kIncompatibleMethodReceiver, | 165 throw MakeTypeError(kIncompatibleMethodReceiver, |
171 'RegExp.prototype.exec', this); | 166 'RegExp.prototype.exec', this); |
172 } | 167 } |
173 | 168 |
174 string = TO_STRING(string); | 169 string = TO_STRING(string); |
175 var lastIndex = this.lastIndex; | 170 var lastIndex = this.lastIndex; |
176 | 171 |
177 // Conversion is required by the ES2015 specification (RegExpBuiltinExec | 172 // Conversion is required by the ES2015 specification (RegExpBuiltinExec |
178 // algorithm, step 4) even if the value is discarded for non-global RegExps. | 173 // algorithm, step 4) even if the value is discarded for non-global RegExps. |
179 var i = TO_LENGTH_OR_INTEGER(lastIndex); | 174 var i = TO_LENGTH(lastIndex); |
180 | 175 |
181 var updateLastIndex = REGEXP_GLOBAL(this) || REGEXP_STICKY(this); | 176 var updateLastIndex = REGEXP_GLOBAL(this) || REGEXP_STICKY(this); |
182 if (updateLastIndex) { | 177 if (updateLastIndex) { |
183 if (i < 0 || i > string.length) { | 178 if (i < 0 || i > string.length) { |
184 this.lastIndex = 0; | 179 this.lastIndex = 0; |
185 return null; | 180 return null; |
186 } | 181 } |
187 } else { | 182 } else { |
188 i = 0; | 183 i = 0; |
189 } | 184 } |
(...skipping 26 matching lines...) Expand all Loading... |
216 if (!IS_REGEXP(this)) { | 211 if (!IS_REGEXP(this)) { |
217 throw MakeTypeError(kIncompatibleMethodReceiver, | 212 throw MakeTypeError(kIncompatibleMethodReceiver, |
218 'RegExp.prototype.test', this); | 213 'RegExp.prototype.test', this); |
219 } | 214 } |
220 string = TO_STRING(string); | 215 string = TO_STRING(string); |
221 | 216 |
222 var lastIndex = this.lastIndex; | 217 var lastIndex = this.lastIndex; |
223 | 218 |
224 // Conversion is required by the ES2015 specification (RegExpBuiltinExec | 219 // Conversion is required by the ES2015 specification (RegExpBuiltinExec |
225 // algorithm, step 4) even if the value is discarded for non-global RegExps. | 220 // algorithm, step 4) even if the value is discarded for non-global RegExps. |
226 var i = TO_LENGTH_OR_INTEGER(lastIndex); | 221 var i = TO_LENGTH(lastIndex); |
227 | 222 |
228 if (REGEXP_GLOBAL(this) || REGEXP_STICKY(this)) { | 223 if (REGEXP_GLOBAL(this) || REGEXP_STICKY(this)) { |
229 if (i < 0 || i > string.length) { | 224 if (i < 0 || i > string.length) { |
230 this.lastIndex = 0; | 225 this.lastIndex = 0; |
231 return false; | 226 return false; |
232 } | 227 } |
233 // matchIndices is either null or the RegExpLastMatchInfo array. | 228 // matchIndices is either null or the RegExpLastMatchInfo array. |
234 var matchIndices = %_RegExpExec(this, string, i, RegExpLastMatchInfo); | 229 var matchIndices = %_RegExpExec(this, string, i, RegExpLastMatchInfo); |
235 if (IS_NULL(matchIndices)) { | 230 if (IS_NULL(matchIndices)) { |
236 this.lastIndex = 0; | 231 this.lastIndex = 0; |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 // Exports | 737 // Exports |
743 | 738 |
744 utils.Export(function(to) { | 739 utils.Export(function(to) { |
745 to.RegExpExec = DoRegExpExec; | 740 to.RegExpExec = DoRegExpExec; |
746 to.RegExpExecNoTests = RegExpExecNoTests; | 741 to.RegExpExecNoTests = RegExpExecNoTests; |
747 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 742 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
748 to.RegExpTest = RegExpTest; | 743 to.RegExpTest = RegExpTest; |
749 }); | 744 }); |
750 | 745 |
751 }) | 746 }) |
OLD | NEW |