blob: 32835bf5c66f3de42d1c4b67aadfbec3e554efc4 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_JSREGEXP_H_
29#define V8_JSREGEXP_H_
30
31namespace v8 { namespace internal {
32
33class RegExpImpl {
34 public:
35 // Creates a regular expression literal in the old space.
36 // This function calls the garbage collector if necessary.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000037 static Handle<Object> CreateRegExpLiteral(Handle<JSFunction> constructor,
38 Handle<String> pattern,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000039 Handle<String> flags,
40 bool* has_pending_exception);
41
42 // Returns a string representation of a regular expression.
43 // Implements RegExp.prototype.toString, see ECMA-262 section 15.10.6.4.
44 // This function calls the garbage collector if necessary.
45 static Handle<String> ToString(Handle<Object> value);
46
47 static Handle<Object> JsreCompile(Handle<JSValue> re,
48 Handle<String> pattern,
49 Handle<String> flags);
50
51 // Implements RegExp.prototype.exec(string) function.
52 // See ECMA-262 section 15.10.6.2.
53 // This function calls the garbage collector if necessary.
54 static Handle<Object> JsreExec(Handle<JSValue> regexp,
55 Handle<String> subject,
56 Handle<Object> index);
57
58 // Call RegExp.prototyp.exec(string) in a loop.
59 // Used by String.prototype.match and String.prototype.replace.
60 // This function calls the garbage collector if necessary.
61 static Handle<Object> JsreExecGlobal(Handle<JSValue> regexp,
62 Handle<String> subject);
63
64 static void NewSpaceCollectionPrologue();
65 static void OldSpaceCollectionPrologue();
66
67 private:
68 // Converts a source string to a 16 bit flat string. The string
69 // will be either sequential or it will be a SlicedString backed
70 // by a flat string.
71 static Handle<String> StringToTwoByte(Handle<String> pattern);
72 static Handle<String> CachedStringToTwoByte(Handle<String> pattern);
73
74 static String* last_ascii_string_;
75 static String* two_byte_cached_string_;
76
77 // Returns the caputure from the re.
78 static int JsreCapture(Handle<JSValue> re);
79 static ByteArray* JsreInternal(Handle<JSValue> re);
80
81 // Call jsRegExpExecute once
82 static Handle<Object> JsreExecOnce(Handle<JSValue> regexp,
83 int num_captures,
84 Handle<String> subject,
85 int previous_index,
86 const uc16* utf8_subject,
87 int* ovector,
88 int ovector_length);
89
90 // Set the subject cache. The previous string buffer is not deleted, so the
91 // caller should ensure that it doesn't leak.
92 static void SetSubjectCache(String* subject, char* utf8_subject,
93 int uft8_length, int character_position,
94 int utf8_position);
95
96 // A one element cache of the last utf8_subject string and its length. The
97 // subject JS String object is cached in the heap. We also cache a
98 // translation between position and utf8 position.
99 static char* utf8_subject_cache_;
100 static int utf8_length_cache_;
101 static int utf8_position_;
102 static int character_position_;
103};
104
105
106} } // namespace v8::internal
107
108#endif // V8_JSREGEXP_H_