jscript: Don't list LexicalDeclaration in Statement.
Signed-off-by: Paul Gofman <pgofman@codeweavers.com> Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
9008cd2f24
commit
cf751a6dd3
|
@ -2448,7 +2448,7 @@ static HRESULT init_code(compiler_ctx_t *compiler, const WCHAR *source, UINT64 s
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, function_expression_t *func_expr,
|
||||
static HRESULT compile_function(compiler_ctx_t *ctx, statement_list_t *source, function_expression_t *func_expr,
|
||||
BOOL from_eval, function_code_t *func)
|
||||
{
|
||||
function_expression_t *iter;
|
||||
|
@ -2506,7 +2506,7 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
|
|||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
hres = visit_block_statement(ctx, NULL, source->statement);
|
||||
hres = visit_block_statement(ctx, NULL, source ? source->head : NULL);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
|
@ -2547,7 +2547,7 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
|
|||
|
||||
ctx->current_function_expr = ctx->func_head;
|
||||
off = ctx->code_off;
|
||||
hres = compile_block_statement(ctx, NULL, source->statement);
|
||||
hres = compile_block_statement(ctx, NULL, source ? source->head : NULL);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
|
@ -2563,7 +2563,7 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
|
|||
func->instr_off = off;
|
||||
|
||||
for(iter = ctx->func_head, i=0; iter; iter = iter->next, i++) {
|
||||
hres = compile_function(ctx, iter->source_elements, iter, FALSE, func->funcs+i);
|
||||
hres = compile_function(ctx, iter->statement_list, iter, FALSE, func->funcs+i);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
|
||||
|
|
|
@ -16,9 +16,14 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
typedef struct _source_elements_t source_elements_t;
|
||||
typedef struct _expression_t expression_t;
|
||||
typedef struct _statement_t statement_t;
|
||||
|
||||
typedef struct _statement_list_t {
|
||||
statement_t *head;
|
||||
statement_t *tail;
|
||||
} statement_list_t;
|
||||
|
||||
struct _bytecode_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -36,7 +41,7 @@ typedef struct _parser_ctx_t {
|
|||
|
||||
script_ctx_t *script;
|
||||
struct _compiler_ctx_t *compiler;
|
||||
source_elements_t *source;
|
||||
statement_list_t *source;
|
||||
BOOL nl;
|
||||
BOOL implicit_nl_semicolon;
|
||||
BOOL is_html;
|
||||
|
@ -290,17 +295,12 @@ typedef struct _parameter_t {
|
|||
struct _parameter_t *next;
|
||||
} parameter_t;
|
||||
|
||||
struct _source_elements_t {
|
||||
statement_t *statement;
|
||||
statement_t *statement_tail;
|
||||
};
|
||||
|
||||
typedef struct _function_expression_t {
|
||||
expression_t expr;
|
||||
const WCHAR *identifier;
|
||||
const WCHAR *event_target;
|
||||
parameter_t *parameter_list;
|
||||
source_elements_t *source_elements;
|
||||
statement_list_t *statement_list;
|
||||
const WCHAR *src_str;
|
||||
DWORD src_len;
|
||||
unsigned func_id;
|
||||
|
|
|
@ -31,11 +31,6 @@ static void set_error(parser_ctx_t*,unsigned,HRESULT);
|
|||
static BOOL explicit_error(parser_ctx_t*,void*,WCHAR);
|
||||
static BOOL allow_auto_semicolon(parser_ctx_t*);
|
||||
|
||||
typedef struct _statement_list_t {
|
||||
statement_t *head;
|
||||
statement_t *tail;
|
||||
} statement_list_t;
|
||||
|
||||
static literal_t *new_string_literal(parser_ctx_t*,jsstr_t*);
|
||||
static literal_t *new_null_literal(parser_ctx_t*);
|
||||
|
||||
|
@ -121,7 +116,7 @@ static parameter_list_t *parameter_list_add(parser_ctx_t*,parameter_list_t*,cons
|
|||
|
||||
static void *new_expression(parser_ctx_t *ctx,expression_type_t,size_t);
|
||||
static expression_t *new_function_expression(parser_ctx_t*,const WCHAR*,parameter_list_t*,
|
||||
source_elements_t*,const WCHAR*,const WCHAR*,DWORD);
|
||||
statement_list_t*,const WCHAR*,const WCHAR*,DWORD);
|
||||
static expression_t *new_binary_expression(parser_ctx_t*,expression_type_t,expression_t*,expression_t*);
|
||||
static expression_t *new_unary_expression(parser_ctx_t*,expression_type_t,expression_t*);
|
||||
static expression_t *new_conditional_expression(parser_ctx_t*,expression_t*,expression_t*,expression_t*);
|
||||
|
@ -133,9 +128,6 @@ static expression_t *new_literal_expression(parser_ctx_t*,literal_t*);
|
|||
static expression_t *new_array_literal_expression(parser_ctx_t*,element_list_t*,int);
|
||||
static expression_t *new_prop_and_value_expression(parser_ctx_t*,property_list_t*);
|
||||
|
||||
static source_elements_t *new_source_elements(parser_ctx_t*);
|
||||
static source_elements_t *source_elements_add_statement(source_elements_t*,statement_t*);
|
||||
|
||||
#define YYLTYPE unsigned
|
||||
#define YYLLOC_DEFAULT(Cur, Rhs, N) Cur = YYRHSLOC((Rhs), (N) ? 1 : 0)
|
||||
|
||||
|
@ -144,7 +136,7 @@ static source_elements_t *source_elements_add_statement(source_elements_t*,state
|
|||
%lex-param { parser_ctx_t *ctx }
|
||||
%parse-param { parser_ctx_t *ctx }
|
||||
%define api.pure
|
||||
%start Program
|
||||
%start Script
|
||||
|
||||
%union {
|
||||
int ival;
|
||||
|
@ -160,7 +152,6 @@ static source_elements_t *source_elements_add_statement(source_elements_t*,state
|
|||
struct _parameter_list_t *parameter_list;
|
||||
struct _property_list_t *property_list;
|
||||
property_definition_t *property_definition;
|
||||
source_elements_t *source_elements;
|
||||
statement_t *statement;
|
||||
struct _statement_list_t *statement_list;
|
||||
struct _variable_list_t *variable_list;
|
||||
|
@ -179,9 +170,11 @@ static source_elements_t *source_elements_add_statement(source_elements_t*,state
|
|||
%token <literal> tNumericLiteral tBooleanLiteral
|
||||
%token <str> tStringLiteral
|
||||
|
||||
%type <source_elements> SourceElements
|
||||
%type <source_elements> FunctionBody
|
||||
%type <statement_list> FunctionBody
|
||||
%type <statement_list> ScriptBody
|
||||
%type <statement_list> FunctionStatementList
|
||||
%type <statement> Statement
|
||||
%type <statement> Declaration
|
||||
%type <statement> Block
|
||||
%type <statement> LexicalDeclaration
|
||||
%type <statement> VariableStatement
|
||||
|
@ -198,6 +191,7 @@ static source_elements_t *source_elements_add_statement(source_elements_t*,state
|
|||
%type <statement> ThrowStatement
|
||||
%type <statement> TryStatement
|
||||
%type <statement> Finally
|
||||
%type <statement> StatementListItem
|
||||
%type <statement_list> StatementList StatementList_opt
|
||||
%type <parameter_list> FormalParameterList FormalParameterList_opt
|
||||
%type <expr> Expression Expression_opt Expression_err
|
||||
|
@ -252,19 +246,21 @@ static source_elements_t *source_elements_add_statement(source_elements_t*,state
|
|||
|
||||
%%
|
||||
|
||||
/* ECMA-262 3rd Edition 14 */
|
||||
Program
|
||||
: SourceElements HtmlComment { ctx->source = $1; }
|
||||
/* ECMA-262 10th Edition 15.1 */
|
||||
Script
|
||||
: ScriptBody HtmlComment { ctx->source = $1; }
|
||||
|
||||
/* ECMA-262 10th Edition 15.1 */
|
||||
ScriptBody
|
||||
: StatementList_opt { $$ = $1; }
|
||||
|
||||
HtmlComment
|
||||
: tHTMLCOMMENT
|
||||
| /* empty */
|
||||
|
||||
/* ECMA-262 3rd Edition 14 */
|
||||
SourceElements
|
||||
: /* empty */ { $$ = new_source_elements(ctx); }
|
||||
| SourceElements Statement
|
||||
{ $$ = source_elements_add_statement($1, $2); }
|
||||
/* ECMA-262 10th Edition 14.1 */
|
||||
FunctionStatementList
|
||||
: StatementList_opt { $$ = $1; }
|
||||
|
||||
/* ECMA-262 3rd Edition 13 */
|
||||
FunctionExpression
|
||||
|
@ -275,9 +271,9 @@ FunctionExpression
|
|||
| kFUNCTION tIdentifier kDCOL tIdentifier left_bracket FormalParameterList_opt right_bracket '{' FunctionBody '}'
|
||||
{ $$ = new_function_expression(ctx, $4, $6, $9, $2, ctx->begin + @1, @10 - @1 + 1); }
|
||||
|
||||
/* ECMA-262 3rd Edition 13 */
|
||||
/* ECMA-262 10th Edition 14.1 */
|
||||
FunctionBody
|
||||
: SourceElements { $$ = $1; }
|
||||
: FunctionStatementList { $$ = $1; }
|
||||
|
||||
/* ECMA-262 3rd Edition 13 */
|
||||
FormalParameterList
|
||||
|
@ -293,7 +289,6 @@ FormalParameterList_opt
|
|||
/* ECMA-262 3rd Edition 12 */
|
||||
Statement
|
||||
: Block { $$ = $1; }
|
||||
| LexicalDeclaration { $$ = $1; }
|
||||
| VariableStatement { $$ = $1; }
|
||||
| EmptyStatement { $$ = $1; }
|
||||
| FunctionExpression { $$ = new_expression_statement(ctx, @$, $1); }
|
||||
|
@ -309,10 +304,19 @@ Statement
|
|||
| ThrowStatement { $$ = $1; }
|
||||
| TryStatement { $$ = $1; }
|
||||
|
||||
/* ECMA-262 3rd Edition 12.2 */
|
||||
/* ECMA-262 10th Edition 13. TODO: HoistableDeclaration */
|
||||
Declaration
|
||||
: LexicalDeclaration { $$ = $1; }
|
||||
|
||||
/* ECMA-262 10th Edition 13.2 */
|
||||
StatementListItem
|
||||
: Statement { $$ = $1; }
|
||||
| Declaration { $$ = $1; }
|
||||
|
||||
/* ECMA-262 10th Edition 13.2 */
|
||||
StatementList
|
||||
: Statement { $$ = new_statement_list(ctx, $1); }
|
||||
| StatementList Statement
|
||||
: StatementListItem { $$ = new_statement_list(ctx, $1); }
|
||||
| StatementList StatementListItem
|
||||
{ $$ = statement_list_add($1, $2); }
|
||||
|
||||
/* ECMA-262 3rd Edition 12.2 */
|
||||
|
@ -1404,13 +1408,13 @@ static parameter_list_t *parameter_list_add(parser_ctx_t *ctx, parameter_list_t
|
|||
}
|
||||
|
||||
static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *identifier, parameter_list_t *parameter_list,
|
||||
source_elements_t *source_elements, const WCHAR *event_target, const WCHAR *src_str, DWORD src_len)
|
||||
statement_list_t *statement_list, const WCHAR *event_target, const WCHAR *src_str, DWORD src_len)
|
||||
{
|
||||
function_expression_t *ret = new_expression(ctx, EXPR_FUNC, sizeof(*ret));
|
||||
|
||||
ret->identifier = identifier;
|
||||
ret->parameter_list = parameter_list ? parameter_list->head : NULL;
|
||||
ret->source_elements = source_elements;
|
||||
ret->statement_list = statement_list;
|
||||
ret->event_target = event_target;
|
||||
ret->src_str = src_str;
|
||||
ret->src_len = src_len;
|
||||
|
@ -1553,25 +1557,6 @@ static expression_t *new_literal_expression(parser_ctx_t *ctx, literal_t *litera
|
|||
return &ret->expr;
|
||||
}
|
||||
|
||||
static source_elements_t *new_source_elements(parser_ctx_t *ctx)
|
||||
{
|
||||
source_elements_t *ret = parser_alloc(ctx, sizeof(source_elements_t));
|
||||
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static source_elements_t *source_elements_add_statement(source_elements_t *source_elements, statement_t *statement)
|
||||
{
|
||||
if(source_elements->statement_tail)
|
||||
source_elements->statement_tail = source_elements->statement_tail->next = statement;
|
||||
else
|
||||
source_elements->statement = source_elements->statement_tail = statement;
|
||||
|
||||
return source_elements;
|
||||
}
|
||||
|
||||
static statement_list_t *new_statement_list(parser_ctx_t *ctx, statement_t *statement)
|
||||
{
|
||||
statement_list_t *ret = parser_alloc_tmp(ctx, sizeof(statement_list_t));
|
||||
|
|
|
@ -1318,6 +1318,18 @@ sync_test("declaration_let", function() {
|
|||
}
|
||||
|
||||
ok(a == 3, "a != 3");
|
||||
|
||||
var except = false
|
||||
|
||||
try
|
||||
{
|
||||
eval('if (true) let a = 3');
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
except = true;
|
||||
}
|
||||
ok(except, "with({w:9}) let a = 3: expected exception.");
|
||||
});
|
||||
|
||||
sync_test("let scope instances", function() {
|
||||
|
|
Loading…
Reference in New Issue