Module: wine Branch: master Commit: 1b1d09724a94b1d5a6d266f259c20cbfaa4b3888 URL: https://gitlab.winehq.org/wine/wine/-/commit/1b1d09724a94b1d5a6d266f259c20cb...
Author: Gabriel Ivăncescu gabrielopcode@gmail.com Date: Mon Jul 31 18:50:59 2023 +0300
jscript: Call the getter with the proper 'this' in invoke_prop_func.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com
---
dlls/jscript/dispex.c | 18 +++++++++--------- dlls/mshtml/tests/es5.js | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c index 2da2270fb0f..0dd575434c1 100644 --- a/dlls/jscript/dispex.c +++ b/dlls/jscript/dispex.c @@ -442,7 +442,7 @@ static HRESULT convert_params(script_ctx_t *ctx, const DISPPARAMS *dp, jsval_t * return S_OK; }
-static HRESULT prop_get(jsdisp_t *This, dispex_prop_t *prop, jsval_t *r) +static HRESULT prop_get(jsdisp_t *This, IDispatch *jsthis, dispex_prop_t *prop, jsval_t *r) { jsdisp_t *prop_obj = This; HRESULT hres; @@ -461,7 +461,7 @@ static HRESULT prop_get(jsdisp_t *This, dispex_prop_t *prop, jsval_t *r) break; case PROP_ACCESSOR: if(prop->u.accessor.getter) { - hres = jsdisp_call_value(prop->u.accessor.getter, jsval_obj(This), + hres = jsdisp_call_value(prop->u.accessor.getter, jsval_disp(jsthis), DISPATCH_METHOD, 0, NULL, r); }else { *r = jsval_undefined(); @@ -579,7 +579,7 @@ static HRESULT invoke_prop_func(jsdisp_t *This, IDispatch *jsthis, dispex_prop_t case PROP_IDX: { jsval_t val;
- hres = prop_get(This, prop, &val); + hres = prop_get(This, jsthis ? jsthis : (IDispatch *)&This->IDispatchEx_iface, prop, &val); if(FAILED(hres)) return hres;
@@ -1973,7 +1973,7 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc jsval_t r;
if(prop) - hres = prop_get(This, prop, &r); + hres = prop_get(This, to_disp(This), prop, &r); else { hres = to_primitive(This->ctx, jsval_obj(This), &r, NO_HINT); if(hres == JS_E_TO_PRIMITIVE) @@ -2305,7 +2305,7 @@ HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const built if(SUCCEEDED(hres) && prop && prop->type!=PROP_DELETED) { jsval_t val;
- hres = prop_get(constr, prop, &val); + hres = prop_get(constr, to_disp(constr), prop, &val); if(FAILED(hres)) { ERR("Could not get prototype\n"); return hres; @@ -2754,7 +2754,7 @@ HRESULT jsdisp_propget_name(jsdisp_t *obj, const WCHAR *name, jsval_t *val) return S_OK; }
- return prop_get(obj, prop, val); + return prop_get(obj, to_disp(obj), prop, val); }
HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, jsval_t *r) @@ -2774,7 +2774,7 @@ HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, jsval_t *r) return DISP_E_UNKNOWNNAME; }
- return prop_get(obj, prop, r); + return prop_get(obj, to_disp(obj), prop, r); }
HRESULT jsdisp_propget(jsdisp_t *jsdisp, DISPID id, jsval_t *val) @@ -2785,7 +2785,7 @@ HRESULT jsdisp_propget(jsdisp_t *jsdisp, DISPID id, jsval_t *val) if(!prop) return DISP_E_MEMBERNOTFOUND;
- return prop_get(jsdisp, prop, val); + return prop_get(jsdisp, to_disp(jsdisp), prop, val); }
HRESULT disp_propget(script_ctx_t *ctx, IDispatch *disp, DISPID id, jsval_t *val) @@ -2981,7 +2981,7 @@ HRESULT jsdisp_get_own_property(jsdisp_t *obj, const WCHAR *name, BOOL flags_onl desc->mask |= PROPF_WRITABLE; desc->explicit_value = TRUE; if(!flags_only) { - hres = prop_get(obj, prop, &desc->value); + hres = prop_get(obj, to_disp(obj), prop, &desc->value); if(FAILED(hres)) return hres; } diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js index e86ab1dbe77..cef3c77c207 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -794,6 +794,7 @@ sync_test("defineProperty", function() { /* call prop with getter */ desc = { get: function() { + ok(this === obj, "this != obj"); return function(x) { ok(x === 100, "x = " + x); return 10; @@ -804,6 +805,10 @@ sync_test("defineProperty", function() { test_accessor_prop_desc(obj, "funcprop", desc); ok(obj.funcprop(100) === 10, "obj.funcprop() = " + obj.funcprop(100));
+ Object.defineProperty(child.prototype, "funcprop_prot", desc); + test_accessor_prop_desc(child.prototype, "funcprop_prot", desc); + ok(obj.funcprop_prot(100) === 10, "obj.funcprop_prot() = " + obj.funcprop_prot(100)); + expect_exception(function() { Object.defineProperty(null, "funcprop", desc); }, JS_E_OBJECT_EXPECTED);