Piotr Caban : jscript: Added "Expected '('" error.

Alexandre Julliard julliard at winehq.org
Fri Jul 24 08:49:36 CDT 2009


Module: wine
Branch: master
Commit: 29d9f09992a3fa8821cb77588e1afe1b1c552f5d
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=29d9f09992a3fa8821cb77588e1afe1b1c552f5d

Author: Piotr Caban <piotr.caban at gmail.com>
Date:   Fri Jul 24 09:36:04 2009 +0200

jscript: Added "Expected '('" error.

---

 dlls/jscript/jscript_En.rc |    1 +
 dlls/jscript/parser.y      |   40 ++++++++++++++++++++++++++--------------
 dlls/jscript/resource.h    |    1 +
 dlls/jscript/tests/api.js  |    7 +++++++
 4 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/dlls/jscript/jscript_En.rc b/dlls/jscript/jscript_En.rc
index 154479a..325df41 100644
--- a/dlls/jscript/jscript_En.rc
+++ b/dlls/jscript/jscript_En.rc
@@ -27,6 +27,7 @@ STRINGTABLE DISCARDABLE
     IDS_NO_PROPERTY         "Object doesn't support this property or method"
     IDS_ARG_NOT_OPT         "Argument not optional"
     IDS_SYNTAX_ERROR        "Syntax error"
+    IDS_LBRACKET            "Expected '('"
     IDS_NOT_FUNC            "Function expected"
     IDS_NOT_DATE            "'[object]' is not a date object"
     IDS_NOT_NUM             "Number expected"
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index adec6bc..3777478 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -25,6 +25,7 @@
 #define YYPARSE_PARAM ctx
 
 static int parser_error(const char*);
+static void set_error(parser_ctx_t*,UINT);
 static BOOL allow_auto_semicolon(parser_ctx_t*);
 static void program_parsed(parser_ctx_t*,source_elements_t*);
 static source_elements_t *function_body_parsed(parser_ctx_t*,source_elements_t*);
@@ -266,7 +267,7 @@ SourceElements
 
 /* ECMA-262 3rd Edition    13 */
 FunctionExpression
-        : KFunction Identifier_opt '(' FormalParameterList_opt ')' '{' FunctionBody '}'
+        : KFunction Identifier_opt left_bracket FormalParameterList_opt ')' '{' FunctionBody '}'
                                 { $$ = new_function_expression(ctx, $2, $4, $7, $1, $8-$1+1); }
 
 KFunction
@@ -379,24 +380,24 @@ ExpressionStatement
 
 /* ECMA-262 3rd Edition    12.5 */
 IfStatement
-        : kIF '(' Expression ')' Statement kELSE Statement
+        : kIF left_bracket Expression ')' Statement kELSE Statement
                                 { $$ = new_if_statement(ctx, $3, $5, $7); }
-        | kIF '(' Expression ')' Statement %prec LOWER_THAN_ELSE
+        | kIF left_bracket Expression ')' Statement %prec LOWER_THAN_ELSE
                                 { $$ = new_if_statement(ctx, $3, $5, NULL); }
 
 /* ECMA-262 3rd Edition    12.6 */
 IterationStatement
-        : kDO Statement kWHILE '(' Expression ')' semicolon_opt
+        : kDO Statement kWHILE left_bracket Expression ')' semicolon_opt
                                 { $$ = new_while_statement(ctx, TRUE, $5, $2); }
-        | kWHILE '(' Expression ')' Statement
+        | kWHILE left_bracket Expression ')' Statement
                                 { $$ = new_while_statement(ctx, FALSE, $3, $5); }
-        | kFOR '(' ExpressionNoIn_opt ';' Expression_opt ';' Expression_opt ')' Statement
+        | kFOR left_bracket ExpressionNoIn_opt ';' Expression_opt ';' Expression_opt ')' Statement
                                 { $$ = new_for_statement(ctx, NULL, $3, $5, $7, $9); }
-        | kFOR '(' kVAR VariableDeclarationListNoIn ';' Expression_opt ';' Expression_opt ')' Statement
+        | kFOR left_bracket kVAR VariableDeclarationListNoIn ';' Expression_opt ';' Expression_opt ')' Statement
                                 { $$ = new_for_statement(ctx, $4, NULL, $6, $8, $10); }
-        | kFOR '(' LeftHandSideExpression kIN Expression ')' Statement
+        | kFOR left_bracket LeftHandSideExpression kIN Expression ')' Statement
                                 { $$ = new_forin_statement(ctx, NULL, $3, $5, $7); }
