[api] Deprecate misleading v8::String::IsExernal method
v8::String::IsExternal is confusing since it only checks for external two byte strings. The goal is to reintroduce String::IsExternal which checks for one and two byte external strings after removing the old, misleading api method. - Add String::IsExternalTwoByte - Deprecate String::IsExternal for now since it is misleading Bug: v8:10641 Change-Id: I8989de7576c823846e0536fc1898e769b6d68c87 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2284495 Commit-Queue: Camillo Bruni <cbruni@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/master@{#69674}
This commit is contained in:
parent
a73ffca3a4
commit
9d413c635d
10
include/v8.h
10
include/v8.h
@ -3113,10 +3113,18 @@ class V8_EXPORT String : public Name {
|
||||
V8_INLINE static Local<String> Empty(Isolate* isolate);
|
||||
|
||||
/**
|
||||
* Returns true if the string is external
|
||||
* Returns true if the string is external one-byte.
|
||||
*
|
||||
*/
|
||||
V8_DEPRECATE_SOON(
|
||||
"Use String::IsExternalTwoByte() or String::IsExternalOneByte()")
|
||||
bool IsExternal() const;
|
||||
|
||||
/**
|
||||
* Returns true if the string is both external and two-byte.
|
||||
*/
|
||||
bool IsExternalTwoByte() const;
|
||||
|
||||
/**
|
||||
* Returns true if the string is both external and one-byte.
|
||||
*/
|
||||
|
@ -5460,6 +5460,10 @@ int String::Write(Isolate* isolate, uint16_t* buffer, int start, int length,
|
||||
}
|
||||
|
||||
bool v8::String::IsExternal() const {
|
||||
return IsExternalTwoByte();
|
||||
}
|
||||
|
||||
bool v8::String::IsExternalTwoByte() const {
|
||||
i::Handle<i::String> str = Utils::OpenHandle(this);
|
||||
return i::StringShape(*str).IsExternalTwoByte();
|
||||
}
|
||||
|
@ -509,7 +509,7 @@ THREADED_TEST(ScriptUsingStringResource) {
|
||||
Local<Value> value = script->Run(env.local()).ToLocalChecked();
|
||||
CHECK(value->IsNumber());
|
||||
CHECK_EQ(7, value->Int32Value(env.local()).FromJust());
|
||||
CHECK(source->IsExternal());
|
||||
CHECK(source->IsExternalTwoByte());
|
||||
CHECK_EQ(resource,
|
||||
static_cast<TestResource*>(source->GetExternalStringResource()));
|
||||
String::Encoding encoding = String::UNKNOWN_ENCODING;
|
||||
@ -568,7 +568,7 @@ THREADED_TEST(ScriptMakingExternalString) {
|
||||
// Trigger GCs so that the newly allocated string moves to old gen.
|
||||
CcTest::CollectGarbage(i::NEW_SPACE); // in survivor space now
|
||||
CcTest::CollectGarbage(i::NEW_SPACE); // in old gen now
|
||||
CHECK(!source->IsExternal());
|
||||
CHECK(!source->IsExternalTwoByte());
|
||||
CHECK(!source->IsExternalOneByte());
|
||||
String::Encoding encoding = String::UNKNOWN_ENCODING;
|
||||
CHECK(!source->GetExternalStringResourceBase(&encoding));
|
||||
@ -16794,10 +16794,11 @@ class VisitorImpl : public v8::ExternalResourceVisitor {
|
||||
}
|
||||
~VisitorImpl() override = default;
|
||||
void VisitExternalString(v8::Local<v8::String> string) override {
|
||||
if (!string->IsExternal()) {
|
||||
CHECK(string->IsExternalOneByte());
|
||||
if (string->IsExternalOneByte()) {
|
||||
CHECK(!string->IsExternalTwoByte());
|
||||
return;
|
||||
}
|
||||
CHECK(string->IsExternalTwoByte());
|
||||
v8::String::ExternalStringResource* resource =
|
||||
string->GetExternalStringResource();
|
||||
CHECK(resource);
|
||||
@ -16836,7 +16837,7 @@ TEST(ExternalizeOldSpaceTwoByteCons) {
|
||||
AsciiToTwoByteString("Romeo Montague Juliet Capulet"));
|
||||
cons->MakeExternal(resource);
|
||||
|
||||
CHECK(cons->IsExternal());
|
||||
CHECK(cons->IsExternalTwoByte());
|
||||
CHECK_EQ(resource, cons->GetExternalStringResource());
|
||||
String::Encoding encoding;
|
||||
CHECK_EQ(resource, cons->GetExternalStringResourceBase(&encoding));
|
||||
@ -16903,10 +16904,10 @@ TEST(VisitExternalStrings) {
|
||||
CHECK(string3_i->IsInternalizedString());
|
||||
|
||||
// We need to add usages for string* to avoid warnings in GCC 4.7
|
||||
CHECK(string0->IsExternal());
|
||||
CHECK(string1->IsExternal());
|
||||
CHECK(string2->IsExternal());
|
||||
CHECK(string3->IsExternal());
|
||||
CHECK(string0->IsExternalTwoByte());
|
||||
CHECK(string1->IsExternalTwoByte());
|
||||
CHECK(string2->IsExternalTwoByte());
|
||||
CHECK(string3->IsExternalTwoByte());
|
||||
|
||||
VisitorImpl visitor(resource);
|
||||
isolate->VisitExternalResources(&visitor);
|
||||
|
@ -2857,8 +2857,12 @@ UNINITIALIZED_TEST(SnapshotCreatorExternalReferences) {
|
||||
ExpectInt32("f()", 42);
|
||||
ExpectString("one_byte", "one_byte");
|
||||
ExpectString("two_byte", "two_byte");
|
||||
CHECK(CompileRun("one_byte").As<v8::String>()->IsExternalOneByte());
|
||||
CHECK(CompileRun("two_byte").As<v8::String>()->IsExternal());
|
||||
v8::Local<v8::String> one_byte = CompileRun("one_byte").As<v8::String>();
|
||||
v8::Local<v8::String> two_byte = CompileRun("two_byte").As<v8::String>();
|
||||
CHECK(one_byte->IsExternalOneByte());
|
||||
CHECK(!one_byte->IsExternalTwoByte());
|
||||
CHECK(!two_byte->IsExternalOneByte());
|
||||
CHECK(two_byte->IsExternalTwoByte());
|
||||
}
|
||||
isolate->Dispose();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user