| 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 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 function PatternFlags(pattern) { | 75 function PatternFlags(pattern) { |
| 76 return (REGEXP_GLOBAL(pattern) ? 'g' : '') + | 76 return (REGEXP_GLOBAL(pattern) ? 'g' : '') + |
| 77 (REGEXP_IGNORE_CASE(pattern) ? 'i' : '') + | 77 (REGEXP_IGNORE_CASE(pattern) ? 'i' : '') + |
| 78 (REGEXP_MULTILINE(pattern) ? 'm' : '') + | 78 (REGEXP_MULTILINE(pattern) ? 'm' : '') + |
| 79 (REGEXP_UNICODE(pattern) ? 'u' : '') + | 79 (REGEXP_UNICODE(pattern) ? 'u' : '') + |
| 80 (REGEXP_STICKY(pattern) ? 'y' : ''); | 80 (REGEXP_STICKY(pattern) ? 'y' : ''); |
| 81 } | 81 } |
| 82 | 82 |
| 83 | 83 |
| 84 // ES#sec-regexp-pattern-flags | |
| 85 // RegExp ( pattern, flags ) | |
| 86 function RegExpConstructor(pattern, flags) { | |
| 87 var newtarget = new.target; | |
| 88 var pattern_is_regexp = IsRegExp(pattern); | |
| 89 | |
| 90 if (IS_UNDEFINED(newtarget)) { | |
| 91 newtarget = GlobalRegExp; | |
| 92 | |
| 93 // ES6 section 21.2.3.1 step 3.b | |
| 94 if (pattern_is_regexp && IS_UNDEFINED(flags) && | |
| 95 pattern.constructor === newtarget) { | |
| 96 return pattern; | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 if (IS_REGEXP(pattern)) { | |
| 101 if (IS_UNDEFINED(flags)) flags = PatternFlags(pattern); | |
| 102 pattern = REGEXP_SOURCE(pattern); | |
| 103 | |
| 104 } else if (pattern_is_regexp) { | |
| 105 var input_pattern = pattern; | |
| 106 pattern = pattern.source; | |
| 107 if (IS_UNDEFINED(flags)) flags = input_pattern.flags; | |
| 108 } | |
| 109 | |
| 110 var object = %_NewObject(GlobalRegExp, newtarget); | |
| 111 return RegExpInitialize(object, pattern, flags); | |
| 112 } | |
| 113 | |
| 114 | |
| 115 // ES#sec-regexp.prototype.compile RegExp.prototype.compile (pattern, flags) | 84 // ES#sec-regexp.prototype.compile RegExp.prototype.compile (pattern, flags) |
| 116 function RegExpCompileJS(pattern, flags) { | 85 function RegExpCompileJS(pattern, flags) { |
| 117 if (!IS_REGEXP(this)) { | 86 if (!IS_REGEXP(this)) { |
| 118 throw %make_type_error(kIncompatibleMethodReceiver, | 87 throw %make_type_error(kIncompatibleMethodReceiver, |
| 119 "RegExp.prototype.compile", this); | 88 "RegExp.prototype.compile", this); |
| 120 } | 89 } |
| 121 | 90 |
| 122 if (IS_REGEXP(pattern)) { | 91 if (IS_REGEXP(pattern)) { |
| 123 if (!IS_UNDEFINED(flags)) throw %make_type_error(kRegExpFlags); | 92 if (!IS_UNDEFINED(flags)) throw %make_type_error(kRegExpFlags); |
| 124 | 93 |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 %SetForceInlineFlag(RegExpGetUnicode); | 935 %SetForceInlineFlag(RegExpGetUnicode); |
| 967 | 936 |
| 968 | 937 |
| 969 function RegExpSpecies() { | 938 function RegExpSpecies() { |
| 970 return this; | 939 return this; |
| 971 } | 940 } |
| 972 | 941 |
| 973 | 942 |
| 974 // ------------------------------------------------------------------- | 943 // ------------------------------------------------------------------- |
| 975 | 944 |
| 976 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp'); | |
| 977 %SetCode(GlobalRegExp, RegExpConstructor); | |
| 978 | |
| 979 utils.InstallGetter(GlobalRegExp, speciesSymbol, RegExpSpecies); | 945 utils.InstallGetter(GlobalRegExp, speciesSymbol, RegExpSpecies); |
| 980 | 946 |
| 981 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ | 947 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ |
| 982 "test", RegExpSubclassTest, | 948 "test", RegExpSubclassTest, |
| 983 "toString", RegExpToString, | 949 "toString", RegExpToString, |
| 984 "compile", RegExpCompileJS, | 950 "compile", RegExpCompileJS, |
| 985 matchSymbol, RegExpSubclassMatch, | 951 matchSymbol, RegExpSubclassMatch, |
| 986 replaceSymbol, RegExpSubclassReplace, | 952 replaceSymbol, RegExpSubclassReplace, |
| 987 searchSymbol, RegExpSubclassSearch, | 953 searchSymbol, RegExpSubclassSearch, |
| 988 splitSymbol, RegExpSubclassSplit, | 954 splitSymbol, RegExpSubclassSplit, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 to.GetSubstitution = GetSubstitution; | 1049 to.GetSubstitution = GetSubstitution; |
| 1084 to.InternalRegExpMatch = InternalRegExpMatch; | 1050 to.InternalRegExpMatch = InternalRegExpMatch; |
| 1085 to.InternalRegExpReplace = InternalRegExpReplace; | 1051 to.InternalRegExpReplace = InternalRegExpReplace; |
| 1086 to.IsRegExp = IsRegExp; | 1052 to.IsRegExp = IsRegExp; |
| 1087 to.RegExpExec = DoRegExpExec; | 1053 to.RegExpExec = DoRegExpExec; |
| 1088 to.RegExpInitialize = RegExpInitialize; | 1054 to.RegExpInitialize = RegExpInitialize; |
| 1089 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 1055 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
| 1090 }); | 1056 }); |
| 1091 | 1057 |
| 1092 }) | 1058 }) |
| OLD | NEW |