Jacek Caban : jscript: Add Object.getPrototypeOf implementation.

Alexandre Julliard julliard at winehq.org
Mon Mar 11 16:29:53 CDT 2019


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Mar 11 14:39:27 2019 +0100

jscript: Add Object.getPrototypeOf implementation.

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

---

 dlls/jscript/object.c             | 30 +++++++++++++++++++++++++++++-
 dlls/mshtml/tests/documentmode.js |  2 ++
 dlls/mshtml/tests/es5.js          | 30 +++++++++++++++++++++++++++++-
 3 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c
index 487eb5f..c4c3a6e 100644
--- a/dlls/jscript/object.c
+++ b/dlls/jscript/object.c
@@ -34,6 +34,8 @@ static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','
 
 static const WCHAR getOwnPropertyDescriptorW[] =
     {'g','e','t','O','w','n','P','r','o','p','e','r','t','y','D','e','s','c','r','i','p','t','o','r',0};
+static const WCHAR getPrototypeOfW[] =
+    {'g','e','t','P','r','o','t','o','t','y','p','e','O','f',0};
 static const WCHAR definePropertyW[] = {'d','e','f','i','n','e','P','r','o','p','e','r','t','y',0};
 
 static const WCHAR definePropertiesW[] = {'d','e','f','i','n','e','P','r','o','p','e','r','t','i','e','s',0};
@@ -519,10 +521,36 @@ static HRESULT Object_getOwnPropertyDescriptor(script_ctx_t *ctx, vdisp_t *jsthi
     return hres;
 }
 
+static HRESULT Object_getPrototypeOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
+                                     unsigned argc, jsval_t *argv, jsval_t *r)
+{
+    jsdisp_t *obj;
+
+    if(!argc || !is_object_instance(argv[0])) {
+        FIXME("invalid arguments\n");
+        return E_NOTIMPL;
+    }
+
+    TRACE("(%s)\n", debugstr_jsval(argv[1]));
+
+    obj = to_jsdisp(get_object(argv[0]));
+    if(!obj) {
+        FIXME("Non-JS object\n");
+        return E_NOTIMPL;
+    }
+
+    if(r)
+        *r = obj->prototype
+            ? jsval_obj(jsdisp_addref(obj->prototype))
+            : jsval_null();
+    return S_OK;
+}
+
 static const builtin_prop_t ObjectConstr_props[] = {
     {definePropertiesW,         Object_defineProperties,            PROPF_ES5|PROPF_METHOD|2},
     {definePropertyW,           Object_defineProperty,              PROPF_ES5|PROPF_METHOD|2},
-    {getOwnPropertyDescriptorW, Object_getOwnPropertyDescriptor,    PROPF_ES5|PROPF_METHOD|2}
+    {getOwnPropertyDescriptorW, Object_getOwnPropertyDescriptor,    PROPF_ES5|PROPF_METHOD|2},
+    {getPrototypeOfW,           Object_getPrototypeOf,              PROPF_ES5|PROPF_METHOD|1}
 };
 
 static const builtin_info_t ObjectConstr_info = {
diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js
index 58c7a4c..1e8fabd 100644
--- a/dlls/mshtml/tests/documentmode.js
+++ b/dlls/mshtml/tests/documentmode.js
@@ -198,6 +198,8 @@ function test_javascript() {
         test_exposed("defineProperties", Object, v >= 8);
     }
 
+    test_exposed("getPrototypeOf", Object, v >= 9);
+
     test_parses("if(false) { o.default; }", v >= 9);
     test_parses("if(false) { o.with; }", v >= 9);
     test_parses("if(false) { o.if; }", v >= 9);
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index 928c558..69fe0fe 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -592,6 +592,33 @@ function test_string_split() {
     next_test();
 }
 
+function test_getPrototypeOf() {
+    ok(Object.getPrototypeOf(new Object()) === Object.prototype,
+       "Object.getPrototypeOf(new Object()) !== Object.prototype");
+
+    function Constr() {}
+    var obj = new Constr();
+    ok(Object.getPrototypeOf(Constr.prototype) === Object.prototype,
+       "Object.getPrototypeOf(Constr.prototype) !== Object.prototype");
+    ok(Object.getPrototypeOf(obj) === Constr.prototype,
+       "Object.getPrototypeOf(obj) !== Constr.prototype");
+
+    var proto = new Object();
+    Constr.prototype = proto;
+    ok(Object.getPrototypeOf(obj) != proto,
+       "Object.getPrototypeOf(obj) == proto");
+    obj = new Constr();
+    ok(Object.getPrototypeOf(obj) === proto,
+       "Object.getPrototypeOf(obj) !== proto");
+    ok(Object.getPrototypeOf(obj, 2, 3, 4) === proto,
+       "Object.getPrototypeOf(obj) !== proto");
+
+    ok(Object.getPrototypeOf(Object.prototype) === null,
+       "Object.getPrototypeOf(Object.prototype) !== null");
+
+    next_test();
+}
+
 var tests = [
     test_date_now,
     test_toISOString,
@@ -604,5 +631,6 @@ var tests = [
     test_property_definitions,
     test_string_trim,
     test_global_properties,
-    test_string_split
+    test_string_split,
+    test_getPrototypeOf
 ];




More information about the wine-cvs mailing list