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 'use strict'; | 7 'use strict'; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 | 13 |
14 var AddIndexedProperty; | |
15 var ExpandReplacement; | 14 var ExpandReplacement; |
16 var GlobalArray = global.Array; | 15 var GlobalArray = global.Array; |
17 var GlobalObject = global.Object; | 16 var GlobalObject = global.Object; |
18 var GlobalRegExp = global.RegExp; | 17 var GlobalRegExp = global.RegExp; |
19 var GlobalRegExpPrototype; | 18 var GlobalRegExpPrototype; |
20 var InternalArray = utils.InternalArray; | 19 var InternalArray = utils.InternalArray; |
21 var InternalPackedArray = utils.InternalPackedArray; | 20 var InternalPackedArray = utils.InternalPackedArray; |
22 var MakeTypeError; | 21 var MakeTypeError; |
23 var MaxSimple; | 22 var MaxSimple; |
24 var MinSimple; | 23 var MinSimple; |
25 var matchSymbol = utils.ImportNow("match_symbol"); | 24 var matchSymbol = utils.ImportNow("match_symbol"); |
26 var replaceSymbol = utils.ImportNow("replace_symbol"); | 25 var replaceSymbol = utils.ImportNow("replace_symbol"); |
27 var searchSymbol = utils.ImportNow("search_symbol"); | 26 var searchSymbol = utils.ImportNow("search_symbol"); |
28 var splitSymbol = utils.ImportNow("split_symbol"); | 27 var splitSymbol = utils.ImportNow("split_symbol"); |
29 var SpeciesConstructor; | 28 var SpeciesConstructor; |
30 | 29 |
31 utils.Import(function(from) { | 30 utils.Import(function(from) { |
32 AddIndexedProperty = from.AddIndexedProperty; | |
33 ExpandReplacement = from.ExpandReplacement; | 31 ExpandReplacement = from.ExpandReplacement; |
34 MakeTypeError = from.MakeTypeError; | 32 MakeTypeError = from.MakeTypeError; |
35 MaxSimple = from.MaxSimple; | 33 MaxSimple = from.MaxSimple; |
36 MinSimple = from.MinSimple; | 34 MinSimple = from.MinSimple; |
37 SpeciesConstructor = from.SpeciesConstructor; | 35 SpeciesConstructor = from.SpeciesConstructor; |
38 }); | 36 }); |
39 | 37 |
40 // ------------------------------------------------------------------- | 38 // ------------------------------------------------------------------- |
41 | 39 |
42 // Property of the builtins object for recording the result of the last | 40 // Property of the builtins object for recording the result of the last |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 var splitter = new constructor(this, newFlags); | 493 var splitter = new constructor(this, newFlags); |
496 var array = new GlobalArray(); | 494 var array = new GlobalArray(); |
497 var arrayIndex = 0; | 495 var arrayIndex = 0; |
498 var lim = (IS_UNDEFINED(limit)) ? kMaxUint32 : TO_UINT32(limit); | 496 var lim = (IS_UNDEFINED(limit)) ? kMaxUint32 : TO_UINT32(limit); |
499 var size = string.length; | 497 var size = string.length; |
500 var prevStringIndex = 0; | 498 var prevStringIndex = 0; |
501 if (lim === 0) return array; | 499 if (lim === 0) return array; |
502 var result; | 500 var result; |
503 if (size === 0) { | 501 if (size === 0) { |
504 result = RegExpSubclassExec(splitter, string); | 502 result = RegExpSubclassExec(splitter, string); |
505 if (IS_NULL(result)) AddIndexedProperty(array, 0, string); | 503 if (IS_NULL(result)) %AddElement(array, 0, string); |
506 return array; | 504 return array; |
507 } | 505 } |
508 var stringIndex = prevStringIndex; | 506 var stringIndex = prevStringIndex; |
509 while (stringIndex < size) { | 507 while (stringIndex < size) { |
510 splitter.lastIndex = stringIndex; | 508 splitter.lastIndex = stringIndex; |
511 result = RegExpSubclassExec(splitter, string, exec); | 509 result = RegExpSubclassExec(splitter, string, exec); |
512 // Ensure exec will be read again on the next loop through. | 510 // Ensure exec will be read again on the next loop through. |
513 exec = UNDEFINED; | 511 exec = UNDEFINED; |
514 if (IS_NULL(result)) { | 512 if (IS_NULL(result)) { |
515 stringIndex += AdvanceStringIndex(string, stringIndex, unicode); | 513 stringIndex += AdvanceStringIndex(string, stringIndex, unicode); |
516 } else { | 514 } else { |
517 var end = MinSimple(TO_LENGTH(splitter.lastIndex), size); | 515 var end = MinSimple(TO_LENGTH(splitter.lastIndex), size); |
518 if (end === stringIndex) { | 516 if (end === stringIndex) { |
519 stringIndex += AdvanceStringIndex(string, stringIndex, unicode); | 517 stringIndex += AdvanceStringIndex(string, stringIndex, unicode); |
520 } else { | 518 } else { |
521 AddIndexedProperty( | 519 %AddElement( |
522 array, arrayIndex, | 520 array, arrayIndex, |
523 %_SubString(string, prevStringIndex, stringIndex)); | 521 %_SubString(string, prevStringIndex, stringIndex)); |
524 arrayIndex++; | 522 arrayIndex++; |
525 if (arrayIndex === lim) return array; | 523 if (arrayIndex === lim) return array; |
526 prevStringIndex = end; | 524 prevStringIndex = end; |
527 var numberOfCaptures = MaxSimple(TO_LENGTH(result.length), 0); | 525 var numberOfCaptures = MaxSimple(TO_LENGTH(result.length), 0); |
528 for (var i = 1; i < numberOfCaptures; i++) { | 526 for (var i = 1; i < numberOfCaptures; i++) { |
529 AddIndexedProperty(array, arrayIndex, result[i]); | 527 %AddElement(array, arrayIndex, result[i]); |
530 arrayIndex++; | 528 arrayIndex++; |
531 if (arrayIndex === lim) return array; | 529 if (arrayIndex === lim) return array; |
532 } | 530 } |
533 stringIndex = prevStringIndex; | 531 stringIndex = prevStringIndex; |
534 } | 532 } |
535 } | 533 } |
536 } | 534 } |
537 AddIndexedProperty(array, arrayIndex, | 535 %AddElement(array, arrayIndex, |
538 %_SubString(string, prevStringIndex, size)); | 536 %_SubString(string, prevStringIndex, size)); |
539 return array; | 537 return array; |
540 } | 538 } |
541 %FunctionRemovePrototype(RegExpSubclassSplit); | 539 %FunctionRemovePrototype(RegExpSubclassSplit); |
542 | 540 |
543 | 541 |
544 // Legacy implementation of RegExp.prototype[Symbol.match] which | 542 // Legacy implementation of RegExp.prototype[Symbol.match] which |
545 // doesn't properly call the underlying exec method | 543 // doesn't properly call the underlying exec method |
546 function RegExpMatch(string) { | 544 function RegExpMatch(string) { |
547 if (!IS_REGEXP(this)) { | 545 if (!IS_REGEXP(this)) { |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 to.RegExpSubclassExecJS = RegExpSubclassExecJS; | 1237 to.RegExpSubclassExecJS = RegExpSubclassExecJS; |
1240 to.RegExpSubclassMatch = RegExpSubclassMatch; | 1238 to.RegExpSubclassMatch = RegExpSubclassMatch; |
1241 to.RegExpSubclassReplace = RegExpSubclassReplace; | 1239 to.RegExpSubclassReplace = RegExpSubclassReplace; |
1242 to.RegExpSubclassSearch = RegExpSubclassSearch; | 1240 to.RegExpSubclassSearch = RegExpSubclassSearch; |
1243 to.RegExpSubclassSplit = RegExpSubclassSplit; | 1241 to.RegExpSubclassSplit = RegExpSubclassSplit; |
1244 to.RegExpSubclassTest = RegExpSubclassTest; | 1242 to.RegExpSubclassTest = RegExpSubclassTest; |
1245 to.RegExpTest = RegExpTest; | 1243 to.RegExpTest = RegExpTest; |
1246 }); | 1244 }); |
1247 | 1245 |
1248 }) | 1246 }) |
OLD | NEW |