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 /* Regular expression-related operations. */ 8 9 #ifndef js_RegExp_h 10 #define js_RegExp_h 11 12 #include <stddef.h> // size_t 13 14 #include "jstypes.h" // JS_PUBLIC_API 15 16 #include "js/RegExpFlags.h" // JS::RegExpFlags 17 #include "js/TypeDecls.h" 18 19 struct JS_PUBLIC_API JSContext; 20 class JS_PUBLIC_API JSString; 21 22 namespace JS { 23 24 /** 25 * Create a new RegExp for the given Latin-1-encoded bytes and flags. 26 */ 27 extern JS_PUBLIC_API JSObject* NewRegExpObject(JSContext* cx, const char* bytes, 28 size_t length, 29 RegExpFlags flags); 30 31 /** 32 * Create a new RegExp for the given source and flags. 33 */ 34 extern JS_PUBLIC_API JSObject* NewUCRegExpObject(JSContext* cx, 35 const char16_t* chars, 36 size_t length, 37 RegExpFlags flags); 38 39 extern JS_PUBLIC_API bool SetRegExpInput(JSContext* cx, Handle<JSObject*> obj, 40 Handle<JSString*> input); 41 42 extern JS_PUBLIC_API bool ClearRegExpStatics(JSContext* cx, 43 Handle<JSObject*> obj); 44 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); 50 51 /* RegExp interface for clients without a global object. */ 52 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); 56 57 /** 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 60 * failure. 61 * 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. 64 */ 65 extern JS_PUBLIC_API bool ObjectIsRegExp(JSContext* cx, Handle<JSObject*> obj, 66 bool* isRegExp); 67 68 /** 69 * Given a RegExp object (or a wrapper around one), return the set of all 70 * JS::RegExpFlag::* for it. 71 */ 72 extern JS_PUBLIC_API RegExpFlags GetRegExpFlags(JSContext* cx, 73 Handle<JSObject*> obj); 74 75 /** 76 * Return the source text for a RegExp object (or a wrapper around one), or null 77 * on failure. 78 */ 79 extern JS_PUBLIC_API JSString* GetRegExpSource(JSContext* cx, 80 Handle<JSObject*> obj); 81 /** 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. 86 */ 87 extern JS_PUBLIC_API bool CheckRegExpSyntax(JSContext* cx, 88 const char16_t* chars, 89 size_t length, RegExpFlags flags, 90 MutableHandle<Value> error); 91 92 } // namespace JS 93 94 #endif // js_RegExp_h 95