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(ctx, val->u.idref.disp, val->u.idref.id, 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(script_ctx_t *script_ctx, IDispatch *this_obj, DispatchEx *var_disp,
182 scope_chain_t *scope, exec_ctx_t **ret)
186 ctx = heap_alloc_zero(sizeof(exec_ctx_t));
188 return E_OUTOFMEMORY;
193 ctx->this_obj = this_obj;
194 else if(script_ctx->host_global)
195 ctx->this_obj = script_ctx->host_global;
197 ctx->this_obj = (IDispatch*)_IDispatchEx_(script_ctx->global);
198 IDispatch_AddRef(ctx->this_obj);
200 IDispatchEx_AddRef(_IDispatchEx_(var_disp));
201 ctx->var_disp = var_disp;
205 ctx->scope_chain = scope;
212 void exec_release(exec_ctx_t *ctx)
218 scope_release(ctx->scope_chain);
220 jsdisp_release(ctx->var_disp);
222 IDispatch_Release(ctx->this_obj);
226 static HRESULT disp_get_id(script_ctx_t *ctx, IDispatch *disp, BSTR name, DWORD flags, DISPID *id)
231 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
233 TRACE("unsing IDispatch\n");
236 return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
240 hres = IDispatchEx_GetDispID(dispex, name, make_grfdex(ctx, flags|fdexNameCaseSensitive), id);
241 IDispatchEx_Release(dispex);
245 /* ECMA-262 3rd Edition 8.7.2 */
246 static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei)
248 if(ref->type != EXPRVAL_IDREF)
249 return throw_reference_error(ctx, ei, IDS_ILLEGAL_ASSIGN, NULL);
251 return disp_propput(ctx, ref->u.idref.disp, ref->u.idref.id, v, ei, NULL/*FIXME*/);
254 static inline BOOL is_null(const VARIANT *v)
256 return V_VT(v) == VT_NULL || (V_VT(v) == VT_DISPATCH && !V_DISPATCH(v));
259 static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, BOOL *ret)
261 IObjectIdentity *identity;
262 IUnknown *unk1, *unk2;
270 if(!disp1 || !disp2) {
275 hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
279 hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
281 IUnknown_Release(unk1);
288 hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
289 if(SUCCEEDED(hres)) {
290 hres = IObjectIdentity_IsEqualObject(identity, unk2);
291 IObjectIdentity_Release(identity);
298 IUnknown_Release(unk1);
299 IUnknown_Release(unk2);
303 /* ECMA-262 3rd Edition 11.9.6 */
304 static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
308 if(V_VT(lval) != V_VT(rval)) {
309 if(is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval)))
310 *ret = num_val(lval) == num_val(rval);
311 else if(is_null(lval))
312 *ret = is_null(rval);
324 *ret = V_I4(lval) == V_I4(rval);
327 *ret = V_R8(lval) == V_R8(rval);
331 *ret = SysStringLen(V_BSTR(rval))?FALSE:TRUE;
332 else if(!V_BSTR(rval))
333 *ret = SysStringLen(V_BSTR(lval))?FALSE:TRUE;
335 *ret = !strcmpW(V_BSTR(lval), V_BSTR(rval));
338 return disp_cmp(V_DISPATCH(lval), V_DISPATCH(rval), ret);
340 *ret = !V_BOOL(lval) == !V_BOOL(rval);
343 FIXME("unimplemented vt %d\n", V_VT(lval));
350 static HRESULT literal_to_var(script_ctx_t *ctx, literal_t *literal, VARIANT *v)
352 switch(literal->type) {
361 V_I4(v) = literal->u.lval;
365 V_R8(v) = literal->u.dval;
368 BSTR str = SysAllocString(literal->u.wstr);
370 return E_OUTOFMEMORY;
378 V_BOOL(v) = literal->u.bval;
384 hres = create_regexp(ctx, literal->u.regexp.str, literal->u.regexp.str_len,
385 literal->u.regexp.flags, ®exp);
389 V_VT(v) = VT_DISPATCH;
390 V_DISPATCH(v) = (IDispatch*)_IDispatchEx_(regexp);
397 static BOOL lookup_global_members(script_ctx_t *ctx, BSTR identifier, exprval_t *ret)
403 for(item = ctx->named_items; item; item = item->next) {
404 if(item->flags & SCRIPTITEM_GLOBALMEMBERS) {
405 hres = disp_get_id(ctx, item->disp, identifier, 0, &id);
406 if(SUCCEEDED(hres)) {
408 exprval_set_idref(ret, item->disp, id);
417 HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, jsexcept_t *ei, VARIANT *retv)
419 script_ctx_t *script = parser->script;
420 function_declaration_t *func;
421 parser_ctx_t *prev_parser;
425 exec_ctx_t *prev_ctx;
429 for(func = source->functions; func; func = func->next) {
430 DispatchEx *func_obj;
433 hres = create_source_function(parser, func->expr->parameter_list, func->expr->source_elements,
434 ctx->scope_chain, func->expr->src_str, func->expr->src_len, &func_obj);
438 V_VT(&var) = VT_DISPATCH;
439 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(func_obj);
440 hres = jsdisp_propput_name(ctx->var_disp, func->expr->identifier, &var, ei, NULL);
441 jsdisp_release(func_obj);
446 for(var = source->variables; var; var = var->next) {
450 name = SysAllocString(var->identifier);
452 return E_OUTOFMEMORY;
454 if(!lookup_global_members(parser->script, name, NULL))
455 hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
461 prev_ctx = script->exec_ctx;
462 script->exec_ctx = ctx;
464 prev_parser = ctx->parser;
465 ctx->parser = parser;
467 V_VT(&val) = VT_EMPTY;
468 memset(&rt, 0, sizeof(rt));
471 for(stat = source->statement; stat; stat = stat->next) {
472 hres = stat_eval(ctx, stat, &rt, &tmp);
478 if(rt.type != RT_NORMAL)
482 script->exec_ctx = prev_ctx;
483 ctx->parser = prev_parser;
485 if(rt.type != RT_NORMAL && rt.type != RT_RETURN) {
486 FIXME("wrong rt %d\n", rt.type);
503 /* ECMA-262 3rd Edition 10.1.4 */
504 static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, jsexcept_t *ei, exprval_t *ret)
506 scope_chain_t *scope;
511 TRACE("%s\n", debugstr_w(identifier));
513 for(scope = ctx->scope_chain; scope; scope = scope->next) {
514 hres = jsdisp_get_id(scope->obj, identifier, 0, &id);
520 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(scope->obj), id);
524 hres = jsdisp_get_id(ctx->parser->script->global, identifier, 0, &id);
525 if(SUCCEEDED(hres)) {
526 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->global), id);
530 for(item = ctx->parser->script->named_items; item; item = item->next) {
531 if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpW(item->name, identifier)) {
535 if(!ctx->parser->script->site)
538 hres = IActiveScriptSite_GetItemInfo(ctx->parser->script->site, identifier,
539 SCRIPTINFO_IUNKNOWN, &unk, NULL);
541 WARN("GetItemInfo failed: %08x\n", hres);
545 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
546 IUnknown_Release(unk);
548 WARN("object does not implement IDispatch\n");
553 ret->type = EXPRVAL_VARIANT;
554 V_VT(&ret->u.var) = VT_DISPATCH;
555 V_DISPATCH(&ret->u.var) = item->disp;
556 IDispatch_AddRef(item->disp);
561 if(lookup_global_members(ctx->parser->script, identifier, ret))
564 if(flags & EXPR_NEWREF) {
565 hres = jsdisp_get_id(ctx->parser->script->global, identifier, fdexNameEnsure, &id);
569 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->global), id);
573 ret->type = EXPRVAL_INVALID;
574 ret->u.identifier = SysAllocString(identifier);
575 if(!ret->u.identifier)
576 return E_OUTOFMEMORY;
581 /* ECMA-262 3rd Edition 12.1 */
582 HRESULT block_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
584 block_statement_t *stat = (block_statement_t*)_stat;
591 V_VT(&val) = VT_EMPTY;
592 for(iter = stat->stat_list; iter; iter = iter->next) {
593 hres = stat_eval(ctx, iter, rt, &tmp);
599 if(rt->type != RT_NORMAL)
612 /* ECMA-262 3rd Edition 12.2 */
613 static HRESULT variable_list_eval(exec_ctx_t *ctx, variable_declaration_t *var_list, jsexcept_t *ei)
615 variable_declaration_t *iter;
618 for(iter = var_list; iter; iter = iter->next) {
625 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
629 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
630 exprval_release(&exprval);
634 hres = jsdisp_propput_name(ctx->var_disp, iter->identifier, &val, ei, NULL/*FIXME*/);
643 /* ECMA-262 3rd Edition 12.2 */
644 HRESULT var_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
646 var_statement_t *stat = (var_statement_t*)_stat;
651 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
655 V_VT(ret) = VT_EMPTY;
659 /* ECMA-262 3rd Edition 12.3 */
660 HRESULT empty_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
664 V_VT(ret) = VT_EMPTY;
668 /* ECMA-262 3rd Edition 12.4 */
669 HRESULT expression_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
671 expression_statement_t *stat = (expression_statement_t*)_stat;
678 hres = expr_eval(ctx, stat->expr, EXPR_NOVAL, &rt->ei, &exprval);
682 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
683 exprval_release(&exprval);
688 TRACE("= %s\n", debugstr_variant(ret));
692 /* ECMA-262 3rd Edition 12.5 */
693 HRESULT if_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
695 if_statement_t *stat = (if_statement_t*)_stat;
702 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
706 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
707 exprval_release(&exprval);
712 hres = stat_eval(ctx, stat->if_stat, rt, ret);
713 else if(stat->else_stat)
714 hres = stat_eval(ctx, stat->else_stat, rt, ret);
716 V_VT(ret) = VT_EMPTY;
721 /* ECMA-262 3rd Edition 12.6.2 */
722 HRESULT while_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
724 while_statement_t *stat = (while_statement_t*)_stat;
733 V_VT(&val) = VT_EMPTY;
734 test_expr = !stat->do_while;
738 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
742 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
743 exprval_release(&exprval);
744 if(FAILED(hres) || !b)
750 hres = stat_eval(ctx, stat->statement, rt, &tmp);
757 if(rt->type == RT_CONTINUE)
758 rt->type = RT_NORMAL;
759 if(rt->type != RT_NORMAL)
768 if(rt->type == RT_BREAK)
769 rt->type = RT_NORMAL;
775 /* ECMA-262 3rd Edition 12.6.3 */
776 HRESULT for_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
778 for_statement_t *stat = (for_statement_t*)_stat;
779 VARIANT val, tmp, retv;
786 if(stat->variable_list) {
787 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
790 }else if(stat->begin_expr) {
791 hres = expr_eval(ctx, stat->begin_expr, EXPR_NEWREF, &rt->ei, &exprval);
795 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
796 exprval_release(&exprval);
803 V_VT(&retv) = VT_EMPTY;
807 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
811 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
812 exprval_release(&exprval);
813 if(FAILED(hres) || !b)
817 hres = stat_eval(ctx, stat->statement, rt, &tmp);
824 if(rt->type == RT_CONTINUE)
825 rt->type = RT_NORMAL;
826 else if(rt->type != RT_NORMAL)
830 hres = expr_eval(ctx, stat->end_expr, 0, &rt->ei, &exprval);
834 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
835 exprval_release(&exprval);
848 if(rt->type == RT_BREAK)
849 rt->type = RT_NORMAL;
855 /* ECMA-262 3rd Edition 12.6.4 */
856 HRESULT forin_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
858 forin_statement_t *stat = (forin_statement_t*)_stat;
859 VARIANT val, name, retv, tmp;
860 DISPID id = DISPID_STARTENUM;
861 BSTR str, identifier = NULL;
869 hres = variable_list_eval(ctx, stat->variable, &rt->ei);
874 hres = expr_eval(ctx, stat->in_expr, EXPR_NEWREF, &rt->ei, &exprval);
878 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
879 exprval_release(&exprval);
883 if(V_VT(&val) != VT_DISPATCH) {
884 TRACE("in vt %d\n", V_VT(&val));
886 V_VT(ret) = VT_EMPTY;
890 hres = IDispatch_QueryInterface(V_DISPATCH(&val), &IID_IDispatchEx, (void**)&in_obj);
891 IDispatch_Release(V_DISPATCH(&val));
893 FIXME("Object doesn't support IDispatchEx\n");
897 V_VT(&retv) = VT_EMPTY;
900 identifier = SysAllocString(stat->variable->identifier);
903 hres = IDispatchEx_GetNextDispID(in_obj, fdexEnumDefault, id, &id);
904 if(FAILED(hres) || hres == S_FALSE)
907 hres = IDispatchEx_GetMemberName(in_obj, id, &str);
911 TRACE("iter %s\n", debugstr_w(str));
914 hres = identifier_eval(ctx, identifier, 0, NULL, &exprval);
916 hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval);
917 if(SUCCEEDED(hres)) {
918 V_VT(&name) = VT_BSTR;
920 hres = put_value(ctx->parser->script, &exprval, &name, &rt->ei);
921 exprval_release(&exprval);
927 hres = stat_eval(ctx, stat->statement, rt, &tmp);
934 if(rt->type == RT_CONTINUE)
935 rt->type = RT_NORMAL;
936 else if(rt->type != RT_NORMAL)
940 SysFreeString(identifier);
941 IDispatchEx_Release(in_obj);
947 if(rt->type == RT_BREAK)
948 rt->type = RT_NORMAL;
954 /* ECMA-262 3rd Edition 12.7 */
955 HRESULT continue_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
957 branch_statement_t *stat = (branch_statement_t*)_stat;
961 if(stat->identifier) {
962 FIXME("indentifier not implemented\n");
966 rt->type = RT_CONTINUE;
967 V_VT(ret) = VT_EMPTY;
971 /* ECMA-262 3rd Edition 12.8 */
972 HRESULT break_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
974 branch_statement_t *stat = (branch_statement_t*)_stat;
978 if(stat->identifier) {
979 FIXME("indentifier not implemented\n");
984 V_VT(ret) = VT_EMPTY;
988 /* ECMA-262 3rd Edition 12.9 */
989 HRESULT return_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
991 expression_statement_t *stat = (expression_statement_t*)_stat;
999 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1003 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, ret);
1004 exprval_release(&exprval);
1008 V_VT(ret) = VT_EMPTY;
1011 TRACE("= %s\n", debugstr_variant(ret));
1012 rt->type = RT_RETURN;
1016 /* ECMA-262 3rd Edition 12.10 */
1017 HRESULT with_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1019 with_statement_t *stat = (with_statement_t*)_stat;
1028 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1032 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1033 exprval_release(&exprval);
1037 hres = to_object(ctx->parser->script, &val, &disp);
1042 obj = iface_to_jsdisp((IUnknown*)disp);
1043 IDispatch_Release(disp);
1045 FIXME("disp id not jsdisp\n");
1049 hres = scope_push(ctx->scope_chain, obj, &ctx->scope_chain);
1050 jsdisp_release(obj);
1054 hres = stat_eval(ctx, stat->statement, rt, ret);
1056 scope_pop(&ctx->scope_chain);
1060 /* ECMA-262 3rd Edition 12.12 */
1061 HRESULT labelled_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
1067 /* ECMA-262 3rd Edition 12.13 */
1068 HRESULT switch_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1070 switch_statement_t *stat = (switch_statement_t*)_stat;
1071 case_clausule_t *iter, *default_clausule = NULL;
1072 statement_t *stat_iter;
1080 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1084 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1085 exprval_release(&exprval);
1089 for(iter = stat->case_list; iter; iter = iter->next) {
1091 default_clausule = iter;
1095 hres = expr_eval(ctx, iter->expr, 0, &rt->ei, &exprval);
1099 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &cval);
1100 exprval_release(&exprval);
1104 hres = equal2_values(&val, &cval, &b);
1105 VariantClear(&cval);
1106 if(FAILED(hres) || b)
1115 iter = default_clausule;
1117 V_VT(&val) = VT_EMPTY;
1121 for(stat_iter = iter->stat; stat_iter; stat_iter = stat_iter->next) {
1122 hres = stat_eval(ctx, stat_iter, rt, &tmp);
1129 if(rt->type != RT_NORMAL)
1139 if(rt->type == RT_BREAK)
1140 rt->type = RT_NORMAL;
1146 /* ECMA-262 3rd Edition 12.13 */
1147 HRESULT throw_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1149 expression_statement_t *stat = (expression_statement_t*)_stat;
1156 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1160 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1161 exprval_release(&exprval);
1166 return DISP_E_EXCEPTION;
1169 /* ECMA-262 3rd Edition 12.14 */
1170 static HRESULT catch_eval(exec_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
1172 DispatchEx *var_disp;
1177 memset(&rt->ei, 0, sizeof(jsexcept_t));
1179 hres = create_dispex(ctx->parser->script, NULL, NULL, &var_disp);
1180 if(SUCCEEDED(hres)) {
1181 hres = jsdisp_propput_name(var_disp, block->identifier, &ex, &rt->ei, NULL/*FIXME*/);
1182 if(SUCCEEDED(hres)) {
1183 hres = scope_push(ctx->scope_chain, var_disp, &ctx->scope_chain);
1184 if(SUCCEEDED(hres)) {
1185 hres = stat_eval(ctx, block->statement, rt, &val);
1186 scope_pop(&ctx->scope_chain);
1190 jsdisp_release(var_disp);
1201 /* ECMA-262 3rd Edition 12.14 */
1202 HRESULT try_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1204 try_statement_t *stat = (try_statement_t*)_stat;
1210 hres = stat_eval(ctx, stat->try_statement, rt, &val);
1212 TRACE("EXCEPTION\n");
1213 if(!stat->catch_block)
1216 hres = catch_eval(ctx, stat->catch_block, rt, &val);
1221 if(stat->finally_statement) {
1223 hres = stat_eval(ctx, stat->finally_statement, rt, &val);
1232 static HRESULT return_bool(exprval_t *ret, DWORD b)
1234 ret->type = EXPRVAL_VARIANT;
1235 V_VT(&ret->u.var) = VT_BOOL;
1236 V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;
1241 static HRESULT get_binary_expr_values(exec_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
1246 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1250 hres = exprval_to_value(ctx->parser->script, &exprval, ei, lval);
1251 exprval_release(&exprval);
1255 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1256 if(SUCCEEDED(hres)) {
1257 hres = exprval_to_value(ctx->parser->script, &exprval, ei, rval);
1258 exprval_release(&exprval);
1269 typedef HRESULT (*oper_t)(exec_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);
1271 static HRESULT binary_expr_eval(exec_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
1274 VARIANT lval, rval, retv;
1277 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1281 hres = oper(ctx, &lval, &rval, ei, &retv);
1282 VariantClear(&lval);
1283 VariantClear(&rval);
1287 ret->type = EXPRVAL_VARIANT;
1292 /* ECMA-262 3rd Edition 11.13.2 */
1293 static HRESULT assign_oper_eval(exec_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
1294 jsexcept_t *ei, exprval_t *ret)
1296 VARIANT retv, lval, rval;
1297 exprval_t exprval, exprvalr;
1300 hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
1304 hres = exprval_value(ctx->parser->script, &exprval, ei, &lval);
1305 if(SUCCEEDED(hres)) {
1306 hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
1307 if(SUCCEEDED(hres)) {
1308 hres = exprval_value(ctx->parser->script, &exprvalr, ei, &rval);
1309 exprval_release(&exprvalr);
1311 if(SUCCEEDED(hres)) {
1312 hres = oper(ctx, &lval, &rval, ei, &retv);
1313 VariantClear(&rval);
1315 VariantClear(&lval);
1318 if(SUCCEEDED(hres)) {
1319 hres = put_value(ctx->parser->script, &exprval, &retv, ei);
1321 VariantClear(&retv);
1323 exprval_release(&exprval);
1328 ret->type = EXPRVAL_VARIANT;
1333 /* ECMA-262 3rd Edition 13 */
1334 HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1336 function_expression_t *expr = (function_expression_t*)_expr;
1342 if(expr->identifier) {
1343 hres = jsdisp_propget_name(ctx->var_disp, expr->identifier, &var, ei, NULL/*FIXME*/);
1349 hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain,
1350 expr->src_str, expr->src_len, &dispex);
1354 V_VT(&var) = VT_DISPATCH;
1355 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
1358 ret->type = EXPRVAL_VARIANT;
1363 /* ECMA-262 3rd Edition 11.12 */
1364 HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1366 conditional_expression_t *expr = (conditional_expression_t*)_expr;
1373 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1377 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
1378 exprval_release(&exprval);
1382 return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
1385 /* ECMA-262 3rd Edition 11.2.1 */
1386 HRESULT array_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1388 array_expression_t *expr = (array_expression_t*)_expr;
1390 VARIANT member, val;
1393 IDispatch *obj = NULL;
1398 hres = expr_eval(ctx, expr->member_expr, EXPR_NEWREF, ei, &exprval);
1402 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1403 exprval_release(&exprval);
1407 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
1408 if(SUCCEEDED(hres)) {
1409 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1410 exprval_release(&exprval);
1414 hres = to_object(ctx->parser->script, &member, &obj);
1415 VariantClear(&member);
1416 if(SUCCEEDED(hres)) {
1417 hres = to_string(ctx->parser->script, &val, ei, &str);
1418 if(SUCCEEDED(hres)) {
1419 if(flags & EXPR_STRREF) {
1420 ret->type = EXPRVAL_NAMEREF;
1421 ret->u.nameref.disp = obj;
1422 ret->u.nameref.name = str;
1426 hres = disp_get_id(ctx->parser->script, obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1429 if(SUCCEEDED(hres)) {
1430 exprval_set_idref(ret, obj, id);
1431 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1436 IDispatch_Release(obj);
1442 /* ECMA-262 3rd Edition 11.2.1 */
1443 HRESULT member_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1445 member_expression_t *expr = (member_expression_t*)_expr;
1446 IDispatch *obj = NULL;
1455 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1459 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1460 exprval_release(&exprval);
1464 hres = to_object(ctx->parser->script, &member, &obj);
1465 VariantClear(&member);
1469 str = SysAllocString(expr->identifier);
1470 if(flags & EXPR_STRREF) {
1471 ret->type = EXPRVAL_NAMEREF;
1472 ret->u.nameref.disp = obj;
1473 ret->u.nameref.name = str;
1477 hres = disp_get_id(ctx->parser->script, obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1479 if(SUCCEEDED(hres)) {
1480 exprval_set_idref(ret, obj, id);
1481 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1486 IDispatch_Release(obj);
1490 static void free_dp(DISPPARAMS *dp)
1494 for(i=0; i < dp->cArgs; i++)
1495 VariantClear(dp->rgvarg+i);
1496 heap_free(dp->rgvarg);
1499 static HRESULT args_to_param(exec_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
1505 HRESULT hres = S_OK;
1507 memset(dp, 0, sizeof(*dp));
1511 for(iter = args; iter; iter = iter->next)
1514 vargs = heap_alloc_zero(cnt * sizeof(*vargs));
1516 return E_OUTOFMEMORY;
1518 for(i = cnt, iter = args; iter; iter = iter->next) {
1519 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
1523 hres = exprval_to_value(ctx->parser->script, &exprval, ei, vargs + (--i));
1524 exprval_release(&exprval);
1539 /* ECMA-262 3rd Edition 11.2.2 */
1540 HRESULT new_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1542 call_expression_t *expr = (call_expression_t*)_expr;
1544 VARIANT constr, var;
1550 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1554 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1556 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &constr);
1557 exprval_release(&exprval);
1561 if(V_VT(&constr) != VT_DISPATCH) {
1562 FIXME("throw TypeError\n");
1563 VariantClear(&constr);
1567 hres = disp_call(ctx->parser->script, V_DISPATCH(&constr), DISPID_VALUE,
1568 DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
1569 IDispatch_Release(V_DISPATCH(&constr));
1573 ret->type = EXPRVAL_VARIANT;
1578 /* ECMA-262 3rd Edition 11.2.3 */
1579 HRESULT call_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1581 call_expression_t *expr = (call_expression_t*)_expr;
1589 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1593 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1594 if(SUCCEEDED(hres)) {
1595 switch(exprval.type) {
1596 case EXPRVAL_VARIANT:
1597 if(V_VT(&exprval.u.var) == VT_DISPATCH)
1598 hres = disp_call(ctx->parser->script, V_DISPATCH(&exprval.u.var), DISPID_VALUE,
1599 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1601 hres = throw_type_error(ctx->parser->script, ei, IDS_NO_PROPERTY, NULL);
1604 hres = disp_call(ctx->parser->script, exprval.u.idref.disp, exprval.u.idref.id,
1605 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1607 case EXPRVAL_INVALID:
1608 hres = throw_type_error(ctx->parser->script, ei, IDS_OBJECT_EXPECTED, NULL);
1611 FIXME("unimplemented type %d\n", exprval.type);
1618 exprval_release(&exprval);
1622 ret->type = EXPRVAL_VARIANT;
1623 if(flags & EXPR_NOVAL) {
1624 V_VT(&ret->u.var) = VT_EMPTY;
1626 TRACE("= %s\n", debugstr_variant(&var));
1632 /* ECMA-262 3rd Edition 11.1.1 */
1633 HRESULT this_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1637 ret->type = EXPRVAL_VARIANT;
1638 V_VT(&ret->u.var) = VT_DISPATCH;
1639 V_DISPATCH(&ret->u.var) = ctx->this_obj;
1640 IDispatch_AddRef(ctx->this_obj);
1644 /* ECMA-262 3rd Edition 10.1.4 */
1645 HRESULT identifier_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1647 identifier_expression_t *expr = (identifier_expression_t*)_expr;
1653 identifier = SysAllocString(expr->identifier);
1655 return E_OUTOFMEMORY;
1657 hres = identifier_eval(ctx, identifier, flags, ei, ret);
1659 SysFreeString(identifier);
1663 /* ECMA-262 3rd Edition 7.8 */
1664 HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1666 literal_expression_t *expr = (literal_expression_t*)_expr;
1672 hres = literal_to_var(ctx->parser->script, expr->literal, &var);
1676 ret->type = EXPRVAL_VARIANT;
1681 /* ECMA-262 3rd Edition 11.1.4 */
1682 HRESULT array_literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1684 array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
1685 DWORD length = 0, i = 0;
1686 array_element_t *elem;
1694 for(elem = expr->element_list; elem; elem = elem->next)
1695 length += elem->elision+1;
1696 length += expr->length;
1698 hres = create_array(ctx->parser->script, length, &array);
1702 for(elem = expr->element_list; elem; elem = elem->next) {
1705 hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
1709 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1710 exprval_release(&exprval);
1714 hres = jsdisp_propput_idx(array, i, &val, ei, NULL/*FIXME*/);
1723 jsdisp_release(array);
1727 ret->type = EXPRVAL_VARIANT;
1728 V_VT(&ret->u.var) = VT_DISPATCH;
1729 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(array);
1733 /* ECMA-262 3rd Edition 11.1.5 */
1734 HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1736 property_value_expression_t *expr = (property_value_expression_t*)_expr;
1746 hres = create_object(ctx->parser->script, NULL, &obj);
1750 for(iter = expr->property_list; iter; iter = iter->next) {
1751 hres = literal_to_var(ctx->parser->script, iter->name, &tmp);
1755 hres = to_string(ctx->parser->script, &tmp, ei, &name);
1760 hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
1761 if(SUCCEEDED(hres)) {
1762 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1763 exprval_release(&exprval);
1764 if(SUCCEEDED(hres)) {
1765 hres = jsdisp_propput_name(obj, name, &val, ei, NULL/*FIXME*/);
1770 SysFreeString(name);
1776 jsdisp_release(obj);
1780 ret->type = EXPRVAL_VARIANT;
1781 V_VT(&ret->u.var) = VT_DISPATCH;
1782 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(obj);
1786 /* ECMA-262 3rd Edition 11.14 */
1787 HRESULT comma_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1789 binary_expression_t *expr = (binary_expression_t*)_expr;
1795 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1799 VariantClear(&lval);
1801 ret->type = EXPRVAL_VARIANT;
1806 /* ECMA-262 3rd Edition 11.11 */
1807 HRESULT logical_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1809 binary_expression_t *expr = (binary_expression_t*)_expr;
1817 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1821 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1822 exprval_release(&exprval);
1826 hres = to_boolean(&val, &b);
1827 if(SUCCEEDED(hres) && b) {
1828 ret->type = EXPRVAL_VARIANT;
1837 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1841 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1842 exprval_release(&exprval);
1846 ret->type = EXPRVAL_VARIANT;
1851 /* ECMA-262 3rd Edition 11.11 */
1852 HRESULT logical_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1854 binary_expression_t *expr = (binary_expression_t*)_expr;
1862 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1866 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1867 exprval_release(&exprval);
1871 hres = to_boolean(&val, &b);
1872 if(SUCCEEDED(hres) && !b) {
1873 ret->type = EXPRVAL_VARIANT;
1882 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1886 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1887 exprval_release(&exprval);
1891 ret->type = EXPRVAL_VARIANT;
1896 /* ECMA-262 3rd Edition 11.10 */
1897 static HRESULT bitor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1902 hres = to_int32(ctx->parser->script, lval, ei, &li);
1906 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1915 /* ECMA-262 3rd Edition 11.10 */
1916 HRESULT binary_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1918 binary_expression_t *expr = (binary_expression_t*)_expr;
1922 return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
1925 /* ECMA-262 3rd Edition 11.10 */
1926 static HRESULT xor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1931 hres = to_int32(ctx->parser->script, lval, ei, &li);
1935 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1944 /* ECMA-262 3rd Edition 11.10 */
1945 HRESULT binary_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1947 binary_expression_t *expr = (binary_expression_t*)_expr;
1951 return binary_expr_eval(ctx, expr, xor_eval, ei, ret);
1954 /* ECMA-262 3rd Edition 11.10 */
1955 static HRESULT bitand_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1960 hres = to_int32(ctx->parser->script, lval, ei, &li);
1964 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1973 /* ECMA-262 3rd Edition 11.10 */
1974 HRESULT binary_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1976 binary_expression_t *expr = (binary_expression_t*)_expr;
1980 return binary_expr_eval(ctx, expr, bitand_eval, ei, ret);
1983 /* ECMA-262 3rd Edition 11.8.6 */
1984 static HRESULT instanceof_eval(exec_ctx_t *ctx, VARIANT *inst, VARIANT *objv, jsexcept_t *ei, VARIANT *retv)
1986 DispatchEx *obj, *iter, *tmp = NULL;
1987 VARIANT_BOOL ret = VARIANT_FALSE;
1992 static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
1994 if(V_VT(objv) != VT_DISPATCH) {
1995 FIXME("throw TypeError\n");
1999 obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(objv));
2001 FIXME("throw TypeError\n");
2005 if(is_class(obj, JSCLASS_FUNCTION)) {
2006 hres = jsdisp_propget_name(obj, prototypeW, &var, ei, NULL/*FIXME*/);
2008 FIXME("throw TypeError\n");
2011 jsdisp_release(obj);
2015 if(V_VT(&var) == VT_DISPATCH) {
2016 if(V_VT(inst) == VT_DISPATCH)
2017 tmp = iface_to_jsdisp((IUnknown*)V_DISPATCH(inst));
2018 for(iter = tmp; iter; iter = iter->prototype) {
2019 hres = disp_cmp(V_DISPATCH(&var), (IDispatch*)_IDispatchEx_(iter), &b);
2029 jsdisp_release(tmp);
2031 FIXME("prototype is not an object\n");
2039 V_VT(retv) = VT_BOOL;
2044 /* ECMA-262 3rd Edition 11.8.6 */
2045 HRESULT instanceof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2047 binary_expression_t *expr = (binary_expression_t*)_expr;
2051 return binary_expr_eval(ctx, expr, instanceof_eval, ei, ret);
2054 /* ECMA-262 3rd Edition 11.8.7 */
2055 static HRESULT in_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *obj, jsexcept_t *ei, VARIANT *retv)
2062 if(V_VT(obj) != VT_DISPATCH) {
2063 FIXME("throw TypeError\n");
2067 hres = to_string(ctx->parser->script, lval, ei, &str);
2071 hres = disp_get_id(ctx->parser->script, V_DISPATCH(obj), str, 0, &id);
2075 else if(hres == DISP_E_UNKNOWNNAME)
2076 ret = VARIANT_FALSE;
2080 V_VT(retv) = VT_BOOL;
2085 /* ECMA-262 3rd Edition 11.8.7 */
2086 HRESULT in_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2088 binary_expression_t *expr = (binary_expression_t*)_expr;
2092 return binary_expr_eval(ctx, expr, in_eval, ei, ret);
2095 /* ECMA-262 3rd Edition 11.6.1 */
2096 static HRESULT add_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2101 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
2105 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
2111 if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
2112 BSTR lstr = NULL, rstr = NULL;
2114 if(V_VT(&l) == VT_BSTR)
2117 hres = to_string(ctx->parser->script, &l, ei, &lstr);
2119 if(SUCCEEDED(hres)) {
2120 if(V_VT(&r) == VT_BSTR)
2123 hres = to_string(ctx->parser->script, &r, ei, &rstr);
2126 if(SUCCEEDED(hres)) {
2129 len1 = SysStringLen(lstr);
2130 len2 = SysStringLen(rstr);
2132 V_VT(retv) = VT_BSTR;
2133 V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
2134 memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
2135 memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
2138 if(V_VT(&l) != VT_BSTR)
2139 SysFreeString(lstr);
2140 if(V_VT(&r) != VT_BSTR)
2141 SysFreeString(rstr);
2145 hres = to_number(ctx->parser->script, &l, ei, &nl);
2146 if(SUCCEEDED(hres)) {
2147 hres = to_number(ctx->parser->script, &r, ei, &nr);
2149 num_set_val(retv, num_val(&nl) + num_val(&nr));
2158 /* ECMA-262 3rd Edition 11.6.1 */
2159 HRESULT add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2161 binary_expression_t *expr = (binary_expression_t*)_expr;
2165 return binary_expr_eval(ctx, expr, add_eval, ei, ret);
2168 /* ECMA-262 3rd Edition 11.6.2 */
2169 static HRESULT sub_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2174 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2178 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2182 num_set_val(retv, num_val(&lnum) - num_val(&rnum));
2186 /* ECMA-262 3rd Edition 11.6.2 */
2187 HRESULT sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2189 binary_expression_t *expr = (binary_expression_t*)_expr;
2193 return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
2196 /* ECMA-262 3rd Edition 11.5.1 */
2197 static HRESULT mul_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2202 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2206 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2210 num_set_val(retv, num_val(&lnum) * num_val(&rnum));
2214 /* ECMA-262 3rd Edition 11.5.1 */
2215 HRESULT mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2217 binary_expression_t *expr = (binary_expression_t*)_expr;
2221 return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
2224 /* ECMA-262 3rd Edition 11.5.2 */
2225 static HRESULT div_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2230 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2234 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2238 num_set_val(retv, num_val(&lnum) / num_val(&rnum));
2242 /* ECMA-262 3rd Edition 11.5.2 */
2243 HRESULT div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2245 binary_expression_t *expr = (binary_expression_t*)_expr;
2249 return binary_expr_eval(ctx, expr, div_eval, ei, ret);
2252 /* ECMA-262 3rd Edition 11.5.3 */
2253 static HRESULT mod_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2258 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2262 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2266 num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
2270 /* ECMA-262 3rd Edition 11.5.3 */
2271 HRESULT mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2273 binary_expression_t *expr = (binary_expression_t*)_expr;
2277 return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
2280 /* ECMA-262 3rd Edition 11.4.2 */
2281 HRESULT delete_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2283 unary_expression_t *expr = (unary_expression_t*)_expr;
2284 VARIANT_BOOL b = VARIANT_FALSE;
2290 hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
2294 switch(exprval.type) {
2295 case EXPRVAL_IDREF: {
2296 IDispatchEx *dispex;
2298 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2299 if(SUCCEEDED(hres)) {
2300 hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
2302 IDispatchEx_Release(dispex);
2306 case EXPRVAL_NAMEREF: {
2307 IDispatchEx *dispex;
2309 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2310 if(SUCCEEDED(hres)) {
2311 hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name,
2312 make_grfdex(ctx->parser->script, fdexNameCaseSensitive));
2314 IDispatchEx_Release(dispex);
2319 FIXME("unsupported type %d\n", exprval.type);
2323 exprval_release(&exprval);
2327 return return_bool(ret, b);
2330 /* ECMA-262 3rd Edition 11.4.2 */
2331 HRESULT void_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2333 unary_expression_t *expr = (unary_expression_t*)_expr;
2340 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2344 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &tmp);
2345 exprval_release(&exprval);
2351 ret->type = EXPRVAL_VARIANT;
2352 V_VT(&ret->u.var) = VT_EMPTY;
2356 /* ECMA-262 3rd Edition 11.4.3 */
2357 static HRESULT typeof_exprval(exec_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, const WCHAR **ret)
2362 static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
2363 static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
2364 static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
2365 static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
2366 static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
2367 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
2369 if(exprval->type == EXPRVAL_INVALID) {
2374 hres = exprval_to_value(ctx->parser->script, exprval, ei, &val);
2378 switch(V_VT(&val)) {
2398 if(V_DISPATCH(&val) && (dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val)))) {
2399 *ret = is_class(dispex, JSCLASS_FUNCTION) ? functionW : objectW;
2400 jsdisp_release(dispex);
2407 FIXME("unhandled vt %d\n", V_VT(&val));
2415 HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2417 unary_expression_t *expr = (unary_expression_t*)_expr;
2418 const WCHAR *str = NULL;
2424 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2428 hres = typeof_exprval(ctx, &exprval, ei, &str);
2429 exprval_release(&exprval);
2433 ret->type = EXPRVAL_VARIANT;
2434 V_VT(&ret->u.var) = VT_BSTR;
2435 V_BSTR(&ret->u.var) = SysAllocString(str);
2436 if(!V_BSTR(&ret->u.var))
2437 return E_OUTOFMEMORY;
2442 /* ECMA-262 3rd Edition 11.4.7 */
2443 HRESULT minus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2445 unary_expression_t *expr = (unary_expression_t*)_expr;
2452 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2456 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2457 exprval_release(&exprval);
2461 hres = to_number(ctx->parser->script, &val, ei, &num);
2466 ret->type = EXPRVAL_VARIANT;
2467 num_set_val(&ret->u.var, -num_val(&num));
2471 /* ECMA-262 3rd Edition 11.4.6 */
2472 HRESULT plus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2474 unary_expression_t *expr = (unary_expression_t*)_expr;
2481 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2485 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2486 exprval_release(&exprval);
2490 hres = to_number(ctx->parser->script, &val, ei, &num);
2494 ret->type = EXPRVAL_VARIANT;
2499 /* ECMA-262 3rd Edition 11.3.1 */
2500 HRESULT post_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2502 unary_expression_t *expr = (unary_expression_t*)_expr;
2509 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2513 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2514 if(SUCCEEDED(hres)) {
2515 hres = to_number(ctx->parser->script, &val, ei, &num);
2519 if(SUCCEEDED(hres)) {
2521 num_set_val(&inc, num_val(&num)+1.0);
2522 hres = put_value(ctx->parser->script, &exprval, &inc, ei);
2525 exprval_release(&exprval);
2529 ret->type = EXPRVAL_VARIANT;
2534 /* ECMA-262 3rd Edition 11.3.2 */
2535 HRESULT post_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2537 unary_expression_t *expr = (unary_expression_t*)_expr;
2544 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2548 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2549 if(SUCCEEDED(hres)) {
2550 hres = to_number(ctx->parser->script, &val, ei, &num);
2554 if(SUCCEEDED(hres)) {
2556 num_set_val(&dec, num_val(&num)-1.0);
2557 hres = put_value(ctx->parser->script, &exprval, &dec, ei);
2560 exprval_release(&exprval);
2564 ret->type = EXPRVAL_VARIANT;
2569 /* ECMA-262 3rd Edition 11.4.4 */
2570 HRESULT pre_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2572 unary_expression_t *expr = (unary_expression_t*)_expr;
2579 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2583 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2584 if(SUCCEEDED(hres)) {
2585 hres = to_number(ctx->parser->script, &val, ei, &num);
2589 if(SUCCEEDED(hres)) {
2590 num_set_val(&val, num_val(&num)+1.0);
2591 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2594 exprval_release(&exprval);
2598 ret->type = EXPRVAL_VARIANT;
2603 /* ECMA-262 3rd Edition 11.4.5 */
2604 HRESULT pre_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2606 unary_expression_t *expr = (unary_expression_t*)_expr;
2613 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2617 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2618 if(SUCCEEDED(hres)) {
2619 hres = to_number(ctx->parser->script, &val, ei, &num);
2623 if(SUCCEEDED(hres)) {
2624 num_set_val(&val, num_val(&num)-1.0);
2625 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2628 exprval_release(&exprval);
2632 ret->type = EXPRVAL_VARIANT;
2637 /* ECMA-262 3rd Edition 11.9.3 */
2638 static HRESULT equal_values(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
2640 if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
2641 return equal2_values(lval, rval, ret);
2643 /* FIXME: NULL disps should be handled in more general way */
2644 if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
2647 return equal_values(ctx, &v, rval, ei, ret);
2650 if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
2653 return equal_values(ctx, lval, &v, ei, ret);
2656 if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
2657 (V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
2662 if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
2666 hres = to_number(ctx->parser->script, lval, ei, &v);
2670 return equal_values(ctx, &v, rval, ei, ret);
2673 if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
2677 hres = to_number(ctx->parser->script, rval, ei, &v);
2681 return equal_values(ctx, lval, &v, ei, ret);
2684 if(V_VT(rval) == VT_BOOL) {
2688 V_I4(&v) = V_BOOL(rval) ? 1 : 0;
2689 return equal_values(ctx, lval, &v, ei, ret);
2692 if(V_VT(lval) == VT_BOOL) {
2696 V_I4(&v) = V_BOOL(lval) ? 1 : 0;
2697 return equal_values(ctx, &v, rval, ei, ret);
2701 if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
2705 hres = to_primitive(ctx->parser->script, rval, ei, &v, NO_HINT);
2709 hres = equal_values(ctx, lval, &v, ei, ret);
2716 if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
2720 hres = to_primitive(ctx->parser->script, lval, ei, &v, NO_HINT);
2724 hres = equal_values(ctx, &v, rval, ei, ret);
2735 /* ECMA-262 3rd Edition 11.9.1 */
2736 HRESULT equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2738 binary_expression_t *expr = (binary_expression_t*)_expr;
2745 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2749 hres = equal_values(ctx, &rval, &lval, ei, &b);
2753 return return_bool(ret, b);
2756 /* ECMA-262 3rd Edition 11.9.4 */
2757 HRESULT equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2759 binary_expression_t *expr = (binary_expression_t*)_expr;
2766 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2770 hres = equal2_values(&rval, &lval, &b);
2774 return return_bool(ret, b);
2777 /* ECMA-262 3rd Edition 11.9.2 */
2778 HRESULT not_equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2780 binary_expression_t *expr = (binary_expression_t*)_expr;
2787 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2791 hres = equal_values(ctx, &lval, &rval, ei, &b);
2795 return return_bool(ret, !b);
2798 /* ECMA-262 3rd Edition 11.9.5 */
2799 HRESULT not_equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2801 binary_expression_t *expr = (binary_expression_t*)_expr;
2808 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2812 hres = equal2_values(&lval, &rval, &b);
2816 return return_bool(ret, !b);
2819 /* ECMA-262 3rd Edition 11.8.5 */
2820 static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
2822 VARIANT l, r, ln, rn;
2825 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
2829 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
2835 if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
2836 *ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
2837 SysFreeString(V_BSTR(&l));
2838 SysFreeString(V_BSTR(&r));
2842 hres = to_number(ctx->parser->script, &l, ei, &ln);
2845 hres = to_number(ctx->parser->script, &r, ei, &rn);
2850 if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
2851 *ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
2853 DOUBLE ld = num_val(&ln);
2854 DOUBLE rd = num_val(&rn);
2856 *ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
2862 /* ECMA-262 3rd Edition 11.8.1 */
2863 HRESULT less_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2865 binary_expression_t *expr = (binary_expression_t*)_expr;
2872 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2876 hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
2877 VariantClear(&lval);
2878 VariantClear(&rval);
2882 return return_bool(ret, b);
2885 /* ECMA-262 3rd Edition 11.8.3 */
2886 HRESULT lesseq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2888 binary_expression_t *expr = (binary_expression_t*)_expr;
2895 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2899 hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
2900 VariantClear(&lval);
2901 VariantClear(&rval);
2905 return return_bool(ret, b);
2908 /* ECMA-262 3rd Edition 11.8.2 */
2909 HRESULT greater_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2911 binary_expression_t *expr = (binary_expression_t*)_expr;
2918 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2922 hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
2923 VariantClear(&lval);
2924 VariantClear(&rval);
2928 return return_bool(ret, b);
2931 /* ECMA-262 3rd Edition 11.8.4 */
2932 HRESULT greatereq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2934 binary_expression_t *expr = (binary_expression_t*)_expr;
2941 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2945 hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
2946 VariantClear(&lval);
2947 VariantClear(&rval);
2951 return return_bool(ret, b);
2954 /* ECMA-262 3rd Edition 11.4.8 */
2955 HRESULT binary_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2957 unary_expression_t *expr = (unary_expression_t*)_expr;
2965 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2969 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2970 exprval_release(&exprval);
2974 hres = to_int32(ctx->parser->script, &val, ei, &i);
2978 ret->type = EXPRVAL_VARIANT;
2979 V_VT(&ret->u.var) = VT_I4;
2980 V_I4(&ret->u.var) = ~i;
2984 /* ECMA-262 3rd Edition 11.4.9 */
2985 HRESULT logical_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2987 unary_expression_t *expr = (unary_expression_t*)_expr;
2994 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2998 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
2999 exprval_release(&exprval);
3003 return return_bool(ret, !b);
3006 /* ECMA-262 3rd Edition 11.7.1 */
3007 static HRESULT lshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3013 hres = to_int32(ctx->parser->script, lval, ei, &li);
3017 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3022 V_I4(retv) = li << (ri&0x1f);
3026 /* ECMA-262 3rd Edition 11.7.1 */
3027 HRESULT left_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3029 binary_expression_t *expr = (binary_expression_t*)_expr;
3033 return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
3036 /* ECMA-262 3rd Edition 11.7.2 */
3037 static HRESULT rshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3043 hres = to_int32(ctx->parser->script, lval, ei, &li);
3047 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3052 V_I4(retv) = li >> (ri&0x1f);
3056 /* ECMA-262 3rd Edition 11.7.2 */
3057 HRESULT right_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3059 binary_expression_t *expr = (binary_expression_t*)_expr;
3063 return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
3066 /* ECMA-262 3rd Edition 11.7.3 */
3067 static HRESULT rshift2_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3072 hres = to_uint32(ctx->parser->script, lval, ei, &li);
3076 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3081 V_I4(retv) = li >> (ri&0x1f);
3085 /* ECMA-262 3rd Edition 11.7.3 */
3086 HRESULT right2_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3088 binary_expression_t *expr = (binary_expression_t*)_expr;
3092 return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
3095 /* ECMA-262 3rd Edition 11.13.1 */
3096 HRESULT assign_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3098 binary_expression_t *expr = (binary_expression_t*)_expr;
3099 exprval_t exprval, exprvalr;
3105 hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
3109 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
3110 if(SUCCEEDED(hres)) {
3111 hres = exprval_to_value(ctx->parser->script, &exprvalr, ei, &rval);
3112 exprval_release(&exprvalr);
3116 hres = put_value(ctx->parser->script, &exprval, &rval, ei);
3118 exprval_release(&exprval);
3122 ret->type = EXPRVAL_VARIANT;
3127 /* ECMA-262 3rd Edition 11.13.2 */
3128 HRESULT assign_lshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3130 binary_expression_t *expr = (binary_expression_t*)_expr;
3134 return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
3137 /* ECMA-262 3rd Edition 11.13.2 */
3138 HRESULT assign_rshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3140 binary_expression_t *expr = (binary_expression_t*)_expr;
3144 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift_eval, ei, ret);
3147 /* ECMA-262 3rd Edition 11.13.2 */
3148 HRESULT assign_rrshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3150 binary_expression_t *expr = (binary_expression_t*)_expr;
3154 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift2_eval, ei, ret);
3157 /* ECMA-262 3rd Edition 11.13.2 */
3158 HRESULT assign_add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3160 binary_expression_t *expr = (binary_expression_t*)_expr;
3164 return assign_oper_eval(ctx, expr->expression1, expr->expression2, add_eval, ei, ret);
3167 /* ECMA-262 3rd Edition 11.13.2 */
3168 HRESULT assign_sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3170 binary_expression_t *expr = (binary_expression_t*)_expr;
3174 return assign_oper_eval(ctx, expr->expression1, expr->expression2, sub_eval, ei, ret);
3177 /* ECMA-262 3rd Edition 11.13.2 */
3178 HRESULT assign_mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3180 binary_expression_t *expr = (binary_expression_t*)_expr;
3184 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mul_eval, ei, ret);
3187 /* ECMA-262 3rd Edition 11.13.2 */
3188 HRESULT assign_div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3190 binary_expression_t *expr = (binary_expression_t*)_expr;
3194 return assign_oper_eval(ctx, expr->expression1, expr->expression2, div_eval, ei, ret);
3197 /* ECMA-262 3rd Edition 11.13.2 */
3198 HRESULT assign_mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3200 binary_expression_t *expr = (binary_expression_t*)_expr;
3204 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mod_eval, ei, ret);
3207 /* ECMA-262 3rd Edition 11.13.2 */
3208 HRESULT assign_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3210 binary_expression_t *expr = (binary_expression_t*)_expr;
3214 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitand_eval, ei, ret);
3217 /* ECMA-262 3rd Edition 11.13.2 */
3218 HRESULT assign_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3220 binary_expression_t *expr = (binary_expression_t*)_expr;
3224 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitor_eval, ei, ret);
3227 /* ECMA-262 3rd Edition 11.13.2 */
3228 HRESULT assign_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3230 binary_expression_t *expr = (binary_expression_t*)_expr;
3234 return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);