re2 1.21.0 → 1.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -8
  3. package/binding.gyp +13 -4
  4. package/lib/accessors.cc +29 -1
  5. package/lib/addon.cc +35 -9
  6. package/lib/exec.cc +1 -1
  7. package/lib/match.cc +1 -1
  8. package/lib/new.cc +6 -1
  9. package/lib/replace.cc +1 -1
  10. package/lib/search.cc +1 -1
  11. package/lib/split.cc +1 -1
  12. package/lib/str-val.h +1 -0
  13. package/lib/test.cc +1 -1
  14. package/lib/to_string.cc +4 -0
  15. package/lib/wrapped_re2.h +33 -4
  16. package/package.json +2 -2
  17. package/re2.js +1 -1
  18. package/vendor/re2/.github/workflows/ci-bazel.yml +2 -2
  19. package/vendor/re2/.github/workflows/ci-cmake.yml +8 -14
  20. package/vendor/re2/.github/workflows/ci.yml +12 -9
  21. package/vendor/re2/.github/workflows/pages.yml +3 -3
  22. package/vendor/re2/.github/workflows/pr.yml +1 -1
  23. package/vendor/re2/.github/workflows/python.yml +7 -7
  24. package/vendor/re2/.github/workflows/release.yml +1 -1
  25. package/vendor/re2/BUILD.bazel +37 -2
  26. package/vendor/re2/CMakeLists.txt +6 -1
  27. package/vendor/re2/MODULE.bazel +3 -3
  28. package/vendor/re2/Makefile +5 -3
  29. package/vendor/re2/python/_re2.cc +9 -2
  30. package/vendor/re2/python/setup.py +1 -1
  31. package/vendor/re2/re2/bitmap256.cc +4 -4
  32. package/vendor/re2/re2/bitmap256.h +11 -9
  33. package/vendor/re2/re2/bitstate.cc +9 -6
  34. package/vendor/re2/re2/compile.cc +14 -11
  35. package/vendor/re2/re2/dfa.cc +26 -22
  36. package/vendor/re2/re2/filtered_re2.cc +8 -5
  37. package/vendor/re2/re2/fuzzing/re2_fuzzer.cc +2 -0
  38. package/vendor/re2/re2/mimics_pcre.cc +3 -3
  39. package/vendor/re2/re2/nfa.cc +21 -17
  40. package/vendor/re2/re2/onepass.cc +17 -15
  41. package/vendor/re2/re2/parse.cc +14 -13
  42. package/vendor/re2/re2/prefilter.cc +15 -13
  43. package/vendor/re2/re2/prefilter.h +3 -2
  44. package/vendor/re2/re2/prefilter_tree.cc +18 -18
  45. package/vendor/re2/re2/prefilter_tree.h +5 -4
  46. package/vendor/re2/re2/prog.cc +39 -31
  47. package/vendor/re2/re2/prog.h +42 -16
  48. package/vendor/re2/re2/re2.cc +56 -51
  49. package/vendor/re2/re2/re2.h +23 -27
  50. package/vendor/re2/re2/regexp.cc +13 -11
  51. package/vendor/re2/re2/regexp.h +40 -11
  52. package/vendor/re2/re2/set.cc +15 -10
  53. package/vendor/re2/re2/simplify.cc +13 -9
  54. package/vendor/re2/re2/sparse_array.h +9 -7
  55. package/vendor/re2/re2/sparse_set.h +9 -7
  56. package/vendor/re2/re2/testing/backtrack.cc +8 -6
  57. package/vendor/re2/re2/testing/charclass_test.cc +1 -1
  58. package/vendor/re2/re2/testing/compile_test.cc +10 -7
  59. package/vendor/re2/re2/testing/dfa_test.cc +15 -12
  60. package/vendor/re2/re2/testing/dump.cc +5 -4
  61. package/vendor/re2/re2/testing/exhaustive1_test.cc +1 -0
  62. package/vendor/re2/re2/testing/exhaustive2_test.cc +2 -2
  63. package/vendor/re2/re2/testing/exhaustive3_test.cc +3 -3
  64. package/vendor/re2/re2/testing/exhaustive_test.cc +0 -1
  65. package/vendor/re2/re2/testing/exhaustive_tester.cc +14 -5
  66. package/vendor/re2/re2/testing/exhaustive_tester.h +1 -0
  67. package/vendor/re2/re2/testing/filtered_re2_test.cc +12 -11
  68. package/vendor/re2/re2/testing/mimics_pcre_test.cc +2 -1
  69. package/vendor/re2/re2/testing/null_walker.cc +2 -3
  70. package/vendor/re2/re2/testing/parse_test.cc +4 -2
  71. package/vendor/re2/re2/testing/possible_match_test.cc +9 -6
  72. package/vendor/re2/re2/testing/random_test.cc +1 -1
  73. package/vendor/re2/re2/testing/re2_arg_test.cc +4 -5
  74. package/vendor/re2/re2/testing/re2_test.cc +13 -9
  75. package/vendor/re2/re2/testing/regexp_benchmark.cc +189 -153
  76. package/vendor/re2/re2/testing/regexp_generator.cc +11 -7
  77. package/vendor/re2/re2/testing/regexp_generator.h +1 -0
  78. package/vendor/re2/re2/testing/regexp_test.cc +3 -2
  79. package/vendor/re2/re2/testing/required_prefix_test.cc +2 -1
  80. package/vendor/re2/re2/testing/search_test.cc +6 -3
  81. package/vendor/re2/re2/testing/set_test.cc +4 -4
  82. package/vendor/re2/re2/testing/simplify_test.cc +2 -3
  83. package/vendor/re2/re2/testing/string_generator.cc +11 -8
  84. package/vendor/re2/re2/testing/string_generator.h +1 -0
  85. package/vendor/re2/re2/testing/string_generator_test.cc +6 -2
  86. package/vendor/re2/re2/testing/tester.cc +46 -40
  87. package/vendor/re2/re2/testing/tester.h +1 -1
  88. package/vendor/re2/re2/tostring.cc +5 -4
  89. package/vendor/re2/re2/walker-inl.h +4 -3
  90. package/vendor/re2/util/pcre.cc +3 -2
  91. package/vendor/re2/util/pcre.h +16 -16
  92. package/vendor/re2/util/logging.h +0 -109
