Commit 5f1ae37a authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[messages] Cap string length we try to format

When building the error message for a TypeError when e.g.
a non-callable is called, we should avoid running into the
max string length. Printing many megabytes there isn't going
to be useful anyway.

Fixed: v8:10963
Change-Id: Ief89800f660bdd48585f84c3e3d4ece21b02b760
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2438068Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70226}
parent 44355d75
...@@ -1234,7 +1234,18 @@ Handle<String> BuildDefaultCallSite(Isolate* isolate, Handle<Object> object) { ...@@ -1234,7 +1234,18 @@ Handle<String> BuildDefaultCallSite(Isolate* isolate, Handle<Object> object) {
builder.AppendString(Object::TypeOf(isolate, object)); builder.AppendString(Object::TypeOf(isolate, object));
if (object->IsString()) { if (object->IsString()) {
builder.AppendCString(" \""); builder.AppendCString(" \"");
builder.AppendString(Handle<String>::cast(object)); Handle<String> string = Handle<String>::cast(object);
// This threshold must be sufficiently far below String::kMaxLength that
// the {builder}'s result can never exceed that limit.
constexpr int kMaxPrintedStringLength = 100;
if (string->length() <= kMaxPrintedStringLength) {
builder.AppendString(string);
} else {
string = isolate->factory()->NewProperSubString(string, 0,
kMaxPrintedStringLength);
builder.AppendString(string);
builder.AppendCString("<...>");
}
builder.AppendCString("\""); builder.AppendCString("\"");
} else if (object->IsNull(isolate)) { } else if (object->IsNull(isolate)) {
builder.AppendCString(" "); builder.AppendCString(" ");
......
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