2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
31 #define EXPR_NOVAL 0x0001
32 #define EXPR_NEWREF 0x0002
33 #define EXPR_STRREF 0x0004
35 static inline HRESULT stat_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
37 return stat->eval(ctx, stat, rt, ret);
40 static inline HRESULT expr_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
42 return _expr->eval(ctx, _expr, flags, ei, ret);
45 static void exprval_release(exprval_t *val)
49 if(V_VT(&val->u.var) != VT_EMPTY)
50 VariantClear(&val->u.var);
54 IDispatch_Release(val->u.idref.disp);
57 if(val->u.nameref.disp)
58 IDispatch_Release(val->u.nameref.disp);
59 SysFreeString(val->u.nameref.name);
62 SysFreeString(val->u.identifier);
66 /* ECMA-262 3rd Edition 8.7.1 */
67 static HRESULT exprval_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
73 return VariantCopy(ret, &val->u.var);
75 if(!val->u.idref.disp) {
76 FIXME("throw ReferenceError\n");
80 return disp_propget(val->u.idref.disp, val->u.idref.id, ctx->lcid, ret, ei, NULL/*FIXME*/);
84 return throw_type_error(ctx, ei, IDS_UNDEFINED, val->u.identifier);
87 ERR("type %d\n", val->type);
91 static HRESULT exprval_to_value(script_ctx_t *ctx, exprval_t *val, jsexcept_t *ei, VARIANT *ret)
93 if(val->type == EXPRVAL_VARIANT) {
95 V_VT(&val->u.var) = VT_EMPTY;
99 return exprval_value(ctx, val, ei, ret);
102 static HRESULT exprval_to_boolean(script_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, VARIANT_BOOL *b)
104 if(exprval->type != EXPRVAL_VARIANT) {
108 hres = exprval_to_value(ctx, exprval, ei, &val);
112 hres = to_boolean(&val, b);
117 return to_boolean(&exprval->u.var, b);
120 static void exprval_init(exprval_t *val)
122 val->type = EXPRVAL_VARIANT;
123 V_VT(&val->u.var) = VT_EMPTY;
126 static void exprval_set_idref(exprval_t *val, IDispatch *disp, DISPID id)
128 val->type = EXPRVAL_IDREF;
129 val->u.idref.disp = disp;
130 val->u.idref.id = id;
133 IDispatch_AddRef(disp);
136 HRESULT scope_push(scope_chain_t *scope, DispatchEx *obj, scope_chain_t **ret)
138 scope_chain_t *new_scope;
140 new_scope = heap_alloc(sizeof(scope_chain_t));
142 return E_OUTOFMEMORY;
146 IDispatchEx_AddRef(_IDispatchEx_(obj));
147 new_scope->obj = obj;
151 new_scope->next = scope;
153 new_scope->next = NULL;
160 static void scope_pop(scope_chain_t **scope)
169 void scope_release(scope_chain_t *scope)
175 scope_release(scope->next);
177 jsdisp_release(scope->obj);
181 HRESULT create_exec_ctx(IDispatch *this_obj, DispatchEx *var_disp, scope_chain_t *scope, exec_ctx_t **ret)
185 ctx = heap_alloc_zero(sizeof(exec_ctx_t));
187 return E_OUTOFMEMORY;
191 IDispatch_AddRef(this_obj);
192 ctx->this_obj = this_obj;
194 IDispatchEx_AddRef(_IDispatchEx_(var_disp));
195 ctx->var_disp = var_disp;
199 ctx->scope_chain = scope;
206 void exec_release(exec_ctx_t *ctx)
212 scope_release(ctx->scope_chain);
214 jsdisp_release(ctx->var_disp);
216 IDispatch_Release(ctx->this_obj);
220 static HRESULT disp_get_id(IDispatch *disp, BSTR name, DWORD flags, DISPID *id)
225 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
227 TRACE("unsing IDispatch\n");
230 return IDispatch_GetIDsOfNames(disp, &IID_NULL, &name, 1, 0, id);
234 hres = IDispatchEx_GetDispID(dispex, name, flags|fdexNameCaseSensitive, id);
235 IDispatchEx_Release(dispex);
239 /* ECMA-262 3rd Edition 8.7.2 */
240 static HRESULT put_value(script_ctx_t *ctx, exprval_t *ref, VARIANT *v, jsexcept_t *ei)
242 if(ref->type != EXPRVAL_IDREF)
243 return throw_reference_error(ctx, ei, IDS_ILLEGAL_ASSIGN, NULL);
245 return disp_propput(ref->u.idref.disp, ref->u.idref.id, ctx->lcid, v, ei, NULL/*FIXME*/);
248 static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, BOOL *ret)
250 IObjectIdentity *identity;
251 IUnknown *unk1, *unk2;
259 hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
263 hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
265 IUnknown_Release(unk1);
272 hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
273 if(SUCCEEDED(hres)) {
274 hres = IObjectIdentity_IsEqualObject(identity, unk2);
275 IObjectIdentity_Release(identity);
282 IUnknown_Release(unk1);
283 IUnknown_Release(unk2);
287 /* ECMA-262 3rd Edition 11.9.6 */
288 static HRESULT equal2_values(VARIANT *lval, VARIANT *rval, BOOL *ret)
292 if(V_VT(lval) != V_VT(rval)) {
293 if(is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))) {
294 *ret = num_val(lval) == num_val(rval);
308 *ret = V_I4(lval) == V_I4(rval);
311 *ret = V_R8(lval) == V_R8(rval);
315 *ret = SysStringLen(V_BSTR(rval))?FALSE:TRUE;
316 else if(!V_BSTR(rval))
317 *ret = SysStringLen(V_BSTR(lval))?FALSE:TRUE;
319 *ret = !strcmpW(V_BSTR(lval), V_BSTR(rval));
322 return disp_cmp(V_DISPATCH(lval), V_DISPATCH(rval), ret);
324 *ret = !V_BOOL(lval) == !V_BOOL(rval);
327 FIXME("unimplemented vt %d\n", V_VT(lval));
334 static HRESULT literal_to_var(literal_t *literal, VARIANT *v)
336 V_VT(v) = literal->vt;
343 V_I4(v) = literal->u.lval;
346 V_R8(v) = literal->u.dval;
349 V_BSTR(v) = SysAllocString(literal->u.wstr);
352 V_BOOL(v) = literal->u.bval;
355 IDispatch_AddRef(literal->u.disp);
356 V_DISPATCH(v) = literal->u.disp;
359 ERR("wrong type %d\n", V_VT(v));
366 static BOOL lookup_global_members(script_ctx_t *ctx, BSTR identifier, exprval_t *ret)
372 for(item = ctx->named_items; item; item = item->next) {
373 if(item->flags & SCRIPTITEM_GLOBALMEMBERS) {
374 hres = disp_get_id(item->disp, identifier, 0, &id);
375 if(SUCCEEDED(hres)) {
377 exprval_set_idref(ret, item->disp, id);
386 HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, jsexcept_t *ei, VARIANT *retv)
388 script_ctx_t *script = parser->script;
389 function_declaration_t *func;
390 parser_ctx_t *prev_parser;
394 exec_ctx_t *prev_ctx;
398 for(func = source->functions; func; func = func->next) {
399 DispatchEx *func_obj;
402 hres = create_source_function(parser, func->expr->parameter_list, func->expr->source_elements,
403 ctx->scope_chain, func->expr->src_str, func->expr->src_len, &func_obj);
407 V_VT(&var) = VT_DISPATCH;
408 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(func_obj);
409 hres = jsdisp_propput_name(ctx->var_disp, func->expr->identifier, script->lcid, &var, ei, NULL);
410 jsdisp_release(func_obj);
415 for(var = source->variables; var; var = var->next) {
419 name = SysAllocString(var->identifier);
421 return E_OUTOFMEMORY;
423 if(!lookup_global_members(parser->script, name, NULL))
424 hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
430 prev_ctx = script->exec_ctx;
431 script->exec_ctx = ctx;
433 prev_parser = ctx->parser;
434 ctx->parser = parser;
436 V_VT(&val) = VT_EMPTY;
437 memset(&rt, 0, sizeof(rt));
440 for(stat = source->statement; stat; stat = stat->next) {
441 hres = stat_eval(ctx, stat, &rt, &tmp);
447 if(rt.type != RT_NORMAL)
451 script->exec_ctx = prev_ctx;
452 ctx->parser = prev_parser;
454 if(rt.type != RT_NORMAL && rt.type != RT_RETURN) {
455 FIXME("wrong rt %d\n", rt.type);
472 /* ECMA-262 3rd Edition 10.1.4 */
473 static HRESULT identifier_eval(exec_ctx_t *ctx, BSTR identifier, DWORD flags, jsexcept_t *ei, exprval_t *ret)
475 scope_chain_t *scope;
480 TRACE("%s\n", debugstr_w(identifier));
482 for(scope = ctx->scope_chain; scope; scope = scope->next) {
483 hres = jsdisp_get_id(scope->obj, identifier, 0, &id);
489 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(scope->obj), id);
493 hres = jsdisp_get_id(ctx->parser->script->global, identifier, 0, &id);
494 if(SUCCEEDED(hres)) {
495 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->global), id);
499 for(item = ctx->parser->script->named_items; item; item = item->next) {
500 if((item->flags & SCRIPTITEM_ISVISIBLE) && !strcmpW(item->name, identifier)) {
504 if(!ctx->parser->script->site)
507 hres = IActiveScriptSite_GetItemInfo(ctx->parser->script->site, identifier,
508 SCRIPTINFO_IUNKNOWN, &unk, NULL);
510 WARN("GetItemInfo failed: %08x\n", hres);
514 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&item->disp);
515 IUnknown_Release(unk);
517 WARN("object does not implement IDispatch\n");
522 ret->type = EXPRVAL_VARIANT;
523 V_VT(&ret->u.var) = VT_DISPATCH;
524 V_DISPATCH(&ret->u.var) = item->disp;
525 IDispatch_AddRef(item->disp);
530 hres = jsdisp_get_id(ctx->parser->script->script_disp, identifier, 0, &id);
531 if(SUCCEEDED(hres)) {
532 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->script_disp), id);
536 if(lookup_global_members(ctx->parser->script, identifier, ret))
539 if(flags & EXPR_NEWREF) {
540 hres = jsdisp_get_id(ctx->parser->script->script_disp, identifier, fdexNameEnsure, &id);
544 exprval_set_idref(ret, (IDispatch*)_IDispatchEx_(ctx->parser->script->script_disp), id);
548 ret->type = EXPRVAL_INVALID;
549 ret->u.identifier = SysAllocString(identifier);
550 if(!ret->u.identifier)
551 return E_OUTOFMEMORY;
556 /* ECMA-262 3rd Edition 12.1 */
557 HRESULT block_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
559 block_statement_t *stat = (block_statement_t*)_stat;
566 V_VT(&val) = VT_EMPTY;
567 for(iter = stat->stat_list; iter; iter = iter->next) {
568 hres = stat_eval(ctx, iter, rt, &tmp);
574 if(rt->type != RT_NORMAL)
587 /* ECMA-262 3rd Edition 12.2 */
588 static HRESULT variable_list_eval(exec_ctx_t *ctx, variable_declaration_t *var_list, jsexcept_t *ei)
590 variable_declaration_t *iter;
593 for(iter = var_list; iter; iter = iter->next) {
600 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
604 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
605 exprval_release(&exprval);
609 hres = jsdisp_propput_name(ctx->var_disp, iter->identifier, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
618 /* ECMA-262 3rd Edition 12.2 */
619 HRESULT var_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
621 var_statement_t *stat = (var_statement_t*)_stat;
626 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
630 V_VT(ret) = VT_EMPTY;
634 /* ECMA-262 3rd Edition 12.3 */
635 HRESULT empty_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
639 V_VT(ret) = VT_EMPTY;
643 /* ECMA-262 3rd Edition 12.4 */
644 HRESULT expression_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
646 expression_statement_t *stat = (expression_statement_t*)_stat;
653 hres = expr_eval(ctx, stat->expr, EXPR_NOVAL, &rt->ei, &exprval);
657 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
658 exprval_release(&exprval);
663 TRACE("= %s\n", debugstr_variant(ret));
667 /* ECMA-262 3rd Edition 12.5 */
668 HRESULT if_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
670 if_statement_t *stat = (if_statement_t*)_stat;
677 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
681 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
682 exprval_release(&exprval);
687 hres = stat_eval(ctx, stat->if_stat, rt, ret);
688 else if(stat->else_stat)
689 hres = stat_eval(ctx, stat->else_stat, rt, ret);
691 V_VT(ret) = VT_EMPTY;
696 /* ECMA-262 3rd Edition 12.6.2 */
697 HRESULT while_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
699 while_statement_t *stat = (while_statement_t*)_stat;
708 V_VT(&val) = VT_EMPTY;
709 test_expr = !stat->do_while;
713 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
717 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
718 exprval_release(&exprval);
719 if(FAILED(hres) || !b)
725 hres = stat_eval(ctx, stat->statement, rt, &tmp);
732 if(rt->type == RT_CONTINUE)
733 rt->type = RT_NORMAL;
734 if(rt->type != RT_NORMAL)
743 if(rt->type == RT_BREAK)
744 rt->type = RT_NORMAL;
750 /* ECMA-262 3rd Edition 12.6.3 */
751 HRESULT for_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
753 for_statement_t *stat = (for_statement_t*)_stat;
754 VARIANT val, tmp, retv;
761 if(stat->variable_list) {
762 hres = variable_list_eval(ctx, stat->variable_list, &rt->ei);
765 }else if(stat->begin_expr) {
766 hres = expr_eval(ctx, stat->begin_expr, EXPR_NEWREF, &rt->ei, &exprval);
770 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
771 exprval_release(&exprval);
778 V_VT(&retv) = VT_EMPTY;
782 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
786 hres = exprval_to_boolean(ctx->parser->script, &exprval, &rt->ei, &b);
787 exprval_release(&exprval);
788 if(FAILED(hres) || !b)
792 hres = stat_eval(ctx, stat->statement, rt, &tmp);
799 if(rt->type == RT_CONTINUE)
800 rt->type = RT_NORMAL;
801 else if(rt->type != RT_NORMAL)
805 hres = expr_eval(ctx, stat->end_expr, 0, &rt->ei, &exprval);
809 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
810 exprval_release(&exprval);
823 if(rt->type == RT_BREAK)
824 rt->type = RT_NORMAL;
830 /* ECMA-262 3rd Edition 12.6.4 */
831 HRESULT forin_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
833 forin_statement_t *stat = (forin_statement_t*)_stat;
834 VARIANT val, name, retv, tmp;
835 DISPID id = DISPID_STARTENUM;
836 BSTR str, identifier = NULL;
844 hres = variable_list_eval(ctx, stat->variable, &rt->ei);
849 hres = expr_eval(ctx, stat->in_expr, EXPR_NEWREF, &rt->ei, &exprval);
853 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
854 exprval_release(&exprval);
858 if(V_VT(&val) != VT_DISPATCH) {
859 TRACE("in vt %d\n", V_VT(&val));
861 V_VT(ret) = VT_EMPTY;
865 hres = IDispatch_QueryInterface(V_DISPATCH(&val), &IID_IDispatchEx, (void**)&in_obj);
866 IDispatch_Release(V_DISPATCH(&val));
868 FIXME("Object doesn't support IDispatchEx\n");
872 V_VT(&retv) = VT_EMPTY;
875 identifier = SysAllocString(stat->variable->identifier);
878 hres = IDispatchEx_GetNextDispID(in_obj, fdexEnumDefault, id, &id);
879 if(FAILED(hres) || hres == S_FALSE)
882 hres = IDispatchEx_GetMemberName(in_obj, id, &str);
886 TRACE("iter %s\n", debugstr_w(str));
889 hres = identifier_eval(ctx, identifier, 0, NULL, &exprval);
891 hres = expr_eval(ctx, stat->expr, EXPR_NEWREF, &rt->ei, &exprval);
892 if(SUCCEEDED(hres)) {
893 V_VT(&name) = VT_BSTR;
895 hres = put_value(ctx->parser->script, &exprval, &name, &rt->ei);
896 exprval_release(&exprval);
902 hres = stat_eval(ctx, stat->statement, rt, &tmp);
909 if(rt->type == RT_CONTINUE)
910 rt->type = RT_NORMAL;
911 else if(rt->type != RT_NORMAL)
915 SysFreeString(identifier);
916 IDispatchEx_Release(in_obj);
922 if(rt->type == RT_BREAK)
923 rt->type = RT_NORMAL;
929 /* ECMA-262 3rd Edition 12.7 */
930 HRESULT continue_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
932 branch_statement_t *stat = (branch_statement_t*)_stat;
936 if(stat->identifier) {
937 FIXME("indentifier not implemented\n");
941 rt->type = RT_CONTINUE;
942 V_VT(ret) = VT_EMPTY;
946 /* ECMA-262 3rd Edition 12.8 */
947 HRESULT break_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
949 branch_statement_t *stat = (branch_statement_t*)_stat;
953 if(stat->identifier) {
954 FIXME("indentifier not implemented\n");
959 V_VT(ret) = VT_EMPTY;
963 /* ECMA-262 3rd Edition 12.9 */
964 HRESULT return_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
966 expression_statement_t *stat = (expression_statement_t*)_stat;
974 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
978 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, ret);
979 exprval_release(&exprval);
983 V_VT(ret) = VT_EMPTY;
986 TRACE("= %s\n", debugstr_variant(ret));
987 rt->type = RT_RETURN;
991 /* ECMA-262 3rd Edition 12.10 */
992 HRESULT with_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
994 with_statement_t *stat = (with_statement_t*)_stat;
1003 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1007 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1008 exprval_release(&exprval);
1012 hres = to_object(ctx->parser->script, &val, &disp);
1017 obj = iface_to_jsdisp((IUnknown*)disp);
1018 IDispatch_Release(disp);
1020 FIXME("disp id not jsdisp\n");
1024 hres = scope_push(ctx->scope_chain, obj, &ctx->scope_chain);
1025 jsdisp_release(obj);
1029 hres = stat_eval(ctx, stat->statement, rt, ret);
1031 scope_pop(&ctx->scope_chain);
1035 /* ECMA-262 3rd Edition 12.12 */
1036 HRESULT labelled_statement_eval(exec_ctx_t *ctx, statement_t *stat, return_type_t *rt, VARIANT *ret)
1042 /* ECMA-262 3rd Edition 12.13 */
1043 HRESULT switch_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1045 switch_statement_t *stat = (switch_statement_t*)_stat;
1046 case_clausule_t *iter, *default_clausule = NULL;
1047 statement_t *stat_iter;
1055 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1059 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1060 exprval_release(&exprval);
1064 for(iter = stat->case_list; iter; iter = iter->next) {
1066 default_clausule = iter;
1070 hres = expr_eval(ctx, iter->expr, 0, &rt->ei, &exprval);
1074 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &cval);
1075 exprval_release(&exprval);
1079 hres = equal2_values(&val, &cval, &b);
1080 VariantClear(&cval);
1081 if(FAILED(hres) || b)
1090 iter = default_clausule;
1092 V_VT(&val) = VT_EMPTY;
1096 for(stat_iter = iter->stat; stat_iter; stat_iter = stat_iter->next) {
1097 hres = stat_eval(ctx, stat_iter, rt, &tmp);
1104 if(rt->type != RT_NORMAL)
1114 if(rt->type == RT_BREAK)
1115 rt->type = RT_NORMAL;
1121 /* ECMA-262 3rd Edition 12.13 */
1122 HRESULT throw_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1124 expression_statement_t *stat = (expression_statement_t*)_stat;
1131 hres = expr_eval(ctx, stat->expr, 0, &rt->ei, &exprval);
1135 hres = exprval_to_value(ctx->parser->script, &exprval, &rt->ei, &val);
1136 exprval_release(&exprval);
1141 return DISP_E_EXCEPTION;
1144 /* ECMA-262 3rd Edition 12.14 */
1145 static HRESULT catch_eval(exec_ctx_t *ctx, catch_block_t *block, return_type_t *rt, VARIANT *ret)
1147 DispatchEx *var_disp;
1152 memset(&rt->ei, 0, sizeof(jsexcept_t));
1154 hres = create_dispex(ctx->parser->script, NULL, NULL, &var_disp);
1155 if(SUCCEEDED(hres)) {
1156 hres = jsdisp_propput_name(var_disp, block->identifier, ctx->parser->script->lcid,
1157 &ex, &rt->ei, NULL/*FIXME*/);
1158 if(SUCCEEDED(hres)) {
1159 hres = scope_push(ctx->scope_chain, var_disp, &ctx->scope_chain);
1160 if(SUCCEEDED(hres)) {
1161 hres = stat_eval(ctx, block->statement, rt, &val);
1162 scope_pop(&ctx->scope_chain);
1166 jsdisp_release(var_disp);
1177 /* ECMA-262 3rd Edition 12.14 */
1178 HRESULT try_statement_eval(exec_ctx_t *ctx, statement_t *_stat, return_type_t *rt, VARIANT *ret)
1180 try_statement_t *stat = (try_statement_t*)_stat;
1186 hres = stat_eval(ctx, stat->try_statement, rt, &val);
1188 TRACE("EXCEPTION\n");
1189 if(!stat->catch_block)
1192 hres = catch_eval(ctx, stat->catch_block, rt, &val);
1197 if(stat->finally_statement) {
1199 hres = stat_eval(ctx, stat->finally_statement, rt, &val);
1208 static HRESULT return_bool(exprval_t *ret, DWORD b)
1210 ret->type = EXPRVAL_VARIANT;
1211 V_VT(&ret->u.var) = VT_BOOL;
1212 V_BOOL(&ret->u.var) = b ? VARIANT_TRUE : VARIANT_FALSE;
1217 static HRESULT get_binary_expr_values(exec_ctx_t *ctx, binary_expression_t *expr, jsexcept_t *ei, VARIANT *lval, VARIANT *rval)
1222 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1226 hres = exprval_to_value(ctx->parser->script, &exprval, ei, lval);
1227 exprval_release(&exprval);
1231 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1232 if(SUCCEEDED(hres)) {
1233 hres = exprval_to_value(ctx->parser->script, &exprval, ei, rval);
1234 exprval_release(&exprval);
1245 typedef HRESULT (*oper_t)(exec_ctx_t*,VARIANT*,VARIANT*,jsexcept_t*,VARIANT*);
1247 static HRESULT binary_expr_eval(exec_ctx_t *ctx, binary_expression_t *expr, oper_t oper, jsexcept_t *ei,
1250 VARIANT lval, rval, retv;
1253 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1257 hres = oper(ctx, &lval, &rval, ei, &retv);
1258 VariantClear(&lval);
1259 VariantClear(&rval);
1263 ret->type = EXPRVAL_VARIANT;
1268 /* ECMA-262 3rd Edition 11.13.2 */
1269 static HRESULT assign_oper_eval(exec_ctx_t *ctx, expression_t *lexpr, expression_t *rexpr, oper_t oper,
1270 jsexcept_t *ei, exprval_t *ret)
1272 VARIANT retv, lval, rval;
1273 exprval_t exprval, exprvalr;
1276 hres = expr_eval(ctx, lexpr, EXPR_NEWREF, ei, &exprval);
1280 hres = exprval_value(ctx->parser->script, &exprval, ei, &lval);
1281 if(SUCCEEDED(hres)) {
1282 hres = expr_eval(ctx, rexpr, 0, ei, &exprvalr);
1283 if(SUCCEEDED(hres)) {
1284 hres = exprval_value(ctx->parser->script, &exprvalr, ei, &rval);
1285 exprval_release(&exprvalr);
1287 if(SUCCEEDED(hres)) {
1288 hres = oper(ctx, &lval, &rval, ei, &retv);
1289 VariantClear(&rval);
1291 VariantClear(&lval);
1294 if(SUCCEEDED(hres)) {
1295 hres = put_value(ctx->parser->script, &exprval, &retv, ei);
1297 VariantClear(&retv);
1299 exprval_release(&exprval);
1304 ret->type = EXPRVAL_VARIANT;
1309 /* ECMA-262 3rd Edition 13 */
1310 HRESULT function_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1312 function_expression_t *expr = (function_expression_t*)_expr;
1318 if(expr->identifier) {
1319 hres = jsdisp_propget_name(ctx->var_disp, expr->identifier, ctx->parser->script->lcid, &var, ei, NULL/*FIXME*/);
1325 hres = create_source_function(ctx->parser, expr->parameter_list, expr->source_elements, ctx->scope_chain,
1326 expr->src_str, expr->src_len, &dispex);
1330 V_VT(&var) = VT_DISPATCH;
1331 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
1334 ret->type = EXPRVAL_VARIANT;
1339 /* ECMA-262 3rd Edition 11.12 */
1340 HRESULT conditional_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1342 conditional_expression_t *expr = (conditional_expression_t*)_expr;
1349 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1353 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
1354 exprval_release(&exprval);
1358 return expr_eval(ctx, b ? expr->true_expression : expr->false_expression, flags, ei, ret);
1361 /* ECMA-262 3rd Edition 11.2.1 */
1362 HRESULT array_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1364 array_expression_t *expr = (array_expression_t*)_expr;
1366 VARIANT member, val;
1369 IDispatch *obj = NULL;
1374 hres = expr_eval(ctx, expr->member_expr, EXPR_NEWREF, ei, &exprval);
1378 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1379 exprval_release(&exprval);
1383 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
1384 if(SUCCEEDED(hres)) {
1385 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1386 exprval_release(&exprval);
1390 hres = to_object(ctx->parser->script, &member, &obj);
1391 VariantClear(&member);
1392 if(SUCCEEDED(hres)) {
1393 hres = to_string(ctx->parser->script, &val, ei, &str);
1394 if(SUCCEEDED(hres)) {
1395 if(flags & EXPR_STRREF) {
1396 ret->type = EXPRVAL_NAMEREF;
1397 ret->u.nameref.disp = obj;
1398 ret->u.nameref.name = str;
1402 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1405 if(SUCCEEDED(hres)) {
1406 exprval_set_idref(ret, obj, id);
1407 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1412 IDispatch_Release(obj);
1418 /* ECMA-262 3rd Edition 11.2.1 */
1419 HRESULT member_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1421 member_expression_t *expr = (member_expression_t*)_expr;
1422 IDispatch *obj = NULL;
1431 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1435 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &member);
1436 exprval_release(&exprval);
1440 hres = to_object(ctx->parser->script, &member, &obj);
1441 VariantClear(&member);
1445 str = SysAllocString(expr->identifier);
1446 if(flags & EXPR_STRREF) {
1447 ret->type = EXPRVAL_NAMEREF;
1448 ret->u.nameref.disp = obj;
1449 ret->u.nameref.name = str;
1453 hres = disp_get_id(obj, str, flags & EXPR_NEWREF ? fdexNameEnsure : 0, &id);
1455 if(SUCCEEDED(hres)) {
1456 exprval_set_idref(ret, obj, id);
1457 }else if(!(flags & EXPR_NEWREF) && hres == DISP_E_UNKNOWNNAME) {
1462 IDispatch_Release(obj);
1466 static void free_dp(DISPPARAMS *dp)
1470 for(i=0; i < dp->cArgs; i++)
1471 VariantClear(dp->rgvarg+i);
1472 heap_free(dp->rgvarg);
1475 static HRESULT args_to_param(exec_ctx_t *ctx, argument_t *args, jsexcept_t *ei, DISPPARAMS *dp)
1481 HRESULT hres = S_OK;
1483 memset(dp, 0, sizeof(*dp));
1487 for(iter = args; iter; iter = iter->next)
1490 vargs = heap_alloc_zero(cnt * sizeof(*vargs));
1492 return E_OUTOFMEMORY;
1494 for(i = cnt, iter = args; iter; iter = iter->next) {
1495 hres = expr_eval(ctx, iter->expr, 0, ei, &exprval);
1499 hres = exprval_to_value(ctx->parser->script, &exprval, ei, vargs + (--i));
1500 exprval_release(&exprval);
1515 /* ECMA-262 3rd Edition 11.2.2 */
1516 HRESULT new_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1518 call_expression_t *expr = (call_expression_t*)_expr;
1520 VARIANT constr, var;
1526 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1530 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1532 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &constr);
1533 exprval_release(&exprval);
1537 if(V_VT(&constr) != VT_DISPATCH) {
1538 FIXME("throw TypeError\n");
1539 VariantClear(&constr);
1543 hres = disp_call(V_DISPATCH(&constr), DISPID_VALUE, ctx->parser->script->lcid,
1544 DISPATCH_CONSTRUCT, &dp, &var, ei, NULL/*FIXME*/);
1545 IDispatch_Release(V_DISPATCH(&constr));
1549 ret->type = EXPRVAL_VARIANT;
1554 /* ECMA-262 3rd Edition 11.2.3 */
1555 HRESULT call_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1557 call_expression_t *expr = (call_expression_t*)_expr;
1565 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
1569 hres = args_to_param(ctx, expr->argument_list, ei, &dp);
1570 if(SUCCEEDED(hres)) {
1571 switch(exprval.type) {
1572 case EXPRVAL_VARIANT:
1573 if(V_VT(&exprval.u.var) == VT_DISPATCH)
1574 hres = disp_call(V_DISPATCH(&exprval.u.var), DISPID_VALUE, ctx->parser->script->lcid,
1575 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1577 hres = throw_type_error(ctx->var_disp->ctx, ei, IDS_NO_PROPERTY, NULL);
1580 hres = disp_call(exprval.u.idref.disp, exprval.u.idref.id, ctx->parser->script->lcid,
1581 DISPATCH_METHOD, &dp, flags & EXPR_NOVAL ? NULL : &var, ei, NULL/*FIXME*/);
1583 case EXPRVAL_INVALID:
1584 hres = throw_type_error(ctx->var_disp->ctx, ei, IDS_OBJECT_EXPECTED, NULL);
1587 FIXME("unimplemented type %d\n", exprval.type);
1594 exprval_release(&exprval);
1598 ret->type = EXPRVAL_VARIANT;
1599 if(flags & EXPR_NOVAL) {
1600 V_VT(&ret->u.var) = VT_EMPTY;
1602 TRACE("= %s\n", debugstr_variant(&var));
1608 /* ECMA-262 3rd Edition 11.1.1 */
1609 HRESULT this_expression_eval(exec_ctx_t *ctx, expression_t *expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1613 ret->type = EXPRVAL_VARIANT;
1614 V_VT(&ret->u.var) = VT_DISPATCH;
1615 V_DISPATCH(&ret->u.var) = ctx->this_obj;
1616 IDispatch_AddRef(ctx->this_obj);
1620 /* ECMA-262 3rd Edition 10.1.4 */
1621 HRESULT identifier_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1623 identifier_expression_t *expr = (identifier_expression_t*)_expr;
1629 identifier = SysAllocString(expr->identifier);
1631 return E_OUTOFMEMORY;
1633 hres = identifier_eval(ctx, identifier, flags, ei, ret);
1635 SysFreeString(identifier);
1639 /* ECMA-262 3rd Edition 7.8 */
1640 HRESULT literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1642 literal_expression_t *expr = (literal_expression_t*)_expr;
1648 hres = literal_to_var(expr->literal, &var);
1652 ret->type = EXPRVAL_VARIANT;
1657 /* ECMA-262 3rd Edition 11.1.4 */
1658 HRESULT array_literal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1660 array_literal_expression_t *expr = (array_literal_expression_t*)_expr;
1661 DWORD length = 0, i = 0;
1662 array_element_t *elem;
1670 for(elem = expr->element_list; elem; elem = elem->next)
1671 length += elem->elision+1;
1672 length += expr->length;
1674 hres = create_array(ctx->parser->script, length, &array);
1678 for(elem = expr->element_list; elem; elem = elem->next) {
1681 hres = expr_eval(ctx, elem->expr, 0, ei, &exprval);
1685 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1686 exprval_release(&exprval);
1690 hres = jsdisp_propput_idx(array, i, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1699 jsdisp_release(array);
1703 ret->type = EXPRVAL_VARIANT;
1704 V_VT(&ret->u.var) = VT_DISPATCH;
1705 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(array);
1709 /* ECMA-262 3rd Edition 11.1.5 */
1710 HRESULT property_value_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1712 property_value_expression_t *expr = (property_value_expression_t*)_expr;
1722 hres = create_object(ctx->parser->script, NULL, &obj);
1726 for(iter = expr->property_list; iter; iter = iter->next) {
1727 hres = literal_to_var(iter->name, &tmp);
1731 hres = to_string(ctx->parser->script, &tmp, ei, &name);
1736 hres = expr_eval(ctx, iter->value, 0, ei, &exprval);
1737 if(SUCCEEDED(hres)) {
1738 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1739 exprval_release(&exprval);
1740 if(SUCCEEDED(hres)) {
1741 hres = jsdisp_propput_name(obj, name, ctx->parser->script->lcid, &val, ei, NULL/*FIXME*/);
1746 SysFreeString(name);
1752 jsdisp_release(obj);
1756 ret->type = EXPRVAL_VARIANT;
1757 V_VT(&ret->u.var) = VT_DISPATCH;
1758 V_DISPATCH(&ret->u.var) = (IDispatch*)_IDispatchEx_(obj);
1762 /* ECMA-262 3rd Edition 11.14 */
1763 HRESULT comma_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1765 binary_expression_t *expr = (binary_expression_t*)_expr;
1771 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
1775 VariantClear(&lval);
1777 ret->type = EXPRVAL_VARIANT;
1782 /* ECMA-262 3rd Edition 11.11 */
1783 HRESULT logical_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1785 binary_expression_t *expr = (binary_expression_t*)_expr;
1793 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1797 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1798 exprval_release(&exprval);
1802 hres = to_boolean(&val, &b);
1803 if(SUCCEEDED(hres) && b) {
1804 ret->type = EXPRVAL_VARIANT;
1813 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1817 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1818 exprval_release(&exprval);
1822 ret->type = EXPRVAL_VARIANT;
1827 /* ECMA-262 3rd Edition 11.11 */
1828 HRESULT logical_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1830 binary_expression_t *expr = (binary_expression_t*)_expr;
1838 hres = expr_eval(ctx, expr->expression1, 0, ei, &exprval);
1842 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1843 exprval_release(&exprval);
1847 hres = to_boolean(&val, &b);
1848 if(SUCCEEDED(hres) && !b) {
1849 ret->type = EXPRVAL_VARIANT;
1858 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprval);
1862 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
1863 exprval_release(&exprval);
1867 ret->type = EXPRVAL_VARIANT;
1872 /* ECMA-262 3rd Edition 11.10 */
1873 static HRESULT bitor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1878 hres = to_int32(ctx->parser->script, lval, ei, &li);
1882 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1891 /* ECMA-262 3rd Edition 11.10 */
1892 HRESULT binary_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
1894 binary_expression_t *expr = (binary_expression_t*)_expr;
1898 return binary_expr_eval(ctx, expr, bitor_eval, ei, ret);
1901 /* ECMA-262 3rd Edition 11.10 */
1902 static HRESULT xor_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1907 hres = to_int32(ctx->parser->script, lval, ei, &li);
1911 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1920 /* ECMA-262 3rd Edition 11.10 */
1921 HRESULT binary_xor_expression_eval(exec_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, xor_eval, ei, ret);
1930 /* ECMA-262 3rd Edition 11.10 */
1931 static HRESULT bitand_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
1936 hres = to_int32(ctx->parser->script, lval, ei, &li);
1940 hres = to_int32(ctx->parser->script, rval, ei, &ri);
1949 /* ECMA-262 3rd Edition 11.10 */
1950 HRESULT binary_and_expression_eval(exec_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, bitand_eval, ei, ret);
1959 /* ECMA-262 3rd Edition 11.8.6 */
1960 static HRESULT instanceof_eval(exec_ctx_t *ctx, VARIANT *inst, VARIANT *objv, jsexcept_t *ei, VARIANT *retv)
1962 DispatchEx *obj, *iter, *tmp = NULL;
1963 VARIANT_BOOL ret = VARIANT_FALSE;
1968 static const WCHAR prototypeW[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
1970 if(V_VT(objv) != VT_DISPATCH) {
1971 FIXME("throw TypeError\n");
1975 obj = iface_to_jsdisp((IUnknown*)V_DISPATCH(objv));
1977 FIXME("throw TypeError\n");
1981 if(is_class(obj, JSCLASS_FUNCTION)) {
1982 hres = jsdisp_propget_name(obj, prototypeW, ctx->parser->script->lcid, &var, ei, NULL/*FIXME*/);
1984 FIXME("throw TypeError\n");
1987 jsdisp_release(obj);
1991 if(V_VT(&var) == VT_DISPATCH) {
1992 if(V_VT(inst) == VT_DISPATCH)
1993 tmp = iface_to_jsdisp((IUnknown*)V_DISPATCH(inst));
1994 for(iter = tmp; iter; iter = iter->prototype) {
1995 hres = disp_cmp(V_DISPATCH(&var), (IDispatch*)_IDispatchEx_(iter), &b);
2005 jsdisp_release(tmp);
2007 FIXME("prototype is not an object\n");
2015 V_VT(retv) = VT_BOOL;
2020 /* ECMA-262 3rd Edition 11.8.6 */
2021 HRESULT instanceof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2023 binary_expression_t *expr = (binary_expression_t*)_expr;
2027 return binary_expr_eval(ctx, expr, instanceof_eval, ei, ret);
2030 /* ECMA-262 3rd Edition 11.8.7 */
2031 static HRESULT in_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *obj, jsexcept_t *ei, VARIANT *retv)
2038 if(V_VT(obj) != VT_DISPATCH) {
2039 FIXME("throw TypeError\n");
2043 hres = to_string(ctx->parser->script, lval, ei, &str);
2047 hres = disp_get_id(V_DISPATCH(obj), str, 0, &id);
2051 else if(hres == DISP_E_UNKNOWNNAME)
2052 ret = VARIANT_FALSE;
2056 V_VT(retv) = VT_BOOL;
2061 /* ECMA-262 3rd Edition 11.8.7 */
2062 HRESULT in_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2064 binary_expression_t *expr = (binary_expression_t*)_expr;
2068 return binary_expr_eval(ctx, expr, in_eval, ei, ret);
2071 /* ECMA-262 3rd Edition 11.6.1 */
2072 static HRESULT add_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2077 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
2081 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
2087 if(V_VT(&l) == VT_BSTR || V_VT(&r) == VT_BSTR) {
2088 BSTR lstr = NULL, rstr = NULL;
2090 if(V_VT(&l) == VT_BSTR)
2093 hres = to_string(ctx->parser->script, &l, ei, &lstr);
2095 if(SUCCEEDED(hres)) {
2096 if(V_VT(&r) == VT_BSTR)
2099 hres = to_string(ctx->parser->script, &r, ei, &rstr);
2102 if(SUCCEEDED(hres)) {
2105 len1 = SysStringLen(lstr);
2106 len2 = SysStringLen(rstr);
2108 V_VT(retv) = VT_BSTR;
2109 V_BSTR(retv) = SysAllocStringLen(NULL, len1+len2);
2110 memcpy(V_BSTR(retv), lstr, len1*sizeof(WCHAR));
2111 memcpy(V_BSTR(retv)+len1, rstr, (len2+1)*sizeof(WCHAR));
2114 if(V_VT(&l) != VT_BSTR)
2115 SysFreeString(lstr);
2116 if(V_VT(&r) != VT_BSTR)
2117 SysFreeString(rstr);
2121 hres = to_number(ctx->parser->script, &l, ei, &nl);
2122 if(SUCCEEDED(hres)) {
2123 hres = to_number(ctx->parser->script, &r, ei, &nr);
2125 num_set_val(retv, num_val(&nl) + num_val(&nr));
2134 /* ECMA-262 3rd Edition 11.6.1 */
2135 HRESULT add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2137 binary_expression_t *expr = (binary_expression_t*)_expr;
2141 return binary_expr_eval(ctx, expr, add_eval, ei, ret);
2144 /* ECMA-262 3rd Edition 11.6.2 */
2145 static HRESULT sub_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2150 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2154 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2158 num_set_val(retv, num_val(&lnum) - num_val(&rnum));
2162 /* ECMA-262 3rd Edition 11.6.2 */
2163 HRESULT sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2165 binary_expression_t *expr = (binary_expression_t*)_expr;
2169 return binary_expr_eval(ctx, expr, sub_eval, ei, ret);
2172 /* ECMA-262 3rd Edition 11.5.1 */
2173 static HRESULT mul_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2178 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2182 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2186 num_set_val(retv, num_val(&lnum) * num_val(&rnum));
2190 /* ECMA-262 3rd Edition 11.5.1 */
2191 HRESULT mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2193 binary_expression_t *expr = (binary_expression_t*)_expr;
2197 return binary_expr_eval(ctx, expr, mul_eval, ei, ret);
2200 /* ECMA-262 3rd Edition 11.5.2 */
2201 static HRESULT div_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2206 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2210 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2214 num_set_val(retv, num_val(&lnum) / num_val(&rnum));
2218 /* ECMA-262 3rd Edition 11.5.2 */
2219 HRESULT div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2221 binary_expression_t *expr = (binary_expression_t*)_expr;
2225 return binary_expr_eval(ctx, expr, div_eval, ei, ret);
2228 /* ECMA-262 3rd Edition 11.5.3 */
2229 static HRESULT mod_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2234 hres = to_number(ctx->parser->script, lval, ei, &lnum);
2238 hres = to_number(ctx->parser->script, rval, ei, &rnum);
2242 num_set_val(retv, fmod(num_val(&lnum), num_val(&rnum)));
2246 /* ECMA-262 3rd Edition 11.5.3 */
2247 HRESULT mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2249 binary_expression_t *expr = (binary_expression_t*)_expr;
2253 return binary_expr_eval(ctx, expr, mod_eval, ei, ret);
2256 /* ECMA-262 3rd Edition 11.4.2 */
2257 HRESULT delete_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2259 unary_expression_t *expr = (unary_expression_t*)_expr;
2260 VARIANT_BOOL b = VARIANT_FALSE;
2266 hres = expr_eval(ctx, expr->expression, EXPR_STRREF, ei, &exprval);
2270 switch(exprval.type) {
2271 case EXPRVAL_IDREF: {
2272 IDispatchEx *dispex;
2274 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2275 if(SUCCEEDED(hres)) {
2276 hres = IDispatchEx_DeleteMemberByDispID(dispex, exprval.u.idref.id);
2278 IDispatchEx_Release(dispex);
2282 case EXPRVAL_NAMEREF: {
2283 IDispatchEx *dispex;
2285 hres = IDispatch_QueryInterface(exprval.u.nameref.disp, &IID_IDispatchEx, (void**)&dispex);
2286 if(SUCCEEDED(hres)) {
2287 hres = IDispatchEx_DeleteMemberByName(dispex, exprval.u.nameref.name, fdexNameCaseSensitive);
2289 IDispatchEx_Release(dispex);
2294 FIXME("unsupported type %d\n", exprval.type);
2298 exprval_release(&exprval);
2302 return return_bool(ret, b);
2305 /* ECMA-262 3rd Edition 11.4.2 */
2306 HRESULT void_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2308 unary_expression_t *expr = (unary_expression_t*)_expr;
2315 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2319 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &tmp);
2320 exprval_release(&exprval);
2326 ret->type = EXPRVAL_VARIANT;
2327 V_VT(&ret->u.var) = VT_EMPTY;
2331 /* ECMA-262 3rd Edition 11.4.3 */
2332 static HRESULT typeof_exprval(exec_ctx_t *ctx, exprval_t *exprval, jsexcept_t *ei, const WCHAR **ret)
2337 static const WCHAR booleanW[] = {'b','o','o','l','e','a','n',0};
2338 static const WCHAR functionW[] = {'f','u','n','c','t','i','o','n',0};
2339 static const WCHAR numberW[] = {'n','u','m','b','e','r',0};
2340 static const WCHAR objectW[] = {'o','b','j','e','c','t',0};
2341 static const WCHAR stringW[] = {'s','t','r','i','n','g',0};
2342 static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
2344 if(exprval->type == EXPRVAL_INVALID) {
2349 hres = exprval_to_value(ctx->parser->script, exprval, ei, &val);
2353 switch(V_VT(&val)) {
2373 if(V_DISPATCH(&val) && (dispex = iface_to_jsdisp((IUnknown*)V_DISPATCH(&val)))) {
2374 *ret = is_class(dispex, JSCLASS_FUNCTION) ? functionW : objectW;
2375 jsdisp_release(dispex);
2382 FIXME("unhandled vt %d\n", V_VT(&val));
2390 HRESULT typeof_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2392 unary_expression_t *expr = (unary_expression_t*)_expr;
2393 const WCHAR *str = NULL;
2399 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2403 hres = typeof_exprval(ctx, &exprval, ei, &str);
2404 exprval_release(&exprval);
2408 ret->type = EXPRVAL_VARIANT;
2409 V_VT(&ret->u.var) = VT_BSTR;
2410 V_BSTR(&ret->u.var) = SysAllocString(str);
2411 if(!V_BSTR(&ret->u.var))
2412 return E_OUTOFMEMORY;
2417 /* ECMA-262 3rd Edition 11.4.7 */
2418 HRESULT minus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2420 unary_expression_t *expr = (unary_expression_t*)_expr;
2427 hres = expr_eval(ctx, expr->expression, 0, ei, &exprval);
2431 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2432 exprval_release(&exprval);
2436 hres = to_number(ctx->parser->script, &val, ei, &num);
2441 ret->type = EXPRVAL_VARIANT;
2442 num_set_val(&ret->u.var, -num_val(&num));
2446 /* ECMA-262 3rd Edition 11.4.6 */
2447 HRESULT plus_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2449 unary_expression_t *expr = (unary_expression_t*)_expr;
2456 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2460 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2461 exprval_release(&exprval);
2465 hres = to_number(ctx->parser->script, &val, ei, &num);
2469 ret->type = EXPRVAL_VARIANT;
2474 /* ECMA-262 3rd Edition 11.3.1 */
2475 HRESULT post_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2477 unary_expression_t *expr = (unary_expression_t*)_expr;
2484 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2488 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2489 if(SUCCEEDED(hres)) {
2490 hres = to_number(ctx->parser->script, &val, ei, &num);
2494 if(SUCCEEDED(hres)) {
2496 num_set_val(&inc, num_val(&num)+1.0);
2497 hres = put_value(ctx->parser->script, &exprval, &inc, ei);
2500 exprval_release(&exprval);
2504 ret->type = EXPRVAL_VARIANT;
2509 /* ECMA-262 3rd Edition 11.3.2 */
2510 HRESULT post_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2512 unary_expression_t *expr = (unary_expression_t*)_expr;
2519 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2523 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2524 if(SUCCEEDED(hres)) {
2525 hres = to_number(ctx->parser->script, &val, ei, &num);
2529 if(SUCCEEDED(hres)) {
2531 num_set_val(&dec, num_val(&num)-1.0);
2532 hres = put_value(ctx->parser->script, &exprval, &dec, ei);
2535 exprval_release(&exprval);
2539 ret->type = EXPRVAL_VARIANT;
2544 /* ECMA-262 3rd Edition 11.4.4 */
2545 HRESULT pre_increment_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2547 unary_expression_t *expr = (unary_expression_t*)_expr;
2554 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2558 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2559 if(SUCCEEDED(hres)) {
2560 hres = to_number(ctx->parser->script, &val, ei, &num);
2564 if(SUCCEEDED(hres)) {
2565 num_set_val(&val, num_val(&num)+1.0);
2566 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2569 exprval_release(&exprval);
2573 ret->type = EXPRVAL_VARIANT;
2578 /* ECMA-262 3rd Edition 11.4.5 */
2579 HRESULT pre_decrement_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2581 unary_expression_t *expr = (unary_expression_t*)_expr;
2588 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2592 hres = exprval_value(ctx->parser->script, &exprval, ei, &val);
2593 if(SUCCEEDED(hres)) {
2594 hres = to_number(ctx->parser->script, &val, ei, &num);
2598 if(SUCCEEDED(hres)) {
2599 num_set_val(&val, num_val(&num)-1.0);
2600 hres = put_value(ctx->parser->script, &exprval, &val, ei);
2603 exprval_release(&exprval);
2607 ret->type = EXPRVAL_VARIANT;
2612 /* ECMA-262 3rd Edition 11.9.3 */
2613 static HRESULT equal_values(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, BOOL *ret)
2615 if(V_VT(lval) == V_VT(rval) || (is_num_vt(V_VT(lval)) && is_num_vt(V_VT(rval))))
2616 return equal2_values(lval, rval, ret);
2618 /* FIXME: NULL disps should be handled in more general way */
2619 if(V_VT(lval) == VT_DISPATCH && !V_DISPATCH(lval)) {
2622 return equal_values(ctx, &v, rval, ei, ret);
2625 if(V_VT(rval) == VT_DISPATCH && !V_DISPATCH(rval)) {
2628 return equal_values(ctx, lval, &v, ei, ret);
2631 if((V_VT(lval) == VT_NULL && V_VT(rval) == VT_EMPTY) ||
2632 (V_VT(lval) == VT_EMPTY && V_VT(rval) == VT_NULL)) {
2637 if(V_VT(lval) == VT_BSTR && is_num_vt(V_VT(rval))) {
2641 hres = to_number(ctx->parser->script, lval, ei, &v);
2645 return equal_values(ctx, &v, rval, ei, ret);
2648 if(V_VT(rval) == VT_BSTR && is_num_vt(V_VT(lval))) {
2652 hres = to_number(ctx->parser->script, rval, ei, &v);
2656 return equal_values(ctx, lval, &v, ei, ret);
2659 if(V_VT(rval) == VT_BOOL) {
2663 V_I4(&v) = V_BOOL(rval) ? 1 : 0;
2664 return equal_values(ctx, lval, &v, ei, ret);
2667 if(V_VT(lval) == VT_BOOL) {
2671 V_I4(&v) = V_BOOL(lval) ? 1 : 0;
2672 return equal_values(ctx, &v, rval, ei, ret);
2676 if(V_VT(rval) == VT_DISPATCH && (V_VT(lval) == VT_BSTR || is_num_vt(V_VT(lval)))) {
2680 hres = to_primitive(ctx->parser->script, rval, ei, &v, NO_HINT);
2684 hres = equal_values(ctx, lval, &v, ei, ret);
2691 if(V_VT(lval) == VT_DISPATCH && (V_VT(rval) == VT_BSTR || is_num_vt(V_VT(rval)))) {
2695 hres = to_primitive(ctx->parser->script, lval, ei, &v, NO_HINT);
2699 hres = equal_values(ctx, &v, rval, ei, ret);
2710 /* ECMA-262 3rd Edition 11.9.1 */
2711 HRESULT equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2713 binary_expression_t *expr = (binary_expression_t*)_expr;
2720 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2724 hres = equal_values(ctx, &rval, &lval, ei, &b);
2728 return return_bool(ret, b);
2731 /* ECMA-262 3rd Edition 11.9.4 */
2732 HRESULT equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2734 binary_expression_t *expr = (binary_expression_t*)_expr;
2741 hres = get_binary_expr_values(ctx, expr, ei, &rval, &lval);
2745 hres = equal2_values(&rval, &lval, &b);
2749 return return_bool(ret, b);
2752 /* ECMA-262 3rd Edition 11.9.2 */
2753 HRESULT not_equal_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2755 binary_expression_t *expr = (binary_expression_t*)_expr;
2762 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2766 hres = equal_values(ctx, &lval, &rval, ei, &b);
2770 return return_bool(ret, !b);
2773 /* ECMA-262 3rd Edition 11.9.5 */
2774 HRESULT not_equal2_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2776 binary_expression_t *expr = (binary_expression_t*)_expr;
2783 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2787 hres = equal2_values(&lval, &rval, &b);
2791 return return_bool(ret, !b);
2794 /* ECMA-262 3rd Edition 11.8.5 */
2795 static HRESULT less_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, BOOL greater, jsexcept_t *ei, BOOL *ret)
2797 VARIANT l, r, ln, rn;
2800 hres = to_primitive(ctx->parser->script, lval, ei, &l, NO_HINT);
2804 hres = to_primitive(ctx->parser->script, rval, ei, &r, NO_HINT);
2810 if(V_VT(&l) == VT_BSTR && V_VT(&r) == VT_BSTR) {
2811 *ret = (strcmpW(V_BSTR(&l), V_BSTR(&r)) < 0) ^ greater;
2812 SysFreeString(V_BSTR(&l));
2813 SysFreeString(V_BSTR(&r));
2817 hres = to_number(ctx->parser->script, &l, ei, &ln);
2820 hres = to_number(ctx->parser->script, &r, ei, &rn);
2825 if(V_VT(&ln) == VT_I4 && V_VT(&rn) == VT_I4) {
2826 *ret = (V_I4(&ln) < V_I4(&rn)) ^ greater;
2828 DOUBLE ld = num_val(&ln);
2829 DOUBLE rd = num_val(&rn);
2831 *ret = !isnan(ld) && !isnan(rd) && ((ld < rd) ^ greater);
2837 /* ECMA-262 3rd Edition 11.8.1 */
2838 HRESULT less_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2840 binary_expression_t *expr = (binary_expression_t*)_expr;
2847 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2851 hres = less_eval(ctx, &lval, &rval, FALSE, ei, &b);
2852 VariantClear(&lval);
2853 VariantClear(&rval);
2857 return return_bool(ret, b);
2860 /* ECMA-262 3rd Edition 11.8.3 */
2861 HRESULT lesseq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2863 binary_expression_t *expr = (binary_expression_t*)_expr;
2870 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2874 hres = less_eval(ctx, &rval, &lval, TRUE, ei, &b);
2875 VariantClear(&lval);
2876 VariantClear(&rval);
2880 return return_bool(ret, b);
2883 /* ECMA-262 3rd Edition 11.8.2 */
2884 HRESULT greater_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2886 binary_expression_t *expr = (binary_expression_t*)_expr;
2893 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2897 hres = less_eval(ctx, &rval, &lval, FALSE, ei, &b);
2898 VariantClear(&lval);
2899 VariantClear(&rval);
2903 return return_bool(ret, b);
2906 /* ECMA-262 3rd Edition 11.8.4 */
2907 HRESULT greatereq_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2909 binary_expression_t *expr = (binary_expression_t*)_expr;
2916 hres = get_binary_expr_values(ctx, expr, ei, &lval, &rval);
2920 hres = less_eval(ctx, &lval, &rval, TRUE, ei, &b);
2921 VariantClear(&lval);
2922 VariantClear(&rval);
2926 return return_bool(ret, b);
2929 /* ECMA-262 3rd Edition 11.4.8 */
2930 HRESULT binary_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2932 unary_expression_t *expr = (unary_expression_t*)_expr;
2940 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2944 hres = exprval_to_value(ctx->parser->script, &exprval, ei, &val);
2945 exprval_release(&exprval);
2949 hres = to_int32(ctx->parser->script, &val, ei, &i);
2953 ret->type = EXPRVAL_VARIANT;
2954 V_VT(&ret->u.var) = VT_I4;
2955 V_I4(&ret->u.var) = ~i;
2959 /* ECMA-262 3rd Edition 11.4.9 */
2960 HRESULT logical_negation_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
2962 unary_expression_t *expr = (unary_expression_t*)_expr;
2969 hres = expr_eval(ctx, expr->expression, EXPR_NEWREF, ei, &exprval);
2973 hres = exprval_to_boolean(ctx->parser->script, &exprval, ei, &b);
2974 exprval_release(&exprval);
2978 return return_bool(ret, !b);
2981 /* ECMA-262 3rd Edition 11.7.1 */
2982 static HRESULT lshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
2988 hres = to_int32(ctx->parser->script, lval, ei, &li);
2992 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
2997 V_I4(retv) = li << (ri&0x1f);
3001 /* ECMA-262 3rd Edition 11.7.1 */
3002 HRESULT left_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3004 binary_expression_t *expr = (binary_expression_t*)_expr;
3008 return binary_expr_eval(ctx, expr, lshift_eval, ei, ret);
3011 /* ECMA-262 3rd Edition 11.7.2 */
3012 static HRESULT rshift_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3018 hres = to_int32(ctx->parser->script, lval, ei, &li);
3022 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3027 V_I4(retv) = li >> (ri&0x1f);
3031 /* ECMA-262 3rd Edition 11.7.2 */
3032 HRESULT right_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3034 binary_expression_t *expr = (binary_expression_t*)_expr;
3038 return binary_expr_eval(ctx, expr, rshift_eval, ei, ret);
3041 /* ECMA-262 3rd Edition 11.7.3 */
3042 static HRESULT rshift2_eval(exec_ctx_t *ctx, VARIANT *lval, VARIANT *rval, jsexcept_t *ei, VARIANT *retv)
3047 hres = to_uint32(ctx->parser->script, lval, ei, &li);
3051 hres = to_uint32(ctx->parser->script, rval, ei, &ri);
3056 V_I4(retv) = li >> (ri&0x1f);
3060 /* ECMA-262 3rd Edition 11.7.3 */
3061 HRESULT right2_shift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3063 binary_expression_t *expr = (binary_expression_t*)_expr;
3067 return binary_expr_eval(ctx, expr, rshift2_eval, ei, ret);
3070 /* ECMA-262 3rd Edition 11.13.1 */
3071 HRESULT assign_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3073 binary_expression_t *expr = (binary_expression_t*)_expr;
3074 exprval_t exprval, exprvalr;
3080 hres = expr_eval(ctx, expr->expression1, EXPR_NEWREF, ei, &exprval);
3084 hres = expr_eval(ctx, expr->expression2, 0, ei, &exprvalr);
3085 if(SUCCEEDED(hres)) {
3086 hres = exprval_to_value(ctx->parser->script, &exprvalr, ei, &rval);
3087 exprval_release(&exprvalr);
3091 hres = put_value(ctx->parser->script, &exprval, &rval, ei);
3093 exprval_release(&exprval);
3097 ret->type = EXPRVAL_VARIANT;
3102 /* ECMA-262 3rd Edition 11.13.2 */
3103 HRESULT assign_lshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3105 binary_expression_t *expr = (binary_expression_t*)_expr;
3109 return assign_oper_eval(ctx, expr->expression1, expr->expression2, lshift_eval, ei, ret);
3112 /* ECMA-262 3rd Edition 11.13.2 */
3113 HRESULT assign_rshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3115 binary_expression_t *expr = (binary_expression_t*)_expr;
3119 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift_eval, ei, ret);
3122 /* ECMA-262 3rd Edition 11.13.2 */
3123 HRESULT assign_rrshift_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3125 binary_expression_t *expr = (binary_expression_t*)_expr;
3129 return assign_oper_eval(ctx, expr->expression1, expr->expression2, rshift2_eval, ei, ret);
3132 /* ECMA-262 3rd Edition 11.13.2 */
3133 HRESULT assign_add_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3135 binary_expression_t *expr = (binary_expression_t*)_expr;
3139 return assign_oper_eval(ctx, expr->expression1, expr->expression2, add_eval, ei, ret);
3142 /* ECMA-262 3rd Edition 11.13.2 */
3143 HRESULT assign_sub_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3145 binary_expression_t *expr = (binary_expression_t*)_expr;
3149 return assign_oper_eval(ctx, expr->expression1, expr->expression2, sub_eval, ei, ret);
3152 /* ECMA-262 3rd Edition 11.13.2 */
3153 HRESULT assign_mul_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3155 binary_expression_t *expr = (binary_expression_t*)_expr;
3159 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mul_eval, ei, ret);
3162 /* ECMA-262 3rd Edition 11.13.2 */
3163 HRESULT assign_div_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3165 binary_expression_t *expr = (binary_expression_t*)_expr;
3169 return assign_oper_eval(ctx, expr->expression1, expr->expression2, div_eval, ei, ret);
3172 /* ECMA-262 3rd Edition 11.13.2 */
3173 HRESULT assign_mod_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3175 binary_expression_t *expr = (binary_expression_t*)_expr;
3179 return assign_oper_eval(ctx, expr->expression1, expr->expression2, mod_eval, ei, ret);
3182 /* ECMA-262 3rd Edition 11.13.2 */
3183 HRESULT assign_and_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3185 binary_expression_t *expr = (binary_expression_t*)_expr;
3189 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitand_eval, ei, ret);
3192 /* ECMA-262 3rd Edition 11.13.2 */
3193 HRESULT assign_or_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3195 binary_expression_t *expr = (binary_expression_t*)_expr;
3199 return assign_oper_eval(ctx, expr->expression1, expr->expression2, bitor_eval, ei, ret);
3202 /* ECMA-262 3rd Edition 11.13.2 */
3203 HRESULT assign_xor_expression_eval(exec_ctx_t *ctx, expression_t *_expr, DWORD flags, jsexcept_t *ei, exprval_t *ret)
3205 binary_expression_t *expr = (binary_expression_t*)_expr;
3209 return assign_oper_eval(ctx, expr->expression1, expr->expression2, xor_eval, ei, ret);