Bug 1890689 apply drift correction to input rate instead of output rate r=pehrsons
[gecko.git] / js / public / RegExp.h
blobeda8cdb6fa56f8b5e571999c5336721fdaae7c97
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/. */
7 /* Regular expression-related operations. */
9 #ifndef js_RegExp_h
10 #define js_RegExp_h
12 #include <stddef.h> // size_t
14 #include "jstypes.h" // JS_PUBLIC_API
16 #include "js/RegExpFlags.h" // JS::RegExpFlags
17 #include "js/TypeDecls.h"
19 struct JS_PUBLIC_API JSContext;
20 class JS_PUBLIC_API JSString;
22 namespace JS {
24 /**
25 * Create a new RegExp for the given Latin-1-encoded bytes and flags.
27 extern JS_PUBLIC_API JSObject* NewRegExpObject(JSContext* cx, const char* bytes,
28 size_t length,
29 RegExpFlags flags);
31 /**
32 * Create a new RegExp for the given source and flags.
34 extern JS_PUBLIC_API JSObject* NewUCRegExpObject(JSContext* cx,
35 const char16_t* chars,
36 size_t length,
37 RegExpFlags flags);
39 extern JS_PUBLIC_API bool SetRegExpInput(JSContext* cx, Handle<JSObject*> obj,
40 Handle<JSString*> input);
42 extern JS_PUBLIC_API bool ClearRegExpStatics(JSContext* cx,
43 Handle<JSObject*> obj);
45 /**
46 * Execute a regexp on a given input, starting from |indexp|.
47 * Returns false on OOM or over-recursion.
49 * On no match, |rval| is set to Null.
50 * On a match, |indexp| and the RegExp statics are updated.
51 * Then, if |test| is true, |rval| is set to true.
52 * Otherwise, |rval| is set to a match result object.
54 extern JS_PUBLIC_API bool ExecuteRegExp(JSContext* cx, Handle<JSObject*> obj,
55 Handle<JSObject*> reobj,
56 const char16_t* chars, size_t length,
57 size_t* indexp, bool test,
58 MutableHandle<Value> rval);
60 /**
61 * Execute a regexp on a given input, starting from |indexp|.
62 * This is the same as ExecuteRegExp, except it does not update the RegExp
63 * statics and can be called without a global object.
65 extern JS_PUBLIC_API bool ExecuteRegExpNoStatics(
66 JSContext* cx, Handle<JSObject*> reobj, const char16_t* chars,
67 size_t length, size_t* indexp, bool test, MutableHandle<Value> rval);
69 /**
70 * On success, returns true, setting |*isRegExp| to true if |obj| is a RegExp
71 * object or a wrapper around one, or to false if not. Returns false on
72 * failure.
74 * This method returns true with |*isRegExp == false| when passed an ES6 proxy
75 * whose target is a RegExp, or when passed a revoked proxy.
77 extern JS_PUBLIC_API bool ObjectIsRegExp(JSContext* cx, Handle<JSObject*> obj,
78 bool* isRegExp);
80 /**
81 * Given a RegExp object (or a wrapper around one), return the set of all
82 * JS::RegExpFlag::* for it.
84 extern JS_PUBLIC_API RegExpFlags GetRegExpFlags(JSContext* cx,
85 Handle<JSObject*> obj);
87 /**
88 * Return the source text for a RegExp object (or a wrapper around one), or null
89 * on failure.
91 extern JS_PUBLIC_API JSString* GetRegExpSource(JSContext* cx,
92 Handle<JSObject*> obj);
93 /**
94 * Check whether the given source is a valid regexp. If the regexp parses
95 * successfully, returns true and sets |error| to undefined. If the regexp
96 * has a syntax error, returns true, sets |error| to that error object, and
97 * clears the exception. Returns false on OOM or over-recursion.
99 extern JS_PUBLIC_API bool CheckRegExpSyntax(JSContext* cx,
100 const char16_t* chars,
101 size_t length, RegExpFlags flags,
102 MutableHandle<Value> error);
104 } // namespace JS
106 #endif // js_RegExp_h