-        | kFOR '(' kVAR VariableDeclarationNoIn kIN Expression ')' Statement
+        | kFOR left_bracket kVAR VariableDeclarationNoIn kIN Expression ')' Statement
                                 { $$ = new_forin_statement(ctx, $4, NULL, $6, $8); }
 
 /* ECMA-262 3rd Edition    12.7 */
@@ -416,7 +417,7 @@ ReturnStatement
 
 /* ECMA-262 3rd Edition    12.10 */
 WithStatement
-        : kWITH '(' Expression ')' Statement
+        : kWITH left_bracket Expression ')' Statement
                                 { $$ = new_with_statement(ctx, $3, $5); }
 
 /* ECMA-262 3rd Edition    12.12 */
@@ -426,8 +427,8 @@ LabelledStatement
 
 /* ECMA-262 3rd Edition    12.11 */
 SwitchStatement
-        : kSWITCH '(' Expression ')' CaseBlock
-                                 { $$ = new_switch_statement(ctx, $3, $5); }
+        : kSWITCH left_bracket Expression ')' CaseBlock
+                                { $$ = new_switch_statement(ctx, $3, $5); }
 
 /* ECMA-262 3rd Edition    12.11 */
 CaseBlock
@@ -471,8 +472,8 @@ TryStatement
 
 /* ECMA-262 3rd Edition    12.14 */
 Catch
-        : kCATCH '(' tIdentifier ')' Block
-                                 { $$ = new_catch_block(ctx, $3, $5); }
+        : kCATCH left_bracket tIdentifier ')' Block
+                                { $$ = new_catch_block(ctx, $3, $5); }
 
 /* ECMA-262 3rd Edition    12.14 */
 Finally
@@ -493,6 +494,7 @@ Expression
 ExpressionNoIn_opt
         : /* empty */           { $$ = NULL; }
         | ExpressionNoIn        { $$ = $1; }
+        | error                 {  set_error(ctx, IDS_SYNTAX_ERROR); YYABORT; }
 
 /* ECMA-262 3rd Edition    11.14 */
 ExpressionNoIn
@@ -796,6 +798,10 @@ semicolon_opt
         : ';'
         | error                 { if(!allow_auto_semicolon(ctx)) {YYABORT;} }
 
+left_bracket
+        : '('
+        | error                 { set_error(ctx, IDS_LBRACKET); YYABORT; }
+
 %%
 
 static BOOL allow_auto_semicolon(parser_ctx_t *ctx)
@@ -1434,6 +1440,12 @@ static int parser_error(const char *str)
     return 0;
 }
 
+static void set_error(parser_ctx_t *ctx, UINT error)
+{
+    ctx->hres = JSCRIPT_ERROR|error;
+}
+
+
 static expression_t *new_identifier_expression(parser_ctx_t *ctx, const WCHAR *identifier)
 {
     identifier_expression_t *ret = parser_alloc(ctx, sizeof(identifier_expression_t));
diff --git a/dlls/jscript/resource.h b/dlls/jscript/resource.h
index fd2cb82..c0e73f9 100644
--- a/dlls/jscript/resource.h
+++ b/dlls/jscript/resource.h
@@ -23,6 +23,7 @@
 #define IDS_NO_PROPERTY                     0x01B6
 #define IDS_ARG_NOT_OPT                     0x01c1
 #define IDS_SYNTAX_ERROR                    0x03EA
+#define IDS_LBRACKET                        0x03ED
 #define IDS_NOT_FUNC                        0x138A
 #define IDS_NOT_DATE                        0x138E
 #define IDS_NOT_NUM                         0x1389
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index a71c0aa..efc8578 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -1318,5 +1318,12 @@ exception_test(function() {arr.toString = Function.prototype.toString; arr.toStr
 exception_test(function() {date();}, "TypeError", -2146823286);
 exception_test(function() {arr();}, "TypeError", -2146823286);
 exception_test(function() {eval("for(i=0;) {}");}, "SyntaxError", -2146827286);
+exception_test(function() {eval("function {};");}, "SyntaxError", -2146827283);
+exception_test(function() {eval("if");}, "SyntaxError", -2146827283);
+exception_test(function() {eval("do i=0; while");}, "SyntaxError", -2146827283);
+exception_test(function() {eval("while");}, "SyntaxError", -2146827283);
+exception_test(function() {eval("for");}, "SyntaxError", -2146827283);
+exception_test(function() {eval("with");}, "SyntaxError", -2146827283);
+exception_test(function() {eval("switch");}, "SyntaxError", -2146827283);
 
 reportSuccess();




More information about the wine-cvs mailing list