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
);
63 /* ECMA-262 3rd Edition 8.7.1 */
64 static HRESULT
exprval_value(script_ctx_t
*ctx
, exprval_t
*val
, jsexcept_t
*ei
, VARIANT
*ret
)
70 return VariantCopy(ret
, &val
->u
.var
);
72 if(!val
->u
.idref
.disp
) {
73 FIXME("throw ReferenceError\n");
77 return disp_propget(val
->u
.idref
.disp
, val
->u
.idref
.id
, ctx
->lcid
, ret
, ei
, NULL
/*FIXME*/);
79 ERR("type %d\n", val
->type
);
84 static HRESULT
exprval_to_value(script_ctx_t
*ctx
, exprval_t
*val
, jsexcept_t
*ei
, VARIANT
*ret
)
86 if(val
->type
== EXPRVAL_VARIANT
) {
88 V_VT(&val
->u
.var
) = VT_EMPTY
;
92 return exprval_value(ctx
, val
, ei
, ret
);
95 static HRESULT
exprval_to_boolean(script_ctx_t
*ctx
, exprval_t
*exprval
, jsexcept_t
*ei
, VARIANT_BOOL
*b
)
97 if(exprval
->type
!= EXPRVAL_VARIANT
) {
101 hres
= exprval_to_value(ctx
, exprval
, ei
, &val
);
105 hres
= to_boolean(&val
, b
);
110 return to_boolean(&exprval
->u
.var
, b
);
113 static void exprval_init(exprval_t
*val
)
115 val
->type
= EXPRVAL_VARIANT
;
116 V_VT(&val
->u
.var
) = VT_EMPTY
;
119 static void exprval_set_idref(exprval_t
*val
, IDispatch
*disp
, DISPID id
)
121 val
->type
= EXPRVAL_IDREF
;
122 val
->u
.idref
.disp
= disp
;
123 val
->u
.idref
.id
= id
;
126 IDispatch_AddRef(disp
);
129 HRESULT
scope_push(scope_chain_t
*scope
, DispatchEx
*obj
, scope_chain_t
**ret
)
131 scope_chain_t
*new_scope
;
133 new_scope
= heap_alloc(sizeof(scope_chain_t
));
135 return E_OUTOFMEMORY
;
139 IDispatchEx_AddRef(_IDispatchEx_(obj
));
140 new_scope
->obj
= obj
;
144 new_scope
->next
= scope
;
146 new_scope
->next
= NULL
;
153 static void scope_pop(scope_chain_t
**scope
)
162 void scope_release(scope_chain_t
*scope
)
168 scope_release(scope
->next
);
170 IDispatchEx_Release(_IDispatchEx_(scope
->obj
));
174 HRESULT
create_exec_ctx(IDispatch
*this_obj
, DispatchEx
*var_disp
, scope_chain_t
*scope
, exec_ctx_t
**ret
)
178 ctx
= heap_alloc_zero(sizeof(exec_ctx_t
));
180 return E_OUTOFMEMORY
;
182 IDispatch_AddRef(this_obj
);
183 ctx
->this_obj
= this_obj
;
185 IDispatchEx_AddRef(_IDispatchEx_(var_disp
));
186 ctx
->var_disp
= var_disp
;
190 ctx
->scope_chain
= scope
;
197 void exec_release(exec_ctx_t
*ctx
)
203 scope_release(ctx
->scope_chain
);
205 IDispatchEx_Release(_IDispatchEx_(ctx
->var_disp
));
207 IDispatch_Release(ctx
->this_obj
);
211 static HRESULT
disp_get_id(IDispatch
*disp
, BSTR name
, DWORD flags
, DISPID
*id
)
216 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
218 TRACE("unsing IDispatch\n");
221 return IDispatch_GetIDsOfNames(disp
, &IID_NULL
, &name
, 1, 0, id
);
225 hres
= IDispatchEx_GetDispID(dispex
, name
, flags
|fdexNameCaseSensitive
, id
);
226 IDispatchEx_Release(dispex
);
230 /* ECMA-262 3rd Edition 8.7.2 */
231 static HRESULT
put_value(script_ctx_t
*ctx
, exprval_t
*ref
, VARIANT
*v
, jsexcept_t
*ei
)
233 if(ref
->type
!= EXPRVAL_IDREF
) {
234 FIXME("throw ReferemceError\n");
238 return disp_propput(ref
->u
.idref
.disp
, ref
->u
.idref
.id
, ctx
->lcid
, v
, ei
, NULL
/*FIXME*/);
241 static HRESULT
disp_cmp(IDispatch
*disp1
, IDispatch
*disp2
, BOOL
*ret
)
243 IObjectIdentity
*identity
;
244 IUnknown
*unk1
, *unk2
;
252 hres
= IDispatch_QueryInterface(disp1
, &IID_IUnknown
, (void**)&unk1
);
256 hres
= IDispatch_QueryInterface(disp2
, &IID_IUnknown
, (void**)&unk2
);
258 IUnknown_Release(unk1
);
265 hres
= IUnknown_QueryInterface(unk1
, &IID_IObjectIdentity
, (void**)&identity
);
266 if(SUCCEEDED(hres
)) {
267 hres
= IObjectIdentity_IsEqualObject(identity
, unk2
);
268 IObjectIdentity_Release(identity
);
275 IUnknown_Release(unk1
);
276 IUnknown_Release(unk2
);
280 /* ECMA-262 3rd Edition 11.9.6 */
281 static HRESULT
equal2_values(VARIANT
*lval
, VARIANT
*rval
, BOOL
*ret
)
285 if(V_VT(lval
) != V_VT(rval
)) {
286 if(is_num_vt(V_VT(lval
)) && is_num_vt(V_VT(rval
))) {
287 *ret
= num_val(lval
) == num_val(rval
);
301 *ret
= V_I4(lval
) == V_I4(rval
);
304 *ret
= V_R8(lval
) == V_R8(rval
);
307 *ret
= !strcmpW(V_BSTR(lval
), V_BSTR(rval
));
310 return disp_cmp(V_DISPATCH(lval
), V_DISPATCH(rval
), ret
);
312 *ret
= !V_BOOL(lval
) == !V_BOOL(rval
);
315 FIXME("unimplemented vt %d\n", V_VT(lval
));
322 static HRESULT
literal_to_var(literal_t
*literal
, VARIANT
*v
)
324 V_VT(v
) = literal
->vt
;
331 V_I4(v
) = literal
->u
.lval
;
334 V_R8(v
) = literal
->u
.dval
;
337 V_BSTR(v
) = SysAllocString(literal
->u
.wstr
);
340 V_BOOL(v
) = literal
->u
.bval
;
343 IDispatch_AddRef(literal
->u
.disp
);
344 V_DISPATCH(v
) = literal
->u
.disp
;
347 ERR("wrong type %d\n", V_VT(v
));
354 HRESULT
exec_source(exec_ctx_t
*ctx
, parser_ctx_t
*parser
, source_elements_t
*source
, jsexcept_t
*ei
, VARIANT
*retv
)
356 script_ctx_t
*script
= parser
->script
;
357 function_declaration_t
*func
;
358 parser_ctx_t
*prev_parser
;
362 exec_ctx_t
*prev_ctx
;
366 for(func
= source
->functions
; func
; func
= func
->next
) {
367 DispatchEx
*func_obj
;
370 hres
= create_source_function(parser
, func
->expr
->parameter_list
, func
->expr
->source_elements
,
371 ctx
->scope_chain
, func
->expr
->src_str
, func
->expr
->src_len
, &func_obj
);
375 V_VT(&var
) = VT_DISPATCH
;
376 V_DISPATCH(&var
) = (IDispatch
*)_IDispatchEx_(func_obj
);
377 hres
= jsdisp_propput_name(ctx
->var_disp
, func
->expr
->identifier
, script
->lcid
, &var
, ei
, NULL
);
378 jsdisp_release(func_obj
);
383 for(var
= source
->variables
; var
; var
= var
->next
) {
386 hres
= jsdisp_get_id(ctx
->var_disp
, var
->identifier
, fdexNameEnsure
, &id
);
391 prev_ctx
= script
->exec_ctx
;
392 script
->exec_ctx
= ctx
;
394 prev_parser
= ctx
->parser
;
395 ctx
->parser
= parser
;
397 V_VT(&val
) = VT_EMPTY
;
398 memset(&rt
, 0, sizeof(rt
));
401 for(stat
= source
->statement
; stat
; stat
= stat
->next
) {
402 hres
= stat_eval(ctx
, stat
, &rt
, &tmp
);
408 if(rt
.type
!= RT_NORMAL
)
412 script
->exec_ctx
= prev_ctx
;
413 ctx
->parser
= prev_parser
;
415 if(rt
.type
!= RT_NORMAL
&& rt
.type
!= RT_RETURN
) {
416 FIXME("wrong rt %d\n", rt
.type
);
433 /* ECMA-262 3rd Edition 10.1.4 */
434 static HRESULT
identifier_eval(exec_ctx_t
*ctx
, BSTR identifier
, DWORD flags
, exprval_t
*ret
)
436 scope_chain_t
*scope
;
441 TRACE("%s\n", debugstr_w(identifier
));
443 for(scope
= ctx
->scope_chain
; scope
; scope
= scope
->next
) {
444 hres
= jsdisp_get_id(scope
->obj
, identifier
, 0, &id
);
450 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(scope
->obj
), id
);
454 hres
= jsdisp_get_id(ctx
->parser
->script
->global
, identifier
, 0, &id
);
455 if(SUCCEEDED(hres
)) {
456 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->parser
->script
->global
), id
);
460 for(item
= ctx
->parser
->script
->named_items
; item
; item
= item
->next
) {
461 if((item
->flags
& SCRIPTITEM_ISVISIBLE
) && !strcmpW(item
->name
, identifier
)) {
465 if(!ctx
->parser
->script
->site
)
468 hres
= IActiveScriptSite_GetItemInfo(ctx
->parser
->script
->site
, identifier
,
469 SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
471 WARN("GetItemInfo failed: %08x\n", hres
);
475 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&item
->disp
);
476 IUnknown_Release(unk
);
478 WARN("object does not implement IDispatch\n");
483 ret
->type
= EXPRVAL_VARIANT
;
484 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
485 V_DISPATCH(&ret
->u
.var
) = item
->disp
;
486 IDispatch_AddRef(item
->disp
);
491 for(item
= ctx
->parser
->script
->named_items
; item
; item
= item
->next
) {
492 hres
= disp_get_id(item
->disp
, identifier
, 0, &id
);
498 exprval_set_idref(ret
, (IDispatch
*)item
->disp
, id
);
502 hres
= jsdisp_get_id(ctx
->parser
->script
->script_disp
, identifier
, 0, &id
);
503 if(SUCCEEDED(hres
)) {
504 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->parser
->script
->script_disp
), id
);
508 if(flags
& EXPR_NEWREF
) {
509 hres
= jsdisp_get_id(ctx
->var_disp
, identifier
, fdexNameEnsure
, &id
);
513 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->var_disp
), id
);
517 WARN("Could not find identifier %s\n", debugstr_w(identifier
));
521 /* ECMA-262 3rd Edition 12.1 */
522 HRESULT
block_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
524 block_statement_t
*stat
= (block_statement_t
*)_stat
;
531 V_VT(&val
) = VT_EMPTY
;
532 for(iter
= stat
->stat_list
; iter
; iter
= iter
->next
) {
533 hres
= stat_eval(ctx
, iter
, rt
, &tmp
);
539 if(rt
->type
!= RT_NORMAL
)
552 /* ECMA-262 3rd Edition 12.2 */
553 static HRESULT
variable_list_eval(exec_ctx_t
*ctx
, variable_declaration_t
*var_list
, jsexcept_t
*ei
)
555 variable_declaration_t
*iter
;
558 for(iter
= var_list
; iter
; iter
= iter
->next
) {
565 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
569 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
570 exprval_release(&exprval
);
574 hres
= jsdisp_propput_name(ctx
->var_disp
, iter
->identifier
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
583 /* ECMA-262 3rd Edition 12.2 */
584 HRESULT
var_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
586 var_statement_t
*stat
= (var_statement_t
*)_stat
;
591 hres
= variable_list_eval(ctx
, stat
->variable_list
, &rt
->ei
);
595 V_VT(ret
) = VT_EMPTY
;
599 /* ECMA-262 3rd Edition 12.3 */
600 HRESULT
empty_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
604 V_VT(ret
) = VT_EMPTY
;
608 /* ECMA-262 3rd Edition 12.4 */
609 HRESULT
expression_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
611 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
618 hres
= expr_eval(ctx
, stat
->expr
, EXPR_NOVAL
, &rt
->ei
, &exprval
);
622 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
623 exprval_release(&exprval
);
628 TRACE("= %s\n", debugstr_variant(ret
));
632 /* ECMA-262 3rd Edition 12.5 */
633 HRESULT
if_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
635 if_statement_t
*stat
= (if_statement_t
*)_stat
;
642 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
646 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
647 exprval_release(&exprval
);
652 hres
= stat_eval(ctx
, stat
->if_stat
, rt
, ret
);
653 else if(stat
->else_stat
)
654 hres
= stat_eval(ctx
, stat
->else_stat
, rt
, ret
);
656 V_VT(ret
) = VT_EMPTY
;
661 /* ECMA-262 3rd Edition 12.6.2 */
662 HRESULT
while_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
664 while_statement_t
*stat
= (while_statement_t
*)_stat
;
673 V_VT(&val
) = VT_EMPTY
;
674 test_expr
= !stat
->do_while
;
678 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
682 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
683 exprval_release(&exprval
);
684 if(FAILED(hres
) || !b
)
690 hres
= stat_eval(ctx
, stat
->statement
, rt
, &tmp
);
697 if(rt
->type
== RT_CONTINUE
)
698 rt
->type
= RT_NORMAL
;
699 if(rt
->type
!= RT_NORMAL
)
708 if(rt
->type
== RT_BREAK
)
709 rt
->type
= RT_NORMAL
;
715 /* ECMA-262 3rd Edition 12.6.3 */
716 HRESULT
for_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
718 for_statement_t
*stat
= (for_statement_t
*)_stat
;
719 VARIANT val
, tmp
, retv
;
726 if(stat
->variable_list
) {
727 hres
= variable_list_eval(ctx
, stat
->variable_list
, &rt
->ei
);
730 }else if(stat
->begin_expr
) {
731 hres
= expr_eval(ctx
, stat
->begin_expr
, EXPR_NEWREF
, &rt
->ei
, &exprval
);
735 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
736 exprval_release(&exprval
);
743 V_VT(&retv
) = VT_EMPTY
;
747 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
751 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
752 exprval_release(&exprval
);
753 if(FAILED(hres
) || !b
)
757 hres
= stat_eval(ctx
, stat
->statement
, rt
, &tmp
);
764 if(rt
->type
== RT_CONTINUE
)
765 rt
->type
= RT_NORMAL
;
766 else if(rt
->type
!= RT_NORMAL
)
770 hres
= expr_eval(ctx
, stat
->end_expr
, 0, &rt
->ei
, &exprval
);
774 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
775 exprval_release(&exprval
);
788 if(rt
->type
== RT_BREAK
)
789 rt
->type
= RT_NORMAL
;
795 /* ECMA-262 3rd Edition 12.6.4 */
796 HRESULT
forin_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
798 forin_statement_t
*stat
= (forin_statement_t
*)_stat
;
799 VARIANT val
, name
, retv
, tmp
;
800 DISPID id
= DISPID_STARTENUM
;
801 BSTR str
, identifier
= NULL
;
809 hres
= variable_list_eval(ctx
, stat
->variable
, &rt
->ei
);
814 hres
= expr_eval(ctx
, stat
->in_expr
, EXPR_NEWREF
, &rt
->ei
, &exprval
);
818 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
819 exprval_release(&exprval
);
823 if(V_VT(&val
) != VT_DISPATCH
) {
824 TRACE("in vt %d\n", V_VT(&val
));
826 V_VT(ret
) = VT_EMPTY
;
830 hres
= IDispatch_QueryInterface(V_DISPATCH(&val
), &IID_IDispatchEx
, (void**)&in_obj
);
831 IDispatch_Release(V_DISPATCH(&val
));
833 FIXME("Object doesn't support IDispatchEx\n");
837 V_VT(&retv
) = VT_EMPTY
;
840 identifier
= SysAllocString(stat
->variable
->identifier
);
843 hres
= IDispatchEx_GetNextDispID(in_obj
, fdexEnumDefault
, id
, &id
);
844 if(FAILED(hres
) || hres
== S_FALSE
)
847 hres
= IDispatchEx_GetMemberName(in_obj
, id
, &str
);
851 TRACE("iter %s\n", debugstr_w(str
));
854 hres
= identifier_eval(ctx
, identifier
, 0, &exprval
);
856 hres
= expr_eval(ctx
, stat
->expr
, EXPR_NEWREF
, &rt
->ei
, &exprval
);
857 if(SUCCEEDED(hres
)) {
858 V_VT(&name
) = VT_BSTR
;
860 hres
= put_value(ctx
->parser
->script
, &exprval
, &name
, &rt
->ei
);
861 exprval_release(&exprval
);
867 hres
= stat_eval(ctx
, stat
->statement
, rt
, &tmp
);
874 if(rt
->type
== RT_CONTINUE
)
875 rt
->type
= RT_NORMAL
;
876 else if(rt
->type
!= RT_NORMAL
)
880 SysFreeString(identifier
);
881 IDispatchEx_Release(in_obj
);
887 if(rt
->type
== RT_BREAK
)
888 rt
->type
= RT_NORMAL
;
894 /* ECMA-262 3rd Edition 12.7 */
895 HRESULT
continue_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
897 branch_statement_t
*stat
= (branch_statement_t
*)_stat
;
901 if(stat
->identifier
) {
902 FIXME("indentifier not implemented\n");
906 rt
->type
= RT_CONTINUE
;
907 V_VT(ret
) = VT_EMPTY
;
911 /* ECMA-262 3rd Edition 12.8 */
912 HRESULT
break_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
914 branch_statement_t
*stat
= (branch_statement_t
*)_stat
;
918 if(stat
->identifier
) {
919 FIXME("indentifier not implemented\n");
924 V_VT(ret
) = VT_EMPTY
;
928 /* ECMA-262 3rd Edition 12.9 */
929 HRESULT
return_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
931 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
939 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
943 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, ret
);
944 exprval_release(&exprval
);
948 V_VT(ret
) = VT_EMPTY
;
951 TRACE("= %s\n", debugstr_variant(ret
));
952 rt
->type
= RT_RETURN
;
956 /* ECMA-262 3rd Edition 12.10 */
957 HRESULT
with_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
959 with_statement_t
*stat
= (with_statement_t
*)_stat
;
968 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
972 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
973 exprval_release(&exprval
);
977 hres
= to_object(ctx
, &val
, &disp
);
982 obj
= iface_to_jsdisp((IUnknown
*)disp
);
983 IDispatch_Release(disp
);
985 FIXME("disp id not jsdisp\n");
989 hres
= scope_push(ctx
->scope_chain
, obj
, &ctx
->scope_chain
);
994 hres
= stat_eval(ctx
, stat
->statement
, rt
, ret
);
996 scope_pop(&ctx
->scope_chain
);
1000 /* ECMA-262 3rd Edition 12.12 */
1001 HRESULT
labelled_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
1007 /* ECMA-262 3rd Edition 12.13 */
1008 HRESULT
switch_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
1010 switch_statement_t
*stat
= (switch_statement_t
*)_stat
;
1011 case_clausule_t
*iter
, *default_clausule
= NULL
;
1012 statement_t
*stat_iter
;
1020 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
1024 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
1025 exprval_release(&exprval
);
1029 for(iter
= stat
->case_list
; iter
; iter
= iter
->next
) {
1031 default_clausule
= iter
;
1035 hres
= expr_eval(ctx
, iter
->expr
, 0, &rt
->ei
, &exprval
);
1039 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &cval
);
1040 exprval_release(&exprval
);
1044 hres
= equal2_values(&val
, &cval
, &b
);
1045 VariantClear(&cval
);
1046 if(FAILED(hres
) || b
)
1055 iter
= default_clausule
;
1057 V_VT(&val
) = VT_EMPTY
;
1061 for(stat_iter
= iter
->stat
; stat_iter
; stat_iter
= stat_iter
->next
) {
1062 hres
= stat_eval(ctx
, stat_iter
, rt
, &tmp
);
1069 if(rt
->type
!= RT_NORMAL
)
1079 if(rt
->type
== RT_BREAK
)
1080 rt
->type
= RT_NORMAL
;
1086 /* ECMA-262 3rd Edition 12.13 */
1087 HRESULT
throw_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
1089 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
1096 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
1100 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
1101 exprval_release(&exprval
);
1106 return DISP_E_EXCEPTION
;
1109 /* ECMA-262 3rd Edition 12.14 */
1110 static HRESULT
catch_eval(exec_ctx_t
*ctx
, catch_block_t
*block
, return_type_t
*rt
, VARIANT
*ret
)
1112 DispatchEx
*var_disp
;
1117 memset(&rt
->ei
, 0, sizeof(jsexcept_t
));
1119 hres
= create_dispex(ctx
->parser
->script
, NULL
, NULL
, &var_disp
);
1120 if(SUCCEEDED(hres
)) {
1121 hres
= jsdisp_propput_name(var_disp
, block
->identifier
, ctx
->parser
->script
->lcid
,
1122 &ex
, &rt
->ei
, NULL
/*FIXME*/);
1123 if(SUCCEEDED(hres
)) {
1124 hres
= scope_push(ctx
->scope_chain
, var_disp
, &ctx
->scope_chain
);
1125 if(SUCCEEDED(hres
)) {
1126 hres
= stat_eval(ctx
, block
->statement
, rt
, &val
);
1127 scope_pop(&ctx
->scope_chain
);
1131 jsdisp_release(var_disp
);
1142 /* ECMA-262 3rd Edition 12.14 */
1143 HRESULT
try_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
1145 try_statement_t
*stat
= (try_statement_t
*)_stat
;
1151 hres
= stat_eval(ctx
, stat
->try_statement
, rt
, &val
);
1153 TRACE("EXCEPTION\n");
1154 if(!stat
->catch_block
)
1157 hres
= catch_eval(ctx
, stat
->catch_block
, rt
, &val
);
1162 if(stat
->finally_statement
) {
1164 hres
= stat_eval(ctx
, stat
->finally_statement
, rt
, &val
);
1173 static HRESULT
return_bool(exprval_t
*ret
, DWORD b
)
1175 ret
->type
= EXPRVAL_VARIANT
;
1176 V_VT(&ret
->u
.var
) = VT_BOOL
;
1177 V_BOOL(&ret
->u
.var
) = b
? VARIANT_TRUE
: VARIANT_FALSE
;
1182 static HRESULT
get_binary_expr_values(exec_ctx_t
*ctx
, binary_expression_t
*expr
, jsexcept_t
*ei
, VARIANT
*lval
, VARIANT
*rval
)
1187 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1191 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, lval
);
1192 exprval_release(&exprval
);
1196 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1197 if(SUCCEEDED(hres
)) {
1198 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, rval
);
1199 exprval_release(&exprval
);
1210 typedef HRESULT (*oper_t
)(exec_ctx_t
*,VARIANT
*,VARIANT
*,jsexcept_t
*,VARIANT
*);
1212 static HRESULT
binary_expr_eval(exec_ctx_t
*ctx
, binary_expression_t
*expr
, oper_t oper
, jsexcept_t
*ei
,
1215 VARIANT lval
, rval
, retv
;
1218 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1222 hres
= oper(ctx
, &lval
, &rval
, ei
, &retv
);
1223 VariantClear(&lval
);
1224 VariantClear(&rval
);
1228 ret
->type
= EXPRVAL_VARIANT
;
1233 /* ECMA-262 3rd Edition 11.13.2 */
1234 static HRESULT
assign_oper_eval(exec_ctx_t
*ctx
, expression_t
*lexpr
, expression_t
*rexpr
, oper_t oper
,
1235 jsexcept_t
*ei
, exprval_t
*ret
)
1237 VARIANT retv
, lval
, rval
;
1238 exprval_t exprval
, exprvalr
;
1241 hres
= expr_eval(ctx
, lexpr
, EXPR_NEWREF
, ei
, &exprval
);
1245 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &lval
);
1246 if(SUCCEEDED(hres
)) {
1247 hres
= expr_eval(ctx
, rexpr
, 0, ei
, &exprvalr
);
1248 if(SUCCEEDED(hres
)) {
1249 hres
= exprval_value(ctx
->parser
->script
, &exprvalr
, ei
, &rval
);
1250 exprval_release(&exprvalr
);
1252 if(SUCCEEDED(hres
)) {
1253 hres
= oper(ctx
, &lval
, &rval
, ei
, &retv
);
1254 VariantClear(&rval
);
1256 VariantClear(&lval
);
1259 if(SUCCEEDED(hres
)) {
1260 hres
= put_value(ctx
->parser
->script
, &exprval
, &retv
, ei
);
1262 VariantClear(&retv
);
1264 exprval_release(&exprval
);
1269 ret
->type
= EXPRVAL_VARIANT
;
1274 /* ECMA-262 3rd Edition 13 */
1275 HRESULT
function_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1277 function_expression_t
*expr
= (function_expression_t
*)_expr
;
1283 if(expr
->identifier
) {
1284 hres
= jsdisp_propget_name(ctx
->var_disp
, expr
->identifier
, ctx
->parser
->script
->lcid
, &var
, ei
, NULL
/*FIXME*/);
1290 hres
= create_source_function(ctx
->parser
, expr
->parameter_list
, expr
->source_elements
, ctx
->scope_chain
,
1291 expr
->src_str
, expr
->src_len
, &dispex
);
1295 V_VT(&var
) = VT_DISPATCH
;
1296 V_DISPATCH(&var
) = (IDispatch
*)_IDispatchEx_(dispex
);
1299 ret
->type
= EXPRVAL_VARIANT
;
1304 /* ECMA-262 3rd Edition 11.12 */
1305 HRESULT
conditional_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1307 conditional_expression_t
*expr
= (conditional_expression_t
*)_expr
;
1314 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1318 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, ei
, &b
);
1319 exprval_release(&exprval
);
1323 return expr_eval(ctx
, b
? expr
->true_expression
: expr
->false_expression
, flags
, ei
, ret
);
1326 /* ECMA-262 3rd Edition 11.2.1 */
1327 HRESULT
array_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1329 array_expression_t
*expr
= (array_expression_t
*)_expr
;
1331 VARIANT member
, val
;
1334 IDispatch
*obj
= NULL
;
1339 hres
= expr_eval(ctx
, expr
->member_expr
, EXPR_NEWREF
, ei
, &exprval
);
1343 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &member
);
1344 exprval_release(&exprval
);
1348 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
1349 if(SUCCEEDED(hres
)) {
1350 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1351 exprval_release(&exprval
);
1355 hres
= to_object(ctx
, &member
, &obj
);
1356 VariantClear(&member
);
1357 if(SUCCEEDED(hres
)) {
1358 hres
= to_string(ctx
->parser
->script
, &val
, ei
, &str
);
1359 if(SUCCEEDED(hres
)) {
1360 if(flags
& EXPR_STRREF
) {
1361 ret
->type
= EXPRVAL_NAMEREF
;
1362 ret
->u
.nameref
.disp
= obj
;
1363 ret
->u
.nameref
.name
= str
;
1367 hres
= disp_get_id(obj
, str
, flags
& EXPR_NEWREF
? fdexNameEnsure
: 0, &id
);
1370 if(SUCCEEDED(hres
)) {
1371 exprval_set_idref(ret
, obj
, id
);
1372 }else if(!(flags
& EXPR_NEWREF
) && hres
== DISP_E_UNKNOWNNAME
) {
1377 IDispatch_Release(obj
);
1383 /* ECMA-262 3rd Edition 11.2.1 */
1384 HRESULT
member_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1386 member_expression_t
*expr
= (member_expression_t
*)_expr
;
1387 IDispatch
*obj
= NULL
;
1396 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1400 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &member
);
1401 exprval_release(&exprval
);
1405 hres
= to_object(ctx
, &member
, &obj
);
1406 VariantClear(&member
);
1410 str
= SysAllocString(expr
->identifier
);
1411 if(flags
& EXPR_STRREF
) {
1412 ret
->type
= EXPRVAL_NAMEREF
;
1413 ret
->u
.nameref
.disp
= obj
;
1414 ret
->u
.nameref
.name
= str
;
1418 hres
= disp_get_id(obj
, str
, flags
& EXPR_NEWREF
? fdexNameEnsure
: 0, &id
);
1420 if(SUCCEEDED(hres
)) {
1421 exprval_set_idref(ret
, obj
, id
);
1422 }else if(!(flags
& EXPR_NEWREF
) && hres
== DISP_E_UNKNOWNNAME
) {
1427 IDispatch_Release(obj
);
1431 static void free_dp(DISPPARAMS
*dp
)
1435 for(i
=0; i
< dp
->cArgs
; i
++)
1436 VariantClear(dp
->rgvarg
+i
);
1437 heap_free(dp
->rgvarg
);
1440 static HRESULT
args_to_param(exec_ctx_t
*ctx
, argument_t
*args
, jsexcept_t
*ei
, DISPPARAMS
*dp
)
1446 HRESULT hres
= S_OK
;
1448 memset(dp
, 0, sizeof(*dp
));
1452 for(iter
= args
; iter
; iter
= iter
->next
)
1455 vargs
= heap_alloc_zero(cnt
* sizeof(*vargs
));
1457 return E_OUTOFMEMORY
;
1459 for(i
= cnt
, iter
= args
; iter
; iter
= iter
->next
) {
1460 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
1464 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, vargs
+ (--i
));
1465 exprval_release(&exprval
);
1480 /* ECMA-262 3rd Edition 11.2.2 */
1481 HRESULT
new_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1483 call_expression_t
*expr
= (call_expression_t
*)_expr
;
1485 VARIANT constr
, var
;
1491 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1495 hres
= args_to_param(ctx
, expr
->argument_list
, ei
, &dp
);
1497 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &constr
);
1498 exprval_release(&exprval
);
1502 if(V_VT(&constr
) != VT_DISPATCH
) {
1503 FIXME("throw TypeError\n");
1504 VariantClear(&constr
);
1508 hres
= disp_call(V_DISPATCH(&constr
), DISPID_VALUE
, ctx
->parser
->script
->lcid
,
1509 DISPATCH_CONSTRUCT
, &dp
, &var
, ei
, NULL
/*FIXME*/);
1510 IDispatch_Release(V_DISPATCH(&constr
));
1514 ret
->type
= EXPRVAL_VARIANT
;
1519 /* ECMA-262 3rd Edition 11.2.3 */
1520 HRESULT
call_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1522 call_expression_t
*expr
= (call_expression_t
*)_expr
;
1530 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1534 hres
= args_to_param(ctx
, expr
->argument_list
, ei
, &dp
);
1535 if(SUCCEEDED(hres
)) {
1536 switch(exprval
.type
) {
1538 hres
= disp_call(exprval
.u
.idref
.disp
, exprval
.u
.idref
.id
, ctx
->parser
->script
->lcid
, DISPATCH_METHOD
,
1539 &dp
, flags
& EXPR_NOVAL
? NULL
: &var
, ei
, NULL
/*FIXME*/);
1540 if(flags
& EXPR_NOVAL
)
1541 V_VT(&var
) = VT_EMPTY
;
1544 FIXME("unimplemented type %d\n", exprval
.type
);
1551 exprval_release(&exprval
);
1555 TRACE("= %s\n", debugstr_variant(&var
));
1556 ret
->type
= EXPRVAL_VARIANT
;
1561 /* ECMA-262 3rd Edition 11.1.1 */
1562 HRESULT
this_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1566 ret
->type
= EXPRVAL_VARIANT
;
1567 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1568 V_DISPATCH(&ret
->u
.var
) = ctx
->this_obj
;
1569 IDispatch_AddRef(ctx
->this_obj
);
1573 /* ECMA-262 3rd Edition 10.1.4 */
1574 HRESULT
identifier_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1576 identifier_expression_t
*expr
= (identifier_expression_t
*)_expr
;
1582 identifier
= SysAllocString(expr
->identifier
);
1584 return E_OUTOFMEMORY
;
1586 hres
= identifier_eval(ctx
, identifier
, flags
, ret
);
1588 SysFreeString(identifier
);
1592 /* ECMA-262 3rd Edition 7.8 */
1593 HRESULT
literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1595 literal_expression_t
*expr
= (literal_expression_t
*)_expr
;
1601 hres
= literal_to_var(expr
->literal
, &var
);
1605 ret
->type
= EXPRVAL_VARIANT
;
1610 /* ECMA-262 3rd Edition 11.1.4 */
1611 HRESULT
array_literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1613 array_literal_expression_t
*expr
= (array_literal_expression_t
*)_expr
;
1614 DWORD length
= 0, i
= 0;
1615 array_element_t
*elem
;
1623 for(elem
= expr
->element_list
; elem
; elem
= elem
->next
)
1624 length
+= elem
->elision
+1;
1625 length
+= expr
->length
;
1627 hres
= create_array(ctx
->parser
->script
, length
, &array
);
1631 for(elem
= expr
->element_list
; elem
; elem
= elem
->next
) {
1634 hres
= expr_eval(ctx
, elem
->expr
, 0, ei
, &exprval
);
1638 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1639 exprval_release(&exprval
);
1643 hres
= jsdisp_propput_idx(array
, i
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
1652 jsdisp_release(array
);
1656 ret
->type
= EXPRVAL_VARIANT
;
1657 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1658 V_DISPATCH(&ret
->u
.var
) = (IDispatch
*)_IDispatchEx_(array
);
1662 /* ECMA-262 3rd Edition 11.1.5 */
1663 HRESULT
property_value_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1665 property_value_expression_t
*expr
= (property_value_expression_t
*)_expr
;
1675 hres
= create_object(ctx
->parser
->script
, NULL
, &obj
);
1679 for(iter
= expr
->property_list
; iter
; iter
= iter
->next
) {
1680 hres
= literal_to_var(iter
->name
, &tmp
);
1684 hres
= to_string(ctx
->parser
->script
, &tmp
, ei
, &name
);
1689 hres
= expr_eval(ctx
, iter
->value
, 0, ei
, &exprval
);
1690 if(SUCCEEDED(hres
)) {
1691 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1692 exprval_release(&exprval
);
1693 if(SUCCEEDED(hres
)) {
1694 hres
= jsdisp_propput_name(obj
, name
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
1699 SysFreeString(name
);
1705 jsdisp_release(obj
);
1709 ret
->type
= EXPRVAL_VARIANT
;
1710 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1711 V_DISPATCH(&ret
->u
.var
) = (IDispatch
*)_IDispatchEx_(obj
);
1715 /* ECMA-262 3rd Edition 11.14 */
1716 HRESULT
comma_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1718 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1724 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1728 VariantClear(&lval
);
1730 ret
->type
= EXPRVAL_VARIANT
;
1735 /* ECMA-262 3rd Edition 11.11 */
1736 HRESULT
logical_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1738 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1746 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1750 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1751 exprval_release(&exprval
);
1755 hres
= to_boolean(&val
, &b
);
1756 if(SUCCEEDED(hres
) && b
) {
1757 ret
->type
= EXPRVAL_VARIANT
;
1766 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1770 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1771 exprval_release(&exprval
);
1775 ret
->type
= EXPRVAL_VARIANT
;
1780 /* ECMA-262 3rd Edition 11.11 */
1781 HRESULT
logical_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1783 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1791 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1795 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1796 exprval_release(&exprval
);
1800 hres
= to_boolean(&val
, &b
);
1801 if(SUCCEEDED(hres
) && !b
) {
1802 ret
->type
= EXPRVAL_VARIANT
;
1811 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1815 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1816 exprval_release(&exprval
);
1820 ret
->type
= EXPRVAL_VARIANT
;
1825 /* ECMA-262 3rd Edition 11.10 */
1826 static HRESULT
bitor_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1831 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
1835 hres
= to_int32(ctx
->parser
->script
, rval
, ei
, &ri
);
1844 /* ECMA-262 3rd Edition 11.10 */
1845 HRESULT
binary_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1847 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1851 return binary_expr_eval(ctx
, expr
, bitor_eval
, ei
, ret
);
1854 /* ECMA-262 3rd Edition 11.10 */
1855 static HRESULT
xor_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1860 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
1864 hres
= to_int32(ctx
->parser
->script
, rval
, ei
, &ri
);
1873 /* ECMA-262 3rd Edition 11.10 */
1874 HRESULT
binary_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1876 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1880 return binary_expr_eval(ctx
, expr
, xor_eval
, ei
, ret
);
1883 /* ECMA-262 3rd Edition 11.10 */
1884 static HRESULT
bitand_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1889 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
1893 hres
= to_int32(ctx
->parser
->script
, rval
, ei
, &ri
);
1902 /* ECMA-262 3rd Edition 11.10 */
1903 HRESULT
binary_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1905 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1909 return binary_expr_eval(ctx
, expr
, bitand_eval
, ei
, ret
);
1912 /* ECMA-262 3rd Edition 11.8.6 */
1913 HRESULT
instanceof_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1919 /* ECMA-262 3rd Edition 11.8.7 */
1920 HRESULT
in_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1926 /* ECMA-262 3rd Edition 11.6.1 */
1927 static HRESULT
add_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1932 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &l
);
1936 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &r
);
1942 if(V_VT(&l
) == VT_BSTR
|| V_VT(&r
) == VT_BSTR
) {
1943 BSTR lstr
= NULL
, rstr
= NULL
;
1945 if(V_VT(&l
) == VT_BSTR
)
1948 hres
= to_string(ctx
->parser
->script
, &l
, ei
, &lstr
);
1950 if(SUCCEEDED(hres
)) {
1951 if(V_VT(&r
) == VT_BSTR
)
1954 hres
= to_string(ctx
->parser
->script
, &r
, ei
, &rstr
);
1957 if(SUCCEEDED(hres
)) {
1960 len1
= SysStringLen(lstr
);
1961 len2
= SysStringLen(rstr
);
1963 V_VT(retv
) = VT_BSTR
;
1964 V_BSTR(retv
) = SysAllocStringLen(NULL
, len1
+len2
);
1965 memcpy(V_BSTR(retv
), lstr
, len1
*sizeof(WCHAR
));
1966 memcpy(V_BSTR(retv
)+len1
, rstr
, (len2
+1)*sizeof(WCHAR
));
1969 if(V_VT(&l
) != VT_BSTR
)
1970 SysFreeString(lstr
);
1971 if(V_VT(&r
) != VT_BSTR
)
1972 SysFreeString(rstr
);
1976 hres
= to_number(ctx
->parser
->script
, &l
, ei
, &nl
);
1977 if(SUCCEEDED(hres
)) {
1978 hres
= to_number(ctx
->parser
->script
, &r
, ei
, &nr
);
1980 num_set_val(retv
, num_val(&nl
) + num_val(&nr
));
1989 /* ECMA-262 3rd Edition 11.6.1 */
1990 HRESULT
add_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1992 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1996 return binary_expr_eval(ctx
, expr
, add_eval
, ei
, ret
);
1999 /* ECMA-262 3rd Edition 11.6.2 */
2000 static HRESULT
sub_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2005 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2009 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2013 num_set_val(retv
, num_val(&lnum
) - num_val(&rnum
));
2017 /* ECMA-262 3rd Edition 11.6.2 */
2018 HRESULT
sub_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2020 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2024 return binary_expr_eval(ctx
, expr
, sub_eval
, ei
, ret
);
2027 /* ECMA-262 3rd Edition 11.5.1 */
2028 static HRESULT
mul_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2033 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2037 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2041 num_set_val(retv
, num_val(&lnum
) * num_val(&rnum
));
2045 /* ECMA-262 3rd Edition 11.5.1 */
2046 HRESULT
mul_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2048 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2052 return binary_expr_eval(ctx
, expr
, mul_eval
, ei
, ret
);
2055 /* ECMA-262 3rd Edition 11.5.2 */
2056 static HRESULT
div_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2061 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2065 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2069 num_set_val(retv
, num_val(&lnum
) / num_val(&rnum
));
2073 /* ECMA-262 3rd Edition 11.5.2 */
2074 HRESULT
div_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2076 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2080 return binary_expr_eval(ctx
, expr
, div_eval
, ei
, ret
);
2083 /* ECMA-262 3rd Edition 11.5.3 */
2084 static HRESULT
mod_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2089 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2093 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2097 num_set_val(retv
, fmod(num_val(&lnum
), num_val(&rnum
)));
2101 /* ECMA-262 3rd Edition 11.5.3 */
2102 HRESULT
mod_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2104 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2108 return binary_expr_eval(ctx
, expr
, mod_eval
, ei
, ret
);
2111 /* ECMA-262 3rd Edition 11.4.2 */
2112 HRESULT
delete_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2114 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2115 VARIANT_BOOL b
= VARIANT_FALSE
;
2121 hres
= expr_eval(ctx
, expr
->expression
, EXPR_STRREF
, ei
, &exprval
);
2125 switch(exprval
.type
) {
2126 case EXPRVAL_IDREF
: {
2127 IDispatchEx
*dispex
;
2129 hres
= IDispatch_QueryInterface(exprval
.u
.nameref
.disp
, &IID_IDispatchEx
, (void**)&dispex
);
2130 if(SUCCEEDED(hres
)) {
2131 hres
= IDispatchEx_DeleteMemberByDispID(dispex
, exprval
.u
.idref
.id
);
2133 IDispatchEx_Release(dispex
);
2137 case EXPRVAL_NAMEREF
: {
2138 IDispatchEx
*dispex
;
2140 hres
= IDispatch_QueryInterface(exprval
.u
.nameref
.disp
, &IID_IDispatchEx
, (void**)&dispex
);
2141 if(SUCCEEDED(hres
)) {
2142 hres
= IDispatchEx_DeleteMemberByName(dispex
, exprval
.u
.nameref
.name
, fdexNameCaseSensitive
);
2144 IDispatchEx_Release(dispex
);
2149 FIXME("unsupported type %d\n", exprval
.type
);
2153 exprval_release(&exprval
);
2157 return return_bool(ret
, b
);
2160 /* ECMA-262 3rd Edition 11.4.2 */
2161 HRESULT
void_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2163 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2170 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
2174 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &tmp
);
2175 exprval_release(&exprval
);
2181 ret
->type
= EXPRVAL_VARIANT
;
2182 V_VT(&ret
->u
.var
) = VT_EMPTY
;
2186 /* ECMA-262 3rd Edition 11.4.3 */
2187 HRESULT
typeof_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2189 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2195 static const WCHAR booleanW
[] = {'b','o','o','l','e','a','n',0};
2196 static const WCHAR functionW
[] = {'f','u','n','c','t','i','o','n',0};
2197 static const WCHAR numberW
[] = {'n','u','m','b','e','r',0};
2198 static const WCHAR objectW
[] = {'o','b','j','e','c','t',0};
2199 static const WCHAR stringW
[] = {'s','t','r','i','n','g',0};
2200 static const WCHAR undefinedW
[] = {'u','n','d','e','f','i','n','e','d',0};
2204 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
2208 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2209 exprval_release(&exprval
);
2213 switch(V_VT(&val
)) {
2233 dispex
= iface_to_jsdisp((IUnknown
*)V_DISPATCH(&val
));
2235 str
= dispex
->builtin_info
->class == JSCLASS_FUNCTION
? functionW
: objectW
;
2236 IDispatchEx_Release(_IDispatchEx_(dispex
));
2243 FIXME("unhandled vt %d\n", V_VT(&val
));
2250 ret
->type
= EXPRVAL_VARIANT
;
2251 V_VT(&ret
->u
.var
) = VT_BSTR
;
2252 V_BSTR(&ret
->u
.var
) = SysAllocString(str
);
2256 /* ECMA-262 3rd Edition 11.4.7 */
2257 HRESULT
minus_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
;
2266 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
2270 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2271 exprval_release(&exprval
);
2275 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2280 ret
->type
= EXPRVAL_VARIANT
;
2281 num_set_val(&ret
->u
.var
, -num_val(&num
));
2285 /* ECMA-262 3rd Edition 11.4.6 */
2286 HRESULT
plus_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2288 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2295 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2299 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2300 exprval_release(&exprval
);
2304 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2308 ret
->type
= EXPRVAL_VARIANT
;
2313 /* ECMA-262 3rd Edition 11.3.1 */
2314 HRESULT
post_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2316 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2323 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2327 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2328 if(SUCCEEDED(hres
)) {
2329 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2333 if(SUCCEEDED(hres
)) {
2335 num_set_val(&inc
, num_val(&num
)+1.0);
2336 hres
= put_value(ctx
->parser
->script
, &exprval
, &inc
, ei
);
2339 exprval_release(&exprval
);
2343 ret
->type
= EXPRVAL_VARIANT
;
2348 /* ECMA-262 3rd Edition 11.3.2 */
2349 HRESULT
post_decrement_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2351 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2358 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2362 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2363 if(SUCCEEDED(hres
)) {
2364 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2368 if(SUCCEEDED(hres
)) {
2370 num_set_val(&dec
, num_val(&num
)-1.0);
2371 hres
= put_value(ctx
->parser
->script
, &exprval
, &dec
, ei
);
2374 exprval_release(&exprval
);
2378 ret
->type
= EXPRVAL_VARIANT
;
2383 /* ECMA-262 3rd Edition 11.4.4 */
2384 HRESULT
pre_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2386 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2393 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2397 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2398 if(SUCCEEDED(hres
)) {
2399 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2403 if(SUCCEEDED(hres
)) {
2404 num_set_val(&val
, num_val(&num
)+1.0);
2405 hres
= put_value(ctx
->parser
->script
, &exprval
, &val
, ei
);
2408 exprval_release(&exprval
);
2412 ret
->type
= EXPRVAL_VARIANT
;
2417 /* ECMA-262 3rd Edition 11.4.5 */
2418 HRESULT
pre_decrement_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
, EXPR_NEWREF
, ei
, &exprval
);
2431 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2432 if(SUCCEEDED(hres
)) {
2433 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2437 if(SUCCEEDED(hres
)) {
2438 num_set_val(&val
, num_val(&num
)-1.0);
2439 hres
= put_value(ctx
->parser
->script
, &exprval
, &val
, ei
);
2442 exprval_release(&exprval
);
2446 ret
->type
= EXPRVAL_VARIANT
;
2451 /* ECMA-262 3rd Edition 11.9.3 */
2452 static HRESULT
equal_values(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, BOOL
*ret
)
2454 if(V_VT(lval
) == V_VT(rval
) || (is_num_vt(V_VT(lval
)) && is_num_vt(V_VT(rval
))))
2455 return equal2_values(lval
, rval
, ret
);
2457 /* FIXME: NULL disps should be handled in more general way */
2458 if(V_VT(lval
) == VT_DISPATCH
&& !V_DISPATCH(lval
)) {
2461 return equal_values(ctx
, &v
, rval
, ei
, ret
);
2464 if(V_VT(rval
) == VT_DISPATCH
&& !V_DISPATCH(rval
)) {
2467 return equal_values(ctx
, lval
, &v
, ei
, ret
);
2470 if((V_VT(lval
) == VT_NULL
&& V_VT(rval
) == VT_EMPTY
) ||
2471 (V_VT(lval
) == VT_EMPTY
&& V_VT(rval
) == VT_NULL
)) {
2476 if(V_VT(lval
) == VT_BSTR
&& is_num_vt(V_VT(rval
))) {
2480 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &v
);
2484 return equal_values(ctx
, &v
, rval
, ei
, ret
);
2487 if(V_VT(rval
) == VT_BSTR
&& is_num_vt(V_VT(lval
))) {
2491 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &v
);
2495 return equal_values(ctx
, lval
, &v
, ei
, ret
);
2498 if(V_VT(rval
) == VT_BOOL
) {
2502 V_I4(&v
) = V_BOOL(rval
) ? 1 : 0;
2503 return equal_values(ctx
, lval
, &v
, ei
, ret
);
2506 if(V_VT(lval
) == VT_BOOL
) {
2510 V_I4(&v
) = V_BOOL(lval
) ? 1 : 0;
2511 return equal_values(ctx
, &v
, rval
, ei
, ret
);
2515 if(V_VT(rval
) == VT_DISPATCH
&& (V_VT(lval
) == VT_BSTR
|| is_num_vt(V_VT(lval
)))) {
2519 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &v
);
2523 hres
= equal_values(ctx
, lval
, &v
, ei
, ret
);
2530 if(V_VT(lval
) == VT_DISPATCH
&& (V_VT(rval
) == VT_BSTR
|| is_num_vt(V_VT(rval
)))) {
2534 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &v
);
2538 hres
= equal_values(ctx
, &v
, rval
, ei
, ret
);
2549 /* ECMA-262 3rd Edition 11.9.1 */
2550 HRESULT
equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2552 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2559 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
2563 hres
= equal_values(ctx
, &rval
, &lval
, ei
, &b
);
2567 return return_bool(ret
, b
);
2570 /* ECMA-262 3rd Edition 11.9.4 */
2571 HRESULT
equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2573 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2580 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
2584 hres
= equal2_values(&rval
, &lval
, &b
);
2588 return return_bool(ret
, b
);
2591 /* ECMA-262 3rd Edition 11.9.2 */
2592 HRESULT
not_equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2594 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2601 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2605 hres
= equal_values(ctx
, &lval
, &rval
, ei
, &b
);
2609 return return_bool(ret
, !b
);
2612 /* ECMA-262 3rd Edition 11.9.5 */
2613 HRESULT
not_equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2615 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2622 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2626 hres
= equal2_values(&lval
, &rval
, &b
);
2630 return return_bool(ret
, !b
);
2633 /* ECMA-262 3rd Edition 11.8.5 */
2634 static HRESULT
less_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, BOOL greater
, jsexcept_t
*ei
, BOOL
*ret
)
2636 VARIANT l
, r
, ln
, rn
;
2639 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &l
);
2643 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &r
);
2649 if(V_VT(&l
) == VT_BSTR
&& V_VT(&r
) == VT_BSTR
) {
2650 *ret
= (strcmpW(V_BSTR(&l
), V_BSTR(&r
)) < 0) ^ greater
;
2651 SysFreeString(V_BSTR(&l
));
2652 SysFreeString(V_BSTR(&r
));
2656 hres
= to_number(ctx
->parser
->script
, &l
, ei
, &ln
);
2659 hres
= to_number(ctx
->parser
->script
, &r
, ei
, &rn
);
2664 if(V_VT(&ln
) == VT_I4
&& V_VT(&rn
) == VT_I4
) {
2665 *ret
= (V_I4(&ln
) < V_I4(&rn
)) ^ greater
;
2667 DOUBLE ld
= num_val(&ln
);
2668 DOUBLE rd
= num_val(&rn
);
2670 *ret
= !isnan(ld
) && !isnan(rd
) && ((ld
< rd
) ^ greater
);
2676 /* ECMA-262 3rd Edition 11.8.1 */
2677 HRESULT
less_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2679 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2686 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2690 hres
= less_eval(ctx
, &lval
, &rval
, FALSE
, ei
, &b
);
2691 VariantClear(&lval
);
2692 VariantClear(&rval
);
2696 return return_bool(ret
, b
);
2699 /* ECMA-262 3rd Edition 11.8.3 */
2700 HRESULT
lesseq_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2702 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2709 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2713 hres
= less_eval(ctx
, &rval
, &lval
, TRUE
, ei
, &b
);
2714 VariantClear(&lval
);
2715 VariantClear(&rval
);
2719 return return_bool(ret
, b
);
2722 /* ECMA-262 3rd Edition 11.8.2 */
2723 HRESULT
greater_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2725 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2732 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2736 hres
= less_eval(ctx
, &rval
, &lval
, FALSE
, ei
, &b
);
2737 VariantClear(&lval
);
2738 VariantClear(&rval
);
2742 return return_bool(ret
, b
);
2745 /* ECMA-262 3rd Edition 11.8.4 */
2746 HRESULT
greatereq_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2748 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2755 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2759 hres
= less_eval(ctx
, &lval
, &rval
, TRUE
, ei
, &b
);
2760 VariantClear(&lval
);
2761 VariantClear(&rval
);
2765 return return_bool(ret
, b
);
2768 /* ECMA-262 3rd Edition 11.4.8 */
2769 HRESULT
binary_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2771 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2779 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2783 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2784 exprval_release(&exprval
);
2788 hres
= to_int32(ctx
->parser
->script
, &val
, ei
, &i
);
2792 ret
->type
= EXPRVAL_VARIANT
;
2793 V_VT(&ret
->u
.var
) = VT_I4
;
2794 V_I4(&ret
->u
.var
) = ~i
;
2798 /* ECMA-262 3rd Edition 11.4.9 */
2799 HRESULT
logical_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2801 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2808 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2812 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, ei
, &b
);
2813 exprval_release(&exprval
);
2817 return return_bool(ret
, !b
);
2820 /* ECMA-262 3rd Edition 11.7.1 */
2821 static HRESULT
lshift_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2827 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
2831 hres
= to_uint32(ctx
->parser
->script
, rval
, ei
, &ri
);
2836 V_I4(retv
) = li
<< (ri
&0x1f);
2840 /* ECMA-262 3rd Edition 11.7.1 */
2841 HRESULT
left_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2843 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2847 return binary_expr_eval(ctx
, expr
, lshift_eval
, ei
, ret
);
2850 /* ECMA-262 3rd Edition 11.7.2 */
2851 static HRESULT
rshift_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2857 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
2861 hres
= to_uint32(ctx
->parser
->script
, rval
, ei
, &ri
);
2866 V_I4(retv
) = li
>> (ri
&0x1f);
2870 /* ECMA-262 3rd Edition 11.7.2 */
2871 HRESULT
right_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2873 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2877 return binary_expr_eval(ctx
, expr
, rshift_eval
, ei
, ret
);
2880 /* ECMA-262 3rd Edition 11.7.3 */
2881 static HRESULT
rshift2_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2886 hres
= to_uint32(ctx
->parser
->script
, lval
, ei
, &li
);
2890 hres
= to_uint32(ctx
->parser
->script
, rval
, ei
, &ri
);
2895 V_I4(retv
) = li
>> (ri
&0x1f);
2899 /* ECMA-262 3rd Edition 11.7.3 */
2900 HRESULT
right2_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2902 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2906 return binary_expr_eval(ctx
, expr
, rshift2_eval
, ei
, ret
);
2909 /* ECMA-262 3rd Edition 11.13.1 */
2910 HRESULT
assign_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2912 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2913 exprval_t exprval
, exprvalr
;
2919 hres
= expr_eval(ctx
, expr
->expression1
, EXPR_NEWREF
, ei
, &exprval
);
2923 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprvalr
);
2924 if(SUCCEEDED(hres
)) {
2925 hres
= exprval_to_value(ctx
->parser
->script
, &exprvalr
, ei
, &rval
);
2926 exprval_release(&exprvalr
);
2930 hres
= put_value(ctx
->parser
->script
, &exprval
, &rval
, ei
);
2932 exprval_release(&exprval
);
2936 ret
->type
= EXPRVAL_VARIANT
;
2941 /* ECMA-262 3rd Edition 11.13.2 */
2942 HRESULT
assign_lshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2944 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2948 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, lshift_eval
, ei
, ret
);
2951 /* ECMA-262 3rd Edition 11.13.2 */
2952 HRESULT
assign_rshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2954 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2958 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, rshift_eval
, ei
, ret
);
2961 /* ECMA-262 3rd Edition 11.13.2 */
2962 HRESULT
assign_rrshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2964 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2968 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, rshift2_eval
, ei
, ret
);
2971 /* ECMA-262 3rd Edition 11.13.2 */
2972 HRESULT
assign_add_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2974 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2978 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, add_eval
, ei
, ret
);
2981 /* ECMA-262 3rd Edition 11.13.2 */
2982 HRESULT
assign_sub_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2984 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2988 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, sub_eval
, ei
, ret
);
2991 /* ECMA-262 3rd Edition 11.13.2 */
2992 HRESULT
assign_mul_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2994 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2998 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, mul_eval
, ei
, ret
);
3001 /* ECMA-262 3rd Edition 11.13.2 */
3002 HRESULT
assign_div_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 assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, div_eval
, ei
, ret
);
3011 /* ECMA-262 3rd Edition 11.13.2 */
3012 HRESULT
assign_mod_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
3014 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
3018 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, mod_eval
, ei
, ret
);
3021 /* ECMA-262 3rd Edition 11.13.2 */
3022 HRESULT
assign_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
3024 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
3028 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, bitand_eval
, ei
, ret
);
3031 /* ECMA-262 3rd Edition 11.13.2 */
3032 HRESULT
assign_or_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 assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, bitor_eval
, ei
, ret
);
3041 /* ECMA-262 3rd Edition 11.13.2 */
3042 HRESULT
assign_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
3044 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
3048 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, xor_eval
, ei
, ret
);