configure: Get rid of the va_copy checks.
[wine/wine64.git] / dlls / jscript / engine.c
blob5a14c5ff07af7b5aac5a0700ccb05d397ef2d63a
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 IDispatch_AddRef(this_obj);
183 ctx->this_obj = this_obj;
185 IDispatchEx_AddRef(_IDispatchEx_(var_disp));
186 ctx->var_disp = var_disp;
188 if(scope) {
189 scope_addref(scope);
190 ctx->scope_chain = scope;
193 *ret = ctx;
194 return S_OK;
197 void exec_release(exec_ctx_t *ctx)
199 if(--ctx->ref)
200 return;
202 if(ctx->scope_chain)
203 scope_release(ctx->scope_chain);
204 if(ctx->var_disp)
205 IDispatchEx_Release(_IDispatchEx_(ctx->var_disp));
206 if(ctx->this_obj)
207 IDispatch_Release(ctx->this_obj);
208 heap_free(ctx);
211 static HRESULT disp_get_id(IDispatch *disp, BSTR name, DWORD flags, DISPID *id)
213 IDispatchEx *dispex;
214 HRESULT hres;
216 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
217 if(FAILED(hres)) {
218 TRACE("unsing IDispatch\n");
220 *id = 0;
221 return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
224 *id = 0;
225 hres = IDispatchEx_GetDispID(dispex, name, flags|fdexNameCaseSensitive, id);
226 IDispatchEx_Release(dispex);
227 return hres;
230 /* ECMA-262 3rd Edition 8.7.2 */
231 static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei)
233 if(ref->type != EXPRVAL_IDREF) {
234 FIXME("throw ReferemceError\n");
235 return E_FAIL;
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, 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 hres = disp_get_id(item->disp, identifier, 0, &id);
493 if(SUCCEEDED(hres))
494 break;
497 if(item) {
498 exprval_set_idref(ret, (IDispatch*)item->disp, id);
499 return S_OK;
502 hres = jsdisp_get_id(ctx->parser->script->script_disp, identifier, 0, &id);
503 if(SUCCEEDED(hres)) {
504 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->script_disp), id);
505 return S_OK;
508 if(flags & EXPR_NEWREF) {
509 hres = jsdisp_get_id(ctx->var_disp, identifier, fdexNameEnsure, &id);
510 if(FAILED(hres))
511 return hres;
513 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->var_disp), id);
514 return S_OK;
517 WARN("Could not find identifier %s\n", debugstr_w(identifier));
518 return E_FAIL;
521 /* ECMA-262 3rd Edition 12.1 */
522 HRESULT block_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
524 block_statement_t *stat = (block_statement_t*)_stat;
525 VARIANT val, tmp;
526 statement_t *iter;
527 HRESULT hres = S_OK;
529 TRACE("\n");
531 V_VT(&val) = VT_EMPTY;
532 for(iter = stat->stat_list; iter; iter = iter->next) {
533 hres = stat_eval(ctx, iter, rt, &tmp);
534 if(FAILED(hres))
535 break;
537 VariantClear(&val);
538 val = tmp;
539 if(rt->type != RT_NORMAL)
540 break;
543 if(FAILED(hres)) {
544 VariantClear(&val);
545 return hres;
548 *ret = val;
549 return S_OK;
552 /* ECMA-262 3rd Edition 12.2 */
553 static HRESULT variable_list_eval(exec_ctx_t *ctx, variable_declaration_t *var_list, jsexcept_t *ei)
555 variable_declaration_t *iter;
556 HRESULT hres = S_OK;
558 for(iter = var_list; iter; iter = iter->next) {
559 exprval_t exprval;
560 VARIANT val;
562 if(!iter->expr)
563 continue;
565 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
566 if(FAILED(hres))
567 break;
569 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
570 exprval_release(&exprval);
571 if(FAILED(hres))
572 break;
574 hres = jsdisp_propput_name(ctx->var_disp, iter->identifier, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
575 VariantClear(&val);
576 if(FAILED(hres))
577 break;
580 return hres;
583 /* ECMA-262 3rd Edition 12.2 */
584 HRESULT var_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
586 var_statement_t *stat = (var_statement_t*)_stat;
587 HRESULT hres;
589 TRACE("\n");
591 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
592 if(FAILED(hres))
593 return hres;
595 V_VT(ret) = VT_EMPTY;
596 return S_OK;
599 /* ECMA-262 3rd Edition 12.3 */
600 HRESULT empty_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
602 TRACE("\n");
604 V_VT(ret) = VT_EMPTY;
605 return S_OK;
608 /* ECMA-262 3rd Edition 12.4 */
609 HRESULT expression_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
611 expression_statement_t *stat = (expression_statement_t*)_stat;
612 exprval_t exprval;
613 VARIANT val;
614 HRESULT hres;
616 TRACE("\n");
618 hres = expr_eval(ctx, stat->expr, EXPR_NOVAL, &rt->ei, &exprval);
619 if(FAILED(hres))
620 return hres;
622 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
623 exprval_release(&exprval);
624 if(FAILED(hres))
625 return hres;
627 *ret = val;
628 TRACE("= %s\n", debugstr_variant(ret));
629 return S_OK;
632 /* ECMA-262 3rd Edition 12.5 */
633 HRESULT if_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
635 if_statement_t *stat = (if_statement_t*)_stat;
636 exprval_t exprval;
637 VARIANT_BOOL b;
638 HRESULT hres;
640 TRACE("\n");
642 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
643 if(FAILED(hres))
644 return hres;
646 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
647 exprval_release(&exprval);
648 if(FAILED(hres))
649 return hres;
651 if(b)
652 hres = stat_eval(ctx, stat->if_stat, rt, ret);
653 else if(stat->else_stat)
654 hres = stat_eval(ctx, stat->else_stat, rt, ret);
655 else
656 V_VT(ret) = VT_EMPTY;
658 return hres;
661 /* ECMA-262 3rd Edition 12.6.2 */
662 HRESULT while_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
664 while_statement_t *stat = (while_statement_t*)_stat;
665 exprval_t exprval;
666 VARIANT val, tmp;
667 VARIANT_BOOL b;
668 BOOL test_expr;
669 HRESULT hres;
671 TRACE("\n");
673 V_VT(&val) = VT_EMPTY;
674 test_expr = !stat->do_while;
676 while(1) {
677 if(test_expr) {
678 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
679 if(FAILED(hres))
680 break;
682 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
683 exprval_release(&exprval);
684 if(FAILED(hres) || !b)
685 break;
686 }else {
687 test_expr = TRUE;
690 hres = stat_eval(ctx, stat->statement, rt, &tmp);
691 if(FAILED(hres))
692 break;
694 VariantClear(&val);
695 val = tmp;
697 if(rt->type == RT_CONTINUE)
698 rt->type = RT_NORMAL;
699 if(rt->type != RT_NORMAL)
700 break;
703 if(FAILED(hres)) {
704 VariantClear(&val);
705 return hres;
708 if(rt->type == RT_BREAK)
709 rt->type = RT_NORMAL;
711 *ret = val;
712 return S_OK;
715 /* ECMA-262 3rd Edition 12.6.3 */
716 HRESULT for_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
718 for_statement_t *stat = (for_statement_t*)_stat;
719 VARIANT val, tmp, retv;
720 exprval_t exprval;
721 VARIANT_BOOL b;
722 HRESULT hres;
724 TRACE("\n");
726 if(stat->variable_list) {
727 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
728 if(FAILED(hres))
729 return hres;
730 }else if(stat->begin_expr) {
731 hres = expr_eval(ctx, stat->begin_expr, EXPR_NEWREF, &rt->ei, &exprval);
732 if(FAILED(hres))
733 return hres;
735 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
736 exprval_release(&exprval);
737 if(FAILED(hres))
738 return hres;
740 VariantClear(&val);
743 V_VT(&retv) = VT_EMPTY;
745 while(1) {
746 if(stat->expr) {
747 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
748 if(FAILED(hres))
749 break;
751 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
752 exprval_release(&exprval);
753 if(FAILED(hres) || !b)
754 break;
757 hres = stat_eval(ctx, stat->statement, rt, &tmp);
758 if(FAILED(hres))
759 break;
761 VariantClear(&retv);
762 retv = tmp;
764 if(rt->type == RT_CONTINUE)
765 rt->type = RT_NORMAL;
766 else if(rt->type != RT_NORMAL)
767 break;
769 if(stat->end_expr) {
770 hres = expr_eval(ctx, stat->end_expr, 0, &rt->ei, &exprval);
771 if(FAILED(hres))
772 break;
774 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
775 exprval_release(&exprval);
776 if(FAILED(hres))
777 break;
779 VariantClear(&val);
783 if(FAILED(hres)) {
784 VariantClear(&retv);
785 return hres;
788 if(rt->type == RT_BREAK)
789 rt->type = RT_NORMAL;
791 *ret = retv;
792 return S_OK;
795 /* ECMA-262 3rd Edition 12.6.4 */
796 HRESULT forin_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
798 forin_statement_t *stat = (forin_statement_t*)_stat;
799 VARIANT val, name, retv, tmp;
800 DISPID id = DISPID_STARTENUM;
801 BSTR str, identifier = NULL;
802 IDispatchEx *in_obj;
803 exprval_t exprval;
804 HRESULT hres;
806 TRACE("\n");
808 if(stat->variable) {
809 hres = variable_list_eval(ctx, stat->variable, &rt->ei);
810 if(FAILED(hres))
811 return hres;
814 hres = expr_eval(ctx, stat->in_expr, EXPR_NEWREF, &rt->ei, &exprval);
815 if(FAILED(hres))
816 return hres;
818 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
819 exprval_release(&exprval);
820 if(FAILED(hres))
821 return hres;
823 if(V_VT(&val) != VT_DISPATCH) {
824 TRACE("in vt %d\n", V_VT(&val));
825 VariantClear(&val);
826 V_VT(ret) = VT_EMPTY;
827 return S_OK;
830 hres = IDispatch_QueryInterface(V_DISPATCH(&val), &IID_IDispatchEx, (void**)&in_obj);
831 IDispatch_Release(V_DISPATCH(&val));
832 if(FAILED(hres)) {
833 FIXME("Object doesn't support IDispatchEx\n");
834 return E_NOTIMPL;
837 V_VT(&retv) = VT_EMPTY;
839 if(stat->variable)
840 identifier = SysAllocString(stat->variable->identifier);
842 while(1) {
843 hres = IDispatchEx_GetNextDispID(in_obj, fdexEnumDefault, id, &id);
844 if(FAILED(hres) || hres == S_FALSE)
845 break;
847 hres = IDispatchEx_GetMemberName(in_obj, id, &str);
848 if(FAILED(hres))
849 break;
851 TRACE("iter %s\n", debugstr_w(str));
853 if(stat->variable)
854 hres = identifier_eval(ctx, identifier, 0, &exprval);
855 else
856 hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval);
857 if(SUCCEEDED(hres)) {
858 V_VT(&name) = VT_BSTR;
859 V_BSTR(&name) = str;
860 hres = put_value(ctx->parser->script, &exprval, &name, &rt->ei);
861 exprval_release(&exprval);
863 SysFreeString(str);
864 if(FAILED(hres))
865 break;
867 hres = stat_eval(ctx, stat->statement, rt, &tmp);
868 if(FAILED(hres))
869 break;
871 VariantClear(&retv);
872 retv = tmp;
874 if(rt->type == RT_CONTINUE)
875 rt->type = RT_NORMAL;
876 else if(rt->type != RT_NORMAL)
877 break;
880 SysFreeString(identifier);
881 IDispatchEx_Release(in_obj);
882 if(FAILED(hres)) {
883 VariantClear(&retv);
884 return hres;
887 if(rt->type == RT_BREAK)
888 rt->type = RT_NORMAL;
890 *ret = retv;
891 return S_OK;
894 /* ECMA-262 3rd Edition 12.7 */
895 HRESULT continue_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
897 branch_statement_t *stat = (branch_statement_t*)_stat;
899 TRACE("\n");
901 if(stat->identifier) {
902 FIXME("indentifier not implemented\n");
903 return E_NOTIMPL;
906 rt->type = RT_CONTINUE;
907 V_VT(ret) = VT_EMPTY;
908 return S_OK;
911 /* ECMA-262 3rd Edition 12.8 */
912 HRESULT break_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
914 branch_statement_t *stat = (branch_statement_t*)_stat;
916 TRACE("\n");
918 if(stat->identifier) {
919 FIXME("indentifier not implemented\n");
920 return E_NOTIMPL;
923 rt->type = RT_BREAK;
924 V_VT(ret) = VT_EMPTY;
925 return S_OK;
928 /* ECMA-262 3rd Edition 12.9 */
929 HRESULT return_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
931 expression_statement_t *stat = (expression_statement_t*)_stat;
932 HRESULT hres;
934 TRACE("\n");
936 if(stat->expr) {
937 exprval_t exprval;
939 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
940 if(FAILED(hres))
941 return hres;
943 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, ret);
944 exprval_release(&exprval);
945 if(FAILED(hres))
946 return hres;
947 }else {
948 V_VT(ret) = VT_EMPTY;
951 TRACE("= %s\n", debugstr_variant(ret));
952 rt->type = RT_RETURN;
953 return S_OK;
956 /* ECMA-262 3rd Edition 12.10 */
957 HRESULT with_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
959 with_statement_t *stat = (with_statement_t*)_stat;
960 exprval_t exprval;
961 IDispatch *disp;
962 DispatchEx *obj;
963 VARIANT val;
964 HRESULT hres;
966 TRACE("\n");
968 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
969 if(FAILED(hres))
970 return hres;
972 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
973 exprval_release(&exprval);
974 if(FAILED(hres))
975 return hres;
977 hres = to_object(ctx, &val, &disp);
978 VariantClear(&val);
979 if(FAILED(hres))
980 return hres;
982 obj = iface_to_jsdisp((IUnknown*)disp);
983 IDispatch_Release(disp);
984 if(!obj) {
985 FIXME("disp id not jsdisp\n");
986 return E_NOTIMPL;
989 hres = scope_push(ctx->scope_chain, obj, &ctx->scope_chain);
990 jsdisp_release(obj);
991 if(FAILED(hres))
992 return hres;
994 hres = stat_eval(ctx, stat->statement, rt, ret);
996 scope_pop(&ctx->scope_chain);
997 return hres;
1000 /* ECMA-262 3rd Edition 12.12 */
1001 HRESULT labelled_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
1003 FIXME("\n");
1004 return E_NOTIMPL;
1007 /* ECMA-262 3rd Edition 12.13 */
1008 HRESULT switch_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1010 switch_statement_t *stat = (switch_statement_t*)_stat;
1011 case_clausule_t *iter, *default_clausule = NULL;
1012 statement_t *stat_iter;
1013 VARIANT val, cval;
1014 exprval_t exprval;
1015 BOOL b;
1016 HRESULT hres;
1018 TRACE("\n");
1020 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1021 if(FAILED(hres))
1022 return hres;
1024 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1025 exprval_release(&exprval);
1026 if(FAILED(hres))
1027 return hres;
1029 for(iter = stat->case_list; iter; iter = iter->next) {
1030 if(!iter->expr) {
1031 default_clausule = iter;
1032 continue;
1035 hres = expr_eval(ctx, iter->expr, 0, &rt->ei, &exprval);
1036 if(FAILED(hres))
1037 break;
1039 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &cval);
1040 exprval_release(&exprval);
1041 if(FAILED(hres))
1042 break;
1044 hres = equal2_values(&val, &cval, &b);
1045 VariantClear(&cval);
1046 if(FAILED(hres) || b)
1047 break;
1050 VariantClear(&val);
1051 if(FAILED(hres))
1052 return hres;
1054 if(!iter)
1055 iter = default_clausule;
1057 V_VT(&val) = VT_EMPTY;
1058 if(iter) {
1059 VARIANT tmp;
1061 for(stat_iter = iter->stat; stat_iter; stat_iter = stat_iter->next) {
1062 hres = stat_eval(ctx, stat_iter, rt, &tmp);
1063 if(FAILED(hres))
1064 break;
1066 VariantClear(&val);
1067 val = tmp;
1069 if(rt->type != RT_NORMAL)
1070 break;
1074 if(FAILED(hres)) {
1075 VariantClear(&val);
1076 return hres;
1079 if(rt->type == RT_BREAK)
1080 rt->type = RT_NORMAL;
1082 *ret = val;
1083 return S_OK;
1086 /* ECMA-262 3rd Edition 12.13 */
1087 HRESULT throw_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1089 expression_statement_t *stat = (expression_statement_t*)_stat;
1090 exprval_t exprval;
1091 VARIANT val;
1092 HRESULT hres;
1094 TRACE("\n");
1096 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1097 if(FAILED(hres))
1098 return hres;
1100 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1101 exprval_release(&exprval);
1102 if(FAILED(hres))
1103 return hres;
1105 rt->ei.var = val;
1106 return DISP_E_EXCEPTION;
1109 /* ECMA-262 3rd Edition 12.14 */
1110 static HRESULT catch_eval(exec_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
1112 DispatchEx *var_disp;
1113 VARIANT ex, val;
1114 HRESULT hres;
1116 ex = rt->ei.var;
1117 memset(&rt->ei, 0, sizeof(jsexcept_t));
1119 hres = create_dispex(ctx->parser->script, NULL, NULL, &var_disp);
1120 if(SUCCEEDED(hres)) {
1121 hres = jsdisp_propput_name(var_disp, block->identifier, ctx->parser->script->lcid,
1122 &ex, &rt->ei, NULL/*FIXME*/);
1123 if(SUCCEEDED(hres)) {
1124 hres = scope_push(ctx->scope_chain, var_disp, &ctx->scope_chain);
1125 if(SUCCEEDED(hres)) {
1126 hres = stat_eval(ctx, block->statement, rt, &val);
1127 scope_pop(&ctx->scope_chain);
1131 jsdisp_release(var_disp);
1134 VariantClear(&ex);
1135 if(FAILED(hres))
1136 return hres;
1138 *ret = val;
1139 return S_OK;
1142 /* ECMA-262 3rd Edition 12.14 */
1143 HRESULT try_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1145 try_statement_t *stat = (try_statement_t*)_stat;
1146 VARIANT val;
1147 HRESULT hres;
1149 TRACE("\n");
1151 hres = stat_eval(ctx, stat->try_statement, rt, &val);
1152 if(FAILED(hres)) {
1153 TRACE("EXCEPTION\n");
1154 if(!stat->catch_block)
1155 return hres;
1157 hres = catch_eval(ctx, stat->catch_block, rt, &val);
1158 if(FAILED(hres))
1159 return hres;
1162 if(stat->finally_statement) {
1163 VariantClear(&val);
1164 hres = stat_eval(ctx, stat->finally_statement, rt, &val);
1165 if(FAILED(hres))
1166 return hres;
1169 *ret = val;
1170 return S_OK;
1173 static HRESULT return_bool(exprval_t *ret, DWORD b)
1175 ret->type = EXPRVAL_VARIANT;
1176 V_VT(&ret->u.var) = VT_BOOL;
1177 V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;
1179 return S_OK;
1182 static HRESULT get_binary_expr_values(exec_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
1184 exprval_t exprval;
1185 HRESULT hres;
1187 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1188 if(FAILED(hres))
1189 return hres;
1191 hres = exprval_to_value(ctx->parser->script, &exprval, ei, lval);
1192 exprval_release(&exprval);
1193 if(FAILED(hres))
1194 return hres;
1196 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1197 if(SUCCEEDED(hres)) {
1198 hres = exprval_to_value(ctx->parser->script, &exprval, ei, rval);
1199 exprval_release(&exprval);
1202 if(FAILED(hres)) {
1203 VariantClear(lval);
1204 return hres;
1207 return S_OK;
1210 typedef HRESULT (*oper_t)(exec_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);
1212 static HRESULT binary_expr_eval(exec_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
1213 exprval_t *ret)
1215 VARIANT lval, rval, retv;
1216 HRESULT hres;
1218 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1219 if(FAILED(hres))
1220 return hres;
1222 hres = oper(ctx, &lval, &rval, ei, &retv);
1223 VariantClear(&lval);
1224 VariantClear(&rval);
1225 if(FAILED(hres))
1226 return hres;
1228 ret->type = EXPRVAL_VARIANT;
1229 ret->u.var = retv;
1230 return S_OK;
1233 /* ECMA-262 3rd Edition 11.13.2 */
1234 static HRESULT assign_oper_eval(exec_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
1235 jsexcept_t *ei, exprval_t *ret)
1237 VARIANT retv, lval, rval;
1238 exprval_t exprval, exprvalr;
1239 HRESULT hres;
1241 hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
1242 if(FAILED(hres))
1243 return hres;
1245 hres = exprval_value(ctx->parser->script, &exprval, ei, &lval);
1246 if(SUCCEEDED(hres)) {
1247 hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
1248 if(SUCCEEDED(hres)) {
1249 hres = exprval_value(ctx->parser->script, &exprvalr, ei, &rval);
1250 exprval_release(&exprvalr);
1252 if(SUCCEEDED(hres)) {
1253 hres = oper(ctx, &lval, &rval, ei, &retv);
1254 VariantClear(&rval);
1256 VariantClear(&lval);
1259 if(SUCCEEDED(hres)) {
1260 hres = put_value(ctx->parser->script, &exprval, &retv, ei);
1261 if(FAILED(hres))
1262 VariantClear(&retv);
1264 exprval_release(&exprval);
1266 if(FAILED(hres))
1267 return hres;
1269 ret->type = EXPRVAL_VARIANT;
1270 ret->u.var = retv;
1271 return S_OK;
1274 /* ECMA-262 3rd Edition 13 */
1275 HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1277 function_expression_t *expr = (function_expression_t*)_expr;
1278 VARIANT var;
1279 HRESULT hres;
1281 TRACE("\n");
1283 if(expr->identifier) {
1284 hres = jsdisp_propget_name(ctx->var_disp, expr->identifier, ctx->parser->script->lcid, &var, ei, NULL/*FIXME*/);
1285 if(FAILED(hres))
1286 return hres;
1287 }else {
1288 DispatchEx *dispex;
1290 hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain,
1291 expr->src_str, expr->src_len, &dispex);
1292 if(FAILED(hres))
1293 return hres;
1295 V_VT(&var) = VT_DISPATCH;
1296 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
1299 ret->type = EXPRVAL_VARIANT;
1300 ret->u.var = var;
1301 return S_OK;
1304 /* ECMA-262 3rd Edition 11.12 */
1305 HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1307 conditional_expression_t *expr = (conditional_expression_t*)_expr;
1308 exprval_t exprval;
1309 VARIANT_BOOL b;
1310 HRESULT hres;
1312 TRACE("\n");
1314 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1315 if(FAILED(hres))
1316 return hres;
1318 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
1319 exprval_release(&exprval);
1320 if(FAILED(hres))
1321 return hres;
1323 return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
1326 /* ECMA-262 3rd Edition 11.2.1 */
1327 HRESULT array_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1329 array_expression_t *expr = (array_expression_t*)_expr;
1330 exprval_t exprval;
1331 VARIANT member, val;
1332 DISPID id;
1333 BSTR str;
1334 IDispatch *obj = NULL;
1335 HRESULT hres;
1337 TRACE("\n");
1339 hres = expr_eval(ctx, expr->member_expr, EXPR_NEWREF, ei, &exprval);
1340 if(FAILED(hres))
1341 return hres;
1343 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1344 exprval_release(&exprval);
1345 if(FAILED(hres))
1346 return hres;
1348 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
1349 if(SUCCEEDED(hres)) {
1350 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1351 exprval_release(&exprval);
1354 if(SUCCEEDED(hres))
1355 hres = to_object(ctx, &member, &obj);
1356 VariantClear(&member);
1357 if(SUCCEEDED(hres)) {
1358 hres = to_string(ctx->parser->script, &val, ei, &str);
1359 if(SUCCEEDED(hres)) {
1360 if(flags & EXPR_STRREF) {
1361 ret->type = EXPRVAL_NAMEREF;
1362 ret->u.nameref.disp = obj;
1363 ret->u.nameref.name = str;
1364 return S_OK;
1367 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1370 if(SUCCEEDED(hres)) {
1371 exprval_set_idref(ret, obj, id);
1372 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1373 exprval_init(ret);
1374 hres = S_OK;
1377 IDispatch_Release(obj);
1380 return hres;
1383 /* ECMA-262 3rd Edition 11.2.1 */
1384 HRESULT member_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1386 member_expression_t *expr = (member_expression_t*)_expr;
1387 IDispatch *obj = NULL;
1388 exprval_t exprval;
1389 VARIANT member;
1390 DISPID id;
1391 BSTR str;
1392 HRESULT hres;
1394 TRACE("\n");
1396 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1397 if(FAILED(hres))
1398 return hres;
1400 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1401 exprval_release(&exprval);
1402 if(FAILED(hres))
1403 return hres;
1405 hres = to_object(ctx, &member, &obj);
1406 VariantClear(&member);
1407 if(FAILED(hres))
1408 return hres;
1410 str = SysAllocString(expr->identifier);
1411 if(flags & EXPR_STRREF) {
1412 ret->type = EXPRVAL_NAMEREF;
1413 ret->u.nameref.disp = obj;
1414 ret->u.nameref.name = str;
1415 return S_OK;
1418 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1419 SysFreeString(str);
1420 if(SUCCEEDED(hres)) {
1421 exprval_set_idref(ret, obj, id);
1422 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1423 exprval_init(ret);
1424 hres = S_OK;
1427 IDispatch_Release(obj);
1428 return hres;
1431 static void free_dp(DISPPARAMS *dp)
1433 DWORD i;
1435 for(i=0; i < dp->cArgs; i++)
1436 VariantClear(dp->rgvarg+i);
1437 heap_free(dp->rgvarg);
1440 static HRESULT args_to_param(exec_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
1442 VARIANTARG *vargs;
1443 exprval_t exprval;
1444 argument_t *iter;
1445 DWORD cnt = 0, i;
1446 HRESULT hres = S_OK;
1448 memset(dp, 0, sizeof(*dp));
1449 if(!args)
1450 return S_OK;
1452 for(iter = args; iter; iter = iter->next)
1453 cnt++;
1455 vargs = heap_alloc_zero(cnt * sizeof(*vargs));
1456 if(!vargs)
1457 return E_OUTOFMEMORY;
1459 for(i = cnt, iter = args; iter; iter = iter->next) {
1460 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
1461 if(FAILED(hres))
1462 break;
1464 hres = exprval_to_value(ctx->parser->script, &exprval, ei, vargs + (--i));
1465 exprval_release(&exprval);
1466 if(FAILED(hres))
1467 break;
1470 if(FAILED(hres)) {
1471 free_dp(dp);
1472 return hres;
1475 dp->rgvarg = vargs;
1476 dp->cArgs = cnt;
1477 return S_OK;
1480 /* ECMA-262 3rd Edition 11.2.2 */
1481 HRESULT new_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1483 call_expression_t *expr = (call_expression_t*)_expr;
1484 exprval_t exprval;
1485 VARIANT constr, var;
1486 DISPPARAMS dp;
1487 HRESULT hres;
1489 TRACE("\n");
1491 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1492 if(FAILED(hres))
1493 return hres;
1495 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1496 if(SUCCEEDED(hres))
1497 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &constr);
1498 exprval_release(&exprval);
1499 if(FAILED(hres))
1500 return hres;
1502 if(V_VT(&constr) != VT_DISPATCH) {
1503 FIXME("throw TypeError\n");
1504 VariantClear(&constr);
1505 return E_FAIL;
1508 hres = disp_call(V_DISPATCH(&constr), DISPID_VALUE, ctx->parser->script->lcid,
1509 DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
1510 IDispatch_Release(V_DISPATCH(&constr));
1511 if(FAILED(hres))
1512 return hres;
1514 ret->type = EXPRVAL_VARIANT;
1515 ret->u.var = var;
1516 return S_OK;
1519 /* ECMA-262 3rd Edition 11.2.3 */
1520 HRESULT call_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1522 call_expression_t *expr = (call_expression_t*)_expr;
1523 VARIANT var;
1524 exprval_t exprval;
1525 DISPPARAMS dp;
1526 HRESULT hres;
1528 TRACE("\n");
1530 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1531 if(FAILED(hres))
1532 return hres;
1534 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1535 if(SUCCEEDED(hres)) {
1536 switch(exprval.type) {
1537 case EXPRVAL_IDREF:
1538 hres = disp_call(exprval.u.idref.disp, exprval.u.idref.id, ctx->parser->script->lcid, DISPATCH_METHOD,
1539 &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1540 if(flags & EXPR_NOVAL)
1541 V_VT(&var) = VT_EMPTY;
1542 break;
1543 default:
1544 FIXME("unimplemented type %d\n", exprval.type);
1545 hres = E_NOTIMPL;
1548 free_dp(&dp);
1551 exprval_release(&exprval);
1552 if(FAILED(hres))
1553 return hres;
1555 TRACE("= %s\n", debugstr_variant(&var));
1556 ret->type = EXPRVAL_VARIANT;
1557 ret->u.var = var;
1558 return S_OK;
1561 /* ECMA-262 3rd Edition 11.1.1 */
1562 HRESULT this_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1564 TRACE("\n");
1566 ret->type = EXPRVAL_VARIANT;
1567 V_VT(&ret->u.var) = VT_DISPATCH;
1568 V_DISPATCH(&ret->u.var) = ctx->this_obj;
1569 IDispatch_AddRef(ctx->this_obj);
1570 return S_OK;
1573 /* ECMA-262 3rd Edition 10.1.4 */
1574 HRESULT identifier_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1576 identifier_expression_t *expr = (identifier_expression_t*)_expr;
1577 BSTR identifier;
1578 HRESULT hres;
1580 TRACE("\n");
1582 identifier = SysAllocString(expr->identifier);
1583 if(!identifier)
1584 return E_OUTOFMEMORY;
1586 hres = identifier_eval(ctx, identifier, flags, ret);
1588 SysFreeString(identifier);
1589 return hres;
1592 /* ECMA-262 3rd Edition 7.8 */
1593 HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1595 literal_expression_t *expr = (literal_expression_t*)_expr;
1596 VARIANT var;
1597 HRESULT hres;
1599 TRACE("\n");
1601 hres = literal_to_var(expr->literal, &var);
1602 if(FAILED(hres))
1603 return hres;
1605 ret->type = EXPRVAL_VARIANT;
1606 ret->u.var = var;
1607 return S_OK;
1610 /* ECMA-262 3rd Edition 11.1.4 */
1611 HRESULT array_literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1613 array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
1614 DWORD length = 0, i = 0;
1615 array_element_t *elem;
1616 DispatchEx *array;
1617 exprval_t exprval;
1618 VARIANT val;
1619 HRESULT hres;
1621 TRACE("\n");
1623 for(elem = expr->element_list; elem; elem = elem->next)
1624 length += elem->elision+1;
1625 length += expr->length;
1627 hres = create_array(ctx->parser->script, length, &array);
1628 if(FAILED(hres))
1629 return hres;
1631 for(elem = expr->element_list; elem; elem = elem->next) {
1632 i += elem->elision;
1634 hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
1635 if(FAILED(hres))
1636 break;
1638 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1639 exprval_release(&exprval);
1640 if(FAILED(hres))
1641 break;
1643 hres = jsdisp_propput_idx(array, i, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1644 VariantClear(&val);
1645 if(FAILED(hres))
1646 break;
1648 i++;
1651 if(FAILED(hres)) {
1652 jsdisp_release(array);
1653 return hres;
1656 ret->type = EXPRVAL_VARIANT;
1657 V_VT(&ret->u.var) = VT_DISPATCH;
1658 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(array);
1659 return S_OK;
1662 /* ECMA-262 3rd Edition 11.1.5 */
1663 HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1665 property_value_expression_t *expr = (property_value_expression_t*)_expr;
1666 VARIANT val, tmp;
1667 DispatchEx *obj;
1668 prop_val_t *iter;
1669 exprval_t exprval;
1670 BSTR name;
1671 HRESULT hres;
1673 TRACE("\n");
1675 hres = create_object(ctx->parser->script, NULL, &obj);
1676 if(FAILED(hres))
1677 return hres;
1679 for(iter = expr->property_list; iter; iter = iter->next) {
1680 hres = literal_to_var(iter->name, &tmp);
1681 if(FAILED(hres))
1682 break;
1684 hres = to_string(ctx->parser->script, &tmp, ei, &name);
1685 VariantClear(&tmp);
1686 if(FAILED(hres))
1687 break;
1689 hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
1690 if(SUCCEEDED(hres)) {
1691 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1692 exprval_release(&exprval);
1693 if(SUCCEEDED(hres)) {
1694 hres = jsdisp_propput_name(obj, name, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1695 VariantClear(&val);
1699 SysFreeString(name);
1700 if(FAILED(hres))
1701 break;
1704 if(FAILED(hres)) {
1705 jsdisp_release(obj);
1706 return hres;
1709 ret->type = EXPRVAL_VARIANT;
1710 V_VT(&ret->u.var) = VT_DISPATCH;
1711 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(obj);
1712 return S_OK;
1715 /* ECMA-262 3rd Edition 11.14 */
1716 HRESULT comma_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1718 binary_expression_t *expr = (binary_expression_t*)_expr;
1719 VARIANT lval, rval;
1720 HRESULT hres;
1722 TRACE("\n");
1724 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1725 if(FAILED(hres))
1726 return hres;
1728 VariantClear(&lval);
1730 ret->type = EXPRVAL_VARIANT;
1731 ret->u.var = rval;
1732 return S_OK;
1735 /* ECMA-262 3rd Edition 11.11 */
1736 HRESULT logical_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1738 binary_expression_t *expr = (binary_expression_t*)_expr;
1739 exprval_t exprval;
1740 VARIANT_BOOL b;
1741 VARIANT val;
1742 HRESULT hres;
1744 TRACE("\n");
1746 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1747 if(FAILED(hres))
1748 return hres;
1750 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1751 exprval_release(&exprval);
1752 if(FAILED(hres))
1753 return hres;
1755 hres = to_boolean(&val, &b);
1756 if(SUCCEEDED(hres) && b) {
1757 ret->type = EXPRVAL_VARIANT;
1758 ret->u.var = val;
1759 return S_OK;
1762 VariantClear(&val);
1763 if(FAILED(hres))
1764 return hres;
1766 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1767 if(FAILED(hres))
1768 return hres;
1770 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1771 exprval_release(&exprval);
1772 if(FAILED(hres))
1773 return hres;
1775 ret->type = EXPRVAL_VARIANT;
1776 ret->u.var = val;
1777 return S_OK;
1780 /* ECMA-262 3rd Edition 11.11 */
1781 HRESULT logical_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1783 binary_expression_t *expr = (binary_expression_t*)_expr;
1784 exprval_t exprval;
1785 VARIANT_BOOL b;
1786 VARIANT val;
1787 HRESULT hres;
1789 TRACE("\n");
1791 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1792 if(FAILED(hres))
1793 return hres;
1795 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1796 exprval_release(&exprval);
1797 if(FAILED(hres))
1798 return hres;
1800 hres = to_boolean(&val, &b);
1801 if(SUCCEEDED(hres) && !b) {
1802 ret->type = EXPRVAL_VARIANT;
1803 ret->u.var = val;
1804 return S_OK;
1807 VariantClear(&val);
1808 if(FAILED(hres))
1809 return hres;
1811 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1812 if(FAILED(hres))
1813 return hres;
1815 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1816 exprval_release(&exprval);
1817 if(FAILED(hres))
1818 return hres;
1820 ret->type = EXPRVAL_VARIANT;
1821 ret->u.var = val;
1822 return S_OK;
1825 /* ECMA-262 3rd Edition 11.10 */
1826 static HRESULT bitor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1828 INT li, ri;
1829 HRESULT hres;
1831 hres = to_int32(ctx->parser->script, lval, ei, &li);
1832 if(FAILED(hres))
1833 return hres;
1835 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1836 if(FAILED(hres))
1837 return hres;
1839 V_VT(retv) = VT_I4;
1840 V_I4(retv) = li|ri;
1841 return S_OK;
1844 /* ECMA-262 3rd Edition 11.10 */
1845 HRESULT binary_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1847 binary_expression_t *expr = (binary_expression_t*)_expr;
1849 TRACE("\n");
1851 return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
1854 /* ECMA-262 3rd Edition 11.10 */
1855 static HRESULT xor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1857 INT li, ri;
1858 HRESULT hres;
1860 hres = to_int32(ctx->parser->script, lval, ei, &li);
1861 if(FAILED(hres))
1862 return hres;
1864 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1865 if(FAILED(hres))
1866 return hres;
1868 V_VT(retv) = VT_I4;
1869 V_I4(retv) = li^ri;
1870 return S_OK;
1873 /* ECMA-262 3rd Edition 11.10 */
1874 HRESULT binary_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1876 binary_expression_t *expr = (binary_expression_t*)_expr;
1878 TRACE("\n");
1880 return binary_expr_eval(ctx, expr, xor_eval, ei, ret);
1883 /* ECMA-262 3rd Edition 11.10 */
1884 static HRESULT bitand_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1886 INT li, ri;
1887 HRESULT hres;
1889 hres = to_int32(ctx->parser->script, lval, ei, &li);
1890 if(FAILED(hres))
1891 return hres;
1893 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1894 if(FAILED(hres))
1895 return hres;
1897 V_VT(retv) = VT_I4;
1898 V_I4(retv) = li&ri;
1899 return S_OK;
1902 /* ECMA-262 3rd Edition 11.10 */
1903 HRESULT binary_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1905 binary_expression_t *expr = (binary_expression_t*)_expr;
1907 TRACE("\n");
1909 return binary_expr_eval(ctx, expr, bitand_eval, ei, ret);
1912 /* ECMA-262 3rd Edition 11.8.6 */
1913 HRESULT instanceof_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1915 FIXME("\n");
1916 return E_NOTIMPL;
1919 /* ECMA-262 3rd Edition 11.8.7 */
1920 HRESULT in_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1922 FIXME("\n");
1923 return E_NOTIMPL;
1926 /* ECMA-262 3rd Edition 11.6.1 */
1927 static HRESULT add_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1929 VARIANT r, l;
1930 HRESULT hres;
1932 hres = to_primitive(ctx->parser->script, lval, ei, &l);
1933 if(FAILED(hres))
1934 return hres;
1936 hres = to_primitive(ctx->parser->script, rval, ei, &r);
1937 if(FAILED(hres)) {
1938 VariantClear(&l);
1939 return hres;
1942 if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
1943 BSTR lstr = NULL, rstr = NULL;
1945 if(V_VT(&l) == VT_BSTR)
1946 lstr = V_BSTR(&l);
1947 else
1948 hres = to_string(ctx->parser->script, &l, ei, &lstr);
1950 if(SUCCEEDED(hres)) {
1951 if(V_VT(&r) == VT_BSTR)
1952 rstr = V_BSTR(&r);
1953 else
1954 hres = to_string(ctx->parser->script, &r, ei, &rstr);
1957 if(SUCCEEDED(hres)) {
1958 int len1, len2;
1960 len1 = SysStringLen(lstr);
1961 len2 = SysStringLen(rstr);
1963 V_VT(retv) = VT_BSTR;
1964 V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
1965 memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
1966 memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
1969 if(V_VT(&l) != VT_BSTR)
1970 SysFreeString(lstr);
1971 if(V_VT(&r) != VT_BSTR)
1972 SysFreeString(rstr);
1973 }else {
1974 VARIANT nl, nr;
1976 hres = to_number(ctx->parser->script, &l, ei, &nl);
1977 if(SUCCEEDED(hres)) {
1978 hres = to_number(ctx->parser->script, &r, ei, &nr);
1979 if(SUCCEEDED(hres))
1980 num_set_val(retv, num_val(&nl) + num_val(&nr));
1984 VariantClear(&r);
1985 VariantClear(&l);
1986 return hres;
1989 /* ECMA-262 3rd Edition 11.6.1 */
1990 HRESULT add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1992 binary_expression_t *expr = (binary_expression_t*)_expr;
1994 TRACE("\n");
1996 return binary_expr_eval(ctx, expr, add_eval, ei, ret);
1999 /* ECMA-262 3rd Edition 11.6.2 */
2000 static HRESULT sub_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2002 VARIANT lnum, rnum;
2003 HRESULT hres;
2005 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2006 if(FAILED(hres))
2007 return hres;
2009 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2010 if(FAILED(hres))
2011 return hres;
2013 num_set_val(retv, num_val(&lnum) - num_val(&rnum));
2014 return S_OK;
2017 /* ECMA-262 3rd Edition 11.6.2 */
2018 HRESULT sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2020 binary_expression_t *expr = (binary_expression_t*)_expr;
2022 TRACE("\n");
2024 return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
2027 /* ECMA-262 3rd Edition 11.5.1 */
2028 static HRESULT mul_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2030 VARIANT lnum, rnum;
2031 HRESULT hres;
2033 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2034 if(FAILED(hres))
2035 return hres;
2037 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2038 if(FAILED(hres))
2039 return hres;
2041 num_set_val(retv, num_val(&lnum) * num_val(&rnum));
2042 return S_OK;
2045 /* ECMA-262 3rd Edition 11.5.1 */
2046 HRESULT mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2048 binary_expression_t *expr = (binary_expression_t*)_expr;
2050 TRACE("\n");
2052 return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
2055 /* ECMA-262 3rd Edition 11.5.2 */
2056 static HRESULT div_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2058 VARIANT lnum, rnum;
2059 HRESULT hres;
2061 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2062 if(FAILED(hres))
2063 return hres;
2065 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2066 if(FAILED(hres))
2067 return hres;
2069 num_set_val(retv, num_val(&lnum) / num_val(&rnum));
2070 return S_OK;
2073 /* ECMA-262 3rd Edition 11.5.2 */
2074 HRESULT div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2076 binary_expression_t *expr = (binary_expression_t*)_expr;
2078 TRACE("\n");
2080 return binary_expr_eval(ctx, expr, div_eval, ei, ret);
2083 /* ECMA-262 3rd Edition 11.5.3 */
2084 static HRESULT mod_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2086 VARIANT lnum, rnum;
2087 HRESULT hres;
2089 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2090 if(FAILED(hres))
2091 return hres;
2093 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2094 if(FAILED(hres))
2095 return hres;
2097 num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
2098 return S_OK;
2101 /* ECMA-262 3rd Edition 11.5.3 */
2102 HRESULT mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2104 binary_expression_t *expr = (binary_expression_t*)_expr;
2106 TRACE("\n");
2108 return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
2111 /* ECMA-262 3rd Edition 11.4.2 */
2112 HRESULT delete_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2114 unary_expression_t *expr = (unary_expression_t*)_expr;
2115 VARIANT_BOOL b = VARIANT_FALSE;
2116 exprval_t exprval;
2117 HRESULT hres;
2119 TRACE("\n");
2121 hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
2122 if(FAILED(hres))
2123 return hres;
2125 switch(exprval.type) {
2126 case EXPRVAL_IDREF: {
2127 IDispatchEx *dispex;
2129 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2130 if(SUCCEEDED(hres)) {
2131 hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
2132 b = VARIANT_TRUE;
2133 IDispatchEx_Release(dispex);
2135 break;
2137 case EXPRVAL_NAMEREF: {
2138 IDispatchEx *dispex;
2140 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2141 if(SUCCEEDED(hres)) {
2142 hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name, fdexNameCaseSensitive);
2143 b = VARIANT_TRUE;
2144 IDispatchEx_Release(dispex);
2146 break;
2148 default:
2149 FIXME("unsupported type %d\n", exprval.type);
2150 hres = E_NOTIMPL;
2153 exprval_release(&exprval);
2154 if(FAILED(hres))
2155 return hres;
2157 return return_bool(ret, b);
2160 /* ECMA-262 3rd Edition 11.4.2 */
2161 HRESULT void_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2163 unary_expression_t *expr = (unary_expression_t*)_expr;
2164 exprval_t exprval;
2165 VARIANT tmp;
2166 HRESULT hres;
2168 TRACE("\n");
2170 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2171 if(FAILED(hres))
2172 return hres;
2174 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &tmp);
2175 exprval_release(&exprval);
2176 if(FAILED(hres))
2177 return hres;
2179 VariantClear(&tmp);
2181 ret->type = EXPRVAL_VARIANT;
2182 V_VT(&ret->u.var) = VT_EMPTY;
2183 return S_OK;
2186 /* ECMA-262 3rd Edition 11.4.3 */
2187 HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2189 unary_expression_t *expr = (unary_expression_t*)_expr;
2190 const WCHAR *str;
2191 exprval_t exprval;
2192 VARIANT val;
2193 HRESULT hres;
2195 static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
2196 static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
2197 static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
2198 static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
2199 static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
2200 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
2202 TRACE("\n");
2204 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2205 if(FAILED(hres))
2206 return hres;
2208 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2209 exprval_release(&exprval);
2210 if(FAILED(hres))
2211 return hres;
2213 switch(V_VT(&val)) {
2214 case VT_EMPTY:
2215 str = undefinedW;
2216 break;
2217 case VT_NULL:
2218 str = objectW;
2219 break;
2220 case VT_BOOL:
2221 str = booleanW;
2222 break;
2223 case VT_I4:
2224 case VT_R8:
2225 str = numberW;
2226 break;
2227 case VT_BSTR:
2228 str = stringW;
2229 break;
2230 case VT_DISPATCH: {
2231 DispatchEx *dispex;
2233 dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val));
2234 if(dispex) {
2235 str = dispex->builtin_info->class == JSCLASS_FUNCTION ? functionW : objectW;
2236 IDispatchEx_Release(_IDispatchEx_(dispex));
2237 }else {
2238 str = objectW;
2240 break;
2242 default:
2243 FIXME("unhandled vt %d\n", V_VT(&val));
2244 VariantClear(&val);
2245 return E_NOTIMPL;
2248 VariantClear(&val);
2250 ret->type = EXPRVAL_VARIANT;
2251 V_VT(&ret->u.var) = VT_BSTR;
2252 V_BSTR(&ret->u.var) = SysAllocString(str);
2253 return S_OK;
2256 /* ECMA-262 3rd Edition 11.4.7 */
2257 HRESULT minus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2259 unary_expression_t *expr = (unary_expression_t*)_expr;
2260 exprval_t exprval;
2261 VARIANT val, num;
2262 HRESULT hres;
2264 TRACE("\n");
2266 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2267 if(FAILED(hres))
2268 return hres;
2270 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2271 exprval_release(&exprval);
2272 if(FAILED(hres))
2273 return hres;
2275 hres = to_number(ctx->parser->script, &val, ei, &num);
2276 VariantClear(&val);
2277 if(FAILED(hres))
2278 return hres;
2280 ret->type = EXPRVAL_VARIANT;
2281 num_set_val(&ret->u.var, -num_val(&num));
2282 return S_OK;
2285 /* ECMA-262 3rd Edition 11.4.6 */
2286 HRESULT plus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2288 unary_expression_t *expr = (unary_expression_t*)_expr;
2289 exprval_t exprval;
2290 VARIANT val, num;
2291 HRESULT hres;
2293 TRACE("\n");
2295 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2296 if(FAILED(hres))
2297 return hres;
2299 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2300 exprval_release(&exprval);
2301 if(FAILED(hres))
2302 return hres;
2304 hres = to_number(ctx->parser->script, &val, ei, &num);
2305 if(FAILED(hres))
2306 return hres;
2308 ret->type = EXPRVAL_VARIANT;
2309 ret->u.var = num;
2310 return S_OK;
2313 /* ECMA-262 3rd Edition 11.3.1 */
2314 HRESULT post_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2316 unary_expression_t *expr = (unary_expression_t*)_expr;
2317 VARIANT val, num;
2318 exprval_t exprval;
2319 HRESULT hres;
2321 TRACE("\n");
2323 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2324 if(FAILED(hres))
2325 return hres;
2327 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2328 if(SUCCEEDED(hres)) {
2329 hres = to_number(ctx->parser->script, &val, ei, &num);
2330 VariantClear(&val);
2333 if(SUCCEEDED(hres)) {
2334 VARIANT inc;
2335 num_set_val(&inc, num_val(&num)+1.0);
2336 hres = put_value(ctx->parser->script, &exprval, &inc, ei);
2339 exprval_release(&exprval);
2340 if(FAILED(hres))
2341 return hres;
2343 ret->type = EXPRVAL_VARIANT;
2344 ret->u.var = num;
2345 return S_OK;
2348 /* ECMA-262 3rd Edition 11.3.2 */
2349 HRESULT post_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2351 unary_expression_t *expr = (unary_expression_t*)_expr;
2352 VARIANT val, num;
2353 exprval_t exprval;
2354 HRESULT hres;
2356 TRACE("\n");
2358 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2359 if(FAILED(hres))
2360 return hres;
2362 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2363 if(SUCCEEDED(hres)) {
2364 hres = to_number(ctx->parser->script, &val, ei, &num);
2365 VariantClear(&val);
2368 if(SUCCEEDED(hres)) {
2369 VARIANT dec;
2370 num_set_val(&dec, num_val(&num)-1.0);
2371 hres = put_value(ctx->parser->script, &exprval, &dec, ei);
2374 exprval_release(&exprval);
2375 if(FAILED(hres))
2376 return hres;
2378 ret->type = EXPRVAL_VARIANT;
2379 ret->u.var = num;
2380 return S_OK;
2383 /* ECMA-262 3rd Edition 11.4.4 */
2384 HRESULT pre_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2386 unary_expression_t *expr = (unary_expression_t*)_expr;
2387 VARIANT val, num;
2388 exprval_t exprval;
2389 HRESULT hres;
2391 TRACE("\n");
2393 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2394 if(FAILED(hres))
2395 return hres;
2397 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2398 if(SUCCEEDED(hres)) {
2399 hres = to_number(ctx->parser->script, &val, ei, &num);
2400 VariantClear(&val);
2403 if(SUCCEEDED(hres)) {
2404 num_set_val(&val, num_val(&num)+1.0);
2405 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2408 exprval_release(&exprval);
2409 if(FAILED(hres))
2410 return hres;
2412 ret->type = EXPRVAL_VARIANT;
2413 ret->u.var = val;
2414 return S_OK;
2417 /* ECMA-262 3rd Edition 11.4.5 */
2418 HRESULT pre_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2420 unary_expression_t *expr = (unary_expression_t*)_expr;
2421 VARIANT val, num;
2422 exprval_t exprval;
2423 HRESULT hres;
2425 TRACE("\n");
2427 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2428 if(FAILED(hres))
2429 return hres;
2431 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2432 if(SUCCEEDED(hres)) {
2433 hres = to_number(ctx->parser->script, &val, ei, &num);
2434 VariantClear(&val);
2437 if(SUCCEEDED(hres)) {
2438 num_set_val(&val, num_val(&num)-1.0);
2439 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2442 exprval_release(&exprval);
2443 if(FAILED(hres))
2444 return hres;
2446 ret->type = EXPRVAL_VARIANT;
2447 ret->u.var = val;
2448 return S_OK;
2451 /* ECMA-262 3rd Edition 11.9.3 */
2452 static HRESULT equal_values(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
2454 if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
2455 return equal2_values(lval, rval, ret);
2457 /* FIXME: NULL disps should be handled in more general way */
2458 if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
2459 VARIANT v;
2460 V_VT(&v) = VT_NULL;
2461 return equal_values(ctx, &v, rval, ei, ret);
2464 if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
2465 VARIANT v;
2466 V_VT(&v) = VT_NULL;
2467 return equal_values(ctx, lval, &v, ei, ret);
2470 if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
2471 (V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
2472 *ret = TRUE;
2473 return S_OK;
2476 if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
2477 VARIANT v;
2478 HRESULT hres;
2480 hres = to_number(ctx->parser->script, lval, ei, &v);
2481 if(FAILED(hres))
2482 return hres;
2484 return equal_values(ctx, &v, rval, ei, ret);
2487 if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
2488 VARIANT v;
2489 HRESULT hres;
2491 hres = to_number(ctx->parser->script, rval, ei, &v);
2492 if(FAILED(hres))
2493 return hres;
2495 return equal_values(ctx, lval, &v, ei, ret);
2498 if(V_VT(rval) == VT_BOOL) {
2499 VARIANT v;
2501 V_VT(&v) = VT_I4;
2502 V_I4(&v) = V_BOOL(rval) ? 1 : 0;
2503 return equal_values(ctx, lval, &v, ei, ret);
2506 if(V_VT(lval) == VT_BOOL) {
2507 VARIANT v;
2509 V_VT(&v) = VT_I4;
2510 V_I4(&v) = V_BOOL(lval) ? 1 : 0;
2511 return equal_values(ctx, &v, rval, ei, ret);
2515 if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
2516 VARIANT v;
2517 HRESULT hres;
2519 hres = to_primitive(ctx->parser->script, rval, ei, &v);
2520 if(FAILED(hres))
2521 return hres;
2523 hres = equal_values(ctx, lval, &v, ei, ret);
2525 VariantClear(&v);
2526 return hres;
2530 if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
2531 VARIANT v;
2532 HRESULT hres;
2534 hres = to_primitive(ctx->parser->script, lval, ei, &v);
2535 if(FAILED(hres))
2536 return hres;
2538 hres = equal_values(ctx, &v, rval, ei, ret);
2540 VariantClear(&v);
2541 return hres;
2545 *ret = FALSE;
2546 return S_OK;
2549 /* ECMA-262 3rd Edition 11.9.1 */
2550 HRESULT equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2552 binary_expression_t *expr = (binary_expression_t*)_expr;
2553 VARIANT rval, lval;
2554 BOOL b;
2555 HRESULT hres;
2557 TRACE("\n");
2559 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2560 if(FAILED(hres))
2561 return hres;
2563 hres = equal_values(ctx, &rval, &lval, ei, &b);
2564 if(FAILED(hres))
2565 return hres;
2567 return return_bool(ret, b);
2570 /* ECMA-262 3rd Edition 11.9.4 */
2571 HRESULT equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2573 binary_expression_t *expr = (binary_expression_t*)_expr;
2574 VARIANT rval, lval;
2575 BOOL b;
2576 HRESULT hres;
2578 TRACE("\n");
2580 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2581 if(FAILED(hres))
2582 return hres;
2584 hres = equal2_values(&rval, &lval, &b);
2585 if(FAILED(hres))
2586 return hres;
2588 return return_bool(ret, b);
2591 /* ECMA-262 3rd Edition 11.9.2 */
2592 HRESULT not_equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2594 binary_expression_t *expr = (binary_expression_t*)_expr;
2595 VARIANT rval, lval;
2596 BOOL b;
2597 HRESULT hres;
2599 TRACE("\n");
2601 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2602 if(FAILED(hres))
2603 return hres;
2605 hres = equal_values(ctx, &lval, &rval, ei, &b);
2606 if(FAILED(hres))
2607 return hres;
2609 return return_bool(ret, !b);
2612 /* ECMA-262 3rd Edition 11.9.5 */
2613 HRESULT not_equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2615 binary_expression_t *expr = (binary_expression_t*)_expr;
2616 VARIANT rval, lval;
2617 BOOL b;
2618 HRESULT hres;
2620 TRACE("\n");
2622 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2623 if(FAILED(hres))
2624 return hres;
2626 hres = equal2_values(&lval, &rval, &b);
2627 if(FAILED(hres))
2628 return hres;
2630 return return_bool(ret, !b);
2633 /* ECMA-262 3rd Edition 11.8.5 */
2634 static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
2636 VARIANT l, r, ln, rn;
2637 HRESULT hres;
2639 hres = to_primitive(ctx->parser->script, lval, ei, &l);
2640 if(FAILED(hres))
2641 return hres;
2643 hres = to_primitive(ctx->parser->script, rval, ei, &r);
2644 if(FAILED(hres)) {
2645 VariantClear(&l);
2646 return hres;
2649 if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
2650 *ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
2651 SysFreeString(V_BSTR(&l));
2652 SysFreeString(V_BSTR(&r));
2653 return S_OK;
2656 hres = to_number(ctx->parser->script, &l, ei, &ln);
2657 VariantClear(&l);
2658 if(SUCCEEDED(hres))
2659 hres = to_number(ctx->parser->script, &r, ei, &rn);
2660 VariantClear(&r);
2661 if(FAILED(hres))
2662 return hres;
2664 if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
2665 *ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
2666 }else {
2667 DOUBLE ld = num_val(&ln);
2668 DOUBLE rd = num_val(&rn);
2670 *ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
2673 return S_OK;
2676 /* ECMA-262 3rd Edition 11.8.1 */
2677 HRESULT less_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2679 binary_expression_t *expr = (binary_expression_t*)_expr;
2680 VARIANT rval, lval;
2681 BOOL b;
2682 HRESULT hres;
2684 TRACE("\n");
2686 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2687 if(FAILED(hres))
2688 return hres;
2690 hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
2691 VariantClear(&lval);
2692 VariantClear(&rval);
2693 if(FAILED(hres))
2694 return hres;
2696 return return_bool(ret, b);
2699 /* ECMA-262 3rd Edition 11.8.3 */
2700 HRESULT lesseq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2702 binary_expression_t *expr = (binary_expression_t*)_expr;
2703 VARIANT rval, lval;
2704 BOOL b;
2705 HRESULT hres;
2707 TRACE("\n");
2709 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2710 if(FAILED(hres))
2711 return hres;
2713 hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
2714 VariantClear(&lval);
2715 VariantClear(&rval);
2716 if(FAILED(hres))
2717 return hres;
2719 return return_bool(ret, b);
2722 /* ECMA-262 3rd Edition 11.8.2 */
2723 HRESULT greater_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2725 binary_expression_t *expr = (binary_expression_t*)_expr;
2726 VARIANT rval, lval;
2727 BOOL b;
2728 HRESULT hres;
2730 TRACE("\n");
2732 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2733 if(FAILED(hres))
2734 return hres;
2736 hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
2737 VariantClear(&lval);
2738 VariantClear(&rval);
2739 if(FAILED(hres))
2740 return hres;
2742 return return_bool(ret, b);
2745 /* ECMA-262 3rd Edition 11.8.4 */
2746 HRESULT greatereq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2748 binary_expression_t *expr = (binary_expression_t*)_expr;
2749 VARIANT rval, lval;
2750 BOOL b;
2751 HRESULT hres;
2753 TRACE("\n");
2755 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2756 if(FAILED(hres))
2757 return hres;
2759 hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
2760 VariantClear(&lval);
2761 VariantClear(&rval);
2762 if(FAILED(hres))
2763 return hres;
2765 return return_bool(ret, b);
2768 /* ECMA-262 3rd Edition 11.4.8 */
2769 HRESULT binary_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2771 unary_expression_t *expr = (unary_expression_t*)_expr;
2772 exprval_t exprval;
2773 VARIANT val;
2774 INT i;
2775 HRESULT hres;
2777 TRACE("\n");
2779 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2780 if(FAILED(hres))
2781 return hres;
2783 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2784 exprval_release(&exprval);
2785 if(FAILED(hres))
2786 return hres;
2788 hres = to_int32(ctx->parser->script, &val, ei, &i);
2789 if(FAILED(hres))
2790 return hres;
2792 ret->type = EXPRVAL_VARIANT;
2793 V_VT(&ret->u.var) = VT_I4;
2794 V_I4(&ret->u.var) = ~i;
2795 return S_OK;
2798 /* ECMA-262 3rd Edition 11.4.9 */
2799 HRESULT logical_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2801 unary_expression_t *expr = (unary_expression_t*)_expr;
2802 exprval_t exprval;
2803 VARIANT_BOOL b;
2804 HRESULT hres;
2806 TRACE("\n");
2808 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2809 if(FAILED(hres))
2810 return hres;
2812 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
2813 exprval_release(&exprval);
2814 if(FAILED(hres))
2815 return hres;
2817 return return_bool(ret, !b);
2820 /* ECMA-262 3rd Edition 11.7.1 */
2821 static HRESULT lshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2823 DWORD ri;
2824 INT li;
2825 HRESULT hres;
2827 hres = to_int32(ctx->parser->script, lval, ei, &li);
2828 if(FAILED(hres))
2829 return hres;
2831 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2832 if(FAILED(hres))
2833 return hres;
2835 V_VT(retv) = VT_I4;
2836 V_I4(retv) = li << (ri&0x1f);
2837 return S_OK;
2840 /* ECMA-262 3rd Edition 11.7.1 */
2841 HRESULT left_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2843 binary_expression_t *expr = (binary_expression_t*)_expr;
2845 TRACE("\n");
2847 return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
2850 /* ECMA-262 3rd Edition 11.7.2 */
2851 static HRESULT rshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2853 DWORD ri;
2854 INT li;
2855 HRESULT hres;
2857 hres = to_int32(ctx->parser->script, lval, ei, &li);
2858 if(FAILED(hres))
2859 return hres;
2861 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2862 if(FAILED(hres))
2863 return hres;
2865 V_VT(retv) = VT_I4;
2866 V_I4(retv) = li >> (ri&0x1f);
2867 return S_OK;
2870 /* ECMA-262 3rd Edition 11.7.2 */
2871 HRESULT right_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2873 binary_expression_t *expr = (binary_expression_t*)_expr;
2875 TRACE("\n");
2877 return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
2880 /* ECMA-262 3rd Edition 11.7.3 */
2881 static HRESULT rshift2_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2883 DWORD li, ri;
2884 HRESULT hres;
2886 hres = to_uint32(ctx->parser->script, lval, ei, &li);
2887 if(FAILED(hres))
2888 return hres;
2890 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2891 if(FAILED(hres))
2892 return hres;
2894 V_VT(retv) = VT_I4;
2895 V_I4(retv) = li >> (ri&0x1f);
2896 return S_OK;
2899 /* ECMA-262 3rd Edition 11.7.3 */
2900 HRESULT right2_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2902 binary_expression_t *expr = (binary_expression_t*)_expr;
2904 TRACE("\n");
2906 return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
2909 /* ECMA-262 3rd Edition 11.13.1 */
2910 HRESULT assign_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;
2913 exprval_t exprval, exprvalr;
2914 VARIANT rval;
2915 HRESULT hres;
2917 TRACE("\n");
2919 hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
2920 if(FAILED(hres))
2921 return hres;
2923 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
2924 if(SUCCEEDED(hres)) {
2925 hres = exprval_to_value(ctx->parser->script, &exprvalr, ei, &rval);
2926 exprval_release(&exprvalr);
2929 if(SUCCEEDED(hres))
2930 hres = put_value(ctx->parser->script, &exprval, &rval, ei);
2932 exprval_release(&exprval);
2933 if(FAILED(hres))
2934 return hres;
2936 ret->type = EXPRVAL_VARIANT;
2937 ret->u.var = rval;
2938 return S_OK;
2941 /* ECMA-262 3rd Edition 11.13.2 */
2942 HRESULT assign_lshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2944 binary_expression_t *expr = (binary_expression_t*)_expr;
2946 TRACE("\n");
2948 return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
2951 /* ECMA-262 3rd Edition 11.13.2 */
2952 HRESULT assign_rshift_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, rshift_eval, ei, ret);
2961 /* ECMA-262 3rd Edition 11.13.2 */
2962 HRESULT assign_rrshift_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, rshift2_eval, ei, ret);
2971 /* ECMA-262 3rd Edition 11.13.2 */
2972 HRESULT assign_add_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, add_eval, ei, ret);
2981 /* ECMA-262 3rd Edition 11.13.2 */
2982 HRESULT assign_sub_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, sub_eval, ei, ret);
2991 /* ECMA-262 3rd Edition 11.13.2 */
2992 HRESULT assign_mul_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, mul_eval, ei, ret);
3001 /* ECMA-262 3rd Edition 11.13.2 */
3002 HRESULT assign_div_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, div_eval, ei, ret);
3011 /* ECMA-262 3rd Edition 11.13.2 */
3012 HRESULT assign_mod_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, mod_eval, ei, ret);
3021 /* ECMA-262 3rd Edition 11.13.2 */
3022 HRESULT assign_and_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, bitand_eval, ei, ret);
3031 /* ECMA-262 3rd Edition 11.13.2 */
3032 HRESULT assign_or_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, bitor_eval, ei, ret);
3041 /* ECMA-262 3rd Edition 11.13.2 */
3042 HRESULT assign_xor_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, xor_eval, ei, ret);