jscript: Add GetSourceLineText implementation.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
26ad9a7ba3
commit
150b7391b8
|
@ -2521,7 +2521,7 @@ HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, UINT64 source_conte
|
||||||
if(FAILED(hres)) {
|
if(FAILED(hres)) {
|
||||||
if(hres != DISP_E_EXCEPTION)
|
if(hres != DISP_E_EXCEPTION)
|
||||||
throw_error(ctx, hres, NULL);
|
throw_error(ctx, hres, NULL);
|
||||||
set_error_location(ctx->ei, compiler.code, compiler.loc, IDS_COMPILATION_ERROR);
|
set_error_location(ctx->ei, compiler.code, compiler.loc, IDS_COMPILATION_ERROR, NULL);
|
||||||
release_bytecode(compiler.code);
|
release_bytecode(compiler.code);
|
||||||
return DISP_E_EXCEPTION;
|
return DISP_E_EXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2779,7 +2779,7 @@ 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)
|
||||||
throw_error(ctx, exception_hres, NULL);
|
throw_error(ctx, exception_hres, NULL);
|
||||||
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, NULL);
|
||||||
|
|
||||||
while(!frame->except_frame) {
|
while(!frame->except_frame) {
|
||||||
DWORD flags;
|
DWORD flags;
|
||||||
|
|
|
@ -229,6 +229,7 @@ struct _jsexcept_t {
|
||||||
|
|
||||||
jsstr_t *source;
|
jsstr_t *source;
|
||||||
jsstr_t *message;
|
jsstr_t *message;
|
||||||
|
jsstr_t *line;
|
||||||
|
|
||||||
bytecode_t *code;
|
bytecode_t *code;
|
||||||
unsigned loc;
|
unsigned loc;
|
||||||
|
@ -240,7 +241,7 @@ struct _jsexcept_t {
|
||||||
void enter_script(script_ctx_t*,jsexcept_t*) DECLSPEC_HIDDEN;
|
void enter_script(script_ctx_t*,jsexcept_t*) DECLSPEC_HIDDEN;
|
||||||
HRESULT leave_script(script_ctx_t*,HRESULT) DECLSPEC_HIDDEN;
|
HRESULT leave_script(script_ctx_t*,HRESULT) DECLSPEC_HIDDEN;
|
||||||
void reset_ei(jsexcept_t*) DECLSPEC_HIDDEN;
|
void reset_ei(jsexcept_t*) DECLSPEC_HIDDEN;
|
||||||
void set_error_location(jsexcept_t*,bytecode_t*,unsigned,unsigned) DECLSPEC_HIDDEN;
|
void set_error_location(jsexcept_t*,bytecode_t*,unsigned,unsigned,jsstr_t*) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
typedef struct _except_frame_t except_frame_t;
|
typedef struct _except_frame_t except_frame_t;
|
||||||
struct _parser_ctx_t;
|
struct _parser_ctx_t;
|
||||||
|
|
|
@ -420,7 +420,7 @@ HRESULT throw_error(script_ctx_t *ctx, HRESULT error, const WCHAR *str)
|
||||||
return DISP_E_EXCEPTION;
|
return DISP_E_EXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_error_location(jsexcept_t *ei, bytecode_t *code, unsigned loc, unsigned source_id)
|
void set_error_location(jsexcept_t *ei, bytecode_t *code, unsigned loc, unsigned source_id, jsstr_t *line)
|
||||||
{
|
{
|
||||||
if(is_jscript_error(ei->error)) {
|
if(is_jscript_error(ei->error)) {
|
||||||
if(!ei->source) {
|
if(!ei->source) {
|
||||||
|
@ -438,6 +438,8 @@ void set_error_location(jsexcept_t *ei, bytecode_t *code, unsigned loc, unsigned
|
||||||
|
|
||||||
ei->code = bytecode_addref(code);
|
ei->code = bytecode_addref(code);
|
||||||
ei->loc = loc;
|
ei->loc = loc;
|
||||||
|
if(line)
|
||||||
|
ei->line = jsstr_addref(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
jsdisp_t *create_builtin_error(script_ctx_t *ctx)
|
jsdisp_t *create_builtin_error(script_ctx_t *ctx)
|
||||||
|
|
|
@ -211,12 +211,17 @@ static HRESULT WINAPI JScriptError_GetSourceLineText(IActiveScriptError *iface,
|
||||||
{
|
{
|
||||||
JScriptError *This = impl_from_IActiveScriptError(iface);
|
JScriptError *This = impl_from_IActiveScriptError(iface);
|
||||||
|
|
||||||
FIXME("(%p)->(%p)\n", This, source);
|
TRACE("(%p)->(%p)\n", This, source);
|
||||||
|
|
||||||
if(!source)
|
if(!source)
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
|
||||||
|
if(!This->ei.line) {
|
||||||
*source = NULL;
|
*source = NULL;
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsstr_to_bstr(This->ei.line, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const IActiveScriptErrorVtbl JScriptErrorVtbl = {
|
static const IActiveScriptErrorVtbl JScriptErrorVtbl = {
|
||||||
|
@ -248,6 +253,10 @@ void reset_ei(jsexcept_t *ei)
|
||||||
jsstr_release(ei->message);
|
jsstr_release(ei->message);
|
||||||
ei->message = NULL;
|
ei->message = NULL;
|
||||||
}
|
}
|
||||||
|
if(ei->line) {
|
||||||
|
jsstr_release(ei->line);
|
||||||
|
ei->line = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void enter_script(script_ctx_t *ctx, jsexcept_t *ei)
|
void enter_script(script_ctx_t *ctx, jsexcept_t *ei)
|
||||||
|
|
|
@ -1598,12 +1598,24 @@ HRESULT script_parse(script_ctx_t *ctx, struct _compiler_ctx_t *compiler, byteco
|
||||||
heap_pool_clear(mark);
|
heap_pool_clear(mark);
|
||||||
hres = parser_ctx->hres;
|
hres = parser_ctx->hres;
|
||||||
if(FAILED(hres)) {
|
if(FAILED(hres)) {
|
||||||
WARN("parser failed around %s\n",
|
const WCHAR *line_start = code->source + parser_ctx->error_loc, *line_end = line_start;
|
||||||
debugstr_w(parser_ctx->begin+20 > parser_ctx->ptr ? parser_ctx->begin : parser_ctx->ptr-20));
|
jsstr_t *line_str;
|
||||||
|
|
||||||
|
while(line_start > code->source && line_start[-1] != '\n')
|
||||||
|
line_start--;
|
||||||
|
while(*line_end && *line_end != '\n')
|
||||||
|
line_end++;
|
||||||
|
line_str = jsstr_alloc_len(line_start, line_end - line_start);
|
||||||
|
|
||||||
|
WARN("parser failed around %s in line %s\n",
|
||||||
|
debugstr_w(parser_ctx->begin+20 > parser_ctx->ptr ? parser_ctx->begin : parser_ctx->ptr-20),
|
||||||
|
debugstr_jsstr(line_str));
|
||||||
|
|
||||||
throw_error(ctx, hres, NULL);
|
throw_error(ctx, hres, NULL);
|
||||||
set_error_location(ctx->ei, code, parser_ctx->error_loc, IDS_COMPILATION_ERROR);
|
set_error_location(ctx->ei, code, parser_ctx->error_loc, IDS_COMPILATION_ERROR, line_str);
|
||||||
parser_release(parser_ctx);
|
parser_release(parser_ctx);
|
||||||
|
if(line_str)
|
||||||
|
jsstr_release(line_str);
|
||||||
return DISP_E_EXCEPTION;
|
return DISP_E_EXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2232,6 +2232,13 @@ static void test_error_reports(void)
|
||||||
NULL,
|
NULL,
|
||||||
ERROR_TODO_SCODE | ERROR_TODO_DESCRIPTION
|
ERROR_TODO_SCODE | ERROR_TODO_DESCRIPTION
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
L"f(1\n,\n2,\n ,,3\n);\n",
|
||||||
|
JS_E_SYNTAX, 3, 1,
|
||||||
|
L"Microsoft JScript compilation error",
|
||||||
|
L"Syntax error",
|
||||||
|
L" ,,3"
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!is_lang_english())
|
if (!is_lang_english())
|
||||||
|
@ -2304,9 +2311,7 @@ static void test_error_reports(void)
|
||||||
hres = IActiveScriptError_GetSourceLineText(script_error, &line_text);
|
hres = IActiveScriptError_GetSourceLineText(script_error, &line_text);
|
||||||
if (tests[i].line_text)
|
if (tests[i].line_text)
|
||||||
{
|
{
|
||||||
todo_wine
|
|
||||||
ok(hres == S_OK, "GetSourceLineText failed: %08x\n", hres);
|
ok(hres == S_OK, "GetSourceLineText failed: %08x\n", hres);
|
||||||
todo_wine
|
|
||||||
ok(line_text != NULL && !lstrcmpW(line_text, tests[i].line_text), "[%u] GetSourceLineText returned %s expected %s\n",
|
ok(line_text != NULL && !lstrcmpW(line_text, tests[i].line_text), "[%u] GetSourceLineText returned %s expected %s\n",
|
||||||
i, wine_dbgstr_w(line_text), wine_dbgstr_w(tests[i].line_text));
|
i, wine_dbgstr_w(line_text), wine_dbgstr_w(tests[i].line_text));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue