Commit aee244b0 authored by ishell's avatar ishell Committed by Commit bot

[modules] Define @@toStringTag on namespace object as a field.

The constant field tracking implies data constants to be stored
in fields instead of descriptor arrays. This CL does necessary
modifications to the JSModuleNamespace map setup.

BUG=v8:1569, v8:5495

Review-Url: https://codereview.chromium.org/2625093005
Cr-Commit-Position: refs/heads/master@{#42294}
parent 7c743408
...@@ -2583,11 +2583,14 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2583,11 +2583,14 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // Install @@toStringTag. { // Install @@toStringTag.
PropertyAttributes attribs = PropertyAttributes attribs =
static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY); static_cast<PropertyAttributes>(DONT_DELETE | DONT_ENUM | READ_ONLY);
Descriptor d = Descriptor::DataConstant( Descriptor d =
factory->to_string_tag_symbol(), Descriptor::DataField(factory->to_string_tag_symbol(),
factory->NewStringFromAsciiChecked("Module"), attribs); JSModuleNamespace::kToStringTagFieldIndex,
attribs, Representation::Tagged());
map->AppendDescriptor(&d); map->AppendDescriptor(&d);
} }
map->SetInObjectProperties(JSModuleNamespace::kInObjectFieldCount);
} }
{ // -- I t e r a t o r R e s u l t { // -- I t e r a t o r R e s u l t
......
...@@ -1851,7 +1851,13 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array, ...@@ -1851,7 +1851,13 @@ void Factory::NewJSArrayStorage(Handle<JSArray> array,
Handle<JSModuleNamespace> Factory::NewJSModuleNamespace() { Handle<JSModuleNamespace> Factory::NewJSModuleNamespace() {
Handle<Map> map = isolate()->js_module_namespace_map(); Handle<Map> map = isolate()->js_module_namespace_map();
return Handle<JSModuleNamespace>::cast(NewJSObjectFromMap(map)); Handle<JSModuleNamespace> module_namespace(
Handle<JSModuleNamespace>::cast(NewJSObjectFromMap(map)));
FieldIndex index = FieldIndex::ForDescriptor(
*map, JSModuleNamespace::kToStringTagFieldIndex);
Handle<String> to_string_value = NewStringFromAsciiChecked("Module");
module_namespace->FastPropertyAtPut(index, *to_string_value);
return module_namespace;
} }
Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
......
...@@ -2208,7 +2208,7 @@ int JSObject::GetHeaderSize(InstanceType type) { ...@@ -2208,7 +2208,7 @@ int JSObject::GetHeaderSize(InstanceType type) {
case JS_STRING_ITERATOR_TYPE: case JS_STRING_ITERATOR_TYPE:
return JSStringIterator::kSize; return JSStringIterator::kSize;
case JS_MODULE_NAMESPACE_TYPE: case JS_MODULE_NAMESPACE_TYPE:
return JSModuleNamespace::kSize; return JSModuleNamespace::kHeaderSize;
default: default:
if (type >= FIRST_ARRAY_ITERATOR_TYPE && if (type >= FIRST_ARRAY_ITERATOR_TYPE &&
type <= LAST_ARRAY_ITERATOR_TYPE) { type <= LAST_ARRAY_ITERATOR_TYPE) {
......
...@@ -1279,9 +1279,9 @@ void Module::ModulePrint(std::ostream& os) { // NOLINT ...@@ -1279,9 +1279,9 @@ void Module::ModulePrint(std::ostream& os) { // NOLINT
} }
void JSModuleNamespace::JSModuleNamespacePrint(std::ostream& os) { // NOLINT void JSModuleNamespace::JSModuleNamespacePrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "JSModuleNamespace"); JSObjectPrintHeader(os, this, "JSModuleNamespace");
os << "\n - module: " << Brief(module()); os << "\n - module: " << Brief(module());
os << "\n"; JSObjectPrintBody(os, this);
} }
void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) { // NOLINT void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) { // NOLINT
......
...@@ -7962,8 +7962,16 @@ class JSModuleNamespace : public JSObject { ...@@ -7962,8 +7962,16 @@ class JSModuleNamespace : public JSObject {
// schedule an exception and return Nothing. // schedule an exception and return Nothing.
MUST_USE_RESULT MaybeHandle<Object> GetExport(Handle<String> name); MUST_USE_RESULT MaybeHandle<Object> GetExport(Handle<String> name);
// In-object fields.
enum {
kToStringTagFieldIndex,
kInObjectFieldCount,
};
static const int kModuleOffset = JSObject::kHeaderSize; static const int kModuleOffset = JSObject::kHeaderSize;
static const int kSize = kModuleOffset + kPointerSize; static const int kHeaderSize = kModuleOffset + kPointerSize;
static const int kSize = kHeaderSize + kPointerSize * kInObjectFieldCount;
private: private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSModuleNamespace); DISALLOW_IMPLICIT_CONSTRUCTORS(JSModuleNamespace);
......
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