Commit c5234747 authored by caitp's avatar caitp Committed by Commit bot

[cleanup] remove sloppy generator/async function maps

These maps contain exactly the same information as the strict maps, so
this frees up a few pointers of native context space, gets rid of some
branches in FastNewClosure, and adds missing poisoned properties tests
for async functions.

BUG=v8:2355, v8:4483
R=adamk@chromium.org, bmeurer@chromium.org, littledan@chromium.org

Review-Url: https://codereview.chromium.org/2608333002
Cr-Commit-Position: refs/heads/master@{#42051}
parent 410606a0
...@@ -754,21 +754,11 @@ void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) { ...@@ -754,21 +754,11 @@ void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) {
// 04-14-15, section 25.2.4.3). // 04-14-15, section 25.2.4.3).
Handle<Map> strict_function_map(strict_function_map_writable_prototype_); Handle<Map> strict_function_map(strict_function_map_writable_prototype_);
// Generator functions do not have "caller" or "arguments" accessors. // Generator functions do not have "caller" or "arguments" accessors.
Handle<Map> sloppy_generator_function_map = Handle<Map> generator_function_map =
Map::Copy(strict_function_map, "SloppyGeneratorFunction"); Map::Copy(strict_function_map, "GeneratorFunction");
sloppy_generator_function_map->set_is_constructor(false); generator_function_map->set_is_constructor(false);
Map::SetPrototype(sloppy_generator_function_map, Map::SetPrototype(generator_function_map, generator_function_prototype);
generator_function_prototype); native_context()->set_generator_function_map(*generator_function_map);
native_context()->set_sloppy_generator_function_map(
*sloppy_generator_function_map);
Handle<Map> strict_generator_function_map =
Map::Copy(strict_function_map, "StrictGeneratorFunction");
strict_generator_function_map->set_is_constructor(false);
Map::SetPrototype(strict_generator_function_map,
generator_function_prototype);
native_context()->set_strict_generator_function_map(
*strict_generator_function_map);
Handle<JSFunction> object_function(native_context()->object_function()); Handle<JSFunction> object_function(native_context()->object_function());
Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
...@@ -790,17 +780,11 @@ void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) { ...@@ -790,17 +780,11 @@ void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
Handle<Map> strict_function_map( Handle<Map> strict_function_map(
native_context()->strict_function_without_prototype_map()); native_context()->strict_function_without_prototype_map());
Handle<Map> sloppy_async_function_map = Handle<Map> async_function_map =
Map::Copy(strict_function_map, "SloppyAsyncFunction"); Map::Copy(strict_function_map, "AsyncFunction");
sloppy_async_function_map->set_is_constructor(false); async_function_map->set_is_constructor(false);
Map::SetPrototype(sloppy_async_function_map, async_function_prototype); Map::SetPrototype(async_function_map, async_function_prototype);
native_context()->set_sloppy_async_function_map(*sloppy_async_function_map); native_context()->set_async_function_map(*async_function_map);
Handle<Map> strict_async_function_map =
Map::Copy(strict_function_map, "StrictAsyncFunction");
strict_async_function_map->set_is_constructor(false);
Map::SetPrototype(strict_async_function_map, async_function_prototype);
native_context()->set_strict_async_function_map(*strict_async_function_map);
} }
void Genesis::CreateJSProxyMaps() { void Genesis::CreateJSProxyMaps() {
...@@ -3137,7 +3121,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, ...@@ -3137,7 +3121,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
iterator_prototype, NONE); iterator_prototype, NONE);
{ {
PrototypeIterator iter(native_context->sloppy_generator_function_map()); PrototypeIterator iter(native_context->generator_function_map());
Handle<JSObject> generator_function_prototype(iter.GetCurrent<JSObject>()); Handle<JSObject> generator_function_prototype(iter.GetCurrent<JSObject>());
JSObject::AddProperty( JSObject::AddProperty(
...@@ -3150,7 +3134,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, ...@@ -3150,7 +3134,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
generator_function_prototype, Builtins::kGeneratorFunctionConstructor, generator_function_prototype, Builtins::kGeneratorFunctionConstructor,
kUseStrictFunctionMap); kUseStrictFunctionMap);
generator_function_function->set_prototype_or_initial_map( generator_function_function->set_prototype_or_initial_map(
native_context->sloppy_generator_function_map()); native_context->generator_function_map());
generator_function_function->shared()->DontAdaptArguments(); generator_function_function->shared()->DontAdaptArguments();
generator_function_function->shared()->SetConstructStub( generator_function_function->shared()->SetConstructStub(
*isolate->builtins()->GeneratorFunctionConstructor()); *isolate->builtins()->GeneratorFunctionConstructor());
...@@ -3166,9 +3150,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, ...@@ -3166,9 +3150,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
generator_function_function, generator_function_function,
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
native_context->sloppy_generator_function_map()->SetConstructor( native_context->generator_function_map()->SetConstructor(
*generator_function_function);
native_context->strict_generator_function_map()->SetConstructor(
*generator_function_function); *generator_function_function);
} }
...@@ -3322,7 +3304,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate, ...@@ -3322,7 +3304,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
} }
{ {
PrototypeIterator iter(native_context->sloppy_async_function_map()); PrototypeIterator iter(native_context->async_function_map());
Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>()); Handle<JSObject> async_function_prototype(iter.GetCurrent<JSObject>());
static const bool kUseStrictFunctionMap = true; static const bool kUseStrictFunctionMap = true;
......
...@@ -84,17 +84,13 @@ Node* ConstructorBuiltinsAssembler::EmitFastNewClosure(Node* shared_info, ...@@ -84,17 +84,13 @@ Node* ConstructorBuiltinsAssembler::EmitFastNewClosure(Node* shared_info,
Bind(&if_generator); Bind(&if_generator);
{ {
map_index.Bind(SelectIntPtrConstant( map_index.Bind(IntPtrConstant(Context::GENERATOR_FUNCTION_MAP_INDEX));
is_strict, Context::STRICT_GENERATOR_FUNCTION_MAP_INDEX,
Context::SLOPPY_GENERATOR_FUNCTION_MAP_INDEX));
Goto(&load_map); Goto(&load_map);
} }
Bind(&if_async); Bind(&if_async);
{ {
map_index.Bind(SelectIntPtrConstant( map_index.Bind(IntPtrConstant(Context::ASYNC_FUNCTION_MAP_INDEX));
is_strict, Context::STRICT_ASYNC_FUNCTION_MAP_INDEX,
Context::SLOPPY_ASYNC_FUNCTION_MAP_INDEX));
Goto(&load_map); Goto(&load_map);
} }
......
...@@ -306,24 +306,22 @@ enum ContextLookupFlags { ...@@ -306,24 +306,22 @@ enum ContextLookupFlags {
V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \ V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \
V(SHARED_ARRAY_BUFFER_FUN_INDEX, JSFunction, shared_array_buffer_fun) \ V(SHARED_ARRAY_BUFFER_FUN_INDEX, JSFunction, shared_array_buffer_fun) \
V(SLOPPY_ARGUMENTS_MAP_INDEX, Map, sloppy_arguments_map) \ V(SLOPPY_ARGUMENTS_MAP_INDEX, Map, sloppy_arguments_map) \
V(SLOPPY_ASYNC_FUNCTION_MAP_INDEX, Map, sloppy_async_function_map) \
V(SLOPPY_FUNCTION_MAP_INDEX, Map, sloppy_function_map) \ V(SLOPPY_FUNCTION_MAP_INDEX, Map, sloppy_function_map) \
V(SLOPPY_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \ V(SLOPPY_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \
sloppy_function_without_prototype_map) \ sloppy_function_without_prototype_map) \
V(SLOPPY_FUNCTION_WITH_READONLY_PROTOTYPE_MAP_INDEX, Map, \ V(SLOPPY_FUNCTION_WITH_READONLY_PROTOTYPE_MAP_INDEX, Map, \
sloppy_function_with_readonly_prototype_map) \ sloppy_function_with_readonly_prototype_map) \
V(SLOPPY_GENERATOR_FUNCTION_MAP_INDEX, Map, sloppy_generator_function_map) \
V(SLOW_ALIASED_ARGUMENTS_MAP_INDEX, Map, slow_aliased_arguments_map) \ V(SLOW_ALIASED_ARGUMENTS_MAP_INDEX, Map, slow_aliased_arguments_map) \
V(SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP, Map, \ V(SLOW_OBJECT_WITH_NULL_PROTOTYPE_MAP, Map, \
slow_object_with_null_prototype_map) \ slow_object_with_null_prototype_map) \
V(SLOW_TEMPLATE_INSTANTIATIONS_CACHE_INDEX, UnseededNumberDictionary, \ V(SLOW_TEMPLATE_INSTANTIATIONS_CACHE_INDEX, UnseededNumberDictionary, \
slow_template_instantiations_cache) \ slow_template_instantiations_cache) \
V(STRICT_ARGUMENTS_MAP_INDEX, Map, strict_arguments_map) \ V(STRICT_ARGUMENTS_MAP_INDEX, Map, strict_arguments_map) \
V(STRICT_ASYNC_FUNCTION_MAP_INDEX, Map, strict_async_function_map) \ V(ASYNC_FUNCTION_MAP_INDEX, Map, async_function_map) \
V(STRICT_FUNCTION_MAP_INDEX, Map, strict_function_map) \ V(STRICT_FUNCTION_MAP_INDEX, Map, strict_function_map) \
V(STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \ V(STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \
strict_function_without_prototype_map) \ strict_function_without_prototype_map) \
V(STRICT_GENERATOR_FUNCTION_MAP_INDEX, Map, strict_generator_function_map) \ V(GENERATOR_FUNCTION_MAP_INDEX, Map, generator_function_map) \
V(CLASS_FUNCTION_MAP_INDEX, Map, class_function_map) \ V(CLASS_FUNCTION_MAP_INDEX, Map, class_function_map) \
V(STRING_FUNCTION_INDEX, JSFunction, string_function) \ V(STRING_FUNCTION_INDEX, JSFunction, string_function) \
V(STRING_FUNCTION_PROTOTYPE_MAP_INDEX, Map, string_function_prototype_map) \ V(STRING_FUNCTION_PROTOTYPE_MAP_INDEX, Map, string_function_prototype_map) \
...@@ -639,13 +637,11 @@ class Context: public FixedArray { ...@@ -639,13 +637,11 @@ class Context: public FixedArray {
static int FunctionMapIndex(LanguageMode language_mode, FunctionKind kind) { static int FunctionMapIndex(LanguageMode language_mode, FunctionKind kind) {
// Note: Must be kept in sync with the FastNewClosure builtin. // Note: Must be kept in sync with the FastNewClosure builtin.
if (IsGeneratorFunction(kind)) { if (IsGeneratorFunction(kind)) {
return is_strict(language_mode) ? STRICT_GENERATOR_FUNCTION_MAP_INDEX return GENERATOR_FUNCTION_MAP_INDEX;
: SLOPPY_GENERATOR_FUNCTION_MAP_INDEX;
} }
if (IsAsyncFunction(kind)) { if (IsAsyncFunction(kind)) {
return is_strict(language_mode) ? STRICT_ASYNC_FUNCTION_MAP_INDEX return ASYNC_FUNCTION_MAP_INDEX;
: SLOPPY_ASYNC_FUNCTION_MAP_INDEX;
} }
if (IsClassConstructor(kind)) { if (IsClassConstructor(kind)) {
......
...@@ -9111,12 +9111,13 @@ Handle<Map> Map::CopyInitialMap(Handle<Map> map, int instance_size, ...@@ -9111,12 +9111,13 @@ Handle<Map> Map::CopyInitialMap(Handle<Map> map, int instance_size,
Isolate* isolate = map->GetIsolate(); Isolate* isolate = map->GetIsolate();
// Strict function maps have Function as a constructor but the // Strict function maps have Function as a constructor but the
// Function's initial map is a sloppy function map. Same holds for // Function's initial map is a sloppy function map. Same holds for
// GeneratorFunction and its initial map. // GeneratorFunction / AsyncFunction and its initial map.
Object* constructor = map->GetConstructor(); Object* constructor = map->GetConstructor();
DCHECK(constructor->IsJSFunction()); DCHECK(constructor->IsJSFunction());
DCHECK(*map == JSFunction::cast(constructor)->initial_map() || DCHECK(*map == JSFunction::cast(constructor)->initial_map() ||
*map == *isolate->strict_function_map() || *map == *isolate->strict_function_map() ||
*map == *isolate->strict_generator_function_map()); *map == *isolate->generator_function_map() ||
*map == *isolate->async_function_map());
#endif #endif
// Initial maps must always own their descriptors and it's descriptor array // Initial maps must always own their descriptors and it's descriptor array
// does not contain descriptors that do not belong to the map. // does not contain descriptors that do not belong to the map.
......
...@@ -144,18 +144,32 @@ assertEquals(1, AsyncFunction.length); ...@@ -144,18 +144,32 @@ assertEquals(1, AsyncFunction.length);
// Let F be ! FunctionAllocate(functionPrototype, Strict, "non-constructor") // Let F be ! FunctionAllocate(functionPrototype, Strict, "non-constructor")
async function asyncNonConstructorDecl() {} async function asyncNonConstructorDecl() {}
assertThrows( assertThrows(() => new asyncNonConstructorDecl(), TypeError);
() => new asyncNonConstructorDecl(), TypeError); assertThrows(() => asyncNonConstructorDecl.caller, TypeError);
assertThrows( assertThrows(() => asyncNonConstructorDecl.arguments, TypeError);
() => new (async function() {}), TypeError);
assertThrows(() => new (async function() {}), TypeError);
assertThrows(() => (async function() {}).caller, TypeError);
assertThrows(() => (async function() {}).arguments, TypeError);
assertThrows( assertThrows(
() => new ({ async nonConstructor() {} }).nonConstructor(), TypeError); () => new ({ async nonConstructor() {} }).nonConstructor(), TypeError);
assertThrows( assertThrows(
() => new (() => "not a constructor!"), TypeError); () => ({ async nonConstructor() {} }).nonConstructor.caller, TypeError);
assertThrows( assertThrows(
() => new (AsyncFunction()), TypeError); () => ({ async nonConstructor() {} }).nonConstructor.arguments, TypeError);
assertThrows(
() => new (new AsyncFunction()), TypeError); assertThrows(() => new (() => "not a constructor!"), TypeError);
assertThrows(() => (() => 1).caller, TypeError);
assertThrows(() => (() => 1).arguments, TypeError);
assertThrows(() => new (AsyncFunction()), TypeError);
assertThrows(() => AsyncFunction().caller, TypeError);
assertThrows(() => AsyncFunction().arguments, TypeError);
assertThrows(() => new (new AsyncFunction()), TypeError);
assertThrows(() => (new AsyncFunction()).caller, TypeError);
assertThrows(() => (new AsyncFunction()).arguments, TypeError);
// Normal completion // Normal completion
async function asyncDecl() { return "test"; } async function asyncDecl() { return "test"; }
......
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