Revision: 5137
Author: [email protected]
Date: Tue Jul 27 02:20:21 2010
Log: Fix some bugs in Function.prototype.bind implementation.
Correctly handle not passing thisArg.
Fixes to NewObjectFromBound to use correct argument count, not leak memory,
and handle constructors that throw exceptions.

Review URL: http://codereview.chromium.org/2878057
http://code.google.com/p/v8/source/detail?r=5137

Modified:
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/src/v8natives.js

=======================================
--- /branches/bleeding_edge/src/runtime.cc      Fri Jul 23 10:21:55 2010
+++ /branches/bleeding_edge/src/runtime.cc      Tue Jul 27 02:20:21 2010
@@ -6757,17 +6757,23 @@
   CONVERT_ARG_CHECKED(JSFunction, function, 0);
   CONVERT_ARG_CHECKED(JSArray, params, 1);

+  RUNTIME_ASSERT(params->HasFastElements());
   FixedArray* fixed = FixedArray::cast(params->elements());

-  bool exception = false;
-  Object*** param_data = NewArray<Object**>(fixed->length());
-  for (int i = 0; i < fixed->length();  i++) {
+  int fixed_length = Smi::cast(params->length())->value();
+  SmartPointer<Object**> param_data(NewArray<Object**>(fixed_length));
+  for (int i = 0; i < fixed_length; i++) {
     Handle<Object> val = Handle<Object>(fixed->get(i));
     param_data[i] = val.location();
   }

+  bool exception = false;
   Handle<Object> result = Execution::New(
-      function, fixed->length(), param_data, &exception);
+      function, fixed_length, *param_data, &exception);
+  if (exception) {
+      return Failure::Exception();
+  }
+  ASSERT(!result.is_null());
   return *result;
 }

=======================================
--- /branches/bleeding_edge/src/v8natives.js    Mon Jul 26 23:18:32 2010
+++ /branches/bleeding_edge/src/v8natives.js    Tue Jul 27 02:20:21 2010
@@ -1105,7 +1105,7 @@
       throw new $TypeError('Bind must be called on a function');
   }
   // this_arg is not an argument that should be bound.
-  var argc_bound = %_ArgumentsLength() - 1;
+  var argc_bound = (%_ArgumentsLength() || 1) - 1;
   if (argc_bound > 0) {
     var bound_args = new $Array(argc_bound);
     for(var i = 0; i < argc_bound; i++) {

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to