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(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(ctx, ref->u.idref.disp, ref->u.idref.id, 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, &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, &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, &ex, &rt->ei, NULL/*FIXME*/);
1167 if(SUCCEEDED(hres)) {
1168 hres = scope_push(ctx->scope_chain, var_disp, &ctx->scope_chain);
1169 if(SUCCEEDED(hres)) {
1170 hres = stat_eval(ctx, block->statement, rt, &val);
1171 scope_pop(&ctx->scope_chain);
1175 jsdisp_release(var_disp);
1186 /* ECMA-262 3rd Edition 12.14 */
1187 HRESULT try_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1189 try_statement_t *stat = (try_statement_t*)_stat;
1195 hres = stat_eval(ctx, stat->try_statement, rt, &val);
1197 TRACE("EXCEPTION\n");
1198 if(!stat->catch_block)
1201 hres = catch_eval(ctx, stat->catch_block, rt, &val);
1206 if(stat->finally_statement) {
1208 hres = stat_eval(ctx, stat->finally_statement, rt, &val);
1217 static HRESULT return_bool(exprval_t *ret, DWORD b)
1219 ret->type = EXPRVAL_VARIANT;
1220 V_VT(&ret->u.var) = VT_BOOL;
1221 V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;
1226 static HRESULT get_binary_expr_values(exec_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
1231 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1235 hres = exprval_to_value(ctx->parser->script, &exprval, ei, lval);
1236 exprval_release(&exprval);
1240 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1241 if(SUCCEEDED(hres)) {
1242 hres = exprval_to_value(ctx->parser->script, &exprval, ei, rval);
1243 exprval_release(&exprval);
1254 typedef HRESULT (*oper_t)(exec_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);
1256 static HRESULT binary_expr_eval(exec_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
1259 VARIANT lval, rval, retv;
1262 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1266 hres = oper(ctx, &lval, &rval, ei, &retv);
1267 VariantClear(&lval);
1268 VariantClear(&rval);
1272 ret->type = EXPRVAL_VARIANT;
1277 /* ECMA-262 3rd Edition 11.13.2 */
1278 static HRESULT assign_oper_eval(exec_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
1279 jsexcept_t *ei, exprval_t *ret)
1281 VARIANT retv, lval, rval;
1282 exprval_t exprval, exprvalr;
1285 hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
1289 hres = exprval_value(ctx->parser->script, &exprval, ei, &lval);
1290 if(SUCCEEDED(hres)) {
1291 hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
1292 if(SUCCEEDED(hres)) {
1293 hres = exprval_value(ctx->parser->script, &exprvalr, ei, &rval);
1294 exprval_release(&exprvalr);
1296 if(SUCCEEDED(hres)) {
1297 hres = oper(ctx, &lval, &rval, ei, &retv);
1298 VariantClear(&rval);
1300 VariantClear(&lval);
1303 if(SUCCEEDED(hres)) {
1304 hres = put_value(ctx->parser->script, &exprval, &retv, ei);
1306 VariantClear(&retv);
1308 exprval_release(&exprval);
1313 ret->type = EXPRVAL_VARIANT;
1318 /* ECMA-262 3rd Edition 13 */
1319 HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1321 function_expression_t *expr = (function_expression_t*)_expr;
1327 if(expr->identifier) {
1328 hres = jsdisp_propget_name(ctx->var_disp, expr->identifier, &var, ei, NULL/*FIXME*/);
1334 hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain,
1335 expr->src_str, expr->src_len, &dispex);
1339 V_VT(&var) = VT_DISPATCH;
1340 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
1343 ret->type = EXPRVAL_VARIANT;
1348 /* ECMA-262 3rd Edition 11.12 */
1349 HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1351 conditional_expression_t *expr = (conditional_expression_t*)_expr;
1358 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1362 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
1363 exprval_release(&exprval);
1367 return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
1370 /* ECMA-262 3rd Edition 11.2.1 */
1371 HRESULT array_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1373 array_expression_t *expr = (array_expression_t*)_expr;
1375 VARIANT member, val;
1378 IDispatch *obj = NULL;
1383 hres = expr_eval(ctx, expr->member_expr, EXPR_NEWREF, ei, &exprval);
1387 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1388 exprval_release(&exprval);
1392 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
1393 if(SUCCEEDED(hres)) {
1394 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1395 exprval_release(&exprval);
1399 hres = to_object(ctx->parser->script, &member, &obj);
1400 VariantClear(&member);
1401 if(SUCCEEDED(hres)) {
1402 hres = to_string(ctx->parser->script, &val, ei, &str);
1403 if(SUCCEEDED(hres)) {
1404 if(flags & EXPR_STRREF) {
1405 ret->type = EXPRVAL_NAMEREF;
1406 ret->u.nameref.disp = obj;
1407 ret->u.nameref.name = str;
1411 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1414 if(SUCCEEDED(hres)) {
1415 exprval_set_idref(ret, obj, id);
1416 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1421 IDispatch_Release(obj);
1427 /* ECMA-262 3rd Edition 11.2.1 */
1428 HRESULT member_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1430 member_expression_t *expr = (member_expression_t*)_expr;
1431 IDispatch *obj = NULL;
1440 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1444 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1445 exprval_release(&exprval);
1449 hres = to_object(ctx->parser->script, &member, &obj);
1450 VariantClear(&member);
1454 str = SysAllocString(expr->identifier);
1455 if(flags & EXPR_STRREF) {
1456 ret->type = EXPRVAL_NAMEREF;
1457 ret->u.nameref.disp = obj;
1458 ret->u.nameref.name = str;
1462 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1464 if(SUCCEEDED(hres)) {
1465 exprval_set_idref(ret, obj, id);
1466 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1471 IDispatch_Release(obj);
1475 static void free_dp(DISPPARAMS *dp)
1479 for(i=0; i < dp->cArgs; i++)
1480 VariantClear(dp->rgvarg+i);
1481 heap_free(dp->rgvarg);
1484 static HRESULT args_to_param(exec_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
1490 HRESULT hres = S_OK;
1492 memset(dp, 0, sizeof(*dp));
1496 for(iter = args; iter; iter = iter->next)
1499 vargs = heap_alloc_zero(cnt * sizeof(*vargs));
1501 return E_OUTOFMEMORY;
1503 for(i = cnt, iter = args; iter; iter = iter->next) {
1504 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
1508 hres = exprval_to_value(ctx->parser->script, &exprval, ei, vargs + (--i));
1509 exprval_release(&exprval);
1524 /* ECMA-262 3rd Edition 11.2.2 */
1525 HRESULT new_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1527 call_expression_t *expr = (call_expression_t*)_expr;
1529 VARIANT constr, var;
1535 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1539 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1541 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &constr);
1542 exprval_release(&exprval);
1546 if(V_VT(&constr) != VT_DISPATCH) {
1547 FIXME("throw TypeError\n");
1548 VariantClear(&constr);
1552 hres = disp_call(ctx->parser->script, V_DISPATCH(&constr), DISPID_VALUE,
1553 DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
1554 IDispatch_Release(V_DISPATCH(&constr));
1558 ret->type = EXPRVAL_VARIANT;
1563 /* ECMA-262 3rd Edition 11.2.3 */
1564 HRESULT call_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1566 call_expression_t *expr = (call_expression_t*)_expr;
1574 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1578 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1579 if(SUCCEEDED(hres)) {
1580 switch(exprval.type) {
1581 case EXPRVAL_VARIANT:
1582 if(V_VT(&exprval.u.var) == VT_DISPATCH)
1583 hres = disp_call(ctx->parser->script, V_DISPATCH(&exprval.u.var), DISPID_VALUE,
1584 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1586 hres = throw_type_error(ctx->parser->script, ei, IDS_NO_PROPERTY, NULL);
1589 hres = disp_call(ctx->parser->script, exprval.u.idref.disp, exprval.u.idref.id,
1590 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1592 case EXPRVAL_INVALID:
1593 hres = throw_type_error(ctx->parser->script, ei, IDS_OBJECT_EXPECTED, NULL);
1596 FIXME("unimplemented type %d\n", exprval.type);
1603 exprval_release(&exprval);
1607 ret->type = EXPRVAL_VARIANT;
1608 if(flags & EXPR_NOVAL) {
1609 V_VT(&ret->u.var) = VT_EMPTY;
1611 TRACE("= %s\n", debugstr_variant(&var));
1617 /* ECMA-262 3rd Edition 11.1.1 */
1618 HRESULT this_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1622 ret->type = EXPRVAL_VARIANT;
1623 V_VT(&ret->u.var) = VT_DISPATCH;
1624 V_DISPATCH(&ret->u.var) = ctx->this_obj;
1625 IDispatch_AddRef(ctx->this_obj);
1629 /* ECMA-262 3rd Edition 10.1.4 */
1630 HRESULT identifier_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1632 identifier_expression_t *expr = (identifier_expression_t*)_expr;
1638 identifier = SysAllocString(expr->identifier);
1640 return E_OUTOFMEMORY;
1642 hres = identifier_eval(ctx, identifier, flags, ei, ret);
1644 SysFreeString(identifier);
1648 /* ECMA-262 3rd Edition 7.8 */
1649 HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1651 literal_expression_t *expr = (literal_expression_t*)_expr;
1657 hres = literal_to_var(expr->literal, &var);
1661 ret->type = EXPRVAL_VARIANT;
1666 /* ECMA-262 3rd Edition 11.1.4 */
1667 HRESULT array_literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1669 array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
1670 DWORD length = 0, i = 0;
1671 array_element_t *elem;
1679 for(elem = expr->element_list; elem; elem = elem->next)
1680 length += elem->elision+1;
1681 length += expr->length;
1683 hres = create_array(ctx->parser->script, length, &array);
1687 for(elem = expr->element_list; elem; elem = elem->next) {
1690 hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
1694 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1695 exprval_release(&exprval);
1699 hres = jsdisp_propput_idx(array, i, &val, ei, NULL/*FIXME*/);
1708 jsdisp_release(array);
1712 ret->type = EXPRVAL_VARIANT;
1713 V_VT(&ret->u.var) = VT_DISPATCH;
1714 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(array);
1718 /* ECMA-262 3rd Edition 11.1.5 */
1719 HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1721 property_value_expression_t *expr = (property_value_expression_t*)_expr;
1731 hres = create_object(ctx->parser->script, NULL, &obj);
1735 for(iter = expr->property_list; iter; iter = iter->next) {
1736 hres = literal_to_var(iter->name, &tmp);
1740 hres = to_string(ctx->parser->script, &tmp, ei, &name);
1745 hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
1746 if(SUCCEEDED(hres)) {
1747 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1748 exprval_release(&exprval);
1749 if(SUCCEEDED(hres)) {
1750 hres = jsdisp_propput_name(obj, name, &val, ei, NULL/*FIXME*/);
1755 SysFreeString(name);
1761 jsdisp_release(obj);
1765 ret->type = EXPRVAL_VARIANT;
1766 V_VT(&ret->u.var) = VT_DISPATCH;
1767 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(obj);
1771 /* ECMA-262 3rd Edition 11.14 */
1772 HRESULT comma_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1774 binary_expression_t *expr = (binary_expression_t*)_expr;
1780 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1784 VariantClear(&lval);
1786 ret->type = EXPRVAL_VARIANT;
1791 /* ECMA-262 3rd Edition 11.11 */
1792 HRESULT logical_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1794 binary_expression_t *expr = (binary_expression_t*)_expr;
1802 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1806 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1807 exprval_release(&exprval);
1811 hres = to_boolean(&val, &b);
1812 if(SUCCEEDED(hres) && b) {
1813 ret->type = EXPRVAL_VARIANT;
1822 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1826 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1827 exprval_release(&exprval);
1831 ret->type = EXPRVAL_VARIANT;
1836 /* ECMA-262 3rd Edition 11.11 */
1837 HRESULT logical_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1839 binary_expression_t *expr = (binary_expression_t*)_expr;
1847 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1851 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1852 exprval_release(&exprval);
1856 hres = to_boolean(&val, &b);
1857 if(SUCCEEDED(hres) && !b) {
1858 ret->type = EXPRVAL_VARIANT;
1867 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1871 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1872 exprval_release(&exprval);
1876 ret->type = EXPRVAL_VARIANT;
1881 /* ECMA-262 3rd Edition 11.10 */
1882 static HRESULT bitor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1887 hres = to_int32(ctx->parser->script, lval, ei, &li);
1891 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1900 /* ECMA-262 3rd Edition 11.10 */
1901 HRESULT binary_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1903 binary_expression_t *expr = (binary_expression_t*)_expr;
1907 return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
1910 /* ECMA-262 3rd Edition 11.10 */
1911 static HRESULT xor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1916 hres = to_int32(ctx->parser->script, lval, ei, &li);
1920 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1929 /* ECMA-262 3rd Edition 11.10 */
1930 HRESULT binary_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1932 binary_expression_t *expr = (binary_expression_t*)_expr;
1936 return binary_expr_eval(ctx, expr, xor_eval, ei, ret);
1939 /* ECMA-262 3rd Edition 11.10 */
1940 static HRESULT bitand_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1945 hres = to_int32(ctx->parser->script, lval, ei, &li);
1949 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1958 /* ECMA-262 3rd Edition 11.10 */
1959 HRESULT binary_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1961 binary_expression_t *expr = (binary_expression_t*)_expr;
1965 return binary_expr_eval(ctx, expr, bitand_eval, ei, ret);
1968 /* ECMA-262 3rd Edition 11.8.6 */
1969 static HRESULT instanceof_eval(exec_ctx_t *ctx, VARIANT *inst, VARIANT *objv, jsexcept_t *ei, VARIANT *retv)
1971 DispatchEx *obj, *iter, *tmp = NULL;
1972 VARIANT_BOOL ret = VARIANT_FALSE;
1977 static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
1979 if(V_VT(objv) != VT_DISPATCH) {
1980 FIXME("throw TypeError\n");
1984 obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(objv));
1986 FIXME("throw TypeError\n");
1990 if(is_class(obj, JSCLASS_FUNCTION)) {
1991 hres = jsdisp_propget_name(obj, prototypeW, &var, ei, NULL/*FIXME*/);
1993 FIXME("throw TypeError\n");
1996 jsdisp_release(obj);
2000 if(V_VT(&var) == VT_DISPATCH) {
2001 if(V_VT(inst) == VT_DISPATCH)
2002 tmp = iface_to_jsdisp((IUnknown*)V_DISPATCH(inst));
2003 for(iter = tmp; iter; iter = iter->prototype) {
2004 hres = disp_cmp(V_DISPATCH(&var), (IDispatch*)_IDispatchEx_(iter), &b);
2014 jsdisp_release(tmp);
2016 FIXME("prototype is not an object\n");
2024 V_VT(retv) = VT_BOOL;
2029 /* ECMA-262 3rd Edition 11.8.6 */
2030 HRESULT instanceof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2032 binary_expression_t *expr = (binary_expression_t*)_expr;
2036 return binary_expr_eval(ctx, expr, instanceof_eval, ei, ret);
2039 /* ECMA-262 3rd Edition 11.8.7 */
2040 static HRESULT in_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *obj, jsexcept_t *ei, VARIANT *retv)
2047 if(V_VT(obj) != VT_DISPATCH) {
2048 FIXME("throw TypeError\n");
2052 hres = to_string(ctx->parser->script, lval, ei, &str);
2056 hres = disp_get_id(V_DISPATCH(obj), str, 0, &id);
2060 else if(hres == DISP_E_UNKNOWNNAME)
2061 ret = VARIANT_FALSE;
2065 V_VT(retv) = VT_BOOL;
2070 /* ECMA-262 3rd Edition 11.8.7 */
2071 HRESULT in_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2073 binary_expression_t *expr = (binary_expression_t*)_expr;
2077 return binary_expr_eval(ctx, expr, in_eval, ei, ret);
2080 /* ECMA-262 3rd Edition 11.6.1 */
2081 static HRESULT add_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2086 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
2090 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
2096 if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
2097 BSTR lstr = NULL, rstr = NULL;
2099 if(V_VT(&l) == VT_BSTR)
2102 hres = to_string(ctx->parser->script, &l, ei, &lstr);
2104 if(SUCCEEDED(hres)) {
2105 if(V_VT(&r) == VT_BSTR)
2108 hres = to_string(ctx->parser->script, &r, ei, &rstr);
2111 if(SUCCEEDED(hres)) {
2114 len1 = SysStringLen(lstr);
2115 len2 = SysStringLen(rstr);
2117 V_VT(retv) = VT_BSTR;
2118 V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
2119 memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
2120 memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
2123 if(V_VT(&l) != VT_BSTR)
2124 SysFreeString(lstr);
2125 if(V_VT(&r) != VT_BSTR)
2126 SysFreeString(rstr);
2130 hres = to_number(ctx->parser->script, &l, ei, &nl);
2131 if(SUCCEEDED(hres)) {
2132 hres = to_number(ctx->parser->script, &r, ei, &nr);
2134 num_set_val(retv, num_val(&nl) + num_val(&nr));
2143 /* ECMA-262 3rd Edition 11.6.1 */
2144 HRESULT add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2146 binary_expression_t *expr = (binary_expression_t*)_expr;
2150 return binary_expr_eval(ctx, expr, add_eval, ei, ret);
2153 /* ECMA-262 3rd Edition 11.6.2 */
2154 static HRESULT sub_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2159 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2163 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2167 num_set_val(retv, num_val(&lnum) - num_val(&rnum));
2171 /* ECMA-262 3rd Edition 11.6.2 */
2172 HRESULT sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2174 binary_expression_t *expr = (binary_expression_t*)_expr;
2178 return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
2181 /* ECMA-262 3rd Edition 11.5.1 */
2182 static HRESULT mul_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2187 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2191 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2195 num_set_val(retv, num_val(&lnum) * num_val(&rnum));
2199 /* ECMA-262 3rd Edition 11.5.1 */
2200 HRESULT mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2202 binary_expression_t *expr = (binary_expression_t*)_expr;
2206 return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
2209 /* ECMA-262 3rd Edition 11.5.2 */
2210 static HRESULT div_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2215 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2219 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2223 num_set_val(retv, num_val(&lnum) / num_val(&rnum));
2227 /* ECMA-262 3rd Edition 11.5.2 */
2228 HRESULT div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2230 binary_expression_t *expr = (binary_expression_t*)_expr;
2234 return binary_expr_eval(ctx, expr, div_eval, ei, ret);
2237 /* ECMA-262 3rd Edition 11.5.3 */
2238 static HRESULT mod_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2243 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2247 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2251 num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
2255 /* ECMA-262 3rd Edition 11.5.3 */
2256 HRESULT mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2258 binary_expression_t *expr = (binary_expression_t*)_expr;
2262 return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
2265 /* ECMA-262 3rd Edition 11.4.2 */
2266 HRESULT delete_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2268 unary_expression_t *expr = (unary_expression_t*)_expr;
2269 VARIANT_BOOL b = VARIANT_FALSE;
2275 hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
2279 switch(exprval.type) {
2280 case EXPRVAL_IDREF: {
2281 IDispatchEx *dispex;
2283 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2284 if(SUCCEEDED(hres)) {
2285 hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
2287 IDispatchEx_Release(dispex);
2291 case EXPRVAL_NAMEREF: {
2292 IDispatchEx *dispex;
2294 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2295 if(SUCCEEDED(hres)) {
2296 hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name, fdexNameCaseSensitive);
2298 IDispatchEx_Release(dispex);
2303 FIXME("unsupported type %d\n", exprval.type);
2307 exprval_release(&exprval);
2311 return return_bool(ret, b);
2314 /* ECMA-262 3rd Edition 11.4.2 */
2315 HRESULT void_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2317 unary_expression_t *expr = (unary_expression_t*)_expr;
2324 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2328 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &tmp);
2329 exprval_release(&exprval);
2335 ret->type = EXPRVAL_VARIANT;
2336 V_VT(&ret->u.var) = VT_EMPTY;
2340 /* ECMA-262 3rd Edition 11.4.3 */
2341 static HRESULT typeof_exprval(exec_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, const WCHAR **ret)
2346 static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
2347 static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
2348 static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
2349 static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
2350 static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
2351 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
2353 if(exprval->type == EXPRVAL_INVALID) {
2358 hres = exprval_to_value(ctx->parser->script, exprval, ei, &val);
2362 switch(V_VT(&val)) {
2382 if(V_DISPATCH(&val) && (dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val)))) {
2383 *ret = is_class(dispex, JSCLASS_FUNCTION) ? functionW : objectW;
2384 jsdisp_release(dispex);
2391 FIXME("unhandled vt %d\n", V_VT(&val));
2399 HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2401 unary_expression_t *expr = (unary_expression_t*)_expr;
2402 const WCHAR *str = NULL;
2408 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2412 hres = typeof_exprval(ctx, &exprval, ei, &str);
2413 exprval_release(&exprval);
2417 ret->type = EXPRVAL_VARIANT;
2418 V_VT(&ret->u.var) = VT_BSTR;
2419 V_BSTR(&ret->u.var) = SysAllocString(str);
2420 if(!V_BSTR(&ret->u.var))
2421 return E_OUTOFMEMORY;
2426 /* ECMA-262 3rd Edition 11.4.7 */
2427 HRESULT minus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2429 unary_expression_t *expr = (unary_expression_t*)_expr;
2436 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2440 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2441 exprval_release(&exprval);
2445 hres = to_number(ctx->parser->script, &val, ei, &num);
2450 ret->type = EXPRVAL_VARIANT;
2451 num_set_val(&ret->u.var, -num_val(&num));
2455 /* ECMA-262 3rd Edition 11.4.6 */
2456 HRESULT plus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2458 unary_expression_t *expr = (unary_expression_t*)_expr;
2465 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2469 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2470 exprval_release(&exprval);
2474 hres = to_number(ctx->parser->script, &val, ei, &num);
2478 ret->type = EXPRVAL_VARIANT;
2483 /* ECMA-262 3rd Edition 11.3.1 */
2484 HRESULT post_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2486 unary_expression_t *expr = (unary_expression_t*)_expr;
2493 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2497 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2498 if(SUCCEEDED(hres)) {
2499 hres = to_number(ctx->parser->script, &val, ei, &num);
2503 if(SUCCEEDED(hres)) {
2505 num_set_val(&inc, num_val(&num)+1.0);
2506 hres = put_value(ctx->parser->script, &exprval, &inc, ei);
2509 exprval_release(&exprval);
2513 ret->type = EXPRVAL_VARIANT;
2518 /* ECMA-262 3rd Edition 11.3.2 */
2519 HRESULT post_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2521 unary_expression_t *expr = (unary_expression_t*)_expr;
2528 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2532 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2533 if(SUCCEEDED(hres)) {
2534 hres = to_number(ctx->parser->script, &val, ei, &num);
2538 if(SUCCEEDED(hres)) {
2540 num_set_val(&dec, num_val(&num)-1.0);
2541 hres = put_value(ctx->parser->script, &exprval, &dec, ei);
2544 exprval_release(&exprval);
2548 ret->type = EXPRVAL_VARIANT;
2553 /* ECMA-262 3rd Edition 11.4.4 */
2554 HRESULT pre_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2556 unary_expression_t *expr = (unary_expression_t*)_expr;
2563 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2567 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2568 if(SUCCEEDED(hres)) {
2569 hres = to_number(ctx->parser->script, &val, ei, &num);
2573 if(SUCCEEDED(hres)) {
2574 num_set_val(&val, num_val(&num)+1.0);
2575 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2578 exprval_release(&exprval);
2582 ret->type = EXPRVAL_VARIANT;
2587 /* ECMA-262 3rd Edition 11.4.5 */
2588 HRESULT pre_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2590 unary_expression_t *expr = (unary_expression_t*)_expr;
2597 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2601 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2602 if(SUCCEEDED(hres)) {
2603 hres = to_number(ctx->parser->script, &val, ei, &num);
2607 if(SUCCEEDED(hres)) {
2608 num_set_val(&val, num_val(&num)-1.0);
2609 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2612 exprval_release(&exprval);
2616 ret->type = EXPRVAL_VARIANT;
2621 /* ECMA-262 3rd Edition 11.9.3 */
2622 static HRESULT equal_values(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
2624 if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
2625 return equal2_values(lval, rval, ret);
2627 /* FIXME: NULL disps should be handled in more general way */
2628 if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
2631 return equal_values(ctx, &v, rval, ei, ret);
2634 if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
2637 return equal_values(ctx, lval, &v, ei, ret);
2640 if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
2641 (V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
2646 if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
2650 hres = to_number(ctx->parser->script, lval, ei, &v);
2654 return equal_values(ctx, &v, rval, ei, ret);
2657 if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
2661 hres = to_number(ctx->parser->script, rval, ei, &v);
2665 return equal_values(ctx, lval, &v, ei, ret);
2668 if(V_VT(rval) == VT_BOOL) {
2672 V_I4(&v) = V_BOOL(rval) ? 1 : 0;
2673 return equal_values(ctx, lval, &v, ei, ret);
2676 if(V_VT(lval) == VT_BOOL) {
2680 V_I4(&v) = V_BOOL(lval) ? 1 : 0;
2681 return equal_values(ctx, &v, rval, ei, ret);
2685 if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
2689 hres = to_primitive(ctx->parser->script, rval, ei, &v, NO_HINT);
2693 hres = equal_values(ctx, lval, &v, ei, ret);
2700 if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
2704 hres = to_primitive(ctx->parser->script, lval, ei, &v, NO_HINT);
2708 hres = equal_values(ctx, &v, rval, ei, ret);
2719 /* ECMA-262 3rd Edition 11.9.1 */
2720 HRESULT equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2722 binary_expression_t *expr = (binary_expression_t*)_expr;
2729 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2733 hres = equal_values(ctx, &rval, &lval, ei, &b);
2737 return return_bool(ret, b);
2740 /* ECMA-262 3rd Edition 11.9.4 */
2741 HRESULT equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2743 binary_expression_t *expr = (binary_expression_t*)_expr;
2750 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2754 hres = equal2_values(&rval, &lval, &b);
2758 return return_bool(ret, b);
2761 /* ECMA-262 3rd Edition 11.9.2 */
2762 HRESULT not_equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2764 binary_expression_t *expr = (binary_expression_t*)_expr;
2771 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2775 hres = equal_values(ctx, &lval, &rval, ei, &b);
2779 return return_bool(ret, !b);
2782 /* ECMA-262 3rd Edition 11.9.5 */
2783 HRESULT not_equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2785 binary_expression_t *expr = (binary_expression_t*)_expr;
2792 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2796 hres = equal2_values(&lval, &rval, &b);
2800 return return_bool(ret, !b);
2803 /* ECMA-262 3rd Edition 11.8.5 */
2804 static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
2806 VARIANT l, r, ln, rn;
2809 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
2813 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
2819 if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
2820 *ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
2821 SysFreeString(V_BSTR(&l));
2822 SysFreeString(V_BSTR(&r));
2826 hres = to_number(ctx->parser->script, &l, ei, &ln);
2829 hres = to_number(ctx->parser->script, &r, ei, &rn);
2834 if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
2835 *ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
2837 DOUBLE ld = num_val(&ln);
2838 DOUBLE rd = num_val(&rn);
2840 *ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
2846 /* ECMA-262 3rd Edition 11.8.1 */
2847 HRESULT less_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2849 binary_expression_t *expr = (binary_expression_t*)_expr;
2856 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2860 hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
2861 VariantClear(&lval);
2862 VariantClear(&rval);
2866 return return_bool(ret, b);
2869 /* ECMA-262 3rd Edition 11.8.3 */
2870 HRESULT lesseq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2872 binary_expression_t *expr = (binary_expression_t*)_expr;
2879 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2883 hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
2884 VariantClear(&lval);
2885 VariantClear(&rval);
2889 return return_bool(ret, b);
2892 /* ECMA-262 3rd Edition 11.8.2 */
2893 HRESULT greater_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2895 binary_expression_t *expr = (binary_expression_t*)_expr;
2902 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2906 hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
2907 VariantClear(&lval);
2908 VariantClear(&rval);
2912 return return_bool(ret, b);
2915 /* ECMA-262 3rd Edition 11.8.4 */
2916 HRESULT greatereq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2918 binary_expression_t *expr = (binary_expression_t*)_expr;
2925 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2929 hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
2930 VariantClear(&lval);
2931 VariantClear(&rval);
2935 return return_bool(ret, b);
2938 /* ECMA-262 3rd Edition 11.4.8 */
2939 HRESULT binary_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2941 unary_expression_t *expr = (unary_expression_t*)_expr;
2949 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2953 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2954 exprval_release(&exprval);
2958 hres = to_int32(ctx->parser->script, &val, ei, &i);
2962 ret->type = EXPRVAL_VARIANT;
2963 V_VT(&ret->u.var) = VT_I4;
2964 V_I4(&ret->u.var) = ~i;
2968 /* ECMA-262 3rd Edition 11.4.9 */
2969 HRESULT logical_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2971 unary_expression_t *expr = (unary_expression_t*)_expr;
2978 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2982 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
2983 exprval_release(&exprval);
2987 return return_bool(ret, !b);
2990 /* ECMA-262 3rd Edition 11.7.1 */
2991 static HRESULT lshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2997 hres = to_int32(ctx->parser->script, lval, ei, &li);
3001 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3006 V_I4(retv) = li << (ri&0x1f);
3010 /* ECMA-262 3rd Edition 11.7.1 */
3011 HRESULT left_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3013 binary_expression_t *expr = (binary_expression_t*)_expr;
3017 return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
3020 /* ECMA-262 3rd Edition 11.7.2 */
3021 static HRESULT rshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3027 hres = to_int32(ctx->parser->script, lval, ei, &li);
3031 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3036 V_I4(retv) = li >> (ri&0x1f);
3040 /* ECMA-262 3rd Edition 11.7.2 */
3041 HRESULT right_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3043 binary_expression_t *expr = (binary_expression_t*)_expr;
3047 return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
3050 /* ECMA-262 3rd Edition 11.7.3 */
3051 static HRESULT rshift2_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3056 hres = to_uint32(ctx->parser->script, lval, ei, &li);
3060 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3065 V_I4(retv) = li >> (ri&0x1f);
3069 /* ECMA-262 3rd Edition 11.7.3 */
3070 HRESULT right2_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3072 binary_expression_t *expr = (binary_expression_t*)_expr;
3076 return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
3079 /* ECMA-262 3rd Edition 11.13.1 */
3080 HRESULT assign_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3082 binary_expression_t *expr = (binary_expression_t*)_expr;
3083 exprval_t exprval, exprvalr;
3089 hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
3093 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
3094 if(SUCCEEDED(hres)) {
3095 hres = exprval_to_value(ctx->parser->script, &exprvalr, ei, &rval);
3096 exprval_release(&exprvalr);
3100 hres = put_value(ctx->parser->script, &exprval, &rval, ei);
3102 exprval_release(&exprval);
3106 ret->type = EXPRVAL_VARIANT;
3111 /* ECMA-262 3rd Edition 11.13.2 */
3112 HRESULT assign_lshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3114 binary_expression_t *expr = (binary_expression_t*)_expr;
3118 return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
3121 /* ECMA-262 3rd Edition 11.13.2 */
3122 HRESULT assign_rshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3124 binary_expression_t *expr = (binary_expression_t*)_expr;
3128 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift_eval, ei, ret);
3131 /* ECMA-262 3rd Edition 11.13.2 */
3132 HRESULT assign_rrshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3134 binary_expression_t *expr = (binary_expression_t*)_expr;
3138 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift2_eval, ei, ret);
3141 /* ECMA-262 3rd Edition 11.13.2 */
3142 HRESULT assign_add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3144 binary_expression_t *expr = (binary_expression_t*)_expr;
3148 return assign_oper_eval(ctx, expr->expression1, expr->expression2, add_eval, ei, ret);
3151 /* ECMA-262 3rd Edition 11.13.2 */
3152 HRESULT assign_sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3154 binary_expression_t *expr = (binary_expression_t*)_expr;
3158 return assign_oper_eval(ctx, expr->expression1, expr->expression2, sub_eval, ei, ret);
3161 /* ECMA-262 3rd Edition 11.13.2 */
3162 HRESULT assign_mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3164 binary_expression_t *expr = (binary_expression_t*)_expr;
3168 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mul_eval, ei, ret);
3171 /* ECMA-262 3rd Edition 11.13.2 */
3172 HRESULT assign_div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3174 binary_expression_t *expr = (binary_expression_t*)_expr;
3178 return assign_oper_eval(ctx, expr->expression1, expr->expression2, div_eval, ei, ret);
3181 /* ECMA-262 3rd Edition 11.13.2 */
3182 HRESULT assign_mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3184 binary_expression_t *expr = (binary_expression_t*)_expr;
3188 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mod_eval, ei, ret);
3191 /* ECMA-262 3rd Edition 11.13.2 */
3192 HRESULT assign_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3194 binary_expression_t *expr = (binary_expression_t*)_expr;
3198 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitand_eval, ei, ret);
3201 /* ECMA-262 3rd Edition 11.13.2 */
3202 HRESULT assign_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3204 binary_expression_t *expr = (binary_expression_t*)_expr;
3208 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitor_eval, ei, ret);
3211 /* ECMA-262 3rd Edition 11.13.2 */
3212 HRESULT assign_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3214 binary_expression_t *expr = (binary_expression_t*)_expr;
3218 return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);