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

Unified Diff: src/v8natives.js

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 | « src/objects-inl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
===================================================================
--- src/v8natives.js (revision 310)
+++ src/v8natives.js (working copy)
@@ -414,107 +414,3 @@
};
%SetCode($Function, NewFunction);
-
-
-// NOTE: The following functions (call and apply) are only used in this
-// form on the ARM platform. On IA-32 they are handled through specialized
-// builtins; see builtins-ia32.cc.
-
-%AddProperty($Function.prototype, "call", function(receiver) {
- // Make sure the receiver of this call is a function. If it isn't
- // we "fake" a call of it (without the right arguments) to force
- // an exception to be thrown.
- if (!IS_FUNCTION(this)) this();
-
- // If receiver is null or undefined set the receiver to the global
- // object. If the receiver isn't an object, we convert the
- // receiver to an object.
- if (receiver == null) receiver = global;
- else if (!IS_OBJECT(receiver)) receiver = ToObject(receiver);
-
- %_SetThisFunction(this);
- %_SetThis(receiver);
-
- var len = %_GetArgumentsLength(1);
- return %_ShiftDownAndTailCall(len ? len - 1 : 0);
-}, DONT_ENUM);
-
-
-// This implementation of Function.prototype.apply replaces the stack frame
-// of the apply call with the new stack frame containing the arguments from
-// the args array.
-%AddProperty($Function.prototype, "apply", function(receiver, args) {
- var length = (args == null) ? 0 : ToUint32(args.length);
-
- // We can handle any number of apply arguments if the stack is
- // big enough, but sanity check the value to avoid overflow when
- // multiplying with pointer size.
- if (length > 0x800000) {
- throw new $RangeError(
- "Function.prototype.apply cannot support " + length + " arguments.");
- }
-
- if (!IS_FUNCTION(this)) {
- throw new $TypeError('Function.prototype.apply was called on ' + this.toString() + ', which is a ' + (typeof this) + ' and not a function');
- }
-
- // Make sure args has the right type.
- if (args != null && %ClassOf(args) !== 'Array' && %ClassOf(args) !== 'Arguments') {
- throw new $TypeError('Function.prototype.apply: args has wrong type');
- }
-
- // If receiver is null or undefined set the receiver to the global
- // object. If the receiver isn't an object, we convert the
- // receiver to an object.
- if (receiver == null) receiver = global;
- else if (!IS_OBJECT(receiver)) receiver = ToObject(receiver);
-
- %_SetThisFunction(this);
- %_SetThis(receiver);
-
- var arguments_length = %_GetArgumentsLength(2);
-
- // This method has 2 formal arguments so if less are passed, then space has
- // been made.
- if (arguments_length < 2)
- arguments_length = 2;
-
- // Move some stuff to locals so they don't get overwritten when we start
- // expanding the args array.
- var saved_args = args;
-
- if (arguments_length > length) {
- // We have too many arguments - we need to squash the frame.
- %_SquashFrame(arguments_length, length);
- } else if (arguments_length != length) {
- // We have too few spaces for arguments - we need to expand the frame.
- if (!%_ExpandFrame(arguments_length, length)) {
- throw new $RangeError(
- "Function.prototype.apply cannot find stack space for " + length + " arguments.");
- }
- // GC doesn't like junk in the arguments!
- for (var i = 0; i < length; i++) {
- %_SetArgument(i, 0, length);
- }
- }
-
- // Update-number-of-arguments field to keep things looking consistent for
- // stack traces, and uses of arguments or arguments.length.
- %_SetArgumentsLength(length);
-
- // NOTE: For the fast case this should be implemented in assembler,
- // which would allow us to omit bounds and class checks galore. The
- // assembler version could fall back to this implementation if
- // tricky stuff is found, like arrays implemented as dictionaries or
- // holes in arrays.
- for (var i = 0; i < length; i++) {
- %_SetArgument(i, saved_args[i], length);
- }
-
- // Replaces the current frame with the new call. This has the added effect
- // of removing apply from the stack trace entirely, which matches the
- // behaviour of Firefox.
- return %_TailCallWithArguments(length);
-}, DONT_ENUM);
-
-
« no previous file with comments | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698