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

Unified Diff: src/api-natives.cc

Issue 2107673003: Add an API to create a detached global object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months 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/api-natives.h ('k') | src/bootstrapper.h » ('j') | src/bootstrapper.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()) {
« no previous file with comments | « src/api-natives.h ('k') | src/bootstrapper.h » ('j') | src/bootstrapper.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698