[PATCH v2 1/5] jscript: Implement Object.prototype.isPrototypeOf method.

Gabriel Ivăncescu gabrielopcode at gmail.com
Tue Nov 2 13:07:10 CDT 2021


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

diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c
index 169b47c..fd5ab52 100644
--- a/dlls/jscript/object.c
+++ b/dlls/jscript/object.c
@@ -196,8 +196,24 @@ 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])))) {
+        while(jsdisp->prototype) {
+            if(jsdisp->prototype == jsthis->u.jsdisp) {
+                ret = TRUE;
+                break;
+            }
+            jsdisp = jsdisp->prototype;
+        }
+    }
+
+    *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..63aa669 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -1679,14 +1679,28 @@ 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(instanceOfTest.isPrototypeOf(tmp) === false, "instanceOfTest is prototype of tmp");
+ok(instanceOfTest.prototype.isPrototypeOf(tmp) === true, "instanceOfTest.prototype is not prototype of tmp");
+ok(Object.prototype.isPrototypeOf(tmp) === true, "Object.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(instanceOfTest.prototype.isPrototypeOf(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(Number.prototype.isPrototypeOf(1) === false, "Number.prototype is prototype of 1");
+ok(String.prototype.isPrototypeOf("") === false, "String.prototype is prototype of ''");
+
+ok(tmp.isPrototypeOf(null) === false, "tmp is prototype of null");
+ok(tmp.isPrototypeOf(undefined) === false, "tmp is prototype of undefined");
+ok(Object.prototype.isPrototypeOf.call(tmp) === false, "tmp is prototype of no argument");
+ok(Object.prototype.isPrototypeOf.call(test, Object) === false, "test is prototype of Object");
+ok(Object.prototype.isPrototypeOf.call(testObj, Object) === false, "testObj is prototype of Object");
+ok(Object.prototype.isPrototypeOf(test) === false, "Object.prototype is prototype of test");
+ok(Object.prototype.isPrototypeOf(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