Commit 20876fcf authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[object] Remove FlatStringReader's vector constructor

This simplifies the logic since we can guarantee to have a
Handle<String>. The removed constructor was only used in tests.

Change-Id: I13519e474fe92892e9e8a39802d84cfab2c5b5ed
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2505711
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70849}
parent 3fb07882
......@@ -1511,24 +1511,15 @@ int ExternalString::ExternalPayloadSize() const {
}
FlatStringReader::FlatStringReader(Isolate* isolate, Handle<String> str)
: Relocatable(isolate), str_(str.location()), length_(str->length()) {
: Relocatable(isolate), str_(str), length_(str->length()) {
PostGarbageCollection();
}
FlatStringReader::FlatStringReader(Isolate* isolate, Vector<const char> input)
: Relocatable(isolate),
str_(nullptr),
is_one_byte_(true),
length_(input.length()),
start_(input.begin()) {}
void FlatStringReader::PostGarbageCollection() {
if (str_ == nullptr) return;
Handle<String> str(str_);
DCHECK(str->IsFlat());
DCHECK(str_->IsFlat());
DisallowHeapAllocation no_gc;
// This does not actually prevent the vector from being relocated later.
String::FlatContent content = str->GetFlatContent(no_gc);
String::FlatContent content = str_->GetFlatContent(no_gc);
DCHECK(content.IsFlat());
is_one_byte_ = content.IsOneByte();
if (is_one_byte_) {
......
......@@ -836,7 +836,6 @@ class ExternalTwoByteString : public ExternalString {
class V8_EXPORT_PRIVATE FlatStringReader : public Relocatable {
public:
FlatStringReader(Isolate* isolate, Handle<String> str);
FlatStringReader(Isolate* isolate, Vector<const char> input);
void PostGarbageCollection() override;
inline uc32 Get(int index);
template <typename Char>
......@@ -844,7 +843,7 @@ class V8_EXPORT_PRIVATE FlatStringReader : public Relocatable {
int length() { return length_; }
private:
Address* str_;
Handle<String> str_;
bool is_one_byte_;
int length_;
const void* start_;
......
......@@ -57,25 +57,31 @@ namespace internal {
namespace test_regexp {
static bool CheckParse(const char* input) {
Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate());
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
Zone zone(isolate->allocator(), ZONE_NAME);
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result;
return v8::internal::RegExpParser::ParseRegExp(
CcTest::i_isolate(), &zone, &reader, JSRegExp::kNone, &result);
return v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader,
JSRegExp::kNone, &result);
}
static void CheckParseEq(const char* input, const char* expected,
bool unicode = false) {
Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate());
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
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(CcTest::i_isolate(), &zone,
&reader, flags, &result));
CHECK(v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader, flags,
&result));
CHECK_NOT_NULL(result.tree);
CHECK(result.error == RegExpError::kNone);
std::ostringstream os;
......@@ -88,12 +94,15 @@ static void CheckParseEq(const char* input, const char* expected,
static bool CheckSimple(const char* input) {
Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate());
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
Zone zone(isolate->allocator(), ZONE_NAME);
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result;
CHECK(v8::internal::RegExpParser::ParseRegExp(
CcTest::i_isolate(), &zone, &reader, JSRegExp::kNone, &result));
CHECK(v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader,
JSRegExp::kNone, &result));
CHECK_NOT_NULL(result.tree);
CHECK(result.error == RegExpError::kNone);
return result.simple;
......@@ -106,12 +115,15 @@ struct MinMaxPair {
static MinMaxPair CheckMinMaxMatch(const char* input) {
Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate());
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
Zone zone(isolate->allocator(), ZONE_NAME);
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result;
CHECK(v8::internal::RegExpParser::ParseRegExp(
CcTest::i_isolate(), &zone, &reader, JSRegExp::kNone, &result));
CHECK(v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader,
JSRegExp::kNone, &result));
CHECK_NOT_NULL(result.tree);
CHECK(result.error == RegExpError::kNone);
int min_match = result.tree->min_match();
......@@ -422,7 +434,8 @@ static void ExpectError(const char* input, const char* expected,
v8::HandleScope scope(CcTest::isolate());
Zone zone(isolate->allocator(), ZONE_NAME);
FlatStringReader reader(isolate, CStrVector(input));
Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result;
JSRegExp::Flags flags = JSRegExp::kNone;
if (unicode) flags |= JSRegExp::kUnicode;
......@@ -524,14 +537,15 @@ TEST(CharacterClassEscapes) {
static RegExpNode* Compile(const char* input, bool multiline, bool unicode,
bool is_one_byte, Zone* zone) {
Isolate* isolate = CcTest::i_isolate();
FlatStringReader reader(isolate, CStrVector(input));
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(CcTest::i_isolate(), zone,
&reader, flags, &compile_data))
if (!v8::internal::RegExpParser::ParseRegExp(isolate, zone, &reader, flags,
&compile_data))
return nullptr;
Handle<String> pattern = isolate->factory()
->NewStringFromUtf8(CStrVector(input))
......
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