Jacek Caban : jscript: Use bytecode for binary negation implementation.

Alexandre Julliard julliard at winehq.org
Mon Nov 21 11:10:15 CST 2011


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Nov 21 15:35:15 2011 +0100

jscript: Use bytecode for binary negation implementation.

---

 dlls/jscript/compile.c     |    2 ++
 dlls/jscript/engine.c      |   26 ++++++++------------------
 dlls/jscript/engine.h      |    2 +-
 dlls/jscript/parser.y      |    2 +-
 dlls/jscript/tests/lang.js |    5 +++++
 5 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index b51f68f..8431b5c 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -107,6 +107,8 @@ static HRESULT compile_interp_fallback(compiler_ctx_t *ctx, expression_t *expr)
 static HRESULT compile_expression(compiler_ctx_t *ctx, expression_t *expr)
 {
     switch(expr->type) {
+    case EXPR_BITNEG:
+        return compile_unary_expression(ctx, (unary_expression_t*)expr, OP_bneg);
     case EXPR_EQEQ:
         return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_eq2);
     case EXPR_LOGNEG:
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 29fb64b..17d8fa6 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -3020,33 +3020,23 @@ HRESULT greatereq_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD
 }
 
 /* ECMA-262 3rd Edition    11.4.8 */
-HRESULT binary_negation_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
+HRESULT interp_bneg(exec_ctx_t *ctx)
 {
-    unary_expression_t *expr = (unary_expression_t*)_expr;
-    exprval_t exprval;
-    VARIANT val;
+    VARIANT *v, r;
     INT i;
     HRESULT hres;
 
     TRACE("\n");
 
-    hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
-    if(FAILED(hres))
-        return hres;
-
-    hres = exprval_to_value(ctx, &exprval, ei, &val);
-    exprval_release(&exprval);
-    if(FAILED(hres))
-        return hres;
-
-    hres = to_int32(ctx, &val, ei, &i);
+    v = stack_pop(ctx);
+    hres = to_int32(ctx->parser->script, v, &ctx->ei, &i);
+    VariantClear(v);
     if(FAILED(hres))
         return hres;
 
-    ret->type = EXPRVAL_VARIANT;
-    V_VT(&ret->u.var) = VT_I4;
-    V_I4(&ret->u.var) = ~i;
-    return S_OK;
+    V_VT(&r) = VT_I4;
+    V_I4(&r) = ~i;
+    return stack_push(ctx, &r);
 }
 
 /* ECMA-262 3rd Edition    11.4.9 */
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 55c29e8..8692b0a 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -42,6 +42,7 @@ typedef struct _func_stack {
 } func_stack_t;
 
 #define OP_LIST                                   \
+    X(bneg, 1, 0)                                 \
     X(eq2, 1, 0)                                  \
     X(neg, 1, 0)                                  \
     X(neq2, 1, 0)                                 \
@@ -547,7 +548,6 @@ HRESULT less_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprv
 HRESULT lesseq_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT greater_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 HRESULT greatereq_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
-HRESULT binary_negation_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
 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;
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index fd294bd..d580ec0 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -1335,7 +1335,7 @@ static const expression_eval_t expression_eval_table[] = {
    lesseq_expression_eval,
    greater_expression_eval,
    greatereq_expression_eval,
-   binary_negation_expression_eval,
+   compiled_expression_eval,
    compiled_expression_eval,
    left_shift_expression_eval,
    right_shift_expression_eval,
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index 92eb642..7cd20dd 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -210,6 +210,11 @@ for(var iter in pureDisp)
 
 tmp = new Object();
 ok(!tmp.nonexistent, "!tmp.nonexistent = " + !tmp.nonexistent);
+ok(!("nonexistent" in tmp), "nonexistent is in tmp after '!' expression")
+
+tmp = new Object();
+ok((~tmp.nonexistent) === -1, "!tmp.nonexistent = " + ~tmp.nonexistent);
+ok(!("nonexistent" in tmp), "nonexistent is in tmp after '~' expression")
 
 tmp = 0;
 if(true)




More information about the wine-cvs mailing list