engine.c 77.5 KB
Newer Older
Jacek Caban's avatar
Jacek Caban committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright 2008 Jacek Caban for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

19 20 21
#include "config.h"
#include "wine/port.h"

22 23
#include <math.h>

Jacek Caban's avatar
Jacek Caban committed
24 25 26 27 28 29 30
#include "jscript.h"
#include "engine.h"

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(jscript);

31 32 33 34
#define EXPR_NOVAL   0x0001
#define EXPR_NEWREF  0x0002
#define EXPR_STRREF  0x0004

35 36 37 38 39
static inline HRESULT stat_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
{
    return stat->eval(ctx, stat, rt, ret);
}

40 41 42 43 44 45 46 47 48
static inline HRESULT expr_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    return _expr->eval(ctx, _expr, flags, ei, ret);
}

static void exprval_release(exprval_t *val)
{
    switch(val->type) {
    case EXPRVAL_VARIANT:
49 50
        if(V_VT(&val->u.var) != VT_EMPTY)
            VariantClear(&val->u.var);
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        return;
    case EXPRVAL_IDREF:
        if(val->u.idref.disp)
            IDispatch_Release(val->u.idref.disp);
        return;
    case EXPRVAL_NAMEREF:
        if(val->u.nameref.disp)
            IDispatch_Release(val->u.nameref.disp);
        SysFreeString(val->u.nameref.name);
    }
}

/* ECMA-262 3rd Edition    8.7.1 */
static HRESULT exprval_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
{
    V_VT(ret) = VT_EMPTY;

    switch(val->type) {
    case EXPRVAL_VARIANT:
        return VariantCopy(ret, &val->u.var);
    case EXPRVAL_IDREF:
        if(!val->u.idref.disp) {
            FIXME("throw ReferenceError\n");
            return E_FAIL;
        }

        return disp_propget(val->u.idref.disp, val->u.idref.id, ctx->lcid, ret, ei, NULL/*FIXME*/);
    default:
        ERR("type %d\n", val->type);
        return E_FAIL;
    }
}

static HRESULT exprval_to_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
{
    if(val->type == EXPRVAL_VARIANT) {
        *ret = val->u.var;
        V_VT(&val->u.var) = VT_EMPTY;
        return S_OK;
    }

    return exprval_value(ctx, val, ei, ret);
}

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
static HRESULT exprval_to_boolean(script_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, VARIANT_BOOL *b)
{
    if(exprval->type != EXPRVAL_VARIANT) {
        VARIANT val;
        HRESULT hres;

        hres = exprval_to_value(ctx, exprval, ei, &val);
        if(FAILED(hres))
            return hres;

        hres = to_boolean(&val, b);
        VariantClear(&val);
        return hres;
    }

    return to_boolean(&exprval->u.var, b);
}

113 114 115 116 117 118
static void exprval_init(exprval_t *val)
{
    val->type = EXPRVAL_VARIANT;
    V_VT(&val->u.var) = VT_EMPTY;
}

119 120 121 122 123 124 125 126 127 128
static void exprval_set_idref(exprval_t *val, IDispatch *disp, DISPID id)
{
    val->type = EXPRVAL_IDREF;
    val->u.idref.disp = disp;
    val->u.idref.id = id;

    if(disp)
        IDispatch_AddRef(disp);
}

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
HRESULT scope_push(scope_chain_t *scope, DispatchEx *obj, scope_chain_t **ret)
{
    scope_chain_t *new_scope;

    new_scope = heap_alloc(sizeof(scope_chain_t));
    if(!new_scope)
        return E_OUTOFMEMORY;

    new_scope->ref = 1;

    IDispatchEx_AddRef(_IDispatchEx_(obj));
    new_scope->obj = obj;

    if(scope) {
        scope_addref(scope);
        new_scope->next = scope;
    }else {
        new_scope->next = NULL;
    }

    *ret = new_scope;
    return S_OK;
}

153 154 155 156 157 158 159 160 161
static void scope_pop(scope_chain_t **scope)
{
    scope_chain_t *tmp;

    tmp = *scope;
    *scope = tmp->next;
    scope_release(tmp);
}

162 163 164 165 166 167 168 169 170 171 172 173
void scope_release(scope_chain_t *scope)
{
    if(--scope->ref)
        return;

    if(scope->next)
        scope_release(scope->next);

    IDispatchEx_Release(_IDispatchEx_(scope->obj));
    heap_free(scope);
}

174
HRESULT create_exec_ctx(IDispatch *this_obj, DispatchEx *var_disp, scope_chain_t *scope, exec_ctx_t **ret)
175 176 177 178 179 180 181
{
    exec_ctx_t *ctx;

    ctx = heap_alloc_zero(sizeof(exec_ctx_t));
    if(!ctx)
        return E_OUTOFMEMORY;

182 183 184
    IDispatch_AddRef(this_obj);
    ctx->this_obj = this_obj;

185 186 187
    IDispatchEx_AddRef(_IDispatchEx_(var_disp));
    ctx->var_disp = var_disp;

188 189 190 191 192
    if(scope) {
        scope_addref(scope);
        ctx->scope_chain = scope;
    }

193 194 195 196 197 198 199 200 201
    *ret = ctx;
    return S_OK;
}

void exec_release(exec_ctx_t *ctx)
{
    if(--ctx->ref)
        return;

202 203
    if(ctx->scope_chain)
        scope_release(ctx->scope_chain);
204 205
    if(ctx->var_disp)
        IDispatchEx_Release(_IDispatchEx_(ctx->var_disp));
206 207
    if(ctx->this_obj)
        IDispatch_Release(ctx->this_obj);
208 209 210
    heap_free(ctx);
}

211 212 213 214 215 216 217 218 219 220 221 222 223
static HRESULT disp_get_id(IDispatch *disp, BSTR name, DWORD flags, DISPID *id)
{
    IDispatchEx *dispex;
    HRESULT hres;

    hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
    if(FAILED(hres)) {
        TRACE("unsing IDispatch\n");

        *id = 0;
        return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
    }

224 225
    *id = 0;
    hres = IDispatchEx_GetDispID(dispex, name, flags|fdexNameCaseSensitive, id);
226 227 228 229
    IDispatchEx_Release(dispex);
    return hres;
}

230 231 232 233 234 235 236 237 238 239 240
/* ECMA-262 3rd Edition    8.7.2 */
static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei)
{
    if(ref->type != EXPRVAL_IDREF) {
        FIXME("throw ReferemceError\n");
        return E_FAIL;
    }

    return disp_propput(ref->u.idref.disp, ref->u.idref.id, ctx->lcid, v, ei, NULL/*FIXME*/);
}

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, BOOL *ret)
{
    IObjectIdentity *identity;
    IUnknown *unk1, *unk2;
    HRESULT hres;

    if(disp1 == disp2) {
        *ret = TRUE;
        return S_OK;
    }

    hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
    if(FAILED(hres))
        return hres;

    hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
    if(FAILED(hres)) {
        IUnknown_Release(unk1);
        return hres;
    }

    if(unk1 == unk2) {
        *ret = TRUE;
    }else {
        hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
        if(SUCCEEDED(hres)) {
            hres = IObjectIdentity_IsEqualObject(identity, unk2);
            IObjectIdentity_Release(identity);
            *ret = hres == S_OK;
        }else {
            *ret = FALSE;
        }
    }

    IUnknown_Release(unk1);
    IUnknown_Release(unk2);
    return S_OK;
}

/* ECMA-262 3rd Edition    11.9.6 */
HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
{
    TRACE("\n");

    if(V_VT(lval) != V_VT(rval)) {
        if(is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))) {
            *ret = num_val(lval) == num_val(rval);
            return S_OK;
        }

        *ret = FALSE;
        return S_OK;
    }

    switch(V_VT(lval)) {
    case VT_EMPTY:
    case VT_NULL:
        *ret = VARIANT_TRUE;
        break;
    case VT_I4:
        *ret = V_I4(lval) == V_I4(rval);
        break;
    case VT_R8:
        *ret = V_R8(lval) == V_R8(rval);
        break;
    case VT_BSTR:
        *ret = !strcmpW(V_BSTR(lval), V_BSTR(rval));
        break;
    case VT_DISPATCH:
        return disp_cmp(V_DISPATCH(lval), V_DISPATCH(rval), ret);
    case VT_BOOL:
        *ret = !V_BOOL(lval) == !V_BOOL(rval);
        break;
    default:
        FIXME("unimplemented vt %d\n", V_VT(lval));
        return E_NOTIMPL;
    }

    return S_OK;
}

