Index: src/api-natives.cc |
diff --git a/src/api-natives.cc b/src/api-natives.cc |
index f09f42d5f0480f76b8d6ac4c0e54efb0f6a9314e..af70bfb161b73d75a68377064715deb2a493179d 100644 |
--- a/src/api-natives.cc |
+++ b/src/api-natives.cc |
@@ -539,9 +539,22 @@ Handle<JSFunction> ApiNatives::CreateApiFunction( |
Handle<Object> prototype, ApiInstanceType instance_type) { |
Handle<SharedFunctionInfo> shared = |
FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, obj); |
+ int map_index = |
+ Context::FunctionMapIndex(shared->language_mode(), shared->kind()); |
+ Handle<Map> initial_map(Map::cast(isolate->native_context()->get(map_index))); |
+ return CreateApiFunctionWithMap(isolate, isolate->native_context(), obj, |
+ initial_map, prototype, instance_type); |
+} |
+ |
+Handle<JSFunction> ApiNatives::CreateApiFunctionWithMap( |
+ Isolate* isolate, Handle<Object> context_or_undefined, |
+ Handle<FunctionTemplateInfo> obj, Handle<Map> initial_map, |
+ Handle<Object> prototype, ApiInstanceType instance_type) { |
+ Handle<SharedFunctionInfo> shared = |
+ FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(isolate, obj); |
Handle<JSFunction> result = |
isolate->factory()->NewFunctionFromSharedFunctionInfo( |
- shared, isolate->native_context()); |
+ initial_map, shared, context_or_undefined); |
if (obj->remove_prototype()) { |
result->set_map(*isolate->sloppy_function_without_prototype_map()); |
@@ -560,12 +573,16 @@ Handle<JSFunction> ApiNatives::CreateApiFunction( |
result->set_map(*isolate->sloppy_function_with_readonly_prototype_map()); |
} |
- if (prototype->IsTheHole(isolate)) { |
- prototype = isolate->factory()->NewFunctionPrototype(result); |
+ if (context_or_undefined->IsContext()) { |
+ if (prototype->IsTheHole(isolate)) { |
+ prototype = isolate->factory()->NewFunctionPrototype(result); |
+ } else { |
+ JSObject::AddProperty(Handle<JSObject>::cast(prototype), |
+ isolate->factory()->constructor_string(), result, |
+ DONT_ENUM); |
+ } |
} else { |
- JSObject::AddProperty(Handle<JSObject>::cast(prototype), |
- isolate->factory()->constructor_string(), result, |
- DONT_ENUM); |
+ prototype = isolate->factory()->null_value(); |
jochen (gone - plz use gerrit)
2016/06/28 14:27:00
we can't create a prototype object without the obj
|
} |
int internal_field_count = 0; |
@@ -607,7 +624,7 @@ Handle<JSFunction> ApiNatives::CreateApiFunction( |
Handle<Map> map = |
isolate->factory()->NewMap(type, instance_size, FAST_HOLEY_SMI_ELEMENTS); |
- JSFunction::SetInitialMap(result, map, Handle<JSObject>::cast(prototype)); |
+ JSFunction::SetInitialMap(result, map, prototype); |
// Mark as undetectable if needed. |
if (obj->undetectable()) { |