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

Unified Diff: src/api-natives.cc

Issue 2531653002: [api] Support sharing prototypes between FunctionTemplates (Closed)
Patch Set: fixing test Created 4 years, 1 month 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.cc ('k') | src/objects.h » ('j') | no next file with comments »
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 3fe59e293d3ff2d1d8d3b3fd688897334e6e95c8..bb86f1f5394fc818fbb46914ab3a4f9e1e4754ea 100644
--- a/src/api-natives.cc
+++ b/src/api-natives.cc
@@ -395,6 +395,28 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
return result;
}
+namespace {
+MaybeHandle<Object> GetInstancePrototype(Isolate* isolate,
+ Object* function_template) {
+ // Enter a new scope. Recursion could otherwise create a lot of handles.
+ HandleScope scope(isolate);
+ Handle<JSFunction> parent_instance;
+ ASSIGN_RETURN_ON_EXCEPTION(
+ isolate, parent_instance,
+ InstantiateFunction(
+ isolate,
+ handle(FunctionTemplateInfo::cast(function_template), isolate)),
+ JSFunction);
+ Handle<Object> instance_prototype;
+ // TODO(cbruni): decide what to do here.
+ ASSIGN_RETURN_ON_EXCEPTION(
+ isolate, instance_prototype,
+ JSObject::GetProperty(parent_instance,
+ isolate->factory()->prototype_string()),
+ JSFunction);
+ return scope.CloseAndEscape(instance_prototype);
+}
+} // namespace
MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
Handle<FunctionTemplateInfo> data,
@@ -406,11 +428,18 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
return Handle<JSFunction>::cast(result);
}
}
- Handle<JSObject> prototype;
+ Handle<Object> prototype;
if (!data->remove_prototype()) {
Object* prototype_templ = data->prototype_template();
if (prototype_templ->IsUndefined(isolate)) {
- prototype = isolate->factory()->NewJSObject(isolate->object_function());
+ Object* protoype_provider_templ = data->prototype_provider_template();
+ if (protoype_provider_templ->IsUndefined(isolate)) {
+ prototype = isolate->factory()->NewJSObject(isolate->object_function());
+ } else {
+ ASSIGN_RETURN_ON_EXCEPTION(
+ isolate, prototype,
+ GetInstancePrototype(isolate, protoype_provider_templ), JSFunction);
+ }
} else {
ASSIGN_RETURN_ON_EXCEPTION(
isolate, prototype,
@@ -422,22 +451,12 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
}
Object* parent = data->parent_template();
if (!parent->IsUndefined(isolate)) {
- // Enter a new scope. Recursion could otherwise create a lot of handles.
- HandleScope scope(isolate);
- Handle<JSFunction> parent_instance;
- ASSIGN_RETURN_ON_EXCEPTION(
- isolate, parent_instance,
- InstantiateFunction(
- isolate, handle(FunctionTemplateInfo::cast(parent), isolate)),
- JSFunction);
- // TODO(dcarney): decide what to do here.
Handle<Object> parent_prototype;
- ASSIGN_RETURN_ON_EXCEPTION(
- isolate, parent_prototype,
- JSObject::GetProperty(parent_instance,
- isolate->factory()->prototype_string()),
- JSFunction);
- JSObject::ForceSetPrototype(prototype, parent_prototype);
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, parent_prototype,
+ GetInstancePrototype(isolate, parent),
+ JSFunction);
+ JSObject::ForceSetPrototype(Handle<JSObject>::cast(prototype),
+ parent_prototype);
}
}
Handle<JSFunction> function = ApiNatives::CreateApiFunction(
@@ -606,7 +625,7 @@ Handle<JSFunction> ApiNatives::CreateApiFunction(
if (prototype->IsTheHole(isolate)) {
prototype = isolate->factory()->NewFunctionPrototype(result);
- } else {
+ } else if (obj->prototype_provider_template()->IsUndefined(isolate)) {
JSObject::AddProperty(Handle<JSObject>::cast(prototype),
isolate->factory()->constructor_string(), result,
DONT_ENUM);
« no previous file with comments | « src/api.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698