From 23ccc9a293c6261e035a29f211970bf7c4a37fc5 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 10 Sep 2008 21:11:15 +0200 Subject: [PATCH] jscript: Added conditional expression implementation. --- dlls/jscript/engine.c | 22 +++++++++++++++++++--- dlls/jscript/tests/lang.js | 3 +++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index e19a0bbc1ec..ba3f9b0306b 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -781,10 +781,26 @@ HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD fla return S_OK; } -HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) +/* ECMA-262 3rd Edition 11.12 */ +HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret) { - FIXME("\n"); - return E_NOTIMPL; + conditional_expression_t *expr = (conditional_expression_t*)_expr; + exprval_t exprval; + VARIANT_BOOL b; + HRESULT hres; + + TRACE("\n"); + + hres = expr_eval(ctx, expr->expression, 0, ei, &exprval); + if(FAILED(hres)) + return hres; + + hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b); + exprval_release(&exprval); + if(FAILED(hres)) + return hres; + + return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret); } /* ECMA-262 3rd Edition 11.2.1 */ diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index 76caceeacb4..70964012047 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -150,4 +150,7 @@ ok(obj3.prop2 === "boolean", "obj3.prop2 is not \"boolean\""); } ok(blockVar === 2, "blockVar !== 2"); +ok((true ? 1 : 2) === 1, "conditional expression true is not 1"); +ok((0 === 2 ? 1 : 2) === 2, "conditional expression true is not 2"); + reportSuccess(); -- 2.11.4.GIT