Revision: 9267
Author: [email protected]
Date: Tue Sep 13 10:14:39 2011
Log: Fix for .bind regression.
[email protected]
BUG=
TEST=
Review URL: http://codereview.chromium.org/7892013
http://code.google.com/p/v8/source/detail?r=9267
Added:
/branches/bleeding_edge/test/mjsunit/regress/regress-bind-receiver.js
Modified:
/branches/bleeding_edge/src/execution.cc
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/regress/regress-bind-receiver.js
Tue Sep 13 10:14:39 2011
@@ -0,0 +1,17 @@
+function strict() { 'use strict'; return this; }
+function lenient() { return this; }
+var obj = {};
+
+assertEquals(true, strict.bind(true)());
+assertEquals(42, strict.bind(42)());
+assertEquals("", strict.bind("")());
+assertEquals(null, strict.bind(null)()l);
+assertEquals(undefined, strict.bind(undefined)());
+assertEquals(obj, strict.bind(obj)());
+
+assertEquals(true, lenient.bind(true)() instanceof Boolean);
+assertEquals(true, lenient.bind(42)() instanceof Number);
+assertEquals(true, lenient.bind("")() instanceof String);
+assertEquals(this, lenient.bind(null)());
+assertEquals(this, lenient.bind(undefined)());
+assertEquals(obj, lenient.bind(obj)());
=======================================
--- /branches/bleeding_edge/src/execution.cc Tue Sep 13 04:42:57 2011
+++ /branches/bleeding_edge/src/execution.cc Tue Sep 13 10:14:39 2011
@@ -161,10 +161,11 @@
if (convert_receiver && !receiver->IsJSReceiver() &&
!func->shared()->native() && !func->shared()->strict_mode()) {
if (receiver->IsUndefined() || receiver->IsNull()) {
- // Careful, func->context()->global()->global_receiver() gives
- // the JSBuiltinsObject if func is a builtin. Not what we want here.
- receiver =
- Handle<Object>(func->GetIsolate()->global()->global_receiver());
+ Object* global = func->context()->global()->global_receiver();
+ // For reasons that escape me, 'global' can be the JSBuiltinsObject
+ // under some circumstances. In that case, don't rewrite.
+ // FWIW, the same holds for
GetIsolate()->global()->global_receiver().
+ if (!global->IsJSBuiltinsObject()) receiver = Handle<Object>(global);
} else {
receiver = ToObject(receiver, pending_exception);
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev