Jacek Caban : jscript: Add Object.defineProperties implementation.
Alexandre Julliard
julliard at winehq.org
Wed Aug 21 14:39:33 CDT 2019
Module: wine
Branch: master
Commit: 34d4a9c75188093675b97bc142f2ff6e6489a268
URL: https://source.winehq.org/git/wine.git/?a=commit;h=34d4a9c75188093675b97bc142f2ff6e6489a268
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Aug 21 12:31:18 2019 +0200
jscript: Add Object.defineProperties implementation.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/jscript/object.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 65 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c
index 619356b..7794f1d 100644
--- a/dlls/jscript/object.c
+++ b/dlls/jscript/object.c
@@ -409,6 +409,57 @@ static HRESULT to_property_descriptor(script_ctx_t *ctx, jsdisp_t *attr_obj, pro
return hres;
}
+static HRESULT jsdisp_define_properties(script_ctx_t *ctx, jsdisp_t *obj, jsval_t list_val)
+{
+ DISPID id = DISPID_STARTENUM;
+ property_desc_t prop_desc;
+ IDispatch *list_disp;
+ jsdisp_t *list_obj, *desc_obj;
+ jsval_t desc_val;
+ BSTR name;
+ HRESULT hres;
+
+ hres = to_object(ctx, list_val, &list_disp);
+ if(FAILED(hres))
+ return hres;
+
+ if(!(list_obj = to_jsdisp(list_disp))) {
+ FIXME("non-JS list obj\n");
+ IDispatch_Release(list_disp);
+ return E_NOTIMPL;
+ }
+
+ while(1) {
+ hres = jsdisp_next_prop(list_obj, id, TRUE, &id);
+ if(hres != S_OK)
+ break;
+
+ hres = jsdisp_propget(list_obj, id, &desc_val);
+ if(FAILED(hres))
+ break;
+
+ if(!is_object_instance(desc_val) || !get_object(desc_val) || !(desc_obj = to_jsdisp(get_object(desc_val)))) {
+ jsval_release(desc_val);
+ break;
+ }
+
+ hres = to_property_descriptor(ctx, desc_obj, &prop_desc);
+ jsdisp_release(desc_obj);
+ if(FAILED(hres))
+ break;
+
+ hres = IDispatchEx_GetMemberName(&list_obj->IDispatchEx_iface, id, &name);
+ if(SUCCEEDED(hres))
+ hres = jsdisp_define_property(obj, name, &prop_desc);
+ release_property_descriptor(&prop_desc);
+ if(FAILED(hres))
+ break;
+ }
+
+ jsdisp_release(list_obj);
+ return FAILED(hres) ? hres : S_OK;
+}
+
static HRESULT Object_defineProperty(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, jsval_t *argv, jsval_t *r)
{
@@ -455,8 +506,20 @@ static HRESULT Object_defineProperty(script_ctx_t *ctx, vdisp_t *jsthis, WORD fl
static HRESULT Object_defineProperties(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
unsigned argc, jsval_t *argv, jsval_t *r)
{
- FIXME("\n");
- return E_NOTIMPL;
+ jsdisp_t *obj;
+ HRESULT hres;
+
+ if(argc < 1 || !is_object_instance(argv[0]) || !get_object(argv[0]) || !(obj = to_jsdisp(get_object(argv[0])))) {
+ FIXME("not an object\n");
+ return E_NOTIMPL;
+ }
+
+ TRACE("%p\n", obj);
+
+ hres = jsdisp_define_properties(ctx, obj, argc >= 2 ? argv[1] : jsval_undefined());
+ if(SUCCEEDED(hres) && r)
+ *r = jsval_obj(jsdisp_addref(obj));
+ return hres;
}
static HRESULT Object_getOwnPropertyDescriptor(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
More information about the wine-cvs
mailing list