From 348eef2e02eb3d9fcbbf6a0eb2aa473c816c08c9 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 3 Feb 2020 14:48:07 +0100 Subject: [PATCH] jscript: Add GetSourcePosition implementation. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/jscript.c | 25 +++++++++++++++++++++---- dlls/jscript/tests/run.c | 3 --- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c index 8f79ea4bd4d..860fb01cf51 100644 --- a/dlls/jscript/jscript.c +++ b/dlls/jscript/jscript.c @@ -178,15 +178,32 @@ static HRESULT WINAPI JScriptError_GetExceptionInfo(IActiveScriptError *iface, E static HRESULT WINAPI JScriptError_GetSourcePosition(IActiveScriptError *iface, DWORD *source_context, ULONG *line, LONG *character) { JScriptError *This = impl_from_IActiveScriptError(iface); + bytecode_t *code = This->ei.code; + const WCHAR *nl, *p; + unsigned l; - FIXME("(%p)->(%p %p %p)\n", This, source_context, line, character); + TRACE("(%p)->(%p %p %p)\n", This, source_context, line, character); + + if(!This->ei.code) { + FIXME("unknown position\n"); + return E_FAIL; + } if(source_context) - *source_context = 0; + *source_context = This->ei.code->source_context; + if(!line && !character) + return S_OK; + + l = code->start_line; + for(nl = p = code->source; p < code->source + This->ei.loc; p++) { + if(*p != '\n') continue; + l++; + nl = p + 1; + } if(line) - *line = 0; + *line = l; if(character) - *character = 0; + *character = code->source + This->ei.loc - nl; return S_OK; } diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c index 1d11e00f449..6e2250882d5 100644 --- a/dlls/jscript/tests/run.c +++ b/dlls/jscript/tests/run.c @@ -2285,19 +2285,16 @@ static void test_error_reports(void) source_context = 0xdeadbeef; hres = IActiveScriptError_GetSourcePosition(script_error, &source_context, NULL, NULL); ok(hres == S_OK, "GetSourcePosition failed0x%08x\n", hres); - todo_wine ok(source_context == 10, "source_context = %x\n", source_context); line_number = 0xdeadbeef; hres = IActiveScriptError_GetSourcePosition(script_error, NULL, &line_number, NULL); ok(hres == S_OK, "GetSourcePosition failed%08x\n", hres); - todo_wine_if(tests[i].line) ok(line_number == tests[i].line, "[%u] line = %u expected %u\n", i, line_number, tests[i].line); character = 0xdeadbeef; hres = IActiveScriptError_GetSourcePosition(script_error, NULL, NULL, &character); ok(hres == S_OK, "GetSourcePosition failed: %08x\n", hres); - todo_wine_if(tests[i].character) ok(character == tests[i].character, "[%u] character = %u expected %u\n", i, character, tests[i].character); hres = IActiveScriptError_GetSourceLineText(script_error, NULL);