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 { ...@@ -1511,24 +1511,15 @@ int ExternalString::ExternalPayloadSize() const {
} }
FlatStringReader::FlatStringReader(Isolate* isolate, Handle<String> str) FlatStringReader::FlatStringReader(Isolate* isolate, Handle<String> str)
: Relocatable(isolate), str_(str.location()), length_(str->length()) { : Relocatable(isolate), str_(str), length_(str->length()) {
PostGarbageCollection(); 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() { void FlatStringReader::PostGarbageCollection() {
if (str_ == nullptr) return; DCHECK(str_->IsFlat());
Handle<String> str(str_);
DCHECK(str->IsFlat());
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
// This does not actually prevent the vector from being relocated later. // 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()); DCHECK(content.IsFlat());
is_one_byte_ = content.IsOneByte(); is_one_byte_ = content.IsOneByte();
if (is_one_byte_) { if (is_one_byte_) {
......
...@@ -836,7 +836,6 @@ class ExternalTwoByteString : public ExternalString { ...@@ -836,7 +836,6 @@ class ExternalTwoByteString : public ExternalString {
class V8_EXPORT_PRIVATE FlatStringReader : public Relocatable { class V8_EXPORT_PRIVATE FlatStringReader : public Relocatable {
public: public:
FlatStringReader(Isolate* isolate, Handle<String> str); FlatStringReader(Isolate* isolate, Handle<String> str);
FlatStringReader(Isolate* isolate, Vector<const char> input);
void PostGarbageCollection() override; void PostGarbageCollection() override;
inline uc32 Get(int index); inline uc32 Get(int index);
template <typename Char> template <typename Char>
...@@ -844,7 +843,7 @@ class V8_EXPORT_PRIVATE FlatStringReader : public Relocatable { ...@@ -844,7 +843,7 @@ class V8_EXPORT_PRIVATE FlatStringReader : public Relocatable {
int length() { return length_; } int length() { return length_; }
private: private:
Address* str_; Handle<String> str_;
bool is_one_byte_; bool is_one_byte_;
int length_; int length_;
const void* start_; const void* start_;
......
...@@ -57,25 +57,31 @@ namespace internal { ...@@ -57,25 +57,31 @@ namespace internal {
namespace test_regexp { namespace test_regexp {
static bool CheckParse(const char* input) { static bool CheckParse(const char* input) {
Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); Zone zone(isolate->allocator(), ZONE_NAME);
FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result; RegExpCompileData result;
return v8::internal::RegExpParser::ParseRegExp( return v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader,
CcTest::i_isolate(), &zone, &reader, JSRegExp::kNone, &result); JSRegExp::kNone, &result);
} }
static void CheckParseEq(const char* input, const char* expected, static void CheckParseEq(const char* input, const char* expected,
bool unicode = false) { bool unicode = false) {
Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); Zone zone(isolate->allocator(), ZONE_NAME);
FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result; RegExpCompileData result;
JSRegExp::Flags flags = JSRegExp::kNone; JSRegExp::Flags flags = JSRegExp::kNone;
if (unicode) flags |= JSRegExp::kUnicode; if (unicode) flags |= JSRegExp::kUnicode;
CHECK(v8::internal::RegExpParser::ParseRegExp(CcTest::i_isolate(), &zone, CHECK(v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader, flags,
&reader, flags, &result)); &result));
CHECK_NOT_NULL(result.tree); CHECK_NOT_NULL(result.tree);
CHECK(result.error == RegExpError::kNone); CHECK(result.error == RegExpError::kNone);
std::ostringstream os; std::ostringstream os;
...@@ -88,12 +94,15 @@ static void CheckParseEq(const char* input, const char* expected, ...@@ -88,12 +94,15 @@ static void CheckParseEq(const char* input, const char* expected,
static bool CheckSimple(const char* input) { static bool CheckSimple(const char* input) {
Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); Zone zone(isolate->allocator(), ZONE_NAME);
FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result; RegExpCompileData result;
CHECK(v8::internal::RegExpParser::ParseRegExp( CHECK(v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader,
CcTest::i_isolate(), &zone, &reader, JSRegExp::kNone, &result)); JSRegExp::kNone, &result));
CHECK_NOT_NULL(result.tree); CHECK_NOT_NULL(result.tree);
CHECK(result.error == RegExpError::kNone); CHECK(result.error == RegExpError::kNone);
return result.simple; return result.simple;
...@@ -106,12 +115,15 @@ struct MinMaxPair { ...@@ -106,12 +115,15 @@ struct MinMaxPair {
static MinMaxPair CheckMinMaxMatch(const char* input) { static MinMaxPair CheckMinMaxMatch(const char* input) {
Isolate* isolate = CcTest::i_isolate();
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); Zone zone(isolate->allocator(), ZONE_NAME);
FlatStringReader reader(CcTest::i_isolate(), CStrVector(input)); Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result; RegExpCompileData result;
CHECK(v8::internal::RegExpParser::ParseRegExp( CHECK(v8::internal::RegExpParser::ParseRegExp(isolate, &zone, &reader,
CcTest::i_isolate(), &zone, &reader, JSRegExp::kNone, &result)); JSRegExp::kNone, &result));
CHECK_NOT_NULL(result.tree); CHECK_NOT_NULL(result.tree);
CHECK(result.error == RegExpError::kNone); CHECK(result.error == RegExpError::kNone);
int min_match = result.tree->min_match(); int min_match = result.tree->min_match();
...@@ -422,7 +434,8 @@ static void ExpectError(const char* input, const char* expected, ...@@ -422,7 +434,8 @@ static void ExpectError(const char* input, const char* expected,
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
Zone zone(isolate->allocator(), ZONE_NAME); Zone zone(isolate->allocator(), ZONE_NAME);
FlatStringReader reader(isolate, CStrVector(input)); Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData result; RegExpCompileData result;
JSRegExp::Flags flags = JSRegExp::kNone; JSRegExp::Flags flags = JSRegExp::kNone;
if (unicode) flags |= JSRegExp::kUnicode; if (unicode) flags |= JSRegExp::kUnicode;
...@@ -524,14 +537,15 @@ TEST(CharacterClassEscapes) { ...@@ -524,14 +537,15 @@ TEST(CharacterClassEscapes) {
static RegExpNode* Compile(const char* input, bool multiline, bool unicode, static RegExpNode* Compile(const char* input, bool multiline, bool unicode,
bool is_one_byte, Zone* zone) { bool is_one_byte, Zone* zone) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
FlatStringReader reader(isolate, CStrVector(input)); Handle<String> str = isolate->factory()->NewStringFromAsciiChecked(input);
FlatStringReader reader(isolate, str);
RegExpCompileData compile_data; RegExpCompileData compile_data;
compile_data.compilation_target = RegExpCompilationTarget::kNative; compile_data.compilation_target = RegExpCompilationTarget::kNative;
JSRegExp::Flags flags = JSRegExp::kNone; JSRegExp::Flags flags = JSRegExp::kNone;
if (multiline) flags = JSRegExp::kMultiline; if (multiline) flags = JSRegExp::kMultiline;
if (unicode) flags = JSRegExp::kUnicode; if (unicode) flags = JSRegExp::kUnicode;
if (!v8::internal::RegExpParser::ParseRegExp(CcTest::i_isolate(), zone, if (!v8::internal::RegExpParser::ParseRegExp(isolate, zone, &reader, flags,
&reader, flags, &compile_data)) &compile_data))
return nullptr; return nullptr;
Handle<String> pattern = isolate->factory() Handle<String> pattern = isolate->factory()
->NewStringFromUtf8(CStrVector(input)) ->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