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(script_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(script_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, JS_E_UNDEFINED_VARIABLE, 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, jsdisp_t *obj, scope_chain_t **ret)
138 scope_chain_t *new_scope;
140 new_scope = heap_alloc(sizeof(scope_chain_t));
142 return E_OUTOFMEMORY;
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, jsdisp_t *var_disp,
182 scope_chain_t *scope, BOOL is_global, exec_ctx_t **ret)
186 ctx = heap_alloc_zero(sizeof(exec_ctx_t));
188 return E_OUTOFMEMORY;
191 ctx->is_global = is_global;
194 ctx->this_obj = this_obj;
195 else if(script_ctx->host_global)
196 ctx->this_obj = script_ctx->host_global;
198 ctx->this_obj = to_disp(script_ctx->global);
199 IDispatch_AddRef(ctx->this_obj);
201 jsdisp_addref(var_disp);
202 ctx->var_disp = var_disp;
206 ctx->scope_chain = scope;
213 void exec_release(exec_ctx_t *ctx)
219 scope_release(ctx->scope_chain);
221 jsdisp_release(ctx->var_disp);
223 IDispatch_Release(ctx->this_obj);
227 static HRESULT disp_get_id(script_ctx_t *ctx, IDispatch *disp, BSTR name, DWORD flags, DISPID *id)
232 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
234 TRACE("unsing IDispatch\n");
237 return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
241 hres = IDispatchEx_GetDispID(dispex, name, make_grfdex(ctx, flags|fdexNameCaseSensitive), id);
242 IDispatchEx_Release(dispex);
246 /* ECMA-262 3rd Edition 8.7.2 */
247 static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei)
249 if(ref->type != EXPRVAL_IDREF)
250 return throw_reference_error(ctx, ei, JS_E_ILLEGAL_ASSIGN, NULL);
252 return disp_propput(ctx, ref->u.idref.disp, ref->u.idref.id, v, ei, NULL/*FIXME*/);
255 static inline BOOL is_null(const VARIANT *v)
257 return V_VT(v) == VT_NULL || (V_VT(v) == VT_DISPATCH && !V_DISPATCH(v));
260 static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, BOOL *ret)
262 IObjectIdentity *identity;
263 IUnknown *unk1, *unk2;
271 if(!disp1 || !disp2) {
276 hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
280 hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
282 IUnknown_Release(unk1);
289 hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
290 if(SUCCEEDED(hres)) {
291 hres = IObjectIdentity_IsEqualObject(identity, unk2);
292 IObjectIdentity_Release(identity);
299 IUnknown_Release(unk1);
300 IUnknown_Release(unk2);
304 /* ECMA-262 3rd Edition 11.9.6 */
305 static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
309 if(V_VT(lval) != V_VT(rval)) {
310 if(is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval)))
311 *ret = num_val(lval) == num_val(rval);
312 else if(is_null(lval))
313 *ret = is_null(rval);
325 *ret = V_I4(lval) == V_I4(rval);
328 *ret = V_R8(lval) == V_R8(rval);
332 *ret = SysStringLen(V_BSTR(rval))?FALSE:TRUE;
333 else if(!V_BSTR(rval))
334 *ret = SysStringLen(V_BSTR(lval))?FALSE:TRUE;
336 *ret = !strcmpW(V_BSTR(lval), V_BSTR(rval));
339 return disp_cmp(V_DISPATCH(lval), V_DISPATCH(rval), ret);
341 *ret = !V_BOOL(lval) == !V_BOOL(rval);
344 FIXME("unimplemented vt %d\n", V_VT(lval));
351 static HRESULT literal_to_var(script_ctx_t *ctx, literal_t *literal, VARIANT *v)
353 switch(literal->type) {
359 V_I4(v) = literal->u.lval;
363 V_R8(v) = literal->u.dval;
366 BSTR str = SysAllocString(literal->u.wstr);
368 return E_OUTOFMEMORY;
376 V_BOOL(v) = literal->u.bval;
382 hres = create_regexp(ctx, literal->u.regexp.str, literal->u.regexp.str_len,
383 literal->u.regexp.flags, ®exp);
387 var_set_jsdisp(v, regexp);
394 static BOOL lookup_global_members(script_ctx_t *ctx, BSTR identifier, exprval_t *ret)
400 for(item = ctx->named_items; item; item = item->next) {
401 if(item->flags & SCRIPTITEM_GLOBALMEMBERS) {
402 hres = disp_get_id(ctx, item->disp, identifier, 0, &id);
403 if(SUCCEEDED(hres)) {
405 exprval_set_idref(ret, item->disp, id);
414 HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, BOOL from_eval,
415 jsexcept_t *ei, VARIANT *retv)
417 script_ctx_t *script = parser->script;
418 function_declaration_t *func;
419 parser_ctx_t *prev_parser;
423 exec_ctx_t *prev_ctx;
427 for(func = source->functions; func; func = func->next) {
431 hres = create_source_function(parser, func->expr->parameter_list, func->expr->source_elements,
432 ctx->scope_chain, func->expr->src_str, func->expr->src_len, &func_obj);
436 var_set_jsdisp(&var, func_obj);
437 hres = jsdisp_propput_name(ctx->var_disp, func->expr->identifier, &var, ei, NULL);
438 jsdisp_release(func_obj);
443 for(var = source->variables; var; var = var->next) {
447 name = SysAllocString(var->identifier);
449 return E_OUTOFMEMORY;
451 if(!ctx->is_global || !lookup_global_members(parser->script, name, NULL))
452 hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
458 prev_ctx = script->exec_ctx;
459 script->exec_ctx = ctx;
461 prev_parser = ctx->parser;
462 ctx->parser = parser;
464 V_VT(&val) = VT_EMPTY;
465 memset(&rt, 0, sizeof(rt));
468 for(stat = source->statement; stat; stat = stat->next) {
469 hres = stat_eval(script, stat, &rt, &tmp);
475 if(rt.type != RT_NORMAL)
479 script->exec_ctx = prev_ctx;
480 ctx->parser = prev_parser;
482 if(rt.type != RT_NORMAL && rt.type != RT_RETURN) {
483 FIXME("wrong rt %d\n", rt.type);
493 if(!retv || (!from_eval && rt.type != RT_RETURN))
500 /* ECMA-262 3rd Edition 10.1.4 */
501 static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, DWORD flags, jsexcept_t *ei, exprval_t *ret)
503 scope_chain_t *scope;
508 TRACE("%s\n", debugstr_w(identifier));
510 for(scope = ctx->exec_ctx->scope_chain; scope; scope = scope->next) {
511 hres = jsdisp_get_id(scope->obj, identifier, 0, &id);
512 if(SUCCEEDED(hres)) {
513 exprval_set_idref(ret, to_disp(scope->obj), id);
518 hres = jsdisp_get_id(ctx->global, identifier, 0, &id);
519 if(SUCCEEDED(hres)) {
520 exprval_set_idref(ret, to_disp(ctx->global), id);
524 for(item = ctx->named_items; item; item = item->next) {
525 if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpW(item->name, identifier)) {
532 hres = IActiveScriptSite_GetItemInfo(ctx->site, identifier,
533 SCRIPTINFO_IUNKNOWN, &unk, NULL);
535 WARN("GetItemInfo failed: %08x\n", hres);
539 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
540 IUnknown_Release(unk);
542 WARN("object does not implement IDispatch\n");
547 ret->type = EXPRVAL_VARIANT;
548 V_VT(&ret->u.var) = VT_DISPATCH;
549 V_DISPATCH(&ret->u.var) = item->disp;
550 IDispatch_AddRef(item->disp);
555 if(lookup_global_members(ctx, identifier, ret))
558 if(flags & EXPR_NEWREF) {
559 hres = jsdisp_get_id(ctx->global, identifier, fdexNameEnsure, &id);
563 exprval_set_idref(ret, to_disp(ctx->global), id);
567 ret->type = EXPRVAL_INVALID;
568 ret->u.identifier = SysAllocString(identifier);
569 if(!ret->u.identifier)
570 return E_OUTOFMEMORY;
575 /* ECMA-262 3rd Edition 12.1 */
576 HRESULT block_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
578 block_statement_t *stat = (block_statement_t*)_stat;
585 V_VT(&val) = VT_EMPTY;
586 for(iter = stat->stat_list; iter; iter = iter->next) {
587 hres = stat_eval(ctx, iter, rt, &tmp);
593 if(rt->type != RT_NORMAL)
606 /* ECMA-262 3rd Edition 12.2 */
607 static HRESULT variable_list_eval(script_ctx_t *ctx, variable_declaration_t *var_list, jsexcept_t *ei)
609 variable_declaration_t *iter;
612 for(iter = var_list; iter; iter = iter->next) {
619 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
623 hres = exprval_to_value(ctx, &exprval, ei, &val);
624 exprval_release(&exprval);
628 hres = jsdisp_propput_name(ctx->exec_ctx->var_disp, iter->identifier, &val, ei, NULL/*FIXME*/);
637 /* ECMA-262 3rd Edition 12.2 */
638 HRESULT var_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
640 var_statement_t *stat = (var_statement_t*)_stat;
645 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
649 V_VT(ret) = VT_EMPTY;
653 /* ECMA-262 3rd Edition 12.3 */
654 HRESULT empty_statement_eval(script_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
658 V_VT(ret) = VT_EMPTY;
662 /* ECMA-262 3rd Edition 12.4 */
663 HRESULT expression_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
665 expression_statement_t *stat = (expression_statement_t*)_stat;
672 hres = expr_eval(ctx, stat->expr, EXPR_NOVAL, &rt->ei, &exprval);
676 hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
677 exprval_release(&exprval);
682 TRACE("= %s\n", debugstr_variant(ret));
686 /* ECMA-262 3rd Edition 12.5 */
687 HRESULT if_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
689 if_statement_t *stat = (if_statement_t*)_stat;
696 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
700 hres = exprval_to_boolean(ctx, &exprval, &rt->ei, &b);
701 exprval_release(&exprval);
706 hres = stat_eval(ctx, stat->if_stat, rt, ret);
707 else if(stat->else_stat)
708 hres = stat_eval(ctx, stat->else_stat, rt, ret);
710 V_VT(ret) = VT_EMPTY;
715 /* ECMA-262 3rd Edition 12.6.2 */
716 HRESULT while_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
718 while_statement_t *stat = (while_statement_t*)_stat;
727 V_VT(&val) = VT_EMPTY;
728 test_expr = !stat->do_while;
732 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
736 hres = exprval_to_boolean(ctx, &exprval, &rt->ei, &b);
737 exprval_release(&exprval);
738 if(FAILED(hres) || !b)
744 hres = stat_eval(ctx, stat->statement, rt, &tmp);
751 if(rt->type == RT_CONTINUE)
752 rt->type = RT_NORMAL;
753 if(rt->type != RT_NORMAL)
762 if(rt->type == RT_BREAK)
763 rt->type = RT_NORMAL;
769 /* ECMA-262 3rd Edition 12.6.3 */
770 HRESULT for_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
772 for_statement_t *stat = (for_statement_t*)_stat;
773 VARIANT val, tmp, retv;
780 if(stat->variable_list) {
781 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
784 }else if(stat->begin_expr) {
785 hres = expr_eval(ctx, stat->begin_expr, EXPR_NEWREF, &rt->ei, &exprval);
789 hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
790 exprval_release(&exprval);
797 V_VT(&retv) = VT_EMPTY;
801 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
805 hres = exprval_to_boolean(ctx, &exprval, &rt->ei, &b);
806 exprval_release(&exprval);
807 if(FAILED(hres) || !b)
811 hres = stat_eval(ctx, stat->statement, rt, &tmp);
818 if(rt->type == RT_CONTINUE)
819 rt->type = RT_NORMAL;
820 else if(rt->type != RT_NORMAL)
824 hres = expr_eval(ctx, stat->end_expr, 0, &rt->ei, &exprval);
828 hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
829 exprval_release(&exprval);
842 if(rt->type == RT_BREAK)
843 rt->type = RT_NORMAL;
849 /* ECMA-262 3rd Edition 12.6.4 */
850 HRESULT forin_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
852 forin_statement_t *stat = (forin_statement_t*)_stat;
853 VARIANT val, name, retv, tmp;
854 DISPID id = DISPID_STARTENUM;
855 BSTR str, identifier = NULL;
863 hres = variable_list_eval(ctx, stat->variable, &rt->ei);
868 hres = expr_eval(ctx, stat->in_expr, EXPR_NEWREF, &rt->ei, &exprval);
872 hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
873 exprval_release(&exprval);
877 if(V_VT(&val) != VT_DISPATCH) {
878 TRACE("in vt %d\n", V_VT(&val));
880 V_VT(ret) = VT_EMPTY;
884 hres = IDispatch_QueryInterface(V_DISPATCH(&val), &IID_IDispatchEx, (void**)&in_obj);
885 IDispatch_Release(V_DISPATCH(&val));
887 TRACE("Object doesn't support IDispatchEx\n");
888 V_VT(ret) = VT_EMPTY;
892 V_VT(&retv) = VT_EMPTY;
895 identifier = SysAllocString(stat->variable->identifier);
898 hres = IDispatchEx_GetNextDispID(in_obj, fdexEnumDefault, id, &id);
899 if(FAILED(hres) || hres == S_FALSE)
902 hres = IDispatchEx_GetMemberName(in_obj, id, &str);
906 TRACE("iter %s\n", debugstr_w(str));
909 hres = identifier_eval(ctx, identifier, 0, NULL, &exprval);
911 hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval);
912 if(SUCCEEDED(hres)) {
913 V_VT(&name) = VT_BSTR;
915 hres = put_value(ctx, &exprval, &name, &rt->ei);
916 exprval_release(&exprval);
922 hres = stat_eval(ctx, stat->statement, rt, &tmp);
929 if(rt->type == RT_CONTINUE)
930 rt->type = RT_NORMAL;
931 else if(rt->type != RT_NORMAL)
935 SysFreeString(identifier);
936 IDispatchEx_Release(in_obj);
942 if(rt->type == RT_BREAK)
943 rt->type = RT_NORMAL;
949 /* ECMA-262 3rd Edition 12.7 */
950 HRESULT continue_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
952 branch_statement_t *stat = (branch_statement_t*)_stat;
956 if(stat->identifier) {
957 FIXME("indentifier not implemented\n");
961 rt->type = RT_CONTINUE;
962 V_VT(ret) = VT_EMPTY;
966 /* ECMA-262 3rd Edition 12.8 */
967 HRESULT break_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
969 branch_statement_t *stat = (branch_statement_t*)_stat;
973 if(stat->identifier) {
974 FIXME("indentifier not implemented\n");
979 V_VT(ret) = VT_EMPTY;
983 /* ECMA-262 3rd Edition 12.9 */
984 HRESULT return_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
986 expression_statement_t *stat = (expression_statement_t*)_stat;
994 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
998 hres = exprval_to_value(ctx, &exprval, &rt->ei, ret);
999 exprval_release(&exprval);
1003 V_VT(ret) = VT_EMPTY;
1006 TRACE("= %s\n", debugstr_variant(ret));
1007 rt->type = RT_RETURN;
1011 /* ECMA-262 3rd Edition 12.10 */
1012 HRESULT with_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1014 with_statement_t *stat = (with_statement_t*)_stat;
1023 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1027 hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
1028 exprval_release(&exprval);
1032 hres = to_object(ctx, &val, &disp);
1037 obj = iface_to_jsdisp((IUnknown*)disp);
1038 IDispatch_Release(disp);
1040 FIXME("disp id not jsdisp\n");
1044 hres = scope_push(ctx->exec_ctx->scope_chain, obj, &ctx->exec_ctx->scope_chain);
1045 jsdisp_release(obj);
1049 hres = stat_eval(ctx, stat->statement, rt, ret);
1051 scope_pop(&ctx->exec_ctx->scope_chain);
1055 /* ECMA-262 3rd Edition 12.12 */
1056 HRESULT labelled_statement_eval(script_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
1062 /* ECMA-262 3rd Edition 12.13 */
1063 HRESULT switch_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1065 switch_statement_t *stat = (switch_statement_t*)_stat;
1066 case_clausule_t *iter, *default_clausule = NULL;
1067 statement_t *stat_iter;
1075 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1079 hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
1080 exprval_release(&exprval);
1084 for(iter = stat->case_list; iter; iter = iter->next) {
1086 default_clausule = iter;
1090 hres = expr_eval(ctx, iter->expr, 0, &rt->ei, &exprval);
1094 hres = exprval_to_value(ctx, &exprval, &rt->ei, &cval);
1095 exprval_release(&exprval);
1099 hres = equal2_values(&val, &cval, &b);
1100 VariantClear(&cval);
1101 if(FAILED(hres) || b)
1110 iter = default_clausule;
1112 V_VT(&val) = VT_EMPTY;
1116 for(stat_iter = iter->stat; stat_iter; stat_iter = stat_iter->next) {
1117 hres = stat_eval(ctx, stat_iter, rt, &tmp);
1124 if(rt->type != RT_NORMAL)
1134 if(rt->type == RT_BREAK)
1135 rt->type = RT_NORMAL;
1141 /* ECMA-262 3rd Edition 12.13 */
1142 HRESULT throw_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1144 expression_statement_t *stat = (expression_statement_t*)_stat;
1151 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1155 hres = exprval_to_value(ctx, &exprval, &rt->ei, &val);
1156 exprval_release(&exprval);
1161 return DISP_E_EXCEPTION;
1164 /* ECMA-262 3rd Edition 12.14 */
1165 static HRESULT catch_eval(script_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
1172 memset(&rt->ei, 0, sizeof(jsexcept_t));
1174 hres = create_dispex(ctx, NULL, NULL, &var_disp);
1175 if(SUCCEEDED(hres)) {
1176 hres = jsdisp_propput_name(var_disp, block->identifier, &ex, &rt->ei, NULL/*FIXME*/);
1177 if(SUCCEEDED(hres)) {
1178 hres = scope_push(ctx->exec_ctx->scope_chain, var_disp, &ctx->exec_ctx->scope_chain);
1179 if(SUCCEEDED(hres)) {
1180 hres = stat_eval(ctx, block->statement, rt, &val);
1181 scope_pop(&ctx->exec_ctx->scope_chain);
1185 jsdisp_release(var_disp);
1196 /* ECMA-262 3rd Edition 12.14 */
1197 HRESULT try_statement_eval(script_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1199 try_statement_t *stat = (try_statement_t*)_stat;
1205 hres = stat_eval(ctx, stat->try_statement, rt, &val);
1207 TRACE("EXCEPTION\n");
1208 if(!stat->catch_block)
1211 hres = catch_eval(ctx, stat->catch_block, rt, &val);
1216 if(stat->finally_statement) {
1218 hres = stat_eval(ctx, stat->finally_statement, rt, &val);
1227 static HRESULT return_bool(exprval_t *ret, DWORD b)
1229 ret->type = EXPRVAL_VARIANT;
1230 V_VT(&ret->u.var) = VT_BOOL;
1231 V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;
1236 static HRESULT get_binary_expr_values(script_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
1241 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1245 hres = exprval_to_value(ctx, &exprval, ei, lval);
1246 exprval_release(&exprval);
1250 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1251 if(SUCCEEDED(hres)) {
1252 hres = exprval_to_value(ctx, &exprval, ei, rval);
1253 exprval_release(&exprval);
1264 typedef HRESULT (*oper_t)(script_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);
1266 static HRESULT binary_expr_eval(script_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
1269 VARIANT lval, rval, retv;
1272 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1276 hres = oper(ctx, &lval, &rval, ei, &retv);
1277 VariantClear(&lval);
1278 VariantClear(&rval);
1282 ret->type = EXPRVAL_VARIANT;
1287 /* ECMA-262 3rd Edition 11.13.2 */
1288 static HRESULT assign_oper_eval(script_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
1289 jsexcept_t *ei, exprval_t *ret)
1291 VARIANT retv, lval, rval;
1292 exprval_t exprval, exprvalr;
1295 hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
1299 hres = exprval_value(ctx, &exprval, ei, &lval);
1300 if(SUCCEEDED(hres)) {
1301 hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
1302 if(SUCCEEDED(hres)) {
1303 hres = exprval_value(ctx, &exprvalr, ei, &rval);
1304 exprval_release(&exprvalr);
1306 if(SUCCEEDED(hres)) {
1307 hres = oper(ctx, &lval, &rval, ei, &retv);
1308 VariantClear(&rval);
1310 VariantClear(&lval);
1313 if(SUCCEEDED(hres)) {
1314 hres = put_value(ctx, &exprval, &retv, ei);
1316 VariantClear(&retv);
1318 exprval_release(&exprval);
1323 ret->type = EXPRVAL_VARIANT;
1328 /* ECMA-262 3rd Edition 13 */
1329 HRESULT function_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1331 function_expression_t *expr = (function_expression_t*)_expr;
1337 if(expr->identifier) {
1338 hres = jsdisp_propget_name(ctx->exec_ctx->var_disp, expr->identifier, &var, ei, NULL/*FIXME*/);
1344 hres = create_source_function(ctx->exec_ctx->parser, expr->parameter_list, expr->source_elements, ctx->exec_ctx->scope_chain,
1345 expr->src_str, expr->src_len, &dispex);
1349 var_set_jsdisp(&var, dispex);
1352 ret->type = EXPRVAL_VARIANT;
1357 /* ECMA-262 3rd Edition 11.12 */
1358 HRESULT conditional_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1360 conditional_expression_t *expr = (conditional_expression_t*)_expr;
1367 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1371 hres = exprval_to_boolean(ctx, &exprval, ei, &b);
1372 exprval_release(&exprval);
1376 return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
1379 /* ECMA-262 3rd Edition 11.2.1 */
1380 HRESULT array_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1382 array_expression_t *expr = (array_expression_t*)_expr;
1384 VARIANT member, val;
1387 IDispatch *obj = NULL;
1392 hres = expr_eval(ctx, expr->member_expr, 0, ei, &exprval);
1396 hres = exprval_to_value(ctx, &exprval, ei, &member);
1397 exprval_release(&exprval);
1401 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
1402 if(SUCCEEDED(hres)) {
1403 hres = exprval_to_value(ctx, &exprval, ei, &val);
1404 exprval_release(&exprval);
1407 if(SUCCEEDED(hres)) {
1408 hres = to_object(ctx, &member, &obj);
1412 VariantClear(&member);
1413 if(SUCCEEDED(hres)) {
1414 hres = to_string(ctx, &val, ei, &str);
1416 if(SUCCEEDED(hres)) {
1417 if(flags & EXPR_STRREF) {
1418 ret->type = EXPRVAL_NAMEREF;
1419 ret->u.nameref.disp = obj;
1420 ret->u.nameref.name = str;
1424 hres = disp_get_id(ctx, obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1428 if(SUCCEEDED(hres)) {
1429 exprval_set_idref(ret, obj, id);
1430 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1435 IDispatch_Release(obj);
1441 /* ECMA-262 3rd Edition 11.2.1 */
1442 HRESULT member_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1444 member_expression_t *expr = (member_expression_t*)_expr;
1445 IDispatch *obj = NULL;
1454 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1458 hres = exprval_to_value(ctx, &exprval, ei, &member);
1459 exprval_release(&exprval);
1463 hres = to_object(ctx, &member, &obj);
1464 VariantClear(&member);
1468 str = SysAllocString(expr->identifier);
1469 if(flags & EXPR_STRREF) {
1470 ret->type = EXPRVAL_NAMEREF;
1471 ret->u.nameref.disp = obj;
1472 ret->u.nameref.name = str;
1476 hres = disp_get_id(ctx, obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1478 if(SUCCEEDED(hres)) {
1479 exprval_set_idref(ret, obj, id);
1480 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1485 IDispatch_Release(obj);
1489 static void free_dp(DISPPARAMS *dp)
1493 for(i=0; i < dp->cArgs; i++)
1494 VariantClear(dp->rgvarg+i);
1495 heap_free(dp->rgvarg);
1498 static HRESULT args_to_param(script_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
1504 HRESULT hres = S_OK;
1506 memset(dp, 0, sizeof(*dp));
1510 for(iter = args; iter; iter = iter->next)
1513 vargs = heap_alloc_zero(cnt * sizeof(*vargs));
1515 return E_OUTOFMEMORY;
1517 for(i = cnt, iter = args; iter; iter = iter->next) {
1518 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
1522 hres = exprval_to_value(ctx, &exprval, ei, vargs + (--i));
1523 exprval_release(&exprval);
1538 /* ECMA-262 3rd Edition 11.2.2 */
1539 HRESULT new_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1541 call_expression_t *expr = (call_expression_t*)_expr;
1543 VARIANT constr, var;
1549 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1553 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1555 hres = exprval_to_value(ctx, &exprval, ei, &constr);
1556 exprval_release(&exprval);
1560 /* NOTE: Should use to_object here */
1562 if(V_VT(&constr) == VT_NULL) {
1563 VariantClear(&constr);
1564 return throw_type_error(ctx, ei, JS_E_OBJECT_EXPECTED, NULL);
1565 } else if(V_VT(&constr) != VT_DISPATCH) {
1566 VariantClear(&constr);
1567 return throw_type_error(ctx, ei, JS_E_INVALID_ACTION, NULL);
1568 } else if(!V_DISPATCH(&constr)) {
1569 VariantClear(&constr);
1570 return throw_type_error(ctx, ei, JS_E_INVALID_PROPERTY, NULL);
1573 hres = disp_call(ctx, V_DISPATCH(&constr), DISPID_VALUE,
1574 DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
1575 IDispatch_Release(V_DISPATCH(&constr));
1580 ret->type = EXPRVAL_VARIANT;
1585 /* ECMA-262 3rd Edition 11.2.3 */
1586 HRESULT call_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1588 call_expression_t *expr = (call_expression_t*)_expr;
1596 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1600 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1601 if(SUCCEEDED(hres)) {
1602 switch(exprval.type) {
1603 case EXPRVAL_VARIANT:
1604 if(V_VT(&exprval.u.var) == VT_DISPATCH)
1605 hres = disp_call(ctx, V_DISPATCH(&exprval.u.var), DISPID_VALUE,
1606 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1608 hres = throw_type_error(ctx, ei, JS_E_INVALID_PROPERTY, NULL);
1611 hres = disp_call(ctx, exprval.u.idref.disp, exprval.u.idref.id,
1612 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1614 case EXPRVAL_INVALID:
1615 hres = throw_type_error(ctx, ei, JS_E_OBJECT_EXPECTED, NULL);
1618 FIXME("unimplemented type %d\n", exprval.type);
1625 exprval_release(&exprval);
1629 ret->type = EXPRVAL_VARIANT;
1630 if(flags & EXPR_NOVAL) {
1631 V_VT(&ret->u.var) = VT_EMPTY;
1633 TRACE("= %s\n", debugstr_variant(&var));
1639 /* ECMA-262 3rd Edition 11.1.1 */
1640 HRESULT this_expression_eval(script_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1644 ret->type = EXPRVAL_VARIANT;
1645 V_VT(&ret->u.var) = VT_DISPATCH;
1646 V_DISPATCH(&ret->u.var) = ctx->exec_ctx->this_obj;
1647 IDispatch_AddRef(ctx->exec_ctx->this_obj);
1651 /* ECMA-262 3rd Edition 10.1.4 */
1652 HRESULT identifier_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1654 identifier_expression_t *expr = (identifier_expression_t*)_expr;
1660 identifier = SysAllocString(expr->identifier);
1662 return E_OUTOFMEMORY;
1664 hres = identifier_eval(ctx, identifier, flags, ei, ret);
1666 SysFreeString(identifier);
1670 /* ECMA-262 3rd Edition 7.8 */
1671 HRESULT literal_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1673 literal_expression_t *expr = (literal_expression_t*)_expr;
1679 hres = literal_to_var(ctx, expr->literal, &var);
1683 ret->type = EXPRVAL_VARIANT;
1688 /* ECMA-262 3rd Edition 11.1.4 */
1689 HRESULT array_literal_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1691 array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
1692 DWORD length = 0, i = 0;
1693 array_element_t *elem;
1701 for(elem = expr->element_list; elem; elem = elem->next)
1702 length += elem->elision+1;
1703 length += expr->length;
1705 hres = create_array(ctx, length, &array);
1709 for(elem = expr->element_list; elem; elem = elem->next) {
1712 hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
1716 hres = exprval_to_value(ctx, &exprval, ei, &val);
1717 exprval_release(&exprval);
1721 hres = jsdisp_propput_idx(array, i, &val, ei, NULL/*FIXME*/);
1730 jsdisp_release(array);
1734 ret->type = EXPRVAL_VARIANT;
1735 var_set_jsdisp(&ret->u.var, array);
1739 /* ECMA-262 3rd Edition 11.1.5 */
1740 HRESULT property_value_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1742 property_value_expression_t *expr = (property_value_expression_t*)_expr;
1752 hres = create_object(ctx, NULL, &obj);
1756 for(iter = expr->property_list; iter; iter = iter->next) {
1757 hres = literal_to_var(ctx, iter->name, &tmp);
1761 hres = to_string(ctx, &tmp, ei, &name);
1766 hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
1767 if(SUCCEEDED(hres)) {
1768 hres = exprval_to_value(ctx, &exprval, ei, &val);
1769 exprval_release(&exprval);
1770 if(SUCCEEDED(hres)) {
1771 hres = jsdisp_propput_name(obj, name, &val, ei, NULL/*FIXME*/);
1776 SysFreeString(name);
1782 jsdisp_release(obj);
1786 ret->type = EXPRVAL_VARIANT;
1787 var_set_jsdisp(&ret->u.var, obj);
1791 /* ECMA-262 3rd Edition 11.14 */
1792 HRESULT comma_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1794 binary_expression_t *expr = (binary_expression_t*)_expr;
1800 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1804 VariantClear(&lval);
1806 ret->type = EXPRVAL_VARIANT;
1811 /* ECMA-262 3rd Edition 11.11 */
1812 HRESULT logical_or_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1814 binary_expression_t *expr = (binary_expression_t*)_expr;
1822 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1826 hres = exprval_to_value(ctx, &exprval, ei, &val);
1827 exprval_release(&exprval);
1831 hres = to_boolean(&val, &b);
1832 if(SUCCEEDED(hres) && b) {
1833 ret->type = EXPRVAL_VARIANT;
1842 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1846 hres = exprval_to_value(ctx, &exprval, ei, &val);
1847 exprval_release(&exprval);
1851 ret->type = EXPRVAL_VARIANT;
1856 /* ECMA-262 3rd Edition 11.11 */
1857 HRESULT logical_and_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1859 binary_expression_t *expr = (binary_expression_t*)_expr;
1867 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1871 hres = exprval_to_value(ctx, &exprval, ei, &val);
1872 exprval_release(&exprval);
1876 hres = to_boolean(&val, &b);
1877 if(SUCCEEDED(hres) && !b) {
1878 ret->type = EXPRVAL_VARIANT;
1887 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1891 hres = exprval_to_value(ctx, &exprval, ei, &val);
1892 exprval_release(&exprval);
1896 ret->type = EXPRVAL_VARIANT;
1901 /* ECMA-262 3rd Edition 11.10 */
1902 static HRESULT bitor_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1907 hres = to_int32(ctx, lval, ei, &li);
1911 hres = to_int32(ctx, rval, ei, &ri);
1920 /* ECMA-262 3rd Edition 11.10 */
1921 HRESULT binary_or_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1923 binary_expression_t *expr = (binary_expression_t*)_expr;
1927 return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
1930 /* ECMA-262 3rd Edition 11.10 */
1931 static HRESULT xor_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1936 hres = to_int32(ctx, lval, ei, &li);
1940 hres = to_int32(ctx, rval, ei, &ri);
1949 /* ECMA-262 3rd Edition 11.10 */
1950 HRESULT binary_xor_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1952 binary_expression_t *expr = (binary_expression_t*)_expr;
1956 return binary_expr_eval(ctx, expr, xor_eval, ei, ret);
1959 /* ECMA-262 3rd Edition 11.10 */
1960 static HRESULT bitand_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1965 hres = to_int32(ctx, lval, ei, &li);
1969 hres = to_int32(ctx, rval, ei, &ri);
1978 /* ECMA-262 3rd Edition 11.10 */
1979 HRESULT binary_and_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1981 binary_expression_t *expr = (binary_expression_t*)_expr;
1985 return binary_expr_eval(ctx, expr, bitand_eval, ei, ret);
1988 /* ECMA-262 3rd Edition 11.8.6 */
1989 static HRESULT instanceof_eval(script_ctx_t *ctx, VARIANT *inst, VARIANT *objv, jsexcept_t *ei, VARIANT *retv)
1991 jsdisp_t *obj, *iter, *tmp = NULL;
1992 VARIANT_BOOL ret = VARIANT_FALSE;
1997 static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
1999 if(V_VT(objv) != VT_DISPATCH || !V_DISPATCH(objv))
2000 return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL);
2002 obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(objv));
2004 FIXME("throw TypeError\n");
2008 if(is_class(obj, JSCLASS_FUNCTION)) {
2009 hres = jsdisp_propget_name(obj, prototypeW, &var, ei, NULL/*FIXME*/);
2011 FIXME("throw TypeError\n");
2014 jsdisp_release(obj);
2018 if(V_VT(&var) == VT_DISPATCH) {
2019 if(V_VT(inst) == VT_DISPATCH)
2020 tmp = iface_to_jsdisp((IUnknown*)V_DISPATCH(inst));
2021 for(iter = tmp; iter; iter = iter->prototype) {
2022 hres = disp_cmp(V_DISPATCH(&var), to_disp(iter), &b);
2032 jsdisp_release(tmp);
2034 FIXME("prototype is not an object\n");
2042 V_VT(retv) = VT_BOOL;
2047 /* ECMA-262 3rd Edition 11.8.6 */
2048 HRESULT instanceof_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2050 binary_expression_t *expr = (binary_expression_t*)_expr;
2054 return binary_expr_eval(ctx, expr, instanceof_eval, ei, ret);
2057 /* ECMA-262 3rd Edition 11.8.7 */
2058 static HRESULT in_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *obj, jsexcept_t *ei, VARIANT *retv)
2065 if(V_VT(obj) != VT_DISPATCH || !V_DISPATCH(obj))
2066 return throw_type_error(ctx, ei, JS_E_OBJECT_EXPECTED, NULL);
2068 hres = to_string(ctx, lval, ei, &str);
2072 hres = disp_get_id(ctx, V_DISPATCH(obj), str, 0, &id);
2076 else if(hres == DISP_E_UNKNOWNNAME)
2077 ret = VARIANT_FALSE;
2081 V_VT(retv) = VT_BOOL;
2086 /* ECMA-262 3rd Edition 11.8.7 */
2087 HRESULT in_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2089 binary_expression_t *expr = (binary_expression_t*)_expr;
2093 return binary_expr_eval(ctx, expr, in_eval, ei, ret);
2096 /* ECMA-262 3rd Edition 11.6.1 */
2097 static HRESULT add_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2102 hres = to_primitive(ctx, lval, ei, &l, NO_HINT);
2106 hres = to_primitive(ctx, rval, ei, &r, NO_HINT);
2112 if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
2113 BSTR lstr = NULL, rstr = NULL;
2115 if(V_VT(&l) == VT_BSTR)
2118 hres = to_string(ctx, &l, ei, &lstr);
2120 if(SUCCEEDED(hres)) {
2121 if(V_VT(&r) == VT_BSTR)
2124 hres = to_string(ctx, &r, ei, &rstr);
2127 if(SUCCEEDED(hres)) {
2130 len1 = SysStringLen(lstr);
2131 len2 = SysStringLen(rstr);
2133 V_VT(retv) = VT_BSTR;
2134 V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
2135 memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
2136 memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
2139 if(V_VT(&l) != VT_BSTR)
2140 SysFreeString(lstr);
2141 if(V_VT(&r) != VT_BSTR)
2142 SysFreeString(rstr);
2146 hres = to_number(ctx, &l, ei, &nl);
2147 if(SUCCEEDED(hres)) {
2148 hres = to_number(ctx, &r, ei, &nr);
2150 num_set_val(retv, num_val(&nl) + num_val(&nr));
2159 /* ECMA-262 3rd Edition 11.6.1 */
2160 HRESULT add_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2162 binary_expression_t *expr = (binary_expression_t*)_expr;
2166 return binary_expr_eval(ctx, expr, add_eval, ei, ret);
2169 /* ECMA-262 3rd Edition 11.6.2 */
2170 static HRESULT sub_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2175 hres = to_number(ctx, lval, ei, &lnum);
2179 hres = to_number(ctx, rval, ei, &rnum);
2183 num_set_val(retv, num_val(&lnum) - num_val(&rnum));
2187 /* ECMA-262 3rd Edition 11.6.2 */
2188 HRESULT sub_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2190 binary_expression_t *expr = (binary_expression_t*)_expr;
2194 return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
2197 /* ECMA-262 3rd Edition 11.5.1 */
2198 static HRESULT mul_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2203 hres = to_number(ctx, lval, ei, &lnum);
2207 hres = to_number(ctx, rval, ei, &rnum);
2211 num_set_val(retv, num_val(&lnum) * num_val(&rnum));
2215 /* ECMA-262 3rd Edition 11.5.1 */
2216 HRESULT mul_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2218 binary_expression_t *expr = (binary_expression_t*)_expr;
2222 return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
2225 /* ECMA-262 3rd Edition 11.5.2 */
2226 static HRESULT div_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2231 hres = to_number(ctx, lval, ei, &lnum);
2235 hres = to_number(ctx, rval, ei, &rnum);
2239 num_set_val(retv, num_val(&lnum) / num_val(&rnum));
2243 /* ECMA-262 3rd Edition 11.5.2 */
2244 HRESULT div_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2246 binary_expression_t *expr = (binary_expression_t*)_expr;
2250 return binary_expr_eval(ctx, expr, div_eval, ei, ret);
2253 /* ECMA-262 3rd Edition 11.5.3 */
2254 static HRESULT mod_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2259 hres = to_number(ctx, lval, ei, &lnum);
2263 hres = to_number(ctx, rval, ei, &rnum);
2267 num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
2271 /* ECMA-262 3rd Edition 11.5.3 */
2272 HRESULT mod_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2274 binary_expression_t *expr = (binary_expression_t*)_expr;
2278 return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
2281 /* ECMA-262 3rd Edition 11.4.2 */
2282 HRESULT delete_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2284 unary_expression_t *expr = (unary_expression_t*)_expr;
2285 VARIANT_BOOL b = VARIANT_FALSE;
2291 hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
2295 switch(exprval.type) {
2296 case EXPRVAL_IDREF: {
2297 IDispatchEx *dispex;
2299 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2300 if(SUCCEEDED(hres)) {
2301 hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
2303 IDispatchEx_Release(dispex);
2307 case EXPRVAL_NAMEREF: {
2308 IDispatchEx *dispex;
2310 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2311 if(SUCCEEDED(hres)) {
2312 hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name,
2313 make_grfdex(ctx, fdexNameCaseSensitive));
2315 IDispatchEx_Release(dispex);
2320 FIXME("unsupported type %d\n", exprval.type);
2324 exprval_release(&exprval);
2328 return return_bool(ret, b);
2331 /* ECMA-262 3rd Edition 11.4.2 */
2332 HRESULT void_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2334 unary_expression_t *expr = (unary_expression_t*)_expr;
2341 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2345 hres = exprval_to_value(ctx, &exprval, ei, &tmp);
2346 exprval_release(&exprval);
2352 ret->type = EXPRVAL_VARIANT;
2353 V_VT(&ret->u.var) = VT_EMPTY;
2357 /* ECMA-262 3rd Edition 11.4.3 */
2358 static HRESULT typeof_exprval(script_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, const WCHAR **ret)
2363 static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
2364 static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
2365 static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
2366 static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
2367 static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
2368 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
2369 static const WCHAR unknownW[] = {'u','n','k','n','o','w','n',0};
2371 if(exprval->type == EXPRVAL_INVALID) {
2376 hres = exprval_to_value(ctx, exprval, ei, &val);
2378 if(exprval->type == EXPRVAL_IDREF) {
2385 switch(V_VT(&val)) {
2405 if(V_DISPATCH(&val) && (dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val)))) {
2406 *ret = is_class(dispex, JSCLASS_FUNCTION) ? functionW : objectW;
2407 jsdisp_release(dispex);
2414 FIXME("unhandled vt %d\n", V_VT(&val));
2422 HRESULT typeof_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2424 unary_expression_t *expr = (unary_expression_t*)_expr;
2425 const WCHAR *str = NULL;
2431 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2435 hres = typeof_exprval(ctx, &exprval, ei, &str);
2436 exprval_release(&exprval);
2440 ret->type = EXPRVAL_VARIANT;
2441 V_VT(&ret->u.var) = VT_BSTR;
2442 V_BSTR(&ret->u.var) = SysAllocString(str);
2443 if(!V_BSTR(&ret->u.var))
2444 return E_OUTOFMEMORY;
2449 /* ECMA-262 3rd Edition 11.4.7 */
2450 HRESULT minus_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2452 unary_expression_t *expr = (unary_expression_t*)_expr;
2459 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2463 hres = exprval_to_value(ctx, &exprval, ei, &val);
2464 exprval_release(&exprval);
2468 hres = to_number(ctx, &val, ei, &num);
2473 ret->type = EXPRVAL_VARIANT;
2474 num_set_val(&ret->u.var, -num_val(&num));
2478 /* ECMA-262 3rd Edition 11.4.6 */
2479 HRESULT plus_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2481 unary_expression_t *expr = (unary_expression_t*)_expr;
2488 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2492 hres = exprval_to_value(ctx, &exprval, ei, &val);
2493 exprval_release(&exprval);
2497 hres = to_number(ctx, &val, ei, &num);
2502 ret->type = EXPRVAL_VARIANT;
2507 /* ECMA-262 3rd Edition 11.3.1 */
2508 HRESULT post_increment_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2510 unary_expression_t *expr = (unary_expression_t*)_expr;
2517 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2521 hres = exprval_value(ctx, &exprval, ei, &val);
2522 if(SUCCEEDED(hres)) {
2523 hres = to_number(ctx, &val, ei, &num);
2527 if(SUCCEEDED(hres)) {
2529 num_set_val(&inc, num_val(&num)+1.0);
2530 hres = put_value(ctx, &exprval, &inc, ei);
2533 exprval_release(&exprval);
2537 ret->type = EXPRVAL_VARIANT;
2542 /* ECMA-262 3rd Edition 11.3.2 */
2543 HRESULT post_decrement_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2545 unary_expression_t *expr = (unary_expression_t*)_expr;
2552 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2556 hres = exprval_value(ctx, &exprval, ei, &val);
2557 if(SUCCEEDED(hres)) {
2558 hres = to_number(ctx, &val, ei, &num);
2562 if(SUCCEEDED(hres)) {
2564 num_set_val(&dec, num_val(&num)-1.0);
2565 hres = put_value(ctx, &exprval, &dec, ei);
2568 exprval_release(&exprval);
2572 ret->type = EXPRVAL_VARIANT;
2577 /* ECMA-262 3rd Edition 11.4.4 */
2578 HRESULT pre_increment_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2580 unary_expression_t *expr = (unary_expression_t*)_expr;
2587 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2591 hres = exprval_value(ctx, &exprval, ei, &val);
2592 if(SUCCEEDED(hres)) {
2593 hres = to_number(ctx, &val, ei, &num);
2597 if(SUCCEEDED(hres)) {
2598 num_set_val(&val, num_val(&num)+1.0);
2599 hres = put_value(ctx, &exprval, &val, ei);
2602 exprval_release(&exprval);
2606 ret->type = EXPRVAL_VARIANT;
2611 /* ECMA-262 3rd Edition 11.4.5 */
2612 HRESULT pre_decrement_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2614 unary_expression_t *expr = (unary_expression_t*)_expr;
2621 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2625 hres = exprval_value(ctx, &exprval, ei, &val);
2626 if(SUCCEEDED(hres)) {
2627 hres = to_number(ctx, &val, ei, &num);
2631 if(SUCCEEDED(hres)) {
2632 num_set_val(&val, num_val(&num)-1.0);
2633 hres = put_value(ctx, &exprval, &val, ei);
2636 exprval_release(&exprval);
2640 ret->type = EXPRVAL_VARIANT;
2645 /* ECMA-262 3rd Edition 11.9.3 */
2646 static HRESULT equal_values(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
2648 if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
2649 return equal2_values(lval, rval, ret);
2651 /* FIXME: NULL disps should be handled in more general way */
2652 if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
2655 return equal_values(ctx, &v, rval, ei, ret);
2658 if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
2661 return equal_values(ctx, lval, &v, ei, ret);
2664 if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
2665 (V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
2670 if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
2674 hres = to_number(ctx, lval, ei, &v);
2678 return equal_values(ctx, &v, rval, ei, ret);
2681 if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
2685 hres = to_number(ctx, rval, ei, &v);
2689 return equal_values(ctx, lval, &v, ei, ret);
2692 if(V_VT(rval) == VT_BOOL) {
2696 V_I4(&v) = V_BOOL(rval) ? 1 : 0;
2697 return equal_values(ctx, lval, &v, ei, ret);
2700 if(V_VT(lval) == VT_BOOL) {
2704 V_I4(&v) = V_BOOL(lval) ? 1 : 0;
2705 return equal_values(ctx, &v, rval, ei, ret);
2709 if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
2713 hres = to_primitive(ctx, rval, ei, &v, NO_HINT);
2717 hres = equal_values(ctx, lval, &v, ei, ret);
2724 if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
2728 hres = to_primitive(ctx, lval, ei, &v, NO_HINT);
2732 hres = equal_values(ctx, &v, rval, ei, ret);
2743 /* ECMA-262 3rd Edition 11.9.1 */
2744 HRESULT equal_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2746 binary_expression_t *expr = (binary_expression_t*)_expr;
2753 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2757 hres = equal_values(ctx, &rval, &lval, ei, &b);
2758 VariantClear(&lval);
2759 VariantClear(&rval);
2763 return return_bool(ret, b);
2766 /* ECMA-262 3rd Edition 11.9.4 */
2767 HRESULT equal2_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2769 binary_expression_t *expr = (binary_expression_t*)_expr;
2776 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2780 hres = equal2_values(&rval, &lval, &b);
2781 VariantClear(&lval);
2782 VariantClear(&rval);
2786 return return_bool(ret, b);
2789 /* ECMA-262 3rd Edition 11.9.2 */
2790 HRESULT not_equal_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2792 binary_expression_t *expr = (binary_expression_t*)_expr;
2799 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2803 hres = equal_values(ctx, &lval, &rval, ei, &b);
2804 VariantClear(&lval);
2805 VariantClear(&rval);
2809 return return_bool(ret, !b);
2812 /* ECMA-262 3rd Edition 11.9.5 */
2813 HRESULT not_equal2_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2815 binary_expression_t *expr = (binary_expression_t*)_expr;
2822 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2826 hres = equal2_values(&lval, &rval, &b);
2827 VariantClear(&lval);
2828 VariantClear(&rval);
2832 return return_bool(ret, !b);
2835 /* ECMA-262 3rd Edition 11.8.5 */
2836 static HRESULT less_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
2838 VARIANT l, r, ln, rn;
2841 hres = to_primitive(ctx, lval, ei, &l, NO_HINT);
2845 hres = to_primitive(ctx, rval, ei, &r, NO_HINT);
2851 if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
2852 *ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
2853 SysFreeString(V_BSTR(&l));
2854 SysFreeString(V_BSTR(&r));
2858 hres = to_number(ctx, &l, ei, &ln);
2861 hres = to_number(ctx, &r, ei, &rn);
2866 if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
2867 *ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
2869 DOUBLE ld = num_val(&ln);
2870 DOUBLE rd = num_val(&rn);
2872 *ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
2878 /* ECMA-262 3rd Edition 11.8.1 */
2879 HRESULT less_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2881 binary_expression_t *expr = (binary_expression_t*)_expr;
2888 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2892 hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
2893 VariantClear(&lval);
2894 VariantClear(&rval);
2898 return return_bool(ret, b);
2901 /* ECMA-262 3rd Edition 11.8.3 */
2902 HRESULT lesseq_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2904 binary_expression_t *expr = (binary_expression_t*)_expr;
2911 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2915 hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
2916 VariantClear(&lval);
2917 VariantClear(&rval);
2921 return return_bool(ret, b);
2924 /* ECMA-262 3rd Edition 11.8.2 */
2925 HRESULT greater_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2927 binary_expression_t *expr = (binary_expression_t*)_expr;
2934 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2938 hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
2939 VariantClear(&lval);
2940 VariantClear(&rval);
2944 return return_bool(ret, b);
2947 /* ECMA-262 3rd Edition 11.8.4 */
2948 HRESULT greatereq_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2950 binary_expression_t *expr = (binary_expression_t*)_expr;
2957 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2961 hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
2962 VariantClear(&lval);
2963 VariantClear(&rval);
2967 return return_bool(ret, b);
2970 /* ECMA-262 3rd Edition 11.4.8 */
2971 HRESULT binary_negation_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2973 unary_expression_t *expr = (unary_expression_t*)_expr;
2981 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2985 hres = exprval_to_value(ctx, &exprval, ei, &val);
2986 exprval_release(&exprval);
2990 hres = to_int32(ctx, &val, ei, &i);
2994 ret->type = EXPRVAL_VARIANT;
2995 V_VT(&ret->u.var) = VT_I4;
2996 V_I4(&ret->u.var) = ~i;
3000 /* ECMA-262 3rd Edition 11.4.9 */
3001 HRESULT logical_negation_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3003 unary_expression_t *expr = (unary_expression_t*)_expr;
3010 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
3014 hres = exprval_to_boolean(ctx, &exprval, ei, &b);
3015 exprval_release(&exprval);
3019 return return_bool(ret, !b);
3022 /* ECMA-262 3rd Edition 11.7.1 */
3023 static HRESULT lshift_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3029 hres = to_int32(ctx, lval, ei, &li);
3033 hres = to_uint32(ctx, rval, ei, &ri);
3038 V_I4(retv) = li << (ri&0x1f);
3042 /* ECMA-262 3rd Edition 11.7.1 */
3043 HRESULT left_shift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3045 binary_expression_t *expr = (binary_expression_t*)_expr;
3049 return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
3052 /* ECMA-262 3rd Edition 11.7.2 */
3053 static HRESULT rshift_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3059 hres = to_int32(ctx, lval, ei, &li);
3063 hres = to_uint32(ctx, rval, ei, &ri);
3068 V_I4(retv) = li >> (ri&0x1f);
3072 /* ECMA-262 3rd Edition 11.7.2 */
3073 HRESULT right_shift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3075 binary_expression_t *expr = (binary_expression_t*)_expr;
3079 return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
3082 /* ECMA-262 3rd Edition 11.7.3 */
3083 static HRESULT rshift2_eval(script_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3088 hres = to_uint32(ctx, lval, ei, &li);
3092 hres = to_uint32(ctx, rval, ei, &ri);
3097 V_I4(retv) = li >> (ri&0x1f);
3101 /* ECMA-262 3rd Edition 11.7.3 */
3102 HRESULT right2_shift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3104 binary_expression_t *expr = (binary_expression_t*)_expr;
3108 return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
3111 /* ECMA-262 3rd Edition 11.13.1 */
3112 HRESULT assign_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3114 binary_expression_t *expr = (binary_expression_t*)_expr;
3115 exprval_t exprval, exprvalr;
3121 hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
3125 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
3126 if(SUCCEEDED(hres)) {
3127 hres = exprval_to_value(ctx, &exprvalr, ei, &rval);
3128 exprval_release(&exprvalr);
3131 if(SUCCEEDED(hres)) {
3132 hres = put_value(ctx, &exprval, &rval, ei);
3134 VariantClear(&rval);
3137 exprval_release(&exprval);
3141 ret->type = EXPRVAL_VARIANT;
3146 /* ECMA-262 3rd Edition 11.13.2 */
3147 HRESULT assign_lshift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3149 binary_expression_t *expr = (binary_expression_t*)_expr;
3153 return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
3156 /* ECMA-262 3rd Edition 11.13.2 */
3157 HRESULT assign_rshift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3159 binary_expression_t *expr = (binary_expression_t*)_expr;
3163 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift_eval, ei, ret);
3166 /* ECMA-262 3rd Edition 11.13.2 */
3167 HRESULT assign_rrshift_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3169 binary_expression_t *expr = (binary_expression_t*)_expr;
3173 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift2_eval, ei, ret);
3176 /* ECMA-262 3rd Edition 11.13.2 */
3177 HRESULT assign_add_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3179 binary_expression_t *expr = (binary_expression_t*)_expr;
3183 return assign_oper_eval(ctx, expr->expression1, expr->expression2, add_eval, ei, ret);
3186 /* ECMA-262 3rd Edition 11.13.2 */
3187 HRESULT assign_sub_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3189 binary_expression_t *expr = (binary_expression_t*)_expr;
3193 return assign_oper_eval(ctx, expr->expression1, expr->expression2, sub_eval, ei, ret);
3196 /* ECMA-262 3rd Edition 11.13.2 */
3197 HRESULT assign_mul_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3199 binary_expression_t *expr = (binary_expression_t*)_expr;
3203 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mul_eval, ei, ret);
3206 /* ECMA-262 3rd Edition 11.13.2 */
3207 HRESULT assign_div_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3209 binary_expression_t *expr = (binary_expression_t*)_expr;
3213 return assign_oper_eval(ctx, expr->expression1, expr->expression2, div_eval, ei, ret);
3216 /* ECMA-262 3rd Edition 11.13.2 */
3217 HRESULT assign_mod_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3219 binary_expression_t *expr = (binary_expression_t*)_expr;
3223 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mod_eval, ei, ret);
3226 /* ECMA-262 3rd Edition 11.13.2 */
3227 HRESULT assign_and_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3229 binary_expression_t *expr = (binary_expression_t*)_expr;
3233 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitand_eval, ei, ret);
3236 /* ECMA-262 3rd Edition 11.13.2 */
3237 HRESULT assign_or_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3239 binary_expression_t *expr = (binary_expression_t*)_expr;
3243 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitor_eval, ei, ret);
3246 /* ECMA-262 3rd Edition 11.13.2 */
3247 HRESULT assign_xor_expression_eval(script_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3249 binary_expression_t *expr = (binary_expression_t*)_expr;
3253 return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);