[Cleanup] String::GetChars() should take a DisallowHeapAllocation ref.

Building on https://chromium-review.googlesource.com/c/v8/v8/+/1349243,
which asserted on calls to GetChars() that weren't in a
DisallowHeapAllocation scope, this CL takes a reference to the scope
in order to provide static protection in all builds.


Bug: v8:8238
Change-Id: I481a1dbbd3ae57eb35c5f828c5e242691635be27
Reviewed-on: https://chromium-review.googlesource.com/c/1354038
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58022}
This commit is contained in:
Mike Stanton 2018-11-30 13:40:36 +01:00 committed by Commit Bot
parent 25d8187023
commit 4ab8c906e1
36 changed files with 274 additions and 229 deletions

View File

@ -5270,7 +5270,7 @@ int String::Utf8Length(Isolate* isolate) const {
int length = str->length();
if (length == 0) return 0;
i::DisallowHeapAllocation no_gc;
i::String::FlatContent flat = str->GetFlatContent();
i::String::FlatContent flat = str->GetFlatContent(no_gc);
DCHECK(flat.IsFlat());
int utf8_length = 0;
if (flat.IsOneByte()) {

View File

@ -134,8 +134,10 @@ typedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, false>
DisallowHeapAllocation;
#ifdef DEBUG
#define DISALLOW_HEAP_ALLOCATION(name) DisallowHeapAllocation name
#define DISALLOW_HEAP_ALLOCATION_REF(name) const DisallowHeapAllocation& name
#else
#define DISALLOW_HEAP_ALLOCATION(name)
#define DISALLOW_HEAP_ALLOCATION_REF(name)
#endif
// Scope to introduce an exception to DisallowHeapAllocation.

View File

@ -232,7 +232,7 @@ AstRawString* AstValueFactory::GetTwoByteStringInternal(
const AstRawString* AstValueFactory::GetString(Handle<String> literal) {
AstRawString* result = nullptr;
DisallowHeapAllocation no_gc;
String::FlatContent content = literal->GetFlatContent();
String::FlatContent content = literal->GetFlatContent(no_gc);
if (content.IsOneByte()) {
result = GetOneByteStringInternal(content.ToOneByteVector());
} else {

View File

@ -115,7 +115,7 @@ double ParseDateTimeString(Isolate* isolate, Handle<String> str) {
Handle<FixedArray> tmp =
isolate->factory()->NewFixedArray(DateParser::OUTPUT_SIZE);
DisallowHeapAllocation no_gc;
String::FlatContent str_content = str->GetFlatContent();
String::FlatContent str_content = str->GetFlatContent(no_gc);
bool result;
if (str_content.IsOneByte()) {
result = DateParser::Parse(isolate, str_content.ToOneByteVector(), *tmp);

View File

@ -110,9 +110,10 @@ BUILTIN(StringFromCodePoint) {
static_cast<int>(one_byte_buffer.size() + two_byte_buffer.size())));
DisallowHeapAllocation no_gc;
CopyChars(result->GetChars(), one_byte_buffer.data(), one_byte_buffer.size());
CopyChars(result->GetChars() + one_byte_buffer.size(), two_byte_buffer.data(),
two_byte_buffer.size());
CopyChars(result->GetChars(no_gc), one_byte_buffer.data(),
one_byte_buffer.size());
CopyChars(result->GetChars(no_gc) + one_byte_buffer.size(),
two_byte_buffer.data(), two_byte_buffer.size());
return *result;
}
@ -158,8 +159,8 @@ BUILTIN(StringPrototypeEndsWith) {
search_string = String::Flatten(isolate, search_string);
DisallowHeapAllocation no_gc; // ensure vectors stay valid
String::FlatContent str_content = str->GetFlatContent();
String::FlatContent search_content = search_string->GetFlatContent();
String::FlatContent str_content = str->GetFlatContent(no_gc);
String::FlatContent search_content = search_string->GetFlatContent(no_gc);
if (str_content.IsOneByte() && search_content.IsOneByte()) {
Vector<const uint8_t> str_vector = str_content.ToOneByteVector();
@ -240,8 +241,8 @@ BUILTIN(StringPrototypeLocaleCompare) {
str2 = String::Flatten(isolate, str2);
DisallowHeapAllocation no_gc;
String::FlatContent flat1 = str1->GetFlatContent();
String::FlatContent flat2 = str2->GetFlatContent();
String::FlatContent flat1 = str1->GetFlatContent(no_gc);
String::FlatContent flat2 = str2->GetFlatContent(no_gc);
for (int i = 0; i < end; i++) {
if (flat1.Get(i) != flat2.Get(i)) {
@ -465,11 +466,11 @@ V8_WARN_UNUSED_RESULT static Object* ConvertCase(
Handle<SeqOneByteString> result =
isolate->factory()->NewRawOneByteString(length).ToHandleChecked();
DisallowHeapAllocation no_gc;
String::FlatContent flat_content = s->GetFlatContent();
String::FlatContent flat_content = s->GetFlatContent(no_gc);
DCHECK(flat_content.IsFlat());
bool has_changed_character = false;
int index_to_first_unprocessed = FastAsciiConvert<Converter::kIsToLower>(
reinterpret_cast<char*>(result->GetChars()),
reinterpret_cast<char*>(result->GetChars(no_gc)),
reinterpret_cast<const char*>(flat_content.ToOneByteVector().start()),
length, &has_changed_character);
// If not ASCII, we discard the result and take the 2 byte path.

View File

@ -35,7 +35,8 @@ class MaybeUtf8 {
// strings, the bytes we get from SeqOneByteString are not. buf_ is
// guaranteed to be null terminated.
DisallowHeapAllocation no_gc;
memcpy(buf_, Handle<SeqOneByteString>::cast(string)->GetChars(), len);
memcpy(buf_, Handle<SeqOneByteString>::cast(string)->GetChars(no_gc),
len);
}
} else {
Local<v8::String> local = Utils::ToLocal(string);

View File

@ -88,7 +88,8 @@ void JsonPrintFunctionSource(std::ostream& os, int source_id,
end = shared->EndPosition();
os << ", \"sourceText\": \"";
int len = shared->EndPosition() - start;
SubStringRange source(String::cast(script->source()), start, len);
SubStringRange source(String::cast(script->source()), no_allocation,
start, len);
for (const auto& c : source) {
os << AsEscapedUC16ForJSON(c);
}

View File

@ -565,7 +565,8 @@ void PrintFunctionSource(OptimizedCompilationInfo* info, Isolate* isolate,
DisallowHeapAllocation no_allocation;
int start = shared->StartPosition();
int len = shared->EndPosition() - start;
SubStringRange source(String::cast(script->source()), start, len);
SubStringRange source(String::cast(script->source()), no_allocation,
start, len);
for (const auto& c : source) {
os << AsReversiblyEscapedUC16(c);
}

View File

@ -216,11 +216,13 @@ class StringToIntHelper {
if (raw_one_byte_subject_ != nullptr) {
return Vector<const uint8_t>(raw_one_byte_subject_, length_);
}
return subject_->GetFlatContent().ToOneByteVector();
DisallowHeapAllocation no_gc;
return subject_->GetFlatContent(no_gc).ToOneByteVector();
}
Vector<const uc16> GetTwoByteVector() {
return subject_->GetFlatContent().ToUC16Vector();
DisallowHeapAllocation no_gc;
return subject_->GetFlatContent(no_gc).ToUC16Vector();
}
// Subclasses get access to internal state:
@ -1311,7 +1313,7 @@ double StringToDouble(Isolate* isolate, Handle<String> string, int flags,
Handle<String> flattened = String::Flatten(isolate, string);
{
DisallowHeapAllocation no_gc;
String::FlatContent flat = flattened->GetFlatContent();
String::FlatContent flat = flattened->GetFlatContent(no_gc);
DCHECK(flat.IsFlat());
if (flat.IsOneByte()) {
return StringToDouble(flat.ToOneByteVector(), flags, empty_string_val);

View File

@ -2004,7 +2004,7 @@ void Debug::PrintBreakLocation() {
int line_start = line == 0 ? 0 : Smi::ToInt(line_ends->get(line - 1)) + 1;
int line_end = Smi::ToInt(line_ends->get(line));
DisallowHeapAllocation no_gc;
String::FlatContent content = source->GetFlatContent();
String::FlatContent content = source->GetFlatContent(no_gc);
if (content.IsOneByte()) {
PrintF("[debug] %.*s\n", line_end - line_start,
content.ToOneByteVector().start() + line_start);

View File

@ -629,7 +629,7 @@ MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t> string,
DisallowHeapAllocation no_gc;
// Copy the characters into the new object.
CopyChars(SeqOneByteString::cast(*result)->GetChars(), string.start(),
CopyChars(SeqOneByteString::cast(*result)->GetChars(no_gc), string.start(),
length);
return result;
}
@ -663,7 +663,7 @@ MaybeHandle<String> Factory::NewStringFromUtf8(Vector<const char> string,
// Copy ASCII portion.
DisallowHeapAllocation no_gc;
uint16_t* data = result->GetChars();
uint16_t* data = result->GetChars(no_gc);
for (int i = 0; i < non_ascii_start; i++) {
*data++ = *ascii_data++;
}
@ -683,7 +683,7 @@ MaybeHandle<String> Factory::NewStringFromUtf8SubString(
{
DisallowHeapAllocation no_gc;
const char* ascii_data =
reinterpret_cast<const char*>(str->GetChars() + begin);
reinterpret_cast<const char*>(str->GetChars(no_gc) + begin);
non_ascii_start = String::NonAsciiStart(ascii_data, length);
if (non_ascii_start < length) {
// Non-ASCII and we need to decode.
@ -713,12 +713,12 @@ MaybeHandle<String> Factory::NewStringFromUtf8SubString(
// allocation.
DisallowHeapAllocation no_gc;
const char* ascii_data =
reinterpret_cast<const char*>(str->GetChars() + begin);
reinterpret_cast<const char*>(str->GetChars(no_gc) + begin);
auto non_ascii = Vector<const char>(ascii_data + non_ascii_start,
length - non_ascii_start);
// Copy ASCII portion.
uint16_t* data = result->GetChars();
uint16_t* data = result->GetChars(no_gc);
for (int i = 0; i < non_ascii_start; i++) {
*data++ = *ascii_data++;
}
@ -738,14 +738,14 @@ MaybeHandle<String> Factory::NewStringFromTwoByte(const uc16* string,
ASSIGN_RETURN_ON_EXCEPTION(isolate(), result,
NewRawOneByteString(length, pretenure), String);
DisallowHeapAllocation no_gc;
CopyChars(result->GetChars(), string, length);
CopyChars(result->GetChars(no_gc), string, length);
return result;
} else {
Handle<SeqTwoByteString> result;
ASSIGN_RETURN_ON_EXCEPTION(isolate(), result,
NewRawTwoByteString(length, pretenure), String);
DisallowHeapAllocation no_gc;
CopyChars(result->GetChars(), string, length);
CopyChars(result->GetChars(no_gc), string, length);
return result;
}
}
@ -842,7 +842,7 @@ Handle<String> Factory::AllocateTwoByteInternalizedString(
DisallowHeapAllocation no_gc;
// Fill in the characters.
MemCopy(answer->GetChars(), str.start(), str.length() * kUC16Size);
MemCopy(answer->GetChars(no_gc), str.start(), str.length() * kUC16Size);
return answer;
}
@ -876,9 +876,11 @@ Handle<String> Factory::AllocateInternalizedStringImpl(T t, int chars,
DisallowHeapAllocation no_gc;
if (is_one_byte) {
WriteOneByteData(t, SeqOneByteString::cast(*answer)->GetChars(), chars);
WriteOneByteData(t, SeqOneByteString::cast(*answer)->GetChars(no_gc),
chars);
} else {
WriteTwoByteData(t, SeqTwoByteString::cast(*answer)->GetChars(), chars);
WriteTwoByteData(t, SeqTwoByteString::cast(*answer)->GetChars(no_gc),
chars);
}
return answer;
}
@ -890,7 +892,7 @@ Handle<String> Factory::NewInternalizedStringFromUtf8(Vector<const char> str,
Handle<SeqOneByteString> result =
AllocateRawOneByteInternalizedString(str.length(), hash_field);
DisallowHeapAllocation no_allocation;
MemCopy(result->GetChars(), str.start(), str.length());
MemCopy(result->GetChars(no_allocation), str.start(), str.length());
return result;
}
return AllocateInternalizedStringImpl<false>(str, chars, hash_field);
@ -901,7 +903,7 @@ Handle<String> Factory::NewOneByteInternalizedString(Vector<const uint8_t> str,
Handle<SeqOneByteString> result =
AllocateRawOneByteInternalizedString(str.length(), hash_field);
DisallowHeapAllocation no_allocation;
MemCopy(result->GetChars(), str.start(), str.length());
MemCopy(result->GetChars(no_allocation), str.start(), str.length());
return result;
}
@ -911,7 +913,8 @@ Handle<String> Factory::NewOneByteInternalizedSubString(
Handle<SeqOneByteString> result =
AllocateRawOneByteInternalizedString(length, hash_field);
DisallowHeapAllocation no_allocation;
MemCopy(result->GetChars(), string->GetChars() + offset, length);
MemCopy(result->GetChars(no_allocation),
string->GetChars(no_allocation) + offset, length);
return result;
}
@ -1069,7 +1072,7 @@ static inline Handle<String> MakeOrFindTwoCharacterString(Isolate* isolate,
Handle<SeqOneByteString> str =
isolate->factory()->NewRawOneByteString(2).ToHandleChecked();
DisallowHeapAllocation no_allocation;
uint8_t* dest = str->GetChars();
uint8_t* dest = str->GetChars(no_allocation);
dest[0] = static_cast<uint8_t>(c1);
dest[1] = static_cast<uint8_t>(c2);
return str;
@ -1077,7 +1080,7 @@ static inline Handle<String> MakeOrFindTwoCharacterString(Isolate* isolate,
Handle<SeqTwoByteString> str =
isolate->factory()->NewRawTwoByteString(2).ToHandleChecked();
DisallowHeapAllocation no_allocation;
uc16* dest = str->GetChars();
uc16* dest = str->GetChars(no_allocation);
dest[0] = c1;
dest[1] = c2;
return str;
@ -1089,7 +1092,7 @@ Handle<String> ConcatStringContent(Handle<StringType> result,
Handle<String> first,
Handle<String> second) {
DisallowHeapAllocation pointer_stays_valid;
SinkChar* sink = result->GetChars();
SinkChar* sink = result->GetChars(pointer_stays_valid);
String::WriteToFlat(*first, sink, 0, first->length());
String::WriteToFlat(*second, sink + first->length(), 0, second->length());
return result;
@ -1149,17 +1152,17 @@ MaybeHandle<String> Factory::NewConsString(Handle<String> left,
Handle<SeqOneByteString> result =
NewRawOneByteString(length).ToHandleChecked();
DisallowHeapAllocation no_gc;
uint8_t* dest = result->GetChars();
uint8_t* dest = result->GetChars(no_gc);
// Copy left part.
const uint8_t* src =
left->IsExternalString()
? Handle<ExternalOneByteString>::cast(left)->GetChars()
: Handle<SeqOneByteString>::cast(left)->GetChars();
: Handle<SeqOneByteString>::cast(left)->GetChars(no_gc);
for (int i = 0; i < left_length; i++) *dest++ = src[i];
// Copy right part.
src = right->IsExternalString()
? Handle<ExternalOneByteString>::cast(right)->GetChars()
: Handle<SeqOneByteString>::cast(right)->GetChars();
: Handle<SeqOneByteString>::cast(right)->GetChars(no_gc);
for (int i = 0; i < right_length; i++) *dest++ = src[i];
return result;
}
@ -1207,7 +1210,7 @@ Handle<String> Factory::NewSurrogatePairString(uint16_t lead, uint16_t trail) {
Handle<SeqTwoByteString> str =
isolate()->factory()->NewRawTwoByteString(2).ToHandleChecked();
DisallowHeapAllocation no_allocation;
uc16* dest = str->GetChars();
uc16* dest = str->GetChars(no_allocation);
dest[0] = lead;
dest[1] = trail;
return str;
@ -1241,14 +1244,14 @@ Handle<String> Factory::NewProperSubString(Handle<String> str, int begin,
Handle<SeqOneByteString> result =
NewRawOneByteString(length).ToHandleChecked();
DisallowHeapAllocation no_gc;
uint8_t* dest = result->GetChars();
uint8_t* dest = result->GetChars(no_gc);
String::WriteToFlat(*str, dest, begin, end);
return result;
} else {
Handle<SeqTwoByteString> result =
NewRawTwoByteString(length).ToHandleChecked();
DisallowHeapAllocation no_gc;
uc16* dest = result->GetChars();
uc16* dest = result->GetChars(no_gc);
String::WriteToFlat(*str, dest, begin, end);
return result;
}

View File

@ -256,10 +256,10 @@ bool JsonParser<seq_one_byte>::ParseJsonString(Handle<String> expected) {
int length = expected->length();
if (source_->length() - position_ - 1 > length) {
DisallowHeapAllocation no_gc;
String::FlatContent content = expected->GetFlatContent();
String::FlatContent content = expected->GetFlatContent(no_gc);
if (content.IsOneByte()) {
DCHECK_EQ('"', c0_);
const uint8_t* input_chars = seq_source_->GetChars() + position_ + 1;
const uint8_t* input_chars = seq_source_->GetChars(no_gc) + position_ + 1;
const uint8_t* expected_chars = content.ToOneByteVector().start();
for (int i = 0; i < length; i++) {
uint8_t c0 = input_chars[i];
@ -668,7 +668,7 @@ Handle<Object> JsonParser<seq_one_byte>::ParseJsonNumber() {
double number;
if (seq_one_byte) {
DisallowHeapAllocation no_gc;
Vector<const uint8_t> chars(seq_source_->GetChars() + beg_pos, length);
Vector<const uint8_t> chars(seq_source_->GetChars(no_gc) + beg_pos, length);
number = StringToDouble(chars,
NO_FLAGS, // Hex, octal or trailing junk.
std::numeric_limits<double>::quiet_NaN());
@ -731,7 +731,7 @@ Handle<String> JsonParser<seq_one_byte>::SlowScanJsonString(
{
DisallowHeapAllocation no_gc;
// Copy prefix into seq_str.
SinkChar* dest = seq_string->GetChars();
SinkChar* dest = seq_string->GetChars(no_gc);
String::WriteToFlat(*prefix, dest, start, end);
}
@ -899,8 +899,8 @@ Handle<String> JsonParser<seq_one_byte>::ScanJsonString() {
}
if (!element->IsTheHole(isolate())) {
DisallowHeapAllocation no_gc;
Vector<const uint8_t> string_vector(seq_source_->GetChars() + position_,
length);
Vector<const uint8_t> string_vector(
seq_source_->GetChars(no_gc) + position_, length);
if (String::cast(element)->IsOneByteEqualTo(string_vector)) {
result = Handle<String>(String::cast(element), isolate());
DCHECK_EQ(result->Hash(),
@ -937,7 +937,7 @@ Handle<String> JsonParser<seq_one_byte>::ScanJsonString() {
Handle<String> result =
factory()->NewRawOneByteString(length, pretenure_).ToHandleChecked();
DisallowHeapAllocation no_gc;
uint8_t* dest = SeqOneByteString::cast(*result)->GetChars();
uint8_t* dest = SeqOneByteString::cast(*result)->GetChars(no_gc);
String::WriteToFlat(*source_, dest, beg_pos, position_);
DCHECK_EQ('"', c0_);

View File

@ -809,9 +809,9 @@ void JsonStringifier::SerializeString_(Handle<String> string) {
// part, or we might need to allocate.
if (int worst_case_length = builder_.EscapedLengthIfCurrentPartFits(length)) {
DisallowHeapAllocation no_gc;
Vector<const SrcChar> vector = string->GetCharVector<SrcChar>();
Vector<const SrcChar> vector = string->GetCharVector<SrcChar>(no_gc);
IncrementalStringBuilder::NoExtendBuilder<DestChar> no_extend(
&builder_, worst_case_length);
&builder_, worst_case_length, no_gc);
SerializeStringUnchecked_(vector, &no_extend);
} else {
FlatStringReader reader(isolate_, string);

View File

@ -2638,13 +2638,13 @@ Handle<String> String::SlowFlatten(Isolate* isolate, Handle<ConsString> cons,
Handle<SeqOneByteString> flat = isolate->factory()->NewRawOneByteString(
length, tenure).ToHandleChecked();
DisallowHeapAllocation no_gc;
WriteToFlat(*cons, flat->GetChars(), 0, length);
WriteToFlat(*cons, flat->GetChars(no_gc), 0, length);
result = flat;
} else {
Handle<SeqTwoByteString> flat = isolate->factory()->NewRawTwoByteString(
length, tenure).ToHandleChecked();
DisallowHeapAllocation no_gc;
WriteToFlat(*cons, flat->GetChars(), 0, length);
WriteToFlat(*cons, flat->GetChars(no_gc), 0, length);
result = flat;
}
cons->set_first(isolate, *result);
@ -11005,7 +11005,8 @@ Handle<Object> String::ToNumber(Isolate* isolate, Handle<String> subject) {
if (len == 0) return handle(Smi::kZero, isolate);
DisallowHeapAllocation no_gc;
uint8_t const* data = Handle<SeqOneByteString>::cast(subject)->GetChars();
uint8_t const* data =
Handle<SeqOneByteString>::cast(subject)->GetChars(no_gc);
bool minus = (data[0] == '-');
int start_pos = (minus ? 1 : 0);
@ -11047,9 +11048,9 @@ Handle<Object> String::ToNumber(Isolate* isolate, Handle<String> subject) {
return isolate->factory()->NewNumber(StringToDouble(isolate, subject, flags));
}
String::FlatContent String::GetFlatContent() {
DCHECK(!AllowHeapAllocation::IsAllowed());
String::FlatContent String::GetFlatContent(
const DisallowHeapAllocation& no_gc) {
USE(no_gc);
int length = this->length();
StringShape shape(*this);
String string = *this;
@ -11079,7 +11080,7 @@ String::FlatContent String::GetFlatContent() {
if (shape.encoding_tag() == kOneByteStringTag) {
const uint8_t* start;
if (shape.representation_tag() == kSeqStringTag) {
start = SeqOneByteString::cast(string)->GetChars();
start = SeqOneByteString::cast(string)->GetChars(no_gc);
} else {
start = ExternalOneByteString::cast(string)->GetChars();
}
@ -11088,7 +11089,7 @@ String::FlatContent String::GetFlatContent() {
DCHECK_EQ(shape.encoding_tag(), kTwoByteStringTag);
const uc16* start;
if (shape.representation_tag() == kSeqStringTag) {
start = SeqTwoByteString::cast(string)->GetChars();
start = SeqTwoByteString::cast(string)->GetChars(no_gc);
} else {
start = ExternalTwoByteString::cast(string)->GetChars();
}
@ -11216,7 +11217,7 @@ void FlatStringReader::PostGarbageCollection() {
DCHECK(str->IsFlat());
DisallowHeapAllocation no_gc;
// This does not actually prevent the vector from being relocated later.
String::FlatContent content = str->GetFlatContent();
String::FlatContent content = str->GetFlatContent(no_gc);
DCHECK(content.IsFlat());
is_one_byte_ = content.IsOneByte();
if (is_one_byte_) {
@ -11416,14 +11417,12 @@ void String::WriteToFlat(String src, sinkchar* sink, int f, int t) {
return;
}
case kOneByteStringTag | kSeqStringTag: {
CopyChars(sink,
SeqOneByteString::cast(source)->GetChars() + from,
CopyChars(sink, SeqOneByteString::cast(source)->GetChars(no_gc) + from,
to - from);
return;
}
case kTwoByteStringTag | kSeqStringTag: {
CopyChars(sink,
SeqTwoByteString::cast(source)->GetChars() + from,
CopyChars(sink, SeqTwoByteString::cast(source)->GetChars(no_gc) + from,
to - from);
return;
}
@ -11458,7 +11457,7 @@ void String::WriteToFlat(String src, sinkchar* sink, int f, int t) {
sink[boundary - from] = static_cast<sinkchar>(second->Get(0));
} else if (second->IsSeqOneByteString()) {
CopyChars(sink + boundary - from,
SeqOneByteString::cast(second)->GetChars(),
SeqOneByteString::cast(second)->GetChars(no_gc),
to - boundary);
} else {
WriteToFlat(second,
@ -11519,7 +11518,7 @@ Handle<FixedArray> String::CalculateLineEnds(Isolate* isolate,
line_ends.reserve(line_count_estimate);
{ DisallowHeapAllocation no_allocation; // ensure vectors stay valid.
// Dispatch on type of strings.
String::FlatContent content = src->GetFlatContent();
String::FlatContent content = src->GetFlatContent(no_allocation);
DCHECK(content.IsFlat());
if (content.IsOneByte()) {
CalculateLineEndsImpl(isolate,
@ -11561,7 +11560,8 @@ void WriteFixedArrayToFlat(FixedArray fixed_array, int length, String separator,
if (use_one_byte_separator_fast_path) {
CHECK(StringShape(separator).IsSequentialOneByte());
CHECK_EQ(separator->length(), 1);
separator_one_char = SeqOneByteString::cast(separator)->GetChars()[0];
separator_one_char =
SeqOneByteString::cast(separator)->GetChars(no_allocation)[0];
}
uint32_t num_separators = 0;
@ -11639,12 +11639,12 @@ Address JSArray::ArrayJoinConcatToSequentialString(Isolate* isolate,
if (StringShape(dest).IsSequentialOneByte()) {
WriteFixedArrayToFlat(fixed_array, static_cast<int>(length), separator,
SeqOneByteString::cast(dest)->GetChars(),
SeqOneByteString::cast(dest)->GetChars(no_allocation),
dest->length());
} else {
DCHECK(StringShape(dest).IsSequentialTwoByte());
WriteFixedArrayToFlat(fixed_array, static_cast<int>(length), separator,
SeqTwoByteString::cast(dest)->GetChars(),
SeqTwoByteString::cast(dest)->GetChars(no_allocation),
dest->length());
}
return dest->ptr();
@ -11843,8 +11843,8 @@ bool String::SlowEquals(String other) {
if (this->Get(0) != other->Get(0)) return false;
if (IsSeqOneByteString() && other->IsSeqOneByteString()) {
const uint8_t* str1 = SeqOneByteString::cast(*this)->GetChars();
const uint8_t* str2 = SeqOneByteString::cast(other)->GetChars();
const uint8_t* str1 = SeqOneByteString::cast(*this)->GetChars(no_gc);
const uint8_t* str2 = SeqOneByteString::cast(other)->GetChars(no_gc);
return CompareRawStringContents(str1, str2, len);
}
@ -11897,8 +11897,8 @@ bool String::SlowEquals(Isolate* isolate, Handle<String> one,
two = String::Flatten(isolate, two);
DisallowHeapAllocation no_gc;
String::FlatContent flat1 = one->GetFlatContent();
String::FlatContent flat2 = two->GetFlatContent();
String::FlatContent flat1 = one->GetFlatContent(no_gc);
String::FlatContent flat2 = two->GetFlatContent(no_gc);
if (flat1.IsOneByte() && flat2.IsOneByte()) {
return CompareRawStringContents(flat1.ToOneByteVector().start(),
@ -11947,8 +11947,8 @@ ComparisonResult String::Compare(Isolate* isolate, Handle<String> x,
result = ComparisonResult::kLessThan;
}
int r;
String::FlatContent x_content = x->GetFlatContent();
String::FlatContent y_content = y->GetFlatContent();
String::FlatContent x_content = x->GetFlatContent(no_gc);
String::FlatContent y_content = y->GetFlatContent(no_gc);
if (x_content.IsOneByte()) {
Vector<const uint8_t> x_chars = x_content.ToOneByteVector();
if (y_content.IsOneByte()) {
@ -12031,8 +12031,8 @@ int String::IndexOf(Isolate* isolate, Handle<String> receiver,
DisallowHeapAllocation no_gc; // ensure vectors stay valid
// Extract flattened substrings of cons strings before getting encoding.
String::FlatContent receiver_content = receiver->GetFlatContent();
String::FlatContent search_content = search->GetFlatContent();
String::FlatContent receiver_content = receiver->GetFlatContent(no_gc);
String::FlatContent search_content = search->GetFlatContent(no_gc);
// dispatch on type of strings
if (search_content.IsOneByte()) {
@ -12293,8 +12293,8 @@ Object* String::LastIndexOf(Isolate* isolate, Handle<Object> receiver,
int last_index = -1;
DisallowHeapAllocation no_gc; // ensure vectors stay valid
String::FlatContent receiver_content = receiver_string->GetFlatContent();
String::FlatContent search_content = search_string->GetFlatContent();
String::FlatContent receiver_content = receiver_string->GetFlatContent(no_gc);
String::FlatContent search_content = search_string->GetFlatContent(no_gc);
if (search_content.IsOneByte()) {
Vector<const uint8_t> pat_vector = search_content.ToOneByteVector();
@ -12352,7 +12352,7 @@ bool String::IsOneByteEqualTo(Vector<const uint8_t> str) {
int slen = length();
if (str.length() != slen) return false;
DisallowHeapAllocation no_gc;
FlatContent content = GetFlatContent();
FlatContent content = GetFlatContent(no_gc);
if (content.IsOneByte()) {
return CompareChars(content.ToOneByteVector().start(),
str.start(), slen) == 0;
@ -12365,7 +12365,7 @@ bool String::IsTwoByteEqualTo(Vector<const uc16> str) {
int slen = length();
if (str.length() != slen) return false;
DisallowHeapAllocation no_gc;
FlatContent content = GetFlatContent();
FlatContent content = GetFlatContent(no_gc);
if (content.IsOneByte()) {
return CompareChars(content.ToOneByteVector().start(), str.start(), slen) ==
0;
@ -16625,7 +16625,7 @@ template <typename Char>
inline int CountRequiredEscapes(Handle<String> source) {
DisallowHeapAllocation no_gc;
int escapes = 0;
Vector<const Char> src = source->GetCharVector<Char>();
Vector<const Char> src = source->GetCharVector<Char>(no_gc);
for (int i = 0; i < src.length(); i++) {
if (src[i] == '\\') {
// Escape. Skip next character;
@ -16643,8 +16643,8 @@ template <typename Char, typename StringType>
inline Handle<StringType> WriteEscapedRegExpSource(Handle<String> source,
Handle<StringType> result) {
DisallowHeapAllocation no_gc;
Vector<const Char> src = source->GetCharVector<Char>();
Vector<Char> dst(result->GetChars(), result->length());
Vector<const Char> src = source->GetCharVector<Char>(no_gc);
Vector<Char> dst(result->GetChars(no_gc), result->length());
int s = 0;
int d = 0;
while (s < src.length()) {
@ -16786,7 +16786,7 @@ Handle<String> SeqOneByteSubStringKey::AsHandle(Isolate* isolate) {
bool SeqOneByteSubStringKey::IsMatch(Object* string) {
DisallowHeapAllocation no_gc;
Vector<const uint8_t> chars(string_->GetChars() + from_, length_);
Vector<const uint8_t> chars(string_->GetChars(no_gc) + from_, length_);
return String::cast(string)->IsOneByteEqualTo(chars);
}
@ -17396,6 +17396,7 @@ class StringTableNoAllocateKey : public StringTableKey {
int len = string_->length();
if (len != other->length()) return false;
DisallowHeapAllocation no_gc;
if (!special_flattening_) {
if (string_->Get(0) != other->Get(0)) return false;
if (string_->IsFlat()) {
@ -17403,15 +17404,15 @@ class StringTableNoAllocateKey : public StringTableKey {
StringShape shape2(other);
if (shape1.encoding_tag() == kOneByteStringTag &&
shape2.encoding_tag() == kOneByteStringTag) {
String::FlatContent flat1 = string_->GetFlatContent();
String::FlatContent flat2 = other->GetFlatContent();
String::FlatContent flat1 = string_->GetFlatContent(no_gc);
String::FlatContent flat2 = other->GetFlatContent(no_gc);
return CompareRawStringContents(flat1.ToOneByteVector().start(),
flat2.ToOneByteVector().start(), len);
}
if (shape1.encoding_tag() == kTwoByteStringTag &&
shape2.encoding_tag() == kTwoByteStringTag) {
String::FlatContent flat1 = string_->GetFlatContent();
String::FlatContent flat2 = other->GetFlatContent();
String::FlatContent flat1 = string_->GetFlatContent(no_gc);
String::FlatContent flat2 = other->GetFlatContent(no_gc);
return CompareRawStringContents(flat1.ToUC16Vector().start(),
flat2.ToUC16Vector().start(), len);
}
@ -17420,7 +17421,7 @@ class StringTableNoAllocateKey : public StringTableKey {
return comparator.Equals(string_, other);
}
String::FlatContent flat_content = other->GetFlatContent();
String::FlatContent flat_content = other->GetFlatContent(no_gc);
if (one_byte_) {
if (flat_content.IsOneByte()) {
return CompareRawStringContents(

View File

@ -1976,7 +1976,7 @@ MaybeHandle<String> MutableBigInt::ToStringBasePowerOfTwo(
->NewRawOneByteString(static_cast<int>(chars_required))
.ToHandleChecked();
DisallowHeapAllocation no_gc;
uint8_t* buffer = result->GetChars();
uint8_t* buffer = result->GetChars(no_gc);
// Print the number into the string, starting from the last position.
int pos = static_cast<int>(chars_required - 1);
digit_t digit = 0;
@ -2053,7 +2053,7 @@ MaybeHandle<String> MutableBigInt::ToStringGeneric(Isolate* isolate,
// Zap the string first.
{
DisallowHeapAllocation no_gc;
uint8_t* chars = result->GetChars();
uint8_t* chars = result->GetChars(no_gc);
for (int i = 0; i < static_cast<int>(chars_required); i++) chars[i] = '?';
}
#endif
@ -2086,7 +2086,7 @@ MaybeHandle<String> MutableBigInt::ToStringGeneric(Isolate* isolate,
DCHECK(!rest.is_null());
dividend = reinterpret_cast<Handle<BigIntBase>*>(&rest);
DisallowHeapAllocation no_gc;
uint8_t* chars = result->GetChars();
uint8_t* chars = result->GetChars(no_gc);
for (int i = 0; i < chunk_chars; i++) {
chars[pos++] = kConversionChars[chunk % radix];
chunk /= radix;
@ -2100,7 +2100,7 @@ MaybeHandle<String> MutableBigInt::ToStringGeneric(Isolate* isolate,
last_digit = rest->digit(0);
}
DisallowHeapAllocation no_gc;
uint8_t* chars = result->GetChars();
uint8_t* chars = result->GetChars(no_gc);
do {
chars[pos++] = kConversionChars[last_digit % radix];
last_digit /= radix;

View File

@ -193,9 +193,10 @@ icu::UnicodeString Intl::ToICUUnicodeString(Isolate* isolate,
{
DisallowHeapAllocation no_gc;
std::unique_ptr<uc16[]> sap;
return icu::UnicodeString(GetUCharBufferFromFlat(string->GetFlatContent(),
&sap, string->length()),
string->length());
return icu::UnicodeString(
GetUCharBufferFromFlat(string->GetFlatContent(no_gc), &sap,
string->length()),
string->length());
}
}
@ -221,11 +222,12 @@ MaybeHandle<String> LocaleConvertCase(Isolate* isolate, Handle<String> s,
String);
DisallowHeapAllocation no_gc;
DCHECK(s->IsFlat());
String::FlatContent flat = s->GetFlatContent();
String::FlatContent flat = s->GetFlatContent(no_gc);
const UChar* src = GetUCharBufferFromFlat(flat, &sap, src_length);
status = U_ZERO_ERROR;
dest_length = case_converter(reinterpret_cast<UChar*>(result->GetChars()),
dest_length, src, src_length, lang, &status);
dest_length =
case_converter(reinterpret_cast<UChar*>(result->GetChars(no_gc)),
dest_length, src, src_length, lang, &status);
if (status != U_BUFFER_OVERFLOW_ERROR) break;
}
@ -257,8 +259,8 @@ String Intl::ConvertOneByteToLower(String src, String dst) {
DisallowHeapAllocation no_gc;
const int length = src->length();
String::FlatContent src_flat = src->GetFlatContent();
uint8_t* dst_data = SeqOneByteString::cast(dst)->GetChars();
String::FlatContent src_flat = src->GetFlatContent(no_gc);
uint8_t* dst_data = SeqOneByteString::cast(dst)->GetChars(no_gc);
if (src_flat.IsOneByte()) {
const uint8_t* src_data = src_flat.ToOneByteVector().start();
@ -335,15 +337,15 @@ MaybeHandle<String> Intl::ConvertToUpper(Isolate* isolate, Handle<String> s) {
bool is_result_single_byte;
{
DisallowHeapAllocation no_gc;
String::FlatContent flat = s->GetFlatContent();
uint8_t* dest = result->GetChars();
String::FlatContent flat = s->GetFlatContent(no_gc);
uint8_t* dest = result->GetChars(no_gc);
if (flat.IsOneByte()) {
Vector<const uint8_t> src = flat.ToOneByteVector();
bool has_changed_character = false;
int index_to_first_unprocessed =
FastAsciiConvert<false>(reinterpret_cast<char*>(result->GetChars()),
reinterpret_cast<const char*>(src.start()),
length, &has_changed_character);
int index_to_first_unprocessed = FastAsciiConvert<false>(
reinterpret_cast<char*>(result->GetChars(no_gc)),
reinterpret_cast<const char*>(src.start()), length,
&has_changed_character);
if (index_to_first_unprocessed == length) {
return has_changed_character ? result : s;
}
@ -375,7 +377,7 @@ MaybeHandle<String> Intl::ConvertToUpper(Isolate* isolate, Handle<String> s) {
isolate->factory()->NewRawOneByteString(length + sharp_s_count),
String);
DisallowHeapAllocation no_gc;
String::FlatContent flat = s->GetFlatContent();
String::FlatContent flat = s->GetFlatContent(no_gc);
if (flat.IsOneByte()) {
ToUpperWithSharpS(flat.ToOneByteVector(), result);
} else {

View File

@ -256,7 +256,7 @@ class SeqOneByteSubStringKey : public StringTableKey {
// We have to set the hash later.
DisallowHeapAllocation no_gc;
uint32_t hash = StringHasher::HashSequentialString(
string->GetChars() + from, length, isolate->heap()->HashSeed());
string->GetChars(no_gc) + from, length, isolate->heap()->HashSeed());
set_hash_field(hash);
DCHECK_LE(0, length_);
@ -410,13 +410,13 @@ ConsString String::VisitFlat(Visitor* visitor, String string,
switch (type & (kStringRepresentationMask | kStringEncodingMask)) {
case kSeqStringTag | kOneByteStringTag:
visitor->VisitOneByteString(
SeqOneByteString::cast(string)->GetChars() + slice_offset,
SeqOneByteString::cast(string)->GetChars(no_gc) + slice_offset,
length - offset);
return ConsString();
case kSeqStringTag | kTwoByteStringTag:
visitor->VisitTwoByteString(
SeqTwoByteString::cast(string)->GetChars() + slice_offset,
SeqTwoByteString::cast(string)->GetChars(no_gc) + slice_offset,
length - offset);
return ConsString();
@ -456,15 +456,17 @@ ConsString String::VisitFlat(Visitor* visitor, String string,
}
template <>
inline Vector<const uint8_t> String::GetCharVector() {
String::FlatContent flat = GetFlatContent();
inline Vector<const uint8_t> String::GetCharVector(
const DisallowHeapAllocation& no_gc) {
String::FlatContent flat = GetFlatContent(no_gc);
DCHECK(flat.IsOneByte());
return flat.ToOneByteVector();
}
template <>
inline Vector<const uc16> String::GetCharVector() {
String::FlatContent flat = GetFlatContent();
inline Vector<const uc16> String::GetCharVector(
const DisallowHeapAllocation& no_gc) {
String::FlatContent flat = GetFlatContent(no_gc);
DCHECK(flat.IsTwoByte());
return flat.ToUC16Vector();
}
@ -491,8 +493,8 @@ Address SeqOneByteString::GetCharsAddress() {
return FIELD_ADDR(this, kHeaderSize);
}
uint8_t* SeqOneByteString::GetChars() {
DCHECK(!AllowHeapAllocation::IsAllowed());
uint8_t* SeqOneByteString::GetChars(const DisallowHeapAllocation& no_gc) {
USE(no_gc);
return reinterpret_cast<uint8_t*>(GetCharsAddress());
}
@ -500,8 +502,8 @@ Address SeqTwoByteString::GetCharsAddress() {
return FIELD_ADDR(this, kHeaderSize);
}
uc16* SeqTwoByteString::GetChars() {
DCHECK(!AllowHeapAllocation::IsAllowed());
uc16* SeqTwoByteString::GetChars(const DisallowHeapAllocation& no_gc) {
USE(no_gc);
return reinterpret_cast<uc16*>(FIELD_ADDR(this, kHeaderSize));
}
@ -750,10 +752,13 @@ bool String::AsArrayIndex(uint32_t* index) {
return SlowAsArrayIndex(index);
}
SubStringRange::SubStringRange(String string, int first, int length)
SubStringRange::SubStringRange(String string,
const DisallowHeapAllocation& no_gc, int first,
int length)
: string_(string),
first_(first),
length_(length == -1 ? string->length() : length) {}
length_(length == -1 ? string->length() : length),
no_gc_(no_gc) {}
class SubStringRange::iterator final {
public:
@ -781,18 +786,18 @@ class SubStringRange::iterator final {
private:
friend class String;
friend class SubStringRange;
iterator(String from, int offset)
: content_(from->GetFlatContent()), offset_(offset) {}
iterator(String from, int offset, const DisallowHeapAllocation& no_gc)
: content_(from->GetFlatContent(no_gc)), offset_(offset) {}
String::FlatContent content_;
int offset_;
};
SubStringRange::iterator SubStringRange::begin() {
return SubStringRange::iterator(string_, first_);
return SubStringRange::iterator(string_, first_, no_gc_);
}
SubStringRange::iterator SubStringRange::end() {
return SubStringRange::iterator(string_, first_ + length_);
return SubStringRange::iterator(string_, first_ + length_, no_gc_);
}
} // namespace internal

View File

@ -143,7 +143,8 @@ class String : public Name {
};
template <typename Char>
V8_INLINE Vector<const Char> GetCharVector();
V8_INLINE Vector<const Char> GetCharVector(
const DisallowHeapAllocation& no_gc);
// Get and set the length of the string.
inline int length() const;
@ -201,7 +202,7 @@ class String : public Name {
// If the string isn't flat, and therefore doesn't have flat content, the
// returned structure will report so, and can't provide a vector of either
// kind.
FlatContent GetFlatContent();
FlatContent GetFlatContent(const DisallowHeapAllocation& no_gc);
// Returns the parent of a sliced string or first part of a flat cons string.
// Requires: StringShape(this).IsIndirect() && this->IsFlat()
@ -456,7 +457,8 @@ class String : public Name {
class SubStringRange {
public:
explicit inline SubStringRange(String string, int first = 0, int length = -1);
inline SubStringRange(String string, const DisallowHeapAllocation& no_gc,
int first = 0, int length = -1);
class iterator;
inline iterator begin();
inline iterator end();
@ -465,6 +467,7 @@ class SubStringRange {
String string_;
int first_;
int length_;
const DisallowHeapAllocation& no_gc_;
};
// The SeqString abstract class captures sequential string values.
@ -502,7 +505,7 @@ class SeqOneByteString : public SeqString {
// Get the address of the characters in this string.
inline Address GetCharsAddress();
inline uint8_t* GetChars();
inline uint8_t* GetChars(const DisallowHeapAllocation& no_gc);
// Clear uninitialized padding space. This ensures that the snapshot content
// is deterministic.
@ -543,7 +546,7 @@ class SeqTwoByteString : public SeqString {
// Get the address of the characters in this string.
inline Address GetCharsAddress();
inline uc16* GetChars();
inline uc16* GetChars(const DisallowHeapAllocation& no_gc);
// Clear uninitialized padding space. This ensures that the snapshot content
// is deterministic.

View File

@ -88,9 +88,12 @@ class OnHeapStream {
UNREACHABLE();
}
Range<Char> GetDataAt(size_t pos, RuntimeCallStats* stats) {
return {&string_->GetChars()[start_offset_ + Min(length_, pos)],
&string_->GetChars()[start_offset_ + length_]};
// The no_gc argument is only here because of the templated way this class
// is used along with other implementations that require V8 heap access.
Range<Char> GetDataAt(size_t pos, RuntimeCallStats* stats,
DisallowHeapAllocation* no_gc) {
return {&string_->GetChars(*no_gc)[start_offset_ + Min(length_, pos)],
&string_->GetChars(*no_gc)[start_offset_ + length_]};
}
static const bool kCanBeCloned = false;
@ -118,7 +121,10 @@ class ExternalStringStream {
ExternalStringStream(const ExternalStringStream& other)
: lock_(other.lock_), data_(other.data_), length_(other.length_) {}
Range<Char> GetDataAt(size_t pos, RuntimeCallStats* stats) {
// The no_gc argument is only here because of the templated way this class
// is used along with other implementations that require V8 heap access.
Range<Char> GetDataAt(size_t pos, RuntimeCallStats* stats,
DisallowHeapAllocation* no_gc = nullptr) {
return {&data_[Min(length_, pos)], &data_[length_]};
}
@ -137,7 +143,10 @@ class TestingStream {
public:
TestingStream(const Char* data, size_t length)
: data_(data), length_(length) {}
Range<Char> GetDataAt(size_t pos, RuntimeCallStats* stats) {
// The no_gc argument is only here because of the templated way this class
// is used along with other implementations that require V8 heap access.
Range<Char> GetDataAt(size_t pos, RuntimeCallStats* stats,
DisallowHeapAllocation* no_gc = nullptr) {
return {&data_[Min(length_, pos)], &data_[length_]};
}
@ -161,7 +170,10 @@ class ChunkedStream {
UNREACHABLE();
}
Range<Char> GetDataAt(size_t pos, RuntimeCallStats* stats) {
// The no_gc argument is only here because of the templated way this class
// is used along with other implementations that require V8 heap access.
Range<Char> GetDataAt(size_t pos, RuntimeCallStats* stats,
DisallowHeapAllocation* no_gc = nullptr) {
Chunk chunk = FindChunk(pos, stats);
size_t buffer_end = chunk.length;
size_t buffer_pos = Min(buffer_end, pos - chunk.position);
@ -259,7 +271,7 @@ class BufferedCharacterStream : public Utf16CharacterStream {
DisallowHeapAllocation no_gc;
Range<uint8_t> range =
byte_stream_.GetDataAt(position, runtime_call_stats());
byte_stream_.GetDataAt(position, runtime_call_stats(), &no_gc);
if (range.length() == 0) {
buffer_end_ = buffer_start_;
return false;
@ -313,7 +325,7 @@ class UnbufferedCharacterStream : public Utf16CharacterStream {
buffer_pos_ = position;
DisallowHeapAllocation no_gc;
Range<uint16_t> range =
byte_stream_.GetDataAt(position, runtime_call_stats());
byte_stream_.GetDataAt(position, runtime_call_stats(), &no_gc);
buffer_start_ = range.start;
buffer_end_ = range.end;
buffer_cursor_ = buffer_start_;
@ -359,7 +371,8 @@ class RelocatingCharacterStream
void UpdateBufferPointers() {
DisallowHeapAllocation no_gc;
Range<uint16_t> range = byte_stream_.GetDataAt(0, runtime_call_stats());
Range<uint16_t> range =
byte_stream_.GetDataAt(0, runtime_call_stats(), &no_gc);
if (range.start != buffer_start_) {
buffer_cursor_ = (buffer_cursor_ - buffer_start_) + range.start;
buffer_start_ = range.start;

View File

@ -291,12 +291,13 @@ size_t GetScriptNameLength(const SourcePositionInfo& info) {
}
Vector<const char> GetScriptName(const SourcePositionInfo& info,
std::unique_ptr<char[]>* storage) {
std::unique_ptr<char[]>* storage,
const DisallowHeapAllocation& no_gc) {
if (!info.script.is_null()) {
Object* name_or_url = info.script->GetNameOrSourceURL();
if (name_or_url->IsSeqOneByteString()) {
SeqOneByteString str = SeqOneByteString::cast(name_or_url);
return {reinterpret_cast<char*>(str->GetChars()),
return {reinterpret_cast<char*>(str->GetChars(no_gc)),
static_cast<size_t>(str->length())};
} else if (name_or_url->IsString()) {
int length;
@ -377,7 +378,7 @@ void PerfJitLogger::LogWriteDebugInfo(Code code, SharedFunctionInfo shared) {
// The extracted name may point into heap-objects, thus disallow GC.
DisallowHeapAllocation no_gc;
std::unique_ptr<char[]> name_storage;
Vector<const char> name_string = GetScriptName(info, &name_storage);
Vector<const char> name_string = GetScriptName(info, &name_storage, no_gc);
LogWriteBytes(name_string.start(),
static_cast<uint32_t>(name_string.size()) + 1);
}

View File

@ -598,7 +598,7 @@ RegExpImpl::IrregexpResult IrregexpInterpreter::Match(
DisallowHeapAllocation no_gc;
const byte* code_base = code_array->GetDataStartAddress();
uc16 previous_char = '\n';
String::FlatContent subject_content = subject->GetFlatContent();
String::FlatContent subject_content = subject->GetFlatContent(no_gc);
if (subject_content.IsOneByte()) {
Vector<const uint8_t> subject_vector = subject_content.ToOneByteVector();
if (start_position != 0) previous_char = subject_vector[start_position - 1];

View File

@ -240,8 +240,8 @@ int RegExpImpl::AtomExecRaw(Isolate* isolate, Handle<JSRegExp> regexp,
}
for (int i = 0; i < output_size; i += 2) {
String::FlatContent needle_content = needle->GetFlatContent();
String::FlatContent subject_content = subject->GetFlatContent();
String::FlatContent needle_content = needle->GetFlatContent(no_gc);
String::FlatContent subject_content = subject->GetFlatContent(no_gc);
DCHECK(needle_content.IsFlat());
DCHECK(subject_content.IsFlat());
// dispatch on type of strings

View File

@ -121,7 +121,7 @@ bool NativeRegExpMacroAssembler::CanReadUnaligned() {
}
const byte* NativeRegExpMacroAssembler::StringCharacterPosition(
String subject, int start_index) {
String subject, int start_index, const DisallowHeapAllocation& no_gc) {
if (subject->IsConsString()) {
subject = ConsString::cast(subject)->first();
} else if (subject->IsSlicedString()) {
@ -135,10 +135,10 @@ const byte* NativeRegExpMacroAssembler::StringCharacterPosition(
DCHECK_LE(start_index, subject->length());
if (subject->IsSeqOneByteString()) {
return reinterpret_cast<const byte*>(
SeqOneByteString::cast(subject)->GetChars() + start_index);
SeqOneByteString::cast(subject)->GetChars(no_gc) + start_index);
} else if (subject->IsSeqTwoByteString()) {
return reinterpret_cast<const byte*>(
SeqTwoByteString::cast(subject)->GetChars() + start_index);
SeqTwoByteString::cast(subject)->GetChars(no_gc) + start_index);
} else if (subject->IsExternalOneByteString()) {
return reinterpret_cast<const byte*>(
ExternalOneByteString::cast(subject)->GetChars() + start_index);
@ -200,7 +200,8 @@ int NativeRegExpMacroAssembler::CheckStackGuardState(
} else {
*subject = subject_handle->ptr();
intptr_t byte_length = *input_end - *input_start;
*input_start = StringCharacterPosition(*subject_handle, start_index);
*input_start =
StringCharacterPosition(*subject_handle, start_index, no_gc);
*input_end = *input_start + byte_length;
}
}
@ -250,7 +251,7 @@ NativeRegExpMacroAssembler::Result NativeRegExpMacroAssembler::Match(
DisallowHeapAllocation no_gc;
const byte* input_start =
StringCharacterPosition(subject_ptr, start_offset + slice_offset);
StringCharacterPosition(subject_ptr, start_offset + slice_offset, no_gc);
int byte_length = char_length << char_size_shift;
const byte* input_end = input_start + byte_length;
Result res = Execute(*regexp_code,

View File

@ -230,7 +230,8 @@ class NativeRegExpMacroAssembler: public RegExpMacroAssembler {
static Address GrowStack(Address stack_pointer, Address* stack_top,
Isolate* isolate);
static const byte* StringCharacterPosition(String subject, int start_index);
static const byte* StringCharacterPosition(
String subject, int start_index, const DisallowHeapAllocation& no_gc);
static int CheckStackGuardState(Isolate* isolate, int start_index,
bool is_direct_call, Address* return_address,

View File

@ -497,7 +497,8 @@ RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) {
if (args[0]->IsString()) {
// With a string argument, the results are appended to that file.
CONVERT_ARG_HANDLE_CHECKED(String, arg0, 0);
String::FlatContent flat = arg0->GetFlatContent();
DisallowHeapAllocation no_gc;
String::FlatContent flat = arg0->GetFlatContent(no_gc);
const char* filename =
reinterpret_cast<const char*>(&(flat.ToOneByteVector()[0]));
f = std::fopen(filename, "a");

View File

@ -316,7 +316,7 @@ bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp,
int subject_length) {
{
DisallowHeapAllocation no_gc;
String::FlatContent content = replacement->GetFlatContent();
String::FlatContent content = replacement->GetFlatContent(no_gc);
DCHECK(content.IsFlat());
FixedArray capture_name_map;
@ -454,8 +454,8 @@ void FindStringIndicesDispatch(Isolate* isolate, String subject, String pattern,
std::vector<int>* indices, unsigned int limit) {
{
DisallowHeapAllocation no_gc;
String::FlatContent subject_content = subject->GetFlatContent();
String::FlatContent pattern_content = pattern->GetFlatContent();
String::FlatContent subject_content = subject->GetFlatContent(no_gc);
String::FlatContent pattern_content = pattern->GetFlatContent(no_gc);
DCHECK(subject_content.IsFlat());
DCHECK(pattern_content.IsFlat());
if (subject_content.IsOneByte()) {
@ -573,14 +573,14 @@ V8_WARN_UNUSED_RESULT static Object* StringReplaceGlobalAtomRegExpWithString(
for (int index : *indices) {
// Copy non-matched subject content.
if (subject_pos < index) {
String::WriteToFlat(*subject, result->GetChars() + result_pos,
String::WriteToFlat(*subject, result->GetChars(no_gc) + result_pos,
subject_pos, index);
result_pos += index - subject_pos;
}
// Replace match.
if (replacement_len > 0) {
String::WriteToFlat(*replacement, result->GetChars() + result_pos, 0,
String::WriteToFlat(*replacement, result->GetChars(no_gc) + result_pos, 0,
replacement_len);
result_pos += replacement_len;
}
@ -589,8 +589,8 @@ V8_WARN_UNUSED_RESULT static Object* StringReplaceGlobalAtomRegExpWithString(
}
// Add remaining subject content at the end.
if (subject_pos < subject_len) {
String::WriteToFlat(*subject, result->GetChars() + result_pos, subject_pos,
subject_len);
String::WriteToFlat(*subject, result->GetChars(no_gc) + result_pos,
subject_pos, subject_len);
}
int32_t match_indices[] = {indices->back(), indices->back() + pattern_len};
@ -745,7 +745,8 @@ V8_WARN_UNUSED_RESULT static Object* StringReplaceGlobalRegExpWithEmptyString(
end = current_match[1];
if (prev < start) {
// Add substring subject[prev;start] to answer string.
String::WriteToFlat(*subject, answer->GetChars() + position, prev, start);
String::WriteToFlat(*subject, answer->GetChars(no_gc) + position, prev,
start);
position += start - prev;
}
prev = end;
@ -760,7 +761,7 @@ V8_WARN_UNUSED_RESULT static Object* StringReplaceGlobalRegExpWithEmptyString(
if (prev < subject_length) {
// Add substring subject[prev;length] to answer string.
String::WriteToFlat(*subject, answer->GetChars() + position, prev,
String::WriteToFlat(*subject, answer->GetChars(no_gc) + position, prev,
subject_length);
position += subject_length - prev;
}

View File

@ -328,7 +328,7 @@ RUNTIME_FUNCTION(Runtime_StringBuilderConcat) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, answer, isolate->factory()->NewRawOneByteString(length));
DisallowHeapAllocation no_gc;
StringBuilderConcatHelper(*special, answer->GetChars(),
StringBuilderConcatHelper(*special, answer->GetChars(no_gc),
FixedArray::cast(array->elements()),
array_length);
return *answer;
@ -337,7 +337,7 @@ RUNTIME_FUNCTION(Runtime_StringBuilderConcat) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, answer, isolate->factory()->NewRawTwoByteString(length));
DisallowHeapAllocation no_gc;
StringBuilderConcatHelper(*special, answer->GetChars(),
StringBuilderConcatHelper(*special, answer->GetChars(no_gc),
FixedArray::cast(array->elements()),
array_length);
return *answer;
@ -397,7 +397,7 @@ RUNTIME_FUNCTION(Runtime_StringBuilderJoin) {
DisallowHeapAllocation no_gc;
uc16* sink = answer->GetChars();
uc16* sink = answer->GetChars(no_gc);
#ifdef DEBUG
uc16* end = sink + length;
#endif
@ -558,7 +558,7 @@ RUNTIME_FUNCTION(Runtime_SparseJoinWithSeparator) {
JoinSparseArrayWithSeparator<uint8_t>(
FixedArray::cast(elements_array->elements()), elements_length,
array_length, *separator,
Vector<uint8_t>(result->GetChars(), string_length));
Vector<uint8_t>(result->GetChars(no_gc), string_length));
return *result;
} else {
Handle<SeqTwoByteString> result = isolate->factory()
@ -568,7 +568,7 @@ RUNTIME_FUNCTION(Runtime_SparseJoinWithSeparator) {
JoinSparseArrayWithSeparator<uc16>(
FixedArray::cast(elements_array->elements()), elements_length,
array_length, *separator,
Vector<uc16>(result->GetChars(), string_length));
Vector<uc16>(result->GetChars(no_gc), string_length));
return *result;
}
}
@ -623,7 +623,7 @@ RUNTIME_FUNCTION(Runtime_StringToArray) {
elements = isolate->factory()->NewUninitializedFixedArray(length);
DisallowHeapAllocation no_gc;
String::FlatContent content = s->GetFlatContent();
String::FlatContent content = s->GetFlatContent(no_gc);
if (content.IsOneByte()) {
Vector<const uint8_t> chars = content.ToOneByteVector();
// Note, this will initialize all elements (not only the prefix)

View File

@ -182,14 +182,15 @@ class IncrementalStringBuilder {
template <typename DestChar>
class NoExtend {
public:
explicit NoExtend(Handle<String> string, int offset) {
NoExtend(Handle<String> string, int offset,
const DisallowHeapAllocation& no_gc) {
DCHECK(string->IsSeqOneByteString() || string->IsSeqTwoByteString());
if (sizeof(DestChar) == 1) {
start_ = reinterpret_cast<DestChar*>(
Handle<SeqOneByteString>::cast(string)->GetChars() + offset);
Handle<SeqOneByteString>::cast(string)->GetChars(no_gc) + offset);
} else {
start_ = reinterpret_cast<DestChar*>(
Handle<SeqTwoByteString>::cast(string)->GetChars() + offset);
Handle<SeqTwoByteString>::cast(string)->GetChars(no_gc) + offset);
}
cursor_ = start_;
}
@ -231,8 +232,10 @@ class IncrementalStringBuilder {
template <typename DestChar>
class NoExtendBuilder : public NoExtend<DestChar> {
public:
NoExtendBuilder(IncrementalStringBuilder* builder, int required_length)
: NoExtend<DestChar>(builder->current_part(), builder->current_index_),
NoExtendBuilder(IncrementalStringBuilder* builder, int required_length,
const DisallowHeapAllocation& no_gc)
: NoExtend<DestChar>(builder->current_part(), builder->current_index_,
no_gc),
builder_(builder) {
DCHECK(builder->CurrentPartCanFit(required_length));
}

View File

@ -203,7 +203,7 @@ MaybeHandle<String> ReplacementStringBuilder::ToString() {
String);
DisallowHeapAllocation no_gc;
uint8_t* char_buffer = seq->GetChars();
uint8_t* char_buffer = seq->GetChars(no_gc);
StringBuilderConcatHelper(*subject_, char_buffer, *array_builder_.array(),
array_builder_.length());
joined_string = Handle<String>::cast(seq);
@ -215,7 +215,7 @@ MaybeHandle<String> ReplacementStringBuilder::ToString() {
String);
DisallowHeapAllocation no_gc;
uc16* char_buffer = seq->GetChars();
uc16* char_buffer = seq->GetChars(no_gc);
StringBuilderConcatHelper(*subject_, char_buffer, *array_builder_.array(),
array_builder_.length());
joined_string = Handle<String>::cast(seq);

View File

@ -138,7 +138,7 @@ bool IntoOneAndTwoByte(Handle<String> uri, bool is_uri,
std::vector<uint8_t>* one_byte_buffer,
std::vector<uc16>* two_byte_buffer) {
DisallowHeapAllocation no_gc;
String::FlatContent uri_content = uri->GetFlatContent();
String::FlatContent uri_content = uri->GetFlatContent(no_gc);
int uri_length = uri->length();
for (int k = 0; k < uri_length; k++) {
@ -195,9 +195,10 @@ MaybeHandle<String> Uri::Decode(Isolate* isolate, Handle<String> uri,
String);
DisallowHeapAllocation no_gc;
CopyChars(result->GetChars(), one_byte_buffer.data(), one_byte_buffer.size());
CopyChars(result->GetChars() + one_byte_buffer.size(), two_byte_buffer.data(),
two_byte_buffer.size());
CopyChars(result->GetChars(no_gc), one_byte_buffer.data(),
one_byte_buffer.size());
CopyChars(result->GetChars(no_gc) + one_byte_buffer.size(),
two_byte_buffer.data(), two_byte_buffer.size());
return result;
}
@ -280,7 +281,7 @@ MaybeHandle<String> Uri::Encode(Isolate* isolate, Handle<String> uri,
{
DisallowHeapAllocation no_gc;
String::FlatContent uri_content = uri->GetFlatContent();
String::FlatContent uri_content = uri->GetFlatContent(no_gc);
for (int k = 0; k < uri_length; k++) {
uc16 cc1 = uri_content.Get(k);
@ -342,7 +343,7 @@ MaybeHandle<String> UnescapeSlow(Isolate* isolate, Handle<String> string,
int unescaped_length = 0;
{
DisallowHeapAllocation no_allocation;
Vector<const Char> vector = string->GetCharVector<Char>();
Vector<const Char> vector = string->GetCharVector<Char>(no_allocation);
for (int i = start_index; i < length; unescaped_length++) {
int step;
if (UnescapeChar(vector, i, length, &step) >
@ -365,7 +366,7 @@ MaybeHandle<String> UnescapeSlow(Isolate* isolate, Handle<String> string,
->NewRawOneByteString(unescaped_length)
.ToHandleChecked();
DisallowHeapAllocation no_allocation;
Vector<const Char> vector = string->GetCharVector<Char>();
Vector<const Char> vector = string->GetCharVector<Char>(no_allocation);
for (int i = start_index; i < length; dest_position++) {
int step;
dest->SeqOneByteStringSet(dest_position,
@ -378,7 +379,7 @@ MaybeHandle<String> UnescapeSlow(Isolate* isolate, Handle<String> string,
->NewRawTwoByteString(unescaped_length)
.ToHandleChecked();
DisallowHeapAllocation no_allocation;
Vector<const Char> vector = string->GetCharVector<Char>();
Vector<const Char> vector = string->GetCharVector<Char>(no_allocation);
for (int i = start_index; i < length; dest_position++) {
int step;
dest->SeqTwoByteStringSet(dest_position,
@ -416,7 +417,7 @@ static MaybeHandle<String> UnescapePrivate(Isolate* isolate,
{
DisallowHeapAllocation no_allocation;
StringSearch<uint8_t, Char> search(isolate, STATIC_CHAR_VECTOR("%"));
index = search.Search(source->GetCharVector<Char>(), 0);
index = search.Search(source->GetCharVector<Char>(no_allocation), 0);
if (index < 0) return source;
}
return UnescapeSlow<Char>(isolate, source, index);
@ -431,7 +432,7 @@ static MaybeHandle<String> EscapePrivate(Isolate* isolate,
{
DisallowHeapAllocation no_allocation;
Vector<const Char> vector = string->GetCharVector<Char>();
Vector<const Char> vector = string->GetCharVector<Char>(no_allocation);
for (int i = 0; i < length; i++) {
uint16_t c = vector[i];
if (c >= 256) {
@ -459,7 +460,7 @@ static MaybeHandle<String> EscapePrivate(Isolate* isolate,
{
DisallowHeapAllocation no_allocation;
Vector<const Char> vector = string->GetCharVector<Char>();
Vector<const Char> vector = string->GetCharVector<Char>(no_allocation);
for (int i = 0; i < length; i++) {
uint16_t c = vector[i];
if (c >= 256) {

View File

@ -439,7 +439,7 @@ void ValueSerializer::WriteBigInt(BigInt bigint) {
void ValueSerializer::WriteString(Handle<String> string) {
string = String::Flatten(isolate_, string);
DisallowHeapAllocation no_gc;
String::FlatContent flat = string->GetFlatContent();
String::FlatContent flat = string->GetFlatContent(no_gc);
DCHECK(flat.IsFlat());
if (flat.IsOneByte()) {
Vector<const uint8_t> chars = flat.ToOneByteVector();
@ -1332,7 +1332,7 @@ MaybeHandle<String> ValueDeserializer::ReadTwoByteString() {
// Copy the bytes directly into the new string.
// Warning: this uses host endianness.
DisallowHeapAllocation no_gc;
memcpy(string->GetChars(), bytes.begin(), bytes.length());
memcpy(string->GetChars(no_gc), bytes.begin(), bytes.length());
return string;
}
@ -1352,7 +1352,7 @@ bool ValueDeserializer::ReadExpectedString(Handle<String> expected) {
return false;
}
String::FlatContent flat = expected->GetFlatContent();
String::FlatContent flat = expected->GetFlatContent(no_gc);
// If the bytes are verbatim what is in the flattened string, then the string
// is successfully consumed.

View File

@ -2143,7 +2143,8 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
v8::Maybe<bool> status = JSReceiver::DefineOwnProperty(
isolate_, export_to, name, &desc, kThrowOnError);
if (!status.IsJust()) {
TruncatedUserString<> trunc_name(name->GetCharVector<uint8_t>());
DisallowHeapAllocation no_gc;
TruncatedUserString<> trunc_name(name->GetCharVector<uint8_t>(no_gc));
thrower_->LinkError("export of %.*s failed.", trunc_name.length(),
trunc_name.start());
return;

View File

@ -1788,16 +1788,16 @@ TEST(OneToTwoByteStringCopy) {
FunctionTester ft(asm_tester.GenerateCode(), kNumParams);
ft.Call(string1, string2);
DisallowHeapAllocation no_gc;
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[0],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[0]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[1],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[1]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[2],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[2]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[3],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[3]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[4],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[4]);
}
TEST(OneToOneByteStringCopy) {
@ -1820,16 +1820,16 @@ TEST(OneToOneByteStringCopy) {
FunctionTester ft(asm_tester.GenerateCode(), kNumParams);
ft.Call(string1, string2);
DisallowHeapAllocation no_gc;
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
Handle<SeqOneByteString>::cast(string2)->GetChars()[0]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
Handle<SeqOneByteString>::cast(string2)->GetChars()[1]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2],
Handle<SeqOneByteString>::cast(string2)->GetChars()[2]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3],
Handle<SeqOneByteString>::cast(string2)->GetChars()[3]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4],
Handle<SeqOneByteString>::cast(string2)->GetChars()[4]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[0],
Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[0]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[1],
Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[1]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[2],
Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[2]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[3],
Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[3]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[4],
Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[4]);
}
TEST(OneToOneByteStringCopyNonZeroStart) {
@ -1852,13 +1852,13 @@ TEST(OneToOneByteStringCopyNonZeroStart) {
FunctionTester ft(asm_tester.GenerateCode(), kNumParams);
ft.Call(string1, string2);
DisallowHeapAllocation no_gc;
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
Handle<SeqOneByteString>::cast(string2)->GetChars()[3]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
Handle<SeqOneByteString>::cast(string2)->GetChars()[4]);
CHECK_EQ(100, Handle<SeqOneByteString>::cast(string2)->GetChars()[0]);
CHECK_EQ(101, Handle<SeqOneByteString>::cast(string2)->GetChars()[1]);
CHECK_EQ(102, Handle<SeqOneByteString>::cast(string2)->GetChars()[2]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[0],
Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[3]);
CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars(no_gc)[1],
Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[4]);
CHECK_EQ(100, Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[0]);
CHECK_EQ(101, Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[1]);
CHECK_EQ(102, Handle<SeqOneByteString>::cast(string2)->GetChars(no_gc)[2]);
}
TEST(TwoToTwoByteStringCopy) {
@ -1884,16 +1884,16 @@ TEST(TwoToTwoByteStringCopy) {
FunctionTester ft(asm_tester.GenerateCode(), kNumParams);
ft.Call(string1, string2);
DisallowHeapAllocation no_gc;
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[0],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]);
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4],
Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars(no_gc)[0],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[0]);
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars(no_gc)[1],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[1]);
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars(no_gc)[2],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[2]);
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars(no_gc)[3],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[3]);
CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars(no_gc)[4],
Handle<SeqTwoByteString>::cast(string2)->GetChars(no_gc)[4]);
}
TEST(Arguments) {

View File

@ -71,7 +71,7 @@ static void CheckFunctionName(v8::Local<v8::Script> script,
{
i::DisallowHeapAllocation no_gc;
Vector<const uint8_t> func_pos_str = i::OneByteVector(func_pos_src);
i::String::FlatContent script_content = script_src->GetFlatContent();
i::String::FlatContent script_content = script_src->GetFlatContent(no_gc);
func_pos = SearchString(isolate, script_content.ToOneByteVector(),
func_pos_str, 0);
}

View File

@ -917,7 +917,7 @@ void TestScanRegExp(const char* re_source, const char* expected) {
ast_value_factory.Internalize(CcTest::i_isolate());
i::Handle<i::String> val = current_symbol->string();
i::DisallowHeapAllocation no_alloc;
i::String::FlatContent content = val->GetFlatContent();
i::String::FlatContent content = val->GetFlatContent(no_alloc);
CHECK(content.IsOneByte());
i::Vector<const uint8_t> actual = content.ToOneByteVector();
for (int i = 0; i < actual.length(); i++) {

View File

@ -1813,7 +1813,7 @@ TEST(Regress876759) {
Handle<SeqTwoByteString> raw =
factory->NewRawTwoByteString(kLength).ToHandleChecked();
DisallowHeapAllocation no_gc;
CopyChars(raw->GetChars(), two_byte_buf, kLength);
CopyChars(raw->GetChars(no_gc), two_byte_buf, kLength);
parent = raw;
}
CHECK(parent->IsTwoByteRepresentation());