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

Side by Side Diff: src/jsregexp.h

Issue 10535164: Unbreak interpreted regexp. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/ia32/regexp-macro-assembler-ia32.h ('k') | src/jsregexp.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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // Returns false if compilation fails. 71 // Returns false if compilation fails.
72 static Handle<Object> Compile(Handle<JSRegExp> re, 72 static Handle<Object> Compile(Handle<JSRegExp> re,
73 Handle<String> pattern, 73 Handle<String> pattern,
74 Handle<String> flags); 74 Handle<String> flags);
75 75
76 // See ECMA-262 section 15.10.6.2. 76 // See ECMA-262 section 15.10.6.2.
77 // This function calls the garbage collector if necessary. 77 // This function calls the garbage collector if necessary.
78 static Handle<Object> Exec(Handle<JSRegExp> regexp, 78 static Handle<Object> Exec(Handle<JSRegExp> regexp,
79 Handle<String> subject, 79 Handle<String> subject,
80 int index, 80 int index,
81 Handle<JSArray> lastMatchInfo, 81 Handle<JSArray> lastMatchInfo);
82 Zone* zone);
83 82
84 // Prepares a JSRegExp object with Irregexp-specific data. 83 // Prepares a JSRegExp object with Irregexp-specific data.
85 static void IrregexpInitialize(Handle<JSRegExp> re, 84 static void IrregexpInitialize(Handle<JSRegExp> re,
86 Handle<String> pattern, 85 Handle<String> pattern,
87 JSRegExp::Flags flags, 86 JSRegExp::Flags flags,
88 int capture_register_count); 87 int capture_register_count);
89 88
90 89
91 static void AtomCompile(Handle<JSRegExp> re, 90 static void AtomCompile(Handle<JSRegExp> re,
92 Handle<String> pattern, 91 Handle<String> pattern,
93 JSRegExp::Flags flags, 92 JSRegExp::Flags flags,
94 Handle<String> match_pattern); 93 Handle<String> match_pattern);
95 94
96 static Handle<Object> AtomExec(Handle<JSRegExp> regexp, 95 static Handle<Object> AtomExec(Handle<JSRegExp> regexp,
97 Handle<String> subject, 96 Handle<String> subject,
98 int index, 97 int index,
99 Handle<JSArray> lastMatchInfo); 98 Handle<JSArray> lastMatchInfo);
100 99
101 enum IrregexpResult { RE_FAILURE = 0, RE_SUCCESS = 1, RE_EXCEPTION = -1 }; 100 enum IrregexpResult { RE_FAILURE = 0, RE_SUCCESS = 1, RE_EXCEPTION = -1 };
102 101
103 // Prepare a RegExp for being executed one or more times (using 102 // Prepare a RegExp for being executed one or more times (using
104 // IrregexpExecOnce) on the subject. 103 // IrregexpExecOnce) on the subject.
105 // This ensures that the regexp is compiled for the subject, and that 104 // This ensures that the regexp is compiled for the subject, and that
106 // the subject is flat. 105 // the subject is flat.
107 // Returns the number of integer spaces required by IrregexpExecOnce 106 // Returns the number of integer spaces required by IrregexpExecOnce
108 // as its "registers" argument. If the regexp cannot be compiled, 107 // as its "registers" argument. If the regexp cannot be compiled,
109 // an exception is set as pending, and this function returns negative. 108 // an exception is set as pending, and this function returns negative.
110 static int IrregexpPrepare(Handle<JSRegExp> regexp, 109 static int IrregexpPrepare(Handle<JSRegExp> regexp,
111 Handle<String> subject, 110 Handle<String> subject);
112 Zone* zone);
113 111
114 // Calculate the size of offsets vector for the case of global regexp 112 // Calculate the size of offsets vector for the case of global regexp
115 // and the number of matches this vector is able to store. 113 // and the number of matches this vector is able to store.
116 static int GlobalOffsetsVectorSize(Handle<JSRegExp> regexp, 114 static int GlobalOffsetsVectorSize(Handle<JSRegExp> regexp,
117 int registers_per_match, 115 int registers_per_match,
118 int* max_matches); 116 int* max_matches);
119 117
120 // Execute a regular expression on the subject, starting from index. 118 // Execute a regular expression on the subject, starting from index.
121 // If matching succeeds, return the number of matches. This can be larger 119 // If matching succeeds, return the number of matches. This can be larger
122 // than one in the case of global regular expressions. 120 // than one in the case of global regular expressions.
123 // The captures and subcaptures are stored into the registers vector. 121 // The captures and subcaptures are stored into the registers vector.
124 // If matching fails, returns RE_FAILURE. 122 // If matching fails, returns RE_FAILURE.
125 // If execution fails, sets a pending exception and returns RE_EXCEPTION. 123 // If execution fails, sets a pending exception and returns RE_EXCEPTION.
126 static int IrregexpExecRaw(Handle<JSRegExp> regexp, 124 static int IrregexpExecRaw(Handle<JSRegExp> regexp,
127 Handle<String> subject, 125 Handle<String> subject,
128 int index, 126 int index,
129 Vector<int> registers, 127 Vector<int> registers);
130 Zone* zone);
131 128
132 // Execute an Irregexp bytecode pattern. 129 // Execute an Irregexp bytecode pattern.
133 // On a successful match, the result is a JSArray containing 130 // On a successful match, the result is a JSArray containing
134 // captured positions. On a failure, the result is the null value. 131 // captured positions. On a failure, the result is the null value.
135 // Returns an empty handle in case of an exception. 132 // Returns an empty handle in case of an exception.
136 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp, 133 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp,
137 Handle<String> subject, 134 Handle<String> subject,
138 int index, 135 int index,
139 Handle<JSArray> lastMatchInfo, 136 Handle<JSArray> lastMatchInfo);
140 Zone* zone);
141 137
142 // Array index in the lastMatchInfo array. 138 // Array index in the lastMatchInfo array.
143 static const int kLastCaptureCount = 0; 139 static const int kLastCaptureCount = 0;
144 static const int kLastSubject = 1; 140 static const int kLastSubject = 1;
145 static const int kLastInput = 2; 141 static const int kLastInput = 2;
146 static const int kFirstCapture = 3; 142 static const int kFirstCapture = 3;
147 static const int kLastMatchOverhead = 3; 143 static const int kLastMatchOverhead = 3;
148 144
149 // Direct offset into the lastMatchInfo array. 145 // Direct offset into the lastMatchInfo array.
150 static const int kLastCaptureCountOffset = 146 static const int kLastCaptureCountOffset =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // total regexp code compiled including code that has subsequently been freed 191 // total regexp code compiled including code that has subsequently been freed
196 // and the total executable memory at any point. 192 // and the total executable memory at any point.
197 static const int kRegExpExecutableMemoryLimit = 16 * MB; 193 static const int kRegExpExecutableMemoryLimit = 16 * MB;
198 static const int kRegWxpCompiledLimit = 1 * MB; 194 static const int kRegWxpCompiledLimit = 1 * MB;
199 195
200 private: 196 private:
201 static String* last_ascii_string_; 197 static String* last_ascii_string_;
202 static String* two_byte_cached_string_; 198 static String* two_byte_cached_string_;
203 199
204 static bool CompileIrregexp( 200 static bool CompileIrregexp(
205 Handle<JSRegExp> re, Handle<String> sample_subject, bool is_ascii, 201 Handle<JSRegExp> re, Handle<String> sample_subject, bool is_ascii);
206 Zone* zone);
207 static inline bool EnsureCompiledIrregexp( 202 static inline bool EnsureCompiledIrregexp(
208 Handle<JSRegExp> re, Handle<String> sample_subject, bool is_ascii, 203 Handle<JSRegExp> re, Handle<String> sample_subject, bool is_ascii);
209 Zone* zone);
210 204
211 205
212 // Set the subject cache. The previous string buffer is not deleted, so the 206 // Set the subject cache. The previous string buffer is not deleted, so the
213 // caller should ensure that it doesn't leak. 207 // caller should ensure that it doesn't leak.
214 static void SetSubjectCache(String* subject, 208 static void SetSubjectCache(String* subject,
215 char* utf8_subject, 209 char* utf8_subject,
216 int uft8_length, 210 int uft8_length,
217 int character_position, 211 int character_position,
218 int utf8_position); 212 int utf8_position);
219 213
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 int* vector_; 1651 int* vector_;
1658 int offsets_vector_length_; 1652 int offsets_vector_length_;
1659 1653
1660 friend class ExternalReference; 1654 friend class ExternalReference;
1661 }; 1655 };
1662 1656
1663 1657
1664 } } // namespace v8::internal 1658 } } // namespace v8::internal
1665 1659
1666 #endif // V8_JSREGEXP_H_ 1660 #endif // V8_JSREGEXP_H_
OLDNEW
« no previous file with comments | « src/ia32/regexp-macro-assembler-ia32.h ('k') | src/jsregexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698