Commit 153f2cea authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

[ptr-cage] Deprecate Symbol::Description() in favor of Symbol::Description(isolate)

With a shared cage, there's no easy way to recover an Isolate from a
heap pointer. Symbol::Description relies on RO symbols' description slot
being uncompressed so a Handle could point to it. This isn't possible
with a shared cage without going through TLS to get an Isolate for
Handle construction, so deprecate the method in favor of one that takes
an Isolate directly.

Bug: v8:11460
Change-Id: I69b2b7d77f4c00d0f58954cd80e22cba5ff222e3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2802860
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73924}
parent fb533e8d
...@@ -3626,7 +3626,9 @@ class V8_EXPORT Symbol : public Name { ...@@ -3626,7 +3626,9 @@ class V8_EXPORT Symbol : public Name {
/** /**
* Returns the description string of the symbol, or undefined if none. * Returns the description string of the symbol, or undefined if none.
*/ */
V8_DEPRECATE_SOON("Use Symbol::Description(isolate)")
Local<Value> Description() const; Local<Value> Description() const;
Local<Value> Description(Isolate* isolate) const;
V8_DEPRECATED("Use Symbol::Description()") V8_DEPRECATED("Use Symbol::Description()")
Local<Value> Name() const { return Description(); } Local<Value> Name() const { return Description(); }
......
...@@ -5618,19 +5618,33 @@ Local<Value> Symbol::Description() const { ...@@ -5618,19 +5618,33 @@ Local<Value> Symbol::Description() const {
// RO_SPACE. Since RO_SPACE objects are immovable we can use the // RO_SPACE. Since RO_SPACE objects are immovable we can use the
// Handle(Address*) constructor with the address of the description // Handle(Address*) constructor with the address of the description
// field in the Symbol object without needing an isolate. // field in the Symbol object without needing an isolate.
DCHECK(!COMPRESS_POINTERS_BOOL); DCHECK(!COMPRESS_POINTERS_IN_ISOLATE_CAGE_BOOL);
#ifndef V8_COMPRESS_POINTERS_IN_SHARED_CAGE
i::Handle<i::HeapObject> ro_description(reinterpret_cast<i::Address*>( i::Handle<i::HeapObject> ro_description(reinterpret_cast<i::Address*>(
sym->GetFieldAddress(i::Symbol::kDescriptionOffset))); sym->GetFieldAddress(i::Symbol::kDescriptionOffset)));
return Utils::ToLocal(ro_description); return Utils::ToLocal(ro_description);
#else
isolate = reinterpret_cast<i::Isolate*>(Isolate::GetCurrent());
#endif
} }
i::Handle<i::Object> description(sym->description(), isolate); return Description(reinterpret_cast<Isolate*>(isolate));
}
Local<Value> Symbol::Description(Isolate* isolate) const {
i::Handle<i::Symbol> sym = Utils::OpenHandle(this);
i::Handle<i::Object> description(sym->description(),
reinterpret_cast<i::Isolate*>(isolate));
return Utils::ToLocal(description); return Utils::ToLocal(description);
} }
Local<Value> Private::Name() const { Local<Value> Private::Name() const {
return reinterpret_cast<const Symbol*>(this)->Description(); const Symbol* sym = reinterpret_cast<const Symbol*>(this);
i::Handle<i::Symbol> i_sym = Utils::OpenHandle(sym);
// v8::Private symbols are created by API and are therefore writable, so we
// can always recover an Isolate.
i::Isolate* isolate = i::GetIsolateFromWritableObject(*i_sym);
return sym->Description(reinterpret_cast<Isolate*>(isolate));
} }
double Number::Value() const { double Number::Value() const {
......
...@@ -19,7 +19,7 @@ void WriteToFile(const char* prefix, FILE* file, Isolate* isolate, ...@@ -19,7 +19,7 @@ void WriteToFile(const char* prefix, FILE* file, Isolate* isolate,
Local<Value> arg = args[i]; Local<Value> arg = args[i];
Local<String> str_obj; Local<String> str_obj;
if (arg->IsSymbol()) arg = Local<Symbol>::Cast(arg)->Description(); if (arg->IsSymbol()) arg = Local<Symbol>::Cast(arg)->Description(isolate);
if (!arg->ToString(isolate->GetCurrentContext()).ToLocal(&str_obj)) return; if (!arg->ToString(isolate->GetCurrentContext()).ToLocal(&str_obj)) return;
v8::String::Utf8Value str(isolate, str_obj); v8::String::Utf8Value str(isolate, str_obj);
......
...@@ -1939,7 +1939,7 @@ void WriteToFile(FILE* file, const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -1939,7 +1939,7 @@ void WriteToFile(FILE* file, const v8::FunctionCallbackInfo<v8::Value>& args) {
Local<String> str_obj; Local<String> str_obj;
if (arg->IsSymbol()) { if (arg->IsSymbol()) {
arg = arg.As<Symbol>()->Description(); arg = arg.As<Symbol>()->Description(args.GetIsolate());
} }
if (!arg->ToString(args.GetIsolate()->GetCurrentContext()) if (!arg->ToString(args.GetIsolate()->GetCurrentContext())
.ToLocal(&str_obj)) { .ToLocal(&str_obj)) {
......
...@@ -152,7 +152,7 @@ class V8ValueStringBuilder { ...@@ -152,7 +152,7 @@ class V8ValueStringBuilder {
bool append(v8::Local<v8::Symbol> symbol) { bool append(v8::Local<v8::Symbol> symbol) {
m_builder.append("Symbol("); m_builder.append("Symbol(");
bool result = append(symbol->Description(), IgnoreUndefined); bool result = append(symbol->Description(m_isolate), IgnoreUndefined);
m_builder.append(')'); m_builder.append(')');
return result; return result;
} }
......
...@@ -165,9 +165,10 @@ String16 abbreviateString(const String16& value, AbbreviateMode mode) { ...@@ -165,9 +165,10 @@ String16 abbreviateString(const String16& value, AbbreviateMode mode) {
String16 descriptionForSymbol(v8::Local<v8::Context> context, String16 descriptionForSymbol(v8::Local<v8::Context> context,
v8::Local<v8::Symbol> symbol) { v8::Local<v8::Symbol> symbol) {
return String16::concat("Symbol(", v8::Isolate* isolate = context->GetIsolate();
toProtocolStringWithTypeCheck(context->GetIsolate(), return String16::concat(
symbol->Description()), "Symbol(",
toProtocolStringWithTypeCheck(isolate, symbol->Description(isolate)),
")"); ")");
} }
......
...@@ -81,17 +81,19 @@ void SimpleAccessorSetter(Local<String> name, Local<Value> value, ...@@ -81,17 +81,19 @@ void SimpleAccessorSetter(Local<String> name, Local<Value> value,
void SymbolAccessorGetter(Local<Name> name, void SymbolAccessorGetter(Local<Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) { const v8::PropertyCallbackInfo<v8::Value>& info) {
CHECK(name->IsSymbol()); CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>(); Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return; if (sym->Description(isolate)->IsUndefined()) return;
SimpleAccessorGetter(sym->Description().As<String>(), info); SimpleAccessorGetter(sym->Description(isolate).As<String>(), info);
} }
void SymbolAccessorSetter(Local<Name> name, Local<Value> value, void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) { const v8::PropertyCallbackInfo<void>& info) {
CHECK(name->IsSymbol()); CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>(); Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return; if (sym->Description(isolate)->IsUndefined()) return;
SimpleAccessorSetter(sym->Description().As<String>(), value, info); SimpleAccessorSetter(sym->Description(isolate).As<String>(), value, info);
} }
void InterceptorGetter(Local<Name> generic_name, void InterceptorGetter(Local<Name> generic_name,
...@@ -139,9 +141,10 @@ void InterceptorSetter(Local<Name> generic_name, Local<Value> value, ...@@ -139,9 +141,10 @@ void InterceptorSetter(Local<Name> generic_name, Local<Value> value,
void GenericInterceptorGetter(Local<Name> generic_name, void GenericInterceptorGetter(Local<Name> generic_name,
const v8::PropertyCallbackInfo<v8::Value>& info) { const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
Local<String> str; Local<String> str;
if (generic_name->IsSymbol()) { if (generic_name->IsSymbol()) {
Local<Value> name = generic_name.As<Symbol>()->Description(); Local<Value> name = generic_name.As<Symbol>()->Description(isolate);
if (name->IsUndefined()) return; if (name->IsUndefined()) return;
str = String::Concat(info.GetIsolate(), v8_str("_sym_"), name.As<String>()); str = String::Concat(info.GetIsolate(), v8_str("_sym_"), name.As<String>());
} else { } else {
...@@ -159,9 +162,10 @@ void GenericInterceptorGetter(Local<Name> generic_name, ...@@ -159,9 +162,10 @@ void GenericInterceptorGetter(Local<Name> generic_name,
void GenericInterceptorSetter(Local<Name> generic_name, Local<Value> value, void GenericInterceptorSetter(Local<Name> generic_name, Local<Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) { const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
Local<String> str; Local<String> str;
if (generic_name->IsSymbol()) { if (generic_name->IsSymbol()) {
Local<Value> name = generic_name.As<Symbol>()->Description(); Local<Value> name = generic_name.As<Symbol>()->Description(isolate);
if (name->IsUndefined()) return; if (name->IsUndefined()) return;
str = String::Concat(info.GetIsolate(), v8_str("_sym_"), name.As<String>()); str = String::Concat(info.GetIsolate(), v8_str("_sym_"), name.As<String>());
} else { } else {
......
...@@ -2672,24 +2672,28 @@ void SimpleAccessorSetter(Local<String> name, Local<Value> value, ...@@ -2672,24 +2672,28 @@ void SimpleAccessorSetter(Local<String> name, Local<Value> value,
void SymbolAccessorGetter(Local<Name> name, void SymbolAccessorGetter(Local<Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) { const v8::PropertyCallbackInfo<v8::Value>& info) {
CHECK(name->IsSymbol()); CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>(); Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return; if (sym->Description(isolate)->IsUndefined()) return;
SimpleAccessorGetter(Local<String>::Cast(sym->Description()), info); SimpleAccessorGetter(Local<String>::Cast(sym->Description(isolate)), info);
} }
void SymbolAccessorSetter(Local<Name> name, Local<Value> value, void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) { const v8::PropertyCallbackInfo<void>& info) {
CHECK(name->IsSymbol()); CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>(); Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return; if (sym->Description(isolate)->IsUndefined()) return;
SimpleAccessorSetter(Local<String>::Cast(sym->Description()), value, info); SimpleAccessorSetter(Local<String>::Cast(sym->Description(isolate)), value,
info);
} }
void SymbolAccessorGetterReturnsDefault( void SymbolAccessorGetterReturnsDefault(
Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
CHECK(name->IsSymbol()); CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>(); Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return; if (sym->Description(isolate)->IsUndefined()) return;
info.GetReturnValue().Set(info.Data()); info.GetReturnValue().Set(info.Data());
} }
...@@ -3319,8 +3323,9 @@ THREADED_TEST(SymbolProperties) { ...@@ -3319,8 +3323,9 @@ THREADED_TEST(SymbolProperties) {
CHECK(!sym1->StrictEquals(sym2)); CHECK(!sym1->StrictEquals(sym2));
CHECK(!sym2->StrictEquals(sym1)); CHECK(!sym2->StrictEquals(sym1));
CHECK( CHECK(sym2->Description(isolate)
sym2->Description()->Equals(env.local(), v8_str("my-symbol")).FromJust()); ->Equals(env.local(), v8_str("my-symbol"))
.FromJust());
v8::Local<v8::Value> sym_val = sym2; v8::Local<v8::Value> sym_val = sym2;
CHECK(sym_val->IsSymbol()); CHECK(sym_val->IsSymbol());
...@@ -14191,8 +14196,8 @@ void CheckIsSymbolAt(v8::Isolate* isolate, v8::Local<v8::Array> properties, ...@@ -14191,8 +14196,8 @@ void CheckIsSymbolAt(v8::Isolate* isolate, v8::Local<v8::Array> properties,
properties->Get(context, v8::Integer::New(isolate, index)) properties->Get(context, v8::Integer::New(isolate, index))
.ToLocalChecked(); .ToLocalChecked();
CHECK(value->IsSymbol()); CHECK(value->IsSymbol());
v8::String::Utf8Value symbol_name(isolate, v8::String::Utf8Value symbol_name(
Local<Symbol>::Cast(value)->Description()); isolate, Local<Symbol>::Cast(value)->Description(isolate));
if (strcmp(name, *symbol_name) != 0) { if (strcmp(name, *symbol_name) != 0) {
FATAL("properties[%u] was Symbol('%s') instead of Symbol('%s').", index, FATAL("properties[%u] was Symbol('%s') instead of Symbol('%s').", index,
name, *symbol_name); name, *symbol_name);
...@@ -128,7 +128,7 @@ class UtilsExtension : public IsolateData::SetupGlobalTask { ...@@ -128,7 +128,7 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
v8::Local<v8::String> str_obj; v8::Local<v8::String> str_obj;
if (arg->IsSymbol()) { if (arg->IsSymbol()) {
arg = v8::Local<v8::Symbol>::Cast(arg)->Description(); arg = v8::Local<v8::Symbol>::Cast(arg)->Description(args.GetIsolate());
} }
if (!arg->ToString(args.GetIsolate()->GetCurrentContext()) if (!arg->ToString(args.GetIsolate()->GetCurrentContext())
.ToLocal(&str_obj)) { .ToLocal(&str_obj)) {
......
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