tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RegExp.h (8229B)


      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                                       HandleObject newTarget);
    119 
    120 [[nodiscard]] extern bool IsRegExpPrototypeOptimizable(JSContext* cx,
    121                                                       unsigned argc,
    122                                                       Value* vp);
    123 
    124 [[nodiscard]] extern bool IsOptimizableRegExpObject(JSObject* obj,
    125                                                    JSContext* cx);
    126 
    127 [[nodiscard]] extern bool IsOptimizableRegExpObject(JSContext* cx,
    128                                                    unsigned argc, Value* vp);
    129 
    130 [[nodiscard]] extern bool RegExpBuiltinExec(JSContext* cx,
    131                                            Handle<RegExpObject*> regexp,
    132                                            Handle<JSString*> string,
    133                                            bool forTest,
    134                                            MutableHandle<Value> rval);
    135 
    136 [[nodiscard]] extern bool RegExpExec(JSContext* cx, Handle<JSObject*> regexp,
    137                                     Handle<JSString*> string, bool forTest,
    138                                     MutableHandle<Value> rval);
    139 
    140 [[nodiscard]] extern bool RegExpGetSubstitution(
    141    JSContext* cx, Handle<ArrayObject*> matchResult,
    142    Handle<JSLinearString*> string, size_t position,
    143    Handle<JSLinearString*> replacement, size_t firstDollarIndex,
    144    HandleValue namedCaptures, MutableHandleValue rval);
    145 
    146 [[nodiscard]] extern bool RegExpHasCaptureGroups(JSContext* cx,
    147                                                 Handle<RegExpObject*> obj,
    148                                                 Handle<JSString*> input,
    149                                                 bool* result);
    150 
    151 [[nodiscard]] extern bool GetFirstDollarIndex(JSContext* cx, unsigned argc,
    152                                              Value* vp);
    153 
    154 [[nodiscard]] extern bool GetFirstDollarIndexRaw(JSContext* cx, JSString* str,
    155                                                 int32_t* index);
    156 
    157 template <typename StringT>
    158 extern int32_t GetFirstDollarIndexRawFlat(const StringT* text);
    159 
    160 // RegExp ClassSpec members used in RegExpObject.cpp.
    161 [[nodiscard]] extern bool regexp_construct(JSContext* cx, unsigned argc,
    162                                           Value* vp);
    163 extern const JSPropertySpec regexp_static_props[];
    164 extern const JSFunctionSpec regexp_static_methods[];
    165 extern const JSPropertySpec regexp_properties[];
    166 extern const JSFunctionSpec regexp_methods[];
    167 
    168 // Used in OptimizeRegExpPrototypeFuse::checkInvariant.
    169 [[nodiscard]] extern bool regexp_hasIndices(JSContext* cx, unsigned argc,
    170                                            JS::Value* vp);
    171 [[nodiscard]] extern bool regexp_global(JSContext* cx, unsigned argc,
    172                                        JS::Value* vp);
    173 [[nodiscard]] extern bool regexp_ignoreCase(JSContext* cx, unsigned argc,
    174                                            JS::Value* vp);
    175 [[nodiscard]] extern bool regexp_multiline(JSContext* cx, unsigned argc,
    176                                           JS::Value* vp);
    177 [[nodiscard]] extern bool regexp_dotAll(JSContext* cx, unsigned argc,
    178                                        JS::Value* vp);
    179 [[nodiscard]] extern bool regexp_sticky(JSContext* cx, unsigned argc,
    180                                        JS::Value* vp);
    181 [[nodiscard]] extern bool regexp_unicode(JSContext* cx, unsigned argc,
    182                                         JS::Value* vp);
    183 [[nodiscard]] extern bool regexp_unicodeSets(JSContext* cx, unsigned argc,
    184                                             JS::Value* vp);
    185 
    186 #ifdef DEBUG
    187 // Sentinel value for cx->regExpSearcherLastLimit.
    188 constexpr uint32_t RegExpSearcherLastLimitSentinel = UINT32_MAX;
    189 #endif
    190 
    191 } /* namespace js */
    192 
    193 #endif /* builtin_RegExp_h */