322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
static HRESULT literal_to_var(literal_t *literal, VARIANT *v)
{
    V_VT(v) = literal->vt;

    switch(V_VT(v)) {
    case VT_EMPTY:
    case VT_NULL:
        break;
    case VT_I4:
        V_I4(v) = literal->u.lval;
        break;
    case VT_R8:
        V_R8(v) = literal->u.dval;
        break;
    case VT_BSTR:
        V_BSTR(v) = SysAllocString(literal->u.wstr);
        break;
    case VT_BOOL:
        V_BOOL(v) = literal->u.bval;
        break;
    case VT_DISPATCH:
        IDispatch_AddRef(literal->u.disp);
        V_DISPATCH(v) = literal->u.disp;
        break;
    default:
        ERR("wrong type %d\n", V_VT(v));
        return E_NOTIMPL;
    }

    return S_OK;
}

354 355 356
HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, jsexcept_t *ei, VARIANT *retv)
{
    script_ctx_t *script = parser->script;
357
    function_declaration_t *func;
358
    parser_ctx_t *prev_parser;
359
    var_list_t *var;
360 361 362 363 364 365
    VARIANT val, tmp;
    statement_t *stat;
    exec_ctx_t *prev_ctx;
    return_type_t rt;
    HRESULT hres = S_OK;

366 367 368 369
    for(func = source->functions; func; func = func->next) {
        DispatchEx *func_obj;
        VARIANT var;

370 371
        hres = create_source_function(parser, func->expr->parameter_list, func->expr->source_elements,
                ctx->scope_chain, func->expr->src_str, func->expr->src_len, &func_obj);
372 373 374 375 376
        if(FAILED(hres))
            return hres;

        V_VT(&var) = VT_DISPATCH;
        V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(func_obj);
377
        hres = jsdisp_propput_name(ctx->var_disp, func->expr->identifier, script->lcid, &var, ei, NULL);
378 379 380 381 382 383 384 385 386
        jsdisp_release(func_obj);
        if(FAILED(hres))
            return hres;
    }

    for(var = source->variables; var; var = var->next) {
        DISPID id = 0;

        hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
387 388 389 390
        if(FAILED(hres))
            return hres;
    }

391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    prev_ctx = script->exec_ctx;
    script->exec_ctx = ctx;

    prev_parser = ctx->parser;
    ctx->parser = parser;

    V_VT(&val) = VT_EMPTY;
    memset(&rt, 0, sizeof(rt));
    rt.type = RT_NORMAL;

    for(stat = source->statement; stat; stat = stat->next) {
        hres = stat_eval(ctx, stat, &rt, &tmp);
        if(FAILED(hres))
            break;

        VariantClear(&val);
        val = tmp;
        if(rt.type != RT_NORMAL)
            break;
    }

    script->exec_ctx = prev_ctx;
    ctx->parser = prev_parser;

    if(rt.type != RT_NORMAL && rt.type != RT_RETURN) {
        FIXME("wrong rt %d\n", rt.type);
        hres = E_FAIL;
    }

    *ei = rt.ei;
    if(FAILED(hres)) {
        VariantClear(&val);
        return hres;
    }

    if(retv)
        *retv = val;
    else
        VariantClear(&val);
    return S_OK;
}

433 434 435
/* ECMA-262 3rd Edition    10.1.4 */
static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, exprval_t *ret)
{
436
    scope_chain_t *scope;
437
    named_item_t *item;
438 439 440 441 442
    DISPID id = 0;
    HRESULT hres;

    TRACE("%s\n", debugstr_w(identifier));

443
    for(scope = ctx->scope_chain; scope; scope = scope->next) {
444
        hres = jsdisp_get_id(scope->obj, identifier, 0, &id);
445 446 447 448 449 450 451 452
        if(SUCCEEDED(hres))
            break;
    }

    if(scope) {
        exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(scope->obj), id);
        return S_OK;
    }
453

454
    hres = jsdisp_get_id(ctx->parser->script->global, identifier, 0, &id);
455 456 457 458
    if(SUCCEEDED(hres)) {
        exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->global), id);
        return S_OK;
    }
459

460 461 462 463 464 465 466 467 468 469
    for(item = ctx->parser->script->named_items; item; item = item->next) {
        if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpW(item->name, identifier)) {
            ret->type = EXPRVAL_VARIANT;
            V_VT(&ret->u.var) = VT_DISPATCH;
            V_DISPATCH(&ret->u.var) = item->disp;
            IDispatch_AddRef(item->disp);
            return S_OK;
        }
    }

470 471 472 473 474 475 476 477 478 479
    for(item = ctx->parser->script->named_items; item; item = item->next) {
        hres = disp_get_id(item->disp, identifier, 0, &id);
        if(SUCCEEDED(hres))
            break;
    }

    if(item) {
        exprval_set_idref(ret, (IDispatch*)item->disp, id);
        return S_OK;
    }
480

481
    hres = jsdisp_get_id(ctx->parser->script->script_disp, identifier, 0, &id);
482 483 484 485 486 487
    if(SUCCEEDED(hres)) {
        exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->script_disp), id);
        return S_OK;
    }

    if(flags & EXPR_NEWREF) {
488
        hres = jsdisp_get_id(ctx->var_disp, identifier, fdexNameEnsure, &id);
489 490 491 492 493
        if(FAILED(hres))
            return hres;

        exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->var_disp), id);
        return S_OK;
494 495 496 497 498 499
    }

    WARN("Could not find identifier %s\n", debugstr_w(identifier));
    return E_FAIL;
}

500 501
/* ECMA-262 3rd Edition    12.1 */
HRESULT block_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
502
{
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
    block_statement_t *stat = (block_statement_t*)_stat;
    VARIANT val, tmp;
    statement_t *iter;
    HRESULT hres = S_OK;

    TRACE("\n");

    V_VT(&val) = VT_EMPTY;
    for(iter = stat->stat_list; iter; iter = iter->next) {
        hres = stat_eval(ctx, iter, rt, &tmp);
        if(FAILED(hres))
            break;

        VariantClear(&val);
        val = tmp;
        if(rt->type != RT_NORMAL)
            break;
    }

    if(FAILED(hres)) {
        VariantClear(&val);
        return hres;
    }

    *ret = val;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
529 530
}

