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 {
/**
* 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(Isolate* isolate) const;
V8_DEPRECATED("Use Symbol::Description()")
Local<Value> Name() const { return Description(); }
......
......@@ -5618,19 +5618,33 @@ Local<Value> Symbol::Description() const {
// RO_SPACE. Since RO_SPACE objects are immovable we can use the
// Handle(Address*) constructor with the address of the description
// 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*>(
sym->GetFieldAddress(i::Symbol::kDescriptionOffset)));
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);
}
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 {
......
......@@ -19,7 +19,7 @@ void WriteToFile(const char* prefix, FILE* file, Isolate* isolate,
Local<Value> arg = args[i];
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;
v8::String::Utf8Value str(isolate, str_obj);
......
......@@ -1939,7 +1939,7 @@ void WriteToFile(FILE* file, const v8::FunctionCallbackInfo<v8::Value>& args) {
Local<String> str_obj;
if (arg->IsSymbol()) {
arg = arg.As<Symbol>()->Description();
arg = arg.As<Symbol>()->Description(args.GetIsolate());
}
if (!arg->ToString(args.GetIsolate()->GetCurrentContext())
.ToLocal(&str_obj)) {
......
......@@ -152,7 +152,7 @@ class V8ValueStringBuilder {
bool append(v8::Local<v8::Symbol> symbol) {
m_builder.append("Symbol(");
bool result = append(symbol->Description(), IgnoreUndefined);
bool result = append(symbol->Description(m_isolate), IgnoreUndefined);
m_builder.append(')');
return result;
}
......
......@@ -165,9 +165,10 @@ String16 abbreviateString(const String16& value, AbbreviateMode mode) {
String16 descriptionForSymbol(v8::Local<v8::Context> context,
v8::Local<v8::Symbol> symbol) {
return String16::concat("Symbol(",
toProtocolStringWithTypeCheck(context->GetIsolate(),
symbol->Description()),
v8::Isolate* isolate = context->GetIsolate();
return String16::concat(
"Symbol(",
toProtocolStringWithTypeCheck(isolate, symbol->Description(isolate)),
")");
}
......
......@@ -81,17 +81,19 @@ void SimpleAccessorSetter(Local<String> name, Local<Value> value,
void SymbolAccessorGetter(Local<Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
SimpleAccessorGetter(sym->Description().As<String>(), info);
if (sym->Description(isolate)->IsUndefined()) return;
SimpleAccessorGetter(sym->Description(isolate).As<String>(), info);
}
void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) {
CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
SimpleAccessorSetter(sym->Description().As<String>(), value, info);
if (sym->Description(isolate)->IsUndefined()) return;
SimpleAccessorSetter(sym->Description(isolate).As<String>(), value, info);
}
void InterceptorGetter(Local<Name> generic_name,
......@@ -139,9 +141,10 @@ void InterceptorSetter(Local<Name> generic_name, Local<Value> value,
void GenericInterceptorGetter(Local<Name> generic_name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
Local<String> str;
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;
str = String::Concat(info.GetIsolate(), v8_str("_sym_"), name.As<String>());
} else {
......@@ -159,9 +162,10 @@ void GenericInterceptorGetter(Local<Name> generic_name,
void GenericInterceptorSetter(Local<Name> generic_name, Local<Value> value,
const v8::PropertyCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
Local<String> str;
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;
str = String::Concat(info.GetIsolate(), v8_str("_sym_"), name.As<String>());
} else {
......
......@@ -2672,24 +2672,28 @@ void SimpleAccessorSetter(Local<String> name, Local<Value> value,
void SymbolAccessorGetter(Local<Name> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
SimpleAccessorGetter(Local<String>::Cast(sym->Description()), info);
if (sym->Description(isolate)->IsUndefined()) return;
SimpleAccessorGetter(Local<String>::Cast(sym->Description(isolate)), info);
}
void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
const v8::PropertyCallbackInfo<void>& info) {
CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
SimpleAccessorSetter(Local<String>::Cast(sym->Description()), value, info);
if (sym->Description(isolate)->IsUndefined()) return;
SimpleAccessorSetter(Local<String>::Cast(sym->Description(isolate)), value,
info);
}
void SymbolAccessorGetterReturnsDefault(
Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
CHECK(name->IsSymbol());
v8::Isolate* isolate = info.GetIsolate();
Local<Symbol> sym = name.As<Symbol>();
if (sym->Description()->IsUndefined()) return;
if (sym->Description(isolate)->IsUndefined()) return;
info.GetReturnValue().Set(info.Data());
}
......@@ -3319,8 +3323,9 @@ THREADED_TEST(SymbolProperties) {
CHECK(!sym1->StrictEquals(sym2));
CHECK(!sym2->StrictEquals(sym1));
CHECK(
sym2->Description()->Equals(env.local(), v8_str("my-symbol")).FromJust());
CHECK(sym2->Description(isolate)
->Equals(env.local(), v8_str("my-symbol"))
.FromJust());
v8::Local<v8::Value> sym_val = sym2;
CHECK(sym_val->IsSymbol());
......@@ -14191,8 +14196,8 @@ void CheckIsSymbolAt(v8::Isolate* isolate, v8::Local<v8::Array> properties,
properties->Get(context, v8::Integer::New(isolate, index))
.ToLocalChecked();
CHECK(value->IsSymbol());
v8::String::Utf8Value symbol_name(isolate,
Local<Symbol>::Cast(value)->Description());
v8::String::Utf8Value symbol_name(
isolate, Local<Symbol>::Cast(value)->Description(isolate));
if (strcmp(name, *symbol_name) != 0) {
FATAL("properties[%u] was Symbol('%s') instead of Symbol('%s').", index,
name, *symbol_name);
......@@ -128,7 +128,7 @@ class UtilsExtension : public IsolateData::SetupGlobalTask {
v8::Local<v8::String> str_obj;
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())
.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