1 description("Tests Function.bind.");
7 result = this + " -> x:" + x + ", y:" + y;
10 G = F.bind("'a'", "'b'");
11 H = G.bind("'Cannot rebind this!'", "'c'");
14 shouldBe("result", '"[object DOMWindow] -> x:1, y:2"');
16 shouldBe("result", '"\'a\' -> x:\'b\', y:1"');
18 shouldBe("result", '"\'a\' -> x:\'b\', y:\'c\'"');
21 shouldBe("result", '"[object Object] -> x:1, y:2"');
23 shouldBe("result", '"[object Object] -> x:\'b\', y:1"');
25 shouldBe("result", '"[object Object] -> x:\'b\', y:\'c\'"');
27 // Objects f & g & h are all actually instances of F, G's HasInstance method
28 // actually is checking whether the argument is an instance of F, and H's
29 // HasInstance calls G's which calls F's!
30 shouldBeTrue('f instanceof F');
31 shouldBeTrue('f instanceof G');
32 shouldBeTrue('f instanceof H');
33 shouldBeTrue('g instanceof F');
34 shouldBeTrue('g instanceof G');
35 shouldBeTrue('g instanceof H');
36 shouldBeTrue('h instanceof F');
37 shouldBeTrue('h instanceof G');
38 shouldBeTrue('h instanceof H');
40 // Bound functions don't have a 'prototype' property.
41 shouldBeTrue('"prototype" in F');
42 shouldBeFalse('"prototype" in G');
43 shouldBeFalse('"prototype" in H');
45 // The object passed to bind as 'this' must be callable.
46 shouldThrow('Function.bind.call(undefined)');
47 // Objects that allow call but not construct can be bound, but should throw if used with new.
48 var abcAt = String.prototype.charAt.bind("abc");
49 shouldBe('abcAt(1)', '"b"');
50 shouldThrow('new abcAt(1)');
52 // This exposes a bug in our implementation of instanceof. The prototype property should not
53 // be accessed until after we have established the default HasInstance is being executed.
54 // https://bugs.webkit.org/show_bug.cgi?id=68656
55 var boundFunctionPrototypeAccessed = false;
57 Object.defineProperty(P, 'prototype', { get:function(){ boundFunctionPrototypeAccessed = true; } });
59 shouldBeFalse('boundFunctionPrototypeAccessed');
61 shouldBe('Function.bind.length', '1');