Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: src/js/regexp.js

Issue 1838563003: Remove --harmony-regexps flag (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/js/harmony-regexp.js ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 var index = n * 2; 1013 var index = n * 2;
1014 if (index >= NUMBER_OF_CAPTURES(RegExpLastMatchInfo)) return ''; 1014 if (index >= NUMBER_OF_CAPTURES(RegExpLastMatchInfo)) return '';
1015 var matchStart = RegExpLastMatchInfo[CAPTURE(index)]; 1015 var matchStart = RegExpLastMatchInfo[CAPTURE(index)];
1016 var matchEnd = RegExpLastMatchInfo[CAPTURE(index + 1)]; 1016 var matchEnd = RegExpLastMatchInfo[CAPTURE(index + 1)];
1017 if (matchStart == -1 || matchEnd == -1) return ''; 1017 if (matchStart == -1 || matchEnd == -1) return '';
1018 return %_SubString(LAST_SUBJECT(RegExpLastMatchInfo), matchStart, matchEnd); 1018 return %_SubString(LAST_SUBJECT(RegExpLastMatchInfo), matchStart, matchEnd);
1019 }; 1019 };
1020 } 1020 }
1021 1021
1022 1022
1023 // ES6 21.2.5.3.
1024 function RegExpGetFlags() {
1025 if (!IS_RECEIVER(this)) {
1026 throw MakeTypeError(
1027 kRegExpNonObject, "RegExp.prototype.flags", TO_STRING(this));
1028 }
1029 var result = '';
1030 if (this.global) result += 'g';
1031 if (this.ignoreCase) result += 'i';
1032 if (this.multiline) result += 'm';
1033 if (this.unicode) result += 'u';
1034 if (this.sticky) result += 'y';
1035 return result;
1036 }
1037
1038
1023 // ES6 21.2.5.4. 1039 // ES6 21.2.5.4.
1024 function RegExpGetGlobal() { 1040 function RegExpGetGlobal() {
1025 if (!IS_REGEXP(this)) { 1041 if (!IS_REGEXP(this)) {
1026 // TODO(littledan): Remove this RegExp compat workaround 1042 // TODO(littledan): Remove this RegExp compat workaround
1027 if (this === GlobalRegExpPrototype) { 1043 if (this === GlobalRegExpPrototype) {
1028 %IncrementUseCounter(kRegExpPrototypeOldFlagGetter); 1044 %IncrementUseCounter(kRegExpPrototypeOldFlagGetter);
1029 return UNDEFINED; 1045 return UNDEFINED;
1030 } 1046 }
1031 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.global"); 1047 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.global");
1032 } 1048 }
1033 return !!REGEXP_GLOBAL(this); 1049 return !!REGEXP_GLOBAL(this);
1034 } 1050 }
1035 %FunctionSetName(RegExpGetGlobal, "RegExp.prototype.global");
1036 %SetNativeFlag(RegExpGetGlobal);
1037 1051
1038 1052
1039 // ES6 21.2.5.5. 1053 // ES6 21.2.5.5.
1040 function RegExpGetIgnoreCase() { 1054 function RegExpGetIgnoreCase() {
1041 if (!IS_REGEXP(this)) { 1055 if (!IS_REGEXP(this)) {
1042 // TODO(littledan): Remove this RegExp compat workaround 1056 // TODO(littledan): Remove this RegExp compat workaround
1043 if (this === GlobalRegExpPrototype) { 1057 if (this === GlobalRegExpPrototype) {
1044 %IncrementUseCounter(kRegExpPrototypeOldFlagGetter); 1058 %IncrementUseCounter(kRegExpPrototypeOldFlagGetter);
1045 return UNDEFINED; 1059 return UNDEFINED;
1046 } 1060 }
1047 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.ignoreCase"); 1061 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.ignoreCase");
1048 } 1062 }
1049 return !!REGEXP_IGNORE_CASE(this); 1063 return !!REGEXP_IGNORE_CASE(this);
1050 } 1064 }
1051 %FunctionSetName(RegExpGetIgnoreCase, "RegExp.prototype.ignoreCase");
1052 %SetNativeFlag(RegExpGetIgnoreCase);
1053 1065
1054 1066
1055 // ES6 21.2.5.7. 1067 // ES6 21.2.5.7.
1056 function RegExpGetMultiline() { 1068 function RegExpGetMultiline() {
1057 if (!IS_REGEXP(this)) { 1069 if (!IS_REGEXP(this)) {
1058 // TODO(littledan): Remove this RegExp compat workaround 1070 // TODO(littledan): Remove this RegExp compat workaround
1059 if (this === GlobalRegExpPrototype) { 1071 if (this === GlobalRegExpPrototype) {
1060 %IncrementUseCounter(kRegExpPrototypeOldFlagGetter); 1072 %IncrementUseCounter(kRegExpPrototypeOldFlagGetter);
1061 return UNDEFINED; 1073 return UNDEFINED;
1062 } 1074 }
1063 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.multiline"); 1075 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.multiline");
1064 } 1076 }
1065 return !!REGEXP_MULTILINE(this); 1077 return !!REGEXP_MULTILINE(this);
1066 } 1078 }
1067 %FunctionSetName(RegExpGetMultiline, "RegExp.prototype.multiline");
1068 %SetNativeFlag(RegExpGetMultiline);
1069 1079
1070 1080
1071 // ES6 21.2.5.10. 1081 // ES6 21.2.5.10.
1072 function RegExpGetSource() { 1082 function RegExpGetSource() {
1073 if (!IS_REGEXP(this)) { 1083 if (!IS_REGEXP(this)) {
1074 // TODO(littledan): Remove this RegExp compat workaround 1084 // TODO(littledan): Remove this RegExp compat workaround
1075 if (this === GlobalRegExpPrototype) { 1085 if (this === GlobalRegExpPrototype) {
1076 %IncrementUseCounter(kRegExpPrototypeSourceGetter); 1086 %IncrementUseCounter(kRegExpPrototypeSourceGetter);
1077 return UNDEFINED; 1087 return UNDEFINED;
1078 } 1088 }
1079 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.source"); 1089 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.source");
1080 } 1090 }
1081 return REGEXP_SOURCE(this); 1091 return REGEXP_SOURCE(this);
1082 } 1092 }
1083 %FunctionSetName(RegExpGetSource, "RegExp.prototype.source"); 1093
1084 %SetNativeFlag(RegExpGetSource); 1094
1095 // ES6 21.2.5.12.
1096 function RegExpGetSticky() {
1097 if (!IS_REGEXP(this)) {
1098 // Compat fix: RegExp.prototype.sticky == undefined; UseCounter tracks it
1099 // TODO(littledan): Remove this workaround or standardize it
1100 if (this === GlobalRegExpPrototype) {
1101 %IncrementUseCounter(kRegExpPrototypeStickyGetter);
1102 return UNDEFINED;
1103 }
1104 throw MakeTypeError(kRegExpNonRegExp, "RegExp.prototype.sticky");
1105 }
1106 return !!REGEXP_STICKY(this);
1107 }
1085 1108
1086 // ------------------------------------------------------------------- 1109 // -------------------------------------------------------------------
1087 1110
1088 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp'); 1111 %FunctionSetInstanceClassName(GlobalRegExp, 'RegExp');
1089 GlobalRegExpPrototype = new GlobalObject(); 1112 GlobalRegExpPrototype = new GlobalObject();
1090 %FunctionSetPrototype(GlobalRegExp, GlobalRegExpPrototype); 1113 %FunctionSetPrototype(GlobalRegExp, GlobalRegExpPrototype);
1091 %AddNamedProperty( 1114 %AddNamedProperty(
1092 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM); 1115 GlobalRegExp.prototype, 'constructor', GlobalRegExp, DONT_ENUM);
1093 %SetCode(GlobalRegExp, RegExpConstructor); 1116 %SetCode(GlobalRegExp, RegExpConstructor);
1094 1117
1095 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ 1118 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [
1096 "exec", RegExpExecJS, 1119 "exec", RegExpExecJS,
1097 "test", RegExpTest, 1120 "test", RegExpTest,
1098 "toString", RegExpToString, 1121 "toString", RegExpToString,
1099 "compile", RegExpCompileJS, 1122 "compile", RegExpCompileJS,
1100 matchSymbol, RegExpMatch, 1123 matchSymbol, RegExpMatch,
1101 replaceSymbol, RegExpReplace, 1124 replaceSymbol, RegExpReplace,
1102 searchSymbol, RegExpSearch, 1125 searchSymbol, RegExpSearch,
1103 splitSymbol, RegExpSplit, 1126 splitSymbol, RegExpSplit,
1104 ]); 1127 ]);
1105 1128
1129 utils.InstallGetter(GlobalRegExp.prototype, 'flags', RegExpGetFlags);
1106 utils.InstallGetter(GlobalRegExp.prototype, 'global', RegExpGetGlobal); 1130 utils.InstallGetter(GlobalRegExp.prototype, 'global', RegExpGetGlobal);
1107 utils.InstallGetter(GlobalRegExp.prototype, 'ignoreCase', RegExpGetIgnoreCase); 1131 utils.InstallGetter(GlobalRegExp.prototype, 'ignoreCase', RegExpGetIgnoreCase);
1108 utils.InstallGetter(GlobalRegExp.prototype, 'multiline', RegExpGetMultiline); 1132 utils.InstallGetter(GlobalRegExp.prototype, 'multiline', RegExpGetMultiline);
1109 utils.InstallGetter(GlobalRegExp.prototype, 'source', RegExpGetSource); 1133 utils.InstallGetter(GlobalRegExp.prototype, 'source', RegExpGetSource);
1134 utils.InstallGetter(GlobalRegExp.prototype, 'sticky', RegExpGetSticky);
1110 1135
1111 // The properties `input` and `$_` are aliases for each other. When this 1136 // The properties `input` and `$_` are aliases for each other. When this
1112 // value is set the value it is set to is coerced to a string. 1137 // value is set the value it is set to is coerced to a string.
1113 // Getter and setter for the input. 1138 // Getter and setter for the input.
1114 var RegExpGetInput = function() { 1139 var RegExpGetInput = function() {
1115 var regExpInput = LAST_INPUT(RegExpLastMatchInfo); 1140 var regExpInput = LAST_INPUT(RegExpLastMatchInfo);
1116 return IS_UNDEFINED(regExpInput) ? "" : regExpInput; 1141 return IS_UNDEFINED(regExpInput) ? "" : regExpInput;
1117 }; 1142 };
1118 var RegExpSetInput = function(string) { 1143 var RegExpSetInput = function(string) {
1119 LAST_INPUT(RegExpLastMatchInfo) = TO_STRING(string); 1144 LAST_INPUT(RegExpLastMatchInfo) = TO_STRING(string);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 to.RegExpSubclassMatch = RegExpSubclassMatch; 1188 to.RegExpSubclassMatch = RegExpSubclassMatch;
1164 to.RegExpSubclassReplace = RegExpSubclassReplace; 1189 to.RegExpSubclassReplace = RegExpSubclassReplace;
1165 to.RegExpSubclassSearch = RegExpSubclassSearch; 1190 to.RegExpSubclassSearch = RegExpSubclassSearch;
1166 to.RegExpSubclassSplit = RegExpSubclassSplit; 1191 to.RegExpSubclassSplit = RegExpSubclassSplit;
1167 to.RegExpSubclassTest = RegExpSubclassTest; 1192 to.RegExpSubclassTest = RegExpSubclassTest;
1168 to.RegExpTest = RegExpTest; 1193 to.RegExpTest = RegExpTest;
1169 to.IsRegExp = IsRegExp; 1194 to.IsRegExp = IsRegExp;
1170 }); 1195 });
1171 1196
1172 }) 1197 })
OLDNEW
« no previous file with comments | « src/js/harmony-regexp.js ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698