From 6beb0cf4cf9b33d7a82275a53422903b8fcad5ca Mon Sep 17 00:00:00 2001 From: Iain Ireland Date: Mon, 25 Jul 2022 10:40:37 -0700 Subject: [PATCH] [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 Reviewed-by: Jakob Linke Cr-Commit-Position: refs/heads/main@{#81988} --- src/regexp/regexp-macro-assembler.h | 4 ++-- src/regexp/regexp-parser.cc | 8 -------- src/regexp/regexp-parser.h | 6 ------ 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/regexp/regexp-macro-assembler.h b/src/regexp/regexp-macro-assembler.h index 16a23414e1..c231d112f8 100644 --- a/src/regexp/regexp-macro-assembler.h +++ b/src/regexp/regexp-macro-assembler.h @@ -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> range_array_cache_; + ZoneUnorderedMap> range_array_cache_; }; } // namespace internal diff --git a/src/regexp/regexp-parser.cc b/src/regexp/regexp-parser.cc index 5d71527eba..f50a5ffd0a 100644 --- a/src/regexp/regexp-parser.cc +++ b/src/regexp/regexp-parser.cc @@ -2367,14 +2367,6 @@ template bool RegExpParser::VerifyRegExpSyntax( Zone*, uintptr_t, const base::uc16*, int, RegExpFlags, RegExpCompileData*, const DisallowGarbageCollection&); -// static -bool RegExpParser::VerifyRegExpSyntax(Isolate* isolate, Zone* zone, - Handle input, RegExpFlags flags, - RegExpCompileData* result, - const DisallowGarbageCollection&) { - return ParseRegExpFromHeapString(isolate, zone, input, flags, result); -} - #undef LAST } // namespace internal diff --git a/src/regexp/regexp-parser.h b/src/regexp/regexp-parser.h index 4fc6400297..d7ff611dcb 100644 --- a/src/regexp/regexp-parser.h +++ b/src/regexp/regexp-parser.h @@ -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 input, RegExpFlags flags, - RegExpCompileData* result, - const DisallowGarbageCollection& no_gc); }; } // namespace internal