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

Unified Diff: src/factory.cc

Issue 253603003: Pass in the prototype to CreateApiFunction rather than setting it on the result. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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/factory.h ('k') | src/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 4ca8734100fcb4ce056fe3ad6650a7caac59e374..8307cfa196ab3835f7f57b7185f58ab77c92148b 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -1239,19 +1239,30 @@ Handle<Object> Factory::NewError(const char* constructor,
}
-Handle<JSFunction> Factory::NewFunction(Handle<String> name,
+Handle<JSFunction> Factory::NewFunction(MaybeHandle<Object> maybe_prototype,
+ Handle<String> name,
InstanceType type,
int instance_size,
Handle<Code> code,
bool force_initial_map) {
// Allocate the function
- Handle<JSFunction> function = NewFunction(name, code, the_hole_value());
+ Handle<JSFunction> function = NewFunction(name, code, maybe_prototype);
- if (force_initial_map ||
- type != JS_OBJECT_TYPE ||
- instance_size != JSObject::kHeaderSize) {
+ Handle<Object> prototype;
+ if (maybe_prototype.ToHandle(&prototype) &&
+ (force_initial_map ||
+ type != JS_OBJECT_TYPE ||
+ instance_size != JSObject::kHeaderSize)) {
Handle<Map> initial_map = NewMap(type, instance_size);
- Handle<JSObject> prototype = NewFunctionPrototype(function);
+ if (prototype->IsJSObject()) {
+ JSObject::SetLocalPropertyIgnoreAttributes(
+ Handle<JSObject>::cast(prototype),
+ constructor_string(),
+ function,
+ DONT_ENUM).Assert();
+ } else if (!function->shared()->is_generator()) {
+ prototype = NewFunctionPrototype(function);
+ }
initial_map->set_prototype(*prototype);
function->set_initial_map(*initial_map);
initial_map->set_constructor(*function);
@@ -1264,6 +1275,16 @@ Handle<JSFunction> Factory::NewFunction(Handle<String> name,
}
+Handle<JSFunction> Factory::NewFunction(Handle<String> name,
+ InstanceType type,
+ int instance_size,
+ Handle<Code> code,
+ bool force_initial_map) {
+ return NewFunction(
+ the_hole_value(), name, type, instance_size, code, force_initial_map);
+}
+
+
Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name,
InstanceType type,
int instance_size,
@@ -2041,7 +2062,9 @@ Handle<JSObject> Factory::NewArgumentsObject(Handle<Object> callee,
Handle<JSFunction> Factory::CreateApiFunction(
- Handle<FunctionTemplateInfo> obj, ApiInstanceType instance_type) {
+ Handle<FunctionTemplateInfo> obj,
+ Handle<Object> prototype,
+ ApiInstanceType instance_type) {
Handle<Code> code = isolate()->builtins()->HandleApiCall();
Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi();
@@ -2077,20 +2100,28 @@ Handle<JSFunction> Factory::CreateApiFunction(
break;
}
+ MaybeHandle<Object> maybe_prototype = prototype;
+ if (obj->remove_prototype()) maybe_prototype = MaybeHandle<Object>();
+
Handle<JSFunction> result = NewFunction(
- Factory::empty_string(), type, instance_size, code, true);
+ maybe_prototype, Factory::empty_string(), type,
+ instance_size, code, true);
- // Set length.
result->shared()->set_length(obj->length());
-
- // Set class name.
- Handle<Object> class_name = Handle<Object>(obj->class_name(), isolate());
+ Handle<Object> class_name(obj->class_name(), isolate());
if (class_name->IsString()) {
result->shared()->set_instance_class_name(*class_name);
result->shared()->set_name(*class_name);
}
+ result->shared()->set_function_data(*obj);
+ result->shared()->set_construct_stub(*construct_stub);
+ result->shared()->DontAdaptArguments();
+
+ if (obj->remove_prototype()) return result;
Igor Sheludko 2014/04/28 15:00:38 Does it make sense to put ASSERT(result->shared()-
Toon Verwaest 2014/04/29 09:41:13 Done.
+ // Down from here is only valid for API functions that can be used as a
+ // constructor (don't set the "remove prototype" flag).
- Handle<Map> map = Handle<Map>(result->initial_map());
+ Handle<Map> map(result->initial_map());
// Mark as undetectable if needed.
if (obj->undetectable()) {
@@ -2120,10 +2151,6 @@ Handle<JSFunction> Factory::CreateApiFunction(
map->set_has_instance_call_handler();
}
- result->shared()->set_function_data(*obj);
- result->shared()->set_construct_stub(*construct_stub);
- result->shared()->DontAdaptArguments();
-
// Recursively copy parent instance templates' accessors,
// 'data' may be modified.
int max_number_of_additional_properties = 0;
« no previous file with comments | « src/factory.h ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698