531 532
/* ECMA-262 3rd Edition    12.2 */
static HRESULT variable_list_eval(exec_ctx_t *ctx, variable_declaration_t *var_list, jsexcept_t *ei)
Jacek Caban's avatar
Jacek Caban committed
533
{
534
    variable_declaration_t *iter;
535
    HRESULT hres = S_OK;
536 537

    for(iter = var_list; iter; iter = iter->next) {
538
        exprval_t exprval;
539 540
        VARIANT val;

541 542
        if(!iter->expr)
            continue;
543

544 545 546
        hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
        if(FAILED(hres))
            break;
547

548 549 550 551
        hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
        exprval_release(&exprval);
        if(FAILED(hres))
            break;
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575

        hres = jsdisp_propput_name(ctx->var_disp, iter->identifier, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
        VariantClear(&val);
        if(FAILED(hres))
            break;
    }

    return hres;
}

/* ECMA-262 3rd Edition    12.2 */
HRESULT var_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
{
    var_statement_t *stat = (var_statement_t*)_stat;
    HRESULT hres;

    TRACE("\n");

    hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
    if(FAILED(hres))
        return hres;

    V_VT(ret) = VT_EMPTY;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
576 577
}

578
/* ECMA-262 3rd Edition    12.3 */
Jacek Caban's avatar
Jacek Caban committed
579 580
HRESULT empty_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
{
581 582 583 584
    TRACE("\n");

    V_VT(ret) = VT_EMPTY;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
585 586
}

587 588
/* ECMA-262 3rd Edition    12.4 */
HRESULT expression_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
589
{
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
    expression_statement_t *stat = (expression_statement_t*)_stat;
    exprval_t exprval;
    VARIANT val;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, stat->expr, EXPR_NOVAL, &rt->ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    *ret = val;
    TRACE("= %s\n", debugstr_variant(ret));
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
609 610
}

611 612
/* ECMA-262 3rd Edition    12.5 */
HRESULT if_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
613
{
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
    if_statement_t *stat = (if_statement_t*)_stat;
    exprval_t exprval;
    VARIANT_BOOL b;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    if(b)
        hres = stat_eval(ctx, stat->if_stat, rt, ret);
    else if(stat->else_stat)
        hres = stat_eval(ctx, stat->else_stat, rt, ret);
    else
        V_VT(ret) = VT_EMPTY;

    return hres;
Jacek Caban's avatar
Jacek Caban committed
638 639
}

640 641
/* ECMA-262 3rd Edition    12.6.2 */
HRESULT while_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
642
{
643 644 645 646 647 648
    while_statement_t *stat = (while_statement_t*)_stat;
    exprval_t exprval;
    VARIANT val, tmp;
    VARIANT_BOOL b;
    BOOL test_expr;
    HRESULT hres;
Jacek Caban's avatar
Jacek Caban committed
649

650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
    TRACE("\n");

    V_VT(&val) = VT_EMPTY;
    test_expr = !stat->do_while;

    while(1) {
        if(test_expr) {
            hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
            if(FAILED(hres))
                break;

            hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
            exprval_release(&exprval);
            if(FAILED(hres) || !b)
                break;
        }else {
            test_expr = TRUE;
        }

        hres = stat_eval(ctx, stat->statement, rt, &tmp);
        if(FAILED(hres))
            break;

        VariantClear(&val);
        val = tmp;

        if(rt->type == RT_CONTINUE)
            rt->type = RT_NORMAL;
        if(rt->type != RT_NORMAL)
            break;
    }

    if(FAILED(hres)) {
        VariantClear(&val);
        return hres;
    }

    if(rt->type == RT_BREAK)
        rt->type = RT_NORMAL;

    *ret = val;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
692 693
}

694 695
/* ECMA-262 3rd Edition    12.6.3 */
HRESULT for_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
696
{
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
    for_statement_t *stat = (for_statement_t*)_stat;
    VARIANT val, tmp, retv;
    exprval_t exprval;
    VARIANT_BOOL b;
    HRESULT hres;

    TRACE("\n");

    if(stat->variable_list) {
        hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
        if(FAILED(hres))
            return hres;
    }else if(stat->begin_expr) {
        hres = expr_eval(ctx, stat->begin_expr, EXPR_NEWREF, &rt->ei, &exprval);
        if(FAILED(hres))
            return hres;

        hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
        exprval_release(&exprval);
        if(FAILED(hres))
            return hres;

        VariantClear(&val);
    }

    V_VT(&retv) = VT_EMPTY;

    while(1) {
        if(stat->expr) {
            hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
            if(FAILED(hres))
                break;

            hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
            exprval_release(&exprval);
            if(FAILED(hres) || !b)
                break;
        }

        hres = stat_eval(ctx, stat->statement, rt, &tmp);
        if(FAILED(hres))
            break;

        VariantClear(&retv);
        retv = tmp;

        if(rt->type == RT_CONTINUE)
            rt->type = RT_NORMAL;
        else if(rt->type != RT_NORMAL)
            break;

        if(stat->end_expr) {
            hres = expr_eval(ctx, stat->end_expr, 0, &rt->ei, &exprval);
            if(FAILED(hres))
                break;

            hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
            exprval_release(&exprval);
            if(FAILED(hres))
                break;

            VariantClear(&val);
        }
    }

    if(FAILED(hres)) {
        VariantClear(&retv);
        return hres;
    }

    if(rt->type == RT_BREAK)
        rt->type = RT_NORMAL;

    *ret = retv;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
772 773
}

774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802
/* ECMA-262 3rd Edition    12.6.4 */
HRESULT forin_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
{
    forin_statement_t *stat = (forin_statement_t*)_stat;
    VARIANT val, name, retv, tmp;
    DISPID id = DISPID_STARTENUM;
    BSTR str, identifier = NULL;
    IDispatchEx *in_obj;
    exprval_t exprval;
    HRESULT hres;

    TRACE("\n");

    if(stat->variable) {
        hres = variable_list_eval(ctx, stat->variable, &rt->ei);
        if(FAILED(hres))
            return hres;
    }

    hres = expr_eval(ctx, stat->in_expr, EXPR_NEWREF, &rt->ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    if(V_VT(&val) != VT_DISPATCH) {
803
        TRACE("in vt %d\n", V_VT(&val));
804
        VariantClear(&val);
805 806
        V_VT(ret) = VT_EMPTY;
        return S_OK;
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
    }

    hres = IDispatch_QueryInterface(V_DISPATCH(&val), &IID_IDispatchEx, (void**)&in_obj);
    IDispatch_Release(V_DISPATCH(&val));
    if(FAILED(hres)) {
        FIXME("Object doesn't support IDispatchEx\n");
        return E_NOTIMPL;
    }

    V_VT(&retv) = VT_EMPTY;

    if(stat->variable)
        identifier = SysAllocString(stat->variable->identifier);

    while(1) {
        hres = IDispatchEx_GetNextDispID(in_obj, fdexEnumDefault, id, &id);
        if(FAILED(hres) || hres == S_FALSE)
            break;

        hres = IDispatchEx_GetMemberName(in_obj, id, &str);
        if(FAILED(hres))
            break;

        TRACE("iter %s\n", debugstr_w(str));

        if(stat->variable)
            hres = identifier_eval(ctx, identifier, 0, &exprval);
        else
            hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval);
        if(SUCCEEDED(hres)) {
            V_VT(&name) = VT_BSTR;
            V_BSTR(&name) = str;
            hres = put_value(ctx->parser->script, &exprval, &name, &rt->ei);
            exprval_release(&exprval);
        }
        SysFreeString(str);
        if(FAILED(hres))
            break;

        hres = stat_eval(ctx, stat->statement, rt, &tmp);
        if(FAILED(hres))
            break;

        VariantClear(&retv);
        retv = tmp;

        if(rt->type == RT_CONTINUE)
            rt->type = RT_NORMAL;
        else if(rt->type != RT_NORMAL)
            break;
    }

    SysFreeString(identifier);
    IDispatchEx_Release(in_obj);
    if(FAILED(hres)) {
        VariantClear(&retv);
        return hres;
    }

    if(rt->type == RT_BREAK)
        rt->type = RT_NORMAL;

    *ret = retv;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
871 872
}

873 874
/* ECMA-262 3rd Edition    12.7 */
HRESULT continue_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
875
{
876 877 878 879 880 881 882 883 884 885 886 887
    branch_statement_t *stat = (branch_statement_t*)_stat;

    TRACE("\n");

    if(stat->identifier) {
        FIXME("indentifier not implemented\n");
        return E_NOTIMPL;
    }

    rt->type = RT_CONTINUE;
    V_VT(ret) = VT_EMPTY;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
888 889
}

890 891
/* ECMA-262 3rd Edition    12.8 */
HRESULT break_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
892
{
893 894 895 896 897 898 899 900 901 902 903 904
    branch_statement_t *stat = (branch_statement_t*)_stat;

    TRACE("\n");

    if(stat->identifier) {
        FIXME("indentifier not implemented\n");
        return E_NOTIMPL;
    }

    rt->type = RT_BREAK;
    V_VT(ret) = VT_EMPTY;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
905 906
}

907 908
/* ECMA-262 3rd Edition    12.9 */
HRESULT return_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
909
{
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
    expression_statement_t *stat = (expression_statement_t*)_stat;
    HRESULT hres;

    TRACE("\n");

    if(stat->expr) {
        exprval_t exprval;

        hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
        if(FAILED(hres))
            return hres;

        hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, ret);
        exprval_release(&exprval);
        if(FAILED(hres))
            return hres;
    }else {
        V_VT(ret) = VT_EMPTY;
    }

    TRACE("= %s\n", debugstr_variant(ret));
    rt->type = RT_RETURN;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
933 934
}

935 936
/* ECMA-262 3rd Edition    12.10 */
HRESULT with_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
937
{
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
    with_statement_t *stat = (with_statement_t*)_stat;
    exprval_t exprval;
    IDispatch *disp;
    DispatchEx *obj;
    VARIANT val;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    hres = to_object(ctx, &val, &disp);
    VariantClear(&val);
    if(FAILED(hres))
        return hres;

    obj = iface_to_jsdisp((IUnknown*)disp);
    IDispatch_Release(disp);
    if(!obj) {
        FIXME("disp id not jsdisp\n");
        return E_NOTIMPL;
    }

    hres = scope_push(ctx->scope_chain, obj, &ctx->scope_chain);
    jsdisp_release(obj);
Jacek Caban's avatar
Jacek Caban committed
970 971
    if(FAILED(hres))
        return hres;
972 973 974 975 976

    hres = stat_eval(ctx, stat->statement, rt, ret);

    scope_pop(&ctx->scope_chain);
    return hres;
Jacek Caban's avatar
Jacek Caban committed
977 978
}

979
/* ECMA-262 3rd Edition    12.12 */
Jacek Caban's avatar
Jacek Caban committed
980 981 982 983 984 985
HRESULT labelled_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
{
    FIXME("\n");
    return E_NOTIMPL;
}

