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) {
// 04-14-15, section 25.2.4.3).
Handle<Map> strict_function_map(strict_function_map_writable_prototype_);
// Generator functions do not have "caller" or "arguments" accessors.
Handle<Map> sloppy_generator_function_map =
Map::Copy(strict_function_map, "SloppyGeneratorFunction");
sloppy_generator_function_map->set_is_constructor(false);
Map::SetPrototype(sloppy_generator_function_map,
generator_function_prototype);
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<Map> generator_function_map =
Map::Copy(strict_function_map, "GeneratorFunction");
generator_function_map->set_is_constructor(false);
Map::SetPrototype(generator_function_map, generator_function_prototype);
native_context()->set_generator_function_map(*generator_function_map);
Handle<JSFunction> object_function(native_context()->object_function());
Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
......@@ -790,17 +780,11 @@ void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
Handle<Map> strict_function_map(
native_context()->strict_function_without_prototype_map());
Handle<Map> sloppy_async_function_map =
Map::Copy(strict_function_map, "SloppyAsyncFunction");
sloppy_async_function_map->set_is_constructor(false);
Map::SetPrototype(sloppy_async_function_map, async_function_prototype);
native_context()->set_sloppy_async_function_map(*sloppy_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);
Handle<Map> async_function_map =
Map::Copy(strict_function_map, "AsyncFunction");
async_function_map->set_is_constructor(false);
Map::SetPrototype(async_function_map, async_function_prototype);
native_context()->set_async_function_map(*async_function_map);
}
void Genesis::CreateJSProxyMaps() {
......@@ -3137,7 +3121,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
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>());
JSObject::AddProperty(
......@@ -3150,7 +3134,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
generator_function_prototype, Builtins::kGeneratorFunctionConstructor,
kUseStrictFunctionMap);
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()->SetConstructStub(
*isolate->builtins()->GeneratorFunctionConstructor());
......@@ -3166,9 +3150,7 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
generator_function_function,
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
native_context->sloppy_generator_function_map()->SetConstructor(
*generator_function_function);
native_context->strict_generator_function_map()->SetConstructor(
native_context->generator_function_map()->SetConstructor(
*generator_function_function);
}
......@@ -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>());
static const bool kUseStrictFunctionMap = true;
......
......@@ -84,17 +84,13 @@ Node* ConstructorBuiltinsAssembler::EmitFastNewClosure(Node* shared_info,
Bind(&if_generator);
{
map_index.Bind(SelectIntPtrConstant(
is_strict, Context::STRICT_GENERATOR_FUNCTION_MAP_INDEX,
Context::SLOPPY_GENERATOR_FUNCTION_MAP_INDEX));
map_index.Bind(IntPtrConstant(Context::GENERATOR_FUNCTION_MAP_INDEX));
Goto(&load_map);
}
Bind(&if_async);
{
map_index.Bind(SelectIntPtrConstant(
is_strict, Context::STRICT_ASYNC_FUNCTION_MAP_INDEX,
Context::SLOPPY_ASYNC_FUNCTION_MAP_INDEX));
map_index.Bind(IntPtrConstant(Context::ASYNC_FUNCTION_MAP_INDEX));
Goto(&load_map);
}
......
......@@ -306,24 +306,22 @@ enum ContextLookupFlags {
V(SET_ITERATOR_MAP_INDEX, Map, set_iterator_map) \
V(SHARED_ARRAY_BUFFER_FUN_INDEX, JSFunction, shared_array_buffer_fun) \
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_WITHOUT_PROTOTYPE_MAP_INDEX, Map, \
sloppy_function_without_prototype_map) \
V(SLOPPY_FUNCTION_WITH_READONLY_PROTOTYPE_MAP_INDEX, 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_OBJECT_WITH_NULL_PROTOTYPE_MAP, Map, \
slow_object_with_null_prototype_map) \
V(SLOW_TEMPLATE_INSTANTIATIONS_CACHE_INDEX, UnseededNumberDictionary, \
slow_template_instantiations_cache) \
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_WITHOUT_PROTOTYPE_MAP_INDEX, 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(STRING_FUNCTION_INDEX, JSFunction, string_function) \
V(STRING_FUNCTION_PROTOTYPE_MAP_INDEX, Map, string_function_prototype_map) \
......@@ -639,13 +637,11 @@ class Context: public FixedArray {
static int FunctionMapIndex(LanguageMode language_mode, FunctionKind kind) {
// Note: Must be kept in sync with the FastNewClosure builtin.
if (IsGeneratorFunction(kind)) {
return is_strict(language_mode) ? STRICT_GENERATOR_FUNCTION_MAP_INDEX
: SLOPPY_GENERATOR_FUNCTION_MAP_INDEX;
return GENERATOR_FUNCTION_MAP_INDEX;
}
if (IsAsyncFunction(kind)) {
return is_strict(language_mode) ? STRICT_ASYNC_FUNCTION_MAP_INDEX
: SLOPPY_ASYNC_FUNCTION_MAP_INDEX;
return ASYNC_FUNCTION_MAP_INDEX;
}
if (IsClassConstructor(kind)) {
......
......@@ -9111,12 +9111,13 @@ Handle<Map> Map::CopyInitialMap(Handle<Map> map, int instance_size,
Isolate* isolate = map->GetIsolate();
// Strict function maps have Function as a constructor but the
// 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();
DCHECK(constructor->IsJSFunction());
DCHECK(*map == JSFunction::cast(constructor)->initial_map() ||
*map == *isolate->strict_function_map() ||
*map == *isolate->strict_generator_function_map());
*map == *isolate->generator_function_map() ||
*map == *isolate->async_function_map());
#endif
// Initial maps must always own their descriptors and it's descriptor array
// does not contain descriptors that do not belong to the map.
......
......@@ -144,18 +144,32 @@ assertEquals(1, AsyncFunction.length);
// Let F be ! FunctionAllocate(functionPrototype, Strict, "non-constructor")
async function asyncNonConstructorDecl() {}
assertThrows(
() => new asyncNonConstructorDecl(), TypeError);
assertThrows(
() => new (async function() {}), TypeError);
assertThrows(() => new asyncNonConstructorDecl(), TypeError);
assertThrows(() => asyncNonConstructorDecl.caller, TypeError);
assertThrows(() => asyncNonConstructorDecl.arguments, TypeError);
assertThrows(() => new (async function() {}), TypeError);
assertThrows(() => (async function() {}).caller, TypeError);
assertThrows(() => (async function() {}).arguments, TypeError);
assertThrows(
() => new ({ async nonConstructor() {} }).nonConstructor(), TypeError);
assertThrows(
() => new (() => "not a constructor!"), TypeError);
() => ({ async nonConstructor() {} }).nonConstructor.caller, TypeError);
assertThrows(
() => new (AsyncFunction()), TypeError);
assertThrows(
() => new (new AsyncFunction()), TypeError);
() => ({ async nonConstructor() {} }).nonConstructor.arguments, 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
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