package/LICENSE CHANGED
@@ -7,7 +7,7 @@ The text of the BSD license is reproduced below.
7
7
  The "New" BSD License:
8
8
  **********************
9
9
 
10
- Copyright (c) 2005-2020, Eugene Lazutkin
10
+ Copyright (c) 2005-2024, Eugene Lazutkin
11
11
  All rights reserved.
12
12
 
13
13
  Redistribution and use in source and binary forms, with or without
package/README.md CHANGED
@@ -353,6 +353,7 @@ console.log('re2_res : ' + re2_res); // prints: re2_res : abc,a,b,c
353
353
 
354
354
  ## Release history
355
355
 
356
+ - 1.21.1 *Fixed a memory regression reported by [matthewvalentine](https://github.com/matthewvalentine), thx! Updated deps.*
356
357
  - 1.21.0 *Fixed the performance problem reported by [matthewvalentine](https://github.com/matthewvalentine) (thx!). The change improves performance for multiple use cases.*
357
358
  - 1.20.12 *Updated deps. Maintenance chores. Fixes for buffer-related bugs: `exec()` index (reported by [matthewvalentine](https://github.com/matthewvalentine), thx) and `match()` index.*
358
359
  - 1.20.11 *Updated deps. Added support for Node 22 (thx, [Elton Leong](https://github.com/eltonkl)).*
@@ -367,16 +368,9 @@ console.log('re2_res : ' + re2_res); // prints: re2_res : abc,a,b,c
367
368
  - 1.20.2 *Fix: added a missing C++ file, which caused a bug on Alpine Linux. Thx, [rbitanga-manticore](https://github.com/rbitanga-manticore).*
368
369
  - 1.20.1 *Fix: files included in the npm package to build the C++ code.*
369
370
  - 1.20.0 *Updated RE2. New version uses `abseil-cpp` and required the adaptation work. Thx, [Stefano Rivera](https://github.com/stefanor).*
370
- - 1.19.2 *Bugfix: infinite loop in matchAll() with empty matches. Thx, [ziyunfei](https://github.com/ziyunfei).*
371
- - 1.19.1 *Bugfix: indices for the `d` flag when `lastIndex` is non zero. Bugfix: the match result. Thx, [teebu](https://github.com/teebu).*
372
- - 1.19.0 *Added `hasIndices` AKA the `d` flag. Thx, [teebu](https://github.com/teebu).*
373
- - 1.18.3 *Fixed bug with non-matched groups. Thx, [Dan Setterquist](https://github.com/dset).*
374
- - 1.18.2 *Reference to the binary module by its full name.*
375
- - 1.18.1 *Support for Node 16, 18, 20 + Darwin arm64 precompiled binaries.*
376
- - 1.18.0 *Modified TS bindings, added a type test (thx, [Kenichi Kamiya](https://github.com/kachick) and [Jamie Magee](https://github.com/JamieMagee)).*
377
371
 
378
372
  The rest can be consulted in the project's wiki [Release history](https://github.com/uhop/node-re2/wiki/Release-history).
379
373
 
380
374
  ## License
381
375
 
382
- BSD
376
+ BSD-3-Clause
package/binding.gyp CHANGED
@@ -3,8 +3,10 @@
3
3
  {
4
4
  "target_name": "re2",
5
5
  "sources": [
6
- "lib/str-val.cc",
7
6
  "lib/addon.cc",
7
+ "lib/accessors.cc",
8
+ "lib/str-val.cc",
9
+ "lib/util.cc",
8
10
  "lib/new.cc",
9
11
  "lib/exec.cc",
10
12
  "lib/test.cc",
@@ -13,9 +15,6 @@
13
15
  "lib/search.cc",
14
16
  "lib/split.cc",
15
17
  "lib/to_string.cc",
16
- "lib/accessors.cc",
17
- "lib/util.cc",
18
- "lib/str-val.cc",
19
18
  "vendor/re2/re2/bitmap256.cc",
20
19
  "vendor/re2/re2/bitstate.cc",
21
20
  "vendor/re2/re2/compile.cc",
@@ -44,6 +43,7 @@
44
43
  "vendor/abseil-cpp/absl/base/internal/raw_logging.cc",
45
44
  "vendor/abseil-cpp/absl/base/internal/spinlock.cc",
46
45
  "vendor/abseil-cpp/absl/base/internal/spinlock_wait.cc",
46
+ "vendor/abseil-cpp/absl/base/internal/strerror.cc",
47
47
  "vendor/abseil-cpp/absl/base/internal/sysinfo.cc",
48
48
  "vendor/abseil-cpp/absl/base/internal/thread_identity.cc",
49
49
  "vendor/abseil-cpp/absl/base/internal/throw_delegate.cc",
@@ -52,6 +52,7 @@
52
52
  "vendor/abseil-cpp/absl/container/internal/raw_hash_set.cc",
53
53
  "vendor/abseil-cpp/absl/debugging/internal/address_is_readable.cc",
54
54
  "vendor/abseil-cpp/absl/debugging/internal/elf_mem_image.cc",
55
+ "vendor/abseil-cpp/absl/debugging/internal/examine_stack.cc",
55
56
  "vendor/abseil-cpp/absl/debugging/internal/vdso_support.cc",
56
57
  "vendor/abseil-cpp/absl/debugging/stacktrace.cc",
57
58
  "vendor/abseil-cpp/absl/debugging/symbolize.cc",
@@ -66,6 +67,14 @@
66
67
  "vendor/abseil-cpp/absl/hash/internal/city.cc",
67
68
  "vendor/abseil-cpp/absl/hash/internal/hash.cc",
68
69
  "vendor/abseil-cpp/absl/hash/internal/low_level_hash.cc",
70
+ "vendor/abseil-cpp/absl/log/internal/globals.cc",
71
+ "vendor/abseil-cpp/absl/log/internal/log_format.cc",
72
+ "vendor/abseil-cpp/absl/log/internal/log_message.cc",
73
+ "vendor/abseil-cpp/absl/log/internal/log_sink_set.cc",
74
+ "vendor/abseil-cpp/absl/log/internal/nullguard.cc",
75
+ "vendor/abseil-cpp/absl/log/internal/proto.cc",
76
+ "vendor/abseil-cpp/absl/log/globals.cc",
77
+ "vendor/abseil-cpp/absl/log/log_sink.cc",
69
78
  "vendor/abseil-cpp/absl/numeric/int128.cc",
70
79
  "vendor/abseil-cpp/absl/strings/ascii.cc",
71
80
  "vendor/abseil-cpp/absl/strings/charconv.cc",
package/lib/accessors.cc CHANGED
@@ -28,6 +28,30 @@ NAN_GETTER(WrappedRE2::GetInternalSource)
28
28
  info.GetReturnValue().Set(Nan::New(re2->regexp.pattern()).ToLocalChecked());
29
29
  }
30
30
 
31
+ NAN_GETTER(WrappedRE2::GetEnabledCache)
32
+ {
33
+ if (!WrappedRE2::HasInstance(info.This()))
34
+ {
35
+ info.GetReturnValue().SetUndefined();
36
+ return;
37
+ }
38
+
39
+ auto re2 = Nan::ObjectWrap::Unwrap<WrappedRE2>(info.This());
40
+ info.GetReturnValue().Set(re2->enabledCache);
41
+ }
42
+
43
+ NAN_GETTER(WrappedRE2::GetIsCached)
44
+ {
45
+ if (!WrappedRE2::HasInstance(info.This()))
46
+ {
47
+ info.GetReturnValue().SetUndefined();
48
+ return;
49
+ }
50
+
51
+ auto re2 = Nan::ObjectWrap::Unwrap<WrappedRE2>(info.This());
52
+ info.GetReturnValue().Set(!!re2->lastStringValue);
53
+ }
54
+
31
55
  NAN_GETTER(WrappedRE2::GetFlags)
32
56
  {
33
57
  if (!WrappedRE2::HasInstance(info.This()))
@@ -39,9 +63,13 @@ NAN_GETTER(WrappedRE2::GetFlags)
39
63
  auto re2 = Nan::ObjectWrap::Unwrap<WrappedRE2>(info.This());
40
64
 
41
65
  std::string flags;
66
+ if (re2->enabledCache)
67
+ {
68
+ flags += "\b";
69
+ }
42
70
  if (re2->hasIndices)
43
71
  {
44
- flags = "d";
72
+ flags += "d";
45
73
  }
46
74
  if (re2->global)
47
75
  {
package/lib/addon.cc CHANGED
@@ -74,6 +74,8 @@ v8::Local<v8::Function> WrappedRE2::Init()
74
74
  Nan::SetAccessor(instanceTemplate, Nan::New("hasIndices").ToLocalChecked(), GetHasIndices);
75
75
  Nan::SetAccessor(instanceTemplate, Nan::New("lastIndex").ToLocalChecked(), GetLastIndex, SetLastIndex);
76
76
  Nan::SetAccessor(instanceTemplate, Nan::New("internalSource").ToLocalChecked(), GetInternalSource);
77
+ Nan::SetAccessor(instanceTemplate, Nan::New("enabledCache").ToLocalChecked(), GetEnabledCache);
78
+ Nan::SetAccessor(instanceTemplate, Nan::New("isCached").ToLocalChecked(), GetIsCached);
77
79
 
78
80
  auto ctr = Nan::GetFunction(tpl).ToLocalChecked();
79
81
 
@@ -92,8 +94,29 @@ NODE_MODULE_INIT()
92
94
  Nan::Set(module->ToObject(context).ToLocalChecked(), Nan::New("exports").ToLocalChecked(), WrappedRE2::Init());
93
95
  }
94
96
 
97
+ WrappedRE2::~WrappedRE2()
98
+ {
99
+ for (auto ptr : callbackRegistry)
100
+ {
101
+ *ptr = nullptr;
102
+ }
103
+ dropLastString();
104
+ }
105
+
95
106
  // private methods
96
107
 
108
+ WrappedRE2::PtrWrappedRE2 *WrappedRE2::registerCallback()
109
+ {
110
+ PtrWrappedRE2 *ptr = new PtrWrappedRE2(this);
111
+ callbackRegistry.insert(ptr);
112
+ return ptr;
113
+ }
114
+
115
+ void WrappedRE2::unregisterCallback(PtrWrappedRE2 *ptr)
116
+ {
117
+ callbackRegistry.erase(ptr);
118
+ }
119
+
97
120
  void WrappedRE2::dropLastString()
98
121
  {
99
122
  lastString.Reset();
@@ -104,17 +127,15 @@ void WrappedRE2::dropLastString()
104
127
  }
105
128
  }
106
129
 
107
- inline size_t countBytes(const char *data, size_t from, size_t n)
130
+ void WrappedRE2::weakLastStringCallback(const Nan::WeakCallbackInfo<PtrWrappedRE2> &data)
108
131
  {
109
- for (; n > 0; --n)
132
+ PtrWrappedRE2 *re2 = data.GetParameter();
133
+ if (*re2)
110
134
  {
111
- size_t s = getUtf8CharSize(data[from]);
112
- from += s;
113
- if (s == 4 && n >= 2)
114
- --n; // this utf8 character will take two utf16 characters
115
- // the decrement above is protected to avoid an overflow of an unsigned integer
135
+ (*re2)->unregisterCallback(re2);
136
+ (*re2)->dropLastString();
116
137
  }
117
- return from;
138
+ delete re2;
118
139
  }
119
140
 
120
141
  void WrappedRE2::prepareLastString(const v8::Local<v8::Value> &arg, bool ignoreLastIndex)
@@ -140,7 +161,12 @@ void WrappedRE2::prepareLastString(const v8::Local<v8::Value> &arg, bool ignoreL
140
161
  }
141
162
 
142
163
  dropLastString();
164
+
143
165
  lastString.Reset(arg);
144
- static_cast<v8::PersistentBase<v8::Value>&>(lastString).SetWeak();
166
+ static_cast<v8::PersistentBase<v8::Value> &>(lastString).SetWeak();
167
+
168
+ Nan::Persistent<v8::Value> dummy(arg);
169
+ dummy.SetWeak(registerCallback(), weakLastStringCallback, Nan::WeakCallbackType::kParameter);
170
+
145
171
  lastStringValue = new StrValString(arg, startFrom);
146
172
  };
package/lib/exec.cc CHANGED
@@ -15,7 +15,7 @@ NAN_METHOD(WrappedRE2::Exec)
15
15
  return;
16
16
  }
17
17
 
18
- re2->prepareLastString(info[0]);
18
+ PrepareLastString prepare(re2, info[0]);
19
19
  StrValBase &str = *re2->lastStringValue;
20
20
  if (str.isBad) return; // throws an exception
21
21
 
package/lib/match.cc CHANGED
@@ -15,7 +15,7 @@ NAN_METHOD(WrappedRE2::Match)
15
15
  return;
16
16
  }
17
17
 
18
- re2->prepareLastString(info[0], re2->global);
18
+ PrepareLastString prepare(re2, info[0], re2->global);
19
19
  StrValBase &str = *re2->lastStringValue;
20
20
  if (str.isBad) return; // throws an exception
21
21
 
package/lib/new.cc CHANGED
@@ -233,6 +233,7 @@ NAN_METHOD(WrappedRE2::New)
233
233
  bool unicode = false;
234
234
  bool sticky = false;
235
235
  bool hasIndices = false;
236
+ bool enabledCache = false;
236
237
 
237
238
  auto context = Nan::GetCurrentContext();
238
239
  bool needFlags = true;
@@ -256,6 +257,9 @@ NAN_METHOD(WrappedRE2::New)
256
257
  {
257
258
  switch (data[i])
258
259
  {
260
+ case '\b':
261
+ enabledCache = true;
262
+ break;
259
263
  case 'g':
260
264
  global = true;
261
265
  break;
@@ -339,6 +343,7 @@ NAN_METHOD(WrappedRE2::New)
339
343
 
340
344
  if (needFlags)
341
345
  {
346
+ enabledCache = re2->enabledCache;
342
347
  global = re2->global;
343
348
  ignoreCase = re2->ignoreCase;
344
349
  multiline = re2->multiline;
@@ -401,7 +406,7 @@ NAN_METHOD(WrappedRE2::New)
401
406
  options.set_dot_nl(dotAll);
402
407
  options.set_log_errors(false); // inappropriate when embedding
403
408
 
404
- std::unique_ptr<WrappedRE2> re2(new WrappedRE2(re2::StringPiece(data, size), options, source, global, ignoreCase, multiline, dotAll, sticky, hasIndices));
409
+ std::unique_ptr<WrappedRE2> re2(new WrappedRE2(re2::StringPiece(data, size), options, source, enabledCache, global, ignoreCase, multiline, dotAll, sticky, hasIndices));
405
410
  if (!re2->regexp.ok())
406
411
  {
407
412
  return Nan::ThrowSyntaxError(re2->regexp.error().c_str());
package/lib/replace.cc CHANGED
@@ -492,7 +492,7 @@ NAN_METHOD(WrappedRE2::Replace)
492
492
  return;
493
493
  }
494
494
 
495
- re2->prepareLastString(info[0]);
495
+ PrepareLastString prepare(re2, info[0]);
496
496
  StrValBase &replacee = *re2->lastStringValue;
497
497
  if (replacee.isBad) return; // throws an exception
498
498
 
package/lib/search.cc CHANGED
@@ -13,7 +13,7 @@ NAN_METHOD(WrappedRE2::Search)
13
13
  return;
14
14
  }
15
15
 
16
- re2->prepareLastString(info[0], true);
16
+ PrepareLastString prepare(re2, info[0], true);
17
17
  StrValBase &str = *re2->lastStringValue;
18
18
  if (str.isBad) return; // throws an exception
19
19
 
package/lib/split.cc CHANGED
@@ -20,7 +20,7 @@ NAN_METHOD(WrappedRE2::Split)
20
20
  return;
21
21
  }
22
22
 
23
- re2->prepareLastString(info[0], true);
23
+ PrepareLastString prepare(re2, info[0], true);
24
24
  StrValBase &str = *re2->lastStringValue;
25
25
  if (str.isBad) return; // throws an exception
26
26
 
package/lib/str-val.h CHANGED
@@ -11,6 +11,7 @@ struct StrValBase
11
11
  bool isBuffer, isIndexValid, isBad;
12
12
 
13
13
  StrValBase() : data(NULL), size(0), length(0), index(0), byteIndex(0), isBuffer(false), isIndexValid(false), isBad(false) {}
14
+ virtual ~StrValBase() {}
14
15
 
15
16
  operator re2::StringPiece() const { return re2::StringPiece(data, size); }
16
17
 
package/lib/test.cc CHANGED
@@ -15,7 +15,7 @@ NAN_METHOD(WrappedRE2::Test)
15
15
  return;
16
16
  }
17
17
 
18
- re2->prepareLastString(info[0]);
18
+ PrepareLastString prepare(re2, info[0]);
19
19
  StrValBase &str = *re2->lastStringValue;
20
20
  if (str.isBad) return; // throws an exception
21
21
 
package/lib/to_string.cc CHANGED
@@ -20,6 +20,10 @@ NAN_METHOD(WrappedRE2::ToString)
20
20
  buffer += re2->source;
21
21
  buffer += "/";
22
22
 
23
+ if (re2->enabledCache)
24
+ {
25
+ buffer += "\b";
26
+ }
23
27
  if (re2->global)
24
28
  {
25
29
  buffer += "g";
package/lib/wrapped_re2.h CHANGED
@@ -6,6 +6,7 @@
6
6
  #include <re2/re2.h>
7
7
 
8
8
  #include <string>
9
+ #include <unordered_set>
9
10
 
10
11
  struct StrValBase;
11
12
 
@@ -16,6 +17,7 @@ private:
16
17
  const re2::StringPiece &pattern,
17
18
  const re2::RE2::Options &options,
18
19
  const std::string &src,
20
+ const bool &c,
19
21
  const bool &g,
20
22
  const bool &i,
21
23
  const bool &m,
@@ -23,6 +25,7 @@ private:
23
25
  const bool &y,
24
26
  const bool &d) : regexp(pattern, options),
25
27
  source(src),
28
+ enabledCache(c),
26
29
  global(g),
27
30
  ignoreCase(i),
28
31
  multiline(m),
@@ -47,6 +50,8 @@ private:
47
50
  static NAN_GETTER(GetLastIndex);
48
51
  static NAN_SETTER(SetLastIndex);
49
52
  static NAN_GETTER(GetInternalSource);
53
+ static NAN_GETTER(GetEnabledCache);
54
+ static NAN_GETTER(GetIsCached);
50
55
 
51
56
  // RegExp methods
52
57
  static NAN_METHOD(Exec);
@@ -63,10 +68,7 @@ private:
63
68
  static NAN_SETTER(SetUnicodeWarningLevel);
64
69
 
65
70
  public:
66
- ~WrappedRE2()
67
- {
68
- dropLastString();
69
- }
71
+ ~WrappedRE2();
70
72
 
71
73
  static v8::Local<v8::Function> Init();
72
74
 
@@ -89,6 +91,7 @@ public:
89
91
 
90
92
  re2::RE2 regexp;
91
93
  std::string source;
94
+ bool enabledCache;
92
95
  bool global;
93
96
  bool ignoreCase;
94
97
  bool multiline;
@@ -97,14 +100,40 @@ public:
97
100
  bool hasIndices;
98
101
  size_t lastIndex;
99
102
 
103
+ friend class PrepareLastString;
104
+
100
105
  private:
101
106
  Nan::Persistent<v8::Value> lastString; // weak pointer
102
107
  StrValBase *lastStringValue;
103
108
 
109
+ typedef WrappedRE2 *PtrWrappedRE2;
110
+
111
+ std::unordered_set<PtrWrappedRE2 *> callbackRegistry;
112
+ PtrWrappedRE2 *registerCallback();
113
+ void unregisterCallback(PtrWrappedRE2 *re2);
114
+
115
+ static void weakLastStringCallback(const Nan::WeakCallbackInfo<PtrWrappedRE2> &data);
116
+
104
117
  void dropLastString();
105
118
  void prepareLastString(const v8::Local<v8::Value> &arg, bool ignoreLastIndex = false);
106
119
  };
107
120
 
121
+ struct PrepareLastString
122
+ {
123
+ PrepareLastString(WrappedRE2 *re2, const v8::Local<v8::Value> &arg, bool ignoreLastIndex = false) : re2(re2)
124
+ {
125
+ re2->prepareLastString(arg, ignoreLastIndex);
126
+ }
127
+
128
+ ~PrepareLastString()
129
+ {
130
+ if (!re2->enabledCache || !(re2->global || re2->sticky))
131
+ re2->dropLastString();
132
+ }
133
+
134
+ WrappedRE2 *re2;
135
+ };
136
+
108
137
  // utilities
109
138
 
110
139
  inline size_t getUtf8Length(const uint16_t *from, const uint16_t *to)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "re2",
3
- "version": "1.21.0",
3
+ "version": "1.21.1",
4
4
  "description": "Bindings for RE2: fast, safe alternative to backtracking regular expression engines.",
5
5
  "homepage": "https://github.com/uhop/node-re2",
6
6
  "bugs": "https://github.com/uhop/node-re2/issues",
@@ -20,7 +20,7 @@
20
20
  "node-gyp": "^10.1.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/node": "^20.12.12",
23
+ "@types/node": "^20.14.2",
24
24
  "heya-unit": "^0.3.0",
25
25
  "typescript": "^5.4.5"
26
26
  },
package/re2.js CHANGED
@@ -24,7 +24,7 @@ if (typeof Symbol != 'undefined') {
24
24
  if (!this.global) {
25
25
  throw TypeError('String.prototype.matchAll called with a non-global RE2 argument');
26
26
  }
27
- const re = new RE2(this);
27
+ const re = new RE2(this, this.flags + '\b');
28
28
  re.lastIndex = this.lastIndex;
29
29
  for (;;) {
30
30
  const result = re.exec(str);
@@ -14,8 +14,8 @@ jobs:
14
14
  env:
15
15
  BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16
16
  steps:
17
- - uses: actions/checkout@v4.1.4
18
- - uses: bazel-contrib/setup-bazel@0.8.2
17
+ - uses: actions/checkout@v4.1.6
18
+ - uses: bazel-contrib/setup-bazel@0.8.4
19
19
  with:
20
20
  bazelisk-version: '1.x'
21
21
  - run: .github/bazel.sh
@@ -7,26 +7,20 @@ permissions:
7
7
  jobs:
8
8
  build-linux:
9
9
  runs-on: ubuntu-latest
10
- # The Benchmark package on Ubuntu 22.04 LTS is problematic whereas this
11
- # Docker container is based on Debian bookworm and has a newer version.
12
- container: gcc:13
13
10
  strategy:
14
11
  fail-fast: false
15
12
  matrix:
16
13
  build_shared_libs: [OFF, ON]
17
14
  steps:
18
- - uses: actions/checkout@v4.1.4
19
- - name: Install CMake
20
- run: |
21
- apt update -y
22
- apt install -y cmake
23
- shell: bash
15
+ - uses: actions/checkout@v4.1.6
24
16
  - name: Install Abseil, GoogleTest and Benchmark
25
17
  run: |
26
- apt update -y
27
- apt install -y libabsl-dev libgtest-dev libbenchmark-dev
18
+ vcpkg update
19
+ vcpkg install abseil gtest benchmark
28
20
  shell: bash
29
- - run: .github/cmake.sh -D BUILD_SHARED_LIBS=${{ matrix.build_shared_libs }}
21
+ - run: |
22
+ .github/cmake.sh -D BUILD_SHARED_LIBS=${{ matrix.build_shared_libs }} \
23
+ -D CMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake
30
24
  shell: bash
31
25
  build-macos:
32
26
  runs-on: macos-latest
@@ -35,7 +29,7 @@ jobs:
35
29
  matrix:
36
30
  build_shared_libs: [OFF, ON]
37
31
  steps:
38
- - uses: actions/checkout@v4.1.4
32
+ - uses: actions/checkout@v4.1.6
39
33
  - name: Install Abseil, GoogleTest and Benchmark
40
34
  run: |
41
35
  brew update
@@ -50,7 +44,7 @@ jobs:
50
44
  matrix:
51
45
  build_shared_libs: [OFF, ON]
52
46
  steps:
53
- - uses: actions/checkout@v4.1.4
47
+ - uses: actions/checkout@v4.1.6
54
48
  - name: Install Abseil, GoogleTest and Benchmark
55
49
  run: |
56
50
  vcpkg update
@@ -21,7 +21,7 @@ jobs:
21
21
  # (The other two flags are the default provided for CXXFLAGS in Makefile.)
22
22
  CXXFLAGS: -O3 -g -std=c++${{ matrix.ver }}
23
23
  steps:
24
- - uses: actions/checkout@v4.1.4
24
+ - uses: actions/checkout@v4.1.6
25
25
  - name: Install Abseil, GoogleTest and Benchmark
26
26
  run: |
27
27
  brew update
@@ -38,8 +38,9 @@ jobs:
38
38
  env:
39
39
  CC: clang-${{ matrix.ver }}
40
40
  CXX: clang++-${{ matrix.ver }}
41
+ PKG_CONFIG_PATH: /usr/local/share/vcpkg/installed/x64-linux/lib/pkgconfig
41
42
  steps:
42
- - uses: actions/checkout@v4.1.4
43
+ - uses: actions/checkout@v4.1.6
43
44
  - name: Install Clang ${{ matrix.ver }}
44
45
  run: |
45
46
  # Avoid `Conflicts: python3-lldb-x.y` between packages.
@@ -50,26 +51,28 @@ jobs:
50
51
  shell: bash
51
52
  - name: Install Abseil, GoogleTest and Benchmark
52
53
  run: |
53
- sudo apt update -y
54
- sudo apt install -y libabsl-dev libgtest-dev libbenchmark-dev
54
+ vcpkg update
55
+ vcpkg install abseil gtest benchmark
55
56
  shell: bash
56
57
  - run: make && make test
57
58
  shell: bash
58
59
  build-gcc:
59
- runs-on: ubuntu-latest
60
+ # TODO(junyer): Switch back to `ubuntu-latest` when this becomes that.
61
+ runs-on: ubuntu-24.04
60
62
  strategy:
61
63
  fail-fast: false
62
64
  matrix:
63
- ver: [11, 12, 13]
65
+ ver: [12, 13, 14]
64
66
  env:
65
67
  CC: gcc-${{ matrix.ver }}
66
68
  CXX: g++-${{ matrix.ver }}
69
+ PKG_CONFIG_PATH: /usr/local/share/vcpkg/installed/x64-linux/lib/pkgconfig
67
70
  steps:
68
- - uses: actions/checkout@v4.1.4
71
+ - uses: actions/checkout@v4.1.6
69
72
  - name: Install Abseil, GoogleTest and Benchmark
70
73
  run: |
71
- sudo apt update -y
72
- sudo apt install -y libabsl-dev libgtest-dev libbenchmark-dev
74
+ vcpkg update
75
+ vcpkg install abseil gtest benchmark
73
76
  shell: bash
74
77
  - run: make && make test
75
78
  shell: bash
@@ -17,8 +17,8 @@ jobs:
17
17
  # Bazel fails if the username is unknown.
18
18
  USER: runner
19
19
  steps:
20
- - uses: actions/checkout@v4.1.4
21
- - uses: bazel-contrib/setup-bazel@0.8.2
20
+ - uses: actions/checkout@v4.1.6
21
+ - uses: bazel-contrib/setup-bazel@0.8.4
22
22
  with:
23
23
  bazelisk-version: '1.x'
24
24
  - run: app/build.sh
@@ -37,5 +37,5 @@ jobs:
37
37
  environment: github-pages
38
38
  runs-on: ubuntu-latest
39
39
  steps:
40
- - uses: actions/checkout@v4.1.4
40
+ - uses: actions/checkout@v4.1.6
41
41
  - uses: actions/deploy-pages@v4.0.5
@@ -15,7 +15,7 @@ jobs:
15
15
  pull-requests: write
16
16
  runs-on: ubuntu-latest
17
17
  steps:
18
- - uses: actions/checkout@v4.1.4
18
+ - uses: actions/checkout@v4.1.6
19
19
  - uses: actions/github-script@v7.0.1
20
20
  with:
21
21
  script: |
@@ -31,11 +31,11 @@ jobs:
31
31
  # Bazel fails if the username is unknown.
32
32
  USER: runner
33
33
  steps:
34
- - uses: actions/checkout@v4.1.4
34
+ - uses: actions/checkout@v4.1.6
35
35
  # Stash the timestamp for the commit SHA that triggered the workflow.
36
36
  - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
37
37
  shell: bash
38
- - uses: bazel-contrib/setup-bazel@0.8.2
38
+ - uses: bazel-contrib/setup-bazel@0.8.4
39
39
  with:
40
40
  bazelisk-version: '1.x'
41
41
  - name: Prepare Python ${{ matrix.ver }} environment
@@ -87,11 +87,11 @@ jobs:
87
87
  # Otherwise, Python refuses to install the built wheel!
88
88
  SYSTEM_VERSION_COMPAT: 0
89
89
  steps:
90
- - uses: actions/checkout@v4.1.4
90
+ - uses: actions/checkout@v4.1.6
91
91
  # Stash the timestamp for the commit SHA that triggered the workflow.
92
92
  - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
93
93
  shell: bash
94
- - uses: bazel-contrib/setup-bazel@0.8.2
94
+ - uses: bazel-contrib/setup-bazel@0.8.4
95
95
  with:
96
96
  bazelisk-version: '1.x'
97
97
  - uses: actions/setup-python@v5.1.0
@@ -138,11 +138,11 @@ jobs:
138
138
  BAZEL_CPU: ${{ matrix.arch.bazel-name }}_windows
139
139
  PLAT_NAME: ${{ matrix.arch.python-name }}
140
140
  steps:
141
- - uses: actions/checkout@v4.1.4
141
+ - uses: actions/checkout@v4.1.6
142
142
  # Stash the timestamp for the commit SHA that triggered the workflow.
143
143
  - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
144
144
  shell: bash
145
- - uses: bazel-contrib/setup-bazel@0.8.2
145
+ - uses: bazel-contrib/setup-bazel@0.8.4
146
146
  with:
147
147
  bazelisk-version: '1.x'
148
148
  # Lowercase the architecture name for `actions/setup-python`.
@@ -190,7 +190,7 @@ jobs:
190
190
  id-token: write
191
191
  runs-on: ubuntu-latest
192
192
  steps:
193
- - uses: actions/checkout@v4.1.4
193
+ - uses: actions/checkout@v4.1.6
194
194
  # Stash the timestamp for the commit SHA that triggered the workflow.
195
195
  - run: echo "timestamp=$(git log -1 --pretty=%ct)" >> "${GITHUB_ENV}"
196
196
  shell: bash
@@ -16,7 +16,7 @@ jobs:
16
16
  env:
17
17
  GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18
18
  steps:
19
- - uses: actions/checkout@v4.1.4
19
+ - uses: actions/checkout@v4.1.6
20
20
  - run: |
21
21
  gh release create "${GITHUB_REF_NAME}" \
22
22
  --generate-notes --latest --verify-tag \