@@ -66,4 +66,51 @@ public void functionHasNameOfVarInsideFunction() {
6666
6767 Utils .assertWithAllModes_ES6 ("undefinedhi" , script );
6868 }
69+
70+ @ Test
71+ public void applyThisFromBoundArgs () throws Exception {
72+ String script =
73+ "var f = function(x) { return this.toString(); };\n "
74+ + "var a = f.apply;\n "
75+ + "var b = a.bind(f, 'Hello!');\n "
76+ + "b([1,2]);" ;
77+
78+ Utils .assertWithAllModes_ES6 ("Hello!" , script );
79+ }
80+
81+ @ Test
82+ public void applyToApplyCallsCorrectFunction () throws Exception {
83+ String script =
84+ "function foo(x) {return x;};\n "
85+ + "Function.prototype.apply.apply(foo, ['b', ['Hello!', 'Goodbye!']]);\n " ;
86+
87+ Utils .assertWithAllModes_ES6 ("Hello!" , script );
88+ }
89+
90+ @ Test
91+ public void applyToApplySetsCorrectFunctionThis () throws Exception {
92+ String script =
93+ "function foo(x) {return this.toString();};\n "
94+ + "Function.prototype.apply.apply(foo, ['b', ['Hello!', 'Goodbye!']]);\n " ;
95+
96+ Utils .assertWithAllModes_ES6 ("b" , script );
97+ }
98+
99+ @ Test
100+ public void applyToCallCallsCorrectFunction () throws Exception {
101+ String script =
102+ "function foo(x) {return x;};\n "
103+ + "foo.call.apply(foo, ['b', 'Hello!']);\n " ;
104+
105+ Utils .assertWithAllModes_ES6 ("Hello!" , script );
106+ }
107+
108+ @ Test
109+ public void applyToCallSetsCorrectFunctionThis () throws Exception {
110+ String script =
111+ "function foo(x) {return this.toString();};\n "
112+ + "foo.call.apply(foo, ['b', 'Hello!']);\n " ;
113+
114+ Utils .assertWithAllModes_ES6 ("b" , script );
115+ }
69116}
0 commit comments