From ef78010df4975ccdd98c0f7496327505f39026c3 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 19 Sep 2008 00:44:11 +0200 Subject: [PATCH] jscript: Added '<<' expression implementation. --- dlls/jscript/engine.c | 28 ++++++++++++++++++++++++++-- dlls/jscript/jscript.h | 1 + dlls/jscript/jsutils.c | 14 ++++++++++++++ dlls/jscript/tests/lang.js | 6 ++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index b89d808291c..ae41df47382 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -2747,10 +2747,34 @@ HRESULT logical_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, D return return_bool(ret, !b); } +/* ECMA-262 3rd Edition 11.7.1 */ +static HRESULT lshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv) +{ + DWORD ri; + INT li; + HRESULT hres; + + hres = to_int32(ctx->parser->script, lval, ei, &li); + if(FAILED(hres)) + return hres; + + hres = to_uint32(ctx->parser->script, rval, ei, &ri); + if(FAILED(hres)) + return hres; + + V_VT(retv) = VT_I4; + V_I4(retv) = li << (ri&0x1f); + return S_OK; +} + +/* ECMA-262 3rd Edition 11.7.1 */ HRESULT left_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) { - FIXME("\n"); - return E_NOTIMPL; + binary_expression_t *expr = (binary_expression_t*)_expr; + + TRACE("\n"); + + return binary_expr_eval(ctx, expr, lshift_eval, ei, ret); } HRESULT right_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 776a2a38a05..603b27996ba 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -142,6 +142,7 @@ HRESULT to_boolean(VARIANT*,VARIANT_BOOL*); HRESULT to_number(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*); HRESULT to_integer(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*); HRESULT to_int32(script_ctx_t*,VARIANT*,jsexcept_t*,INT*); +HRESULT to_uint32(script_ctx_t*,VARIANT*,jsexcept_t*,DWORD*); HRESULT to_string(script_ctx_t*,VARIANT*,jsexcept_t*,BSTR*); HRESULT to_object(exec_ctx_t*,VARIANT*,IDispatch**); diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index 027b0778089..4913568218d 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -273,6 +273,20 @@ HRESULT to_int32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, INT *ret) return S_OK; } +/* ECMA-262 3rd Edition 9.6 */ +HRESULT to_uint32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, DWORD *ret) +{ + VARIANT num; + HRESULT hres; + + hres = to_number(ctx, v, ei, &num); + if(FAILED(hres)) + return hres; + + *ret = V_VT(&num) == VT_I4 ? V_I4(&num) : (DWORD)V_R8(&num); + return S_OK; +} + static BSTR int_to_bstr(INT i) { WCHAR buf[12], *p; diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index 9ad1cc38be0..c7a79d8a996 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -289,6 +289,12 @@ tmp = (-3.5) & 0xffffffff; ok(tmp === -3, "-3.5 & 0xffff !== -3"); ok(getVT(tmp) === "VT_I4", "getVT(3.5&0xffff) = " + getVT(tmp)); +tmp = 2 << 3; +ok(tmp === 16, "2 << 3 = " + tmp); + +tmp = 2 << 35; +ok(tmp === 16, "2 << 35 = " + tmp); + tmp = 10; ok((tmp &= 8) === 8, "tmp(10) &= 8 !== 8"); ok(getVT(tmp) === "VT_I4", "getVT(tmp &= 8) = " + getVT(tmp)); -- 2.11.4.GIT