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
20 #include "wine/port.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)
49 if(V_VT(&val->u.var) != VT_EMPTY)
50 VariantClear(&val->u.var);
54 IDispatch_Release(val->u.idref.disp);
57 if(val->u.nameref.disp)
58 IDispatch_Release(val->u.nameref.disp);
59 SysFreeString(val->u.nameref.name);
62 SysFreeString(val->u.identifier);
66 /* ECMA-262 3rd Edition 8.7.1 */
67 static HRESULT exprval_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
73 return VariantCopy(ret, &val->u.var);
75 if(!val->u.idref.disp) {
76 FIXME("throw ReferenceError\n");
80 return disp_propget(val->u.idref.disp, val->u.idref.id, ctx->lcid, ret, ei, NULL/*FIXME*/);
84 return throw_type_error(ctx, ei, IDS_UNDEFINED, val->u.identifier);
87 ERR("type %d\n", val->type);
91 static HRESULT exprval_to_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
93 if(val->type == EXPRVAL_VARIANT) {
95 V_VT(&val->u.var) = VT_EMPTY;
99 return exprval_value(ctx, val, ei, ret);
102 static HRESULT exprval_to_boolean(script_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, VARIANT_BOOL *b)
104 if(exprval->type != EXPRVAL_VARIANT) {
108 hres = exprval_to_value(ctx, exprval, ei, &val);
112 hres = to_boolean(&val, b);
117 return to_boolean(&exprval->u.var, b);
120 static void exprval_init(exprval_t *val)
122 val->type = EXPRVAL_VARIANT;
123 V_VT(&val->u.var) = VT_EMPTY;
126 static void exprval_set_idref(exprval_t *val, IDispatch *disp, DISPID id)
128 val->type = EXPRVAL_IDREF;
129 val->u.idref.disp = disp;
130 val->u.idref.id = id;
133 IDispatch_AddRef(disp);
136 HRESULT scope_push(scope_chain_t *scope, DispatchEx *obj, scope_chain_t **ret)
138 scope_chain_t *new_scope;
140 new_scope = heap_alloc(sizeof(scope_chain_t));
142 return E_OUTOFMEMORY;
146 IDispatchEx_AddRef(_IDispatchEx_(obj));
147 new_scope->obj = obj;
151 new_scope->next = scope;
153 new_scope->next = NULL;
160 static void scope_pop(scope_chain_t **scope)
169 void scope_release(scope_chain_t *scope)
175 scope_release(scope->next);
177 jsdisp_release(scope->obj);
181 HRESULT create_exec_ctx(IDispatch *this_obj, DispatchEx *var_disp, scope_chain_t *scope, exec_ctx_t **ret)
185 ctx = heap_alloc_zero(sizeof(exec_ctx_t));
187 return E_OUTOFMEMORY;
191 IDispatch_AddRef(this_obj);
192 ctx->this_obj = this_obj;
194 IDispatchEx_AddRef(_IDispatchEx_(var_disp));
195 ctx->var_disp = var_disp;
199 ctx->scope_chain = scope;
206 void exec_release(exec_ctx_t *ctx)
212 scope_release(ctx->scope_chain);
214 jsdisp_release(ctx->var_disp);
216 IDispatch_Release(ctx->this_obj);
220 static HRESULT disp_get_id(IDispatch *disp, BSTR name, DWORD flags, DISPID *id)
225 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
227 TRACE("unsing IDispatch\n");
230 return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
234 hres = IDispatchEx_GetDispID(dispex, name, flags|fdexNameCaseSensitive, id);
235 IDispatchEx_Release(dispex);
239 /* ECMA-262 3rd Edition 8.7.2 */
240 static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei)
242 if(ref->type != EXPRVAL_IDREF)
243 return throw_reference_error(ctx, ei, IDS_ILLEGAL_ASSIGN, NULL);
245 return disp_propput(ref->u.idref.disp, ref->u.idref.id, ctx->lcid, v, ei, NULL/*FIXME*/);
248 static inline BOOL is_null(const VARIANT *v)
250 return V_VT(v) == VT_NULL || (V_VT(v) == VT_DISPATCH && !V_DISPATCH(v));
253 static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, BOOL *ret)
255 IObjectIdentity *identity;
256 IUnknown *unk1, *unk2;
264 if(!disp1 || !disp2) {
269 hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
273 hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
275 IUnknown_Release(unk1);
282 hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
283 if(SUCCEEDED(hres)) {
284 hres = IObjectIdentity_IsEqualObject(identity, unk2);
285 IObjectIdentity_Release(identity);
292 IUnknown_Release(unk1);
293 IUnknown_Release(unk2);
297 /* ECMA-262 3rd Edition 11.9.6 */
298 static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
302 if(V_VT(lval) != V_VT(rval)) {
303 if(is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval)))
304 *ret = num_val(lval) == num_val(rval);
305 else if(is_null(lval))
306 *ret = is_null(rval);
318 *ret = V_I4(lval) == V_I4(rval);
321 *ret = V_R8(lval) == V_R8(rval);
325 *ret = SysStringLen(V_BSTR(rval))?FALSE:TRUE;
326 else if(!V_BSTR(rval))
327 *ret = SysStringLen(V_BSTR(lval))?FALSE:TRUE;
329 *ret = !strcmpW(V_BSTR(lval), V_BSTR(rval));
332 return disp_cmp(V_DISPATCH(lval), V_DISPATCH(rval), ret);
334 *ret = !V_BOOL(lval) == !V_BOOL(rval);
337 FIXME("unimplemented vt %d\n", V_VT(lval));
344 static HRESULT literal_to_var(literal_t *literal, VARIANT *v)
346 V_VT(v) = literal->vt;
353 V_I4(v) = literal->u.lval;
356 V_R8(v) = literal->u.dval;
359 V_BSTR(v) = SysAllocString(literal->u.wstr);
362 V_BOOL(v) = literal->u.bval;
365 IDispatch_AddRef(literal->u.disp);
366 V_DISPATCH(v) = literal->u.disp;
369 ERR("wrong type %d\n", V_VT(v));
376 static BOOL lookup_global_members(script_ctx_t *ctx, BSTR identifier, exprval_t *ret)
382 for(item = ctx->named_items; item; item = item->next) {
383 if(item->flags & SCRIPTITEM_GLOBALMEMBERS) {
384 hres = disp_get_id(item->disp, identifier, 0, &id);
385 if(SUCCEEDED(hres)) {
387 exprval_set_idref(ret, item->disp, id);
396 HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, jsexcept_t *ei, VARIANT *retv)
398 script_ctx_t *script = parser->script;
399 function_declaration_t *func;
400 parser_ctx_t *prev_parser;
404 exec_ctx_t *prev_ctx;
408 for(func = source->functions; func; func = func->next) {
409 DispatchEx *func_obj;
412 hres = create_source_function(parser, func->expr->parameter_list, func->expr->source_elements,
413 ctx->scope_chain, func->expr->src_str, func->expr->src_len, &func_obj);
417 V_VT(&var) = VT_DISPATCH;
418 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(func_obj);
419 hres = jsdisp_propput_name(ctx->var_disp, func->expr->identifier, script->lcid, &var, ei, NULL);
420 jsdisp_release(func_obj);
425 for(var = source->variables; var; var = var->next) {
429 name = SysAllocString(var->identifier);
431 return E_OUTOFMEMORY;
433 if(!lookup_global_members(parser->script, name, NULL))
434 hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
440 prev_ctx = script->exec_ctx;
441 script->exec_ctx = ctx;
443 prev_parser = ctx->parser;
444 ctx->parser = parser;
446 V_VT(&val) = VT_EMPTY;
447 memset(&rt, 0, sizeof(rt));
450 for(stat = source->statement; stat; stat = stat->next) {
451 hres = stat_eval(ctx, stat, &rt, &tmp);
457 if(rt.type != RT_NORMAL)
461 script->exec_ctx = prev_ctx;
462 ctx->parser = prev_parser;
464 if(rt.type != RT_NORMAL && rt.type != RT_RETURN) {
465 FIXME("wrong rt %d\n", rt.type);
482 /* ECMA-262 3rd Edition 10.1.4 */
483 static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, jsexcept_t *ei, exprval_t *ret)
485 scope_chain_t *scope;
490 TRACE("%s\n", debugstr_w(identifier));
492 for(scope = ctx->scope_chain; scope; scope = scope->next) {
493 hres = jsdisp_get_id(scope->obj, identifier, 0, &id);
499 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(scope->obj), id);
503 hres = jsdisp_get_id(ctx->parser->script->global, identifier, 0, &id);
504 if(SUCCEEDED(hres)) {
505 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->global), id);
509 for(item = ctx->parser->script->named_items; item; item = item->next) {
510 if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpW(item->name, identifier)) {
514 if(!ctx->parser->script->site)
517 hres = IActiveScriptSite_GetItemInfo(ctx->parser->script->site, identifier,
518 SCRIPTINFO_IUNKNOWN, &unk, NULL);
520 WARN("GetItemInfo failed: %08x\n", hres);
524 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
525 IUnknown_Release(unk);
527 WARN("object does not implement IDispatch\n");
532 ret->type = EXPRVAL_VARIANT;
533 V_VT(&ret->u.var) = VT_DISPATCH;
534 V_DISPATCH(&ret->u.var) = item->disp;
535 IDispatch_AddRef(item->disp);
540 hres = jsdisp_get_id(ctx->parser->script->script_disp, identifier, 0, &id);
541 if(SUCCEEDED(hres)) {
542 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->script_disp), id);
546 if(lookup_global_members(ctx->parser->script, identifier, ret))
549 if(flags & EXPR_NEWREF) {
550 hres = jsdisp_get_id(ctx->parser->script->script_disp, identifier, fdexNameEnsure, &id);
554 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->script_disp), id);
558 ret->type = EXPRVAL_INVALID;
559 ret->u.identifier = SysAllocString(identifier);
560 if(!ret->u.identifier)
561 return E_OUTOFMEMORY;
566 /* ECMA-262 3rd Edition 12.1 */
567 HRESULT block_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
569 block_statement_t *stat = (block_statement_t*)_stat;
576 V_VT(&val) = VT_EMPTY;
577 for(iter = stat->stat_list; iter; iter = iter->next) {
578 hres = stat_eval(ctx, iter, rt, &tmp);
584 if(rt->type != RT_NORMAL)
597 /* ECMA-262 3rd Edition 12.2 */
598 static HRESULT variable_list_eval(exec_ctx_t *ctx, variable_declaration_t *var_list, jsexcept_t *ei)
600 variable_declaration_t *iter;
603 for(iter = var_list; iter; iter = iter->next) {
610 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
614 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
615 exprval_release(&exprval);
619 hres = jsdisp_propput_name(ctx->var_disp, iter->identifier, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
628 /* ECMA-262 3rd Edition 12.2 */
629 HRESULT var_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
631 var_statement_t *stat = (var_statement_t*)_stat;
636 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
640 V_VT(ret) = VT_EMPTY;
644 /* ECMA-262 3rd Edition 12.3 */
645 HRESULT empty_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
649 V_VT(ret) = VT_EMPTY;
653 /* ECMA-262 3rd Edition 12.4 */
654 HRESULT expression_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
656 expression_statement_t *stat = (expression_statement_t*)_stat;
663 hres = expr_eval(ctx, stat->expr, EXPR_NOVAL, &rt->ei, &exprval);
667 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
668 exprval_release(&exprval);
673 TRACE("= %s\n", debugstr_variant(ret));
677 /* ECMA-262 3rd Edition 12.5 */
678 HRESULT if_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
680 if_statement_t *stat = (if_statement_t*)_stat;
687 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
691 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
692 exprval_release(&exprval);
697 hres = stat_eval(ctx, stat->if_stat, rt, ret);
698 else if(stat->else_stat)
699 hres = stat_eval(ctx, stat->else_stat, rt, ret);
701 V_VT(ret) = VT_EMPTY;
706 /* ECMA-262 3rd Edition 12.6.2 */
707 HRESULT while_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
709 while_statement_t *stat = (while_statement_t*)_stat;
718 V_VT(&val) = VT_EMPTY;
719 test_expr = !stat->do_while;
723 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
727 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
728 exprval_release(&exprval);
729 if(FAILED(hres) || !b)
735 hres = stat_eval(ctx, stat->statement, rt, &tmp);
742 if(rt->type == RT_CONTINUE)
743 rt->type = RT_NORMAL;
744 if(rt->type != RT_NORMAL)
753 if(rt->type == RT_BREAK)
754 rt->type = RT_NORMAL;
760 /* ECMA-262 3rd Edition 12.6.3 */
761 HRESULT for_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
763 for_statement_t *stat = (for_statement_t*)_stat;
764 VARIANT val, tmp, retv;
771 if(stat->variable_list) {
772 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
775 }else if(stat->begin_expr) {
776 hres = expr_eval(ctx, stat->begin_expr, EXPR_NEWREF, &rt->ei, &exprval);
780 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
781 exprval_release(&exprval);
788 V_VT(&retv) = VT_EMPTY;
792 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
796 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
797 exprval_release(&exprval);
798 if(FAILED(hres) || !b)
802 hres = stat_eval(ctx, stat->statement, rt, &tmp);
809 if(rt->type == RT_CONTINUE)
810 rt->type = RT_NORMAL;
811 else if(rt->type != RT_NORMAL)
815 hres = expr_eval(ctx, stat->end_expr, 0, &rt->ei, &exprval);
819 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
820 exprval_release(&exprval);
833 if(rt->type == RT_BREAK)
834 rt->type = RT_NORMAL;
840 /* ECMA-262 3rd Edition 12.6.4 */
841 HRESULT forin_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
843 forin_statement_t *stat = (forin_statement_t*)_stat;
844 VARIANT val, name, retv, tmp;
845 DISPID id = DISPID_STARTENUM;
846 BSTR str, identifier = NULL;
854 hres = variable_list_eval(ctx, stat->variable, &rt->ei);
859 hres = expr_eval(ctx, stat->in_expr, EXPR_NEWREF, &rt->ei, &exprval);
863 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
864 exprval_release(&exprval);
868 if(V_VT(&val) != VT_DISPATCH) {
869 TRACE("in vt %d\n", V_VT(&val));
871 V_VT(ret) = VT_EMPTY;
875 hres = IDispatch_QueryInterface(V_DISPATCH(&val), &IID_IDispatchEx, (void**)&in_obj);
876 IDispatch_Release(V_DISPATCH(&val));
878 FIXME("Object doesn't support IDispatchEx\n");
882 V_VT(&retv) = VT_EMPTY;
885 identifier = SysAllocString(stat->variable->identifier);
888 hres = IDispatchEx_GetNextDispID(in_obj, fdexEnumDefault, id, &id);
889 if(FAILED(hres) || hres == S_FALSE)
892 hres = IDispatchEx_GetMemberName(in_obj, id, &str);
896 TRACE("iter %s\n", debugstr_w(str));
899 hres = identifier_eval(ctx, identifier, 0, NULL, &exprval);
901 hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval);
902 if(SUCCEEDED(hres)) {
903 V_VT(&name) = VT_BSTR;
905 hres = put_value(ctx->parser->script, &exprval, &name, &rt->ei);
906 exprval_release(&exprval);
912 hres = stat_eval(ctx, stat->statement, rt, &tmp);
919 if(rt->type == RT_CONTINUE)
920 rt->type = RT_NORMAL;
921 else if(rt->type != RT_NORMAL)
925 SysFreeString(identifier);
926 IDispatchEx_Release(in_obj);
932 if(rt->type == RT_BREAK)
933 rt->type = RT_NORMAL;
939 /* ECMA-262 3rd Edition 12.7 */
940 HRESULT continue_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
942 branch_statement_t *stat = (branch_statement_t*)_stat;
946 if(stat->identifier) {
947 FIXME("indentifier not implemented\n");
951 rt->type = RT_CONTINUE;
952 V_VT(ret) = VT_EMPTY;
956 /* ECMA-262 3rd Edition 12.8 */
957 HRESULT break_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
959 branch_statement_t *stat = (branch_statement_t*)_stat;
963 if(stat->identifier) {
964 FIXME("indentifier not implemented\n");
969 V_VT(ret) = VT_EMPTY;
973 /* ECMA-262 3rd Edition 12.9 */
974 HRESULT return_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
976 expression_statement_t *stat = (expression_statement_t*)_stat;
984 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
988 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, ret);
989 exprval_release(&exprval);
993 V_VT(ret) = VT_EMPTY;
996 TRACE("= %s\n", debugstr_variant(ret));
997 rt->type = RT_RETURN;
1001 /* ECMA-262 3rd Edition 12.10 */
1002 HRESULT with_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1004 with_statement_t *stat = (with_statement_t*)_stat;
1013 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1017 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1018 exprval_release(&exprval);
1022 hres = to_object(ctx->parser->script, &val, &disp);
1027 obj = iface_to_jsdisp((IUnknown*)disp);
1028 IDispatch_Release(disp);
1030 FIXME("disp id not jsdisp\n");
1034 hres = scope_push(ctx->scope_chain, obj, &ctx->scope_chain);
1035 jsdisp_release(obj);
1039 hres = stat_eval(ctx, stat->statement, rt, ret);
1041 scope_pop(&ctx->scope_chain);
1045 /* ECMA-262 3rd Edition 12.12 */
1046 HRESULT labelled_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
1052 /* ECMA-262 3rd Edition 12.13 */
1053 HRESULT switch_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1055 switch_statement_t *stat = (switch_statement_t*)_stat;
1056 case_clausule_t *iter, *default_clausule = NULL;
1057 statement_t *stat_iter;
1065 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1069 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1070 exprval_release(&exprval);
1074 for(iter = stat->case_list; iter; iter = iter->next) {
1076 default_clausule = iter;
1080 hres = expr_eval(ctx, iter->expr, 0, &rt->ei, &exprval);
1084 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &cval);
1085 exprval_release(&exprval);
1089 hres = equal2_values(&val, &cval, &b);
1090 VariantClear(&cval);
1091 if(FAILED(hres) || b)
1100 iter = default_clausule;
1102 V_VT(&val) = VT_EMPTY;
1106 for(stat_iter = iter->stat; stat_iter; stat_iter = stat_iter->next) {
1107 hres = stat_eval(ctx, stat_iter, rt, &tmp);
1114 if(rt->type != RT_NORMAL)
1124 if(rt->type == RT_BREAK)
1125 rt->type = RT_NORMAL;
1131 /* ECMA-262 3rd Edition 12.13 */
1132 HRESULT throw_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1134 expression_statement_t *stat = (expression_statement_t*)_stat;
1141 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1145 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1146 exprval_release(&exprval);
1151 return DISP_E_EXCEPTION;
1154 /* ECMA-262 3rd Edition 12.14 */
1155 static HRESULT catch_eval(exec_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
1157 DispatchEx *var_disp;
1162 memset(&rt->ei, 0, sizeof(jsexcept_t));
1164 hres = create_dispex(ctx->parser->script, NULL, NULL, &var_disp);
1165 if(SUCCEEDED(hres)) {
1166 hres = jsdisp_propput_name(var_disp, block->identifier, ctx->parser->script->lcid,
1167 &ex, &rt->ei, NULL/*FIXME*/);
1168 if(SUCCEEDED(hres)) {
1169 hres = scope_push(ctx->scope_chain, var_disp, &ctx->scope_chain);
1170 if(SUCCEEDED(hres)) {
1171 hres = stat_eval(ctx, block->statement, rt, &val);
1172 scope_pop(&ctx->scope_chain);
1176 jsdisp_release(var_disp);
1187 /* ECMA-262 3rd Edition 12.14 */
1188 HRESULT try_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1190 try_statement_t *stat = (try_statement_t*)_stat;
1196 hres = stat_eval(ctx, stat->try_statement, rt, &val);
1198 TRACE("EXCEPTION\n");
1199 if(!stat->catch_block)
1202 hres = catch_eval(ctx, stat->catch_block, rt, &val);
1207 if(stat->finally_statement) {
1209 hres = stat_eval(ctx, stat->finally_statement, rt, &val);
1218 static HRESULT return_bool(exprval_t *ret, DWORD b)
1220 ret->type = EXPRVAL_VARIANT;
1221 V_VT(&ret->u.var) = VT_BOOL;
1222 V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;
1227 static HRESULT get_binary_expr_values(exec_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
1232 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1236 hres = exprval_to_value(ctx->parser->script, &exprval, ei, lval);
1237 exprval_release(&exprval);
1241 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1242 if(SUCCEEDED(hres)) {
1243 hres = exprval_to_value(ctx->parser->script, &exprval, ei, rval);
1244 exprval_release(&exprval);
1255 typedef HRESULT (*oper_t)(exec_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);
1257 static HRESULT binary_expr_eval(exec_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
1260 VARIANT lval, rval, retv;
1263 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1267 hres = oper(ctx, &lval, &rval, ei, &retv);
1268 VariantClear(&lval);
1269 VariantClear(&rval);
1273 ret->type = EXPRVAL_VARIANT;
1278 /* ECMA-262 3rd Edition 11.13.2 */
1279 static HRESULT assign_oper_eval(exec_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
1280 jsexcept_t *ei, exprval_t *ret)
1282 VARIANT retv, lval, rval;
1283 exprval_t exprval, exprvalr;
1286 hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
1290 hres = exprval_value(ctx->parser->script, &exprval, ei, &lval);
1291 if(SUCCEEDED(hres)) {
1292 hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
1293 if(SUCCEEDED(hres)) {
1294 hres = exprval_value(ctx->parser->script, &exprvalr, ei, &rval);
1295 exprval_release(&exprvalr);
1297 if(SUCCEEDED(hres)) {
1298 hres = oper(ctx, &lval, &rval, ei, &retv);
1299 VariantClear(&rval);
1301 VariantClear(&lval);
1304 if(SUCCEEDED(hres)) {
1305 hres = put_value(ctx->parser->script, &exprval, &retv, ei);
1307 VariantClear(&retv);
1309 exprval_release(&exprval);
1314 ret->type = EXPRVAL_VARIANT;
1319 /* ECMA-262 3rd Edition 13 */
1320 HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1322 function_expression_t *expr = (function_expression_t*)_expr;
1328 if(expr->identifier) {
1329 hres = jsdisp_propget_name(ctx->var_disp, expr->identifier, ctx->parser->script->lcid, &var, ei, NULL/*FIXME*/);
1335 hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain,
1336 expr->src_str, expr->src_len, &dispex);
1340 V_VT(&var) = VT_DISPATCH;
1341 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
1344 ret->type = EXPRVAL_VARIANT;
1349 /* ECMA-262 3rd Edition 11.12 */
1350 HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1352 conditional_expression_t *expr = (conditional_expression_t*)_expr;
1359 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1363 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
1364 exprval_release(&exprval);
1368 return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
1371 /* ECMA-262 3rd Edition 11.2.1 */
1372 HRESULT array_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1374 array_expression_t *expr = (array_expression_t*)_expr;
1376 VARIANT member, val;
1379 IDispatch *obj = NULL;
1384 hres = expr_eval(ctx, expr->member_expr, EXPR_NEWREF, ei, &exprval);
1388 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1389 exprval_release(&exprval);
1393 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
1394 if(SUCCEEDED(hres)) {
1395 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1396 exprval_release(&exprval);
1400 hres = to_object(ctx->parser->script, &member, &obj);
1401 VariantClear(&member);
1402 if(SUCCEEDED(hres)) {
1403 hres = to_string(ctx->parser->script, &val, ei, &str);
1404 if(SUCCEEDED(hres)) {
1405 if(flags & EXPR_STRREF) {
1406 ret->type = EXPRVAL_NAMEREF;
1407 ret->u.nameref.disp = obj;
1408 ret->u.nameref.name = str;
1412 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1415 if(SUCCEEDED(hres)) {
1416 exprval_set_idref(ret, obj, id);
1417 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1422 IDispatch_Release(obj);
1428 /* ECMA-262 3rd Edition 11.2.1 */
1429 HRESULT member_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1431 member_expression_t *expr = (member_expression_t*)_expr;
1432 IDispatch *obj = NULL;
1441 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1445 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1446 exprval_release(&exprval);
1450 hres = to_object(ctx->parser->script, &member, &obj);
1451 VariantClear(&member);
1455 str = SysAllocString(expr->identifier);
1456 if(flags & EXPR_STRREF) {
1457 ret->type = EXPRVAL_NAMEREF;
1458 ret->u.nameref.disp = obj;
1459 ret->u.nameref.name = str;
1463 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1465 if(SUCCEEDED(hres)) {
1466 exprval_set_idref(ret, obj, id);
1467 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1472 IDispatch_Release(obj);
1476 static void free_dp(DISPPARAMS *dp)
1480 for(i=0; i < dp->cArgs; i++)
1481 VariantClear(dp->rgvarg+i);
1482 heap_free(dp->rgvarg);
1485 static HRESULT args_to_param(exec_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
1491 HRESULT hres = S_OK;
1493 memset(dp, 0, sizeof(*dp));
1497 for(iter = args; iter; iter = iter->next)
1500 vargs = heap_alloc_zero(cnt * sizeof(*vargs));
1502 return E_OUTOFMEMORY;
1504 for(i = cnt, iter = args; iter; iter = iter->next) {
1505 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
1509 hres = exprval_to_value(ctx->parser->script, &exprval, ei, vargs + (--i));
1510 exprval_release(&exprval);
1525 /* ECMA-262 3rd Edition 11.2.2 */
1526 HRESULT new_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1528 call_expression_t *expr = (call_expression_t*)_expr;
1530 VARIANT constr, var;
1536 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1540 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1542 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &constr);
1543 exprval_release(&exprval);
1547 if(V_VT(&constr) != VT_DISPATCH) {
1548 FIXME("throw TypeError\n");
1549 VariantClear(&constr);
1553 hres = disp_call(ctx->parser->script, V_DISPATCH(&constr), DISPID_VALUE,
1554 DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
1555 IDispatch_Release(V_DISPATCH(&constr));
1559 ret->type = EXPRVAL_VARIANT;
1564 /* ECMA-262 3rd Edition 11.2.3 */
1565 HRESULT call_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1567 call_expression_t *expr = (call_expression_t*)_expr;
1575 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1579 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1580 if(SUCCEEDED(hres)) {
1581 switch(exprval.type) {
1582 case EXPRVAL_VARIANT:
1583 if(V_VT(&exprval.u.var) == VT_DISPATCH)
1584 hres = disp_call(ctx->parser->script, V_DISPATCH(&exprval.u.var), DISPID_VALUE,
1585 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1587 hres = throw_type_error(ctx->var_disp->ctx, ei, IDS_NO_PROPERTY, NULL);
1590 hres = disp_call(ctx->parser->script, exprval.u.idref.disp, exprval.u.idref.id,
1591 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1593 case EXPRVAL_INVALID:
1594 hres = throw_type_error(ctx->var_disp->ctx, ei, IDS_OBJECT_EXPECTED, NULL);
1597 FIXME("unimplemented type %d\n", exprval.type);
1604 exprval_release(&exprval);
1608 ret->type = EXPRVAL_VARIANT;
1609 if(flags & EXPR_NOVAL) {
1610 V_VT(&ret->u.var) = VT_EMPTY;
1612 TRACE("= %s\n", debugstr_variant(&var));
1618 /* ECMA-262 3rd Edition 11.1.1 */
1619 HRESULT this_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1623 ret->type = EXPRVAL_VARIANT;
1624 V_VT(&ret->u.var) = VT_DISPATCH;
1625 V_DISPATCH(&ret->u.var) = ctx->this_obj;
1626 IDispatch_AddRef(ctx->this_obj);
1630 /* ECMA-262 3rd Edition 10.1.4 */
1631 HRESULT identifier_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1633 identifier_expression_t *expr = (identifier_expression_t*)_expr;
1639 identifier = SysAllocString(expr->identifier);
1641 return E_OUTOFMEMORY;
1643 hres = identifier_eval(ctx, identifier, flags, ei, ret);
1645 SysFreeString(identifier);
1649 /* ECMA-262 3rd Edition 7.8 */
1650 HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1652 literal_expression_t *expr = (literal_expression_t*)_expr;
1658 hres = literal_to_var(expr->literal, &var);
1662 ret->type = EXPRVAL_VARIANT;
1667 /* ECMA-262 3rd Edition 11.1.4 */
1668 HRESULT array_literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1670 array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
1671 DWORD length = 0, i = 0;
1672 array_element_t *elem;
1680 for(elem = expr->element_list; elem; elem = elem->next)
1681 length += elem->elision+1;
1682 length += expr->length;
1684 hres = create_array(ctx->parser->script, length, &array);
1688 for(elem = expr->element_list; elem; elem = elem->next) {
1691 hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
1695 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1696 exprval_release(&exprval);
1700 hres = jsdisp_propput_idx(array, i, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1709 jsdisp_release(array);
1713 ret->type = EXPRVAL_VARIANT;
1714 V_VT(&ret->u.var) = VT_DISPATCH;
1715 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(array);
1719 /* ECMA-262 3rd Edition 11.1.5 */
1720 HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1722 property_value_expression_t *expr = (property_value_expression_t*)_expr;
1732 hres = create_object(ctx->parser->script, NULL, &obj);
1736 for(iter = expr->property_list; iter; iter = iter->next) {
1737 hres = literal_to_var(iter->name, &tmp);
1741 hres = to_string(ctx->parser->script, &tmp, ei, &name);
1746 hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
1747 if(SUCCEEDED(hres)) {
1748 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1749 exprval_release(&exprval);
1750 if(SUCCEEDED(hres)) {
1751 hres = jsdisp_propput_name(obj, name, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1756 SysFreeString(name);
1762 jsdisp_release(obj);
1766 ret->type = EXPRVAL_VARIANT;
1767 V_VT(&ret->u.var) = VT_DISPATCH;
1768 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(obj);
1772 /* ECMA-262 3rd Edition 11.14 */
1773 HRESULT comma_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1775 binary_expression_t *expr = (binary_expression_t*)_expr;
1781 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1785 VariantClear(&lval);
1787 ret->type = EXPRVAL_VARIANT;
1792 /* ECMA-262 3rd Edition 11.11 */
1793 HRESULT logical_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1795 binary_expression_t *expr = (binary_expression_t*)_expr;
1803 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1807 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1808 exprval_release(&exprval);
1812 hres = to_boolean(&val, &b);
1813 if(SUCCEEDED(hres) && b) {
1814 ret->type = EXPRVAL_VARIANT;
1823 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1827 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1828 exprval_release(&exprval);
1832 ret->type = EXPRVAL_VARIANT;
1837 /* ECMA-262 3rd Edition 11.11 */
1838 HRESULT logical_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1840 binary_expression_t *expr = (binary_expression_t*)_expr;
1848 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1852 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1853 exprval_release(&exprval);
1857 hres = to_boolean(&val, &b);
1858 if(SUCCEEDED(hres) && !b) {
1859 ret->type = EXPRVAL_VARIANT;
1868 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1872 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1873 exprval_release(&exprval);
1877 ret->type = EXPRVAL_VARIANT;
1882 /* ECMA-262 3rd Edition 11.10 */
1883 static HRESULT bitor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1888 hres = to_int32(ctx->parser->script, lval, ei, &li);
1892 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1901 /* ECMA-262 3rd Edition 11.10 */
1902 HRESULT binary_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1904 binary_expression_t *expr = (binary_expression_t*)_expr;
1908 return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
1911 /* ECMA-262 3rd Edition 11.10 */
1912 static HRESULT xor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1917 hres = to_int32(ctx->parser->script, lval, ei, &li);
1921 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1930 /* ECMA-262 3rd Edition 11.10 */
1931 HRESULT binary_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1933 binary_expression_t *expr = (binary_expression_t*)_expr;
1937 return binary_expr_eval(ctx, expr, xor_eval, ei, ret);
1940 /* ECMA-262 3rd Edition 11.10 */
1941 static HRESULT bitand_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1946 hres = to_int32(ctx->parser->script, lval, ei, &li);
1950 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1959 /* ECMA-262 3rd Edition 11.10 */
1960 HRESULT binary_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1962 binary_expression_t *expr = (binary_expression_t*)_expr;
1966 return binary_expr_eval(ctx, expr, bitand_eval, ei, ret);
1969 /* ECMA-262 3rd Edition 11.8.6 */
1970 static HRESULT instanceof_eval(exec_ctx_t *ctx, VARIANT *inst, VARIANT *objv, jsexcept_t *ei, VARIANT *retv)
1972 DispatchEx *obj, *iter, *tmp = NULL;
1973 VARIANT_BOOL ret = VARIANT_FALSE;
1978 static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
1980 if(V_VT(objv) != VT_DISPATCH) {
1981 FIXME("throw TypeError\n");
1985 obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(objv));
1987 FIXME("throw TypeError\n");
1991 if(is_class(obj, JSCLASS_FUNCTION)) {
1992 hres = jsdisp_propget_name(obj, prototypeW, ctx->parser->script->lcid, &var, ei, NULL/*FIXME*/);
1994 FIXME("throw TypeError\n");
1997 jsdisp_release(obj);
2001 if(V_VT(&var) == VT_DISPATCH) {
2002 if(V_VT(inst) == VT_DISPATCH)
2003 tmp = iface_to_jsdisp((IUnknown*)V_DISPATCH(inst));
2004 for(iter = tmp; iter; iter = iter->prototype) {
2005 hres = disp_cmp(V_DISPATCH(&var), (IDispatch*)_IDispatchEx_(iter), &b);
2015 jsdisp_release(tmp);
2017 FIXME("prototype is not an object\n");
2025 V_VT(retv) = VT_BOOL;
2030 /* ECMA-262 3rd Edition 11.8.6 */
2031 HRESULT instanceof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2033 binary_expression_t *expr = (binary_expression_t*)_expr;
2037 return binary_expr_eval(ctx, expr, instanceof_eval, ei, ret);
2040 /* ECMA-262 3rd Edition 11.8.7 */
2041 static HRESULT in_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *obj, jsexcept_t *ei, VARIANT *retv)
2048 if(V_VT(obj) != VT_DISPATCH) {
2049 FIXME("throw TypeError\n");
2053 hres = to_string(ctx->parser->script, lval, ei, &str);
2057 hres = disp_get_id(V_DISPATCH(obj), str, 0, &id);
2061 else if(hres == DISP_E_UNKNOWNNAME)
2062 ret = VARIANT_FALSE;
2066 V_VT(retv) = VT_BOOL;
2071 /* ECMA-262 3rd Edition 11.8.7 */
2072 HRESULT in_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2074 binary_expression_t *expr = (binary_expression_t*)_expr;
2078 return binary_expr_eval(ctx, expr, in_eval, ei, ret);
2081 /* ECMA-262 3rd Edition 11.6.1 */
2082 static HRESULT add_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2087 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
2091 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
2097 if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
2098 BSTR lstr = NULL, rstr = NULL;
2100 if(V_VT(&l) == VT_BSTR)
2103 hres = to_string(ctx->parser->script, &l, ei, &lstr);
2105 if(SUCCEEDED(hres)) {
2106 if(V_VT(&r) == VT_BSTR)
2109 hres = to_string(ctx->parser->script, &r, ei, &rstr);
2112 if(SUCCEEDED(hres)) {
2115 len1 = SysStringLen(lstr);
2116 len2 = SysStringLen(rstr);
2118 V_VT(retv) = VT_BSTR;
2119 V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
2120 memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
2121 memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
2124 if(V_VT(&l) != VT_BSTR)
2125 SysFreeString(lstr);
2126 if(V_VT(&r) != VT_BSTR)
2127 SysFreeString(rstr);
2131 hres = to_number(ctx->parser->script, &l, ei, &nl);
2132 if(SUCCEEDED(hres)) {
2133 hres = to_number(ctx->parser->script, &r, ei, &nr);
2135 num_set_val(retv, num_val(&nl) + num_val(&nr));
2144 /* ECMA-262 3rd Edition 11.6.1 */
2145 HRESULT add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2147 binary_expression_t *expr = (binary_expression_t*)_expr;
2151 return binary_expr_eval(ctx, expr, add_eval, ei, ret);
2154 /* ECMA-262 3rd Edition 11.6.2 */
2155 static HRESULT sub_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2160 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2164 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2168 num_set_val(retv, num_val(&lnum) - num_val(&rnum));
2172 /* ECMA-262 3rd Edition 11.6.2 */
2173 HRESULT sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2175 binary_expression_t *expr = (binary_expression_t*)_expr;
2179 return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
2182 /* ECMA-262 3rd Edition 11.5.1 */
2183 static HRESULT mul_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2188 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2192 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2196 num_set_val(retv, num_val(&lnum) * num_val(&rnum));
2200 /* ECMA-262 3rd Edition 11.5.1 */
2201 HRESULT mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2203 binary_expression_t *expr = (binary_expression_t*)_expr;
2207 return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
2210 /* ECMA-262 3rd Edition 11.5.2 */
2211 static HRESULT div_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2216 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2220 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2224 num_set_val(retv, num_val(&lnum) / num_val(&rnum));
2228 /* ECMA-262 3rd Edition 11.5.2 */
2229 HRESULT div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2231 binary_expression_t *expr = (binary_expression_t*)_expr;
2235 return binary_expr_eval(ctx, expr, div_eval, ei, ret);
2238 /* ECMA-262 3rd Edition 11.5.3 */
2239 static HRESULT mod_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2244 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2248 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2252 num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
2256 /* ECMA-262 3rd Edition 11.5.3 */
2257 HRESULT mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2259 binary_expression_t *expr = (binary_expression_t*)_expr;
2263 return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
2266 /* ECMA-262 3rd Edition 11.4.2 */
2267 HRESULT delete_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2269 unary_expression_t *expr = (unary_expression_t*)_expr;
2270 VARIANT_BOOL b = VARIANT_FALSE;
2276 hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
2280 switch(exprval.type) {
2281 case EXPRVAL_IDREF: {
2282 IDispatchEx *dispex;
2284 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2285 if(SUCCEEDED(hres)) {
2286 hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
2288 IDispatchEx_Release(dispex);
2292 case EXPRVAL_NAMEREF: {
2293 IDispatchEx *dispex;
2295 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2296 if(SUCCEEDED(hres)) {
2297 hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name, fdexNameCaseSensitive);
2299 IDispatchEx_Release(dispex);
2304 FIXME("unsupported type %d\n", exprval.type);
2308 exprval_release(&exprval);
2312 return return_bool(ret, b);
2315 /* ECMA-262 3rd Edition 11.4.2 */
2316 HRESULT void_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;
2325 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2329 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &tmp);
2330 exprval_release(&exprval);
2336 ret->type = EXPRVAL_VARIANT;
2337 V_VT(&ret->u.var) = VT_EMPTY;
2341 /* ECMA-262 3rd Edition 11.4.3 */
2342 static HRESULT typeof_exprval(exec_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, const WCHAR **ret)
2347 static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
2348 static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
2349 static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
2350 static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
2351 static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
2352 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
2354 if(exprval->type == EXPRVAL_INVALID) {
2359 hres = exprval_to_value(ctx->parser->script, exprval, ei, &val);
2363 switch(V_VT(&val)) {
2383 if(V_DISPATCH(&val) && (dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val)))) {
2384 *ret = is_class(dispex, JSCLASS_FUNCTION) ? functionW : objectW;
2385 jsdisp_release(dispex);
2392 FIXME("unhandled vt %d\n", V_VT(&val));
2400 HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2402 unary_expression_t *expr = (unary_expression_t*)_expr;
2403 const WCHAR *str = NULL;
2409 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2413 hres = typeof_exprval(ctx, &exprval, ei, &str);
2414 exprval_release(&exprval);
2418 ret->type = EXPRVAL_VARIANT;
2419 V_VT(&ret->u.var) = VT_BSTR;
2420 V_BSTR(&ret->u.var) = SysAllocString(str);
2421 if(!V_BSTR(&ret->u.var))
2422 return E_OUTOFMEMORY;
2427 /* ECMA-262 3rd Edition 11.4.7 */
2428 HRESULT minus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2430 unary_expression_t *expr = (unary_expression_t*)_expr;
2437 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2441 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2442 exprval_release(&exprval);
2446 hres = to_number(ctx->parser->script, &val, ei, &num);
2451 ret->type = EXPRVAL_VARIANT;
2452 num_set_val(&ret->u.var, -num_val(&num));
2456 /* ECMA-262 3rd Edition 11.4.6 */
2457 HRESULT plus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2459 unary_expression_t *expr = (unary_expression_t*)_expr;
2466 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2470 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2471 exprval_release(&exprval);
2475 hres = to_number(ctx->parser->script, &val, ei, &num);
2479 ret->type = EXPRVAL_VARIANT;
2484 /* ECMA-262 3rd Edition 11.3.1 */
2485 HRESULT post_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2487 unary_expression_t *expr = (unary_expression_t*)_expr;
2494 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2498 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2499 if(SUCCEEDED(hres)) {
2500 hres = to_number(ctx->parser->script, &val, ei, &num);
2504 if(SUCCEEDED(hres)) {
2506 num_set_val(&inc, num_val(&num)+1.0);
2507 hres = put_value(ctx->parser->script, &exprval, &inc, ei);
2510 exprval_release(&exprval);
2514 ret->type = EXPRVAL_VARIANT;
2519 /* ECMA-262 3rd Edition 11.3.2 */
2520 HRESULT post_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2522 unary_expression_t *expr = (unary_expression_t*)_expr;
2529 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2533 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2534 if(SUCCEEDED(hres)) {
2535 hres = to_number(ctx->parser->script, &val, ei, &num);
2539 if(SUCCEEDED(hres)) {
2541 num_set_val(&dec, num_val(&num)-1.0);
2542 hres = put_value(ctx->parser->script, &exprval, &dec, ei);
2545 exprval_release(&exprval);
2549 ret->type = EXPRVAL_VARIANT;
2554 /* ECMA-262 3rd Edition 11.4.4 */
2555 HRESULT pre_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2557 unary_expression_t *expr = (unary_expression_t*)_expr;
2564 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2568 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2569 if(SUCCEEDED(hres)) {
2570 hres = to_number(ctx->parser->script, &val, ei, &num);
2574 if(SUCCEEDED(hres)) {
2575 num_set_val(&val, num_val(&num)+1.0);
2576 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2579 exprval_release(&exprval);
2583 ret->type = EXPRVAL_VARIANT;
2588 /* ECMA-262 3rd Edition 11.4.5 */
2589 HRESULT pre_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2591 unary_expression_t *expr = (unary_expression_t*)_expr;
2598 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2602 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2603 if(SUCCEEDED(hres)) {
2604 hres = to_number(ctx->parser->script, &val, ei, &num);
2608 if(SUCCEEDED(hres)) {
2609 num_set_val(&val, num_val(&num)-1.0);
2610 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2613 exprval_release(&exprval);
2617 ret->type = EXPRVAL_VARIANT;
2622 /* ECMA-262 3rd Edition 11.9.3 */
2623 static HRESULT equal_values(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
2625 if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
2626 return equal2_values(lval, rval, ret);
2628 /* FIXME: NULL disps should be handled in more general way */
2629 if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
2632 return equal_values(ctx, &v, rval, ei, ret);
2635 if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
2638 return equal_values(ctx, lval, &v, ei, ret);
2641 if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
2642 (V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
2647 if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
2651 hres = to_number(ctx->parser->script, lval, ei, &v);
2655 return equal_values(ctx, &v, rval, ei, ret);
2658 if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
2662 hres = to_number(ctx->parser->script, rval, ei, &v);
2666 return equal_values(ctx, lval, &v, ei, ret);
2669 if(V_VT(rval) == VT_BOOL) {
2673 V_I4(&v) = V_BOOL(rval) ? 1 : 0;
2674 return equal_values(ctx, lval, &v, ei, ret);
2677 if(V_VT(lval) == VT_BOOL) {
2681 V_I4(&v) = V_BOOL(lval) ? 1 : 0;
2682 return equal_values(ctx, &v, rval, ei, ret);
2686 if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
2690 hres = to_primitive(ctx->parser->script, rval, ei, &v, NO_HINT);
2694 hres = equal_values(ctx, lval, &v, ei, ret);
2701 if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
2705 hres = to_primitive(ctx->parser->script, lval, ei, &v, NO_HINT);
2709 hres = equal_values(ctx, &v, rval, ei, ret);
2720 /* ECMA-262 3rd Edition 11.9.1 */
2721 HRESULT equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2723 binary_expression_t *expr = (binary_expression_t*)_expr;
2730 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2734 hres = equal_values(ctx, &rval, &lval, ei, &b);
2738 return return_bool(ret, b);
2741 /* ECMA-262 3rd Edition 11.9.4 */
2742 HRESULT equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2744 binary_expression_t *expr = (binary_expression_t*)_expr;
2751 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2755 hres = equal2_values(&rval, &lval, &b);
2759 return return_bool(ret, b);
2762 /* ECMA-262 3rd Edition 11.9.2 */
2763 HRESULT not_equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2765 binary_expression_t *expr = (binary_expression_t*)_expr;
2772 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2776 hres = equal_values(ctx, &lval, &rval, ei, &b);
2780 return return_bool(ret, !b);
2783 /* ECMA-262 3rd Edition 11.9.5 */
2784 HRESULT not_equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2786 binary_expression_t *expr = (binary_expression_t*)_expr;
2793 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2797 hres = equal2_values(&lval, &rval, &b);
2801 return return_bool(ret, !b);
2804 /* ECMA-262 3rd Edition 11.8.5 */
2805 static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
2807 VARIANT l, r, ln, rn;
2810 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
2814 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
2820 if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
2821 *ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
2822 SysFreeString(V_BSTR(&l));
2823 SysFreeString(V_BSTR(&r));
2827 hres = to_number(ctx->parser->script, &l, ei, &ln);
2830 hres = to_number(ctx->parser->script, &r, ei, &rn);
2835 if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
2836 *ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
2838 DOUBLE ld = num_val(&ln);
2839 DOUBLE rd = num_val(&rn);
2841 *ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
2847 /* ECMA-262 3rd Edition 11.8.1 */
2848 HRESULT less_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2850 binary_expression_t *expr = (binary_expression_t*)_expr;
2857 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2861 hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
2862 VariantClear(&lval);
2863 VariantClear(&rval);
2867 return return_bool(ret, b);
2870 /* ECMA-262 3rd Edition 11.8.3 */
2871 HRESULT lesseq_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;
2880 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2884 hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
2885 VariantClear(&lval);
2886 VariantClear(&rval);
2890 return return_bool(ret, b);
2893 /* ECMA-262 3rd Edition 11.8.2 */
2894 HRESULT greater_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2896 binary_expression_t *expr = (binary_expression_t*)_expr;
2903 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2907 hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
2908 VariantClear(&lval);
2909 VariantClear(&rval);
2913 return return_bool(ret, b);
2916 /* ECMA-262 3rd Edition 11.8.4 */
2917 HRESULT greatereq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2919 binary_expression_t *expr = (binary_expression_t*)_expr;
2926 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2930 hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
2931 VariantClear(&lval);
2932 VariantClear(&rval);
2936 return return_bool(ret, b);
2939 /* ECMA-262 3rd Edition 11.4.8 */
2940 HRESULT binary_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2942 unary_expression_t *expr = (unary_expression_t*)_expr;
2950 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2954 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2955 exprval_release(&exprval);
2959 hres = to_int32(ctx->parser->script, &val, ei, &i);
2963 ret->type = EXPRVAL_VARIANT;
2964 V_VT(&ret->u.var) = VT_I4;
2965 V_I4(&ret->u.var) = ~i;
2969 /* ECMA-262 3rd Edition 11.4.9 */
2970 HRESULT logical_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2972 unary_expression_t *expr = (unary_expression_t*)_expr;
2979 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2983 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
2984 exprval_release(&exprval);
2988 return return_bool(ret, !b);
2991 /* ECMA-262 3rd Edition 11.7.1 */
2992 static HRESULT lshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2998 hres = to_int32(ctx->parser->script, lval, ei, &li);
3002 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3007 V_I4(retv) = li << (ri&0x1f);
3011 /* ECMA-262 3rd Edition 11.7.1 */
3012 HRESULT left_shift_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;
3018 return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
3021 /* ECMA-262 3rd Edition 11.7.2 */
3022 static HRESULT rshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3028 hres = to_int32(ctx->parser->script, lval, ei, &li);
3032 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3037 V_I4(retv) = li >> (ri&0x1f);
3041 /* ECMA-262 3rd Edition 11.7.2 */
3042 HRESULT right_shift_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;
3048 return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
3051 /* ECMA-262 3rd Edition 11.7.3 */
3052 static HRESULT rshift2_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3057 hres = to_uint32(ctx->parser->script, lval, ei, &li);
3061 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3066 V_I4(retv) = li >> (ri&0x1f);
3070 /* ECMA-262 3rd Edition 11.7.3 */
3071 HRESULT right2_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3073 binary_expression_t *expr = (binary_expression_t*)_expr;
3077 return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
3080 /* ECMA-262 3rd Edition 11.13.1 */
3081 HRESULT assign_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3083 binary_expression_t *expr = (binary_expression_t*)_expr;
3084 exprval_t exprval, exprvalr;
3090 hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
3094 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
3095 if(SUCCEEDED(hres)) {
3096 hres = exprval_to_value(ctx->parser->script, &exprvalr, ei, &rval);
3097 exprval_release(&exprvalr);
3101 hres = put_value(ctx->parser->script, &exprval, &rval, ei);
3103 exprval_release(&exprval);
3107 ret->type = EXPRVAL_VARIANT;
3112 /* ECMA-262 3rd Edition 11.13.2 */
3113 HRESULT assign_lshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3115 binary_expression_t *expr = (binary_expression_t*)_expr;
3119 return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
3122 /* ECMA-262 3rd Edition 11.13.2 */
3123 HRESULT assign_rshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3125 binary_expression_t *expr = (binary_expression_t*)_expr;
3129 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift_eval, ei, ret);
3132 /* ECMA-262 3rd Edition 11.13.2 */
3133 HRESULT assign_rrshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3135 binary_expression_t *expr = (binary_expression_t*)_expr;
3139 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift2_eval, ei, ret);
3142 /* ECMA-262 3rd Edition 11.13.2 */
3143 HRESULT assign_add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3145 binary_expression_t *expr = (binary_expression_t*)_expr;
3149 return assign_oper_eval(ctx, expr->expression1, expr->expression2, add_eval, ei, ret);
3152 /* ECMA-262 3rd Edition 11.13.2 */
3153 HRESULT assign_sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3155 binary_expression_t *expr = (binary_expression_t*)_expr;
3159 return assign_oper_eval(ctx, expr->expression1, expr->expression2, sub_eval, ei, ret);
3162 /* ECMA-262 3rd Edition 11.13.2 */
3163 HRESULT assign_mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3165 binary_expression_t *expr = (binary_expression_t*)_expr;
3169 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mul_eval, ei, ret);
3172 /* ECMA-262 3rd Edition 11.13.2 */
3173 HRESULT assign_div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3175 binary_expression_t *expr = (binary_expression_t*)_expr;
3179 return assign_oper_eval(ctx, expr->expression1, expr->expression2, div_eval, ei, ret);
3182 /* ECMA-262 3rd Edition 11.13.2 */
3183 HRESULT assign_mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3185 binary_expression_t *expr = (binary_expression_t*)_expr;
3189 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mod_eval, ei, ret);
3192 /* ECMA-262 3rd Edition 11.13.2 */
3193 HRESULT assign_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3195 binary_expression_t *expr = (binary_expression_t*)_expr;
3199 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitand_eval, ei, ret);
3202 /* ECMA-262 3rd Edition 11.13.2 */
3203 HRESULT assign_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3205 binary_expression_t *expr = (binary_expression_t*)_expr;
3209 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitor_eval, ei, ret);
3212 /* ECMA-262 3rd Edition 11.13.2 */
3213 HRESULT assign_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3215 binary_expression_t *expr = (binary_expression_t*)_expr;
3219 return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);