986 987
/* ECMA-262 3rd Edition    12.13 */
HRESULT switch_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
988
{
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
    switch_statement_t *stat = (switch_statement_t*)_stat;
    case_clausule_t *iter, *default_clausule = NULL;
    statement_t *stat_iter;
    VARIANT val, cval;
    exprval_t exprval;
    BOOL b;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    for(iter = stat->case_list; iter; iter = iter->next) {
        if(!iter->expr) {
            default_clausule = iter;
            continue;
        }

        hres = expr_eval(ctx, iter->expr, 0, &rt->ei, &exprval);
        if(FAILED(hres))
            break;

        hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &cval);
        exprval_release(&exprval);
        if(FAILED(hres))
            break;

        hres = equal2_values(&val, &cval, &b);
        VariantClear(&cval);
        if(FAILED(hres) || b)
            break;
    }

    VariantClear(&val);
    if(FAILED(hres))
        return hres;

    if(!iter)
        iter = default_clausule;

    V_VT(&val) = VT_EMPTY;
    if(iter) {
        VARIANT tmp;

        for(stat_iter = iter->stat; stat_iter; stat_iter = stat_iter->next) {
            hres = stat_eval(ctx, stat_iter, rt, &tmp);
            if(FAILED(hres))
                break;

            VariantClear(&val);
            val = tmp;

            if(rt->type != RT_NORMAL)
                break;
        }
    }

    if(FAILED(hres)) {
        VariantClear(&val);
        return hres;
    }

    if(rt->type == RT_BREAK)
        rt->type = RT_NORMAL;

    *ret = val;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1063 1064
}

1065
/* ECMA-262 3rd Edition    12.13 */
1066
HRESULT throw_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
1067
{
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
    expression_statement_t *stat = (expression_statement_t*)_stat;
    exprval_t exprval;
    VARIANT val;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    rt->ei.var = val;
    return DISP_E_EXCEPTION;
Jacek Caban's avatar
Jacek Caban committed
1086 1087
}

1088 1089
/* ECMA-262 3rd Edition    12.14 */
static HRESULT catch_eval(exec_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
Jacek Caban's avatar
Jacek Caban committed
1090
{
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
    DispatchEx *var_disp;
    VARIANT ex, val;
    HRESULT hres;

    ex = rt->ei.var;
    memset(&rt->ei, 0, sizeof(jsexcept_t));

    hres = create_dispex(ctx->parser->script, NULL, NULL, &var_disp);
    if(SUCCEEDED(hres)) {
        hres = jsdisp_propput_name(var_disp, block->identifier, ctx->parser->script->lcid,
                &ex, &rt->ei, NULL/*FIXME*/);
        if(SUCCEEDED(hres)) {
            hres = scope_push(ctx->scope_chain, var_disp, &ctx->scope_chain);
            if(SUCCEEDED(hres)) {
                hres = stat_eval(ctx, block->statement, rt, &val);
                scope_pop(&ctx->scope_chain);
            }
        }

        jsdisp_release(var_disp);
    }

    VariantClear(&ex);
    if(FAILED(hres))
        return hres;

    *ret = val;
    return S_OK;
}

/* ECMA-262 3rd Edition    12.14 */
HRESULT try_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
{
    try_statement_t *stat = (try_statement_t*)_stat;
    VARIANT val;
    HRESULT hres;

    TRACE("\n");

    hres = stat_eval(ctx, stat->try_statement, rt, &val);
    if(FAILED(hres)) {
        TRACE("EXCEPTION\n");
        if(!stat->catch_block)
            return hres;

        hres = catch_eval(ctx, stat->catch_block, rt, &val);
        if(FAILED(hres))
            return hres;
    }

    if(stat->finally_statement) {
        VariantClear(&val);
        hres = stat_eval(ctx, stat->finally_statement, rt, &val);
        if(FAILED(hres))
            return hres;
    }

    *ret = val;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1150 1151
}

1152 1153 1154 1155 1156 1157 1158 1159 1160
static HRESULT return_bool(exprval_t *ret, DWORD b)
{
    ret->type = EXPRVAL_VARIANT;
    V_VT(&ret->u.var) = VT_BOOL;
    V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;

    return S_OK;
}

1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
static HRESULT get_binary_expr_values(exec_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
{
    exprval_t exprval;
    HRESULT hres;

    hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, lval);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
    if(SUCCEEDED(hres)) {
        hres = exprval_to_value(ctx->parser->script, &exprval, ei, rval);
        exprval_release(&exprval);
    }

    if(FAILED(hres)) {
        VariantClear(lval);
        return hres;
    }

    return S_OK;
}

1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
typedef HRESULT (*oper_t)(exec_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);

static HRESULT binary_expr_eval(exec_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
        exprval_t *ret)
{
    VARIANT lval, rval, retv;
    HRESULT hres;

    hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
    if(FAILED(hres))
        return hres;

    hres = oper(ctx, &lval, &rval, ei, &retv);
    VariantClear(&lval);
    VariantClear(&rval);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = retv;
    return S_OK;
}

1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252
/* ECMA-262 3rd Edition    11.13.2 */
static HRESULT assign_oper_eval(exec_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
                                jsexcept_t *ei, exprval_t *ret)
{
    VARIANT retv, lval, rval;
    exprval_t exprval, exprvalr;
    HRESULT hres;

    hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_value(ctx->parser->script, &exprval, ei, &lval);
    if(SUCCEEDED(hres)) {
        hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
        if(SUCCEEDED(hres)) {
            hres = exprval_value(ctx->parser->script, &exprvalr, ei, &rval);
            exprval_release(&exprvalr);
        }
        if(SUCCEEDED(hres)) {
            hres = oper(ctx, &lval, &rval, ei, &retv);
            VariantClear(&rval);
        }
        VariantClear(&lval);
    }

    if(SUCCEEDED(hres)) {
        hres = put_value(ctx->parser->script, &exprval, &retv, ei);
        if(FAILED(hres))
            VariantClear(&retv);
    }
    exprval_release(&exprval);

    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = retv;
    return S_OK;
}

1253 1254
/* ECMA-262 3rd Edition    13 */
HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1255
{
1256 1257 1258 1259 1260 1261 1262
    function_expression_t *expr = (function_expression_t*)_expr;
    VARIANT var;
    HRESULT hres;

    TRACE("\n");

    if(expr->identifier) {
1263 1264
        hres = jsdisp_propget_name(ctx->var_disp, expr->identifier, ctx->parser->script->lcid, &var, ei, NULL/*FIXME*/);
        if(FAILED(hres))
1265
            return hres;
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
    }else {
        DispatchEx *dispex;

        hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain,
                expr->src_str, expr->src_len, &dispex);
        if(FAILED(hres))
            return hres;

        V_VT(&var) = VT_DISPATCH;
        V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
1276 1277 1278 1279 1280
    }

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = var;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1281 1282
}

1283 1284
/* 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)
Jacek Caban's avatar
Jacek Caban committed
1285
{
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
    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);
Jacek Caban's avatar
Jacek Caban committed
1303 1304
}

1305 1306
/* ECMA-262 3rd Edition    11.2.1 */
HRESULT array_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1307
{
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
    array_expression_t *expr = (array_expression_t*)_expr;
    exprval_t exprval;
    VARIANT member, val;
    DISPID id;
    BSTR str;
    IDispatch *obj = NULL;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->member_expr, EXPR_NEWREF, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
    if(SUCCEEDED(hres)) {
        hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
        exprval_release(&exprval);
    }

    if(SUCCEEDED(hres))
        hres = to_object(ctx, &member, &obj);
    VariantClear(&member);
    if(SUCCEEDED(hres)) {
        hres = to_string(ctx->parser->script, &val, ei, &str);
        if(SUCCEEDED(hres)) {
            if(flags & EXPR_STRREF) {
                ret->type = EXPRVAL_NAMEREF;
                ret->u.nameref.disp = obj;
                ret->u.nameref.name = str;
                return S_OK;
            }

            hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
        }

        if(SUCCEEDED(hres)) {
            exprval_set_idref(ret, obj, id);
        }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
            exprval_init(ret);
            hres = S_OK;
        }

        IDispatch_Release(obj);
    }

    return hres;
Jacek Caban's avatar
Jacek Caban committed
1360 1361
}

1362 1363
/* ECMA-262 3rd Edition    11.2.1 */
HRESULT member_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1364
{
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
    member_expression_t *expr = (member_expression_t*)_expr;
    IDispatch *obj = NULL;
    exprval_t exprval;
    VARIANT member;
    DISPID id;
    BSTR str;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    hres = to_object(ctx, &member, &obj);
    VariantClear(&member);
    if(FAILED(hres))
        return hres;

    str = SysAllocString(expr->identifier);
    if(flags & EXPR_STRREF) {
        ret->type = EXPRVAL_NAMEREF;
        ret->u.nameref.disp = obj;
        ret->u.nameref.name = str;
        return S_OK;
    }

1397
    hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
    SysFreeString(str);
    if(SUCCEEDED(hres)) {
        exprval_set_idref(ret, obj, id);
    }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
        exprval_init(ret);
        hres = S_OK;
    }

    IDispatch_Release(obj);
    return hres;
