| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 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 <stddef.h> |
| 11 |
#include <stdint.h> |
| 12 |
|
| 13 |
#include "NamespaceImports.h" |
| 14 |
|
| 15 |
#include "js/PropertySpec.h" |
| 16 |
#include "js/RootingAPI.h" |
| 17 |
#include "js/TypeDecls.h" |
| 18 |
#include "vm/RegExpShared.h" |
| 19 |
|
| 20 |
class JSLinearString; |
| 21 |
|
| 22 |
namespace JS { |
| 23 |
class Value; |
| 24 |
} |
| 25 |
|
| 26 |
/* |
| 27 |
* The following builtin natives are extern'd for pointer comparison in |
| 28 |
* other parts of the engine. |
| 29 |
*/ |
| 30 |
|
| 31 |
namespace js { |
| 32 |
|
| 33 |
class ArrayObject; |
| 34 |
class MatchPairs; |
| 35 |
class RegExpObject; |
| 36 |
class RegExpStatics; |
| 37 |
|
| 38 |
JSObject* InitRegExpClass(JSContext* cx, HandleObject obj); |
| 39 |
|
| 40 |
/* |
| 41 |
* Legacy behavior of ExecuteRegExp(), which is baked into the JSAPI. |
| 42 |
* |
| 43 |
* |res| may be nullptr if the RegExpStatics are not to be updated. |
| 44 |
* |input| may be nullptr if there is no JSString corresponding to |
| 45 |
* |chars| and |length|. |
| 46 |
*/ |
| 47 |
[[nodiscard]] bool ExecuteRegExpLegacy(JSContext* cx, RegExpStatics* res, |
| 48 |
Handle<RegExpObject*> reobj, |
| 49 |
Handle<JSLinearString*> input, |
| 50 |
size_t* lastIndex, bool test, |
| 51 |
MutableHandleValue rval); |
| 52 |
|
| 53 |
// Translation from MatchPairs to a JS array in regexp_exec()'s output format. |
| 54 |
[[nodiscard]] bool CreateRegExpMatchResult(JSContext* cx, HandleRegExpShared re, |
| 55 |
HandleString input, |
| 56 |
const MatchPairs& matches, |
| 57 |
MutableHandleValue rval); |
| 58 |
|
| 59 |
[[nodiscard]] extern bool RegExpMatcher(JSContext* cx, unsigned argc, |
| 60 |
Value* vp); |
| 61 |
|
| 62 |
[[nodiscard]] extern bool RegExpMatcherRaw(JSContext* cx, HandleObject regexp, |
| 63 |
HandleString input, |
| 64 |
int32_t lastIndex, |
| 65 |
MatchPairs* maybeMatches, |
| 66 |
MutableHandleValue output); |
| 67 |
|
| 68 |
[[nodiscard]] extern bool RegExpSearcher(JSContext* cx, unsigned argc, |
| 69 |
Value* vp); |
| 70 |
|
| 71 |
[[nodiscard]] extern bool RegExpSearcherRaw(JSContext* cx, HandleObject regexp, |
| 72 |
HandleString input, |
| 73 |
int32_t lastIndex, |
| 74 |
MatchPairs* maybeMatches, |
| 75 |
int32_t* result); |
| 76 |
|
| 77 |
[[nodiscard]] extern bool RegExpSearcherLastLimit(JSContext* cx, unsigned argc, |
| 78 |
Value* vp); |
| 79 |
|
| 80 |
[[nodiscard]] extern bool RegExpBuiltinExecMatchFromJit( |
| 81 |
JSContext* cx, Handle<RegExpObject*> regexp, HandleString input, |
| 82 |
MatchPairs* maybeMatches, MutableHandleValue output); |
| 83 |
|
| 84 |
[[nodiscard]] extern bool RegExpBuiltinExecTestFromJit( |
| 85 |
JSContext* cx, Handle<RegExpObject*> regexp, HandleString input, |
| 86 |
bool* result); |
| 87 |
|
| 88 |
[[nodiscard]] extern bool intrinsic_GetElemBaseForLambda(JSContext* cx, |
| 89 |
unsigned argc, |
| 90 |
Value* vp); |
| 91 |
|
| 92 |
[[nodiscard]] extern bool intrinsic_GetStringDataProperty(JSContext* cx, |
| 93 |
unsigned argc, |
| 94 |
Value* vp); |
| 95 |
|
| 96 |
/* |
| 97 |
* The following functions are for use by self-hosted code. |
| 98 |
*/ |
| 99 |
|
| 100 |
/* |
| 101 |
* Behaves like RegExp(source, flags). |
| 102 |
* |source| must be a valid regular expression pattern, |flags| is a raw |
| 103 |
* integer value representing the regular expression flags. |
| 104 |
* Must be called without |new|. |
| 105 |
* |
| 106 |
* Dedicated function for RegExp.prototype[@@replace] and |
| 107 |
* RegExp.prototype[@@split] optimized paths. |
| 108 |
*/ |
| 109 |
[[nodiscard]] extern bool regexp_construct_raw_flags(JSContext* cx, |
| 110 |
unsigned argc, Value* vp); |
| 111 |
|
| 112 |
[[nodiscard]] extern bool IsRegExp(JSContext* cx, HandleValue value, |
| 113 |
bool* result); |
| 114 |
|
| 115 |
[[nodiscard]] extern bool RegExpCreate(JSContext* cx, HandleValue pattern, |
| 116 |
HandleValue flags, |
| 117 |
MutableHandleValue rval); |
| 118 |
|
| 119 |
[[nodiscard]] extern bool IsRegExpPrototypeOptimizable(JSContext* cx, |
| 120 |
unsigned argc, |
| 121 |
Value* vp); |
| 122 |
|
| 123 |
[[nodiscard]] extern bool IsOptimizableRegExpObject(JSObject* obj, |
| 124 |
JSContext* cx); |
| 125 |
|
| 126 |
[[nodiscard]] extern bool IsOptimizableRegExpObject(JSContext* cx, |
| 127 |
unsigned argc, Value* vp); |
| 128 |
|
| 129 |
[[nodiscard]] extern bool RegExpBuiltinExec(JSContext* cx, |
| 130 |
Handle<RegExpObject*> regexp, |
| 131 |
Handle<JSString*> string, |
| 132 |
bool forTest, |
| 133 |
MutableHandle<Value> rval); |
| 134 |
|
| 135 |
[[nodiscard]] extern bool RegExpExec(JSContext* cx, Handle<JSObject*> regexp, |
| 136 |
Handle<JSString*> string, bool forTest, |
| 137 |
MutableHandle<Value> rval); |
| 138 |
|
| 139 |
[[nodiscard]] extern bool RegExpGetSubstitution( |
| 140 |
JSContext* cx, Handle<ArrayObject*> matchResult, |
| 141 |
Handle<JSLinearString*> string, size_t position, |
| 142 |
Handle<JSLinearString*> replacement, size_t firstDollarIndex, |
| 143 |
HandleValue namedCaptures, MutableHandleValue rval); |
| 144 |
|
| 145 |
[[nodiscard]] extern bool RegExpHasCaptureGroups(JSContext* cx, |
| 146 |
Handle<RegExpObject*> obj, |
| 147 |
Handle<JSString*> input, |
| 148 |
bool* result); |
| 149 |
|
| 150 |
[[nodiscard]] extern bool GetFirstDollarIndex(JSContext* cx, unsigned argc, |
| 151 |
Value* vp); |
| 152 |
|
| 153 |
[[nodiscard]] extern bool GetFirstDollarIndexRaw(JSContext* cx, JSString* str, |
| 154 |
int32_t* index); |
| 155 |
|
| 156 |
extern int32_t GetFirstDollarIndexRawFlat(const JSLinearString* text); |
| 157 |
|
| 158 |
// RegExp ClassSpec members used in RegExpObject.cpp. |
| 159 |
[[nodiscard]] extern bool regexp_construct(JSContext* cx, unsigned argc, |
| 160 |
Value* vp); |
| 161 |
extern const JSPropertySpec regexp_static_props[]; |
| 162 |
extern const JSFunctionSpec regexp_static_methods[]; |
| 163 |
extern const JSPropertySpec regexp_properties[]; |
| 164 |
extern const JSFunctionSpec regexp_methods[]; |
| 165 |
|
| 166 |
// Used in RegExpObject::isOriginalFlagGetter. |
| 167 |
[[nodiscard]] extern bool regexp_hasIndices(JSContext* cx, unsigned argc, |
| 168 |
JS::Value* vp); |
| 169 |
[[nodiscard]] extern bool regexp_global(JSContext* cx, unsigned argc, |
| 170 |
JS::Value* vp); |
| 171 |
[[nodiscard]] extern bool regexp_ignoreCase(JSContext* cx, unsigned argc, |
| 172 |
JS::Value* vp); |
| 173 |
[[nodiscard]] extern bool regexp_multiline(JSContext* cx, unsigned argc, |
| 174 |
JS::Value* vp); |
| 175 |
[[nodiscard]] extern bool regexp_dotAll(JSContext* cx, unsigned argc, |
| 176 |
JS::Value* vp); |
| 177 |
[[nodiscard]] extern bool regexp_sticky(JSContext* cx, unsigned argc, |
| 178 |
JS::Value* vp); |
| 179 |
[[nodiscard]] extern bool regexp_unicode(JSContext* cx, unsigned argc, |
| 180 |
JS::Value* vp); |
| 181 |
[[nodiscard]] extern bool regexp_unicodeSets(JSContext* cx, unsigned argc, |
| 182 |
JS::Value* vp); |
| 183 |
|
| 184 |
#ifdef DEBUG |
| 185 |
// Sentinel value for cx->regExpSearcherLastLimit. |
| 186 |
constexpr uint32_t RegExpSearcherLastLimitSentinel = UINT32_MAX; |
| 187 |
#endif |
| 188 |
|
| 189 |
} /* namespace js */ |
| 190 |
|
| 191 |
#endif /* builtin_RegExp_h */ |