1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=8 sts=4 et sw=4 tw=99:
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef builtin_RegExp_h
8 #define builtin_RegExp_h
9 
10 #include "vm/RegExpObject.h"
11 
12 /*
13  * The following builtin natives are extern'd for pointer comparison in
14  * other parts of the engine.
15  */
16 
17 namespace js {
18 
19 JSObject* InitRegExpClass(JSContext* cx, HandleObject obj);
20 
21 /*
22  * Legacy behavior of ExecuteRegExp(), which is baked into the JSAPI.
23  *
24  * |res| may be nullptr if the RegExpStatics are not to be updated.
25  * |input| may be nullptr if there is no JSString corresponding to
26  * |chars| and |length|.
27  */
28 MOZ_MUST_USE bool ExecuteRegExpLegacy(JSContext* cx, RegExpStatics* res,
29                                       Handle<RegExpObject*> reobj,
30                                       HandleLinearString input,
31                                       size_t* lastIndex, bool test,
32                                       MutableHandleValue rval);
33 
34 /* Translation from MatchPairs to a JS array in regexp_exec()'s output format.
35  */
36 MOZ_MUST_USE bool CreateRegExpMatchResult(JSContext* cx, HandleString input,
37                                           const MatchPairs& matches,
38                                           MutableHandleValue rval);
39 
40 extern MOZ_MUST_USE bool RegExpMatcher(JSContext* cx, unsigned argc, Value* vp);
41 
42 extern MOZ_MUST_USE bool RegExpMatcherRaw(JSContext* cx, HandleObject regexp,
43                                           HandleString input, int32_t lastIndex,
44                                           MatchPairs* maybeMatches,
45                                           MutableHandleValue output);
46 
47 extern MOZ_MUST_USE bool RegExpSearcher(JSContext* cx, unsigned argc,
48                                         Value* vp);
49 
50 extern MOZ_MUST_USE bool RegExpSearcherRaw(JSContext* cx, HandleObject regexp,
51                                            HandleString input,
52                                            int32_t lastIndex,
53                                            MatchPairs* maybeMatches,
54                                            int32_t* result);
55 
56 extern MOZ_MUST_USE bool RegExpTester(JSContext* cx, unsigned argc, Value* vp);
57 
58 extern MOZ_MUST_USE bool RegExpTesterRaw(JSContext* cx, HandleObject regexp,
59                                          HandleString input, int32_t lastIndex,
60                                          int32_t* endIndex);
61 
62 extern MOZ_MUST_USE bool intrinsic_GetElemBaseForLambda(JSContext* cx,
63                                                         unsigned argc,
64                                                         Value* vp);
65 
66 extern MOZ_MUST_USE bool intrinsic_GetStringDataProperty(JSContext* cx,
67                                                          unsigned argc,
68                                                          Value* vp);
69 
70 /*
71  * The following functions are for use by self-hosted code.
72  */
73 
74 /*
75  * Behaves like RegExp(source, flags).
76  * |source| must be a valid regular expression pattern, |flags| is a raw
77  * integer value representing the regular expression flags.
78  * Must be called without |new|.
79  *
80  * Dedicated function for RegExp.prototype[@@replace] and
81  * RegExp.prototype[@@split] optimized paths.
82  */
83 extern MOZ_MUST_USE bool regexp_construct_raw_flags(JSContext* cx,
84                                                     unsigned argc, Value* vp);
85 
86 extern MOZ_MUST_USE bool IsRegExp(JSContext* cx, HandleValue value,
87                                   bool* result);
88 
89 extern MOZ_MUST_USE bool RegExpCreate(JSContext* cx, HandleValue pattern,
90                                       HandleValue flags,
91                                       MutableHandleValue rval);
92 
93 extern MOZ_MUST_USE bool RegExpPrototypeOptimizable(JSContext* cx,
94                                                     unsigned argc, Value* vp);
95 
96 extern MOZ_MUST_USE bool RegExpPrototypeOptimizableRaw(JSContext* cx,
97                                                        JSObject* proto);
98 
99 extern MOZ_MUST_USE bool RegExpInstanceOptimizable(JSContext* cx, unsigned argc,
100                                                    Value* vp);
101 
102 extern MOZ_MUST_USE bool RegExpInstanceOptimizableRaw(JSContext* cx,
103                                                       JSObject* obj,
104                                                       JSObject* proto);
105 
106 extern MOZ_MUST_USE bool RegExpGetSubstitution(
107     JSContext* cx, HandleArrayObject matchResult, HandleLinearString string,
108     size_t position, HandleLinearString replacement, size_t firstDollarIndex,
109     MutableHandleValue rval);
110 
111 extern MOZ_MUST_USE bool GetFirstDollarIndex(JSContext* cx, unsigned argc,
112                                              Value* vp);
113 
114 extern MOZ_MUST_USE bool GetFirstDollarIndexRaw(JSContext* cx, JSString* str,
115                                                 int32_t* index);
116 
117 extern int32_t GetFirstDollarIndexRawFlat(JSLinearString* text);
118 
119 // RegExp ClassSpec members used in RegExpObject.cpp.
120 extern MOZ_MUST_USE bool regexp_construct(JSContext* cx, unsigned argc,
121                                           Value* vp);
122 extern const JSPropertySpec regexp_static_props[];
123 extern const JSPropertySpec regexp_properties[];
124 extern const JSFunctionSpec regexp_methods[];
125 
126 // Used in RegExpObject::isOriginalFlagGetter.
127 extern MOZ_MUST_USE bool regexp_global(JSContext* cx, unsigned argc,
128                                        JS::Value* vp);
129 extern MOZ_MUST_USE bool regexp_ignoreCase(JSContext* cx, unsigned argc,
130                                            JS::Value* vp);
131 extern MOZ_MUST_USE bool regexp_multiline(JSContext* cx, unsigned argc,
132                                           JS::Value* vp);
133 extern MOZ_MUST_USE bool regexp_sticky(JSContext* cx, unsigned argc,
134                                        JS::Value* vp);
135 extern MOZ_MUST_USE bool regexp_unicode(JSContext* cx, unsigned argc,
136                                         JS::Value* vp);
137 
138 } /* namespace js */
139 
140 #endif /* builtin_RegExp_h */
141