Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 1943683e45400b0c98ec1d280a5717f51df64a2c..c54cdd21a38e8b700c2c9b6df140a4772e3b02eb 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -5550,7 +5550,11 @@ Local<String> v8::String::Concat(Handle<String> left, Handle<String> right) { |
LOG_API(isolate, "String::New(char)"); |
ENTER_V8(isolate); |
i::Handle<i::String> right_string = Utils::OpenHandle(*right); |
- // We do not expect this to fail. Change this if it does. |
+ // If we are steering towards a range error, do not wait for the error to be |
+ // thrown, and return the null handle instead. |
+ if (left_string->length() + right_string->length() > i::String::kMaxLength) { |
+ return Local<String>(); |
+ } |
i::Handle<i::String> result = isolate->factory()->NewConsString( |
left_string, right_string).ToHandleChecked(); |
return Utils::ToLocal(result); |