Reviewers: Jakob,
Description:
Fix for .bind regression.
[email protected]
BUG=
TEST=
Please review this at http://codereview.chromium.org/7892013/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/execution.cc
A test/mjsunit/regress/regress-bind-receiver.js
Index: src/execution.cc
diff --git a/src/execution.cc b/src/execution.cc
index
cdea005829fb4e1fec14d4402272592cb58138d5..e956706d39d00b4da22c2567bd82c257ac1d29dd
100644
--- a/src/execution.cc
+++ b/src/execution.cc
@@ -161,10 +161,11 @@ Handle<Object> Execution::Call(Handle<Object>
callable,
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);
}
Index: test/mjsunit/regress/regress-bind-receiver.js
diff --git a/test/mjsunit/regress/regress-bind-receiver.js
b/test/mjsunit/regress/regress-bind-receiver.js
new file mode 100644
index
0000000000000000000000000000000000000000..6cbde33bd48f6a43c79a9bc7319d0d0ef6b50c13
--- /dev/null
+++ b/test/mjsunit/regress/regress-bind-receiver.js
@@ -0,0 +1,18 @@
+function strict() { 'use strict'; return this; }
+function lenient() { return this; }
+var obj = {};
+
+assertEquals(strict.bind(true)(), true);
+assertEquals(strict.bind(42)(), 42);
+assertEquals(strict.bind("")(), "");
+assertEquals(strict.bind(null)(), null);
+assertEquals(strict.bind(undefined)(), undefined);
+assertEquals(strict.bind(obj)(), obj);
+
+assertEquals(lenient.bind(true)() instanceof Boolean, true);
+assertEquals(lenient.bind(42)() instanceof Number, true);
+assertEquals(lenient.bind("")() instanceof String, true);
+assertEquals(lenient.bind(null)(), this);
+assertEquals(lenient.bind(undefined)(), this);
+assertEquals(lenient.bind(obj)(), obj);
+
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev