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

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

Issue 2295273003: [regexp] Port RegExpCompile and RegExpToString (Closed)
Patch Set: Split up patch Created 4 years, 3 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/builtins/builtins-regexp.cc ('k') | no next file » | 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 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 // Imports 10 // Imports
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // ES#sec-regexpinitialize 64 // ES#sec-regexpinitialize
65 // Runtime Semantics: RegExpInitialize ( obj, pattern, flags ) 65 // Runtime Semantics: RegExpInitialize ( obj, pattern, flags )
66 function RegExpInitialize(object, pattern, flags) { 66 function RegExpInitialize(object, pattern, flags) {
67 pattern = IS_UNDEFINED(pattern) ? '' : TO_STRING(pattern); 67 pattern = IS_UNDEFINED(pattern) ? '' : TO_STRING(pattern);
68 flags = IS_UNDEFINED(flags) ? '' : TO_STRING(flags); 68 flags = IS_UNDEFINED(flags) ? '' : TO_STRING(flags);
69 %RegExpInitializeAndCompile(object, pattern, flags); 69 %RegExpInitializeAndCompile(object, pattern, flags);
70 return object; 70 return object;
71 } 71 }
72 72
73 73
74 function PatternFlags(pattern) {
75 return (REGEXP_GLOBAL(pattern) ? 'g' : '') +
76 (REGEXP_IGNORE_CASE(pattern) ? 'i' : '') +
77 (REGEXP_MULTILINE(pattern) ? 'm' : '') +
78 (REGEXP_UNICODE(pattern) ? 'u' : '') +
79 (REGEXP_STICKY(pattern) ? 'y' : '');
80 }
81
82
83 // ES#sec-regexp.prototype.compile RegExp.prototype.compile (pattern, flags)
84 function RegExpCompileJS(pattern, flags) {
85 if (!IS_REGEXP(this)) {
86 throw %make_type_error(kIncompatibleMethodReceiver,
87 "RegExp.prototype.compile", this);
88 }
89
90 if (IS_REGEXP(pattern)) {
91 if (!IS_UNDEFINED(flags)) throw %make_type_error(kRegExpFlags);
92
93 flags = PatternFlags(pattern);
94 pattern = REGEXP_SOURCE(pattern);
95 }
96
97 RegExpInitialize(this, pattern, flags);
98
99 // Return undefined for compatibility with JSC.
100 // See http://crbug.com/585775 for web compat details.
101 }
102
103
104 function DoRegExpExec(regexp, string, index) { 74 function DoRegExpExec(regexp, string, index) {
105 return %_RegExpExec(regexp, string, index, RegExpLastMatchInfo); 75 return %_RegExpExec(regexp, string, index, RegExpLastMatchInfo);
106 } 76 }
107 77
108 78
109 // This is kind of performance sensitive, so we want to avoid unnecessary 79 // This is kind of performance sensitive, so we want to avoid unnecessary
110 // type checks on inputs. But we also don't want to inline it several times 80 // type checks on inputs. But we also don't want to inline it several times
111 // manually, so we use a macro :-) 81 // manually, so we use a macro :-)
112 macro RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING) 82 macro RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING)
113 var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1; 83 var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 regexp_val = 298 regexp_val =
329 new GlobalRegExp( 299 new GlobalRegExp(
330 %_SubString(REGEXP_SOURCE(regexp), 2, REGEXP_SOURCE(regexp).length), 300 %_SubString(REGEXP_SOURCE(regexp), 2, REGEXP_SOURCE(regexp).length),
331 (REGEXP_IGNORE_CASE(regexp) ? REGEXP_MULTILINE(regexp) ? "im" : "i" 301 (REGEXP_IGNORE_CASE(regexp) ? REGEXP_MULTILINE(regexp) ? "im" : "i"
332 : REGEXP_MULTILINE(regexp) ? "m" : "")); 302 : REGEXP_MULTILINE(regexp) ? "m" : ""));
333 } 303 }
334 return regexp_val; 304 return regexp_val;
335 } 305 }
336 306
337 307
338 function RegExpToString() {
339 if (!IS_RECEIVER(this)) {
340 throw %make_type_error(
341 kIncompatibleMethodReceiver, 'RegExp.prototype.toString', this);
342 }
343 if (this === GlobalRegExp.prototype) {
344 %IncrementUseCounter(kRegExpPrototypeToString);
345 }
346 return '/' + TO_STRING(this.source) + '/' + TO_STRING(this.flags);
347 }
348
349
350 function AtSurrogatePair(subject, index) { 308 function AtSurrogatePair(subject, index) {
351 if (index + 1 >= subject.length) return false; 309 if (index + 1 >= subject.length) return false;
352 var first = %_StringCharCodeAt(subject, index); 310 var first = %_StringCharCodeAt(subject, index);
353 if (first < 0xD800 || first > 0xDBFF) return false; 311 if (first < 0xD800 || first > 0xDBFF) return false;
354 var second = %_StringCharCodeAt(subject, index + 1); 312 var second = %_StringCharCodeAt(subject, index + 1);
355 return second >= 0xDC00 || second <= 0xDFFF; 313 return second >= 0xDC00 || second <= 0xDFFF;
356 } 314 }
357 315
358 316
359 // Legacy implementation of RegExp.prototype[Symbol.split] which 317 // Legacy implementation of RegExp.prototype[Symbol.split] which
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 return result.index; 880 return result.index;
923 } 881 }
924 %FunctionRemovePrototype(RegExpSubclassSearch); 882 %FunctionRemovePrototype(RegExpSubclassSearch);
925 883
926 884
927 // ------------------------------------------------------------------- 885 // -------------------------------------------------------------------
928 886
929 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [ 887 utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [
930 "exec", RegExpSubclassExecJS, 888 "exec", RegExpSubclassExecJS,
931 "test", RegExpSubclassTest, 889 "test", RegExpSubclassTest,
932 "toString", RegExpToString,
933 "compile", RegExpCompileJS,
934 matchSymbol, RegExpSubclassMatch, 890 matchSymbol, RegExpSubclassMatch,
935 replaceSymbol, RegExpSubclassReplace, 891 replaceSymbol, RegExpSubclassReplace,
936 searchSymbol, RegExpSubclassSearch, 892 searchSymbol, RegExpSubclassSearch,
937 splitSymbol, RegExpSubclassSplit, 893 splitSymbol, RegExpSubclassSplit,
938 ]); 894 ]);
939 895
940 // Temporary until all RegExpLastMatchInfo accesses are ported to C++. 896 // Temporary until all RegExpLastMatchInfo accesses are ported to C++.
941 SET_PRIVATE(GlobalRegExp, lastMatchInfoSymbol, RegExpLastMatchInfo); 897 SET_PRIVATE(GlobalRegExp, lastMatchInfoSymbol, RegExpLastMatchInfo);
942 898
943 // ------------------------------------------------------------------- 899 // -------------------------------------------------------------------
(...skipping 27 matching lines...) Expand all
971 to.InternalRegExpMatch = InternalRegExpMatch; 927 to.InternalRegExpMatch = InternalRegExpMatch;
972 to.InternalRegExpReplace = InternalRegExpReplace; 928 to.InternalRegExpReplace = InternalRegExpReplace;
973 to.IsRegExp = IsRegExp; 929 to.IsRegExp = IsRegExp;
974 to.RegExpExec = DoRegExpExec; 930 to.RegExpExec = DoRegExpExec;
975 to.RegExpInitialize = RegExpInitialize; 931 to.RegExpInitialize = RegExpInitialize;
976 to.RegExpLastMatchInfo = RegExpLastMatchInfo; 932 to.RegExpLastMatchInfo = RegExpLastMatchInfo;
977 to.RegExpTest = RegExpTest; 933 to.RegExpTest = RegExpTest;
978 }); 934 });
979 935
980 }) 936 })
OLDNEW
« no previous file with comments | « src/builtins/builtins-regexp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698