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. */
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
;
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
,
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
,
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 extern JS_PUBLIC_API
bool ExecuteRegExp(JSContext
* cx
, Handle
<JSObject
*> obj
,
46 Handle
<JSObject
*> reobj
,
47 const char16_t
* chars
, size_t length
,
48 size_t* indexp
, bool test
,
49 MutableHandle
<Value
> rval
);
51 /* RegExp interface for clients without a global object. */
53 extern JS_PUBLIC_API
bool ExecuteRegExpNoStatics(
54 JSContext
* cx
, Handle
<JSObject
*> reobj
, const char16_t
* chars
,
55 size_t length
, size_t* indexp
, bool test
, MutableHandle
<Value
> rval
);
58 * On success, returns true, setting |*isRegExp| to true if |obj| is a RegExp
59 * object or a wrapper around one, or to false if not. Returns false on
62 * This method returns true with |*isRegExp == false| when passed an ES6 proxy
63 * whose target is a RegExp, or when passed a revoked proxy.
65 extern JS_PUBLIC_API
bool ObjectIsRegExp(JSContext
* cx
, Handle
<JSObject
*> obj
,
69 * Given a RegExp object (or a wrapper around one), return the set of all
70 * JS::RegExpFlag::* for it.
72 extern JS_PUBLIC_API RegExpFlags
GetRegExpFlags(JSContext
* cx
,
73 Handle
<JSObject
*> obj
);
76 * Return the source text for a RegExp object (or a wrapper around one), or null
79 extern JS_PUBLIC_API JSString
* GetRegExpSource(JSContext
* cx
,
80 Handle
<JSObject
*> obj
);
82 * Check whether the given source is a valid regexp. If the regexp parses
83 * successfully, returns true and sets |error| to undefined. If the regexp
84 * has a syntax error, returns true, sets |error| to that error object, and
85 * clears the exception. Returns false on OOM or over-recursion.
87 extern JS_PUBLIC_API
bool CheckRegExpSyntax(JSContext
* cx
,
88 const char16_t
* chars
,
89 size_t length
, RegExpFlags flags
,
90 MutableHandle
<Value
> error
);