winapi: Fix the parse_c_declaration() prototype and remove unused variables.
[wine/hacks.git] / dlls / jscript / engine.c
blob05c6225daaeb70d335d9f36d840d965a2b95a7d2
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 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 WARN("Could not find identifier %s\n", debugstr_w(identifier));
520 return E_FAIL;
523 /* ECMA-262 3rd Edition 12.1 */
524 HRESULT block_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
526 block_statement_t *stat = (block_statement_t*)_stat;
527 VARIANT val, tmp;
528 statement_t *iter;
529 HRESULT hres = S_OK;
531 TRACE("\n");
533 V_VT(&val) = VT_EMPTY;
534 for(iter = stat->stat_list; iter; iter = iter->next) {
535 hres = stat_eval(ctx, iter, rt, &tmp);
536 if(FAILED(hres))
537 break;
539 VariantClear(&val);
540 val = tmp;
541 if(rt->type != RT_NORMAL)
542 break;
545 if(FAILED(hres)) {
546 VariantClear(&val);
547 return hres;
550 *ret = val;
551 return S_OK;
554 /* ECMA-262 3rd Edition 12.2 */
555 static HRESULT variable_list_eval(exec_ctx_t *ctx, variable_declaration_t *var_list, jsexcept_t *ei)
557 variable_declaration_t *iter;
558 HRESULT hres = S_OK;
560 for(iter = var_list; iter; iter = iter->next) {
561 exprval_t exprval;
562 VARIANT val;
564 if(!iter->expr)
565 continue;
567 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
568 if(FAILED(hres))
569 break;
571 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
572 exprval_release(&exprval);
573 if(FAILED(hres))
574 break;
576 hres = jsdisp_propput_name(ctx->var_disp, iter->identifier, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
577 VariantClear(&val);
578 if(FAILED(hres))
579 break;
582 return hres;
585 /* ECMA-262 3rd Edition 12.2 */
586 HRESULT var_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
588 var_statement_t *stat = (var_statement_t*)_stat;
589 HRESULT hres;
591 TRACE("\n");
593 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
594 if(FAILED(hres))
595 return hres;
597 V_VT(ret) = VT_EMPTY;
598 return S_OK;
601 /* ECMA-262 3rd Edition 12.3 */
602 HRESULT empty_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
604 TRACE("\n");
606 V_VT(ret) = VT_EMPTY;
607 return S_OK;
610 /* ECMA-262 3rd Edition 12.4 */
611 HRESULT expression_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
613 expression_statement_t *stat = (expression_statement_t*)_stat;
614 exprval_t exprval;
615 VARIANT val;
616 HRESULT hres;
618 TRACE("\n");
620 hres = expr_eval(ctx, stat->expr, EXPR_NOVAL, &rt->ei, &exprval);
621 if(FAILED(hres))
622 return hres;
624 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
625 exprval_release(&exprval);
626 if(FAILED(hres))
627 return hres;
629 *ret = val;
630 TRACE("= %s\n", debugstr_variant(ret));
631 return S_OK;
634 /* ECMA-262 3rd Edition 12.5 */
635 HRESULT if_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
637 if_statement_t *stat = (if_statement_t*)_stat;
638 exprval_t exprval;
639 VARIANT_BOOL b;
640 HRESULT hres;
642 TRACE("\n");
644 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
645 if(FAILED(hres))
646 return hres;
648 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
649 exprval_release(&exprval);
650 if(FAILED(hres))
651 return hres;
653 if(b)
654 hres = stat_eval(ctx, stat->if_stat, rt, ret);
655 else if(stat->else_stat)
656 hres = stat_eval(ctx, stat->else_stat, rt, ret);
657 else
658 V_VT(ret) = VT_EMPTY;
660 return hres;
663 /* ECMA-262 3rd Edition 12.6.2 */
664 HRESULT while_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
666 while_statement_t *stat = (while_statement_t*)_stat;
667 exprval_t exprval;
668 VARIANT val, tmp;
669 VARIANT_BOOL b;
670 BOOL test_expr;
671 HRESULT hres;
673 TRACE("\n");
675 V_VT(&val) = VT_EMPTY;
676 test_expr = !stat->do_while;
678 while(1) {
679 if(test_expr) {
680 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
681 if(FAILED(hres))
682 break;
684 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
685 exprval_release(&exprval);
686 if(FAILED(hres) || !b)
687 break;
688 }else {
689 test_expr = TRUE;
692 hres = stat_eval(ctx, stat->statement, rt, &tmp);
693 if(FAILED(hres))
694 break;
696 VariantClear(&val);
697 val = tmp;
699 if(rt->type == RT_CONTINUE)
700 rt->type = RT_NORMAL;
701 if(rt->type != RT_NORMAL)
702 break;
705 if(FAILED(hres)) {
706 VariantClear(&val);
707 return hres;
710 if(rt->type == RT_BREAK)
711 rt->type = RT_NORMAL;
713 *ret = val;
714 return S_OK;
717 /* ECMA-262 3rd Edition 12.6.3 */
718 HRESULT for_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
720 for_statement_t *stat = (for_statement_t*)_stat;
721 VARIANT val, tmp, retv;
722 exprval_t exprval;
723 VARIANT_BOOL b;
724 HRESULT hres;
726 TRACE("\n");
728 if(stat->variable_list) {
729 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
730 if(FAILED(hres))
731 return hres;
732 }else if(stat->begin_expr) {
733 hres = expr_eval(ctx, stat->begin_expr, EXPR_NEWREF, &rt->ei, &exprval);
734 if(FAILED(hres))
735 return hres;
737 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
738 exprval_release(&exprval);
739 if(FAILED(hres))
740 return hres;
742 VariantClear(&val);
745 V_VT(&retv) = VT_EMPTY;
747 while(1) {
748 if(stat->expr) {
749 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
750 if(FAILED(hres))
751 break;
753 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
754 exprval_release(&exprval);
755 if(FAILED(hres) || !b)
756 break;
759 hres = stat_eval(ctx, stat->statement, rt, &tmp);
760 if(FAILED(hres))
761 break;
763 VariantClear(&retv);
764 retv = tmp;
766 if(rt->type == RT_CONTINUE)
767 rt->type = RT_NORMAL;
768 else if(rt->type != RT_NORMAL)
769 break;
771 if(stat->end_expr) {
772 hres = expr_eval(ctx, stat->end_expr, 0, &rt->ei, &exprval);
773 if(FAILED(hres))
774 break;
776 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
777 exprval_release(&exprval);
778 if(FAILED(hres))
779 break;
781 VariantClear(&val);
785 if(FAILED(hres)) {
786 VariantClear(&retv);
787 return hres;
790 if(rt->type == RT_BREAK)
791 rt->type = RT_NORMAL;
793 *ret = retv;
794 return S_OK;
797 /* ECMA-262 3rd Edition 12.6.4 */
798 HRESULT forin_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
800 forin_statement_t *stat = (forin_statement_t*)_stat;
801 VARIANT val, name, retv, tmp;
802 DISPID id = DISPID_STARTENUM;
803 BSTR str, identifier = NULL;
804 IDispatchEx *in_obj;
805 exprval_t exprval;
806 HRESULT hres;
808 TRACE("\n");
810 if(stat->variable) {
811 hres = variable_list_eval(ctx, stat->variable, &rt->ei);
812 if(FAILED(hres))
813 return hres;
816 hres = expr_eval(ctx, stat->in_expr, EXPR_NEWREF, &rt->ei, &exprval);
817 if(FAILED(hres))
818 return hres;
820 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
821 exprval_release(&exprval);
822 if(FAILED(hres))
823 return hres;
825 if(V_VT(&val) != VT_DISPATCH) {
826 TRACE("in vt %d\n", V_VT(&val));
827 VariantClear(&val);
828 V_VT(ret) = VT_EMPTY;
829 return S_OK;
832 hres = IDispatch_QueryInterface(V_DISPATCH(&val), &IID_IDispatchEx, (void**)&in_obj);
833 IDispatch_Release(V_DISPATCH(&val));
834 if(FAILED(hres)) {
835 FIXME("Object doesn't support IDispatchEx\n");
836 return E_NOTIMPL;
839 V_VT(&retv) = VT_EMPTY;
841 if(stat->variable)
842 identifier = SysAllocString(stat->variable->identifier);
844 while(1) {
845 hres = IDispatchEx_GetNextDispID(in_obj, fdexEnumDefault, id, &id);
846 if(FAILED(hres) || hres == S_FALSE)
847 break;
849 hres = IDispatchEx_GetMemberName(in_obj, id, &str);
850 if(FAILED(hres))
851 break;
853 TRACE("iter %s\n", debugstr_w(str));
855 if(stat->variable)
856 hres = identifier_eval(ctx, identifier, 0, &exprval);
857 else
858 hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval);
859 if(SUCCEEDED(hres)) {
860 V_VT(&name) = VT_BSTR;
861 V_BSTR(&name) = str;
862 hres = put_value(ctx->parser->script, &exprval, &name, &rt->ei);
863 exprval_release(&exprval);
865 SysFreeString(str);
866 if(FAILED(hres))
867 break;
869 hres = stat_eval(ctx, stat->statement, rt, &tmp);
870 if(FAILED(hres))
871 break;
873 VariantClear(&retv);
874 retv = tmp;
876 if(rt->type == RT_CONTINUE)
877 rt->type = RT_NORMAL;
878 else if(rt->type != RT_NORMAL)
879 break;
882 SysFreeString(identifier);
883 IDispatchEx_Release(in_obj);
884 if(FAILED(hres)) {
885 VariantClear(&retv);
886 return hres;
889 if(rt->type == RT_BREAK)
890 rt->type = RT_NORMAL;
892 *ret = retv;
893 return S_OK;
896 /* ECMA-262 3rd Edition 12.7 */
897 HRESULT continue_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
899 branch_statement_t *stat = (branch_statement_t*)_stat;
901 TRACE("\n");
903 if(stat->identifier) {
904 FIXME("indentifier not implemented\n");
905 return E_NOTIMPL;
908 rt->type = RT_CONTINUE;
909 V_VT(ret) = VT_EMPTY;
910 return S_OK;
913 /* ECMA-262 3rd Edition 12.8 */
914 HRESULT break_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
916 branch_statement_t *stat = (branch_statement_t*)_stat;
918 TRACE("\n");
920 if(stat->identifier) {
921 FIXME("indentifier not implemented\n");
922 return E_NOTIMPL;
925 rt->type = RT_BREAK;
926 V_VT(ret) = VT_EMPTY;
927 return S_OK;
930 /* ECMA-262 3rd Edition 12.9 */
931 HRESULT return_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
933 expression_statement_t *stat = (expression_statement_t*)_stat;
934 HRESULT hres;
936 TRACE("\n");
938 if(stat->expr) {
939 exprval_t exprval;
941 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
942 if(FAILED(hres))
943 return hres;
945 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, ret);
946 exprval_release(&exprval);
947 if(FAILED(hres))
948 return hres;
949 }else {
950 V_VT(ret) = VT_EMPTY;
953 TRACE("= %s\n", debugstr_variant(ret));
954 rt->type = RT_RETURN;
955 return S_OK;
958 /* ECMA-262 3rd Edition 12.10 */
959 HRESULT with_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
961 with_statement_t *stat = (with_statement_t*)_stat;
962 exprval_t exprval;
963 IDispatch *disp;
964 DispatchEx *obj;
965 VARIANT val;
966 HRESULT hres;
968 TRACE("\n");
970 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
971 if(FAILED(hres))
972 return hres;
974 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
975 exprval_release(&exprval);
976 if(FAILED(hres))
977 return hres;
979 hres = to_object(ctx, &val, &disp);
980 VariantClear(&val);
981 if(FAILED(hres))
982 return hres;
984 obj = iface_to_jsdisp((IUnknown*)disp);
985 IDispatch_Release(disp);
986 if(!obj) {
987 FIXME("disp id not jsdisp\n");
988 return E_NOTIMPL;
991 hres = scope_push(ctx->scope_chain, obj, &ctx->scope_chain);
992 jsdisp_release(obj);
993 if(FAILED(hres))
994 return hres;
996 hres = stat_eval(ctx, stat->statement, rt, ret);
998 scope_pop(&ctx->scope_chain);
999 return hres;
1002 /* ECMA-262 3rd Edition 12.12 */
1003 HRESULT labelled_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
1005 FIXME("\n");
1006 return E_NOTIMPL;
1009 /* ECMA-262 3rd Edition 12.13 */
1010 HRESULT switch_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1012 switch_statement_t *stat = (switch_statement_t*)_stat;
1013 case_clausule_t *iter, *default_clausule = NULL;
1014 statement_t *stat_iter;
1015 VARIANT val, cval;
1016 exprval_t exprval;
1017 BOOL b;
1018 HRESULT hres;
1020 TRACE("\n");
1022 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1023 if(FAILED(hres))
1024 return hres;
1026 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1027 exprval_release(&exprval);
1028 if(FAILED(hres))
1029 return hres;
1031 for(iter = stat->case_list; iter; iter = iter->next) {
1032 if(!iter->expr) {
1033 default_clausule = iter;
1034 continue;
1037 hres = expr_eval(ctx, iter->expr, 0, &rt->ei, &exprval);
1038 if(FAILED(hres))
1039 break;
1041 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &cval);
1042 exprval_release(&exprval);
1043 if(FAILED(hres))
1044 break;
1046 hres = equal2_values(&val, &cval, &b);
1047 VariantClear(&cval);
1048 if(FAILED(hres) || b)
1049 break;
1052 VariantClear(&val);
1053 if(FAILED(hres))
1054 return hres;
1056 if(!iter)
1057 iter = default_clausule;
1059 V_VT(&val) = VT_EMPTY;
1060 if(iter) {
1061 VARIANT tmp;
1063 for(stat_iter = iter->stat; stat_iter; stat_iter = stat_iter->next) {
1064 hres = stat_eval(ctx, stat_iter, rt, &tmp);
1065 if(FAILED(hres))
1066 break;
1068 VariantClear(&val);
1069 val = tmp;
1071 if(rt->type != RT_NORMAL)
1072 break;
1076 if(FAILED(hres)) {
1077 VariantClear(&val);
1078 return hres;
1081 if(rt->type == RT_BREAK)
1082 rt->type = RT_NORMAL;
1084 *ret = val;
1085 return S_OK;
1088 /* ECMA-262 3rd Edition 12.13 */
1089 HRESULT throw_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1091 expression_statement_t *stat = (expression_statement_t*)_stat;
1092 exprval_t exprval;
1093 VARIANT val;
1094 HRESULT hres;
1096 TRACE("\n");
1098 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1099 if(FAILED(hres))
1100 return hres;
1102 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1103 exprval_release(&exprval);
1104 if(FAILED(hres))
1105 return hres;
1107 rt->ei.var = val;
1108 return DISP_E_EXCEPTION;
1111 /* ECMA-262 3rd Edition 12.14 */
1112 static HRESULT catch_eval(exec_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
1114 DispatchEx *var_disp;
1115 VARIANT ex, val;
1116 HRESULT hres;
1118 ex = rt->ei.var;
1119 memset(&rt->ei, 0, sizeof(jsexcept_t));
1121 hres = create_dispex(ctx->parser->script, NULL, NULL, &var_disp);
1122 if(SUCCEEDED(hres)) {
1123 hres = jsdisp_propput_name(var_disp, block->identifier, ctx->parser->script->lcid,
1124 &ex, &rt->ei, NULL/*FIXME*/);
1125 if(SUCCEEDED(hres)) {
1126 hres = scope_push(ctx->scope_chain, var_disp, &ctx->scope_chain);
1127 if(SUCCEEDED(hres)) {
1128 hres = stat_eval(ctx, block->statement, rt, &val);
1129 scope_pop(&ctx->scope_chain);
1133 jsdisp_release(var_disp);
1136 VariantClear(&ex);
1137 if(FAILED(hres))
1138 return hres;
1140 *ret = val;
1141 return S_OK;
1144 /* ECMA-262 3rd Edition 12.14 */
1145 HRESULT try_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1147 try_statement_t *stat = (try_statement_t*)_stat;
1148 VARIANT val;
1149 HRESULT hres;
1151 TRACE("\n");
1153 hres = stat_eval(ctx, stat->try_statement, rt, &val);
1154 if(FAILED(hres)) {
1155 TRACE("EXCEPTION\n");
1156 if(!stat->catch_block)
1157 return hres;
1159 hres = catch_eval(ctx, stat->catch_block, rt, &val);
1160 if(FAILED(hres))
1161 return hres;
1164 if(stat->finally_statement) {
1165 VariantClear(&val);
1166 hres = stat_eval(ctx, stat->finally_statement, rt, &val);
1167 if(FAILED(hres))
1168 return hres;
1171 *ret = val;
1172 return S_OK;
1175 static HRESULT return_bool(exprval_t *ret, DWORD b)
1177 ret->type = EXPRVAL_VARIANT;
1178 V_VT(&ret->u.var) = VT_BOOL;
1179 V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;
1181 return S_OK;
1184 static HRESULT get_binary_expr_values(exec_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
1186 exprval_t exprval;
1187 HRESULT hres;
1189 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1190 if(FAILED(hres))
1191 return hres;
1193 hres = exprval_to_value(ctx->parser->script, &exprval, ei, lval);
1194 exprval_release(&exprval);
1195 if(FAILED(hres))
1196 return hres;
1198 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1199 if(SUCCEEDED(hres)) {
1200 hres = exprval_to_value(ctx->parser->script, &exprval, ei, rval);
1201 exprval_release(&exprval);
1204 if(FAILED(hres)) {
1205 VariantClear(lval);
1206 return hres;
1209 return S_OK;
1212 typedef HRESULT (*oper_t)(exec_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);
1214 static HRESULT binary_expr_eval(exec_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
1215 exprval_t *ret)
1217 VARIANT lval, rval, retv;
1218 HRESULT hres;
1220 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1221 if(FAILED(hres))
1222 return hres;
1224 hres = oper(ctx, &lval, &rval, ei, &retv);
1225 VariantClear(&lval);
1226 VariantClear(&rval);
1227 if(FAILED(hres))
1228 return hres;
1230 ret->type = EXPRVAL_VARIANT;
1231 ret->u.var = retv;
1232 return S_OK;
1235 /* ECMA-262 3rd Edition 11.13.2 */
1236 static HRESULT assign_oper_eval(exec_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
1237 jsexcept_t *ei, exprval_t *ret)
1239 VARIANT retv, lval, rval;
1240 exprval_t exprval, exprvalr;
1241 HRESULT hres;
1243 hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
1244 if(FAILED(hres))
1245 return hres;
1247 hres = exprval_value(ctx->parser->script, &exprval, ei, &lval);
1248 if(SUCCEEDED(hres)) {
1249 hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
1250 if(SUCCEEDED(hres)) {
1251 hres = exprval_value(ctx->parser->script, &exprvalr, ei, &rval);
1252 exprval_release(&exprvalr);
1254 if(SUCCEEDED(hres)) {
1255 hres = oper(ctx, &lval, &rval, ei, &retv);
1256 VariantClear(&rval);
1258 VariantClear(&lval);
1261 if(SUCCEEDED(hres)) {
1262 hres = put_value(ctx->parser->script, &exprval, &retv, ei);
1263 if(FAILED(hres))
1264 VariantClear(&retv);
1266 exprval_release(&exprval);
1268 if(FAILED(hres))
1269 return hres;
1271 ret->type = EXPRVAL_VARIANT;
1272 ret->u.var = retv;
1273 return S_OK;
1276 /* ECMA-262 3rd Edition 13 */
1277 HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1279 function_expression_t *expr = (function_expression_t*)_expr;
1280 VARIANT var;
1281 HRESULT hres;
1283 TRACE("\n");
1285 if(expr->identifier) {
1286 hres = jsdisp_propget_name(ctx->var_disp, expr->identifier, ctx->parser->script->lcid, &var, ei, NULL/*FIXME*/);
1287 if(FAILED(hres))
1288 return hres;
1289 }else {
1290 DispatchEx *dispex;
1292 hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain,
1293 expr->src_str, expr->src_len, &dispex);
1294 if(FAILED(hres))
1295 return hres;
1297 V_VT(&var) = VT_DISPATCH;
1298 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
1301 ret->type = EXPRVAL_VARIANT;
1302 ret->u.var = var;
1303 return S_OK;
1306 /* ECMA-262 3rd Edition 11.12 */
1307 HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1309 conditional_expression_t *expr = (conditional_expression_t*)_expr;
1310 exprval_t exprval;
1311 VARIANT_BOOL b;
1312 HRESULT hres;
1314 TRACE("\n");
1316 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1317 if(FAILED(hres))
1318 return hres;
1320 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
1321 exprval_release(&exprval);
1322 if(FAILED(hres))
1323 return hres;
1325 return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
1328 /* ECMA-262 3rd Edition 11.2.1 */
1329 HRESULT array_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1331 array_expression_t *expr = (array_expression_t*)_expr;
1332 exprval_t exprval;
1333 VARIANT member, val;
1334 DISPID id;
1335 BSTR str;
1336 IDispatch *obj = NULL;
1337 HRESULT hres;
1339 TRACE("\n");
1341 hres = expr_eval(ctx, expr->member_expr, EXPR_NEWREF, ei, &exprval);
1342 if(FAILED(hres))
1343 return hres;
1345 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1346 exprval_release(&exprval);
1347 if(FAILED(hres))
1348 return hres;
1350 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
1351 if(SUCCEEDED(hres)) {
1352 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1353 exprval_release(&exprval);
1356 if(SUCCEEDED(hres))
1357 hres = to_object(ctx, &member, &obj);
1358 VariantClear(&member);
1359 if(SUCCEEDED(hres)) {
1360 hres = to_string(ctx->parser->script, &val, ei, &str);
1361 if(SUCCEEDED(hres)) {
1362 if(flags & EXPR_STRREF) {
1363 ret->type = EXPRVAL_NAMEREF;
1364 ret->u.nameref.disp = obj;
1365 ret->u.nameref.name = str;
1366 return S_OK;
1369 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1372 if(SUCCEEDED(hres)) {
1373 exprval_set_idref(ret, obj, id);
1374 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1375 exprval_init(ret);
1376 hres = S_OK;
1379 IDispatch_Release(obj);
1382 return hres;
1385 /* ECMA-262 3rd Edition 11.2.1 */
1386 HRESULT member_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1388 member_expression_t *expr = (member_expression_t*)_expr;
1389 IDispatch *obj = NULL;
1390 exprval_t exprval;
1391 VARIANT member;
1392 DISPID id;
1393 BSTR str;
1394 HRESULT hres;
1396 TRACE("\n");
1398 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1399 if(FAILED(hres))
1400 return hres;
1402 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1403 exprval_release(&exprval);
1404 if(FAILED(hres))
1405 return hres;
1407 hres = to_object(ctx, &member, &obj);
1408 VariantClear(&member);
1409 if(FAILED(hres))
1410 return hres;
1412 str = SysAllocString(expr->identifier);
1413 if(flags & EXPR_STRREF) {
1414 ret->type = EXPRVAL_NAMEREF;
1415 ret->u.nameref.disp = obj;
1416 ret->u.nameref.name = str;
1417 return S_OK;
1420 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1421 SysFreeString(str);
1422 if(SUCCEEDED(hres)) {
1423 exprval_set_idref(ret, obj, id);
1424 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1425 exprval_init(ret);
1426 hres = S_OK;
1429 IDispatch_Release(obj);
1430 return hres;
1433 static void free_dp(DISPPARAMS *dp)
1435 DWORD i;
1437 for(i=0; i < dp->cArgs; i++)
1438 VariantClear(dp->rgvarg+i);
1439 heap_free(dp->rgvarg);
1442 static HRESULT args_to_param(exec_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
1444 VARIANTARG *vargs;
1445 exprval_t exprval;
1446 argument_t *iter;
1447 DWORD cnt = 0, i;
1448 HRESULT hres = S_OK;
1450 memset(dp, 0, sizeof(*dp));
1451 if(!args)
1452 return S_OK;
1454 for(iter = args; iter; iter = iter->next)
1455 cnt++;
1457 vargs = heap_alloc_zero(cnt * sizeof(*vargs));
1458 if(!vargs)
1459 return E_OUTOFMEMORY;
1461 for(i = cnt, iter = args; iter; iter = iter->next) {
1462 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
1463 if(FAILED(hres))
1464 break;
1466 hres = exprval_to_value(ctx->parser->script, &exprval, ei, vargs + (--i));
1467 exprval_release(&exprval);
1468 if(FAILED(hres))
1469 break;
1472 if(FAILED(hres)) {
1473 free_dp(dp);
1474 return hres;
1477 dp->rgvarg = vargs;
1478 dp->cArgs = cnt;
1479 return S_OK;
1482 /* ECMA-262 3rd Edition 11.2.2 */
1483 HRESULT new_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1485 call_expression_t *expr = (call_expression_t*)_expr;
1486 exprval_t exprval;
1487 VARIANT constr, var;
1488 DISPPARAMS dp;
1489 HRESULT hres;
1491 TRACE("\n");
1493 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1494 if(FAILED(hres))
1495 return hres;
1497 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1498 if(SUCCEEDED(hres))
1499 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &constr);
1500 exprval_release(&exprval);
1501 if(FAILED(hres))
1502 return hres;
1504 if(V_VT(&constr) != VT_DISPATCH) {
1505 FIXME("throw TypeError\n");
1506 VariantClear(&constr);
1507 return E_FAIL;
1510 hres = disp_call(V_DISPATCH(&constr), DISPID_VALUE, ctx->parser->script->lcid,
1511 DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
1512 IDispatch_Release(V_DISPATCH(&constr));
1513 if(FAILED(hres))
1514 return hres;
1516 ret->type = EXPRVAL_VARIANT;
1517 ret->u.var = var;
1518 return S_OK;
1521 /* ECMA-262 3rd Edition 11.2.3 */
1522 HRESULT call_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1524 call_expression_t *expr = (call_expression_t*)_expr;
1525 VARIANT var;
1526 exprval_t exprval;
1527 DISPPARAMS dp;
1528 HRESULT hres;
1530 TRACE("\n");
1532 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1533 if(FAILED(hres))
1534 return hres;
1536 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1537 if(SUCCEEDED(hres)) {
1538 switch(exprval.type) {
1539 case EXPRVAL_IDREF:
1540 hres = disp_call(exprval.u.idref.disp, exprval.u.idref.id, ctx->parser->script->lcid, DISPATCH_METHOD,
1541 &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1542 if(flags & EXPR_NOVAL)
1543 V_VT(&var) = VT_EMPTY;
1544 break;
1545 default:
1546 FIXME("unimplemented type %d\n", exprval.type);
1547 hres = E_NOTIMPL;
1550 free_dp(&dp);
1553 exprval_release(&exprval);
1554 if(FAILED(hres))
1555 return hres;
1557 TRACE("= %s\n", debugstr_variant(&var));
1558 ret->type = EXPRVAL_VARIANT;
1559 ret->u.var = var;
1560 return S_OK;
1563 /* ECMA-262 3rd Edition 11.1.1 */
1564 HRESULT this_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1566 TRACE("\n");
1568 ret->type = EXPRVAL_VARIANT;
1569 V_VT(&ret->u.var) = VT_DISPATCH;
1570 V_DISPATCH(&ret->u.var) = ctx->this_obj;
1571 IDispatch_AddRef(ctx->this_obj);
1572 return S_OK;
1575 /* ECMA-262 3rd Edition 10.1.4 */
1576 HRESULT identifier_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1578 identifier_expression_t *expr = (identifier_expression_t*)_expr;
1579 BSTR identifier;
1580 HRESULT hres;
1582 TRACE("\n");
1584 identifier = SysAllocString(expr->identifier);
1585 if(!identifier)
1586 return E_OUTOFMEMORY;
1588 hres = identifier_eval(ctx, identifier, flags, ret);
1590 SysFreeString(identifier);
1591 return hres;
1594 /* ECMA-262 3rd Edition 7.8 */
1595 HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1597 literal_expression_t *expr = (literal_expression_t*)_expr;
1598 VARIANT var;
1599 HRESULT hres;
1601 TRACE("\n");
1603 hres = literal_to_var(expr->literal, &var);
1604 if(FAILED(hres))
1605 return hres;
1607 ret->type = EXPRVAL_VARIANT;
1608 ret->u.var = var;
1609 return S_OK;
1612 /* ECMA-262 3rd Edition 11.1.4 */
1613 HRESULT array_literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1615 array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
1616 DWORD length = 0, i = 0;
1617 array_element_t *elem;
1618 DispatchEx *array;
1619 exprval_t exprval;
1620 VARIANT val;
1621 HRESULT hres;
1623 TRACE("\n");
1625 for(elem = expr->element_list; elem; elem = elem->next)
1626 length += elem->elision+1;
1627 length += expr->length;
1629 hres = create_array(ctx->parser->script, length, &array);
1630 if(FAILED(hres))
1631 return hres;
1633 for(elem = expr->element_list; elem; elem = elem->next) {
1634 i += elem->elision;
1636 hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
1637 if(FAILED(hres))
1638 break;
1640 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1641 exprval_release(&exprval);
1642 if(FAILED(hres))
1643 break;
1645 hres = jsdisp_propput_idx(array, i, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1646 VariantClear(&val);
1647 if(FAILED(hres))
1648 break;
1650 i++;
1653 if(FAILED(hres)) {
1654 jsdisp_release(array);
1655 return hres;
1658 ret->type = EXPRVAL_VARIANT;
1659 V_VT(&ret->u.var) = VT_DISPATCH;
1660 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(array);
1661 return S_OK;
1664 /* ECMA-262 3rd Edition 11.1.5 */
1665 HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1667 property_value_expression_t *expr = (property_value_expression_t*)_expr;
1668 VARIANT val, tmp;
1669 DispatchEx *obj;
1670 prop_val_t *iter;
1671 exprval_t exprval;
1672 BSTR name;
1673 HRESULT hres;
1675 TRACE("\n");
1677 hres = create_object(ctx->parser->script, NULL, &obj);
1678 if(FAILED(hres))
1679 return hres;
1681 for(iter = expr->property_list; iter; iter = iter->next) {
1682 hres = literal_to_var(iter->name, &tmp);
1683 if(FAILED(hres))
1684 break;
1686 hres = to_string(ctx->parser->script, &tmp, ei, &name);
1687 VariantClear(&tmp);
1688 if(FAILED(hres))
1689 break;
1691 hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
1692 if(SUCCEEDED(hres)) {
1693 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1694 exprval_release(&exprval);
1695 if(SUCCEEDED(hres)) {
1696 hres = jsdisp_propput_name(obj, name, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1697 VariantClear(&val);
1701 SysFreeString(name);
1702 if(FAILED(hres))
1703 break;
1706 if(FAILED(hres)) {
1707 jsdisp_release(obj);
1708 return hres;
1711 ret->type = EXPRVAL_VARIANT;
1712 V_VT(&ret->u.var) = VT_DISPATCH;
1713 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(obj);
1714 return S_OK;
1717 /* ECMA-262 3rd Edition 11.14 */
1718 HRESULT comma_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1720 binary_expression_t *expr = (binary_expression_t*)_expr;
1721 VARIANT lval, rval;
1722 HRESULT hres;
1724 TRACE("\n");
1726 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1727 if(FAILED(hres))
1728 return hres;
1730 VariantClear(&lval);
1732 ret->type = EXPRVAL_VARIANT;
1733 ret->u.var = rval;
1734 return S_OK;
1737 /* ECMA-262 3rd Edition 11.11 */
1738 HRESULT logical_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1740 binary_expression_t *expr = (binary_expression_t*)_expr;
1741 exprval_t exprval;
1742 VARIANT_BOOL b;
1743 VARIANT val;
1744 HRESULT hres;
1746 TRACE("\n");
1748 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1749 if(FAILED(hres))
1750 return hres;
1752 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1753 exprval_release(&exprval);
1754 if(FAILED(hres))
1755 return hres;
1757 hres = to_boolean(&val, &b);
1758 if(SUCCEEDED(hres) && b) {
1759 ret->type = EXPRVAL_VARIANT;
1760 ret->u.var = val;
1761 return S_OK;
1764 VariantClear(&val);
1765 if(FAILED(hres))
1766 return hres;
1768 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1769 if(FAILED(hres))
1770 return hres;
1772 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1773 exprval_release(&exprval);
1774 if(FAILED(hres))
1775 return hres;
1777 ret->type = EXPRVAL_VARIANT;
1778 ret->u.var = val;
1779 return S_OK;
1782 /* ECMA-262 3rd Edition 11.11 */
1783 HRESULT logical_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1785 binary_expression_t *expr = (binary_expression_t*)_expr;
1786 exprval_t exprval;
1787 VARIANT_BOOL b;
1788 VARIANT val;
1789 HRESULT hres;
1791 TRACE("\n");
1793 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1794 if(FAILED(hres))
1795 return hres;
1797 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1798 exprval_release(&exprval);
1799 if(FAILED(hres))
1800 return hres;
1802 hres = to_boolean(&val, &b);
1803 if(SUCCEEDED(hres) && !b) {
1804 ret->type = EXPRVAL_VARIANT;
1805 ret->u.var = val;
1806 return S_OK;
1809 VariantClear(&val);
1810 if(FAILED(hres))
1811 return hres;
1813 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1814 if(FAILED(hres))
1815 return hres;
1817 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1818 exprval_release(&exprval);
1819 if(FAILED(hres))
1820 return hres;
1822 ret->type = EXPRVAL_VARIANT;
1823 ret->u.var = val;
1824 return S_OK;
1827 /* ECMA-262 3rd Edition 11.10 */
1828 static HRESULT bitor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1830 INT li, ri;
1831 HRESULT hres;
1833 hres = to_int32(ctx->parser->script, lval, ei, &li);
1834 if(FAILED(hres))
1835 return hres;
1837 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1838 if(FAILED(hres))
1839 return hres;
1841 V_VT(retv) = VT_I4;
1842 V_I4(retv) = li|ri;
1843 return S_OK;
1846 /* ECMA-262 3rd Edition 11.10 */
1847 HRESULT binary_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1849 binary_expression_t *expr = (binary_expression_t*)_expr;
1851 TRACE("\n");
1853 return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
1856 /* ECMA-262 3rd Edition 11.10 */
1857 static HRESULT xor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1859 INT li, ri;
1860 HRESULT hres;
1862 hres = to_int32(ctx->parser->script, lval, ei, &li);
1863 if(FAILED(hres))
1864 return hres;
1866 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1867 if(FAILED(hres))
1868 return hres;
1870 V_VT(retv) = VT_I4;
1871 V_I4(retv) = li^ri;
1872 return S_OK;
1875 /* ECMA-262 3rd Edition 11.10 */
1876 HRESULT binary_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1878 binary_expression_t *expr = (binary_expression_t*)_expr;
1880 TRACE("\n");
1882 return binary_expr_eval(ctx, expr, xor_eval, ei, ret);
1885 /* ECMA-262 3rd Edition 11.10 */
1886 static HRESULT bitand_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1888 INT li, ri;
1889 HRESULT hres;
1891 hres = to_int32(ctx->parser->script, lval, ei, &li);
1892 if(FAILED(hres))
1893 return hres;
1895 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1896 if(FAILED(hres))
1897 return hres;
1899 V_VT(retv) = VT_I4;
1900 V_I4(retv) = li&ri;
1901 return S_OK;
1904 /* ECMA-262 3rd Edition 11.10 */
1905 HRESULT binary_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1907 binary_expression_t *expr = (binary_expression_t*)_expr;
1909 TRACE("\n");
1911 return binary_expr_eval(ctx, expr, bitand_eval, ei, ret);
1914 /* ECMA-262 3rd Edition 11.8.6 */
1915 HRESULT instanceof_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1917 FIXME("\n");
1918 return E_NOTIMPL;
1921 /* ECMA-262 3rd Edition 11.8.7 */
1922 HRESULT in_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1924 FIXME("\n");
1925 return E_NOTIMPL;
1928 /* ECMA-262 3rd Edition 11.6.1 */
1929 static HRESULT add_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1931 VARIANT r, l;
1932 HRESULT hres;
1934 hres = to_primitive(ctx->parser->script, lval, ei, &l);
1935 if(FAILED(hres))
1936 return hres;
1938 hres = to_primitive(ctx->parser->script, rval, ei, &r);
1939 if(FAILED(hres)) {
1940 VariantClear(&l);
1941 return hres;
1944 if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
1945 BSTR lstr = NULL, rstr = NULL;
1947 if(V_VT(&l) == VT_BSTR)
1948 lstr = V_BSTR(&l);
1949 else
1950 hres = to_string(ctx->parser->script, &l, ei, &lstr);
1952 if(SUCCEEDED(hres)) {
1953 if(V_VT(&r) == VT_BSTR)
1954 rstr = V_BSTR(&r);
1955 else
1956 hres = to_string(ctx->parser->script, &r, ei, &rstr);
1959 if(SUCCEEDED(hres)) {
1960 int len1, len2;
1962 len1 = SysStringLen(lstr);
1963 len2 = SysStringLen(rstr);
1965 V_VT(retv) = VT_BSTR;
1966 V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
1967 memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
1968 memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
1971 if(V_VT(&l) != VT_BSTR)
1972 SysFreeString(lstr);
1973 if(V_VT(&r) != VT_BSTR)
1974 SysFreeString(rstr);
1975 }else {
1976 VARIANT nl, nr;
1978 hres = to_number(ctx->parser->script, &l, ei, &nl);
1979 if(SUCCEEDED(hres)) {
1980 hres = to_number(ctx->parser->script, &r, ei, &nr);
1981 if(SUCCEEDED(hres))
1982 num_set_val(retv, num_val(&nl) + num_val(&nr));
1986 VariantClear(&r);
1987 VariantClear(&l);
1988 return hres;
1991 /* ECMA-262 3rd Edition 11.6.1 */
1992 HRESULT add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1994 binary_expression_t *expr = (binary_expression_t*)_expr;
1996 TRACE("\n");
1998 return binary_expr_eval(ctx, expr, add_eval, ei, ret);
2001 /* ECMA-262 3rd Edition 11.6.2 */
2002 static HRESULT sub_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2004 VARIANT lnum, rnum;
2005 HRESULT hres;
2007 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2008 if(FAILED(hres))
2009 return hres;
2011 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2012 if(FAILED(hres))
2013 return hres;
2015 num_set_val(retv, num_val(&lnum) - num_val(&rnum));
2016 return S_OK;
2019 /* ECMA-262 3rd Edition 11.6.2 */
2020 HRESULT sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2022 binary_expression_t *expr = (binary_expression_t*)_expr;
2024 TRACE("\n");
2026 return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
2029 /* ECMA-262 3rd Edition 11.5.1 */
2030 static HRESULT mul_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2032 VARIANT lnum, rnum;
2033 HRESULT hres;
2035 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2036 if(FAILED(hres))
2037 return hres;
2039 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2040 if(FAILED(hres))
2041 return hres;
2043 num_set_val(retv, num_val(&lnum) * num_val(&rnum));
2044 return S_OK;
2047 /* ECMA-262 3rd Edition 11.5.1 */
2048 HRESULT mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2050 binary_expression_t *expr = (binary_expression_t*)_expr;
2052 TRACE("\n");
2054 return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
2057 /* ECMA-262 3rd Edition 11.5.2 */
2058 static HRESULT div_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2060 VARIANT lnum, rnum;
2061 HRESULT hres;
2063 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2064 if(FAILED(hres))
2065 return hres;
2067 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2068 if(FAILED(hres))
2069 return hres;
2071 num_set_val(retv, num_val(&lnum) / num_val(&rnum));
2072 return S_OK;
2075 /* ECMA-262 3rd Edition 11.5.2 */
2076 HRESULT div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2078 binary_expression_t *expr = (binary_expression_t*)_expr;
2080 TRACE("\n");
2082 return binary_expr_eval(ctx, expr, div_eval, ei, ret);
2085 /* ECMA-262 3rd Edition 11.5.3 */
2086 static HRESULT mod_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2088 VARIANT lnum, rnum;
2089 HRESULT hres;
2091 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2092 if(FAILED(hres))
2093 return hres;
2095 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2096 if(FAILED(hres))
2097 return hres;
2099 num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
2100 return S_OK;
2103 /* ECMA-262 3rd Edition 11.5.3 */
2104 HRESULT mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2106 binary_expression_t *expr = (binary_expression_t*)_expr;
2108 TRACE("\n");
2110 return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
2113 /* ECMA-262 3rd Edition 11.4.2 */
2114 HRESULT delete_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2116 unary_expression_t *expr = (unary_expression_t*)_expr;
2117 VARIANT_BOOL b = VARIANT_FALSE;
2118 exprval_t exprval;
2119 HRESULT hres;
2121 TRACE("\n");
2123 hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
2124 if(FAILED(hres))
2125 return hres;
2127 switch(exprval.type) {
2128 case EXPRVAL_IDREF: {
2129 IDispatchEx *dispex;
2131 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2132 if(SUCCEEDED(hres)) {
2133 hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
2134 b = VARIANT_TRUE;
2135 IDispatchEx_Release(dispex);
2137 break;
2139 case EXPRVAL_NAMEREF: {
2140 IDispatchEx *dispex;
2142 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2143 if(SUCCEEDED(hres)) {
2144 hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name, fdexNameCaseSensitive);
2145 b = VARIANT_TRUE;
2146 IDispatchEx_Release(dispex);
2148 break;
2150 default:
2151 FIXME("unsupported type %d\n", exprval.type);
2152 hres = E_NOTIMPL;
2155 exprval_release(&exprval);
2156 if(FAILED(hres))
2157 return hres;
2159 return return_bool(ret, b);
2162 /* ECMA-262 3rd Edition 11.4.2 */
2163 HRESULT void_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2165 unary_expression_t *expr = (unary_expression_t*)_expr;
2166 exprval_t exprval;
2167 VARIANT tmp;
2168 HRESULT hres;
2170 TRACE("\n");
2172 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2173 if(FAILED(hres))
2174 return hres;
2176 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &tmp);
2177 exprval_release(&exprval);
2178 if(FAILED(hres))
2179 return hres;
2181 VariantClear(&tmp);
2183 ret->type = EXPRVAL_VARIANT;
2184 V_VT(&ret->u.var) = VT_EMPTY;
2185 return S_OK;
2188 /* ECMA-262 3rd Edition 11.4.3 */
2189 HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2191 unary_expression_t *expr = (unary_expression_t*)_expr;
2192 const WCHAR *str;
2193 exprval_t exprval;
2194 VARIANT val;
2195 HRESULT hres;
2197 static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
2198 static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
2199 static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
2200 static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
2201 static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
2202 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
2204 TRACE("\n");
2206 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2207 if(FAILED(hres))
2208 return hres;
2210 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2211 exprval_release(&exprval);
2212 if(FAILED(hres))
2213 return hres;
2215 switch(V_VT(&val)) {
2216 case VT_EMPTY:
2217 str = undefinedW;
2218 break;
2219 case VT_NULL:
2220 str = objectW;
2221 break;
2222 case VT_BOOL:
2223 str = booleanW;
2224 break;
2225 case VT_I4:
2226 case VT_R8:
2227 str = numberW;
2228 break;
2229 case VT_BSTR:
2230 str = stringW;
2231 break;
2232 case VT_DISPATCH: {
2233 DispatchEx *dispex;
2235 dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val));
2236 if(dispex) {
2237 str = dispex->builtin_info->class == JSCLASS_FUNCTION ? functionW : objectW;
2238 IDispatchEx_Release(_IDispatchEx_(dispex));
2239 }else {
2240 str = objectW;
2242 break;
2244 default:
2245 FIXME("unhandled vt %d\n", V_VT(&val));
2246 VariantClear(&val);
2247 return E_NOTIMPL;
2250 VariantClear(&val);
2252 ret->type = EXPRVAL_VARIANT;
2253 V_VT(&ret->u.var) = VT_BSTR;
2254 V_BSTR(&ret->u.var) = SysAllocString(str);
2255 return S_OK;
2258 /* ECMA-262 3rd Edition 11.4.7 */
2259 HRESULT minus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2261 unary_expression_t *expr = (unary_expression_t*)_expr;
2262 exprval_t exprval;
2263 VARIANT val, num;
2264 HRESULT hres;
2266 TRACE("\n");
2268 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2269 if(FAILED(hres))
2270 return hres;
2272 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2273 exprval_release(&exprval);
2274 if(FAILED(hres))
2275 return hres;
2277 hres = to_number(ctx->parser->script, &val, ei, &num);
2278 VariantClear(&val);
2279 if(FAILED(hres))
2280 return hres;
2282 ret->type = EXPRVAL_VARIANT;
2283 num_set_val(&ret->u.var, -num_val(&num));
2284 return S_OK;
2287 /* ECMA-262 3rd Edition 11.4.6 */
2288 HRESULT plus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2290 unary_expression_t *expr = (unary_expression_t*)_expr;
2291 exprval_t exprval;
2292 VARIANT val, num;
2293 HRESULT hres;
2295 TRACE("\n");
2297 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2298 if(FAILED(hres))
2299 return hres;
2301 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2302 exprval_release(&exprval);
2303 if(FAILED(hres))
2304 return hres;
2306 hres = to_number(ctx->parser->script, &val, ei, &num);
2307 if(FAILED(hres))
2308 return hres;
2310 ret->type = EXPRVAL_VARIANT;
2311 ret->u.var = num;
2312 return S_OK;
2315 /* ECMA-262 3rd Edition 11.3.1 */
2316 HRESULT post_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2318 unary_expression_t *expr = (unary_expression_t*)_expr;
2319 VARIANT val, num;
2320 exprval_t exprval;
2321 HRESULT hres;
2323 TRACE("\n");
2325 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2326 if(FAILED(hres))
2327 return hres;
2329 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2330 if(SUCCEEDED(hres)) {
2331 hres = to_number(ctx->parser->script, &val, ei, &num);
2332 VariantClear(&val);
2335 if(SUCCEEDED(hres)) {
2336 VARIANT inc;
2337 num_set_val(&inc, num_val(&num)+1.0);
2338 hres = put_value(ctx->parser->script, &exprval, &inc, ei);
2341 exprval_release(&exprval);
2342 if(FAILED(hres))
2343 return hres;
2345 ret->type = EXPRVAL_VARIANT;
2346 ret->u.var = num;
2347 return S_OK;
2350 /* ECMA-262 3rd Edition 11.3.2 */
2351 HRESULT post_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2353 unary_expression_t *expr = (unary_expression_t*)_expr;
2354 VARIANT val, num;
2355 exprval_t exprval;
2356 HRESULT hres;
2358 TRACE("\n");
2360 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2361 if(FAILED(hres))
2362 return hres;
2364 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2365 if(SUCCEEDED(hres)) {
2366 hres = to_number(ctx->parser->script, &val, ei, &num);
2367 VariantClear(&val);
2370 if(SUCCEEDED(hres)) {
2371 VARIANT dec;
2372 num_set_val(&dec, num_val(&num)-1.0);
2373 hres = put_value(ctx->parser->script, &exprval, &dec, ei);
2376 exprval_release(&exprval);
2377 if(FAILED(hres))
2378 return hres;
2380 ret->type = EXPRVAL_VARIANT;
2381 ret->u.var = num;
2382 return S_OK;
2385 /* ECMA-262 3rd Edition 11.4.4 */
2386 HRESULT pre_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2388 unary_expression_t *expr = (unary_expression_t*)_expr;
2389 VARIANT val, num;
2390 exprval_t exprval;
2391 HRESULT hres;
2393 TRACE("\n");
2395 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2396 if(FAILED(hres))
2397 return hres;
2399 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2400 if(SUCCEEDED(hres)) {
2401 hres = to_number(ctx->parser->script, &val, ei, &num);
2402 VariantClear(&val);
2405 if(SUCCEEDED(hres)) {
2406 num_set_val(&val, num_val(&num)+1.0);
2407 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2410 exprval_release(&exprval);
2411 if(FAILED(hres))
2412 return hres;
2414 ret->type = EXPRVAL_VARIANT;
2415 ret->u.var = val;
2416 return S_OK;
2419 /* ECMA-262 3rd Edition 11.4.5 */
2420 HRESULT pre_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2422 unary_expression_t *expr = (unary_expression_t*)_expr;
2423 VARIANT val, num;
2424 exprval_t exprval;
2425 HRESULT hres;
2427 TRACE("\n");
2429 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2430 if(FAILED(hres))
2431 return hres;
2433 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2434 if(SUCCEEDED(hres)) {
2435 hres = to_number(ctx->parser->script, &val, ei, &num);
2436 VariantClear(&val);
2439 if(SUCCEEDED(hres)) {
2440 num_set_val(&val, num_val(&num)-1.0);
2441 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2444 exprval_release(&exprval);
2445 if(FAILED(hres))
2446 return hres;
2448 ret->type = EXPRVAL_VARIANT;
2449 ret->u.var = val;
2450 return S_OK;
2453 /* ECMA-262 3rd Edition 11.9.3 */
2454 static HRESULT equal_values(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
2456 if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
2457 return equal2_values(lval, rval, ret);
2459 /* FIXME: NULL disps should be handled in more general way */
2460 if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
2461 VARIANT v;
2462 V_VT(&v) = VT_NULL;
2463 return equal_values(ctx, &v, rval, ei, ret);
2466 if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
2467 VARIANT v;
2468 V_VT(&v) = VT_NULL;
2469 return equal_values(ctx, lval, &v, ei, ret);
2472 if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
2473 (V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
2474 *ret = TRUE;
2475 return S_OK;
2478 if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
2479 VARIANT v;
2480 HRESULT hres;
2482 hres = to_number(ctx->parser->script, lval, ei, &v);
2483 if(FAILED(hres))
2484 return hres;
2486 return equal_values(ctx, &v, rval, ei, ret);
2489 if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
2490 VARIANT v;
2491 HRESULT hres;
2493 hres = to_number(ctx->parser->script, rval, ei, &v);
2494 if(FAILED(hres))
2495 return hres;
2497 return equal_values(ctx, lval, &v, ei, ret);
2500 if(V_VT(rval) == VT_BOOL) {
2501 VARIANT v;
2503 V_VT(&v) = VT_I4;
2504 V_I4(&v) = V_BOOL(rval) ? 1 : 0;
2505 return equal_values(ctx, lval, &v, ei, ret);
2508 if(V_VT(lval) == VT_BOOL) {
2509 VARIANT v;
2511 V_VT(&v) = VT_I4;
2512 V_I4(&v) = V_BOOL(lval) ? 1 : 0;
2513 return equal_values(ctx, &v, rval, ei, ret);
2517 if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
2518 VARIANT v;
2519 HRESULT hres;
2521 hres = to_primitive(ctx->parser->script, rval, ei, &v);
2522 if(FAILED(hres))
2523 return hres;
2525 hres = equal_values(ctx, lval, &v, ei, ret);
2527 VariantClear(&v);
2528 return hres;
2532 if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
2533 VARIANT v;
2534 HRESULT hres;
2536 hres = to_primitive(ctx->parser->script, lval, ei, &v);
2537 if(FAILED(hres))
2538 return hres;
2540 hres = equal_values(ctx, &v, rval, ei, ret);
2542 VariantClear(&v);
2543 return hres;
2547 *ret = FALSE;
2548 return S_OK;
2551 /* ECMA-262 3rd Edition 11.9.1 */
2552 HRESULT equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2554 binary_expression_t *expr = (binary_expression_t*)_expr;
2555 VARIANT rval, lval;
2556 BOOL b;
2557 HRESULT hres;
2559 TRACE("\n");
2561 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2562 if(FAILED(hres))
2563 return hres;
2565 hres = equal_values(ctx, &rval, &lval, ei, &b);
2566 if(FAILED(hres))
2567 return hres;
2569 return return_bool(ret, b);
2572 /* ECMA-262 3rd Edition 11.9.4 */
2573 HRESULT equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2575 binary_expression_t *expr = (binary_expression_t*)_expr;
2576 VARIANT rval, lval;
2577 BOOL b;
2578 HRESULT hres;
2580 TRACE("\n");
2582 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2583 if(FAILED(hres))
2584 return hres;
2586 hres = equal2_values(&rval, &lval, &b);
2587 if(FAILED(hres))
2588 return hres;
2590 return return_bool(ret, b);
2593 /* ECMA-262 3rd Edition 11.9.2 */
2594 HRESULT not_equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2596 binary_expression_t *expr = (binary_expression_t*)_expr;
2597 VARIANT rval, lval;
2598 BOOL b;
2599 HRESULT hres;
2601 TRACE("\n");
2603 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2604 if(FAILED(hres))
2605 return hres;
2607 hres = equal_values(ctx, &lval, &rval, ei, &b);
2608 if(FAILED(hres))
2609 return hres;
2611 return return_bool(ret, !b);
2614 /* ECMA-262 3rd Edition 11.9.5 */
2615 HRESULT not_equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2617 binary_expression_t *expr = (binary_expression_t*)_expr;
2618 VARIANT rval, lval;
2619 BOOL b;
2620 HRESULT hres;
2622 TRACE("\n");
2624 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2625 if(FAILED(hres))
2626 return hres;
2628 hres = equal2_values(&lval, &rval, &b);
2629 if(FAILED(hres))
2630 return hres;
2632 return return_bool(ret, !b);
2635 /* ECMA-262 3rd Edition 11.8.5 */
2636 static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
2638 VARIANT l, r, ln, rn;
2639 HRESULT hres;
2641 hres = to_primitive(ctx->parser->script, lval, ei, &l);
2642 if(FAILED(hres))
2643 return hres;
2645 hres = to_primitive(ctx->parser->script, rval, ei, &r);
2646 if(FAILED(hres)) {
2647 VariantClear(&l);
2648 return hres;
2651 if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
2652 *ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
2653 SysFreeString(V_BSTR(&l));
2654 SysFreeString(V_BSTR(&r));
2655 return S_OK;
2658 hres = to_number(ctx->parser->script, &l, ei, &ln);
2659 VariantClear(&l);
2660 if(SUCCEEDED(hres))
2661 hres = to_number(ctx->parser->script, &r, ei, &rn);
2662 VariantClear(&r);
2663 if(FAILED(hres))
2664 return hres;
2666 if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
2667 *ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
2668 }else {
2669 DOUBLE ld = num_val(&ln);
2670 DOUBLE rd = num_val(&rn);
2672 *ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
2675 return S_OK;
2678 /* ECMA-262 3rd Edition 11.8.1 */
2679 HRESULT less_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2681 binary_expression_t *expr = (binary_expression_t*)_expr;
2682 VARIANT rval, lval;
2683 BOOL b;
2684 HRESULT hres;
2686 TRACE("\n");
2688 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2689 if(FAILED(hres))
2690 return hres;
2692 hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
2693 VariantClear(&lval);
2694 VariantClear(&rval);
2695 if(FAILED(hres))
2696 return hres;
2698 return return_bool(ret, b);
2701 /* ECMA-262 3rd Edition 11.8.3 */
2702 HRESULT lesseq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2704 binary_expression_t *expr = (binary_expression_t*)_expr;
2705 VARIANT rval, lval;
2706 BOOL b;
2707 HRESULT hres;
2709 TRACE("\n");
2711 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2712 if(FAILED(hres))
2713 return hres;
2715 hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
2716 VariantClear(&lval);
2717 VariantClear(&rval);
2718 if(FAILED(hres))
2719 return hres;
2721 return return_bool(ret, b);
2724 /* ECMA-262 3rd Edition 11.8.2 */
2725 HRESULT greater_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2727 binary_expression_t *expr = (binary_expression_t*)_expr;
2728 VARIANT rval, lval;
2729 BOOL b;
2730 HRESULT hres;
2732 TRACE("\n");
2734 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2735 if(FAILED(hres))
2736 return hres;
2738 hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
2739 VariantClear(&lval);
2740 VariantClear(&rval);
2741 if(FAILED(hres))
2742 return hres;
2744 return return_bool(ret, b);
2747 /* ECMA-262 3rd Edition 11.8.4 */
2748 HRESULT greatereq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2750 binary_expression_t *expr = (binary_expression_t*)_expr;
2751 VARIANT rval, lval;
2752 BOOL b;
2753 HRESULT hres;
2755 TRACE("\n");
2757 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2758 if(FAILED(hres))
2759 return hres;
2761 hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
2762 VariantClear(&lval);
2763 VariantClear(&rval);
2764 if(FAILED(hres))
2765 return hres;
2767 return return_bool(ret, b);
2770 /* ECMA-262 3rd Edition 11.4.8 */
2771 HRESULT binary_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2773 unary_expression_t *expr = (unary_expression_t*)_expr;
2774 exprval_t exprval;
2775 VARIANT val;
2776 INT i;
2777 HRESULT hres;
2779 TRACE("\n");
2781 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2782 if(FAILED(hres))
2783 return hres;
2785 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2786 exprval_release(&exprval);
2787 if(FAILED(hres))
2788 return hres;
2790 hres = to_int32(ctx->parser->script, &val, ei, &i);
2791 if(FAILED(hres))
2792 return hres;
2794 ret->type = EXPRVAL_VARIANT;
2795 V_VT(&ret->u.var) = VT_I4;
2796 V_I4(&ret->u.var) = ~i;
2797 return S_OK;
2800 /* ECMA-262 3rd Edition 11.4.9 */
2801 HRESULT logical_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2803 unary_expression_t *expr = (unary_expression_t*)_expr;
2804 exprval_t exprval;
2805 VARIANT_BOOL b;
2806 HRESULT hres;
2808 TRACE("\n");
2810 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2811 if(FAILED(hres))
2812 return hres;
2814 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
2815 exprval_release(&exprval);
2816 if(FAILED(hres))
2817 return hres;
2819 return return_bool(ret, !b);
2822 /* ECMA-262 3rd Edition 11.7.1 */
2823 static HRESULT lshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2825 DWORD ri;
2826 INT li;
2827 HRESULT hres;
2829 hres = to_int32(ctx->parser->script, lval, ei, &li);
2830 if(FAILED(hres))
2831 return hres;
2833 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2834 if(FAILED(hres))
2835 return hres;
2837 V_VT(retv) = VT_I4;
2838 V_I4(retv) = li << (ri&0x1f);
2839 return S_OK;
2842 /* ECMA-262 3rd Edition 11.7.1 */
2843 HRESULT left_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2845 binary_expression_t *expr = (binary_expression_t*)_expr;
2847 TRACE("\n");
2849 return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
2852 /* ECMA-262 3rd Edition 11.7.2 */
2853 static HRESULT rshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2855 DWORD ri;
2856 INT li;
2857 HRESULT hres;
2859 hres = to_int32(ctx->parser->script, lval, ei, &li);
2860 if(FAILED(hres))
2861 return hres;
2863 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2864 if(FAILED(hres))
2865 return hres;
2867 V_VT(retv) = VT_I4;
2868 V_I4(retv) = li >> (ri&0x1f);
2869 return S_OK;
2872 /* ECMA-262 3rd Edition 11.7.2 */
2873 HRESULT right_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2875 binary_expression_t *expr = (binary_expression_t*)_expr;
2877 TRACE("\n");
2879 return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
2882 /* ECMA-262 3rd Edition 11.7.3 */
2883 static HRESULT rshift2_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2885 DWORD li, ri;
2886 HRESULT hres;
2888 hres = to_uint32(ctx->parser->script, lval, ei, &li);
2889 if(FAILED(hres))
2890 return hres;
2892 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2893 if(FAILED(hres))
2894 return hres;
2896 V_VT(retv) = VT_I4;
2897 V_I4(retv) = li >> (ri&0x1f);
2898 return S_OK;
2901 /* ECMA-262 3rd Edition 11.7.3 */
2902 HRESULT right2_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2904 binary_expression_t *expr = (binary_expression_t*)_expr;
2906 TRACE("\n");
2908 return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
2911 /* ECMA-262 3rd Edition 11.13.1 */
2912 HRESULT assign_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2914 binary_expression_t *expr = (binary_expression_t*)_expr;
2915 exprval_t exprval, exprvalr;
2916 VARIANT rval;
2917 HRESULT hres;
2919 TRACE("\n");
2921 hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
2922 if(FAILED(hres))
2923 return hres;
2925 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
2926 if(SUCCEEDED(hres)) {
2927 hres = exprval_to_value(ctx->parser->script, &exprvalr, ei, &rval);
2928 exprval_release(&exprvalr);
2931 if(SUCCEEDED(hres))
2932 hres = put_value(ctx->parser->script, &exprval, &rval, ei);
2934 exprval_release(&exprval);
2935 if(FAILED(hres))
2936 return hres;
2938 ret->type = EXPRVAL_VARIANT;
2939 ret->u.var = rval;
2940 return S_OK;
2943 /* ECMA-262 3rd Edition 11.13.2 */
2944 HRESULT assign_lshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2946 binary_expression_t *expr = (binary_expression_t*)_expr;
2948 TRACE("\n");
2950 return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
2953 /* ECMA-262 3rd Edition 11.13.2 */
2954 HRESULT assign_rshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2956 binary_expression_t *expr = (binary_expression_t*)_expr;
2958 TRACE("\n");
2960 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift_eval, ei, ret);
2963 /* ECMA-262 3rd Edition 11.13.2 */
2964 HRESULT assign_rrshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2966 binary_expression_t *expr = (binary_expression_t*)_expr;
2968 TRACE("\n");
2970 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift2_eval, ei, ret);
2973 /* ECMA-262 3rd Edition 11.13.2 */
2974 HRESULT assign_add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2976 binary_expression_t *expr = (binary_expression_t*)_expr;
2978 TRACE("\n");
2980 return assign_oper_eval(ctx, expr->expression1, expr->expression2, add_eval, ei, ret);
2983 /* ECMA-262 3rd Edition 11.13.2 */
2984 HRESULT assign_sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2986 binary_expression_t *expr = (binary_expression_t*)_expr;
2988 TRACE("\n");
2990 return assign_oper_eval(ctx, expr->expression1, expr->expression2, sub_eval, ei, ret);
2993 /* ECMA-262 3rd Edition 11.13.2 */
2994 HRESULT assign_mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2996 binary_expression_t *expr = (binary_expression_t*)_expr;
2998 TRACE("\n");
3000 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mul_eval, ei, ret);
3003 /* ECMA-262 3rd Edition 11.13.2 */
3004 HRESULT assign_div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3006 binary_expression_t *expr = (binary_expression_t*)_expr;
3008 TRACE("\n");
3010 return assign_oper_eval(ctx, expr->expression1, expr->expression2, div_eval, ei, ret);
3013 /* ECMA-262 3rd Edition 11.13.2 */
3014 HRESULT assign_mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3016 binary_expression_t *expr = (binary_expression_t*)_expr;
3018 TRACE("\n");
3020 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mod_eval, ei, ret);
3023 /* ECMA-262 3rd Edition 11.13.2 */
3024 HRESULT assign_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3026 binary_expression_t *expr = (binary_expression_t*)_expr;
3028 TRACE("\n");
3030 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitand_eval, ei, ret);
3033 /* ECMA-262 3rd Edition 11.13.2 */
3034 HRESULT assign_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3036 binary_expression_t *expr = (binary_expression_t*)_expr;
3038 TRACE("\n");
3040 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitor_eval, ei, ret);
3043 /* ECMA-262 3rd Edition 11.13.2 */
3044 HRESULT assign_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3046 binary_expression_t *expr = (binary_expression_t*)_expr;
3048 TRACE("\n");
3050 return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);