Jacek Caban's avatar
Jacek Caban committed
1408 1409
}

1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
static void free_dp(DISPPARAMS *dp)
{
    DWORD i;

    for(i=0; i < dp->cArgs; i++)
        VariantClear(dp->rgvarg+i);
    heap_free(dp->rgvarg);
}

static HRESULT args_to_param(exec_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
{
    VARIANTARG *vargs;
    exprval_t exprval;
    argument_t *iter;
    DWORD cnt = 0, i;
    HRESULT hres = S_OK;

    memset(dp, 0, sizeof(*dp));
1428 1429
    if(!args)
        return S_OK;
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458

    for(iter = args; iter; iter = iter->next)
        cnt++;

    vargs = heap_alloc_zero(cnt * sizeof(*vargs));
    if(!vargs)
        return E_OUTOFMEMORY;

    for(i = cnt, iter = args; iter; iter = iter->next) {
        hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
        if(FAILED(hres))
            break;

        hres = exprval_to_value(ctx->parser->script, &exprval, ei, vargs + (--i));
        exprval_release(&exprval);
        if(FAILED(hres))
            break;
    }

    if(FAILED(hres)) {
        free_dp(dp);
        return hres;
    }

    dp->rgvarg = vargs;
    dp->cArgs = cnt;
    return S_OK;
}

1459
/* ECMA-262 3rd Edition    11.2.2 */
1460
HRESULT new_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1461
{
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
    call_expression_t *expr = (call_expression_t*)_expr;
    exprval_t exprval;
    VARIANT constr, var;
    DISPPARAMS dp;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = args_to_param(ctx, expr->argument_list, ei, &dp);
    if(SUCCEEDED(hres))
        hres = exprval_to_value(ctx->parser->script, &exprval, ei, &constr);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    if(V_VT(&constr) != VT_DISPATCH) {
        FIXME("throw TypeError\n");
        VariantClear(&constr);
        return E_FAIL;
    }

    hres = disp_call(V_DISPATCH(&constr), DISPID_VALUE, ctx->parser->script->lcid,
                     DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
    IDispatch_Release(V_DISPATCH(&constr));
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = var;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1496 1497
}

Jacek Caban's avatar
Jacek Caban committed
1498
/* ECMA-262 3rd Edition    11.2.3 */
1499
HRESULT call_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1500
{
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
    call_expression_t *expr = (call_expression_t*)_expr;
    VARIANT func, var;
    exprval_t exprval;
    DISPPARAMS dp;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = args_to_param(ctx, expr->argument_list, ei, &dp);
    if(SUCCEEDED(hres)) {
        switch(exprval.type) {
        case EXPRVAL_IDREF:
            hres = disp_call(exprval.u.idref.disp, exprval.u.idref.id, ctx->parser->script->lcid, DISPATCH_METHOD,
                    &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
            if(flags & EXPR_NOVAL)
                V_VT(&var) = VT_EMPTY;
            break;
        default:
            FIXME("unimplemented type %d\n", V_VT(&func));
            hres = E_NOTIMPL;
        }

        free_dp(&dp);
    }

    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    TRACE("= %s\n", debugstr_variant(&var));
    ret->type = EXPRVAL_VARIANT;
    ret->u.var = var;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1538 1539
}

Jacek Caban's avatar
Jacek Caban committed
1540
/* ECMA-262 3rd Edition    11.1.1 */
Jacek Caban's avatar
Jacek Caban committed
1541 1542
HRESULT this_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
1543 1544 1545 1546 1547 1548 1549
    TRACE("\n");

    ret->type = EXPRVAL_VARIANT;
    V_VT(&ret->u.var) = VT_DISPATCH;
    V_DISPATCH(&ret->u.var) = ctx->this_obj;
    IDispatch_AddRef(ctx->this_obj);
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1550 1551
}

1552 1553
/* ECMA-262 3rd Edition    10.1.4 */
HRESULT identifier_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1554
{
1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568
    identifier_expression_t *expr = (identifier_expression_t*)_expr;
    BSTR identifier;
    HRESULT hres;

    TRACE("\n");

    identifier = SysAllocString(expr->identifier);
    if(!identifier)
        return E_OUTOFMEMORY;

    hres = identifier_eval(ctx, identifier, flags, ret);

    SysFreeString(identifier);
    return hres;
Jacek Caban's avatar
Jacek Caban committed
1569 1570
}

1571 1572
/* ECMA-262 3rd Edition    7.8 */
HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1573
{
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
    literal_expression_t *expr = (literal_expression_t*)_expr;
    VARIANT var;
    HRESULT hres;

    TRACE("\n");

    hres = literal_to_var(expr->literal, &var);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = var;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1587 1588
}

1589 1590
/* ECMA-262 3rd Edition    11.1.4 */
HRESULT array_literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1591
{
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638
    array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
    DWORD length = 0, i = 0;
    array_element_t *elem;
    DispatchEx *array;
    exprval_t exprval;
    VARIANT val;
    HRESULT hres;

    TRACE("\n");

    for(elem = expr->element_list; elem; elem = elem->next)
        length += elem->elision+1;
    length += expr->length;

    hres = create_array(ctx->parser->script, length, &array);
    if(FAILED(hres))
        return hres;

    for(elem = expr->element_list; elem; elem = elem->next) {
        i += elem->elision;

        hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
        if(FAILED(hres))
            break;

        hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
        exprval_release(&exprval);
        if(FAILED(hres))
            break;

        hres = jsdisp_propput_idx(array, i, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
        VariantClear(&val);
        if(FAILED(hres))
            break;

        i++;
    }

    if(FAILED(hres)) {
        jsdisp_release(array);
        return hres;
    }

    ret->type = EXPRVAL_VARIANT;
    V_VT(&ret->u.var) = VT_DISPATCH;
    V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(array);
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1639 1640
}

1641 1642
/* ECMA-262 3rd Edition    11.1.5 */
HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1643
{
1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691
    property_value_expression_t *expr = (property_value_expression_t*)_expr;
    VARIANT val, tmp;
    DispatchEx *obj;
    prop_val_t *iter;
    exprval_t exprval;
    BSTR name;
    HRESULT hres;

    TRACE("\n");

    hres = create_object(ctx->parser->script, NULL, &obj);
    if(FAILED(hres))
        return hres;

    for(iter = expr->property_list; iter; iter = iter->next) {
        hres = literal_to_var(iter->name, &tmp);
        if(FAILED(hres))
            break;

        hres = to_string(ctx->parser->script, &tmp, ei, &name);
        VariantClear(&tmp);
        if(FAILED(hres))
            break;

        hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
        if(SUCCEEDED(hres)) {
            hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
            exprval_release(&exprval);
            if(SUCCEEDED(hres)) {
                hres = jsdisp_propput_name(obj, name, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
                VariantClear(&val);
            }
        }

        SysFreeString(name);
        if(FAILED(hres))
            break;
    }

    if(FAILED(hres)) {
        jsdisp_release(obj);
        return hres;
    }

    ret->type = EXPRVAL_VARIANT;
    V_VT(&ret->u.var) = VT_DISPATCH;
    V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(obj);
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1692 1693
}

1694 1695
/* ECMA-262 3rd Edition    11.14 */
HRESULT comma_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1696
{
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
    binary_expression_t *expr = (binary_expression_t*)_expr;
    VARIANT lval, rval;
    HRESULT hres;

    TRACE("\n");

    hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
    if(FAILED(hres))
        return hres;

    VariantClear(&lval);

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = rval;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1712 1713
}

1714 1715
/* ECMA-262 3rd Edition    11.11 */
HRESULT logical_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1716
{
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
    binary_expression_t *expr = (binary_expression_t*)_expr;
    exprval_t exprval;
    VARIANT_BOOL b;
    VARIANT val;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    hres = to_boolean(&val, &b);
    if(SUCCEEDED(hres) && b) {
        ret->type = EXPRVAL_VARIANT;
        ret->u.var = val;
        return S_OK;
    }

    VariantClear(&val);
    if(FAILED(hres))
        return hres;

    hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = val;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1757 1758
}

1759 1760
/* ECMA-262 3rd Edition    11.11 */
HRESULT logical_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
1761
{
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801
    binary_expression_t *expr = (binary_expression_t*)_expr;
    exprval_t exprval;
    VARIANT_BOOL b;
    VARIANT val;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    hres = to_boolean(&val, &b);
    if(SUCCEEDED(hres) && !b) {
        ret->type = EXPRVAL_VARIANT;
        ret->u.var = val;
        return S_OK;
    }

    VariantClear(&val);
    if(FAILED(hres))
        return hres;

    hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = val;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
1802 1803
}

1804 1805
/* ECMA-262 3rd Edition    11.10 */
static HRESULT bitor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
Jacek Caban's avatar
Jacek Caban committed
1806
{
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
    INT li, ri;
    HRESULT hres;

    hres = to_int32(ctx->parser->script, lval, ei, &li);
    if(FAILED(hres))
        return hres;

    hres = to_int32(ctx->parser->script, rval, ei, &ri);
    if(FAILED(hres))
        return hres;

    V_VT(retv) = VT_I4;
    V_I4(retv) = li|ri;
    return S_OK;
}

/* ECMA-262 3rd Edition    11.10 */
HRESULT binary_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
1831 1832
}

1833 1834
/* ECMA-262 3rd Edition    11.10 */
static HRESULT xor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
Jacek Caban's avatar
Jacek Caban committed
1835
{
1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
    INT li, ri;
    HRESULT hres;

    hres = to_int32(ctx->parser->script, lval, ei, &li);
    if(FAILED(hres))
        return hres;

    hres = to_int32(ctx->parser->script, rval, ei, &ri);
    if(FAILED(hres))
        return hres;

    V_VT(retv) = VT_I4;
    V_I4(retv) = li^ri;
    return S_OK;
}

/* ECMA-262 3rd Edition    11.10 */
HRESULT binary_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, xor_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
1860 1861
}

1862 1863
/* ECMA-262 3rd Edition    11.10 */
static HRESULT bitand_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
Jacek Caban's avatar
Jacek Caban committed
1864
{
1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
    INT li, ri;
    HRESULT hres;

    hres = to_int32(ctx->parser->script, lval, ei, &li);
    if(FAILED(hres))
        return hres;

    hres = to_int32(ctx->parser->script, rval, ei, &ri);
    if(FAILED(hres))
        return hres;

    V_VT(retv) = VT_I4;
    V_I4(retv) = li&ri;
    return S_OK;
}

/* ECMA-262 3rd Edition    11.10 */
HRESULT binary_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, bitand_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
1889 1890
}

Jacek Caban's avatar
Jacek Caban committed
1891
/* ECMA-262 3rd Edition    11.8.6 */
Jacek Caban's avatar
Jacek Caban committed
1892 1893 1894 1895 1896 1897
HRESULT instanceof_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    FIXME("\n");
    return E_NOTIMPL;
}

