Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: src/bootstrapper.cc

Issue 1542963002: [runtime] Introduce dedicated JSBoundFunction to represent bound functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@FunctionConstructor
Patch Set: [arm64] Poke does not preserve flags with --debug-code. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/bailout-reason.h ('k') | src/builtins.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 34494122096da30dfc5919d15e74e71547e42136..1dee9794dfc2bd509088fcb9a8b9d57ec32ed540 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -269,8 +269,7 @@ class Genesis BASE_EMBEDDED {
FUNCTION_WITH_WRITEABLE_PROTOTYPE,
FUNCTION_WITH_READONLY_PROTOTYPE,
// Without prototype.
- FUNCTION_WITHOUT_PROTOTYPE,
- BOUND_FUNCTION
+ FUNCTION_WITHOUT_PROTOTYPE
};
static bool IsFunctionModeWithPrototype(FunctionMode function_mode) {
@@ -486,7 +485,7 @@ void Genesis::SetFunctionInstanceDescriptor(Handle<Map> map,
Handle<Map> Genesis::CreateSloppyFunctionMap(FunctionMode function_mode) {
Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
SetFunctionInstanceDescriptor(map, function_mode);
- map->set_is_constructor(IsFunctionModeWithPrototype(function_mode));
+ if (IsFunctionModeWithPrototype(function_mode)) map->set_is_constructor();
map->set_is_callable();
return map;
}
@@ -609,35 +608,22 @@ void Genesis::SetStrictFunctionInstanceDescriptor(Handle<Map> map,
PropertyAttributes roc_attribs =
static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
- if (function_mode == BOUND_FUNCTION) {
- { // Add length.
- Handle<String> length_string = isolate()->factory()->length_string();
- DataDescriptor d(length_string, 0, roc_attribs, Representation::Tagged());
- map->AppendDescriptor(&d);
- }
- { // Add name.
- Handle<String> name_string = isolate()->factory()->name_string();
- DataDescriptor d(name_string, 1, roc_attribs, Representation::Tagged());
- map->AppendDescriptor(&d);
- }
- } else {
- DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ||
- function_mode == FUNCTION_WITH_READONLY_PROTOTYPE ||
- function_mode == FUNCTION_WITHOUT_PROTOTYPE);
- { // Add length.
- Handle<AccessorInfo> length =
- Accessors::FunctionLengthInfo(isolate(), roc_attribs);
- AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())),
- length, roc_attribs);
- map->AppendDescriptor(&d);
- }
- { // Add name.
- Handle<AccessorInfo> name =
- Accessors::FunctionNameInfo(isolate(), roc_attribs);
- AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name,
- roc_attribs);
- map->AppendDescriptor(&d);
- }
+ DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ||
+ function_mode == FUNCTION_WITH_READONLY_PROTOTYPE ||
+ function_mode == FUNCTION_WITHOUT_PROTOTYPE);
+ { // Add length.
+ Handle<AccessorInfo> length =
+ Accessors::FunctionLengthInfo(isolate(), roc_attribs);
+ AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())),
+ length, roc_attribs);
+ map->AppendDescriptor(&d);
+ }
+ { // Add name.
+ Handle<AccessorInfo> name =
+ Accessors::FunctionNameInfo(isolate(), roc_attribs);
+ AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name,
+ roc_attribs);
+ map->AppendDescriptor(&d);
}
if (IsFunctionModeWithPrototype(function_mode)) {
// Add prototype.
@@ -732,7 +718,7 @@ Handle<Map> Genesis::CreateStrictFunctionMap(
FunctionMode function_mode, Handle<JSFunction> empty_function) {
Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
SetStrictFunctionInstanceDescriptor(map, function_mode);
- map->set_is_constructor(IsFunctionModeWithPrototype(function_mode));
+ if (IsFunctionModeWithPrototype(function_mode)) map->set_is_constructor();
map->set_is_callable();
Map::SetPrototype(map, empty_function);
return map;
@@ -743,7 +729,7 @@ Handle<Map> Genesis::CreateStrongFunctionMap(
Handle<JSFunction> empty_function, bool is_constructor) {
Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
SetStrongFunctionInstanceDescriptor(map);
- map->set_is_constructor(is_constructor);
+ if (is_constructor) map->set_is_constructor();
Map::SetPrototype(map, empty_function);
map->set_is_callable();
map->set_is_extensible(is_constructor);
@@ -770,21 +756,6 @@ void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
// This map is installed in MakeFunctionInstancePrototypeWritable.
strict_function_map_writable_prototype_ =
CreateStrictFunctionMap(FUNCTION_WITH_WRITEABLE_PROTOTYPE, empty);
-
- // Special map for non-constructor bound functions.
- // TODO(bmeurer): Bound functions should not be represented as JSFunctions.
- Handle<Map> bound_function_without_constructor_map =
- CreateStrictFunctionMap(BOUND_FUNCTION, empty);
- native_context()->set_bound_function_without_constructor_map(
- *bound_function_without_constructor_map);
-
- // Special map for constructor bound functions.
- // TODO(bmeurer): Bound functions should not be represented as JSFunctions.
- Handle<Map> bound_function_with_constructor_map =
- Map::Copy(bound_function_without_constructor_map, "IsConstructor");
- bound_function_with_constructor_map->set_is_constructor(true);
- native_context()->set_bound_function_with_constructor_map(
- *bound_function_with_constructor_map);
}
@@ -1459,6 +1430,35 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Context::JS_WEAK_SET_FUN_INDEX);
}
+ { // --- B o u n d F u n c t i o n
+ Handle<Map> map =
+ factory->NewMap(JS_BOUND_FUNCTION_TYPE, JSBoundFunction::kSize);
+ map->set_is_callable();
+ Map::SetPrototype(map, empty_function);
+
+ PropertyAttributes roc_attribs =
+ static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
+ Map::EnsureDescriptorSlack(map, 2);
+
+ { // length
+ DataDescriptor d(factory->length_string(), JSBoundFunction::kLengthIndex,
+ roc_attribs, Representation::Tagged());
+ map->AppendDescriptor(&d);
+ }
+ { // name
+ DataDescriptor d(factory->name_string(), JSBoundFunction::kNameIndex,
+ roc_attribs, Representation::Tagged());
+ map->AppendDescriptor(&d);
+ }
+
+ map->SetInObjectProperties(2);
+ native_context()->set_bound_function_without_constructor_map(*map);
+
+ map = Map::Copy(map, "IsConstructor");
+ map->set_is_constructor();
+ native_context()->set_bound_function_with_constructor_map(*map);
+ }
+
{ // --- sloppy arguments map
// Make sure we can recognize argument objects at runtime.
// This is done by introducing an anonymous function with
@@ -2285,7 +2285,7 @@ void Genesis::InstallJSProxyMaps() {
Handle<Map> proxy_function_map =
Map::Copy(isolate()->sloppy_function_without_prototype_map(), "Proxy");
- proxy_function_map->set_is_constructor(true);
+ proxy_function_map->set_is_constructor();
native_context()->set_proxy_function_map(*proxy_function_map);
Handle<Map> proxy_map =
@@ -2299,7 +2299,7 @@ void Genesis::InstallJSProxyMaps() {
Handle<Map> proxy_constructor_map =
Map::Copy(proxy_callable_map, "constructor Proxy");
- proxy_constructor_map->set_is_constructor(true);
+ proxy_constructor_map->set_is_constructor();
native_context()->set_proxy_constructor_map(*proxy_constructor_map);
}
@@ -2525,7 +2525,8 @@ bool Genesis::InstallNatives(ContextType context_type) {
// Set the lengths for the functions to satisfy ECMA-262.
concat->shared()->set_length(1);
}
- // Install Function.prototype.apply, call, and toString.
+
+ // Install Function.prototype.apply, bind, call, and toString.
{
Handle<String> key = factory()->Function_string();
Handle<JSFunction> function =
@@ -2534,9 +2535,11 @@ bool Genesis::InstallNatives(ContextType context_type) {
Handle<JSObject> proto =
Handle<JSObject>(JSObject::cast(function->instance_prototype()));
- // Install the apply, call and toString functions.
+ // Install the apply, bind, call and toString functions.
SimpleInstallFunction(proto, factory()->apply_string(),
Builtins::kFunctionPrototypeApply, 2, false);
+ SimpleInstallFunction(proto, factory()->bind_string(),
+ Builtins::kFunctionPrototypeBind, 1, false);
SimpleInstallFunction(proto, factory()->call_string(),
Builtins::kFunctionPrototypeCall, 1, false);
SimpleInstallFunction(proto, factory()->toString_string(),
« no previous file with comments | « src/bailout-reason.h ('k') | src/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698