Commit b96309b7 authored by Yang Guo's avatar Yang Guo

Move public symbols to the root set.

This allows serializing public symbols that are embedded in code.

BUG=v8:3689
LOG=N
R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/722723002

Cr-Commit-Position: refs/heads/master@{#25315}
parent 07b0a2a1
......@@ -181,7 +181,7 @@ void Accessors::ArgumentsIteratorSetter(
Handle<AccessorInfo> Accessors::ArgumentsIteratorInfo(
Isolate* isolate, PropertyAttributes attributes) {
Handle<Name> name(isolate->native_context()->iterator_symbol(), isolate);
Handle<Name> name = isolate->factory()->iterator_symbol();
return MakeAccessor(isolate, name, &ArgumentsIteratorGetter,
&ArgumentsIteratorSetter, attributes);
}
......
......@@ -6227,27 +6227,21 @@ Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) {
}
static Local<Symbol> GetWellKnownSymbol(Isolate* isolate, const char* name) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::String> i_name =
Utils::OpenHandle(*String::NewFromUtf8(isolate, name));
i::Handle<i::String> part = i_isolate->factory()->for_intern_string();
return Utils::ToLocal(SymbolFor(i_isolate, i_name, part));
}
Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) {
return GetWellKnownSymbol(isolate, "Symbol.iterator");
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
return Utils::ToLocal(i_isolate->factory()->iterator_symbol());
}
Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) {
return GetWellKnownSymbol(isolate, "Symbol.unscopables");
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
return Utils::ToLocal(i_isolate->factory()->unscopables_symbol());
}
Local<Symbol> v8::Symbol::GetToStringTag(Isolate* isolate) {
return GetWellKnownSymbol(isolate, "Symbol.toStringTag");
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
return Utils::ToLocal(i_isolate->factory()->to_string_tag_symbol());
}
......
......@@ -182,9 +182,8 @@ void AstValue::Internalize(Isolate* isolate) {
DCHECK(!string_->string().is_null());
break;
case SYMBOL:
value_ = Object::GetProperty(
isolate, handle(isolate->native_context()->builtins()),
symbol_name_).ToHandleChecked();
DCHECK_EQ(0, strcmp(symbol_name_, "iterator_symbol"));
value_ = isolate->factory()->iterator_symbol();
break;
case NUMBER:
value_ = isolate->factory()->NewNumber(number_, TENURED);
......
......@@ -1561,9 +1561,6 @@ void Genesis::InstallNativeFunctions() {
native_object_get_notifier);
INSTALL_NATIVE(JSFunction, "NativeObjectNotifierPerformChange",
native_object_notifier_perform_change);
INSTALL_NATIVE(Symbol, "symbolIterator", iterator_symbol);
INSTALL_NATIVE(Symbol, "symbolUnscopables", unscopables_symbol);
INSTALL_NATIVE(JSFunction, "ArrayValues", array_values_iterator);
#define INSTALL_NATIVE_FUNCTIONS_FOR(id, descr) InstallNativeFunctions_##id();
......@@ -1988,6 +1985,17 @@ bool Genesis::InstallNatives() {
return true;
}
// Install public symbols.
{
static const PropertyAttributes attributes =
static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
#define INSTALL_PUBLIC_SYMBOL(name, varname, description) \
Handle<String> varname = factory()->NewStringFromStaticChars(#varname); \
JSObject::AddProperty(builtins, varname, factory()->name(), attributes);
PUBLIC_SYMBOL_LIST(INSTALL_PUBLIC_SYMBOL)
#undef INSTALL_PUBLIC_SYMBOL
}
// Install natives.
for (int i = Natives::GetDebuggerCount();
i < Natives::GetBuiltinsCount();
......@@ -2114,22 +2122,22 @@ bool Genesis::InstallNatives() {
Handle<AccessorInfo> arguments_iterator =
Accessors::ArgumentsIteratorInfo(isolate(), attribs);
{
CallbacksDescriptor d(Handle<Name>(native_context()->iterator_symbol()),
arguments_iterator, attribs);
CallbacksDescriptor d(factory()->iterator_symbol(), arguments_iterator,
attribs);
Handle<Map> map(native_context()->sloppy_arguments_map());
Map::EnsureDescriptorSlack(map, 1);
map->AppendDescriptor(&d);
}
{
CallbacksDescriptor d(Handle<Name>(native_context()->iterator_symbol()),
arguments_iterator, attribs);
CallbacksDescriptor d(factory()->iterator_symbol(), arguments_iterator,
attribs);
Handle<Map> map(native_context()->aliased_arguments_map());
Map::EnsureDescriptorSlack(map, 1);
map->AppendDescriptor(&d);
}
{
CallbacksDescriptor d(Handle<Name>(native_context()->iterator_symbol()),
arguments_iterator, attribs);
CallbacksDescriptor d(factory()->iterator_symbol(), arguments_iterator,
attribs);
Handle<Map> map(native_context()->strict_arguments_map());
Map::EnsureDescriptorSlack(map, 1);
map->AppendDescriptor(&d);
......
......@@ -125,8 +125,7 @@ static Maybe<PropertyAttributes> UnscopableLookup(LookupIterator* it) {
DCHECK(attrs.has_value || isolate->has_pending_exception());
if (!attrs.has_value || attrs.value == ABSENT) return attrs;
Handle<Symbol> unscopables_symbol(
isolate->native_context()->unscopables_symbol(), isolate);
Handle<Symbol> unscopables_symbol = isolate->factory()->unscopables_symbol();
Handle<Object> receiver = it->GetReceiver();
Handle<Object> unscopables;
MaybeHandle<Object> maybe_unscopables =
......
......@@ -181,8 +181,6 @@ enum BindingFlags {
V(ITERATOR_RESULT_MAP_INDEX, Map, iterator_result_map) \
V(MAP_ITERATOR_MAP_INDEX, Map, map_iterator_map) \
V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \
V(ITERATOR_SYMBOL_INDEX, Symbol, iterator_symbol) \
V(UNSCOPABLES_SYMBOL_INDEX, Symbol, unscopables_symbol) \
V(ARRAY_VALUES_ITERATOR_INDEX, JSFunction, array_values_iterator) \
V(SCRIPT_CONTEXT_TABLE_INDEX, ScriptContextTable, script_context_table)
......@@ -415,8 +413,6 @@ class Context: public FixedArray {
ITERATOR_RESULT_MAP_INDEX,
MAP_ITERATOR_MAP_INDEX,
SET_ITERATOR_MAP_INDEX,
ITERATOR_SYMBOL_INDEX,
UNSCOPABLES_SYMBOL_INDEX,
ARRAY_VALUES_ITERATOR_INDEX,
SCRIPT_CONTEXT_TABLE_INDEX,
MAP_CACHE_INDEX,
......
......@@ -612,6 +612,14 @@ class Factory FINAL {
PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
#define SYMBOL_ACCESSOR(name, varname, description) \
inline Handle<Symbol> name() { \
return Handle<Symbol>(bit_cast<Symbol**>( \
&isolate()->heap()->roots_[Heap::k##name##RootIndex])); \
}
PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
inline void set_string_table(Handle<StringTable> table) {
isolate()->heap()->set_string_table(*table);
}
......
......@@ -9,8 +9,6 @@
// var $Object = global.Object;
// var $Symbol = global.Symbol;
var symbolToStringTag = InternalSymbol("Symbol.toStringTag");
var kBuiltinStringTags = {
"__proto__": null,
"Arguments": true,
......
......@@ -2162,6 +2162,9 @@ const char* V8HeapExplorer::GetStrongGcSubrootName(Object* object) {
#define SYMBOL_NAME(name) NAME_ENTRY(name)
PRIVATE_SYMBOL_LIST(SYMBOL_NAME)
#undef SYMBOL_NAME
#define SYMBOL_NAME(name, varname, description) NAME_ENTRY(name)
PUBLIC_SYMBOL_LIST(SYMBOL_NAME)
#undef SYMBOL_NAME
#undef NAME_ENTRY
CHECK(!strong_gc_subroot_names_.is_empty());
}
......
......@@ -2921,6 +2921,17 @@ void Heap::CreateInitialObjects() {
#undef SYMBOL_INIT
}
{
HandleScope scope(isolate());
#define SYMBOL_INIT(name, varname, description) \
Handle<Symbol> name = factory->NewSymbol(); \
Handle<String> name##d = factory->NewStringFromStaticChars(#description); \
name->set_name(*name##d); \
roots_[k##name##RootIndex] = *name;
PUBLIC_SYMBOL_LIST(SYMBOL_INIT)
#undef SYMBOL_INIT
}
CreateFixedStubs();
// Allocate the dictionary of intrinsic function names.
......
......@@ -299,6 +299,15 @@ namespace internal {
V(class_start_position_symbol) \
V(class_end_position_symbol)
#define PUBLIC_SYMBOL_LIST(V) \
V(has_instance_symbol, symbolHasInstance, Symbol.hasInstance) \
V(is_concat_spreadable_symbol, symbolIsConcatSpreadable, \
Symbol.isConcatSpreadable) \
V(is_regexp_symbol, symbolIsRegExp, Symbol.isRegExp) \
V(iterator_symbol, symbolIterator, Symbol.iterator) \
V(to_string_tag_symbol, symbolToStringTag, Symbol.toStringTag) \
V(unscopables_symbol, symbolUnscopables, Symbol.unscopables)
// Heap roots that are known to be immortal immovable, for which we can safely
// skip write barriers. This list is not complete and has omissions.
#define IMMORTAL_IMMOVABLE_ROOT_LIST(V) \
......@@ -809,6 +818,11 @@ class Heap {
PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
#define SYMBOL_ACCESSOR(name, varname, description) \
Symbol* name() { return Symbol::cast(roots_[k##name##RootIndex]); }
PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
// The hidden_string is special because it is the empty string, but does
// not match the empty string.
String* hidden_string() { return hidden_string_; }
......@@ -1106,6 +1120,10 @@ class Heap {
PRIVATE_SYMBOL_LIST(SYMBOL_INDEX_DECLARATION)
#undef SYMBOL_INDEX_DECLARATION
#define SYMBOL_INDEX_DECLARATION(name, varname, description) k##name##RootIndex,
PUBLIC_SYMBOL_LIST(SYMBOL_INDEX_DECLARATION)
#undef SYMBOL_INDEX_DECLARATION
// Utility type maps
#define DECLARE_STRUCT_MAP(NAME, Name, name) k##Name##MapRootIndex,
STRUCT_LIST(DECLARE_STRUCT_MAP)
......
......@@ -2348,9 +2348,8 @@ Handle<JSObject> Isolate::GetSymbolRegistry() {
Handle<JSObject> registry = factory()->NewJSObjectFromMap(map);
heap()->set_symbol_registry(*registry);
static const char* nested[] = {
"for", "for_api", "for_intern", "keyFor", "private_api", "private_intern"
};
static const char* nested[] = {"for", "for_api", "keyFor", "private_api",
"private_intern"};
for (unsigned i = 0; i < arraysize(nested); ++i) {
Handle<String> name = factory()->InternalizeUtf8String(nested[i]);
Handle<JSObject> obj = factory()->NewJSObjectFromMap(map);
......
......@@ -757,7 +757,7 @@ Expression* ParserTraits::ExpressionFromString(
Expression* ParserTraits::GetIterator(
Expression* iterable, AstNodeFactory<AstConstructionVisitor>* factory) {
Expression* iterator_symbol_literal =
factory->NewSymbolLiteral("symbolIterator", RelocInfo::kNoPosition);
factory->NewSymbolLiteral("iterator_symbol", RelocInfo::kNoPosition);
int pos = iterable->position();
Expression* prop =
factory->NewProperty(iterable, iterator_symbol_literal, pos);
......
......@@ -1006,7 +1006,7 @@ RUNTIME_FUNCTION(Runtime_GetArgumentsProperty) {
HandleScope scope(isolate);
if (raw_key->IsSymbol()) {
Handle<Symbol> symbol = Handle<Symbol>::cast(raw_key);
if (symbol->Equals(isolate->native_context()->iterator_symbol())) {
if (Name::Equals(symbol, isolate->factory()->iterator_symbol())) {
return isolate->native_context()->array_values_iterator();
}
// Lookup in the initial Object.prototype object.
......
......@@ -8,6 +8,14 @@
// in runtime.js:
// var $Array = global.Array;
// And requires following symbols to be set in the bootstrapper during genesis:
// - symbolHasInstance
// - symbolIsConcatSpreadable
// - symbolIsRegExp
// - symbolIterator
// - symbolToStringTag
// - symbolUnscopables
var $Symbol = global.Symbol;
// -------------------------------------------------------------------
......@@ -40,15 +48,6 @@ function SymbolValueOf() {
}
function InternalSymbol(key) {
var internal_registry = %SymbolRegistry().for_intern;
if (IS_UNDEFINED(internal_registry[key])) {
internal_registry[key] = %CreateSymbol(key);
}
return internal_registry[key];
}
function SymbolFor(key) {
key = TO_STRING_INLINE(key);
var registry = %SymbolRegistry();
......@@ -76,17 +75,6 @@ function ObjectGetOwnPropertySymbols(obj) {
return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING);
}
//-------------------------------------------------------------------
var symbolHasInstance = InternalSymbol("Symbol.hasInstance");
var symbolIsConcatSpreadable = InternalSymbol("Symbol.isConcatSpreadable");
var symbolIsRegExp = InternalSymbol("Symbol.isRegExp");
var symbolIterator = InternalSymbol("Symbol.iterator");
var symbolToStringTag = InternalSymbol("Symbol.toStringTag");
var symbolUnscopables = InternalSymbol("Symbol.unscopables");
//-------------------------------------------------------------------
function SetUpSymbol() {
......
......@@ -51,9 +51,6 @@
# Issue 3389: deopt_every_n_garbage_collections is unsafe
'regress/regress-2653': [SKIP],
# Issue 3689: serializer does not handle internal symbols.
'regress/regress-2506': [PASS, FAIL],
##############################################################################
# TurboFan compiler failures.
......
......@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// TODO(dslomov): Bug 3689. Code caching does not work well with for-of
// Flags: --harmony-scoping --cache=none
// Flags: --harmony-scoping
'use strict';
......
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