DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (053b0bb00fed)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: set ts=8 sts=2 et sw=2 tw=80:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef builtin_RegExp_h
#define builtin_RegExp_h

#include "vm/RegExpObject.h"

/*
 * The following builtin natives are extern'd for pointer comparison in
 * other parts of the engine.
 */

namespace js {

JSObject* InitRegExpClass(JSContext* cx, HandleObject obj);

/*
 * Legacy behavior of ExecuteRegExp(), which is baked into the JSAPI.
 *
 * |res| may be nullptr if the RegExpStatics are not to be updated.
 * |input| may be nullptr if there is no JSString corresponding to
 * |chars| and |length|.
 */
MOZ_MUST_USE bool ExecuteRegExpLegacy(JSContext* cx, RegExpStatics* res,
                                      Handle<RegExpObject*> reobj,
                                      HandleLinearString input,
                                      size_t* lastIndex, bool test,
                                      MutableHandleValue rval);

// Translation from MatchPairs to a JS array in regexp_exec()'s output format.
MOZ_MUST_USE bool CreateRegExpMatchResult(JSContext* cx, HandleString input,
                                          const MatchPairs& matches,
                                          MutableHandleValue rval);

extern MOZ_MUST_USE bool RegExpMatcher(JSContext* cx, unsigned argc, Value* vp);

extern MOZ_MUST_USE bool RegExpMatcherRaw(JSContext* cx, HandleObject regexp,
                                          HandleString input,
                                          int32_t maybeLastIndex,
                                          MatchPairs* maybeMatches,
                                          MutableHandleValue output);

extern MOZ_MUST_USE bool RegExpSearcher(JSContext* cx, unsigned argc,
                                        Value* vp);

extern MOZ_MUST_USE bool RegExpSearcherRaw(JSContext* cx, HandleObject regexp,
                                           HandleString input,
                                           int32_t lastIndex,
                                           MatchPairs* maybeMatches,
                                           int32_t* result);

extern MOZ_MUST_USE bool RegExpTester(JSContext* cx, unsigned argc, Value* vp);

extern MOZ_MUST_USE bool RegExpTesterRaw(JSContext* cx, HandleObject regexp,
                                         HandleString input, int32_t lastIndex,
                                         int32_t* endIndex);

extern MOZ_MUST_USE bool intrinsic_GetElemBaseForLambda(JSContext* cx,
                                                        unsigned argc,
                                                        Value* vp);

extern MOZ_MUST_USE bool intrinsic_GetStringDataProperty(JSContext* cx,
                                                         unsigned argc,
                                                         Value* vp);

/*
 * The following functions are for use by self-hosted code.
 */

/*
 * Behaves like RegExp(source, flags).
 * |source| must be a valid regular expression pattern, |flags| is a raw
 * integer value representing the regular expression flags.
 * Must be called without |new|.
 *
 * Dedicated function for RegExp.prototype[@@replace] and
 * RegExp.prototype[@@split] optimized paths.
 */
extern MOZ_MUST_USE bool regexp_construct_raw_flags(JSContext* cx,
                                                    unsigned argc, Value* vp);

extern MOZ_MUST_USE bool IsRegExp(JSContext* cx, HandleValue value,
                                  bool* result);

extern MOZ_MUST_USE bool RegExpCreate(JSContext* cx, HandleValue pattern,
                                      HandleValue flags,
                                      MutableHandleValue rval);

extern MOZ_MUST_USE bool RegExpPrototypeOptimizable(JSContext* cx,
                                                    unsigned argc, Value* vp);

extern MOZ_MUST_USE bool RegExpPrototypeOptimizableRaw(JSContext* cx,
                                                       JSObject* proto);

extern MOZ_MUST_USE bool RegExpInstanceOptimizable(JSContext* cx, unsigned argc,
                                                   Value* vp);

extern MOZ_MUST_USE bool RegExpInstanceOptimizableRaw(JSContext* cx,
                                                      JSObject* obj,
                                                      JSObject* proto);

extern MOZ_MUST_USE bool RegExpGetSubstitution(
    JSContext* cx, HandleArrayObject matchResult, HandleLinearString string,
    size_t position, HandleLinearString replacement, size_t firstDollarIndex,
    MutableHandleValue rval);

extern MOZ_MUST_USE bool GetFirstDollarIndex(JSContext* cx, unsigned argc,
                                             Value* vp);

extern MOZ_MUST_USE bool GetFirstDollarIndexRaw(JSContext* cx, JSString* str,
                                                int32_t* index);

extern int32_t GetFirstDollarIndexRawFlat(JSLinearString* text);

// RegExp ClassSpec members used in RegExpObject.cpp.
extern MOZ_MUST_USE bool regexp_construct(JSContext* cx, unsigned argc,
                                          Value* vp);
extern const JSPropertySpec regexp_static_props[];
extern const JSPropertySpec regexp_properties[];
extern const JSFunctionSpec regexp_methods[];

// Used in RegExpObject::isOriginalFlagGetter.
extern MOZ_MUST_USE bool regexp_global(JSContext* cx, unsigned argc,
                                       JS::Value* vp);
extern MOZ_MUST_USE bool regexp_ignoreCase(JSContext* cx, unsigned argc,
                                           JS::Value* vp);
extern MOZ_MUST_USE bool regexp_multiline(JSContext* cx, unsigned argc,
                                          JS::Value* vp);
extern MOZ_MUST_USE bool regexp_sticky(JSContext* cx, unsigned argc,
                                       JS::Value* vp);
extern MOZ_MUST_USE bool regexp_unicode(JSContext* cx, unsigned argc,
                                        JS::Value* vp);

} /* namespace js */

#endif /* builtin_RegExp_h */