Jacek Caban's avatar
Jacek Caban committed
1898
/* ECMA-262 3rd Edition    11.8.7 */
Jacek Caban's avatar
Jacek Caban committed
1899 1900 1901 1902 1903 1904
HRESULT in_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    FIXME("\n");
    return E_NOTIMPL;
}

1905 1906
/* ECMA-262 3rd Edition    11.6.1 */
static HRESULT add_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
Jacek Caban's avatar
Jacek Caban committed
1907
{
1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947
    VARIANT r, l;
    HRESULT hres;

    hres = to_primitive(ctx->parser->script, lval, ei, &l);
    if(FAILED(hres))
        return hres;

    hres = to_primitive(ctx->parser->script, rval, ei, &r);
    if(FAILED(hres)) {
        VariantClear(&l);
        return hres;
    }

    if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
        BSTR lstr = NULL, rstr = NULL;

        if(V_VT(&l) == VT_BSTR)
            lstr = V_BSTR(&l);
        else
            hres = to_string(ctx->parser->script, &l, ei, &lstr);

        if(SUCCEEDED(hres)) {
            if(V_VT(&r) == VT_BSTR)
                rstr = V_BSTR(&r);
            else
                hres = to_string(ctx->parser->script, &r, ei, &rstr);
        }

        if(SUCCEEDED(hres)) {
            int len1, len2;

            len1 = SysStringLen(lstr);
            len2 = SysStringLen(rstr);

            V_VT(retv) = VT_BSTR;
            V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
            memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
            memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
        }

1948
        if(V_VT(&l) != VT_BSTR)
1949
            SysFreeString(lstr);
1950
        if(V_VT(&r) != VT_BSTR)
1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975
            SysFreeString(rstr);
    }else {
        VARIANT nl, nr;

        hres = to_number(ctx->parser->script, &l, ei, &nl);
        if(SUCCEEDED(hres)) {
            hres = to_number(ctx->parser->script, &r, ei, &nr);
            if(SUCCEEDED(hres))
                num_set_val(retv, num_val(&nl) + num_val(&nr));
        }
    }

    VariantClear(&r);
    VariantClear(&l);
    return hres;
}

/* ECMA-262 3rd Edition    11.6.1 */
HRESULT add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, add_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
1976 1977
}

1978 1979
/* ECMA-262 3rd Edition    11.6.2 */
static HRESULT sub_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
Jacek Caban's avatar
Jacek Caban committed
1980
{
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003
    VARIANT lnum, rnum;
    HRESULT hres;

    hres = to_number(ctx->parser->script, lval, ei, &lnum);
    if(FAILED(hres))
        return hres;

    hres = to_number(ctx->parser->script, rval, ei, &rnum);
    if(FAILED(hres))
        return hres;

    num_set_val(retv, num_val(&lnum) - num_val(&rnum));
    return S_OK;
}

/* ECMA-262 3rd Edition    11.6.2 */
HRESULT sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2004 2005
}

2006 2007
/* ECMA-262 3rd Edition    11.5.1 */
static HRESULT mul_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
Jacek Caban's avatar
Jacek Caban committed
2008
{
2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031
    VARIANT lnum, rnum;
    HRESULT hres;

    hres = to_number(ctx->parser->script, lval, ei, &lnum);
    if(FAILED(hres))
        return hres;

    hres = to_number(ctx->parser->script, rval, ei, &rnum);
    if(FAILED(hres))
        return hres;

    num_set_val(retv, num_val(&lnum) * num_val(&rnum));
    return S_OK;
}

/* ECMA-262 3rd Edition    11.5.1 */
HRESULT mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2032 2033
}

2034 2035
/* ECMA-262 3rd Edition    11.5.2 */
static HRESULT div_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
Jacek Caban's avatar
Jacek Caban committed
2036
{
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059
    VARIANT lnum, rnum;
    HRESULT hres;

    hres = to_number(ctx->parser->script, lval, ei, &lnum);
    if(FAILED(hres))
        return hres;

    hres = to_number(ctx->parser->script, rval, ei, &rnum);
    if(FAILED(hres))
        return hres;

    num_set_val(retv, num_val(&lnum) / num_val(&rnum));
    return S_OK;
}

/* ECMA-262 3rd Edition    11.5.2 */
HRESULT div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, div_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2060 2061
}

Jacek Caban's avatar
Jacek Caban committed
2062
/* ECMA-262 3rd Edition    11.5.3 */
2063
static HRESULT mod_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
Jacek Caban's avatar
Jacek Caban committed
2064
{
2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087
    VARIANT lnum, rnum;
    HRESULT hres;

    hres = to_number(ctx->parser->script, lval, ei, &lnum);
    if(FAILED(hres))
        return hres;

    hres = to_number(ctx->parser->script, rval, ei, &rnum);
    if(FAILED(hres))
        return hres;

    num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
    return S_OK;
}

/* ECMA-262 3rd Edition    11.5.3 */
HRESULT mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2088 2089
}

2090 2091
/* ECMA-262 3rd Edition    11.4.2 */
HRESULT delete_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2092
{
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104
    unary_expression_t *expr = (unary_expression_t*)_expr;
    VARIANT_BOOL b = VARIANT_FALSE;
    exprval_t exprval;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
    if(FAILED(hres))
        return hres;

    switch(exprval.type) {
2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115
    case EXPRVAL_IDREF: {
        IDispatchEx *dispex;

        hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
        if(SUCCEEDED(hres)) {
            hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
            b = VARIANT_TRUE;
            IDispatchEx_Release(dispex);
        }
        break;
    }
2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136
    case EXPRVAL_NAMEREF: {
        IDispatchEx *dispex;

        hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
        if(SUCCEEDED(hres)) {
            hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name, fdexNameCaseSensitive);
            b = VARIANT_TRUE;
            IDispatchEx_Release(dispex);
        }
        break;
    }
    default:
        FIXME("unsupported type %d\n", exprval.type);
        hres = E_NOTIMPL;
    }

    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    return return_bool(ret, b);
Jacek Caban's avatar
Jacek Caban committed
2137 2138
}

