Commit c464c1bd authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

jscript: Handle NULL return pointers in all constructors.

Instead of crashing. Signed-off-by: 's avatarGabriel Ivăncescu <gabrielopcode@gmail.com> Signed-off-by: 's avatarJacek Caban <jacek@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent dca8e256
...@@ -181,7 +181,8 @@ static HRESULT ActiveXObject_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, ...@@ -181,7 +181,8 @@ static HRESULT ActiveXObject_value(script_ctx_t *ctx, jsval_t vthis, WORD flags,
return E_NOTIMPL; return E_NOTIMPL;
} }
*r = jsval_disp(disp); if(r) *r = jsval_disp(disp);
else IDispatch_Release(disp);
return S_OK; return S_OK;
} }
......
...@@ -1374,6 +1374,8 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, u ...@@ -1374,6 +1374,8 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, u
if(n < 0 || !is_int32(n)) if(n < 0 || !is_int32(n))
return JS_E_INVALID_LENGTH; return JS_E_INVALID_LENGTH;
if(!r)
return S_OK;
hres = create_array(ctx, n, &obj); hres = create_array(ctx, n, &obj);
if(FAILED(hres)) if(FAILED(hres))
...@@ -1383,6 +1385,8 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, u ...@@ -1383,6 +1385,8 @@ static HRESULT ArrayConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, u
return S_OK; return S_OK;
} }
if(!r)
return S_OK;
hres = create_array(ctx, argc, &obj); hres = create_array(ctx, argc, &obj);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
......
...@@ -151,6 +151,9 @@ static HRESULT BoolConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, un ...@@ -151,6 +151,9 @@ static HRESULT BoolConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, un
case DISPATCH_CONSTRUCT: { case DISPATCH_CONSTRUCT: {
jsdisp_t *bool; jsdisp_t *bool;
if(!r)
return S_OK;
hres = create_bool(ctx, value, &bool); hres = create_bool(ctx, value, &bool);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
......
...@@ -2248,7 +2248,8 @@ static HRESULT DateConstr_parse(script_ctx_t *ctx, jsval_t vthis, WORD flags, un ...@@ -2248,7 +2248,8 @@ static HRESULT DateConstr_parse(script_ctx_t *ctx, jsval_t vthis, WORD flags, un
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
*r = jsval_number(n); if(r)
*r = jsval_number(n);
return S_OK; return S_OK;
} }
...@@ -2403,7 +2404,8 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, un ...@@ -2403,7 +2404,8 @@ static HRESULT DateConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, un
} }
} }
*r = jsval_obj(&date->dispex); if(r) *r = jsval_obj(&date->dispex);
else jsdisp_release(&date->dispex);
return S_OK; return S_OK;
case INVOKE_FUNC: { case INVOKE_FUNC: {
......
...@@ -300,7 +300,8 @@ static HRESULT EnumeratorConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD fla ...@@ -300,7 +300,8 @@ static HRESULT EnumeratorConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD fla
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
*r = jsval_obj(obj); if(r) *r = jsval_obj(obj);
else jsdisp_release(obj);
break; break;
} }
default: default:
......
...@@ -1008,7 +1008,8 @@ static HRESULT FunctionConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags ...@@ -1008,7 +1008,8 @@ static HRESULT FunctionConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
*r = jsval_disp(ret); if(r) *r = jsval_disp(ret);
else IDispatch_Release(ret);
break; break;
} }
default: default:
......
...@@ -554,11 +554,12 @@ static HRESULT NumberConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, ...@@ -554,11 +554,12 @@ static HRESULT NumberConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags,
n = 0; n = 0;
} }
hres = create_number(ctx, n, &obj); if(r) {
if(FAILED(hres)) hres = create_number(ctx, n, &obj);
return hres; if(FAILED(hres))
return hres;
*r = jsval_obj(obj); *r = jsval_obj(obj);
}
break; break;
} }
default: default:
......
...@@ -114,6 +114,8 @@ static HRESULT Set_constructor(script_ctx_t *ctx, jsval_t vthis, WORD flags, uns ...@@ -114,6 +114,8 @@ static HRESULT Set_constructor(script_ctx_t *ctx, jsval_t vthis, WORD flags, uns
case DISPATCH_CONSTRUCT: case DISPATCH_CONSTRUCT:
TRACE("\n"); TRACE("\n");
if(!r)
return S_OK;
if(!(set = heap_alloc_zero(sizeof(*set)))) if(!(set = heap_alloc_zero(sizeof(*set))))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
...@@ -461,6 +463,8 @@ static HRESULT Map_constructor(script_ctx_t *ctx, jsval_t vthis, WORD flags, uns ...@@ -461,6 +463,8 @@ static HRESULT Map_constructor(script_ctx_t *ctx, jsval_t vthis, WORD flags, uns
case DISPATCH_CONSTRUCT: case DISPATCH_CONSTRUCT:
TRACE("\n"); TRACE("\n");
if(!r)
return S_OK;
if(!(map = heap_alloc_zero(sizeof(*map)))) if(!(map = heap_alloc_zero(sizeof(*map))))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
......
...@@ -1644,7 +1644,8 @@ static HRESULT StringConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, ...@@ -1644,7 +1644,8 @@ static HRESULT StringConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags,
str = jsstr_empty(); str = jsstr_empty();
} }
*r = jsval_string(str); if(r) *r = jsval_string(str);
else jsstr_release(str);
break; break;
} }
case DISPATCH_CONSTRUCT: { case DISPATCH_CONSTRUCT: {
...@@ -1659,8 +1660,10 @@ static HRESULT StringConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, ...@@ -1659,8 +1660,10 @@ static HRESULT StringConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags,
str = jsstr_empty(); str = jsstr_empty();
} }
hres = create_string(ctx, str, &ret); if(r) {
if (SUCCEEDED(hres)) *r = jsval_obj(ret); hres = create_string(ctx, str, &ret);
if(SUCCEEDED(hres)) *r = jsval_obj(ret);
}
jsstr_release(str); jsstr_release(str);
return hres; return hres;
} }
......
...@@ -287,6 +287,8 @@ ok(Object.prototype.hasOwnProperty('toString'), "Object.prototype.hasOwnProperty ...@@ -287,6 +287,8 @@ ok(Object.prototype.hasOwnProperty('toString'), "Object.prototype.hasOwnProperty
ok(Object.prototype.hasOwnProperty('isPrototypeOf'), "Object.prototype.hasOwnProperty('isPrototypeOf') is false"); ok(Object.prototype.hasOwnProperty('isPrototypeOf'), "Object.prototype.hasOwnProperty('isPrototypeOf') is false");
ok(Function.prototype.hasOwnProperty('call'), "Function.prototype.hasOwnProperty('call') is false"); ok(Function.prototype.hasOwnProperty('call'), "Function.prototype.hasOwnProperty('call') is false");
Object();
new Object();
obj = new Object(); obj = new Object();
ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true"); ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
...@@ -296,28 +298,37 @@ ok(!Object.hasOwnProperty('isPrototypeOf'), "Object.hasOwnProperty('isPrototypeO ...@@ -296,28 +298,37 @@ ok(!Object.hasOwnProperty('isPrototypeOf'), "Object.hasOwnProperty('isPrototypeO
ok(!parseFloat.hasOwnProperty('call'), "parseFloat.hasOwnProperty('call') is true"); ok(!parseFloat.hasOwnProperty('call'), "parseFloat.hasOwnProperty('call') is true");
ok(!Function.hasOwnProperty('call'), "Function.hasOwnProperty('call') is true"); ok(!Function.hasOwnProperty('call'), "Function.hasOwnProperty('call') is true");
Array();
new Array();
obj = new Array(); obj = new Array();
ok(Array.prototype.hasOwnProperty('sort'), "Array.prototype.hasOwnProperty('sort') is false"); ok(Array.prototype.hasOwnProperty('sort'), "Array.prototype.hasOwnProperty('sort') is false");
ok(Array.prototype.hasOwnProperty('length'), "Array.prototype.hasOwnProperty('length') is false"); ok(Array.prototype.hasOwnProperty('length'), "Array.prototype.hasOwnProperty('length') is false");
ok(!obj.hasOwnProperty('sort'), "obj.hasOwnProperty('sort') is true"); ok(!obj.hasOwnProperty('sort'), "obj.hasOwnProperty('sort') is true");
ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is true"); ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is true");
Boolean();
new Boolean();
obj = new Boolean(false); obj = new Boolean(false);
ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true"); ok(!obj.hasOwnProperty('toString'), "obj.hasOwnProperty('toString') is true");
ok(!Boolean.hasOwnProperty('toString'), "Boolean.hasOwnProperty('toString') is true"); ok(!Boolean.hasOwnProperty('toString'), "Boolean.hasOwnProperty('toString') is true");
ok(Boolean.prototype.hasOwnProperty('toString'), "Boolean.prototype.hasOwnProperty('toString') is false"); ok(Boolean.prototype.hasOwnProperty('toString'), "Boolean.prototype.hasOwnProperty('toString') is false");
Date();
new Date();
obj = new Date(); obj = new Date();
ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true"); ok(!obj.hasOwnProperty('getTime'), "obj.hasOwnProperty('getTime') is true");
ok(!Date.hasOwnProperty('getTime'), "Date.hasOwnProperty('getTime') is true"); ok(!Date.hasOwnProperty('getTime'), "Date.hasOwnProperty('getTime') is true");
ok(Date.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false"); ok(Date.prototype.hasOwnProperty('getTime'), "Date.prototype.hasOwnProperty('getTime') is false");
ok(!("now" in Date), "now found in Date"); ok(!("now" in Date), "now found in Date");
Number();
new Number();
obj = new Number(); obj = new Number();
ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true"); ok(!obj.hasOwnProperty('toFixed'), "obj.hasOwnProperty('toFixed') is true");
ok(!Number.hasOwnProperty('toFixed'), "Number.hasOwnProperty('toFixed') is true"); ok(!Number.hasOwnProperty('toFixed'), "Number.hasOwnProperty('toFixed') is true");
ok(Number.prototype.hasOwnProperty('toFixed'), "Number.prototype.hasOwnProperty('toFixed') is false"); ok(Number.prototype.hasOwnProperty('toFixed'), "Number.prototype.hasOwnProperty('toFixed') is false");
/x/;
obj = /x/; obj = /x/;
ok(!obj.hasOwnProperty('exec'), "obj.hasOwnProperty('exec') is true"); ok(!obj.hasOwnProperty('exec'), "obj.hasOwnProperty('exec') is true");
ok(obj.hasOwnProperty('source'), "obj.hasOwnProperty('source') is false"); ok(obj.hasOwnProperty('source'), "obj.hasOwnProperty('source') is false");
...@@ -325,6 +336,8 @@ ok(!RegExp.hasOwnProperty('exec'), "RegExp.hasOwnProperty('exec') is true"); ...@@ -325,6 +336,8 @@ ok(!RegExp.hasOwnProperty('exec'), "RegExp.hasOwnProperty('exec') is true");
ok(!RegExp.hasOwnProperty('source'), "RegExp.hasOwnProperty('source') is true"); ok(!RegExp.hasOwnProperty('source'), "RegExp.hasOwnProperty('source') is true");
ok(RegExp.prototype.hasOwnProperty('source'), "RegExp.prototype.hasOwnProperty('source') is false"); ok(RegExp.prototype.hasOwnProperty('source'), "RegExp.prototype.hasOwnProperty('source') is false");
String();
new String();
obj = new String(); obj = new String();
ok(!obj.hasOwnProperty('charAt'), "obj.hasOwnProperty('charAt') is true"); ok(!obj.hasOwnProperty('charAt'), "obj.hasOwnProperty('charAt') is true");
ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is false"); ok(obj.hasOwnProperty('length'), "obj.hasOwnProperty('length') is false");
...@@ -3127,6 +3140,8 @@ ok(String.length == 1, "String.length = " + String.length); ...@@ -3127,6 +3140,8 @@ ok(String.length == 1, "String.length = " + String.length);
var tmp = createArray(); var tmp = createArray();
ok(getVT(tmp) == "VT_ARRAY|VT_VARIANT", "getVT(createArray()) = " + getVT(tmp)); ok(getVT(tmp) == "VT_ARRAY|VT_VARIANT", "getVT(createArray()) = " + getVT(tmp));
ok(getVT(VBArray(tmp)) == "VT_ARRAY|VT_VARIANT", "getVT(VBArray(tmp)) = " + getVT(VBArray(tmp))); ok(getVT(VBArray(tmp)) == "VT_ARRAY|VT_VARIANT", "getVT(VBArray(tmp)) = " + getVT(VBArray(tmp)));
VBArray(tmp);
new VBArray(tmp);
tmp = new VBArray(tmp); tmp = new VBArray(tmp);
tmp = new VBArray(VBArray(createArray())); tmp = new VBArray(VBArray(createArray()));
ok(tmp.dimensions() == 2, "tmp.dimensions() = " + tmp.dimensions()); ok(tmp.dimensions() == 2, "tmp.dimensions() = " + tmp.dimensions());
......
...@@ -291,11 +291,13 @@ static HRESULT VBArrayConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, ...@@ -291,11 +291,13 @@ static HRESULT VBArrayConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags,
if(argc<1 || !is_variant(argv[0]) || V_VT(get_variant(argv[0])) != (VT_ARRAY|VT_VARIANT)) if(argc<1 || !is_variant(argv[0]) || V_VT(get_variant(argv[0])) != (VT_ARRAY|VT_VARIANT))
return JS_E_VBARRAY_EXPECTED; return JS_E_VBARRAY_EXPECTED;
return jsval_copy(argv[0], r); return r ? jsval_copy(argv[0], r) : S_OK;
case DISPATCH_CONSTRUCT: case DISPATCH_CONSTRUCT:
if(argc<1 || !is_variant(argv[0]) || V_VT(get_variant(argv[0])) != (VT_ARRAY|VT_VARIANT)) if(argc<1 || !is_variant(argv[0]) || V_VT(get_variant(argv[0])) != (VT_ARRAY|VT_VARIANT))
return JS_E_VBARRAY_EXPECTED; return JS_E_VBARRAY_EXPECTED;
if(!r)
return S_OK;
hres = alloc_vbarray(ctx, NULL, &vbarray); hres = alloc_vbarray(ctx, NULL, &vbarray);
if(FAILED(hres)) if(FAILED(hres))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment