Commit e72ecf1e authored by Jakob Gruber's avatar Jakob Gruber Committed by V8 LUCI CQ

[regexp] Change the RegExpParser to operate on raw input arrays

.. instead of a FlatStringReader. This is in preparation for reusing
the regexp parser directly from the JS parser, which uses different
string types (AstRawString instead of heap Strings).

Drive-by: Hide parser internals in the .cc file.

Bug: v8:896
Change-Id: I06bd08f2ef5fd7a5e9812c123d88b89cacf5d864
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3101488
Commit-Queue: Patrick Thier <pthier@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarPatrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76365}
parent 53a527f6
......@@ -73,11 +73,10 @@ base::Optional<CompilationResult> CompileImpl(Isolate* isolate,
// Parse and compile the regexp source.
RegExpCompileData parse_result;
FlatStringReader reader(isolate, source);
DCHECK(!isolate->has_pending_exception());
bool parse_success =
RegExpParser::ParseRegExp(isolate, &zone, &reader, flags, &parse_result);
bool parse_success = RegExpParser::ParseRegExpFromHeapString(
isolate, &zone, source, flags, &parse_result);
if (!parse_success) {
// The pattern was already parsed successfully during initialization, so
// the only way parsing can fail now is because of stack overflow.
......
This diff is collapsed.
This diff is collapsed.
......@@ -180,10 +180,9 @@ MaybeHandle<Object> RegExp::Compile(Isolate* isolate, Handle<JSRegExp> re,
PostponeInterruptsScope postpone(isolate);
RegExpCompileData parse_result;
FlatStringReader reader(isolate, pattern);
DCHECK(!isolate->has_pending_exception());
if (!RegExpParser::ParseRegExp(isolate, &zone, &reader, flags,
&parse_result)) {
if (!RegExpParser::ParseRegExpFromHeapString(isolate, &zone, pattern, flags,
&parse_result)) {
// Throw an exception if we fail to parse the pattern.
return RegExp::ThrowRegExpException(isolate, re, pattern,
parse_result.error);
......@@ -507,9 +506,8 @@ bool RegExpImpl::CompileIrregexp(Isolate* isolate, Handle<JSRegExp> re,
Handle<String> pattern(re->Pattern(), isolate);
pattern = String::Flatten(isolate, pattern);
RegExpCompileData compile_data;
FlatStringReader reader(isolate, pattern);
if (!RegExpParser::ParseRegExp(isolate, &zone, &reader, flags,
&compile_data)) {
if (!RegExpParser::ParseRegExpFromHeapString(isolate, &zone, pattern, flags,
&compile_data)) {
// Throw an exception if we fail to parse the pattern.
// THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once.
USE(RegExp::ThrowRegExpException(isolate, re, pattern, compile_data.error));
......
......@@ -63,9 +63,8 @@ static bool CheckParse(const char* input) {
v8::HandleScope scope(CcTest::isolate());
Zone zone(isolate->allocator(), ZONE_NAME);
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result;
return v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader,
return RegExpParser::ParseRegExpFromHeapString(isolate, &zone, str,
JSRegExp::kNone, &result);
}
......@@ -76,11 +75,10 @@ static void CheckParseEq(const char* input, const char* expected,
v8::HandleScope scope(CcTest::isolate());
Zone zone(isolate->allocator(), ZONE_NAME);
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result;
JSRegExp::Flags flags = JSRegExp::kNone;
if (unicode) flags |= JSRegExp::kUnicode;
CHECK(v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader, flags,
CHECK(RegExpParser::ParseRegExpFromHeapString(isolate, &zone, str, flags,
&result));
CHECK_NOT_NULL(result.tree);
CHECK(result.error == RegExpError::kNone);
......@@ -98,9 +96,8 @@ static bool CheckSimple(const char* input) {
v8::HandleScope scope(CcTest::isolate());
Zone zone(isolate->allocator(), ZONE_NAME);
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result;
CHECK(v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader,
CHECK(RegExpParser::ParseRegExpFromHeapString(isolate, &zone, str,
JSRegExp::kNone, &result));
CHECK_NOT_NULL(result.tree);
CHECK(result.error == RegExpError::kNone);
......@@ -118,9 +115,8 @@ static MinMaxPair CheckMinMaxMatch(const char* input) {
v8::HandleScope scope(CcTest::isolate());
Zone zone(isolate->allocator(), ZONE_NAME);
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result;
CHECK(v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader,
CHECK(RegExpParser::ParseRegExpFromHeapString(isolate, &zone, str,
JSRegExp::kNone, &result));
CHECK_NOT_NULL(result.tree);
CHECK(result.error == RegExpError::kNone);
......@@ -433,11 +429,10 @@ static void ExpectError(const char* input, const char* expected,
v8::HandleScope scope(CcTest::isolate());
Zone zone(isolate->allocator(), ZONE_NAME);
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result;
JSRegExp::Flags flags = JSRegExp::kNone;
if (unicode) flags |= JSRegExp::kUnicode;
CHECK(!v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader, flags,
CHECK(!RegExpParser::ParseRegExpFromHeapString(isolate, &zone, str, flags,
&result));
CHECK_NULL(result.tree);
CHECK(result.error != RegExpError::kNone);
......@@ -536,15 +531,15 @@ static RegExpNode* Compile(const char* input, bool multiline, bool unicode,
bool is_one_byte, Zone* zone) {
Isolate* isolate = CcTest::i_isolate();
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData compile_data;
compile_data.compilation_target = RegExpCompilationTarget::kNative;
JSRegExp::Flags flags = JSRegExp::kNone;
if (multiline) flags = JSRegExp::kMultiline;
if (unicode) flags = JSRegExp::kUnicode;
if (!v8::internal::RegExpParser::ParseRegExp(isolate, zone, &reader, flags,
&compile_data))
if (!RegExpParser::ParseRegExpFromHeapString(isolate, zone, str, flags,
&compile_data)) {
return nullptr;
}
Handle<String> pattern = isolate->factory()
->NewStringFromUtf8(base::CStrVector(input))
.ToHandleChecked();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment