Commit bcba0722 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Support propagating error message.

parent 0f4d4f71
...@@ -1978,6 +1978,8 @@ static HRESULT disp_invoke(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD f ...@@ -1978,6 +1978,8 @@ static HRESULT disp_invoke(script_ctx_t *ctx, IDispatch *disp, DISPID id, WORD f
ctx->ei->error = (SUCCEEDED(ei.scode) || ei.scode == DISP_E_EXCEPTION) ? E_FAIL : ei.scode; ctx->ei->error = (SUCCEEDED(ei.scode) || ei.scode == DISP_E_EXCEPTION) ? E_FAIL : ei.scode;
if(ei.bstrSource) if(ei.bstrSource)
ctx->ei->source = jsstr_alloc_len(ei.bstrSource, SysStringLen(ei.bstrSource)); ctx->ei->source = jsstr_alloc_len(ei.bstrSource, SysStringLen(ei.bstrSource));
if(ei.bstrDescription)
ctx->ei->message = jsstr_alloc_len(ei.bstrDescription, SysStringLen(ei.bstrDescription));
SysFreeString(ei.bstrSource); SysFreeString(ei.bstrSource);
SysFreeString(ei.bstrDescription); SysFreeString(ei.bstrDescription);
SysFreeString(ei.bstrHelpFile); SysFreeString(ei.bstrHelpFile);
......
...@@ -867,6 +867,7 @@ static void set_error_value(script_ctx_t *ctx, jsval_t value) ...@@ -867,6 +867,7 @@ static void set_error_value(script_ctx_t *ctx, jsval_t value)
if(is_object_instance(value) && get_object(value) && (obj = to_jsdisp(get_object(value)))) { if(is_object_instance(value) && get_object(value) && (obj = to_jsdisp(get_object(value)))) {
UINT32 number; UINT32 number;
jsstr_t *str;
jsval_t v; jsval_t v;
HRESULT hres; HRESULT hres;
...@@ -879,8 +880,15 @@ static void set_error_value(script_ctx_t *ctx, jsval_t value) ...@@ -879,8 +880,15 @@ static void set_error_value(script_ctx_t *ctx, jsval_t value)
ei->error = FAILED(number) ? number : E_FAIL; ei->error = FAILED(number) ? number : E_FAIL;
jsval_release(v); jsval_release(v);
} }
}
hres = jsdisp_propget_name(obj, L"description", &v);
if(SUCCEEDED(hres)) {
hres = to_string(ctx, v, &str);
if(SUCCEEDED(hres))
ei->message = str;
jsval_release(v);
}
}
} }
/* ECMA-262 3rd Edition 12.13 */ /* ECMA-262 3rd Edition 12.13 */
...@@ -2769,8 +2777,10 @@ static HRESULT unwind_exception(script_ctx_t *ctx, HRESULT exception_hres) ...@@ -2769,8 +2777,10 @@ static HRESULT unwind_exception(script_ctx_t *ctx, HRESULT exception_hres)
} }
frame = ctx->call_ctx; frame = ctx->call_ctx;
if(exception_hres != DISP_E_EXCEPTION) if(exception_hres != DISP_E_EXCEPTION) {
reset_ei(ei);
ei->error = exception_hres; ei->error = exception_hres;
}
set_error_location(ei, frame->bytecode, frame->bytecode->instrs[frame->ip].loc, IDS_RUNTIME_ERROR); set_error_location(ei, frame->bytecode, frame->bytecode->instrs[frame->ip].loc, IDS_RUNTIME_ERROR);
while(!frame->except_frame) { while(!frame->except_frame) {
......
...@@ -228,6 +228,7 @@ struct _jsexcept_t { ...@@ -228,6 +228,7 @@ struct _jsexcept_t {
jsval_t value; jsval_t value;
jsstr_t *source; jsstr_t *source;
jsstr_t *message;
bytecode_t *code; bytecode_t *code;
unsigned loc; unsigned loc;
......
...@@ -455,6 +455,8 @@ void set_error_location(jsexcept_t *ei, bytecode_t *code, unsigned loc, unsigned ...@@ -455,6 +455,8 @@ void set_error_location(jsexcept_t *ei, bytecode_t *code, unsigned loc, unsigned
len = LoadStringW(jscript_hinstance, source_id, (WCHAR*)&res, 0); len = LoadStringW(jscript_hinstance, source_id, (WCHAR*)&res, 0);
ei->source = jsstr_alloc_len(res, len); ei->source = jsstr_alloc_len(res, len);
} }
if(!ei->message)
ei->message = format_error_message(ei->error, NULL);
} }
TRACE("source %s in %s\n", debugstr_w(code->source + loc), debugstr_w(code->source)); TRACE("source %s in %s\n", debugstr_w(code->source + loc), debugstr_w(code->source));
...@@ -538,6 +540,6 @@ jsdisp_t *create_builtin_error(script_ctx_t *ctx) ...@@ -538,6 +540,6 @@ jsdisp_t *create_builtin_error(script_ctx_t *ctx)
} }
} }
hres = create_error(ctx, constr, ei->error, jsstr_empty(), &r); hres = create_error(ctx, constr, ei->error, ei->message ? ei->message : jsstr_empty(), &r);
return SUCCEEDED(hres) ? r : NULL; return SUCCEEDED(hres) ? r : NULL;
} }
...@@ -223,6 +223,10 @@ void reset_ei(jsexcept_t *ei) ...@@ -223,6 +223,10 @@ void reset_ei(jsexcept_t *ei)
jsstr_release(ei->source); jsstr_release(ei->source);
ei->source = NULL; ei->source = NULL;
} }
if(ei->message) {
jsstr_release(ei->message);
ei->message = NULL;
}
} }
void enter_script(script_ctx_t *ctx, jsexcept_t *ei) void enter_script(script_ctx_t *ctx, jsexcept_t *ei)
......
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