[PATCH] jscript: Ignore BOM mark in next_token. (try 5)
Qian Hong
fracting at gmail.com
Thu Oct 2 16:39:58 CDT 2014
The patch has got in, but if you like, I can proposal a new version
like the attached patches. (Need rebasing on latest Wine).
On Thu, Oct 2, 2014 at 7:26 PM, Qian Hong <fracting at gmail.com> wrote:
> Hi Nikolay,
>
> Thanks for commenting, your thought is helpful as usual :)
>
> I added tests for more space separators, also added tests for parseFloat():
> https://testbot.winehq.org/JobDetails.pl?Key=9203&log_206=1#k206
>
> The test result show that, older version of jscript doesn't flow the
> standard, while newer version is much better.
> The test result also show that, BOM and other space separators are
> also ignored in functions like parseFloat.
> I'm planing on adding tests for the following group of functions.
>
> parseInt()
> eval()
> isNaN()
> isFinite()
> new Number()
> new Function()
>
> new Date()
> Date.parse()
>
> RegExp()
>
> My idea is fixing the code in lex.c first, then fixing other place
> using isspaceW in an incremental way with tests provided, like the
> attached patches demos.
>
> Currently there are two troubles bothering me:
> 1. We need a good way to skip space tests on older IEs
> 2. We need a good way to reduce the length of WCHAR array for the
> jscript code, I believe most of us hate a long array like below...
>
> {'v','a','r',' ','a',' ','=','
> ','p','a','r','s','e','F','l','o','a','t','(','"',SPACE_HOLDER,'3','.','1','4',SPACE_HOLDER,'"',')',';','o','k','(','a','=','=','3','.','1','4',',','
> ','"','h','a','h','a','"',')',';','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}
>
> Do you have any advice?
>
> Thanks!
--
Regards,
Qian Hong
-
http://www.winehq.org
-------------- next part --------------
From 8402b36d91a1d52e118fc61556ce8f6f44cae67d Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong at codeweavers.com>
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 <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>
Cc: Qian Hong<qhong at codeweavers.com>
---
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
-------------- next part --------------
From 3259365bf1581b530070efd75ecaffbb3bb1d49e Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong at codeweavers.com>
Date: Fri, 3 Oct 2014 05:17:03 +0800
Subject: [PATCH 2/5] jscript: Ignore BOM mark in parseFloat.
To: wine-patches <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>
Cc: Qian Hong<qhong at codeweavers.com>
---
dlls/jscript/global.c | 2 +-
dlls/jscript/tests/run.c | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 4d1350f..e0300ac 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -538,7 +538,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
if(FAILED(hres))
return hres;
- while(isspaceW(*str)) str++;
+ while(is_jsspaceW(*str)) str++;
if(*str == '+')
str++;
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index be6bce5..9dd4561 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -1994,6 +1994,9 @@ static const struct spaces_test spaces_tests[] = {
var a = f( 1 , 2 );\
ok(a == 3, \"Function returned \"+a);\
reportSuccess();", S_OK},
+ {"var a = parseFloat(\" 3.14 \");\
+ ok(a == 3.14, \"returned \"+a);\
+ reportSuccess();", S_OK},
{{0}}
};
--
1.9.1
-------------- next part --------------
From 51277bb5f996cb8cae82985ffe8b5cb0a5428cc8 Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong at codeweavers.com>
Date: Fri, 3 Oct 2014 02:30:53 +0800
Subject: [PATCH 3/5] jscript: Ignore BOM mark in parseInt.
To: wine-patches <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>
Cc: Qian Hong<qhong at codeweavers.com>
---
dlls/jscript/global.c | 2 +-
dlls/jscript/tests/run.c | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index e0300ac..de3fe8b 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -470,7 +470,7 @@ static HRESULT JSGlobal_parseInt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(FAILED(hres))
return hres;
- while(isspaceW(*ptr))
+ while(is_jsspaceW(*ptr))
ptr++;
switch(*ptr) {
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index 9dd4561..446adf4 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -1997,6 +1997,9 @@ static const struct spaces_test spaces_tests[] = {
{"var a = parseFloat(\" 3.14 \");\
ok(a == 3.14, \"returned \"+a);\
reportSuccess();", S_OK},
+ {"var a = parseInt(\" 3.14 \");\
+ ok(a == 3, \"returned \"+a);\
+ reportSuccess();", S_OK},
{{0}}
};
--
1.9.1
-------------- next part --------------
From 397d7a248c84a7a1a57592fe3e6f70a13cb6c348 Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong at codeweavers.com>
Date: Fri, 3 Oct 2014 05:09:29 +0800
Subject: [PATCH 4/5] jscript: Ignore BOM mark in str_to_number.
To: wine-patches <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>
Cc: Qian Hong<qhong at codeweavers.com>
---
dlls/jscript/jsutils.c | 6 +++---
dlls/jscript/tests/run.c | 14 ++++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c
index a44168d..336d7c8 100644
--- a/dlls/jscript/jsutils.c
+++ b/dlls/jscript/jsutils.c
@@ -488,7 +488,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
if(!ptr)
return E_OUTOFMEMORY;
- while(isspaceW(*ptr))
+ while(is_jsspaceW(*ptr))
ptr++;
if(*ptr == '-') {
@@ -500,7 +500,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
if(!strncmpW(ptr, infinityW, sizeof(infinityW)/sizeof(WCHAR))) {
ptr += sizeof(infinityW)/sizeof(WCHAR);
- while(*ptr && isspaceW(*ptr))
+ while(*ptr && is_jsspaceW(*ptr))
ptr++;
if(*ptr)
@@ -554,7 +554,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret)
}
}
- while(isspaceW(*ptr))
+ while(is_jsspaceW(*ptr))
ptr++;
if(*ptr) {
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index 446adf4..da60afa 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -2000,6 +2000,20 @@ static const struct spaces_test spaces_tests[] = {
{"var a = parseInt(\" 3.14 \");\
ok(a == 3, \"returned \"+a);\
reportSuccess();", S_OK},
+ {"ok(!isNaN(\" 1 \"), \"!isNaN returned false\");\
+ reportSuccess();", S_OK},
+ {"ok(!isNaN(\" \"), \"!isNaN returned false\");\
+ reportSuccess();", S_OK},
+ {"ok(isFinite(\" 1 \"), \"isFinite returned false\");\
+ reportSuccess();", S_OK},
+ {"ok(isFinite(\" \"), \"isFinite returned false\");\
+ reportSuccess();", S_OK},
+ {"var a = new Number(\" 3.14 \");\
+ ok(a == 3.14, \"Number returned \"+a);\
+ reportSuccess();", S_OK},
+ {"var a = Math.abs(\" -3.14 \");\
+ ok(a == 3.14, \"Number returned \"+a);\
+ reportSuccess();", S_OK},
{{0}}
};
--
1.9.1
-------------- next part --------------
From b6882966bcbcc73893102c87f591ac722c89e339 Mon Sep 17 00:00:00 2001
From: Qian Hong <qhong at codeweavers.com>
Date: Fri, 3 Oct 2014 05:19:00 +0800
Subject: [PATCH 5/5] jscript/tests: Added spaces tests for Date functions.
To: wine-patches <wine-patches at winehq.org>
Reply-To: wine-devel <wine-devel at winehq.org>
Cc: Qian Hong<qhong at codeweavers.com>
---
dlls/jscript/tests/run.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c
index da60afa..9754aa1 100644
--- a/dlls/jscript/tests/run.c
+++ b/dlls/jscript/tests/run.c
@@ -2014,6 +2014,13 @@ static const struct spaces_test spaces_tests[] = {
{"var a = Math.abs(\" -3.14 \");\
ok(a == 3.14, \"Number returned \"+a);\
reportSuccess();", S_OK},
+ {"var a = new Date(\" 100 \");\
+ var y = a.getFullYear();\
+ ok(isNaN(y), \"Date returned \"+y);\
+ reportSuccess();", S_OK},
+ {"var a = Date.parse(\" 1970 \");\
+ ok(isNaN(a), \"Date.parse returned \"+a);\
+ reportSuccess();", S_OK},
{{0}}
};
--
1.9.1
More information about the wine-devel
mailing list