Jacek Caban : jscript: Add Object.create implementation.

Alexandre Julliard julliard at winehq.org
Mon Mar 18 16:20:13 CDT 2019


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Mar 15 16:14:44 2019 +0100

jscript: Add Object.create implementation.

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

---

 dlls/jscript/object.c    | 41 +++++++++++++++++++++++++++++++++++++++++
 dlls/mshtml/tests/es5.js | 12 ++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c
index c4c3a6e..19d67b5 100644
--- a/dlls/jscript/object.c
+++ b/dlls/jscript/object.c
@@ -32,6 +32,7 @@ static const WCHAR propertyIsEnumerableW[] =
     {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
 static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
 
+static const WCHAR createW[] = {'c','r','e','a','t','e',0};
 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[] =
@@ -521,6 +522,45 @@ static HRESULT Object_getOwnPropertyDescriptor(script_ctx_t *ctx, vdisp_t *jsthi
     return hres;
 }
 
+static HRESULT Object_create(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
+                             unsigned argc, jsval_t *argv, jsval_t *r)
+{
+    jsdisp_t *proto = NULL, *obj;
+    HRESULT hres;
+
+    if(!argc || (!is_object_instance(argv[0]) && !is_null(argv[0]))) {
+        FIXME("Invalid arg\n");
+        return E_INVALIDARG;
+    }
+
+    TRACE("(%s)\n", debugstr_jsval(argv[0]));
+
+    if(argc > 1) {
+        FIXME("Unsupported properties argument %s\n", debugstr_jsval(argv[1]));
+        return E_NOTIMPL;
+    }
+
+    if(argc && is_object_instance(argv[0])) {
+        if(get_object(argv[0]))
+            proto = to_jsdisp(get_object(argv[0]));
+        if(!proto) {
+            FIXME("Non-JS prototype\n");
+            return E_NOTIMPL;
+        }
+    }else if(!is_null(argv[0])) {
+        FIXME("Invalid arg %s\n", debugstr_jsval(argc ? argv[0] : jsval_undefined()));
+        return E_INVALIDARG;
+    }
+
+    if(r) {
+        hres = create_dispex(ctx, NULL, proto, &obj);
+        if(FAILED(hres))
+            return hres;
+        *r = jsval_obj(obj);
+    }
+    return S_OK;
+}
+
 static HRESULT Object_getPrototypeOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
                                      unsigned argc, jsval_t *argv, jsval_t *r)
 {
@@ -547,6 +587,7 @@ static HRESULT Object_getPrototypeOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD fl
 }
 
 static const builtin_prop_t ObjectConstr_props[] = {
+    {createW,                   Object_create,                      PROPF_ES5|PROPF_METHOD|2},
     {definePropertiesW,         Object_defineProperties,            PROPF_ES5|PROPF_METHOD|2},
     {definePropertyW,           Object_defineProperty,              PROPF_ES5|PROPF_METHOD|2},
     {getOwnPropertyDescriptorW, Object_getOwnPropertyDescriptor,    PROPF_ES5|PROPF_METHOD|2},
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js
index 6cfee81..0ee2eff 100644
--- a/dlls/mshtml/tests/es5.js
+++ b/dlls/mshtml/tests/es5.js
@@ -637,6 +637,9 @@ function test_string_split() {
 }
 
 function test_getPrototypeOf() {
+    ok(Object.create.length === 2, "Object.create.length = " + Object.create.length);
+    ok(Object.getPrototypeOf.length === 1, "Object.getPrototypeOf.length = " + Object.getPrototypeOf.length);
+
     ok(Object.getPrototypeOf(new Object()) === Object.prototype,
        "Object.getPrototypeOf(new Object()) !== Object.prototype");
 
@@ -660,6 +663,15 @@ function test_getPrototypeOf() {
     ok(Object.getPrototypeOf(Object.prototype) === null,
        "Object.getPrototypeOf(Object.prototype) !== null");
 
+    obj = Object.create(proto = { test: 1 });
+    ok(Object.getPrototypeOf(obj) === proto,
+       "Object.getPrototypeOf(obj) !== proto");
+    ok(obj.test === 1, "obj.test = " + obj.test);
+
+    obj = Object.create(null);
+    ok(!("toString" in obj), "toString is in obj");
+    ok(Object.getPrototypeOf(obj) === null, "Object.getPrototypeOf(obj) = " + Object.getPrototypeOf(obj));
+
     next_test();
 }
 




More information about the wine-cvs mailing list