From 8402b36d91a1d52e118fc61556ce8f6f44cae67d Mon Sep 17 00:00:00 2001 From: Qian Hong Date: Thu, 2 Oct 2014 14:05:50 +0800 Subject: [PATCH 1/5] jscript: Ignore BOM mark in skip_spaces. (try 5) To: wine-patches Reply-To: wine-devel Cc: Qian Hong --- dlls/jscript/jscript.h | 5 +++ dlls/jscript/lex.c | 2 +- dlls/jscript/tests/run.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 0273b00..f6af7f4 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -473,6 +473,11 @@ static inline BOOL is_int32(double d) return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d; } +static inline BOOL is_jsspaceW(WCHAR c) +{ + return isspaceW(c) || c == 0xFEFF /* UTF16 BOM */; +} + static inline DWORD make_grfdex(script_ctx_t *ctx, DWORD flags) { return (ctx->version << 28) | flags; diff --git a/dlls/jscript/lex.c b/dlls/jscript/lex.c index b4a3700..fb1bf61 100644 --- a/dlls/jscript/lex.c +++ b/dlls/jscript/lex.c @@ -241,7 +241,7 @@ static BOOL skip_comment(parser_ctx_t *ctx) static BOOL skip_spaces(parser_ctx_t *ctx) { - while(ctx->ptr < ctx->end && isspaceW(*ctx->ptr)) { + while(ctx->ptr < ctx->end && is_jsspaceW(*ctx->ptr)) { if(is_endline(*ctx->ptr++)) ctx->nl = TRUE; } diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c index aa1783e..be6bce5 100644 --- a/dlls/jscript/tests/run.c +++ b/dlls/jscript/tests/run.c @@ -144,6 +144,7 @@ DEFINE_EXPECT(DeleteMemberByDispID_false); #define DISPID_TESTOBJ_ONLYDISPID 0x2001 #define DISPID_TESTOBJ_WITHPROP 0x2002 +#define JS_E_OUT_OF_MEMORY 0x800a03ec #define JS_E_INVALID_CHAR 0x800a03f6 static const WCHAR testW[] = {'t','e','s','t',0}; @@ -1966,6 +1967,92 @@ static void test_script_exprs(void) testing_expr = FALSE; } +struct spaces_test +{ + char str[1024]; + HRESULT hres; +}; + +static const struct spaces_test spaces_tests[] = { + {"var a=1;reportSuccess();", S_OK}, + {" var a=1;reportSuccess();", S_OK}, + {"var a=1;reportSuccess();", S_OK}, + {"var a =1;reportSuccess();", S_OK}, + {"var a= 1;reportSuccess();", S_OK}, + {"var a=1 ;reportSuccess();", S_OK}, + {"var a=1; reportSuccess();", S_OK}, + {"var a=1;reportSuccess( );", S_OK}, + {"var a=1;reportSuccess() ;", S_OK}, + {"var a=1;reportSuccess(); ", S_OK}, + {" var a = 1; reportSuccess ( ) ; ", S_OK}, + {"v ar a = 1; reportSuccess();", JS_E_OUT_OF_MEMORY}, + {"var a = 1; report Success();", JS_E_OUT_OF_MEMORY}, + {"var a = eval(\" 1 + 3 \");\ + ok(a == 4, \"returned \"+a);\ + reportSuccess();", S_OK}, + {"var f = new Function(\" a \",\" b \",\" return a + b; \");\ + var a = f( 1 , 2 );\ + ok(a == 3, \"Function returned \"+a);\ + reportSuccess();", S_OK}, + {{0}} +}; + +/* ECMA-262 section 7.2 */ +static const WCHAR spaces[] = {0x0009, 0x000B, 0x000C, 0x0020, 0x00A0, 0xFEFF, 0x1680, 0x2000, 0x2001, 0x2002, + 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x200A, 0x202F, 0x205F, 0x3000, 0}; + +static void run_space_test(const char *str, WCHAR space, HRESULT expected_res) +{ + BSTR src = a2bstr(str); + WCHAR *ptr = src; + HRESULT res; + + do { + if (*ptr == 0x0020) + *ptr = space; + } while (*ptr++); + + if(expected_res == S_OK) + { + SET_EXPECT(global_success_d); + SET_EXPECT(global_success_i); + res = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); + ok(res == S_OK, "test %s failed with %08x\n", wine_dbgstr_w(src), res); + CHECK_CALLED(global_success_d); + CHECK_CALLED(global_success_i); + } + else + { + res = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); + todo_wine ok(res == expected_res, "test %s returned with %08x\n", wine_dbgstr_w(src), res); + } + + SysFreeString(src); +} + +static void run_spaces_tests(void) +{ + int i, j; + WCHAR str[] = {'v','a','r',0x205F,'a',0x205F,'=',0x205F,'1',';','\0'}; + BSTR src = SysAllocString(str); + HRESULT hres; + + engine_clsid = &CLSID_JScript; + + hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); + SysFreeString(src); + + if (FAILED(hres)) + { + win_skip("skip spaces tests on old version of jscript\n"); + return; + } + + for (i = 0; spaces_tests[i].str[0]; i++) + for (j = 0; spaces[j]; j++) + run_space_test(spaces_tests[i].str, spaces[j], spaces_tests[i].hres); +} + static BOOL run_tests(void) { HRESULT hres; @@ -2259,6 +2346,8 @@ static BOOL run_tests(void) "Object expected", NULL); + run_spaces_tests(); + return TRUE; } -- 1.9.1