| 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 ExpandReplacement; | 14 var ExpandReplacement; |
| 15 var GlobalArray = global.Array; | 15 var GlobalArray = global.Array; |
| 16 var GlobalObject = global.Object; | 16 var GlobalObject = global.Object; |
| 17 var GlobalRegExp = global.RegExp; | 17 var GlobalRegExp = global.RegExp; |
| 18 var GlobalRegExpPrototype; | 18 var GlobalRegExpPrototype; |
| 19 var InternalArray = utils.InternalArray; | 19 var InternalArray = utils.InternalArray; |
| 20 var InternalPackedArray = utils.InternalPackedArray; | 20 var InternalPackedArray = utils.InternalPackedArray; |
| 21 var MakeTypeError; | 21 var MakeTypeError; |
| 22 var MaxSimple; | 22 var MaxSimple; |
| 23 var MinSimple; | 23 var MinSimple; |
| 24 var matchSymbol = utils.ImportNow("match_symbol"); | 24 var matchSymbol = utils.ImportNow("match_symbol"); |
| 25 var replaceSymbol = utils.ImportNow("replace_symbol"); | 25 var replaceSymbol = utils.ImportNow("replace_symbol"); |
| 26 var searchSymbol = utils.ImportNow("search_symbol"); | 26 var searchSymbol = utils.ImportNow("search_symbol"); |
| 27 var speciesSymbol = utils.ImportNow("species_symbol"); |
| 27 var splitSymbol = utils.ImportNow("split_symbol"); | 28 var splitSymbol = utils.ImportNow("split_symbol"); |
| 28 var SpeciesConstructor; | 29 var SpeciesConstructor; |
| 29 | 30 |
| 30 utils.Import(function(from) { | 31 utils.Import(function(from) { |
| 31 ExpandReplacement = from.ExpandReplacement; | 32 ExpandReplacement = from.ExpandReplacement; |
| 32 MakeTypeError = from.MakeTypeError; | 33 MakeTypeError = from.MakeTypeError; |
| 33 MaxSimple = from.MaxSimple; | 34 MaxSimple = from.MaxSimple; |
| 34 MinSimple = from.MinSimple; | 35 MinSimple = from.MinSimple; |
| 35 SpeciesConstructor = from.SpeciesConstructor; | 36 SpeciesConstructor = from.SpeciesConstructor; |
| 36 }); | 37 }); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 } | 533 } |
| 533 } | 534 } |
| 534 } | 535 } |
| 535 %AddElement(array, arrayIndex, | 536 %AddElement(array, arrayIndex, |
| 536 %_SubString(string, prevStringIndex, size)); | 537 %_SubString(string, prevStringIndex, size)); |
| 537 return array; | 538 return array; |
| 538 } | 539 } |
| 539 %FunctionRemovePrototype(RegExpSubclassSplit); | 540 %FunctionRemovePrototype(RegExpSubclassSplit); |
| 540 | 541 |
| 541 | 542 |
| 542 // Legacy implementation of RegExp.prototype[Symbol.match] which | |
| 543 // doesn't properly call the underlying exec method | |
| 544 function RegExpMatch(string) { | |
| 545 if (!IS_REGEXP(this)) { | |
| 546 throw MakeTypeError(kIncompatibleMethodReceiver, | |
| 547 "RegExp.prototype.@@match", this); | |
| 548 } | |
| 549 var subject = TO_STRING(string); | |
| 550 | |
| 551 if (!REGEXP_GLOBAL(this)) return RegExpExecNoTests(this, subject, 0); | |
| 552 this.lastIndex = 0; | |
| 553 var result = %StringMatch(subject, this, RegExpLastMatchInfo); | |
| 554 return result; | |
| 555 } | |
| 556 | |
| 557 | |
| 558 // ES#sec-regexp.prototype-@@match | 543 // ES#sec-regexp.prototype-@@match |
| 559 // RegExp.prototype [ @@match ] ( string ) | 544 // RegExp.prototype [ @@match ] ( string ) |
| 560 function RegExpSubclassMatch(string) { | 545 function RegExpSubclassMatch(string) { |
| 561 if (!IS_RECEIVER(this)) { | 546 if (!IS_RECEIVER(this)) { |
| 562 throw MakeTypeError(kIncompatibleMethodReceiver, | 547 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 563 "RegExp.prototype.@@match", this); | 548 "RegExp.prototype.@@match", this); |
| 564 } | 549 } |
| 565 string = TO_STRING(string); | 550 string = TO_STRING(string); |
| 566 var global = this.global; | 551 var global = this.global; |
| 567 if (!global) return RegExpSubclassExec(this, string); | 552 if (!global) return RegExpSubclassExec(this, string); |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 %_SubString(string, nextSourcePosition, position) + replacement; | 932 %_SubString(string, nextSourcePosition, position) + replacement; |
| 948 nextSourcePosition = position + matchedLength; | 933 nextSourcePosition = position + matchedLength; |
| 949 } | 934 } |
| 950 } | 935 } |
| 951 if (nextSourcePosition >= length) return accumulatedResult; | 936 if (nextSourcePosition >= length) return accumulatedResult; |
| 952 return accumulatedResult + %_SubString(string, nextSourcePosition, length); | 937 return accumulatedResult + %_SubString(string, nextSourcePosition, length); |
| 953 } | 938 } |
| 954 %FunctionRemovePrototype(RegExpSubclassReplace); | 939 %FunctionRemovePrototype(RegExpSubclassReplace); |
| 955 | 940 |
| 956 | 941 |
| 957 // Legacy implementation of RegExp.prototype[Symbol.search] which | |
| 958 // doesn't properly use the overridden exec method | |
| 959 function RegExpSearch(string) { | |
| 960 if (!IS_REGEXP(this)) { | |
| 961 throw MakeTypeError(kIncompatibleMethodReceiver, | |
| 962 "RegExp.prototype.@@search", this); | |
| 963 } | |
| 964 var match = DoRegExpExec(this, TO_STRING(string), 0); | |
| 965 if (match) return match[CAPTURE0]; | |
| 966 return -1; | |
| 967 } | |
| 968 | |
| 969 | |
| 970 // ES#sec-regexp.prototype-@@search | 942 // ES#sec-regexp.prototype-@@search |
| 971 // RegExp.prototype [ @@search ] ( string ) | 943 // RegExp.prototype [ @@search ] ( string ) |
| 972 function RegExpSubclassSearch(string) { | 944 function RegExpSubclassSearch(string) { |
| 973 if (!IS_RECEIVER(this)) { | 945 if (!IS_RECEIVER(this)) { |
| 974 throw MakeTypeError(kIncompatibleMethodReceiver, | 946 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 975 "RegExp.prototype.@@search", this); | 947 "RegExp.prototype.@@search", this); |
| 976 } | 948 } |
| 977 string = TO_STRING(string); | 949 string = TO_STRING(string); |
| 978 var previousLastIndex = this.lastIndex; | 950 var previousLastIndex = this.lastIndex; |
| 979 this.lastIndex = 0; | 951 this.lastIndex = 0; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 if (this === GlobalRegExpPrototype) { | 1099 if (this === GlobalRegExpPrototype) { |
| 1128 %IncrementUseCounter(kRegExpPrototypeStickyGetter); | 1100 %IncrementUseCounter(kRegExpPrototypeStickyGetter); |
| 1129 return UNDEFINED; | 1101 return UNDEFINED; |
| 1130 } | 1102 } |
| 1131 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.sticky"); | 1103 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.sticky"); |
| 1132 } | 1104 } |
| 1133 return TO_BOOLEAN(REGEXP_STICKY(this)); | 1105 return TO_BOOLEAN(REGEXP_STICKY(this)); |
| 1134 } | 1106 } |
| 1135 %SetForceInlineFlag(RegExpGetSticky); | 1107 %SetForceInlineFlag(RegExpGetSticky); |
| 1136 | 1108 |
| 1109 |
| 1110 // ES6 21.2.5.15. |
| 1111 function RegExpGetUnicode() { |
| 1112 if (!IS_REGEXP(this)) { |
| 1113 // TODO(littledan): Remove this RegExp compat workaround |
| 1114 if (this === GlobalRegExpPrototype) { |
| 1115 %IncrementUseCounter(kRegExpPrototypeUnicodeGetter); |
| 1116 return UNDEFINED; |
| 1117 } |
| 1118 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.unicode"); |
| 1119 } |
| 1120 return TO_BOOLEAN(REGEXP_UNICODE(this)); |
| 1121 } |
| 1122 %SetForceInlineFlag(RegExpGetUnicode); |
| 1123 |
| 1124 |
| 1125 function RegExpSpecies() { |
| 1126 return this; |
| 1127 } |
| 1128 |
| 1129 |
| 1137 // ------------------------------------------------------------------- | 1130 // ------------------------------------------------------------------- |
| 1138 | 1131 |
| 1139 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp'); | 1132 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp'); |
| 1140 GlobalRegExpPrototype = new GlobalObject(); | 1133 GlobalRegExpPrototype = new GlobalObject(); |
| 1141 %FunctionSetPrototype(GlobalRegExp, GlobalRegExpPrototype); | 1134 %FunctionSetPrototype(GlobalRegExp, GlobalRegExpPrototype); |
| 1142 %AddNamedProperty( | 1135 %AddNamedProperty( |
| 1143 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); | 1136 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); |
| 1144 %SetCode(GlobalRegExp, RegExpConstructor); | 1137 %SetCode(GlobalRegExp, RegExpConstructor); |
| 1145 | 1138 |
| 1139 utils.InstallGetter(GlobalRegExp, speciesSymbol, RegExpSpecies); |
| 1140 |
| 1146 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ | 1141 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ |
| 1147 "exec", RegExpExecJS, | 1142 "exec", RegExpSubclassExecJS, |
| 1148 "test", RegExpTest, | 1143 "test", RegExpSubclassTest, |
| 1149 "toString", RegExpToString, | 1144 "toString", RegExpToString, |
| 1150 "compile", RegExpCompileJS, | 1145 "compile", RegExpCompileJS, |
| 1151 matchSymbol, RegExpMatch, | 1146 matchSymbol, RegExpSubclassMatch, |
| 1152 replaceSymbol, RegExpReplace, | 1147 replaceSymbol, RegExpSubclassReplace, |
| 1153 searchSymbol, RegExpSearch, | 1148 searchSymbol, RegExpSubclassSearch, |
| 1154 splitSymbol, RegExpSplit, | 1149 splitSymbol, RegExpSubclassSplit, |
| 1155 ]); | 1150 ]); |
| 1156 | 1151 |
| 1157 utils.InstallGetter(GlobalRegExp.prototype, 'flags', RegExpGetFlags); | 1152 utils.InstallGetter(GlobalRegExp.prototype, 'flags', RegExpGetFlags); |
| 1158 utils.InstallGetter(GlobalRegExp.prototype, 'global', RegExpGetGlobal); | 1153 utils.InstallGetter(GlobalRegExp.prototype, 'global', RegExpGetGlobal); |
| 1159 utils.InstallGetter(GlobalRegExp.prototype, 'ignoreCase', RegExpGetIgnoreCase); | 1154 utils.InstallGetter(GlobalRegExp.prototype, 'ignoreCase', RegExpGetIgnoreCase); |
| 1160 utils.InstallGetter(GlobalRegExp.prototype, 'multiline', RegExpGetMultiline); | 1155 utils.InstallGetter(GlobalRegExp.prototype, 'multiline', RegExpGetMultiline); |
| 1161 utils.InstallGetter(GlobalRegExp.prototype, 'source', RegExpGetSource); | 1156 utils.InstallGetter(GlobalRegExp.prototype, 'source', RegExpGetSource); |
| 1162 utils.InstallGetter(GlobalRegExp.prototype, 'sticky', RegExpGetSticky); | 1157 utils.InstallGetter(GlobalRegExp.prototype, 'sticky', RegExpGetSticky); |
| 1158 utils.InstallGetter(GlobalRegExp.prototype, 'unicode', RegExpGetUnicode); |
| 1163 | 1159 |
| 1164 // The properties `input` and `$_` are aliases for each other. When this | 1160 // The properties `input` and `$_` are aliases for each other. When this |
| 1165 // value is set the value it is set to is coerced to a string. | 1161 // value is set the value it is set to is coerced to a string. |
| 1166 // Getter and setter for the input. | 1162 // Getter and setter for the input. |
| 1167 var RegExpGetInput = function() { | 1163 var RegExpGetInput = function() { |
| 1168 var regExpInput = LAST_INPUT(RegExpLastMatchInfo); | 1164 var regExpInput = LAST_INPUT(RegExpLastMatchInfo); |
| 1169 return IS_UNDEFINED(regExpInput) ? "" : regExpInput; | 1165 return IS_UNDEFINED(regExpInput) ? "" : regExpInput; |
| 1170 }; | 1166 }; |
| 1171 var RegExpSetInput = function(string) { | 1167 var RegExpSetInput = function(string) { |
| 1172 LAST_INPUT(RegExpLastMatchInfo) = TO_STRING(string); | 1168 LAST_INPUT(RegExpLastMatchInfo) = TO_STRING(string); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 // ------------------------------------------------------------------- | 1223 // ------------------------------------------------------------------- |
| 1228 // Exports | 1224 // Exports |
| 1229 | 1225 |
| 1230 utils.Export(function(to) { | 1226 utils.Export(function(to) { |
| 1231 to.InternalRegExpMatch = InternalRegExpMatch; | 1227 to.InternalRegExpMatch = InternalRegExpMatch; |
| 1232 to.InternalRegExpReplace = InternalRegExpReplace; | 1228 to.InternalRegExpReplace = InternalRegExpReplace; |
| 1233 to.IsRegExp = IsRegExp; | 1229 to.IsRegExp = IsRegExp; |
| 1234 to.RegExpExec = DoRegExpExec; | 1230 to.RegExpExec = DoRegExpExec; |
| 1235 to.RegExpInitialize = RegExpInitialize; | 1231 to.RegExpInitialize = RegExpInitialize; |
| 1236 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 1232 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
| 1237 to.RegExpSubclassExecJS = RegExpSubclassExecJS; | |
| 1238 to.RegExpSubclassMatch = RegExpSubclassMatch; | |
| 1239 to.RegExpSubclassReplace = RegExpSubclassReplace; | |
| 1240 to.RegExpSubclassSearch = RegExpSubclassSearch; | |
| 1241 to.RegExpSubclassSplit = RegExpSubclassSplit; | |
| 1242 to.RegExpSubclassTest = RegExpSubclassTest; | |
| 1243 to.RegExpTest = RegExpTest; | 1233 to.RegExpTest = RegExpTest; |
| 1244 }); | 1234 }); |
| 1245 | 1235 |
| 1246 }) | 1236 }) |
| OLD | NEW |