From 622eb728d75b701b6ab54312a1ac7627993fb92c Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 1 May 2017 18:30:06 +0200 Subject: [PATCH] jscript: Added new opcode to enter catch block and use it to setup the scope. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/compile.c | 4 ++++ dlls/jscript/engine.c | 48 +++++++++++++++++++++++------------------- dlls/jscript/engine.h | 1 + 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c index 3770767dde7..662326bcce9 100644 --- a/dlls/jscript/compile.c +++ b/dlls/jscript/compile.c @@ -1720,6 +1720,10 @@ static HRESULT compile_try_statement(compiler_ctx_t *ctx, try_statement_t *stat) instr_ptr(ctx, push_except)->u.arg[0].uint = ctx->code_off; + hres = push_instr_bstr(ctx, OP_enter_catch, ident); + if(FAILED(hres)) + return hres; + hres = compile_statement(ctx, &catch_ctx, stat->catch_block->statement); if(FAILED(hres)) return hres; diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 90e6f8f8659..4aee171f5b4 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -968,6 +968,26 @@ static HRESULT interp_end_finally(script_ctx_t *ctx) return S_OK; } +static HRESULT interp_enter_catch(script_ctx_t *ctx) +{ + const BSTR ident = get_op_bstr(ctx, 0); + jsdisp_t *scope_obj; + jsval_t v; + HRESULT hres; + + hres = create_dispex(ctx, NULL, NULL, &scope_obj); + if(FAILED(hres)) + return hres; + + v = stack_pop(ctx); + hres = jsdisp_propput_name(scope_obj, ident, v); + jsval_release(v); + if(SUCCEEDED(hres)) + hres = scope_push(ctx->call_ctx->scope, scope_obj, to_disp(scope_obj), &ctx->call_ctx->scope); + jsdisp_release(scope_obj); + return hres; +} + /* ECMA-262 3rd Edition 13 */ static HRESULT interp_func(script_ctx_t *ctx) { @@ -2655,6 +2675,7 @@ static HRESULT unwind_exception(script_ctx_t *ctx, HRESULT exception_hres) } except_frame = frame->except_frame; + ident = except_frame->ident; frame->except_frame = except_frame->next; assert(except_frame->stack_top <= ctx->stack_top); @@ -2664,37 +2685,20 @@ static HRESULT unwind_exception(script_ctx_t *ctx, HRESULT exception_hres) scope_pop(&frame->scope); frame->ip = except_frame->catch_off; + if(ident) assert(frame->bytecode->instrs[frame->ip].op == OP_enter_catch); except_val = ctx->ei.val; ctx->ei.val = jsval_undefined(); clear_ei(ctx); - ident = except_frame->ident; heap_free(except_frame); - if(ident) { - jsdisp_t *scope_obj; - - hres = create_dispex(ctx, NULL, NULL, &scope_obj); - if(SUCCEEDED(hres)) { - hres = jsdisp_propput_name(scope_obj, ident, except_val); - if(FAILED(hres)) - jsdisp_release(scope_obj); - } - jsval_release(except_val); - if(FAILED(hres)) - return hres; - - hres = scope_push(frame->scope, scope_obj, to_disp(scope_obj), &frame->scope); - jsdisp_release(scope_obj); - }else { - hres = stack_push(ctx, except_val); - if(FAILED(hres)) - return hres; + hres = stack_push(ctx, except_val); + if(FAILED(hres)) + return hres; + if(!ident) hres = stack_push(ctx, jsval_bool(FALSE)); - } - return hres; } diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index f5b484b8860..bf745761c17 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -35,6 +35,7 @@ X(div, 1, 0,0) \ X(double, 1, ARG_DBL, 0) \ X(end_finally,1, 0,0) \ + X(enter_catch,1, ARG_BSTR, 0) \ X(eq, 1, 0,0) \ X(eq2, 1, 0,0) \ X(forin, 0, ARG_ADDR, 0) \