jscript: Use bytecode for invalid assignments.

This commit is contained in:
Jacek Caban 2011-12-05 11:12:32 +01:00 committed by Alexandre Julliard
parent 5b2c2c5cf9
commit 8511797c07
4 changed files with 43 additions and 37 deletions

View File

@ -172,6 +172,18 @@ static HRESULT push_instr_double(compiler_ctx_t *ctx, jsop_t op, double arg)
return S_OK;
}
static HRESULT push_instr_uint(compiler_ctx_t *ctx, jsop_t op, unsigned arg)
{
unsigned instr;
instr = push_instr(ctx, op);
if(instr == -1)
return E_OUTOFMEMORY;
instr_ptr(ctx, instr)->arg1.uint = arg;
return S_OK;
}
static HRESULT compile_binary_expression(compiler_ctx_t *ctx, binary_expression_t *expr, jsop_t op)
{
HRESULT hres;
@ -390,8 +402,15 @@ static HRESULT compile_assign_expression(compiler_ctx_t *ctx, binary_expression_
break;
}
default:
expr->expr.eval = assign_expression_eval;
return compile_interp_fallback(ctx, &expr->expr);
hres = compile_expression(ctx, expr->expression1);
if(FAILED(hres))
return hres;
hres = compile_expression(ctx, expr->expression2);
if(FAILED(hres))
return hres;
return push_instr_uint(ctx, OP_throw, JS_E_ILLEGAL_ASSIGN);
}

View File

@ -1279,6 +1279,15 @@ HRESULT throw_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_
return DISP_E_EXCEPTION;
}
static HRESULT interp_throw(exec_ctx_t *ctx)
{
const HRESULT arg = ctx->parser->code->instrs[ctx->ip].arg1.uint;
TRACE("%08x\n", arg);
return throw_reference_error(ctx->parser->script, &ctx->ei, arg, NULL);
}
/* ECMA-262 3rd Edition 12.14 */
static HRESULT catch_eval(script_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
{
@ -3307,40 +3316,6 @@ HRESULT right2_shift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWO
return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
}
/* ECMA-262 3rd Edition 11.13.1 */
HRESULT assign_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
binary_expression_t *expr = (binary_expression_t*)_expr;
exprval_t exprval, exprvalr;
VARIANT rval;
HRESULT hres;
TRACE("\n");
hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
if(FAILED(hres))
return hres;
hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
if(SUCCEEDED(hres)) {
hres = exprval_to_value(ctx, &exprvalr, ei, &rval);
exprval_release(&exprvalr);
}
if(SUCCEEDED(hres)) {
assert(exprval.type != EXPRVAL_IDREF);
return throw_reference_error(ctx, ei, JS_E_ILLEGAL_ASSIGN, NULL);
}
exprval_release(&exprval);
if(FAILED(hres))
return hres;
ret->type = EXPRVAL_VARIANT;
ret->u.var = rval;
return S_OK;
}
/* ECMA-262 3rd Edition 11.13.1 */
static HRESULT interp_assign(exec_ctx_t *ctx)
{

View File

@ -76,6 +76,7 @@ typedef struct _func_stack {
X(regexp, 1, ARG_STR, ARG_INT) \
X(str, 1, ARG_STR, 0) \
X(this, 1, 0,0) \
X(throw, 0, ARG_UINT, 0) \
X(tonum, 1, 0,0) \
X(tree, 1, ARG_EXPR, 0) \
X(ret, 0, 0,0) \
@ -570,7 +571,6 @@ HRESULT pre_decrement_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept
HRESULT left_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
HRESULT right_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
HRESULT right2_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
HRESULT assign_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
HRESULT assign_lshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
HRESULT assign_rshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
HRESULT assign_rrshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;

View File

@ -2076,6 +2076,18 @@ tmp = false;
testException(function() {test = (tmp = true);}, "E_ILLEGAL_ASSIGN");
ok(tmp, "expr value on invalid assign not evaluated");
tmp = false;
testException(function() {(tmp = true) = false;}, "E_ILLEGAL_ASSIGN");
ok(tmp, "expr assign not evaluated");
tmp = false;
testException(function() {true = (tmp = true);}, "E_ILLEGAL_ASSIGN");
ok(tmp, "expr value assign not evaluated");
tmp = "";
testException(function() {(tmp = tmp+"1") = (tmp = tmp+"2");}, "E_ILLEGAL_ASSIGN");
ok(tmp === "12", "assign evaluated in unexpected order");
// RegExpError tests
testException(function() {RegExp(/a/, "g");}, "E_REGEXP_SYNTAX_ERROR");