[PATCH 2/7] jscript: Implement Object.prototype.isPrototypeOf method.

Gabriel Ivăncescu gabrielopcode at gmail.com
Mon Oct 25 08:30:26 CDT 2021


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/jscript/object.c      | 13 +++++++++++--
 dlls/jscript/tests/lang.js | 13 +++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c
index 169b47c..8da0ff4 100644
--- a/dlls/jscript/object.c
+++ b/dlls/jscript/object.c
@@ -196,8 +196,17 @@ static HRESULT Object_propertyIsEnumerable(script_ctx_t *ctx, vdisp_t *jsthis, W
 static HRESULT Object_isPrototypeOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
         jsval_t *r)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    jsdisp_t *jsdisp;
+    BOOL ret = FALSE;
+
+    if(!r)
+        return S_OK;
+
+    if(argc && is_jsdisp(jsthis) && is_object_instance(argv[0]) && (jsdisp = to_jsdisp(get_object(argv[0]))))
+        ret = (jsdisp->prototype == jsthis->u.jsdisp);
+
+    *r = jsval_bool(ret);
+    return S_OK;
 }
 
 static HRESULT Object_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index ad1217d..bcfe88b 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -1679,14 +1679,27 @@ tmp = new instanceOfTest();
 ok((tmp instanceof instanceOfTest) === true, "tmp is not instance of instanceOfTest");
 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
 ok((tmp instanceof String) === false, "tmp is instance of String");
+ok(Object.prototype.isPrototypeOf.call(instanceOfTest, tmp) === false, "instanceOfTest is prototype of tmp");
+ok(Object.prototype.isPrototypeOf.call(instanceOfTest.prototype, tmp) === true, "instanceOfTest.prototype is not prototype of tmp");
 
 instanceOfTest.prototype = new Object();
 ok((tmp instanceof instanceOfTest) === false, "tmp is instance of instanceOfTest");
 ok((tmp instanceof Object) === true, "tmp is not instance of Object");
+ok(Object.prototype.isPrototypeOf.call(instanceOfTest.prototype, tmp) === false, "instanceOfTest.prototype is prototype of tmp");
 
 ok((1 instanceof Object) === false, "1 is instance of Object");
 ok((false instanceof Boolean) === false, "false is instance of Boolean");
 ok(("" instanceof Object) === false, "'' is instance of Object");
+ok(Object.prototype.isPrototypeOf.call(Number.prototype, 1) === false, "Number.prototype is prototype of 1");
+ok(Object.prototype.isPrototypeOf.call(String.prototype, "") === false, "String.prototype is prototype of ''");
+
+ok(Object.prototype.isPrototypeOf.call(tmp) === false, "tmp is prototype of no argument");
+ok(Object.prototype.isPrototypeOf.call(tmp, null) === false, "tmp is prototype of null");
+ok(Object.prototype.isPrototypeOf.call(tmp, undefined) === false, "tmp is prototype of undefined");
+ok(Object.prototype.isPrototypeOf.call(test, Object) === false, "test is prototype of Object");
+ok(Object.prototype.isPrototypeOf.call(Object.prototype, test) === false, "Object.prototype is prototype of test");
+ok(Object.prototype.isPrototypeOf.call(testObj, Object) === false, "testObj is prototype of Object");
+ok(Object.prototype.isPrototypeOf.call(Object.prototype, testObj) === false, "Object.prototype is prototype of testObj");
 
 (function () {
     ok((arguments instanceof Object) === true, "argument is not instance of Object");
-- 
2.31.1




More information about the wine-devel mailing list