Skip to content

Commit

Permalink
[ABI-stability] Fix some reverts
Browse files Browse the repository at this point in the history
- constness of internal APIs has not external effect
- restored API function must but adapted to moved internal API.
  • Loading branch information
targos committed Jul 25, 2021
1 parent 251ed9c commit 21011eb
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 67 deletions.
3 changes: 2 additions & 1 deletion src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5128,7 +5128,8 @@ Local<Value> Function::GetDisplayName() const {
}
auto func = i::Handle<i::JSFunction>::cast(self);
i::Handle<i::String> property_name =
isolate->factory()->InternalizeString(i::StaticCharVector("displayName"));
isolate->factory()->InternalizeString(
base::StaticCharVector("displayName"));
i::Handle<i::Object> value =
i::JSReceiver::GetDataProperty(func, property_name);
if (value->IsString()) {
Expand Down
66 changes: 35 additions & 31 deletions src/objects/string-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,49 +133,51 @@ StringShape::StringShape(InstanceType t) : type_(static_cast<uint32_t>(t)) {
DCHECK_EQ(type_ & kIsNotStringMask, kStringTag);
}

bool StringShape::IsInternalized() {
bool StringShape::IsInternalized() const {
DCHECK(valid());
STATIC_ASSERT(kNotInternalizedTag != 0);
return (type_ & (kIsNotStringMask | kIsNotInternalizedMask)) ==
(kStringTag | kInternalizedTag);
}

bool StringShape::IsCons() {
bool StringShape::IsCons() const {
return (type_ & kStringRepresentationMask) == kConsStringTag;
}

bool StringShape::IsThin() {
bool StringShape::IsThin() const {
return (type_ & kStringRepresentationMask) == kThinStringTag;
}

bool StringShape::IsSliced() {
bool StringShape::IsSliced() const {
return (type_ & kStringRepresentationMask) == kSlicedStringTag;
}

bool StringShape::IsIndirect() {
bool StringShape::IsIndirect() const {
return (type_ & kIsIndirectStringMask) == kIsIndirectStringTag;
}

bool StringShape::IsExternal() {
bool StringShape::IsExternal() const {
return (type_ & kStringRepresentationMask) == kExternalStringTag;
}

bool StringShape::IsSequential() {
bool StringShape::IsSequential() const {
return (type_ & kStringRepresentationMask) == kSeqStringTag;
}

bool StringShape::IsUncachedExternal() {
bool StringShape::IsUncachedExternal() const {
return (type_ & kUncachedExternalStringMask) == kUncachedExternalStringTag;
}

StringRepresentationTag StringShape::representation_tag() {
StringRepresentationTag StringShape::representation_tag() const {
uint32_t tag = (type_ & kStringRepresentationMask);
return static_cast<StringRepresentationTag>(tag);
}

uint32_t StringShape::encoding_tag() { return type_ & kStringEncodingMask; }
uint32_t StringShape::encoding_tag() const {
return type_ & kStringEncodingMask;
}

uint32_t StringShape::full_representation_tag() {
uint32_t StringShape::full_representation_tag() const {
return (type_ & (kStringRepresentationMask | kStringEncodingMask));
}

Expand All @@ -185,15 +187,15 @@ STATIC_ASSERT((kStringRepresentationMask | kStringEncodingMask) ==
STATIC_ASSERT(static_cast<uint32_t>(kStringEncodingMask) ==
Internals::kStringEncodingMask);

bool StringShape::IsSequentialOneByte() {
bool StringShape::IsSequentialOneByte() const {
return full_representation_tag() == (kSeqStringTag | kOneByteStringTag);
}

bool StringShape::IsSequentialTwoByte() {
bool StringShape::IsSequentialTwoByte() const {
return full_representation_tag() == (kSeqStringTag | kTwoByteStringTag);
}

bool StringShape::IsExternalOneByte() {
bool StringShape::IsExternalOneByte() const {
return full_representation_tag() == (kExternalStringTag | kOneByteStringTag);
}

Expand All @@ -202,7 +204,7 @@ STATIC_ASSERT((kExternalStringTag | kOneByteStringTag) ==

STATIC_ASSERT(v8::String::ONE_BYTE_ENCODING == kOneByteStringTag);

bool StringShape::IsExternalTwoByte() {
bool StringShape::IsExternalTwoByte() const {
return full_representation_tag() == (kExternalStringTag | kTwoByteStringTag);
}

Expand Down Expand Up @@ -298,7 +300,7 @@ bool String::IsOneByteRepresentationUnderneath(String string) {
}
}

base::uc32 FlatStringReader::Get(int index) {
base::uc32 FlatStringReader::Get(int index) const {
if (is_one_byte_) {
return Get<uint8_t>(index);
} else {
Expand All @@ -307,7 +309,7 @@ base::uc32 FlatStringReader::Get(int index) {
}

template <typename Char>
Char FlatStringReader::Get(int index) {
Char FlatStringReader::Get(int index) const {
DCHECK_EQ(is_one_byte_, sizeof(Char) == 1);
DCHECK(0 <= index && index < length_);
if (sizeof(Char) == 1) {
Expand Down Expand Up @@ -433,14 +435,15 @@ class SeqSubStringKey final : public StringTableKey {
using SeqOneByteSubStringKey = SeqSubStringKey<SeqOneByteString>;
using SeqTwoByteSubStringKey = SeqSubStringKey<SeqTwoByteString>;

bool String::Equals(String other) {
bool String::Equals(String other) const {
if (other == *this) return true;
if (this->IsInternalizedString() && other.IsInternalizedString()) {
return false;
}
return SlowEquals(other);
}

// static
bool String::Equals(Isolate* isolate, Handle<String> one, Handle<String> two) {
if (one.is_identical_to(two)) return true;
if (one->IsInternalizedString() && two->IsInternalizedString()) {
Expand Down Expand Up @@ -577,7 +580,7 @@ bool String::IsOneByteEqualTo(base::Vector<const char> str) {
}

template <typename Char>
const Char* String::GetChars(const DisallowGarbageCollection& no_gc) {
const Char* String::GetChars(const DisallowGarbageCollection& no_gc) const {
DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this));
return StringShape(*this).IsExternal()
? CharTraits<Char>::ExternalString::cast(*this).GetChars()
Expand All @@ -587,7 +590,7 @@ const Char* String::GetChars(const DisallowGarbageCollection& no_gc) {
template <typename Char>
const Char* String::GetChars(
const DisallowGarbageCollection& no_gc,
const SharedStringAccessGuardIfNeeded& access_guard) {
const SharedStringAccessGuardIfNeeded& access_guard) const {
return StringShape(*this).IsExternal()
? CharTraits<Char>::ExternalString::cast(*this).GetChars()
: CharTraits<Char>::String::cast(*this).GetChars(no_gc,
Expand Down Expand Up @@ -623,7 +626,7 @@ uint16_t String::Get(int index, Isolate* isolate) const {
return GetImpl(index, scope);
}

uint16_t String::Get(int index, LocalIsolate* local_isolate) {
uint16_t String::Get(int index, LocalIsolate* local_isolate) const {
SharedStringAccessGuardIfNeeded scope(local_isolate);
return GetImpl(index, scope);
}
Expand Down Expand Up @@ -668,12 +671,12 @@ void String::Set(int index, uint16_t value) {
: SeqTwoByteString::cast(*this).SeqTwoByteStringSet(index, value);
}

bool String::IsFlat() {
bool String::IsFlat() const {
if (!StringShape(*this).IsCons()) return true;
return ConsString::cast(*this).second().length() == 0;
}

String String::GetUnderlying() {
String String::GetUnderlying() const {
// Giving direct access to underlying string only makes sense if the
// wrapping string is already flattened.
DCHECK(this->IsFlat());
Expand Down Expand Up @@ -787,38 +790,39 @@ void SeqOneByteString::SeqOneByteStringSet(int index, uint16_t value) {
WriteField<byte>(kHeaderSize + index * kCharSize, static_cast<byte>(value));
}

Address SeqOneByteString::GetCharsAddress() {
Address SeqOneByteString::GetCharsAddress() const {
return field_address(kHeaderSize);
}

uint8_t* SeqOneByteString::GetChars(const DisallowGarbageCollection& no_gc) {
uint8_t* SeqOneByteString::GetChars(
const DisallowGarbageCollection& no_gc) const {
USE(no_gc);
DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this));
return reinterpret_cast<uint8_t*>(GetCharsAddress());
}

uint8_t* SeqOneByteString::GetChars(
const DisallowGarbageCollection& no_gc,
const SharedStringAccessGuardIfNeeded& access_guard) {
const SharedStringAccessGuardIfNeeded& access_guard) const {
USE(no_gc);
USE(access_guard);
return reinterpret_cast<uint8_t*>(GetCharsAddress());
}

Address SeqTwoByteString::GetCharsAddress() {
Address SeqTwoByteString::GetCharsAddress() const {
return field_address(kHeaderSize);
}

base::uc16* SeqTwoByteString::GetChars(
const DisallowGarbageCollection& no_gc) {
const DisallowGarbageCollection& no_gc) const {
USE(no_gc);
DCHECK(!SharedStringAccessGuardIfNeeded::IsNeeded(*this));
return reinterpret_cast<base::uc16*>(GetCharsAddress());
}

base::uc16* SeqTwoByteString::GetChars(
const DisallowGarbageCollection& no_gc,
const SharedStringAccessGuardIfNeeded& access_guard) {
const SharedStringAccessGuardIfNeeded& access_guard) const {
USE(no_gc);
USE(access_guard);
return reinterpret_cast<base::uc16*>(GetCharsAddress());
Expand Down Expand Up @@ -954,7 +958,7 @@ void ExternalOneByteString::set_resource(
if (resource != nullptr) update_data_cache(isolate);
}

const uint8_t* ExternalOneByteString::GetChars() {
const uint8_t* ExternalOneByteString::GetChars() const {
DisallowGarbageCollection no_gc;
if (is_uncached()) {
if (resource()->IsCacheable()) {
Expand Down Expand Up @@ -1021,7 +1025,7 @@ void ExternalTwoByteString::set_resource(
if (resource != nullptr) update_data_cache(isolate);
}

const uint16_t* ExternalTwoByteString::GetChars() {
const uint16_t* ExternalTwoByteString::GetChars() const {
DisallowGarbageCollection no_gc;
if (is_uncached()) {
if (resource()->IsCacheable()) {
Expand Down
3 changes: 2 additions & 1 deletion src/objects/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ template Handle<FixedArray> String::CalculateLineEnds(LocalIsolate* isolate,
Handle<String> src,
bool include_ending_line);

bool String::SlowEquals(String other) {
bool String::SlowEquals(String other) const {
DisallowGarbageCollection no_gc;
// Fast check: negative check with lengths.
int len = length();
Expand Down Expand Up @@ -845,6 +845,7 @@ bool String::SlowEquals(String other) {
return comparator.Equals(*this, other);
}

// static
bool String::SlowEquals(Isolate* isolate, Handle<String> one,
Handle<String> two) {
// Fast check: negative check with lengths.
Expand Down
Loading

0 comments on commit 21011eb

Please sign in to comment.