summaryrefslogtreecommitdiff
path: root/chromium/v8/src/objects/string.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/v8/src/objects/string.cc
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/objects/string.cc')
-rw-r--r--chromium/v8/src/objects/string.cc116
1 files changed, 63 insertions, 53 deletions
diff --git a/chromium/v8/src/objects/string.cc b/chromium/v8/src/objects/string.cc
index 90abd00ebac..9d07740e19c 100644
--- a/chromium/v8/src/objects/string.cc
+++ b/chromium/v8/src/objects/string.cc
@@ -298,69 +298,60 @@ bool String::SupportsExternalization() {
return !isolate->heap()->IsInGCPostProcessing();
}
-void String::StringShortPrint(StringStream* accumulator, bool show_details) {
- const char* internalized_marker = this->IsInternalizedString() ? "#" : "";
-
- int len = length();
- if (len > kMaxShortPrintLength) {
- accumulator->Add("<Very long string[%s%u]>", internalized_marker, len);
- return;
+const char* String::PrefixForDebugPrint() const {
+ StringShape shape(*this);
+ if (IsTwoByteRepresentation()) {
+ StringShape shape(*this);
+ if (shape.IsInternalized()) {
+ return "u#";
+ } else if (shape.IsCons()) {
+ return "uc\"";
+ } else if (shape.IsThin()) {
+ return "u>\"";
+ } else {
+ return "u\"";
+ }
+ } else {
+ StringShape shape(*this);
+ if (shape.IsInternalized()) {
+ return "#";
+ } else if (shape.IsCons()) {
+ return "c\"";
+ } else if (shape.IsThin()) {
+ return ">\"";
+ } else {
+ return "\"";
+ }
}
+ UNREACHABLE();
+}
+const char* String::SuffixForDebugPrint() const {
+ StringShape shape(*this);
+ if (shape.IsInternalized()) return "";
+ return "\"";
+}
+
+void String::StringShortPrint(StringStream* accumulator) {
if (!LooksValid()) {
accumulator->Add("<Invalid String>");
return;
}
- StringCharacterStream stream(*this);
+ const int len = length();
+ accumulator->Add("<String[%u]: ", len);
+ accumulator->Add(PrefixForDebugPrint());
- bool truncated = false;
if (len > kMaxShortPrintLength) {
- len = kMaxShortPrintLength;
- truncated = true;
+ accumulator->Add("...<truncated>>");
+ accumulator->Add(SuffixForDebugPrint());
+ accumulator->Put('>');
+ return;
}
- bool one_byte = true;
- for (int i = 0; i < len; i++) {
- uint16_t c = stream.GetNext();
- if (c < 32 || c >= 127) {
- one_byte = false;
- }
- }
- stream.Reset(*this);
- if (one_byte) {
- if (show_details)
- accumulator->Add("<String[%s%u]: ", internalized_marker, length());
- for (int i = 0; i < len; i++) {
- accumulator->Put(static_cast<char>(stream.GetNext()));
- }
- if (show_details) accumulator->Put('>');
- } else {
- // Backslash indicates that the string contains control
- // characters and that backslashes are therefore escaped.
- if (show_details)
- accumulator->Add("<String[%s%u]\\: ", internalized_marker, length());
- for (int i = 0; i < len; i++) {
- uint16_t c = stream.GetNext();
- if (c == '\n') {
- accumulator->Add("\\n");
- } else if (c == '\r') {
- accumulator->Add("\\r");
- } else if (c == '\\') {
- accumulator->Add("\\\\");
- } else if (c < 32 || c > 126) {
- accumulator->Add("\\x%02x", c);
- } else {
- accumulator->Put(static_cast<char>(c));
- }
- }
- if (truncated) {
- accumulator->Put('.');
- accumulator->Put('.');
- accumulator->Put('.');
- }
- if (show_details) accumulator->Put('>');
- }
+ PrintUC16(accumulator, 0, len);
+ accumulator->Add(SuffixForDebugPrint());
+ accumulator->Put('>');
}
void String::PrintUC16(std::ostream& os, int start, int end) { // NOLINT
@@ -371,6 +362,25 @@ void String::PrintUC16(std::ostream& os, int start, int end) { // NOLINT
}
}
+void String::PrintUC16(StringStream* accumulator, int start, int end) {
+ if (end < 0) end = length();
+ StringCharacterStream stream(*this, start);
+ for (int i = start; i < end && stream.HasMore(); i++) {
+ uint16_t c = stream.GetNext();
+ if (c == '\n') {
+ accumulator->Add("\\n");
+ } else if (c == '\r') {
+ accumulator->Add("\\r");
+ } else if (c == '\\') {
+ accumulator->Add("\\\\");
+ } else if (!std::isprint(c)) {
+ accumulator->Add("\\x%02x", c);
+ } else {
+ accumulator->Put(static_cast<char>(c));
+ }
+ }
+}
+
// static
Handle<String> String::Trim(Isolate* isolate, Handle<String> string,
TrimMode mode) {
@@ -410,9 +420,9 @@ int32_t String::ToArrayIndex(Address addr) {
bool String::LooksValid() {
// TODO(leszeks): Maybe remove this check entirely, Heap::Contains uses
// basically the same logic as the way we access the heap in the first place.
- MemoryChunk* chunk = MemoryChunk::FromHeapObject(*this);
// RO_SPACE objects should always be valid.
if (ReadOnlyHeap::Contains(*this)) return true;
+ BasicMemoryChunk* chunk = BasicMemoryChunk::FromHeapObject(*this);
if (chunk->heap() == nullptr) return false;
return chunk->heap()->Contains(*this);
}