Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Unified Diff: src/api.cc

Issue 2683903002: Fix missing cases of empty_string canonicalization (Closed)
Patch Set: make LSan happy Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | src/arm/macro-assembler-arm.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 07b967f2b8cf3bf37e093d1e3724b142d50663ad..127b6a7d762d6f3545d25b1f649dadcb4098ca18 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6723,11 +6723,17 @@ MaybeLocal<String> v8::String::NewExternalTwoByte(
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
LOG_API(i_isolate, String, NewExternalTwoByte);
- i::Handle<i::String> string = i_isolate->factory()
- ->NewExternalStringFromTwoByte(resource)
- .ToHandleChecked();
- i_isolate->heap()->RegisterExternalString(*string);
- return Utils::ToLocal(string);
+ if (resource->length() > 0) {
+ i::Handle<i::String> string = i_isolate->factory()
+ ->NewExternalStringFromTwoByte(resource)
+ .ToHandleChecked();
+ i_isolate->heap()->RegisterExternalString(*string);
+ return Utils::ToLocal(string);
+ } else {
+ // The resource isn't going to be used, free it immediately.
+ resource->Dispose();
+ return Utils::ToLocal(i_isolate->factory()->empty_string());
+ }
}
@@ -6747,11 +6753,17 @@ MaybeLocal<String> v8::String::NewExternalOneByte(
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
LOG_API(i_isolate, String, NewExternalOneByte);
- i::Handle<i::String> string = i_isolate->factory()
- ->NewExternalStringFromOneByte(resource)
- .ToHandleChecked();
- i_isolate->heap()->RegisterExternalString(*string);
- return Utils::ToLocal(string);
+ if (resource->length() > 0) {
+ i::Handle<i::String> string = i_isolate->factory()
+ ->NewExternalStringFromOneByte(resource)
+ .ToHandleChecked();
+ i_isolate->heap()->RegisterExternalString(*string);
+ return Utils::ToLocal(string);
+ } else {
+ // The resource isn't going to be used, free it immediately.
+ resource->Dispose();
+ return Utils::ToLocal(i_isolate->factory()->empty_string());
+ }
}
« no previous file with comments | « include/v8.h ('k') | src/arm/macro-assembler-arm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698