Jacek Caban : jscript: Pass global object as this if 'this' argument is null or undefined in Function.apply.
Alexandre Julliard
julliard at winehq.org
Fri Oct 30 11:04:32 CDT 2009
Module: wine
Branch: master
Commit: 710219a53d4944a642b9cb4d2e2448d3ced96c28
URL: http://source.winehq.org/git/wine.git/?a=commit;h=710219a53d4944a642b9cb4d2e2448d3ced96c28
Author: Jacek Caban <jacek at codeweavers.com>
Date: Fri Oct 30 00:02:13 2009 +0100
jscript: Pass global object as this if 'this' argument is null or undefined in Function.apply.
---
dlls/jscript/function.c | 14 +++++++++-----
dlls/jscript/tests/api.js | 3 +++
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index 7d8e812..60f2e43 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -403,9 +403,13 @@ static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI
argc = arg_cnt(dp);
if(argc) {
- hres = to_object(ctx, get_arg(dp,0), &this_obj);
- if(FAILED(hres))
- return hres;
+ VARIANT *v = get_arg(dp,0);
+
+ if(V_VT(v) != VT_EMPTY && V_VT(v) != VT_NULL) {
+ hres = to_object(ctx, v, &this_obj);
+ if(FAILED(hres))
+ return hres;
+ }
}
if(argc >= 2) {
@@ -413,8 +417,8 @@ static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DI
if(V_VT(get_arg(dp,1)) == VT_DISPATCH) {
arg_array = iface_to_jsdisp((IUnknown*)V_DISPATCH(get_arg(dp,1)));
- if(arg_array && (
- !is_class(arg_array, JSCLASS_ARRAY) && !is_class(arg_array, JSCLASS_ARGUMENTS) )) {
+ if(arg_array &&
+ (!is_class(arg_array, JSCLASS_ARRAY) && !is_class(arg_array, JSCLASS_ARGUMENTS) )) {
jsdisp_release(arg_array);
arg_array = NULL;
}
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 9a9481e..d9d8ee8 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -1402,6 +1402,9 @@ function callTest3() {
callTest3.call();
callTest3.call(undefined);
callTest3.call(null);
+callTest3.apply();
+callTest3.apply(undefined);
+callTest3.apply(null);
tmp = Number.prototype.toString.call(3);
ok(tmp === "3", "Number.prototype.toString.call(3) = " + tmp);
More information about the wine-cvs
mailing list