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 |
(...skipping 20 matching lines...) Expand all Loading... |
31 MinSimple = from.MinSimple; | 31 MinSimple = from.MinSimple; |
32 SpeciesConstructor = from.SpeciesConstructor; | 32 SpeciesConstructor = from.SpeciesConstructor; |
33 }); | 33 }); |
34 | 34 |
35 // ------------------------------------------------------------------- | 35 // ------------------------------------------------------------------- |
36 | 36 |
37 // Property of the builtins object for recording the result of the last | 37 // Property of the builtins object for recording the result of the last |
38 // regexp match. The property RegExpLastMatchInfo includes the matchIndices | 38 // regexp match. The property RegExpLastMatchInfo includes the matchIndices |
39 // array of the last successful regexp match (an array of start/end index | 39 // array of the last successful regexp match (an array of start/end index |
40 // pairs for the match and all the captured substrings), the invariant is | 40 // pairs for the match and all the captured substrings), the invariant is |
41 // that there are at least two capture indeces. The array also contains | 41 // that there are at least two capture indices. The array also contains |
42 // the subject string for the last successful match. | 42 // the subject string for the last successful match. |
43 var RegExpLastMatchInfo = new InternalPackedArray( | 43 // We use a JSObject rather than a JSArray so we don't have to manually update |
44 2, // REGEXP_NUMBER_OF_CAPTURES | 44 // its length. |
45 "", // Last subject. | 45 var RegExpLastMatchInfo = { |
46 UNDEFINED, // Last input - settable with RegExpSetInput. | 46 REGEXP_NUMBER_OF_CAPTURES: 2, |
47 0, // REGEXP_FIRST_CAPTURE + 0 | 47 REGEXP_LAST_SUBJECT: "", |
48 0 // REGEXP_FIRST_CAPTURE + 1 | 48 REGEXP_LAST_INPUT: UNDEFINED, // Settable with RegExpSetInput. |
49 ); | 49 CAPTURE0: 0, |
| 50 CAPTURE1: 0 |
| 51 }; |
50 | 52 |
51 // ------------------------------------------------------------------- | 53 // ------------------------------------------------------------------- |
52 | 54 |
53 // ES#sec-isregexp IsRegExp ( argument ) | 55 // ES#sec-isregexp IsRegExp ( argument ) |
54 function IsRegExp(o) { | 56 function IsRegExp(o) { |
55 if (!IS_RECEIVER(o)) return false; | 57 if (!IS_RECEIVER(o)) return false; |
56 var is_regexp = o[matchSymbol]; | 58 var is_regexp = o[matchSymbol]; |
57 if (!IS_UNDEFINED(is_regexp)) return TO_BOOLEAN(is_regexp); | 59 if (!IS_UNDEFINED(is_regexp)) return TO_BOOLEAN(is_regexp); |
58 return IS_REGEXP(o); | 60 return IS_REGEXP(o); |
59 } | 61 } |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 | 1196 |
1195 for (var i = 1; i < 10; ++i) { | 1197 for (var i = 1; i < 10; ++i) { |
1196 utils.InstallGetterSetter(GlobalRegExp, '$' + i, RegExpMakeCaptureGetter(i), | 1198 utils.InstallGetterSetter(GlobalRegExp, '$' + i, RegExpMakeCaptureGetter(i), |
1197 NoOpSetter, DONT_DELETE); | 1199 NoOpSetter, DONT_DELETE); |
1198 } | 1200 } |
1199 %ToFastProperties(GlobalRegExp); | 1201 %ToFastProperties(GlobalRegExp); |
1200 | 1202 |
1201 // ------------------------------------------------------------------- | 1203 // ------------------------------------------------------------------- |
1202 // Internal | 1204 // Internal |
1203 | 1205 |
1204 var InternalRegExpMatchInfo = new InternalPackedArray(2, "", UNDEFINED, 0, 0); | 1206 var InternalRegExpMatchInfo = { |
| 1207 REGEXP_NUMBER_OF_CAPTURES: 2, |
| 1208 REGEXP_LAST_SUBJECT: "", |
| 1209 REGEXP_LAST_INPUT: UNDEFINED, |
| 1210 CAPTURE0: 0, |
| 1211 CAPTURE1: 0 |
| 1212 }; |
1205 | 1213 |
1206 function InternalRegExpMatch(regexp, subject) { | 1214 function InternalRegExpMatch(regexp, subject) { |
1207 var matchInfo = %_RegExpExec(regexp, subject, 0, InternalRegExpMatchInfo); | 1215 var matchInfo = %_RegExpExec(regexp, subject, 0, InternalRegExpMatchInfo); |
1208 if (!IS_NULL(matchInfo)) { | 1216 if (!IS_NULL(matchInfo)) { |
1209 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchInfo, subject); | 1217 RETURN_NEW_RESULT_FROM_MATCH_INFO(matchInfo, subject); |
1210 } | 1218 } |
1211 return null; | 1219 return null; |
1212 } | 1220 } |
1213 | 1221 |
1214 function InternalRegExpReplace(regexp, subject, replacement) { | 1222 function InternalRegExpReplace(regexp, subject, replacement) { |
1215 return %StringReplaceGlobalRegExpWithString( | 1223 return %StringReplaceGlobalRegExpWithString( |
1216 subject, regexp, replacement, InternalRegExpMatchInfo); | 1224 subject, regexp, replacement, InternalRegExpMatchInfo); |
1217 } | 1225 } |
1218 | 1226 |
1219 // ------------------------------------------------------------------- | 1227 // ------------------------------------------------------------------- |
1220 // Exports | 1228 // Exports |
1221 | 1229 |
1222 utils.Export(function(to) { | 1230 utils.Export(function(to) { |
1223 to.InternalRegExpMatch = InternalRegExpMatch; | 1231 to.InternalRegExpMatch = InternalRegExpMatch; |
1224 to.InternalRegExpReplace = InternalRegExpReplace; | 1232 to.InternalRegExpReplace = InternalRegExpReplace; |
1225 to.IsRegExp = IsRegExp; | 1233 to.IsRegExp = IsRegExp; |
1226 to.RegExpExec = DoRegExpExec; | 1234 to.RegExpExec = DoRegExpExec; |
1227 to.RegExpInitialize = RegExpInitialize; | 1235 to.RegExpInitialize = RegExpInitialize; |
1228 to.RegExpLastMatchInfo = RegExpLastMatchInfo; | 1236 to.RegExpLastMatchInfo = RegExpLastMatchInfo; |
1229 to.RegExpTest = RegExpTest; | 1237 to.RegExpTest = RegExpTest; |
1230 }); | 1238 }); |
1231 | 1239 |
1232 }) | 1240 }) |
OLD | NEW |