Jacek Caban : mshtml: Add Function.prototype.bind tests.

Alexandre Julliard julliard at winehq.org
Wed Aug 14 20:17:23 CDT 2019


Module: wine
Branch: master
Commit: eb166fe3493b8fe63a768d45780a7501527db9e1
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=eb166fe3493b8fe63a768d45780a7501527db9e1

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Aug 14 13:19:03 2019 +0200

mshtml: Add Function.prototype.bind tests.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/tests/es5.js | 80 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 79 insertions(+), 1 deletion(-)

diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index 69c0d86..85a6899 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -724,6 +724,83 @@ function test_getPrototypeOf() {
     next_test();
 }
 
+function test_bind() {
+    var f, r;
+    var o = new Object(), o2 = new Object();
+
+    f = (function() {
+        ok(this === o, "this != o");
+        ok(arguments.length === 0, "arguments.length = " + arguments.length);
+        return 1;
+    }).bind(o);
+    ok(f.length === 0, "f.length = " + f.length);
+    r = f.call(o2);
+    ok(r === 1, "r = " + r);
+
+    f = (function() {
+        ok(this === o, "this != o");
+        ok(arguments.length === 1, "arguments.length = " + arguments.length);
+        ok(arguments[0] === 1, "arguments[0] = " + arguments[0]);
+        return 1;
+    }).bind(o, 1);
+    ok(f.length === 0, "f.length = " + f.length);
+    r = f.call(o2);
+    ok(r === 1, "r = " + r);
+
+    f = (function() {
+        ok(this === o, "this != o");
+        ok(arguments.length === 2, "arguments.length = " + arguments.length);
+        ok(arguments[0] === 1, "arguments[0] = " + arguments[0]);
+        ok(arguments[1] === 2, "arguments[1] = " + arguments[0]);
+        return 1;
+    }).bind(o, 1);
+    r = f.call(o2, 2);
+    ok(r === 1, "r = " + r);
+
+    o2.f = f;
+    r = o2.f(2);
+    ok(r === 1, "r = " + r);
+
+    f = (function test(x, y, z) {
+        ok(this === o, "this != o");
+        ok(arguments.length === 2, "arguments.length = " + arguments.length);
+        ok(x === 1, "x = " + x);
+        ok(y === 2, "y = " + y);
+        ok(z === undefined, "z = " + z);
+        return 1;
+    }).bind(o, 1);
+    ok(f.length === 2, "f.length = " + f.length);
+    r = f.call(o2, 2);
+    ok(r === 1, "r = " + r);
+    ok(f.toString() === "\nfunction() {\n    [native code]\n}\n", "f.toString() = " + f.toString());
+    ok(!("prototype" in f), "bound function has prototype");
+
+    var a = [];
+    f = Array.prototype.push.bind(a, 1);
+    f();
+    ok(a.length === 1, "a.length = " + a.length);
+    f(2);
+    ok(a.length === 3, "a.length = " + a.length);
+    ok(f.length === 0, "f.length = " + f.length);
+    ok(f.toString() === "\nfunction() {\n    [native code]\n}\n", "f.toString() = " + f.toString());
+    ok(a.toString() === "1,1,2", "a = " + a);
+    f.call([], 3);
+    ok(a.toString() === "1,1,2,1,3", "a = " + a);
+
+    f = (function() { return this; }).bind(a);
+    ok(f() === a, "f() != a");
+
+    var t;
+    f = (function() { return t = this; }).bind(a);
+    ok(new f() === t, "new f() != a");
+    ok(typeof(t) === "object", "typeof(t) = " + typeof(t));
+    ok(t != a, "t == a");
+
+    ok(Function.prototype.bind.length === 1, "Function.prototype.bind.length = " + Function.prototype.bind.length);
+
+    next_test();
+}
+
 var tests = [
     test_date_now,
     test_toISOString,
@@ -738,5 +815,6 @@ var tests = [
     test_string_trim,
     test_global_properties,
     test_string_split,
-    test_getPrototypeOf
+    test_getPrototypeOf,
+    test_bind
 ];




More information about the wine-cvs mailing list