Gabriel Ivăncescu : jscript: Implement Object.prototype.isPrototypeOf method.
Alexandre Julliard
julliard at winehq.org
Wed Nov 3 16:42:02 CDT 2021
Module: wine
Branch: master
Commit: 87ac636cbb400bf9a3fdc58d48df45ef2f46b486
URL: https://source.winehq.org/git/wine.git/?a=commit;h=87ac636cbb400bf9a3fdc58d48df45ef2f46b486
Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date: Tue Nov 2 20:07:10 2021 +0200
jscript: Implement Object.prototype.isPrototypeOf method.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
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 169b47caea4..fd5ab52a8ae 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 ad1217d6b60..63aa6696f89 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");
More information about the wine-cvs
mailing list