2139 2140
/* ECMA-262 3rd Edition    11.4.2 */
HRESULT void_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2141
{
2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162
    unary_expression_t *expr = (unary_expression_t*)_expr;
    exprval_t exprval;
    VARIANT tmp;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &tmp);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    VariantClear(&tmp);

    ret->type = EXPRVAL_VARIANT;
    V_VT(&ret->u.var) = VT_EMPTY;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
2163 2164
}

2165
/* ECMA-262 3rd Edition    11.4.3 */
2166
HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2167
{
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222
    unary_expression_t *expr = (unary_expression_t*)_expr;
    const WCHAR *str;
    exprval_t exprval;
    VARIANT val;
    HRESULT hres;

    static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
    static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
    static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
    static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
    static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
    static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    switch(V_VT(&val)) {
    case VT_EMPTY:
        str = undefinedW;
        break;
    case VT_NULL:
        str = objectW;
        break;
    case VT_BOOL:
        str = booleanW;
        break;
    case VT_I4:
    case VT_R8:
        str = numberW;
        break;
    case VT_BSTR:
        str = stringW;
        break;
    case VT_DISPATCH: {
        DispatchEx *dispex;

        dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val));
        if(dispex) {
            str = dispex->builtin_info->class == JSCLASS_FUNCTION ? functionW : objectW;
            IDispatchEx_Release(_IDispatchEx_(dispex));
        }else {
            str = objectW;
        }
        break;
    }
    default:
        FIXME("unhandled vt %d\n", V_VT(&val));
2223 2224
        VariantClear(&val);
        return E_NOTIMPL;
2225 2226 2227 2228 2229 2230 2231 2232
    }

    VariantClear(&val);

    ret->type = EXPRVAL_VARIANT;
    V_VT(&ret->u.var) = VT_BSTR;
    V_BSTR(&ret->u.var) = SysAllocString(str);
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
2233 2234
}

2235 2236
/* ECMA-262 3rd Edition    11.4.7 */
HRESULT minus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2237
{
2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261
    unary_expression_t *expr = (unary_expression_t*)_expr;
    exprval_t exprval;
    VARIANT val, num;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    hres = to_number(ctx->parser->script, &val, ei, &num);
    VariantClear(&val);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    num_set_val(&ret->u.var, -num_val(&num));
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
2262 2263
}

2264 2265
/* ECMA-262 3rd Edition    11.4.6 */
HRESULT plus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2266
{
2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289
    unary_expression_t *expr = (unary_expression_t*)_expr;
    exprval_t exprval;
    VARIANT val, num;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    hres = to_number(ctx->parser->script, &val, ei, &num);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = num;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
2290 2291
}

2292 2293
/* ECMA-262 3rd Edition    11.3.1 */
HRESULT post_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2294
{
2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324
    unary_expression_t *expr = (unary_expression_t*)_expr;
    VARIANT val, num;
    exprval_t exprval;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
    if(SUCCEEDED(hres)) {
        hres = to_number(ctx->parser->script, &val, ei, &num);
        VariantClear(&val);
    }

    if(SUCCEEDED(hres)) {
        VARIANT inc;
        num_set_val(&inc, num_val(&num)+1.0);
        hres = put_value(ctx->parser->script, &exprval, &inc, ei);
    }

    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = num;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
2325 2326
}

2327 2328
/* ECMA-262 3rd Edition    11.3.2 */
HRESULT post_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2329
{
2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359
    unary_expression_t *expr = (unary_expression_t*)_expr;
    VARIANT val, num;
    exprval_t exprval;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
    if(SUCCEEDED(hres)) {
        hres = to_number(ctx->parser->script, &val, ei, &num);
        VariantClear(&val);
    }

    if(SUCCEEDED(hres)) {
        VARIANT dec;
        num_set_val(&dec, num_val(&num)-1.0);
        hres = put_value(ctx->parser->script, &exprval, &dec, ei);
    }

    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = num;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
2360 2361
}

2362 2363
/* ECMA-262 3rd Edition    11.4.4 */
HRESULT pre_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2364
{
2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393
    unary_expression_t *expr = (unary_expression_t*)_expr;
    VARIANT val, num;
    exprval_t exprval;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
    if(SUCCEEDED(hres)) {
        hres = to_number(ctx->parser->script, &val, ei, &num);
        VariantClear(&val);
    }

    if(SUCCEEDED(hres)) {
        num_set_val(&val, num_val(&num)+1.0);
        hres = put_value(ctx->parser->script, &exprval, &val, ei);
    }

    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = val;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
2394 2395
}

2396 2397
/* ECMA-262 3rd Edition    11.4.5 */
HRESULT pre_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2398
{
2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427
    unary_expression_t *expr = (unary_expression_t*)_expr;
    VARIANT val, num;
    exprval_t exprval;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
    if(FAILED(hres))
        return hres;

    hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
    if(SUCCEEDED(hres)) {
        hres = to_number(ctx->parser->script, &val, ei, &num);
        VariantClear(&val);
    }

    if(SUCCEEDED(hres)) {
        num_set_val(&val, num_val(&num)-1.0);
        hres = put_value(ctx->parser->script, &exprval, &val, ei);
    }

    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = val;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
2428 2429
}

2430 2431
/* ECMA-262 3rd Edition    11.9.3 */
static HRESULT equal_values(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
Jacek Caban's avatar
Jacek Caban committed
2432
{
2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546
    if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
       return equal2_values(lval, rval, ret);

    /* FIXME: NULL disps should be handled in more general way */
    if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
        VARIANT v;
        V_VT(&v) = VT_NULL;
        return equal_values(ctx, &v, rval, ei, ret);
    }

    if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
        VARIANT v;
        V_VT(&v) = VT_NULL;
        return equal_values(ctx, lval, &v, ei, ret);
    }

    if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
       (V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
        *ret = TRUE;
        return S_OK;
    }

    if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
        VARIANT v;
        HRESULT hres;

        hres = to_number(ctx->parser->script, lval, ei, &v);
        if(FAILED(hres))
            return hres;

        return equal_values(ctx, &v, rval, ei, ret);
    }

    if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
        VARIANT v;
        HRESULT hres;

        hres = to_number(ctx->parser->script, rval, ei, &v);
        if(FAILED(hres))
            return hres;

        return equal_values(ctx, lval, &v, ei, ret);
    }

    if(V_VT(rval) == VT_BOOL) {
        VARIANT v;

        V_VT(&v) = VT_I4;
        V_I4(&v) = V_BOOL(rval) ? 1 : 0;
        return equal_values(ctx, lval, &v, ei, ret);
    }

    if(V_VT(lval) == VT_BOOL) {
        VARIANT v;

        V_VT(&v) = VT_I4;
        V_I4(&v) = V_BOOL(lval) ? 1 : 0;
        return equal_values(ctx, &v, rval, ei, ret);
    }


    if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
        VARIANT v;
        HRESULT hres;

        hres = to_primitive(ctx->parser->script, rval, ei, &v);
        if(FAILED(hres))
            return hres;

        hres = equal_values(ctx, lval, &v, ei, ret);

        VariantClear(&v);
        return hres;
    }


    if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
        VARIANT v;
        HRESULT hres;

        hres = to_primitive(ctx->parser->script, lval, ei, &v);
        if(FAILED(hres))
            return hres;

        hres = equal_values(ctx, &v, rval, ei, ret);

        VariantClear(&v);
        return hres;
    }


    *ret = FALSE;
    return S_OK;
}

/* ECMA-262 3rd Edition    11.9.1 */
HRESULT equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;
    VARIANT rval, lval;
    BOOL b;
    HRESULT hres;

    TRACE("\n");

    hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
    if(FAILED(hres))
        return hres;

    hres = equal_values(ctx, &rval, &lval, ei, &b);
    if(FAILED(hres))
        return hres;

    return return_bool(ret, b);
Jacek Caban's avatar
Jacek Caban committed
2547 2548
}

2549 2550
/* ECMA-262 3rd Edition    11.9.4 */
HRESULT equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2551
{
2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567
    binary_expression_t *expr = (binary_expression_t*)_expr;
    VARIANT rval, lval;
    BOOL b;
    HRESULT hres;

    TRACE("\n");

    hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
    if(FAILED(hres))
        return hres;

    hres = equal2_values(&rval, &lval, &b);
    if(FAILED(hres))
        return hres;

    return return_bool(ret, b);
Jacek Caban's avatar
Jacek Caban committed
2568 2569
}

2570
/* ECMA-262 3rd Edition    11.9.2 */
Jacek Caban's avatar
Jacek Caban committed
2571 2572
HRESULT not_equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
2573 2574 2575 2576
    binary_expression_t *expr = (binary_expression_t*)_expr;
    VARIANT rval, lval;
    BOOL b;
    HRESULT hres;
