v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-regexp.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_REGEXP_H_
6#define INCLUDE_V8_REGEXP_H_
7
8#include "v8-local-handle.h" // NOLINT(build/include_directory)
9#include "v8-object.h" // NOLINT(build/include_directory)
10#include "v8config.h" // NOLINT(build/include_directory)
11
12namespace v8 {
13
14class Context;
15
16/**
17 * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
18 */
19class V8_EXPORT RegExp : public Object {
20 public:
21 /**
22 * Regular expression flag bits. They can be or'ed to enable a set
23 * of flags.
24 * The kLinear value ('l') is experimental and can only be used with
25 * --enable-experimental-regexp-engine. RegExps with kLinear flag are
26 * guaranteed to be executed in asymptotic linear time wrt. the length of
27 * the subject string.
28 */
29 enum Flags {
30 kNone = 0,
31 kGlobal = 1 << 0,
32 kIgnoreCase = 1 << 1,
33 kMultiline = 1 << 2,
34 kSticky = 1 << 3,
35 kUnicode = 1 << 4,
36 kDotAll = 1 << 5,
37 kLinear = 1 << 6,
38 kHasIndices = 1 << 7,
39 kUnicodeSets = 1 << 8,
40 };
41
42 static constexpr int kFlagCount = 9;
43
44 /**
45 * Creates a regular expression from the given pattern string and
46 * the flags bit field. May throw a JavaScript exception as
47 * described in ECMA-262, 15.10.4.1.
48 *
49 * For example,
50 * RegExp::New(v8::String::New("foo"),
51 * static_cast<RegExp::Flags>(kGlobal | kMultiline))
52 * is equivalent to evaluating "/foo/gm".
53 */
55 Local<String> pattern,
56 Flags flags);
57
58 /**
59 * Like New, but additionally specifies a backtrack limit. If the number of
60 * backtracks done in one Exec call hits the limit, a match failure is
61 * immediately returned.
62 */
64 Local<Context> context, Local<String> pattern, Flags flags,
65 uint32_t backtrack_limit);
66
67 /**
68 * Executes the current RegExp instance on the given subject string.
69 * Equivalent to RegExp.prototype.exec as described in
70 *
71 * https://tc39.es/ecma262/#sec-regexp.prototype.exec
72 *
73 * On success, an Array containing the matched strings is returned. On
74 * failure, returns Null.
75 *
76 * Note: modifies global context state, accessible e.g. through RegExp.input.
77 */
79 Local<String> subject);
80
81 /**
82 * Returns the value of the source property: a string representing
83 * the regular expression.
84 */
86
87 /**
88 * Returns the flags bit field.
89 */
90 Flags GetFlags() const;
91
92 V8_INLINE static RegExp* Cast(Value* value) {
93#ifdef V8_ENABLE_CHECKS
94 CheckCast(value);
95#endif
96 return static_cast<RegExp*>(value);
97 }
98
99 private:
100 static void CheckCast(Value* obj);
101};
102
103} // namespace v8
104
105#endif // INCLUDE_V8_REGEXP_H_
friend class Local
friend class MaybeLocal
V8_WARN_UNUSED_RESULT MaybeLocal< Object > Exec(Local< Context > context, Local< String > subject)
static V8_INLINE RegExp * Cast(Value *value)
Definition v8-regexp.h:92
Local< String > GetSource() const
static V8_WARN_UNUSED_RESULT MaybeLocal< RegExp > NewWithBacktrackLimit(Local< Context > context, Local< String > pattern, Flags flags, uint32_t backtrack_limit)
Flags GetFlags() const
static constexpr int kFlagCount
Definition v8-regexp.h:42
static V8_WARN_UNUSED_RESULT MaybeLocal< RegExp > New(Local< Context > context, Local< String > pattern, Flags flags)
#define V8_EXPORT
Definition v8config.h:860
#define V8_INLINE
Definition v8config.h:513
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:684