[regexp] SpiderMonkey embedding fixes

There are two changes in this patch.

1. We previously added `VerifyRegExpSyntax` in regexp-parser.h to support checking regexp syntax for early errors in SpiderMonkey. Now that V8 is also emitting early errors for regexps (bug v8:896), SpiderMonkey can use the same code as V8.

2. Bug v8:11069 used a std::unordered_map as a cache for range arrays. This is currently the only place in irregexp that can call non-placement new, which SpiderMonkey has a static analysis to detect. Converting this to a ZoneUnorderedMap solves the problem for us, and seems consistent with the rest of irregexp.

Bug: v8:13108
Change-Id: Icedafd7d30fd040760cb0676a7bef8d55853bb93
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3785444
Commit-Queue: Jakob Linke <jgruber@chromium.org>
Reviewed-by: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81988}
This commit is contained in:
Iain Ireland 2022-07-25 10:40:37 -07:00 committed by V8 LUCI CQ
parent a691632c81
commit 6beb0cf4cf
3 changed files with 2 additions and 16 deletions

View File

@ -291,7 +291,7 @@ class NativeRegExpMacroAssembler: public RegExpMacroAssembler {
};
NativeRegExpMacroAssembler(Isolate* isolate, Zone* zone)
: RegExpMacroAssembler(isolate, zone) {}
: RegExpMacroAssembler(isolate, zone), range_array_cache_(zone) {}
~NativeRegExpMacroAssembler() override = default;
// Returns a {Result} sentinel, or the number of successful matches.
@ -349,7 +349,7 @@ class NativeRegExpMacroAssembler: public RegExpMacroAssembler {
const byte* input_end, int* output, int output_size,
Isolate* isolate, JSRegExp regexp);
std::unordered_map<uint32_t, Handle<ByteArray>> range_array_cache_;
ZoneUnorderedMap<uint32_t, Handle<ByteArray>> range_array_cache_;
};
} // namespace internal

View File

@ -2367,14 +2367,6 @@ template bool RegExpParser::VerifyRegExpSyntax<base::uc16>(
Zone*, uintptr_t, const base::uc16*, int, RegExpFlags, RegExpCompileData*,
const DisallowGarbageCollection&);
// static
bool RegExpParser::VerifyRegExpSyntax(Isolate* isolate, Zone* zone,
Handle<String> input, RegExpFlags flags,
RegExpCompileData* result,
const DisallowGarbageCollection&) {
return ParseRegExpFromHeapString(isolate, zone, input, flags, result);
}
#undef LAST
} // namespace internal

View File

@ -28,12 +28,6 @@ class V8_EXPORT_PRIVATE RegExpParser : public AllStatic {
const CharT* input, int input_length,
RegExpFlags flags, RegExpCompileData* result,
const DisallowGarbageCollection& no_gc);
// Used by the SpiderMonkey embedding of irregexp.
static bool VerifyRegExpSyntax(Isolate* isolate, Zone* zone,
Handle<String> input, RegExpFlags flags,
RegExpCompileData* result,
const DisallowGarbageCollection& no_gc);
};
} // namespace internal