push 6377a023768d7480eb1b17e57456824888936b43
[wine/hacks.git] / dlls / jscript / engine.c
blobff5e6a896c37502d82ad600084b930f6b022b2af
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
20 #include "wine/port.h"
22 #include <math.h>
24 #include "jscript.h"
25 #include "engine.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
31 #define EXPR_NOVAL 0x0001
32 #define EXPR_NEWREF 0x0002
33 #define EXPR_STRREF 0x0004
35 static inline HRESULT stat_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
37 return stat->eval(ctx, stat, rt, ret);
40 static inline HRESULT expr_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
42 return _expr->eval(ctx, _expr, flags, ei, ret);
45 static void exprval_release(exprval_t *val)
47 switch(val->type) {
48 case EXPRVAL_VARIANT:
49 if(V_VT(&val->u.var) != VT_EMPTY)
50 VariantClear(&val->u.var);
51 return;
52 case EXPRVAL_IDREF:
53 if(val->u.idref.disp)
54 IDispatch_Release(val->u.idref.disp);
55 return;
56 case EXPRVAL_NAMEREF:
57 if(val->u.nameref.disp)
58 IDispatch_Release(val->u.nameref.disp);
59 SysFreeString(val->u.nameref.name);
63 /* ECMA-262 3rd Edition 8.7.1 */
64 static HRESULT exprval_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
66 V_VT(ret) = VT_EMPTY;
68 switch(val->type) {
69 case EXPRVAL_VARIANT:
70 return VariantCopy(ret, &val->u.var);
71 case EXPRVAL_IDREF:
72 if(!val->u.idref.disp) {
73 FIXME("throw ReferenceError\n");
74 return E_FAIL;
77 return disp_propget(val->u.idref.disp, val->u.idref.id, ctx->lcid, ret, ei, NULL/*FIXME*/);
78 default:
79 ERR("type %d\n", val->type);
80 return E_FAIL;
84 static HRESULT exprval_to_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
86 if(val->type == EXPRVAL_VARIANT) {
87 *ret = val->u.var;
88 V_VT(&val->u.var) = VT_EMPTY;
89 return S_OK;
92 return exprval_value(ctx, val, ei, ret);
95 static HRESULT exprval_to_boolean(script_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, VARIANT_BOOL *b)
97 if(exprval->type != EXPRVAL_VARIANT) {
98 VARIANT val;
99 HRESULT hres;
101 hres = exprval_to_value(ctx, exprval, ei, &val);
102 if(FAILED(hres))
103 return hres;
105 hres = to_boolean(&val, b);
106 VariantClear(&val);
107 return hres;
110 return to_boolean(&exprval->u.var, b);
113 static void exprval_init(exprval_t *val)
115 val->type = EXPRVAL_VARIANT;
116 V_VT(&val->u.var) = VT_EMPTY;
119 static void exprval_set_idref(exprval_t *val, IDispatch *disp, DISPID id)
121 val->type = EXPRVAL_IDREF;
122 val->u.idref.disp = disp;
123 val->u.idref.id = id;
125 if(disp)
126 IDispatch_AddRef(disp);
129 HRESULT scope_push(scope_chain_t *scope, DispatchEx *obj, scope_chain_t **ret)
131 scope_chain_t *new_scope;
133 new_scope = heap_alloc(sizeof(scope_chain_t));
134 if(!new_scope)
135 return E_OUTOFMEMORY;
137 new_scope->ref = 1;
139 IDispatchEx_AddRef(_IDispatchEx_(obj));
140 new_scope->obj = obj;
142 if(scope) {
143 scope_addref(scope);
144 new_scope->next = scope;
145 }else {
146 new_scope->next = NULL;
149 *ret = new_scope;
150 return S_OK;
153 static void scope_pop(scope_chain_t **scope)
155 scope_chain_t *tmp;
157 tmp = *scope;
158 *scope = tmp->next;
159 scope_release(tmp);
162 void scope_release(scope_chain_t *scope)
164 if(--scope->ref)
165 return;
167 if(scope->next)
168 scope_release(scope->next);
170 IDispatchEx_Release(_IDispatchEx_(scope->obj));
171 heap_free(scope);
174 HRESULT create_exec_ctx(IDispatch *this_obj, DispatchEx *var_disp, scope_chain_t *scope, exec_ctx_t **ret)
176 exec_ctx_t *ctx;
178 ctx = heap_alloc_zero(sizeof(exec_ctx_t));
179 if(!ctx)
180 return E_OUTOFMEMORY;
182 ctx->ref = 1;
184 IDispatch_AddRef(this_obj);
185 ctx->this_obj = this_obj;
187 IDispatchEx_AddRef(_IDispatchEx_(var_disp));
188 ctx->var_disp = var_disp;
190 if(scope) {
191 scope_addref(scope);
192 ctx->scope_chain = scope;
195 *ret = ctx;
196 return S_OK;
199 void exec_release(exec_ctx_t *ctx)
201 if(--ctx->ref)
202 return;
204 if(ctx->scope_chain)
205 scope_release(ctx->scope_chain);
206 if(ctx->var_disp)
207 IDispatchEx_Release(_IDispatchEx_(ctx->var_disp));
208 if(ctx->this_obj)
209 IDispatch_Release(ctx->this_obj);
210 heap_free(ctx);
213 static HRESULT disp_get_id(IDispatch *disp, BSTR name, DWORD flags, DISPID *id)
215 IDispatchEx *dispex;
216 HRESULT hres;
218 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
219 if(FAILED(hres)) {
220 TRACE("unsing IDispatch\n");
222 *id = 0;
223 return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
226 *id = 0;
227 hres = IDispatchEx_GetDispID(dispex, name, flags|fdexNameCaseSensitive, id);
228 IDispatchEx_Release(dispex);
229 return hres;
232 /* ECMA-262 3rd Edition 8.7.2 */
233 static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei)
235 if(ref->type != EXPRVAL_IDREF)
236 return throw_reference_error(ctx, ei, IDS_ILLEGAL_ASSIGN, NULL);
238 return disp_propput(ref->u.idref.disp, ref->u.idref.id, ctx->lcid, v, ei, NULL/*FIXME*/);
241 static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, BOOL *ret)
243 IObjectIdentity *identity;
244 IUnknown *unk1, *unk2;
245 HRESULT hres;
247 if(disp1 == disp2) {
248 *ret = TRUE;
249 return S_OK;
252 hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
253 if(FAILED(hres))
254 return hres;
256 hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
257 if(FAILED(hres)) {
258 IUnknown_Release(unk1);
259 return hres;
262 if(unk1 == unk2) {
263 *ret = TRUE;
264 }else {
265 hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
266 if(SUCCEEDED(hres)) {
267 hres = IObjectIdentity_IsEqualObject(identity, unk2);
268 IObjectIdentity_Release(identity);
269 *ret = hres == S_OK;
270 }else {
271 *ret = FALSE;
275 IUnknown_Release(unk1);
276 IUnknown_Release(unk2);
277 return S_OK;
280 /* ECMA-262 3rd Edition 11.9.6 */
281 static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
283 TRACE("\n");
285 if(V_VT(lval) != V_VT(rval)) {
286 if(is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))) {
287 *ret = num_val(lval) == num_val(rval);
288 return S_OK;
291 *ret = FALSE;
292 return S_OK;
295 switch(V_VT(lval)) {
296 case VT_EMPTY:
297 case VT_NULL:
298 *ret = VARIANT_TRUE;
299 break;
300 case VT_I4:
301 *ret = V_I4(lval) == V_I4(rval);
302 break;
303 case VT_R8:
304 *ret = V_R8(lval) == V_R8(rval);
305 break;
306 case VT_BSTR:
307 *ret = !strcmpW(V_BSTR(lval), V_BSTR(rval));
308 break;
309 case VT_DISPATCH:
310 return disp_cmp(V_DISPATCH(lval), V_DISPATCH(rval), ret);
311 case VT_BOOL:
312 *ret = !V_BOOL(lval) == !V_BOOL(rval);
313 break;
314 default:
315 FIXME("unimplemented vt %d\n", V_VT(lval));
316 return E_NOTIMPL;
319 return S_OK;
322 static HRESULT literal_to_var(literal_t *literal, VARIANT *v)
324 V_VT(v) = literal->vt;
326 switch(V_VT(v)) {
327 case VT_EMPTY:
328 case VT_NULL:
329 break;
330 case VT_I4:
331 V_I4(v) = literal->u.lval;
332 break;
333 case VT_R8:
334 V_R8(v) = literal->u.dval;
335 break;
336 case VT_BSTR:
337 V_BSTR(v) = SysAllocString(literal->u.wstr);
338 break;
339 case VT_BOOL:
340 V_BOOL(v) = literal->u.bval;
341 break;
342 case VT_DISPATCH:
343 IDispatch_AddRef(literal->u.disp);
344 V_DISPATCH(v) = literal->u.disp;
345 break;
346 default:
347 ERR("wrong type %d\n", V_VT(v));
348 return E_NOTIMPL;
351 return S_OK;
354 HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, jsexcept_t *ei, VARIANT *retv)
356 script_ctx_t *script = parser->script;
357 function_declaration_t *func;
358 parser_ctx_t *prev_parser;
359 var_list_t *var;
360 VARIANT val, tmp;
361 statement_t *stat;
362 exec_ctx_t *prev_ctx;
363 return_type_t rt;
364 HRESULT hres = S_OK;
366 for(func = source->functions; func; func = func->next) {
367 DispatchEx *func_obj;
368 VARIANT var;
370 hres = create_source_function(parser, func->expr->parameter_list, func->expr->source_elements,
371 ctx->scope_chain, func->expr->src_str, func->expr->src_len, &func_obj);
372 if(FAILED(hres))
373 return hres;
375 V_VT(&var) = VT_DISPATCH;
376 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(func_obj);
377 hres = jsdisp_propput_name(ctx->var_disp, func->expr->identifier, script->lcid, &var, ei, NULL);
378 jsdisp_release(func_obj);
379 if(FAILED(hres))
380 return hres;
383 for(var = source->variables; var; var = var->next) {
384 DISPID id = 0;
386 hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
387 if(FAILED(hres))
388 return hres;
391 prev_ctx = script->exec_ctx;
392 script->exec_ctx = ctx;
394 prev_parser = ctx->parser;
395 ctx->parser = parser;
397 V_VT(&val) = VT_EMPTY;
398 memset(&rt, 0, sizeof(rt));
399 rt.type = RT_NORMAL;
401 for(stat = source->statement; stat; stat = stat->next) {
402 hres = stat_eval(ctx, stat, &rt, &tmp);
403 if(FAILED(hres))
404 break;
406 VariantClear(&val);
407 val = tmp;
408 if(rt.type != RT_NORMAL)
409 break;
412 script->exec_ctx = prev_ctx;
413 ctx->parser = prev_parser;
415 if(rt.type != RT_NORMAL && rt.type != RT_RETURN) {
416 FIXME("wrong rt %d\n", rt.type);
417 hres = E_FAIL;
420 *ei = rt.ei;
421 if(FAILED(hres)) {
422 VariantClear(&val);
423 return hres;
426 if(retv)
427 *retv = val;
428 else
429 VariantClear(&val);
430 return S_OK;
433 /* ECMA-262 3rd Edition 10.1.4 */
434 static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, jsexcept_t *ei, exprval_t *ret)
436 scope_chain_t *scope;
437 named_item_t *item;
438 DISPID id = 0;
439 HRESULT hres;
441 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 if(SUCCEEDED(hres))
446 break;
449 if(scope) {
450 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(scope->obj), id);
451 return S_OK;
454 hres = jsdisp_get_id(ctx->parser->script->global, identifier, 0, &id);
455 if(SUCCEEDED(hres)) {
456 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->global), id);
457 return S_OK;
460 for(item = ctx->parser->script->named_items; item; item = item->next) {
461 if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpW(item->name, identifier)) {
462 if(!item->disp) {
463 IUnknown *unk;
465 if(!ctx->parser->script->site)
466 break;
468 hres = IActiveScriptSite_GetItemInfo(ctx->parser->script->site, identifier,
469 SCRIPTINFO_IUNKNOWN, &unk, NULL);
470 if(FAILED(hres)) {
471 WARN("GetItemInfo failed: %08x\n", hres);
472 break;
475 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
476 IUnknown_Release(unk);
477 if(FAILED(hres)) {
478 WARN("object does not implement IDispatch\n");
479 break;
483 ret->type = EXPRVAL_VARIANT;
484 V_VT(&ret->u.var) = VT_DISPATCH;
485 V_DISPATCH(&ret->u.var) = item->disp;
486 IDispatch_AddRef(item->disp);
487 return S_OK;
491 for(item = ctx->parser->script->named_items; item; item = item->next) {
492 if(item->flags & SCRIPTITEM_GLOBALMEMBERS) {
493 hres = disp_get_id(item->disp, identifier, 0, &id);
494 if(SUCCEEDED(hres))
495 break;
499 if(item) {
500 exprval_set_idref(ret, item->disp, id);
501 return S_OK;
504 hres = jsdisp_get_id(ctx->parser->script->script_disp, identifier, 0, &id);
505 if(SUCCEEDED(hres)) {
506 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->script_disp), id);
507 return S_OK;
510 if(flags & EXPR_NEWREF) {
511 hres = jsdisp_get_id(ctx->var_disp, identifier, fdexNameEnsure, &id);
512 if(FAILED(hres))
513 return hres;
515 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->var_disp), id);
516 return S_OK;
519 return throw_type_error(ctx->var_disp->ctx, ei, IDS_UNDEFINED, identifier);
522 /* ECMA-262 3rd Edition 12.1 */
523 HRESULT block_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
525 block_statement_t *stat = (block_statement_t*)_stat;
526 VARIANT val, tmp;
527 statement_t *iter;
528 HRESULT hres = S_OK;
530 TRACE("\n");
532 V_VT(&val) = VT_EMPTY;
533 for(iter = stat->stat_list; iter; iter = iter->next) {
534 hres = stat_eval(ctx, iter, rt, &tmp);
535 if(FAILED(hres))
536 break;
538 VariantClear(&val);
539 val = tmp;
540 if(rt->type != RT_NORMAL)
541 break;
544 if(FAILED(hres)) {
545 VariantClear(&val);
546 return hres;
549 *ret = val;
550 return S_OK;
553 /* ECMA-262 3rd Edition 12.2 */
554 static HRESULT variable_list_eval(exec_ctx_t *ctx, variable_declaration_t *var_list, jsexcept_t *ei)
556 variable_declaration_t *iter;
557 HRESULT hres = S_OK;
559 for(iter = var_list; iter; iter = iter->next) {
560 exprval_t exprval;
561 VARIANT val;
563 if(!iter->expr)
564 continue;
566 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
567 if(FAILED(hres))
568 break;
570 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
571 exprval_release(&exprval);
572 if(FAILED(hres))
573 break;
575 hres = jsdisp_propput_name(ctx->var_disp, iter->identifier, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
576 VariantClear(&val);
577 if(FAILED(hres))
578 break;
581 return hres;
584 /* ECMA-262 3rd Edition 12.2 */
585 HRESULT var_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
587 var_statement_t *stat = (var_statement_t*)_stat;
588 HRESULT hres;
590 TRACE("\n");
592 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
593 if(FAILED(hres))
594 return hres;
596 V_VT(ret) = VT_EMPTY;
597 return S_OK;
600 /* ECMA-262 3rd Edition 12.3 */
601 HRESULT empty_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
603 TRACE("\n");
605 V_VT(ret) = VT_EMPTY;
606 return S_OK;
609 /* ECMA-262 3rd Edition 12.4 */
610 HRESULT expression_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
612 expression_statement_t *stat = (expression_statement_t*)_stat;
613 exprval_t exprval;
614 VARIANT val;
615 HRESULT hres;
617 TRACE("\n");
619 hres = expr_eval(ctx, stat->expr, EXPR_NOVAL, &rt->ei, &exprval);
620 if(FAILED(hres))
621 return hres;
623 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
624 exprval_release(&exprval);
625 if(FAILED(hres))
626 return hres;
628 *ret = val;
629 TRACE("= %s\n", debugstr_variant(ret));
630 return S_OK;
633 /* ECMA-262 3rd Edition 12.5 */
634 HRESULT if_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
636 if_statement_t *stat = (if_statement_t*)_stat;
637 exprval_t exprval;
638 VARIANT_BOOL b;
639 HRESULT hres;
641 TRACE("\n");
643 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
644 if(FAILED(hres))
645 return hres;
647 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
648 exprval_release(&exprval);
649 if(FAILED(hres))
650 return hres;
652 if(b)
653 hres = stat_eval(ctx, stat->if_stat, rt, ret);
654 else if(stat->else_stat)
655 hres = stat_eval(ctx, stat->else_stat, rt, ret);
656 else
657 V_VT(ret) = VT_EMPTY;
659 return hres;
662 /* ECMA-262 3rd Edition 12.6.2 */
663 HRESULT while_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
665 while_statement_t *stat = (while_statement_t*)_stat;
666 exprval_t exprval;
667 VARIANT val, tmp;
668 VARIANT_BOOL b;
669 BOOL test_expr;
670 HRESULT hres;
672 TRACE("\n");
674 V_VT(&val) = VT_EMPTY;
675 test_expr = !stat->do_while;
677 while(1) {
678 if(test_expr) {
679 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
680 if(FAILED(hres))
681 break;
683 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
684 exprval_release(&exprval);
685 if(FAILED(hres) || !b)
686 break;
687 }else {
688 test_expr = TRUE;
691 hres = stat_eval(ctx, stat->statement, rt, &tmp);
692 if(FAILED(hres))
693 break;
695 VariantClear(&val);
696 val = tmp;
698 if(rt->type == RT_CONTINUE)
699 rt->type = RT_NORMAL;
700 if(rt->type != RT_NORMAL)
701 break;
704 if(FAILED(hres)) {
705 VariantClear(&val);
706 return hres;
709 if(rt->type == RT_BREAK)
710 rt->type = RT_NORMAL;
712 *ret = val;
713 return S_OK;
716 /* ECMA-262 3rd Edition 12.6.3 */
717 HRESULT for_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
719 for_statement_t *stat = (for_statement_t*)_stat;
720 VARIANT val, tmp, retv;
721 exprval_t exprval;
722 VARIANT_BOOL b;
723 HRESULT hres;
725 TRACE("\n");
727 if(stat->variable_list) {
728 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
729 if(FAILED(hres))
730 return hres;
731 }else if(stat->begin_expr) {
732 hres = expr_eval(ctx, stat->begin_expr, EXPR_NEWREF, &rt->ei, &exprval);
733 if(FAILED(hres))
734 return hres;
736 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
737 exprval_release(&exprval);
738 if(FAILED(hres))
739 return hres;
741 VariantClear(&val);
744 V_VT(&retv) = VT_EMPTY;
746 while(1) {
747 if(stat->expr) {
748 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
749 if(FAILED(hres))
750 break;
752 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
753 exprval_release(&exprval);
754 if(FAILED(hres) || !b)
755 break;
758 hres = stat_eval(ctx, stat->statement, rt, &tmp);
759 if(FAILED(hres))
760 break;
762 VariantClear(&retv);
763 retv = tmp;
765 if(rt->type == RT_CONTINUE)
766 rt->type = RT_NORMAL;
767 else if(rt->type != RT_NORMAL)
768 break;
770 if(stat->end_expr) {
771 hres = expr_eval(ctx, stat->end_expr, 0, &rt->ei, &exprval);
772 if(FAILED(hres))
773 break;
775 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
776 exprval_release(&exprval);
777 if(FAILED(hres))
778 break;
780 VariantClear(&val);
784 if(FAILED(hres)) {
785 VariantClear(&retv);
786 return hres;
789 if(rt->type == RT_BREAK)
790 rt->type = RT_NORMAL;
792 *ret = retv;
793 return S_OK;
796 /* ECMA-262 3rd Edition 12.6.4 */
797 HRESULT forin_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
799 forin_statement_t *stat = (forin_statement_t*)_stat;
800 VARIANT val, name, retv, tmp;
801 DISPID id = DISPID_STARTENUM;
802 BSTR str, identifier = NULL;
803 IDispatchEx *in_obj;
804 exprval_t exprval;
805 HRESULT hres;
807 TRACE("\n");
809 if(stat->variable) {
810 hres = variable_list_eval(ctx, stat->variable, &rt->ei);
811 if(FAILED(hres))
812 return hres;
815 hres = expr_eval(ctx, stat->in_expr, EXPR_NEWREF, &rt->ei, &exprval);
816 if(FAILED(hres))
817 return hres;
819 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
820 exprval_release(&exprval);
821 if(FAILED(hres))
822 return hres;
824 if(V_VT(&val) != VT_DISPATCH) {
825 TRACE("in vt %d\n", V_VT(&val));
826 VariantClear(&val);
827 V_VT(ret) = VT_EMPTY;
828 return S_OK;
831 hres = IDispatch_QueryInterface(V_DISPATCH(&val), &IID_IDispatchEx, (void**)&in_obj);
832 IDispatch_Release(V_DISPATCH(&val));
833 if(FAILED(hres)) {
834 FIXME("Object doesn't support IDispatchEx\n");
835 return E_NOTIMPL;
838 V_VT(&retv) = VT_EMPTY;
840 if(stat->variable)
841 identifier = SysAllocString(stat->variable->identifier);
843 while(1) {
844 hres = IDispatchEx_GetNextDispID(in_obj, fdexEnumDefault, id, &id);
845 if(FAILED(hres) || hres == S_FALSE)
846 break;
848 hres = IDispatchEx_GetMemberName(in_obj, id, &str);
849 if(FAILED(hres))
850 break;
852 TRACE("iter %s\n", debugstr_w(str));
854 if(stat->variable)
855 hres = identifier_eval(ctx, identifier, 0, NULL, &exprval);
856 else
857 hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval);
858 if(SUCCEEDED(hres)) {
859 V_VT(&name) = VT_BSTR;
860 V_BSTR(&name) = str;
861 hres = put_value(ctx->parser->script, &exprval, &name, &rt->ei);
862 exprval_release(&exprval);
864 SysFreeString(str);
865 if(FAILED(hres))
866 break;
868 hres = stat_eval(ctx, stat->statement, rt, &tmp);
869 if(FAILED(hres))
870 break;
872 VariantClear(&retv);
873 retv = tmp;
875 if(rt->type == RT_CONTINUE)
876 rt->type = RT_NORMAL;
877 else if(rt->type != RT_NORMAL)
878 break;
881 SysFreeString(identifier);
882 IDispatchEx_Release(in_obj);
883 if(FAILED(hres)) {
884 VariantClear(&retv);
885 return hres;
888 if(rt->type == RT_BREAK)
889 rt->type = RT_NORMAL;
891 *ret = retv;
892 return S_OK;
895 /* ECMA-262 3rd Edition 12.7 */
896 HRESULT continue_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
898 branch_statement_t *stat = (branch_statement_t*)_stat;
900 TRACE("\n");
902 if(stat->identifier) {
903 FIXME("indentifier not implemented\n");
904 return E_NOTIMPL;
907 rt->type = RT_CONTINUE;
908 V_VT(ret) = VT_EMPTY;
909 return S_OK;
912 /* ECMA-262 3rd Edition 12.8 */
913 HRESULT break_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
915 branch_statement_t *stat = (branch_statement_t*)_stat;
917 TRACE("\n");
919 if(stat->identifier) {
920 FIXME("indentifier not implemented\n");
921 return E_NOTIMPL;
924 rt->type = RT_BREAK;
925 V_VT(ret) = VT_EMPTY;
926 return S_OK;
929 /* ECMA-262 3rd Edition 12.9 */
930 HRESULT return_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
932 expression_statement_t *stat = (expression_statement_t*)_stat;
933 HRESULT hres;
935 TRACE("\n");
937 if(stat->expr) {
938 exprval_t exprval;
940 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
941 if(FAILED(hres))
942 return hres;
944 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, ret);
945 exprval_release(&exprval);
946 if(FAILED(hres))
947 return hres;
948 }else {
949 V_VT(ret) = VT_EMPTY;
952 TRACE("= %s\n", debugstr_variant(ret));
953 rt->type = RT_RETURN;
954 return S_OK;
957 /* ECMA-262 3rd Edition 12.10 */
958 HRESULT with_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
960 with_statement_t *stat = (with_statement_t*)_stat;
961 exprval_t exprval;
962 IDispatch *disp;
963 DispatchEx *obj;
964 VARIANT val;
965 HRESULT hres;
967 TRACE("\n");
969 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
970 if(FAILED(hres))
971 return hres;
973 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
974 exprval_release(&exprval);
975 if(FAILED(hres))
976 return hres;
978 hres = to_object(ctx, &val, &disp);
979 VariantClear(&val);
980 if(FAILED(hres))
981 return hres;
983 obj = iface_to_jsdisp((IUnknown*)disp);
984 IDispatch_Release(disp);
985 if(!obj) {
986 FIXME("disp id not jsdisp\n");
987 return E_NOTIMPL;
990 hres = scope_push(ctx->scope_chain, obj, &ctx->scope_chain);
991 jsdisp_release(obj);
992 if(FAILED(hres))
993 return hres;
995 hres = stat_eval(ctx, stat->statement, rt, ret);
997 scope_pop(&ctx->scope_chain);
998 return hres;
1001 /* ECMA-262 3rd Edition 12.12 */
1002 HRESULT labelled_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
1004 FIXME("\n");
1005 return E_NOTIMPL;
1008 /* ECMA-262 3rd Edition 12.13 */
1009 HRESULT switch_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1011 switch_statement_t *stat = (switch_statement_t*)_stat;
1012 case_clausule_t *iter, *default_clausule = NULL;
1013 statement_t *stat_iter;
1014 VARIANT val, cval;
1015 exprval_t exprval;
1016 BOOL b;
1017 HRESULT hres;
1019 TRACE("\n");
1021 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1022 if(FAILED(hres))
1023 return hres;
1025 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1026 exprval_release(&exprval);
1027 if(FAILED(hres))
1028 return hres;
1030 for(iter = stat->case_list; iter; iter = iter->next) {
1031 if(!iter->expr) {
1032 default_clausule = iter;
1033 continue;
1036 hres = expr_eval(ctx, iter->expr, 0, &rt->ei, &exprval);
1037 if(FAILED(hres))
1038 break;
1040 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &cval);
1041 exprval_release(&exprval);
1042 if(FAILED(hres))
1043 break;
1045 hres = equal2_values(&val, &cval, &b);
1046 VariantClear(&cval);
1047 if(FAILED(hres) || b)
1048 break;
1051 VariantClear(&val);
1052 if(FAILED(hres))
1053 return hres;
1055 if(!iter)
1056 iter = default_clausule;
1058 V_VT(&val) = VT_EMPTY;
1059 if(iter) {
1060 VARIANT tmp;
1062 for(stat_iter = iter->stat; stat_iter; stat_iter = stat_iter->next) {
1063 hres = stat_eval(ctx, stat_iter, rt, &tmp);
1064 if(FAILED(hres))
1065 break;
1067 VariantClear(&val);
1068 val = tmp;
1070 if(rt->type != RT_NORMAL)
1071 break;
1075 if(FAILED(hres)) {
1076 VariantClear(&val);
1077 return hres;
1080 if(rt->type == RT_BREAK)
1081 rt->type = RT_NORMAL;
1083 *ret = val;
1084 return S_OK;
1087 /* ECMA-262 3rd Edition 12.13 */
1088 HRESULT throw_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1090 expression_statement_t *stat = (expression_statement_t*)_stat;
1091 exprval_t exprval;
1092 VARIANT val;
1093 HRESULT hres;
1095 TRACE("\n");
1097 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1098 if(FAILED(hres))
1099 return hres;
1101 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1102 exprval_release(&exprval);
1103 if(FAILED(hres))
1104 return hres;
1106 rt->ei.var = val;
1107 return DISP_E_EXCEPTION;
1110 /* ECMA-262 3rd Edition 12.14 */
1111 static HRESULT catch_eval(exec_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
1113 DispatchEx *var_disp;
1114 VARIANT ex, val;
1115 HRESULT hres;
1117 ex = rt->ei.var;
1118 memset(&rt->ei, 0, sizeof(jsexcept_t));
1120 hres = create_dispex(ctx->parser->script, NULL, NULL, &var_disp);
1121 if(SUCCEEDED(hres)) {
1122 hres = jsdisp_propput_name(var_disp, block->identifier, ctx->parser->script->lcid,
1123 &ex, &rt->ei, NULL/*FIXME*/);
1124 if(SUCCEEDED(hres)) {
1125 hres = scope_push(ctx->scope_chain, var_disp, &ctx->scope_chain);
1126 if(SUCCEEDED(hres)) {
1127 hres = stat_eval(ctx, block->statement, rt, &val);
1128 scope_pop(&ctx->scope_chain);
1132 jsdisp_release(var_disp);
1135 VariantClear(&ex);
1136 if(FAILED(hres))
1137 return hres;
1139 *ret = val;
1140 return S_OK;
1143 /* ECMA-262 3rd Edition 12.14 */
1144 HRESULT try_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1146 try_statement_t *stat = (try_statement_t*)_stat;
1147 VARIANT val;
1148 HRESULT hres;
1150 TRACE("\n");
1152 hres = stat_eval(ctx, stat->try_statement, rt, &val);
1153 if(FAILED(hres)) {
1154 TRACE("EXCEPTION\n");
1155 if(!stat->catch_block)
1156 return hres;
1158 hres = catch_eval(ctx, stat->catch_block, rt, &val);
1159 if(FAILED(hres))
1160 return hres;
1163 if(stat->finally_statement) {
1164 VariantClear(&val);
1165 hres = stat_eval(ctx, stat->finally_statement, rt, &val);
1166 if(FAILED(hres))
1167 return hres;
1170 *ret = val;
1171 return S_OK;
1174 static HRESULT return_bool(exprval_t *ret, DWORD b)
1176 ret->type = EXPRVAL_VARIANT;
1177 V_VT(&ret->u.var) = VT_BOOL;
1178 V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;
1180 return S_OK;
1183 static HRESULT get_binary_expr_values(exec_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
1185 exprval_t exprval;
1186 HRESULT hres;
1188 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1189 if(FAILED(hres))
1190 return hres;
1192 hres = exprval_to_value(ctx->parser->script, &exprval, ei, lval);
1193 exprval_release(&exprval);
1194 if(FAILED(hres))
1195 return hres;
1197 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1198 if(SUCCEEDED(hres)) {
1199 hres = exprval_to_value(ctx->parser->script, &exprval, ei, rval);
1200 exprval_release(&exprval);
1203 if(FAILED(hres)) {
1204 VariantClear(lval);
1205 return hres;
1208 return S_OK;
1211 typedef HRESULT (*oper_t)(exec_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);
1213 static HRESULT binary_expr_eval(exec_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
1214 exprval_t *ret)
1216 VARIANT lval, rval, retv;
1217 HRESULT hres;
1219 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1220 if(FAILED(hres))
1221 return hres;
1223 hres = oper(ctx, &lval, &rval, ei, &retv);
1224 VariantClear(&lval);
1225 VariantClear(&rval);
1226 if(FAILED(hres))
1227 return hres;
1229 ret->type = EXPRVAL_VARIANT;
1230 ret->u.var = retv;
1231 return S_OK;
1234 /* ECMA-262 3rd Edition 11.13.2 */
1235 static HRESULT assign_oper_eval(exec_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
1236 jsexcept_t *ei, exprval_t *ret)
1238 VARIANT retv, lval, rval;
1239 exprval_t exprval, exprvalr;
1240 HRESULT hres;
1242 hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
1243 if(FAILED(hres))
1244 return hres;
1246 hres = exprval_value(ctx->parser->script, &exprval, ei, &lval);
1247 if(SUCCEEDED(hres)) {
1248 hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
1249 if(SUCCEEDED(hres)) {
1250 hres = exprval_value(ctx->parser->script, &exprvalr, ei, &rval);
1251 exprval_release(&exprvalr);
1253 if(SUCCEEDED(hres)) {
1254 hres = oper(ctx, &lval, &rval, ei, &retv);
1255 VariantClear(&rval);
1257 VariantClear(&lval);
1260 if(SUCCEEDED(hres)) {
1261 hres = put_value(ctx->parser->script, &exprval, &retv, ei);
1262 if(FAILED(hres))
1263 VariantClear(&retv);
1265 exprval_release(&exprval);
1267 if(FAILED(hres))
1268 return hres;
1270 ret->type = EXPRVAL_VARIANT;
1271 ret->u.var = retv;
1272 return S_OK;
1275 /* ECMA-262 3rd Edition 13 */
1276 HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1278 function_expression_t *expr = (function_expression_t*)_expr;
1279 VARIANT var;
1280 HRESULT hres;
1282 TRACE("\n");
1284 if(expr->identifier) {
1285 hres = jsdisp_propget_name(ctx->var_disp, expr->identifier, ctx->parser->script->lcid, &var, ei, NULL/*FIXME*/);
1286 if(FAILED(hres))
1287 return hres;
1288 }else {
1289 DispatchEx *dispex;
1291 hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain,
1292 expr->src_str, expr->src_len, &dispex);
1293 if(FAILED(hres))
1294 return hres;
1296 V_VT(&var) = VT_DISPATCH;
1297 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
1300 ret->type = EXPRVAL_VARIANT;
1301 ret->u.var = var;
1302 return S_OK;
1305 /* ECMA-262 3rd Edition 11.12 */
1306 HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1308 conditional_expression_t *expr = (conditional_expression_t*)_expr;
1309 exprval_t exprval;
1310 VARIANT_BOOL b;
1311 HRESULT hres;
1313 TRACE("\n");
1315 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1316 if(FAILED(hres))
1317 return hres;
1319 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
1320 exprval_release(&exprval);
1321 if(FAILED(hres))
1322 return hres;
1324 return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
1327 /* ECMA-262 3rd Edition 11.2.1 */
1328 HRESULT array_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1330 array_expression_t *expr = (array_expression_t*)_expr;
1331 exprval_t exprval;
1332 VARIANT member, val;
1333 DISPID id;
1334 BSTR str;
1335 IDispatch *obj = NULL;
1336 HRESULT hres;
1338 TRACE("\n");
1340 hres = expr_eval(ctx, expr->member_expr, EXPR_NEWREF, ei, &exprval);
1341 if(FAILED(hres))
1342 return hres;
1344 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1345 exprval_release(&exprval);
1346 if(FAILED(hres))
1347 return hres;
1349 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
1350 if(SUCCEEDED(hres)) {
1351 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1352 exprval_release(&exprval);
1355 if(SUCCEEDED(hres))
1356 hres = to_object(ctx, &member, &obj);
1357 VariantClear(&member);
1358 if(SUCCEEDED(hres)) {
1359 hres = to_string(ctx->parser->script, &val, ei, &str);
1360 if(SUCCEEDED(hres)) {
1361 if(flags & EXPR_STRREF) {
1362 ret->type = EXPRVAL_NAMEREF;
1363 ret->u.nameref.disp = obj;
1364 ret->u.nameref.name = str;
1365 return S_OK;
1368 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1371 if(SUCCEEDED(hres)) {
1372 exprval_set_idref(ret, obj, id);
1373 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1374 exprval_init(ret);
1375 hres = S_OK;
1378 IDispatch_Release(obj);
1381 return hres;
1384 /* ECMA-262 3rd Edition 11.2.1 */
1385 HRESULT member_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1387 member_expression_t *expr = (member_expression_t*)_expr;
1388 IDispatch *obj = NULL;
1389 exprval_t exprval;
1390 VARIANT member;
1391 DISPID id;
1392 BSTR str;
1393 HRESULT hres;
1395 TRACE("\n");
1397 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1398 if(FAILED(hres))
1399 return hres;
1401 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1402 exprval_release(&exprval);
1403 if(FAILED(hres))
1404 return hres;
1406 hres = to_object(ctx, &member, &obj);
1407 VariantClear(&member);
1408 if(FAILED(hres))
1409 return hres;
1411 str = SysAllocString(expr->identifier);
1412 if(flags & EXPR_STRREF) {
1413 ret->type = EXPRVAL_NAMEREF;
1414 ret->u.nameref.disp = obj;
1415 ret->u.nameref.name = str;
1416 return S_OK;
1419 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1420 SysFreeString(str);
1421 if(SUCCEEDED(hres)) {
1422 exprval_set_idref(ret, obj, id);
1423 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1424 exprval_init(ret);
1425 hres = S_OK;
1428 IDispatch_Release(obj);
1429 return hres;
1432 static void free_dp(DISPPARAMS *dp)
1434 DWORD i;
1436 for(i=0; i < dp->cArgs; i++)
1437 VariantClear(dp->rgvarg+i);
1438 heap_free(dp->rgvarg);
1441 static HRESULT args_to_param(exec_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
1443 VARIANTARG *vargs;
1444 exprval_t exprval;
1445 argument_t *iter;
1446 DWORD cnt = 0, i;
1447 HRESULT hres = S_OK;
1449 memset(dp, 0, sizeof(*dp));
1450 if(!args)
1451 return S_OK;
1453 for(iter = args; iter; iter = iter->next)
1454 cnt++;
1456 vargs = heap_alloc_zero(cnt * sizeof(*vargs));
1457 if(!vargs)
1458 return E_OUTOFMEMORY;
1460 for(i = cnt, iter = args; iter; iter = iter->next) {
1461 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
1462 if(FAILED(hres))
1463 break;
1465 hres = exprval_to_value(ctx->parser->script, &exprval, ei, vargs + (--i));
1466 exprval_release(&exprval);
1467 if(FAILED(hres))
1468 break;
1471 if(FAILED(hres)) {
1472 free_dp(dp);
1473 return hres;
1476 dp->rgvarg = vargs;
1477 dp->cArgs = cnt;
1478 return S_OK;
1481 /* ECMA-262 3rd Edition 11.2.2 */
1482 HRESULT new_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1484 call_expression_t *expr = (call_expression_t*)_expr;
1485 exprval_t exprval;
1486 VARIANT constr, var;
1487 DISPPARAMS dp;
1488 HRESULT hres;
1490 TRACE("\n");
1492 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1493 if(FAILED(hres))
1494 return hres;
1496 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1497 if(SUCCEEDED(hres))
1498 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &constr);
1499 exprval_release(&exprval);
1500 if(FAILED(hres))
1501 return hres;
1503 if(V_VT(&constr) != VT_DISPATCH) {
1504 FIXME("throw TypeError\n");
1505 VariantClear(&constr);
1506 return E_FAIL;
1509 hres = disp_call(V_DISPATCH(&constr), DISPID_VALUE, ctx->parser->script->lcid,
1510 DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
1511 IDispatch_Release(V_DISPATCH(&constr));
1512 if(FAILED(hres))
1513 return hres;
1515 ret->type = EXPRVAL_VARIANT;
1516 ret->u.var = var;
1517 return S_OK;
1520 /* ECMA-262 3rd Edition 11.2.3 */
1521 HRESULT call_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1523 call_expression_t *expr = (call_expression_t*)_expr;
1524 VARIANT var;
1525 exprval_t exprval;
1526 DISPPARAMS dp;
1527 HRESULT hres;
1529 TRACE("\n");
1531 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1532 if(FAILED(hres))
1533 return hres;
1535 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1536 if(SUCCEEDED(hres)) {
1537 switch(exprval.type) {
1538 case EXPRVAL_VARIANT:
1539 if(V_VT(&exprval.u.var) != VT_DISPATCH)
1540 return throw_type_error(ctx->var_disp->ctx, ei, IDS_NO_PROPERTY, NULL);
1542 hres = disp_call(V_DISPATCH(&exprval.u.var), DISPID_VALUE, ctx->parser->script->lcid,
1543 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1544 break;
1545 case EXPRVAL_IDREF:
1546 hres = disp_call(exprval.u.idref.disp, exprval.u.idref.id, ctx->parser->script->lcid,
1547 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1548 break;
1549 default:
1550 FIXME("unimplemented type %d\n", exprval.type);
1551 hres = E_NOTIMPL;
1554 free_dp(&dp);
1557 exprval_release(&exprval);
1558 if(FAILED(hres))
1559 return hres;
1561 ret->type = EXPRVAL_VARIANT;
1562 if(flags & EXPR_NOVAL) {
1563 V_VT(&ret->u.var) = VT_EMPTY;
1564 }else {
1565 TRACE("= %s\n", debugstr_variant(&var));
1566 ret->u.var = var;
1568 return S_OK;
1571 /* ECMA-262 3rd Edition 11.1.1 */
1572 HRESULT this_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1574 TRACE("\n");
1576 ret->type = EXPRVAL_VARIANT;
1577 V_VT(&ret->u.var) = VT_DISPATCH;
1578 V_DISPATCH(&ret->u.var) = ctx->this_obj;
1579 IDispatch_AddRef(ctx->this_obj);
1580 return S_OK;
1583 /* ECMA-262 3rd Edition 10.1.4 */
1584 HRESULT identifier_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1586 identifier_expression_t *expr = (identifier_expression_t*)_expr;
1587 BSTR identifier;
1588 HRESULT hres;
1590 TRACE("\n");
1592 identifier = SysAllocString(expr->identifier);
1593 if(!identifier)
1594 return E_OUTOFMEMORY;
1596 hres = identifier_eval(ctx, identifier, flags, ei, ret);
1598 SysFreeString(identifier);
1599 return hres;
1602 /* ECMA-262 3rd Edition 7.8 */
1603 HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1605 literal_expression_t *expr = (literal_expression_t*)_expr;
1606 VARIANT var;
1607 HRESULT hres;
1609 TRACE("\n");
1611 hres = literal_to_var(expr->literal, &var);
1612 if(FAILED(hres))
1613 return hres;
1615 ret->type = EXPRVAL_VARIANT;
1616 ret->u.var = var;
1617 return S_OK;
1620 /* ECMA-262 3rd Edition 11.1.4 */
1621 HRESULT array_literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1623 array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
1624 DWORD length = 0, i = 0;
1625 array_element_t *elem;
1626 DispatchEx *array;
1627 exprval_t exprval;
1628 VARIANT val;
1629 HRESULT hres;
1631 TRACE("\n");
1633 for(elem = expr->element_list; elem; elem = elem->next)
1634 length += elem->elision+1;
1635 length += expr->length;
1637 hres = create_array(ctx->parser->script, length, &array);
1638 if(FAILED(hres))
1639 return hres;
1641 for(elem = expr->element_list; elem; elem = elem->next) {
1642 i += elem->elision;
1644 hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
1645 if(FAILED(hres))
1646 break;
1648 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1649 exprval_release(&exprval);
1650 if(FAILED(hres))
1651 break;
1653 hres = jsdisp_propput_idx(array, i, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1654 VariantClear(&val);
1655 if(FAILED(hres))
1656 break;
1658 i++;
1661 if(FAILED(hres)) {
1662 jsdisp_release(array);
1663 return hres;
1666 ret->type = EXPRVAL_VARIANT;
1667 V_VT(&ret->u.var) = VT_DISPATCH;
1668 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(array);
1669 return S_OK;
1672 /* ECMA-262 3rd Edition 11.1.5 */
1673 HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1675 property_value_expression_t *expr = (property_value_expression_t*)_expr;
1676 VARIANT val, tmp;
1677 DispatchEx *obj;
1678 prop_val_t *iter;
1679 exprval_t exprval;
1680 BSTR name;
1681 HRESULT hres;
1683 TRACE("\n");
1685 hres = create_object(ctx->parser->script, NULL, &obj);
1686 if(FAILED(hres))
1687 return hres;
1689 for(iter = expr->property_list; iter; iter = iter->next) {
1690 hres = literal_to_var(iter->name, &tmp);
1691 if(FAILED(hres))
1692 break;
1694 hres = to_string(ctx->parser->script, &tmp, ei, &name);
1695 VariantClear(&tmp);
1696 if(FAILED(hres))
1697 break;
1699 hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
1700 if(SUCCEEDED(hres)) {
1701 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1702 exprval_release(&exprval);
1703 if(SUCCEEDED(hres)) {
1704 hres = jsdisp_propput_name(obj, name, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1705 VariantClear(&val);
1709 SysFreeString(name);
1710 if(FAILED(hres))
1711 break;
1714 if(FAILED(hres)) {
1715 jsdisp_release(obj);
1716 return hres;
1719 ret->type = EXPRVAL_VARIANT;
1720 V_VT(&ret->u.var) = VT_DISPATCH;
1721 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(obj);
1722 return S_OK;
1725 /* ECMA-262 3rd Edition 11.14 */
1726 HRESULT comma_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1728 binary_expression_t *expr = (binary_expression_t*)_expr;
1729 VARIANT lval, rval;
1730 HRESULT hres;
1732 TRACE("\n");
1734 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1735 if(FAILED(hres))
1736 return hres;
1738 VariantClear(&lval);
1740 ret->type = EXPRVAL_VARIANT;
1741 ret->u.var = rval;
1742 return S_OK;
1745 /* ECMA-262 3rd Edition 11.11 */
1746 HRESULT logical_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1748 binary_expression_t *expr = (binary_expression_t*)_expr;
1749 exprval_t exprval;
1750 VARIANT_BOOL b;
1751 VARIANT val;
1752 HRESULT hres;
1754 TRACE("\n");
1756 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1757 if(FAILED(hres))
1758 return hres;
1760 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1761 exprval_release(&exprval);
1762 if(FAILED(hres))
1763 return hres;
1765 hres = to_boolean(&val, &b);
1766 if(SUCCEEDED(hres) && b) {
1767 ret->type = EXPRVAL_VARIANT;
1768 ret->u.var = val;
1769 return S_OK;
1772 VariantClear(&val);
1773 if(FAILED(hres))
1774 return hres;
1776 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1777 if(FAILED(hres))
1778 return hres;
1780 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1781 exprval_release(&exprval);
1782 if(FAILED(hres))
1783 return hres;
1785 ret->type = EXPRVAL_VARIANT;
1786 ret->u.var = val;
1787 return S_OK;
1790 /* ECMA-262 3rd Edition 11.11 */
1791 HRESULT logical_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1793 binary_expression_t *expr = (binary_expression_t*)_expr;
1794 exprval_t exprval;
1795 VARIANT_BOOL b;
1796 VARIANT val;
1797 HRESULT hres;
1799 TRACE("\n");
1801 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1802 if(FAILED(hres))
1803 return hres;
1805 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1806 exprval_release(&exprval);
1807 if(FAILED(hres))
1808 return hres;
1810 hres = to_boolean(&val, &b);
1811 if(SUCCEEDED(hres) && !b) {
1812 ret->type = EXPRVAL_VARIANT;
1813 ret->u.var = val;
1814 return S_OK;
1817 VariantClear(&val);
1818 if(FAILED(hres))
1819 return hres;
1821 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1822 if(FAILED(hres))
1823 return hres;
1825 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1826 exprval_release(&exprval);
1827 if(FAILED(hres))
1828 return hres;
1830 ret->type = EXPRVAL_VARIANT;
1831 ret->u.var = val;
1832 return S_OK;
1835 /* ECMA-262 3rd Edition 11.10 */
1836 static HRESULT bitor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1838 INT li, ri;
1839 HRESULT hres;
1841 hres = to_int32(ctx->parser->script, lval, ei, &li);
1842 if(FAILED(hres))
1843 return hres;
1845 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1846 if(FAILED(hres))
1847 return hres;
1849 V_VT(retv) = VT_I4;
1850 V_I4(retv) = li|ri;
1851 return S_OK;
1854 /* ECMA-262 3rd Edition 11.10 */
1855 HRESULT binary_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1857 binary_expression_t *expr = (binary_expression_t*)_expr;
1859 TRACE("\n");
1861 return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
1864 /* ECMA-262 3rd Edition 11.10 */
1865 static HRESULT xor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1867 INT li, ri;
1868 HRESULT hres;
1870 hres = to_int32(ctx->parser->script, lval, ei, &li);
1871 if(FAILED(hres))
1872 return hres;
1874 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1875 if(FAILED(hres))
1876 return hres;
1878 V_VT(retv) = VT_I4;
1879 V_I4(retv) = li^ri;
1880 return S_OK;
1883 /* ECMA-262 3rd Edition 11.10 */
1884 HRESULT binary_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1886 binary_expression_t *expr = (binary_expression_t*)_expr;
1888 TRACE("\n");
1890 return binary_expr_eval(ctx, expr, xor_eval, ei, ret);
1893 /* ECMA-262 3rd Edition 11.10 */
1894 static HRESULT bitand_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1896 INT li, ri;
1897 HRESULT hres;
1899 hres = to_int32(ctx->parser->script, lval, ei, &li);
1900 if(FAILED(hres))
1901 return hres;
1903 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1904 if(FAILED(hres))
1905 return hres;
1907 V_VT(retv) = VT_I4;
1908 V_I4(retv) = li&ri;
1909 return S_OK;
1912 /* ECMA-262 3rd Edition 11.10 */
1913 HRESULT binary_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1915 binary_expression_t *expr = (binary_expression_t*)_expr;
1917 TRACE("\n");
1919 return binary_expr_eval(ctx, expr, bitand_eval, ei, ret);
1922 /* ECMA-262 3rd Edition 11.8.6 */
1923 HRESULT instanceof_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1925 FIXME("\n");
1926 return E_NOTIMPL;
1929 /* ECMA-262 3rd Edition 11.8.7 */
1930 HRESULT in_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1932 FIXME("\n");
1933 return E_NOTIMPL;
1936 /* ECMA-262 3rd Edition 11.6.1 */
1937 static HRESULT add_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1939 VARIANT r, l;
1940 HRESULT hres;
1942 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
1943 if(FAILED(hres))
1944 return hres;
1946 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
1947 if(FAILED(hres)) {
1948 VariantClear(&l);
1949 return hres;
1952 if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
1953 BSTR lstr = NULL, rstr = NULL;
1955 if(V_VT(&l) == VT_BSTR)
1956 lstr = V_BSTR(&l);
1957 else
1958 hres = to_string(ctx->parser->script, &l, ei, &lstr);
1960 if(SUCCEEDED(hres)) {
1961 if(V_VT(&r) == VT_BSTR)
1962 rstr = V_BSTR(&r);
1963 else
1964 hres = to_string(ctx->parser->script, &r, ei, &rstr);
1967 if(SUCCEEDED(hres)) {
1968 int len1, len2;
1970 len1 = SysStringLen(lstr);
1971 len2 = SysStringLen(rstr);
1973 V_VT(retv) = VT_BSTR;
1974 V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
1975 memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
1976 memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
1979 if(V_VT(&l) != VT_BSTR)
1980 SysFreeString(lstr);
1981 if(V_VT(&r) != VT_BSTR)
1982 SysFreeString(rstr);
1983 }else {
1984 VARIANT nl, nr;
1986 hres = to_number(ctx->parser->script, &l, ei, &nl);
1987 if(SUCCEEDED(hres)) {
1988 hres = to_number(ctx->parser->script, &r, ei, &nr);
1989 if(SUCCEEDED(hres))
1990 num_set_val(retv, num_val(&nl) + num_val(&nr));
1994 VariantClear(&r);
1995 VariantClear(&l);
1996 return hres;
1999 /* ECMA-262 3rd Edition 11.6.1 */
2000 HRESULT add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2002 binary_expression_t *expr = (binary_expression_t*)_expr;
2004 TRACE("\n");
2006 return binary_expr_eval(ctx, expr, add_eval, ei, ret);
2009 /* ECMA-262 3rd Edition 11.6.2 */
2010 static HRESULT sub_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2012 VARIANT lnum, rnum;
2013 HRESULT hres;
2015 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2016 if(FAILED(hres))
2017 return hres;
2019 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2020 if(FAILED(hres))
2021 return hres;
2023 num_set_val(retv, num_val(&lnum) - num_val(&rnum));
2024 return S_OK;
2027 /* ECMA-262 3rd Edition 11.6.2 */
2028 HRESULT sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2030 binary_expression_t *expr = (binary_expression_t*)_expr;
2032 TRACE("\n");
2034 return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
2037 /* ECMA-262 3rd Edition 11.5.1 */
2038 static HRESULT mul_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2040 VARIANT lnum, rnum;
2041 HRESULT hres;
2043 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2044 if(FAILED(hres))
2045 return hres;
2047 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2048 if(FAILED(hres))
2049 return hres;
2051 num_set_val(retv, num_val(&lnum) * num_val(&rnum));
2052 return S_OK;
2055 /* ECMA-262 3rd Edition 11.5.1 */
2056 HRESULT mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2058 binary_expression_t *expr = (binary_expression_t*)_expr;
2060 TRACE("\n");
2062 return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
2065 /* ECMA-262 3rd Edition 11.5.2 */
2066 static HRESULT div_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2068 VARIANT lnum, rnum;
2069 HRESULT hres;
2071 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2072 if(FAILED(hres))
2073 return hres;
2075 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2076 if(FAILED(hres))
2077 return hres;
2079 num_set_val(retv, num_val(&lnum) / num_val(&rnum));
2080 return S_OK;
2083 /* ECMA-262 3rd Edition 11.5.2 */
2084 HRESULT div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2086 binary_expression_t *expr = (binary_expression_t*)_expr;
2088 TRACE("\n");
2090 return binary_expr_eval(ctx, expr, div_eval, ei, ret);
2093 /* ECMA-262 3rd Edition 11.5.3 */
2094 static HRESULT mod_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2096 VARIANT lnum, rnum;
2097 HRESULT hres;
2099 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2100 if(FAILED(hres))
2101 return hres;
2103 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2104 if(FAILED(hres))
2105 return hres;
2107 num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
2108 return S_OK;
2111 /* ECMA-262 3rd Edition 11.5.3 */
2112 HRESULT mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2114 binary_expression_t *expr = (binary_expression_t*)_expr;
2116 TRACE("\n");
2118 return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
2121 /* ECMA-262 3rd Edition 11.4.2 */
2122 HRESULT delete_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2124 unary_expression_t *expr = (unary_expression_t*)_expr;
2125 VARIANT_BOOL b = VARIANT_FALSE;
2126 exprval_t exprval;
2127 HRESULT hres;
2129 TRACE("\n");
2131 hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
2132 if(FAILED(hres))
2133 return hres;
2135 switch(exprval.type) {
2136 case EXPRVAL_IDREF: {
2137 IDispatchEx *dispex;
2139 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2140 if(SUCCEEDED(hres)) {
2141 hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
2142 b = VARIANT_TRUE;
2143 IDispatchEx_Release(dispex);
2145 break;
2147 case EXPRVAL_NAMEREF: {
2148 IDispatchEx *dispex;
2150 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2151 if(SUCCEEDED(hres)) {
2152 hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name, fdexNameCaseSensitive);
2153 b = VARIANT_TRUE;
2154 IDispatchEx_Release(dispex);
2156 break;
2158 default:
2159 FIXME("unsupported type %d\n", exprval.type);
2160 hres = E_NOTIMPL;
2163 exprval_release(&exprval);
2164 if(FAILED(hres))
2165 return hres;
2167 return return_bool(ret, b);
2170 /* ECMA-262 3rd Edition 11.4.2 */
2171 HRESULT void_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2173 unary_expression_t *expr = (unary_expression_t*)_expr;
2174 exprval_t exprval;
2175 VARIANT tmp;
2176 HRESULT hres;
2178 TRACE("\n");
2180 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2181 if(FAILED(hres))
2182 return hres;
2184 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &tmp);
2185 exprval_release(&exprval);
2186 if(FAILED(hres))
2187 return hres;
2189 VariantClear(&tmp);
2191 ret->type = EXPRVAL_VARIANT;
2192 V_VT(&ret->u.var) = VT_EMPTY;
2193 return S_OK;
2196 /* ECMA-262 3rd Edition 11.4.3 */
2197 HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2199 unary_expression_t *expr = (unary_expression_t*)_expr;
2200 const WCHAR *str;
2201 exprval_t exprval;
2202 VARIANT val;
2203 HRESULT hres;
2205 static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
2206 static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
2207 static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
2208 static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
2209 static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
2210 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
2212 TRACE("\n");
2214 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2215 if(FAILED(hres))
2216 return hres;
2218 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2219 exprval_release(&exprval);
2220 if(FAILED(hres))
2221 return hres;
2223 switch(V_VT(&val)) {
2224 case VT_EMPTY:
2225 str = undefinedW;
2226 break;
2227 case VT_NULL:
2228 str = objectW;
2229 break;
2230 case VT_BOOL:
2231 str = booleanW;
2232 break;
2233 case VT_I4:
2234 case VT_R8:
2235 str = numberW;
2236 break;
2237 case VT_BSTR:
2238 str = stringW;
2239 break;
2240 case VT_DISPATCH: {
2241 DispatchEx *dispex;
2243 dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val));
2244 if(dispex) {
2245 str = dispex->builtin_info->class == JSCLASS_FUNCTION ? functionW : objectW;
2246 IDispatchEx_Release(_IDispatchEx_(dispex));
2247 }else {
2248 str = objectW;
2250 break;
2252 default:
2253 FIXME("unhandled vt %d\n", V_VT(&val));
2254 VariantClear(&val);
2255 return E_NOTIMPL;
2258 VariantClear(&val);
2260 ret->type = EXPRVAL_VARIANT;
2261 V_VT(&ret->u.var) = VT_BSTR;
2262 V_BSTR(&ret->u.var) = SysAllocString(str);
2263 return S_OK;
2266 /* ECMA-262 3rd Edition 11.4.7 */
2267 HRESULT minus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2269 unary_expression_t *expr = (unary_expression_t*)_expr;
2270 exprval_t exprval;
2271 VARIANT val, num;
2272 HRESULT hres;
2274 TRACE("\n");
2276 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2277 if(FAILED(hres))
2278 return hres;
2280 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2281 exprval_release(&exprval);
2282 if(FAILED(hres))
2283 return hres;
2285 hres = to_number(ctx->parser->script, &val, ei, &num);
2286 VariantClear(&val);
2287 if(FAILED(hres))
2288 return hres;
2290 ret->type = EXPRVAL_VARIANT;
2291 num_set_val(&ret->u.var, -num_val(&num));
2292 return S_OK;
2295 /* ECMA-262 3rd Edition 11.4.6 */
2296 HRESULT plus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2298 unary_expression_t *expr = (unary_expression_t*)_expr;
2299 exprval_t exprval;
2300 VARIANT val, num;
2301 HRESULT hres;
2303 TRACE("\n");
2305 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2306 if(FAILED(hres))
2307 return hres;
2309 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2310 exprval_release(&exprval);
2311 if(FAILED(hres))
2312 return hres;
2314 hres = to_number(ctx->parser->script, &val, ei, &num);
2315 if(FAILED(hres))
2316 return hres;
2318 ret->type = EXPRVAL_VARIANT;
2319 ret->u.var = num;
2320 return S_OK;
2323 /* ECMA-262 3rd Edition 11.3.1 */
2324 HRESULT post_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2326 unary_expression_t *expr = (unary_expression_t*)_expr;
2327 VARIANT val, num;
2328 exprval_t exprval;
2329 HRESULT hres;
2331 TRACE("\n");
2333 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2334 if(FAILED(hres))
2335 return hres;
2337 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2338 if(SUCCEEDED(hres)) {
2339 hres = to_number(ctx->parser->script, &val, ei, &num);
2340 VariantClear(&val);
2343 if(SUCCEEDED(hres)) {
2344 VARIANT inc;
2345 num_set_val(&inc, num_val(&num)+1.0);
2346 hres = put_value(ctx->parser->script, &exprval, &inc, ei);
2349 exprval_release(&exprval);
2350 if(FAILED(hres))
2351 return hres;
2353 ret->type = EXPRVAL_VARIANT;
2354 ret->u.var = num;
2355 return S_OK;
2358 /* ECMA-262 3rd Edition 11.3.2 */
2359 HRESULT post_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2361 unary_expression_t *expr = (unary_expression_t*)_expr;
2362 VARIANT val, num;
2363 exprval_t exprval;
2364 HRESULT hres;
2366 TRACE("\n");
2368 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2369 if(FAILED(hres))
2370 return hres;
2372 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2373 if(SUCCEEDED(hres)) {
2374 hres = to_number(ctx->parser->script, &val, ei, &num);
2375 VariantClear(&val);
2378 if(SUCCEEDED(hres)) {
2379 VARIANT dec;
2380 num_set_val(&dec, num_val(&num)-1.0);
2381 hres = put_value(ctx->parser->script, &exprval, &dec, ei);
2384 exprval_release(&exprval);
2385 if(FAILED(hres))
2386 return hres;
2388 ret->type = EXPRVAL_VARIANT;
2389 ret->u.var = num;
2390 return S_OK;
2393 /* ECMA-262 3rd Edition 11.4.4 */
2394 HRESULT pre_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2396 unary_expression_t *expr = (unary_expression_t*)_expr;
2397 VARIANT val, num;
2398 exprval_t exprval;
2399 HRESULT hres;
2401 TRACE("\n");
2403 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2404 if(FAILED(hres))
2405 return hres;
2407 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2408 if(SUCCEEDED(hres)) {
2409 hres = to_number(ctx->parser->script, &val, ei, &num);
2410 VariantClear(&val);
2413 if(SUCCEEDED(hres)) {
2414 num_set_val(&val, num_val(&num)+1.0);
2415 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2418 exprval_release(&exprval);
2419 if(FAILED(hres))
2420 return hres;
2422 ret->type = EXPRVAL_VARIANT;
2423 ret->u.var = val;
2424 return S_OK;
2427 /* ECMA-262 3rd Edition 11.4.5 */
2428 HRESULT pre_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2430 unary_expression_t *expr = (unary_expression_t*)_expr;
2431 VARIANT val, num;
2432 exprval_t exprval;
2433 HRESULT hres;
2435 TRACE("\n");
2437 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2438 if(FAILED(hres))
2439 return hres;
2441 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2442 if(SUCCEEDED(hres)) {
2443 hres = to_number(ctx->parser->script, &val, ei, &num);
2444 VariantClear(&val);
2447 if(SUCCEEDED(hres)) {
2448 num_set_val(&val, num_val(&num)-1.0);
2449 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2452 exprval_release(&exprval);
2453 if(FAILED(hres))
2454 return hres;
2456 ret->type = EXPRVAL_VARIANT;
2457 ret->u.var = val;
2458 return S_OK;
2461 /* ECMA-262 3rd Edition 11.9.3 */
2462 static HRESULT equal_values(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
2464 if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
2465 return equal2_values(lval, rval, ret);
2467 /* FIXME: NULL disps should be handled in more general way */
2468 if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
2469 VARIANT v;
2470 V_VT(&v) = VT_NULL;
2471 return equal_values(ctx, &v, rval, ei, ret);
2474 if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
2475 VARIANT v;
2476 V_VT(&v) = VT_NULL;
2477 return equal_values(ctx, lval, &v, ei, ret);
2480 if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
2481 (V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
2482 *ret = TRUE;
2483 return S_OK;
2486 if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
2487 VARIANT v;
2488 HRESULT hres;
2490 hres = to_number(ctx->parser->script, lval, ei, &v);
2491 if(FAILED(hres))
2492 return hres;
2494 return equal_values(ctx, &v, rval, ei, ret);
2497 if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
2498 VARIANT v;
2499 HRESULT hres;
2501 hres = to_number(ctx->parser->script, rval, ei, &v);
2502 if(FAILED(hres))
2503 return hres;
2505 return equal_values(ctx, lval, &v, ei, ret);
2508 if(V_VT(rval) == VT_BOOL) {
2509 VARIANT v;
2511 V_VT(&v) = VT_I4;
2512 V_I4(&v) = V_BOOL(rval) ? 1 : 0;
2513 return equal_values(ctx, lval, &v, ei, ret);
2516 if(V_VT(lval) == VT_BOOL) {
2517 VARIANT v;
2519 V_VT(&v) = VT_I4;
2520 V_I4(&v) = V_BOOL(lval) ? 1 : 0;
2521 return equal_values(ctx, &v, rval, ei, ret);
2525 if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
2526 VARIANT v;
2527 HRESULT hres;
2529 hres = to_primitive(ctx->parser->script, rval, ei, &v, NO_HINT);
2530 if(FAILED(hres))
2531 return hres;
2533 hres = equal_values(ctx, lval, &v, ei, ret);
2535 VariantClear(&v);
2536 return hres;
2540 if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
2541 VARIANT v;
2542 HRESULT hres;
2544 hres = to_primitive(ctx->parser->script, lval, ei, &v, NO_HINT);
2545 if(FAILED(hres))
2546 return hres;
2548 hres = equal_values(ctx, &v, rval, ei, ret);
2550 VariantClear(&v);
2551 return hres;
2555 *ret = FALSE;
2556 return S_OK;
2559 /* ECMA-262 3rd Edition 11.9.1 */
2560 HRESULT equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2562 binary_expression_t *expr = (binary_expression_t*)_expr;
2563 VARIANT rval, lval;
2564 BOOL b;
2565 HRESULT hres;
2567 TRACE("\n");
2569 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2570 if(FAILED(hres))
2571 return hres;
2573 hres = equal_values(ctx, &rval, &lval, ei, &b);
2574 if(FAILED(hres))
2575 return hres;
2577 return return_bool(ret, b);
2580 /* ECMA-262 3rd Edition 11.9.4 */
2581 HRESULT equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2583 binary_expression_t *expr = (binary_expression_t*)_expr;
2584 VARIANT rval, lval;
2585 BOOL b;
2586 HRESULT hres;
2588 TRACE("\n");
2590 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2591 if(FAILED(hres))
2592 return hres;
2594 hres = equal2_values(&rval, &lval, &b);
2595 if(FAILED(hres))
2596 return hres;
2598 return return_bool(ret, b);
2601 /* ECMA-262 3rd Edition 11.9.2 */
2602 HRESULT not_equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2604 binary_expression_t *expr = (binary_expression_t*)_expr;
2605 VARIANT rval, lval;
2606 BOOL b;
2607 HRESULT hres;
2609 TRACE("\n");
2611 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2612 if(FAILED(hres))
2613 return hres;
2615 hres = equal_values(ctx, &lval, &rval, ei, &b);
2616 if(FAILED(hres))
2617 return hres;
2619 return return_bool(ret, !b);
2622 /* ECMA-262 3rd Edition 11.9.5 */
2623 HRESULT not_equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2625 binary_expression_t *expr = (binary_expression_t*)_expr;
2626 VARIANT rval, lval;
2627 BOOL b;
2628 HRESULT hres;
2630 TRACE("\n");
2632 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2633 if(FAILED(hres))
2634 return hres;
2636 hres = equal2_values(&lval, &rval, &b);
2637 if(FAILED(hres))
2638 return hres;
2640 return return_bool(ret, !b);
2643 /* ECMA-262 3rd Edition 11.8.5 */
2644 static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
2646 VARIANT l, r, ln, rn;
2647 HRESULT hres;
2649 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
2650 if(FAILED(hres))
2651 return hres;
2653 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
2654 if(FAILED(hres)) {
2655 VariantClear(&l);
2656 return hres;
2659 if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
2660 *ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
2661 SysFreeString(V_BSTR(&l));
2662 SysFreeString(V_BSTR(&r));
2663 return S_OK;
2666 hres = to_number(ctx->parser->script, &l, ei, &ln);
2667 VariantClear(&l);
2668 if(SUCCEEDED(hres))
2669 hres = to_number(ctx->parser->script, &r, ei, &rn);
2670 VariantClear(&r);
2671 if(FAILED(hres))
2672 return hres;
2674 if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
2675 *ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
2676 }else {
2677 DOUBLE ld = num_val(&ln);
2678 DOUBLE rd = num_val(&rn);
2680 *ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
2683 return S_OK;
2686 /* ECMA-262 3rd Edition 11.8.1 */
2687 HRESULT less_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2689 binary_expression_t *expr = (binary_expression_t*)_expr;
2690 VARIANT rval, lval;
2691 BOOL b;
2692 HRESULT hres;
2694 TRACE("\n");
2696 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2697 if(FAILED(hres))
2698 return hres;
2700 hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
2701 VariantClear(&lval);
2702 VariantClear(&rval);
2703 if(FAILED(hres))
2704 return hres;
2706 return return_bool(ret, b);
2709 /* ECMA-262 3rd Edition 11.8.3 */
2710 HRESULT lesseq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2712 binary_expression_t *expr = (binary_expression_t*)_expr;
2713 VARIANT rval, lval;
2714 BOOL b;
2715 HRESULT hres;
2717 TRACE("\n");
2719 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2720 if(FAILED(hres))
2721 return hres;
2723 hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
2724 VariantClear(&lval);
2725 VariantClear(&rval);
2726 if(FAILED(hres))
2727 return hres;
2729 return return_bool(ret, b);
2732 /* ECMA-262 3rd Edition 11.8.2 */
2733 HRESULT greater_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2735 binary_expression_t *expr = (binary_expression_t*)_expr;
2736 VARIANT rval, lval;
2737 BOOL b;
2738 HRESULT hres;
2740 TRACE("\n");
2742 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2743 if(FAILED(hres))
2744 return hres;
2746 hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
2747 VariantClear(&lval);
2748 VariantClear(&rval);
2749 if(FAILED(hres))
2750 return hres;
2752 return return_bool(ret, b);
2755 /* ECMA-262 3rd Edition 11.8.4 */
2756 HRESULT greatereq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2758 binary_expression_t *expr = (binary_expression_t*)_expr;
2759 VARIANT rval, lval;
2760 BOOL b;
2761 HRESULT hres;
2763 TRACE("\n");
2765 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2766 if(FAILED(hres))
2767 return hres;
2769 hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
2770 VariantClear(&lval);
2771 VariantClear(&rval);
2772 if(FAILED(hres))
2773 return hres;
2775 return return_bool(ret, b);
2778 /* ECMA-262 3rd Edition 11.4.8 */
2779 HRESULT binary_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2781 unary_expression_t *expr = (unary_expression_t*)_expr;
2782 exprval_t exprval;
2783 VARIANT val;
2784 INT i;
2785 HRESULT hres;
2787 TRACE("\n");
2789 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2790 if(FAILED(hres))
2791 return hres;
2793 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2794 exprval_release(&exprval);
2795 if(FAILED(hres))
2796 return hres;
2798 hres = to_int32(ctx->parser->script, &val, ei, &i);
2799 if(FAILED(hres))
2800 return hres;
2802 ret->type = EXPRVAL_VARIANT;
2803 V_VT(&ret->u.var) = VT_I4;
2804 V_I4(&ret->u.var) = ~i;
2805 return S_OK;
2808 /* ECMA-262 3rd Edition 11.4.9 */
2809 HRESULT logical_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2811 unary_expression_t *expr = (unary_expression_t*)_expr;
2812 exprval_t exprval;
2813 VARIANT_BOOL b;
2814 HRESULT hres;
2816 TRACE("\n");
2818 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2819 if(FAILED(hres))
2820 return hres;
2822 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
2823 exprval_release(&exprval);
2824 if(FAILED(hres))
2825 return hres;
2827 return return_bool(ret, !b);
2830 /* ECMA-262 3rd Edition 11.7.1 */
2831 static HRESULT lshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2833 DWORD ri;
2834 INT li;
2835 HRESULT hres;
2837 hres = to_int32(ctx->parser->script, lval, ei, &li);
2838 if(FAILED(hres))
2839 return hres;
2841 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2842 if(FAILED(hres))
2843 return hres;
2845 V_VT(retv) = VT_I4;
2846 V_I4(retv) = li << (ri&0x1f);
2847 return S_OK;
2850 /* ECMA-262 3rd Edition 11.7.1 */
2851 HRESULT left_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2853 binary_expression_t *expr = (binary_expression_t*)_expr;
2855 TRACE("\n");
2857 return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
2860 /* ECMA-262 3rd Edition 11.7.2 */
2861 static HRESULT rshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2863 DWORD ri;
2864 INT li;
2865 HRESULT hres;
2867 hres = to_int32(ctx->parser->script, lval, ei, &li);
2868 if(FAILED(hres))
2869 return hres;
2871 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2872 if(FAILED(hres))
2873 return hres;
2875 V_VT(retv) = VT_I4;
2876 V_I4(retv) = li >> (ri&0x1f);
2877 return S_OK;
2880 /* ECMA-262 3rd Edition 11.7.2 */
2881 HRESULT right_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2883 binary_expression_t *expr = (binary_expression_t*)_expr;
2885 TRACE("\n");
2887 return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
2890 /* ECMA-262 3rd Edition 11.7.3 */
2891 static HRESULT rshift2_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2893 DWORD li, ri;
2894 HRESULT hres;
2896 hres = to_uint32(ctx->parser->script, lval, ei, &li);
2897 if(FAILED(hres))
2898 return hres;
2900 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2901 if(FAILED(hres))
2902 return hres;
2904 V_VT(retv) = VT_I4;
2905 V_I4(retv) = li >> (ri&0x1f);
2906 return S_OK;
2909 /* ECMA-262 3rd Edition 11.7.3 */
2910 HRESULT right2_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2912 binary_expression_t *expr = (binary_expression_t*)_expr;
2914 TRACE("\n");
2916 return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
2919 /* ECMA-262 3rd Edition 11.13.1 */
2920 HRESULT assign_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2922 binary_expression_t *expr = (binary_expression_t*)_expr;
2923 exprval_t exprval, exprvalr;
2924 VARIANT rval;
2925 HRESULT hres;
2927 TRACE("\n");
2929 hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
2930 if(FAILED(hres))
2931 return hres;
2933 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
2934 if(SUCCEEDED(hres)) {
2935 hres = exprval_to_value(ctx->parser->script, &exprvalr, ei, &rval);
2936 exprval_release(&exprvalr);
2939 if(SUCCEEDED(hres))
2940 hres = put_value(ctx->parser->script, &exprval, &rval, ei);
2942 exprval_release(&exprval);
2943 if(FAILED(hres))
2944 return hres;
2946 ret->type = EXPRVAL_VARIANT;
2947 ret->u.var = rval;
2948 return S_OK;
2951 /* ECMA-262 3rd Edition 11.13.2 */
2952 HRESULT assign_lshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2954 binary_expression_t *expr = (binary_expression_t*)_expr;
2956 TRACE("\n");
2958 return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
2961 /* ECMA-262 3rd Edition 11.13.2 */
2962 HRESULT assign_rshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2964 binary_expression_t *expr = (binary_expression_t*)_expr;
2966 TRACE("\n");
2968 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift_eval, ei, ret);
2971 /* ECMA-262 3rd Edition 11.13.2 */
2972 HRESULT assign_rrshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2974 binary_expression_t *expr = (binary_expression_t*)_expr;
2976 TRACE("\n");
2978 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift2_eval, ei, ret);
2981 /* ECMA-262 3rd Edition 11.13.2 */
2982 HRESULT assign_add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2984 binary_expression_t *expr = (binary_expression_t*)_expr;
2986 TRACE("\n");
2988 return assign_oper_eval(ctx, expr->expression1, expr->expression2, add_eval, ei, ret);
2991 /* ECMA-262 3rd Edition 11.13.2 */
2992 HRESULT assign_sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2994 binary_expression_t *expr = (binary_expression_t*)_expr;
2996 TRACE("\n");
2998 return assign_oper_eval(ctx, expr->expression1, expr->expression2, sub_eval, ei, ret);
3001 /* ECMA-262 3rd Edition 11.13.2 */
3002 HRESULT assign_mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3004 binary_expression_t *expr = (binary_expression_t*)_expr;
3006 TRACE("\n");
3008 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mul_eval, ei, ret);
3011 /* ECMA-262 3rd Edition 11.13.2 */
3012 HRESULT assign_div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3014 binary_expression_t *expr = (binary_expression_t*)_expr;
3016 TRACE("\n");
3018 return assign_oper_eval(ctx, expr->expression1, expr->expression2, div_eval, ei, ret);
3021 /* ECMA-262 3rd Edition 11.13.2 */
3022 HRESULT assign_mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3024 binary_expression_t *expr = (binary_expression_t*)_expr;
3026 TRACE("\n");
3028 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mod_eval, ei, ret);
3031 /* ECMA-262 3rd Edition 11.13.2 */
3032 HRESULT assign_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3034 binary_expression_t *expr = (binary_expression_t*)_expr;
3036 TRACE("\n");
3038 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitand_eval, ei, ret);
3041 /* ECMA-262 3rd Edition 11.13.2 */
3042 HRESULT assign_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3044 binary_expression_t *expr = (binary_expression_t*)_expr;
3046 TRACE("\n");
3048 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitor_eval, ei, ret);
3051 /* ECMA-262 3rd Edition 11.13.2 */
3052 HRESULT assign_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3054 binary_expression_t *expr = (binary_expression_t*)_expr;
3056 TRACE("\n");
3058 return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);