Jacek Caban's avatar
Jacek Caban committed
2577

2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588
    TRACE("\n");

    hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
    if(FAILED(hres))
        return hres;

    hres = equal_values(ctx, &lval, &rval, ei, &b);
    if(FAILED(hres))
        return hres;

    return return_bool(ret, !b);
Jacek Caban's avatar
Jacek Caban committed
2589 2590
}

2591 2592
/* ECMA-262 3rd Edition    11.9.5 */
HRESULT not_equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2593
{
2594 2595 2596 2597 2598 2599 2600
    binary_expression_t *expr = (binary_expression_t*)_expr;
    VARIANT rval, lval;
    BOOL b;
    HRESULT hres;

    TRACE("\n");

Jacek Caban's avatar
Jacek Caban committed
2601
    hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2602 2603 2604
    if(FAILED(hres))
        return hres;

Jacek Caban's avatar
Jacek Caban committed
2605
    hres = equal2_values(&lval, &rval, &b);
2606 2607 2608 2609
    if(FAILED(hres))
        return hres;

    return return_bool(ret, !b);
Jacek Caban's avatar
Jacek Caban committed
2610 2611
}

2612
/* ECMA-262 3rd Edition    11.8.5 */
2613
static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
Jacek Caban's avatar
Jacek Caban committed
2614
{
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628
    VARIANT l, r, ln, rn;
    HRESULT hres;

    hres = to_primitive(ctx->parser->script, lval, ei, &l);
    if(FAILED(hres))
        return hres;

    hres = to_primitive(ctx->parser->script, rval, ei, &r);
    if(FAILED(hres)) {
        VariantClear(&l);
        return hres;
    }

    if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
2629
        *ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642
        SysFreeString(V_BSTR(&l));
        SysFreeString(V_BSTR(&r));
        return S_OK;
    }

    hres = to_number(ctx->parser->script, &l, ei, &ln);
    VariantClear(&l);
    if(SUCCEEDED(hres))
        hres = to_number(ctx->parser->script, &r, ei, &rn);
    VariantClear(&r);
    if(FAILED(hres))
        return hres;

2643 2644 2645 2646 2647 2648 2649 2650
    if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
        *ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
    }else  {
        DOUBLE ld = num_val(&ln);
        DOUBLE rd = num_val(&rn);

        *ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
    }
2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668

    return S_OK;
}

/* ECMA-262 3rd Edition    11.8.1 */
HRESULT less_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
    binary_expression_t *expr = (binary_expression_t*)_expr;
    VARIANT rval, lval;
    BOOL b;
    HRESULT hres;

    TRACE("\n");

    hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
    if(FAILED(hres))
        return hres;

2669
    hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
2670 2671 2672 2673 2674 2675
    VariantClear(&lval);
    VariantClear(&rval);
    if(FAILED(hres))
        return hres;

    return return_bool(ret, b);
Jacek Caban's avatar
Jacek Caban committed
2676 2677
}

2678 2679
/* ECMA-262 3rd Edition    11.8.3 */
HRESULT lesseq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2680
{
2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691
    binary_expression_t *expr = (binary_expression_t*)_expr;
    VARIANT rval, lval;
    BOOL b;
    HRESULT hres;

    TRACE("\n");

    hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
    if(FAILED(hres))
        return hres;

2692
    hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
2693 2694 2695 2696 2697
    VariantClear(&lval);
    VariantClear(&rval);
    if(FAILED(hres))
        return hres;

2698
    return return_bool(ret, b);
Jacek Caban's avatar
Jacek Caban committed
2699 2700
}

2701 2702
/* ECMA-262 3rd Edition    11.8.2 */
HRESULT greater_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2703
{
2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714
    binary_expression_t *expr = (binary_expression_t*)_expr;
    VARIANT rval, lval;
    BOOL b;
    HRESULT hres;

    TRACE("\n");

    hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
    if(FAILED(hres))
        return hres;

2715
    hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
2716 2717 2718 2719 2720 2721
    VariantClear(&lval);
    VariantClear(&rval);
    if(FAILED(hres))
        return hres;

    return return_bool(ret, b);
Jacek Caban's avatar
Jacek Caban committed
2722 2723
}

2724 2725
/* ECMA-262 3rd Edition    11.8.4 */
HRESULT greatereq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2726
{
2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737
    binary_expression_t *expr = (binary_expression_t*)_expr;
    VARIANT rval, lval;
    BOOL b;
    HRESULT hres;

    TRACE("\n");

    hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
    if(FAILED(hres))
        return hres;

2738
    hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
2739 2740 2741 2742 2743
    VariantClear(&lval);
    VariantClear(&rval);
    if(FAILED(hres))
        return hres;

2744
    return return_bool(ret, b);
Jacek Caban's avatar
Jacek Caban committed
2745 2746
}

2747 2748
/* ECMA-262 3rd Edition    11.4.8 */
HRESULT binary_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2749
{
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774
    unary_expression_t *expr = (unary_expression_t*)_expr;
    exprval_t exprval;
    VARIANT val;
    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->parser->script, &exprval, ei, &val);
    exprval_release(&exprval);
    if(FAILED(hres))
        return hres;

    hres = to_int32(ctx->parser->script, &val, ei, &i);
    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;
Jacek Caban's avatar
Jacek Caban committed
2775 2776
}

2777 2778
/* ECMA-262 3rd Edition    11.4.9 */
HRESULT logical_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2779
{
2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796
    unary_expression_t *expr = (unary_expression_t*)_expr;
    exprval_t exprval;
    VARIANT_BOOL b;
    HRESULT hres;

    TRACE("\n");

    hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, 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 return_bool(ret, !b);
Jacek Caban's avatar
Jacek Caban committed
2797 2798
}

2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819
/* 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 */
Jacek Caban's avatar
Jacek Caban committed
2820 2821
HRESULT left_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
2822 2823 2824 2825 2826
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2827 2828
}

2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849
/* ECMA-262 3rd Edition    11.7.2 */
static HRESULT rshift_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.2 */
Jacek Caban's avatar
Jacek Caban committed
2850 2851
HRESULT right_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
2852 2853 2854 2855 2856
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2857 2858
}

2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878
/* ECMA-262 3rd Edition    11.7.3 */
static HRESULT rshift2_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
{
    DWORD li, ri;
    HRESULT hres;

    hres = to_uint32(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.3 */
Jacek Caban's avatar
Jacek Caban committed
2879 2880
HRESULT right2_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
{
2881 2882 2883 2884 2885
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2886 2887
}

2888 2889
/* ECMA-262 3rd Edition    11.13.1 */
HRESULT assign_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2890
{
2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911
    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->parser->script, &exprvalr, ei, &rval);
        exprval_release(&exprvalr);
    }

    if(SUCCEEDED(hres))
        hres = put_value(ctx->parser->script, &exprval, &rval, ei);

    exprval_release(&exprval);
2912
    if(FAILED(hres))
2913 2914 2915 2916 2917
        return hres;

    ret->type = EXPRVAL_VARIANT;
    ret->u.var = rval;
    return S_OK;
Jacek Caban's avatar
Jacek Caban committed
2918 2919
}

2920 2921
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_lshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2922
{
2923 2924 2925 2926 2927
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2928 2929
}

2930 2931
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_rshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2932
{
2933 2934 2935 2936 2937
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2938 2939
}

2940 2941
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_rrshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2942
{
2943 2944 2945 2946 2947
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift2_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2948 2949
}

2950 2951
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2952
{
2953 2954 2955 2956 2957
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, add_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2958 2959
}

2960 2961
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2962
{
2963 2964 2965 2966 2967
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, sub_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2968 2969
}

2970 2971
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2972
{
2973 2974 2975 2976 2977
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, mul_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2978 2979
}

2980 2981
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2982
{
2983 2984 2985 2986 2987
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, div_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2988 2989
}

Jacek Caban's avatar
Jacek Caban committed
2990
/* ECMA-262 3rd Edition    11.13.2 */
2991
HRESULT assign_mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
2992
{
2993 2994 2995 2996 2997
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, mod_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
2998 2999
}

3000 3001
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
3002
{
3003 3004 3005 3006 3007
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitand_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
3008 3009
}

3010 3011
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
3012
{
3013 3014 3015 3016 3017
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitor_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
3018 3019
}

3020 3021
/* ECMA-262 3rd Edition    11.13.2 */
HRESULT assign_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
Jacek Caban's avatar
Jacek Caban committed
3022
{
3023 3024 3025 3026 3027
    binary_expression_t *expr = (binary_expression_t*)_expr;

    TRACE("\n");

    return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);
Jacek Caban's avatar
Jacek Caban committed
3028
}