jscript: Pass msg as jsstr_t to create_error.

This commit is contained in:
Jacek Caban 2013-03-08 11:37:30 +01:00 committed by Alexandre Julliard
parent b8e2edf19c
commit c7c71b87b8

View File

@ -180,10 +180,9 @@ static HRESULT alloc_error(script_ctx_t *ctx, jsdisp_t *prototype,
}
static HRESULT create_error(script_ctx_t *ctx, jsdisp_t *constr,
UINT number, const WCHAR *msg, jsdisp_t **ret)
UINT number, jsstr_t *msg, jsdisp_t **ret)
{
jsdisp_t *err;
jsstr_t *str;
HRESULT hres;
hres = alloc_error(ctx, NULL, constr, &err);
@ -196,16 +195,9 @@ static HRESULT create_error(script_ctx_t *ctx, jsdisp_t *constr,
return hres;
}
if(msg) str = jsstr_alloc(msg);
else str = jsstr_empty();
if(str) {
hres = jsdisp_propput_name(err, messageW, jsval_string(str));
if(SUCCEEDED(hres))
hres = jsdisp_propput_dontenum(err, descriptionW, jsval_string(str));
jsstr_release(str);
}else {
hres = E_OUTOFMEMORY;
}
hres = jsdisp_propput_name(err, messageW, jsval_string(msg));
if(SUCCEEDED(hres))
hres = jsdisp_propput_dontenum(err, descriptionW, jsval_string(msg));
if(FAILED(hres)) {
jsdisp_release(err);
return hres;
@ -235,19 +227,21 @@ static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, jsval_
num = n;
}
if(argc>1 && !msg) {
hres = to_string(ctx, argv[1], &msg);
if(FAILED(hres))
return hres;
if(!msg) {
if(argc > 1) {
hres = to_string(ctx, argv[1], &msg);
if(FAILED(hres))
return hres;
}else {
msg = jsstr_empty();
}
}
switch(flags) {
case INVOKE_FUNC:
case DISPATCH_CONSTRUCT:
hres = create_error(ctx, constr, num, msg ? msg->str : NULL, &err);
if(msg)
jsstr_release(msg);
hres = create_error(ctx, constr, num, msg, &err);
jsstr_release(msg);
if(FAILED(hres))
return hres;
@ -375,6 +369,7 @@ static HRESULT throw_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str, j
{
WCHAR buf[1024], *pos = NULL;
jsdisp_t *err;
jsstr_t *msg;
HRESULT hres;
if(!is_jscript_error(error))
@ -392,7 +387,12 @@ static HRESULT throw_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str, j
WARN("%s\n", debugstr_w(buf));
hres = create_error(ctx, constr, error, buf, &err);
msg = jsstr_alloc(buf);
if(!msg)
return E_OUTOFMEMORY;
hres = create_error(ctx, constr, error, msg, &err);
jsstr_release(msg);
if(FAILED(hres))
return hres;