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

Unified Diff: src/bootstrapper.cc

Issue 2850: Generalize the Function.prototype.call hooks in the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 3 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 | « no previous file | src/builtins.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
===================================================================
--- src/bootstrapper.cc (revision 310)
+++ src/bootstrapper.cc (working copy)
@@ -956,33 +956,37 @@
InstallNativeFunctions();
- // TODO(1240778): Get rid of the JS implementation of
- // Function.prototype.call and simply create a function with the
- // faked formal parameter count (-1) and use the illegal builtin as
- // the code for it.
-
- // Find Function.prototype.call and set it's number of formal
- // parameters to -1 to let the arguments adaptor handle it
- // specially.
- { Handle<JSFunction> function =
- Handle<JSFunction>::cast(GetProperty(Top::global(),
- Factory::function_class_symbol()));
+ // Install Function.prototype.call and apply.
+ { Handle<String> key = Factory::function_class_symbol();
+ Handle<JSFunction> function =
+ Handle<JSFunction>::cast(GetProperty(Top::global(), key));
Handle<JSObject> proto =
Handle<JSObject>(JSObject::cast(function->instance_prototype()));
+
+ // Install the call and the apply functions.
Handle<JSFunction> call =
- Handle<JSFunction>::cast(GetProperty(proto, Factory::call_symbol()));
- call->shared()->set_formal_parameter_count(-1);
+ InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize,
+ Factory::NewJSObject(Top::object_function(), TENURED),
+ Builtins::FunctionCall,
+ false);
+ Handle<JSFunction> apply =
+ InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize,
+ Factory::NewJSObject(Top::object_function(), TENURED),
+ Builtins::FunctionApply,
+ false);
// Make sure that Function.prototype.call appears to be compiled.
// The code will never be called, but inline caching for call will
// only work if it appears to be compiled.
- call->shared()->set_code(Builtins::builtin(Builtins::Illegal));
+ call->shared()->DontAdaptArguments();
ASSERT(call->is_compiled());
- // Use the specialized builtin for Function.prototype.apply.
- Handle<JSFunction> apply =
- Handle<JSFunction>::cast(GetProperty(proto, Factory::apply_symbol()));
- apply->shared()->set_code(Builtins::builtin(Builtins::FunctionApply));
+ // Set the expected paramters for apply to 2; required by builtin.
+ apply->shared()->set_formal_parameter_count(2);
+
+ // Set the lengths for the functions to satisfy ECMA-262.
+ call->shared()->set_length(1);
+ apply->shared()->set_length(2);
}
// Make sure that the builtins object has fast properties.
« no previous file with comments | « no previous file | src/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698