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
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
26 #define EXPR_NOVAL 0x0001
27 #define EXPR_NEWREF 0x0002
28 #define EXPR_STRREF 0x0004
30 static inline HRESULT
stat_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
32 return stat
->eval(ctx
, stat
, rt
, ret
);
35 static inline HRESULT
expr_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
37 return _expr
->eval(ctx
, _expr
, flags
, ei
, ret
);
40 static void exprval_release(exprval_t
*val
)
44 if(V_VT(&val
->u
.var
) != VT_EMPTY
)
45 VariantClear(&val
->u
.var
);
49 IDispatch_Release(val
->u
.idref
.disp
);
52 if(val
->u
.nameref
.disp
)
53 IDispatch_Release(val
->u
.nameref
.disp
);
54 SysFreeString(val
->u
.nameref
.name
);
58 /* ECMA-262 3rd Edition 8.7.1 */
59 static HRESULT
exprval_value(script_ctx_t
*ctx
, exprval_t
*val
, jsexcept_t
*ei
, VARIANT
*ret
)
65 return VariantCopy(ret
, &val
->u
.var
);
67 if(!val
->u
.idref
.disp
) {
68 FIXME("throw ReferenceError\n");
72 return disp_propget(val
->u
.idref
.disp
, val
->u
.idref
.id
, ctx
->lcid
, ret
, ei
, NULL
/*FIXME*/);
74 ERR("type %d\n", val
->type
);
79 static HRESULT
exprval_to_value(script_ctx_t
*ctx
, exprval_t
*val
, jsexcept_t
*ei
, VARIANT
*ret
)
81 if(val
->type
== EXPRVAL_VARIANT
) {
83 V_VT(&val
->u
.var
) = VT_EMPTY
;
87 return exprval_value(ctx
, val
, ei
, ret
);
90 static HRESULT
exprval_to_boolean(script_ctx_t
*ctx
, exprval_t
*exprval
, jsexcept_t
*ei
, VARIANT_BOOL
*b
)
92 if(exprval
->type
!= EXPRVAL_VARIANT
) {
96 hres
= exprval_to_value(ctx
, exprval
, ei
, &val
);
100 hres
= to_boolean(&val
, b
);
105 return to_boolean(&exprval
->u
.var
, b
);
108 static void exprval_init(exprval_t
*val
)
110 val
->type
= EXPRVAL_VARIANT
;
111 V_VT(&val
->u
.var
) = VT_EMPTY
;
114 static void exprval_set_idref(exprval_t
*val
, IDispatch
*disp
, DISPID id
)
116 val
->type
= EXPRVAL_IDREF
;
117 val
->u
.idref
.disp
= disp
;
118 val
->u
.idref
.id
= id
;
121 IDispatch_AddRef(disp
);
124 HRESULT
scope_push(scope_chain_t
*scope
, DispatchEx
*obj
, scope_chain_t
**ret
)
126 scope_chain_t
*new_scope
;
128 new_scope
= heap_alloc(sizeof(scope_chain_t
));
130 return E_OUTOFMEMORY
;
134 IDispatchEx_AddRef(_IDispatchEx_(obj
));
135 new_scope
->obj
= obj
;
139 new_scope
->next
= scope
;
141 new_scope
->next
= NULL
;
148 static void scope_pop(scope_chain_t
**scope
)
157 void scope_release(scope_chain_t
*scope
)
163 scope_release(scope
->next
);
165 IDispatchEx_Release(_IDispatchEx_(scope
->obj
));
169 HRESULT
create_exec_ctx(IDispatch
*this_obj
, DispatchEx
*var_disp
, scope_chain_t
*scope
, exec_ctx_t
**ret
)
173 ctx
= heap_alloc_zero(sizeof(exec_ctx_t
));
175 return E_OUTOFMEMORY
;
177 IDispatch_AddRef(this_obj
);
178 ctx
->this_obj
= this_obj
;
180 IDispatchEx_AddRef(_IDispatchEx_(var_disp
));
181 ctx
->var_disp
= var_disp
;
185 ctx
->scope_chain
= scope
;
192 void exec_release(exec_ctx_t
*ctx
)
198 scope_release(ctx
->scope_chain
);
200 IDispatchEx_Release(_IDispatchEx_(ctx
->var_disp
));
202 IDispatch_Release(ctx
->this_obj
);
206 static HRESULT
dispex_get_id(IDispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*id
)
210 return IDispatchEx_GetDispID(dispex
, name
, flags
|fdexNameCaseSensitive
, id
);
213 static HRESULT
disp_get_id(IDispatch
*disp
, BSTR name
, DWORD flags
, DISPID
*id
)
218 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
220 TRACE("unsing IDispatch\n");
223 return IDispatch_GetIDsOfNames(disp
, &IID_NULL
, &name
, 1, 0, id
);
226 hres
= dispex_get_id(dispex
, name
, flags
, id
);
227 IDispatchEx_Release(dispex
);
231 /* ECMA-262 3rd Edition 8.7.2 */
232 static HRESULT
put_value(script_ctx_t
*ctx
, exprval_t
*ref
, VARIANT
*v
, jsexcept_t
*ei
)
234 if(ref
->type
!= EXPRVAL_IDREF
) {
235 FIXME("throw ReferemceError\n");
239 return disp_propput(ref
->u
.idref
.disp
, ref
->u
.idref
.id
, ctx
->lcid
, v
, ei
, NULL
/*FIXME*/);
242 static HRESULT
disp_cmp(IDispatch
*disp1
, IDispatch
*disp2
, BOOL
*ret
)
244 IObjectIdentity
*identity
;
245 IUnknown
*unk1
, *unk2
;
253 hres
= IDispatch_QueryInterface(disp1
, &IID_IUnknown
, (void**)&unk1
);
257 hres
= IDispatch_QueryInterface(disp2
, &IID_IUnknown
, (void**)&unk2
);
259 IUnknown_Release(unk1
);
266 hres
= IUnknown_QueryInterface(unk1
, &IID_IObjectIdentity
, (void**)&identity
);
267 if(SUCCEEDED(hres
)) {
268 hres
= IObjectIdentity_IsEqualObject(identity
, unk2
);
269 IObjectIdentity_Release(identity
);
276 IUnknown_Release(unk1
);
277 IUnknown_Release(unk2
);
281 /* ECMA-262 3rd Edition 11.9.6 */
282 HRESULT
equal2_values(VARIANT
*lval
, VARIANT
*rval
, BOOL
*ret
)
286 if(V_VT(lval
) != V_VT(rval
)) {
287 if(is_num_vt(V_VT(lval
)) && is_num_vt(V_VT(rval
))) {
288 *ret
= num_val(lval
) == num_val(rval
);
302 *ret
= V_I4(lval
) == V_I4(rval
);
305 *ret
= V_R8(lval
) == V_R8(rval
);
308 *ret
= !strcmpW(V_BSTR(lval
), V_BSTR(rval
));
311 return disp_cmp(V_DISPATCH(lval
), V_DISPATCH(rval
), ret
);
313 *ret
= !V_BOOL(lval
) == !V_BOOL(rval
);
316 FIXME("unimplemented vt %d\n", V_VT(lval
));
323 static HRESULT
literal_to_var(literal_t
*literal
, VARIANT
*v
)
325 V_VT(v
) = literal
->vt
;
332 V_I4(v
) = literal
->u
.lval
;
335 V_R8(v
) = literal
->u
.dval
;
338 V_BSTR(v
) = SysAllocString(literal
->u
.wstr
);
341 V_BOOL(v
) = literal
->u
.bval
;
344 IDispatch_AddRef(literal
->u
.disp
);
345 V_DISPATCH(v
) = literal
->u
.disp
;
348 ERR("wrong type %d\n", V_VT(v
));
355 HRESULT
exec_source(exec_ctx_t
*ctx
, parser_ctx_t
*parser
, source_elements_t
*source
, jsexcept_t
*ei
, VARIANT
*retv
)
357 script_ctx_t
*script
= parser
->script
;
358 function_declaration_t
*func
;
359 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
->parameter_list
, func
->source_elements
,
371 ctx
->scope_chain
, func
->src_str
, func
->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
->identifier
, script
->lcid
, &var
, ei
, NULL
);
378 IDispatchEx_Release(_IDispatchEx_(func_obj
));
383 prev_ctx
= script
->exec_ctx
;
384 script
->exec_ctx
= ctx
;
386 prev_parser
= ctx
->parser
;
387 ctx
->parser
= parser
;
389 V_VT(&val
) = VT_EMPTY
;
390 memset(&rt
, 0, sizeof(rt
));
393 for(stat
= source
->statement
; stat
; stat
= stat
->next
) {
394 hres
= stat_eval(ctx
, stat
, &rt
, &tmp
);
400 if(rt
.type
!= RT_NORMAL
)
404 script
->exec_ctx
= prev_ctx
;
405 ctx
->parser
= prev_parser
;
407 if(rt
.type
!= RT_NORMAL
&& rt
.type
!= RT_RETURN
) {
408 FIXME("wrong rt %d\n", rt
.type
);
425 /* ECMA-262 3rd Edition 10.1.4 */
426 static HRESULT
identifier_eval(exec_ctx_t
*ctx
, BSTR identifier
, DWORD flags
, exprval_t
*ret
)
428 scope_chain_t
*scope
;
433 TRACE("%s\n", debugstr_w(identifier
));
435 for(scope
= ctx
->scope_chain
; scope
; scope
= scope
->next
) {
436 hres
= dispex_get_id(_IDispatchEx_(scope
->obj
), identifier
, 0, &id
);
442 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(scope
->obj
), id
);
446 hres
= dispex_get_id(_IDispatchEx_(ctx
->parser
->script
->global
), identifier
, 0, &id
);
447 if(SUCCEEDED(hres
)) {
448 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->parser
->script
->global
), id
);
452 for(item
= ctx
->parser
->script
->named_items
; item
; item
= item
->next
) {
453 hres
= disp_get_id(item
->disp
, identifier
, 0, &id
);
459 exprval_set_idref(ret
, (IDispatch
*)item
->disp
, id
);
463 hres
= dispex_get_id(_IDispatchEx_(ctx
->parser
->script
->script_disp
), identifier
, 0, &id
);
464 if(SUCCEEDED(hres
)) {
465 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->parser
->script
->script_disp
), id
);
469 if(flags
& EXPR_NEWREF
) {
470 hres
= dispex_get_id(_IDispatchEx_(ctx
->var_disp
), identifier
, fdexNameEnsure
, &id
);
474 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->var_disp
), id
);
478 WARN("Could not find identifier %s\n", debugstr_w(identifier
));
482 /* ECMA-262 3rd Edition 12.1 */
483 HRESULT
block_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
485 block_statement_t
*stat
= (block_statement_t
*)_stat
;
492 V_VT(&val
) = VT_EMPTY
;
493 for(iter
= stat
->stat_list
; iter
; iter
= iter
->next
) {
494 hres
= stat_eval(ctx
, iter
, rt
, &tmp
);
500 if(rt
->type
!= RT_NORMAL
)
513 /* ECMA-262 3rd Edition 12.2 */
514 static HRESULT
variable_list_eval(exec_ctx_t
*ctx
, variable_declaration_t
*var_list
, jsexcept_t
*ei
)
516 variable_declaration_t
*iter
;
517 HRESULT hres
= E_FAIL
;
519 for(iter
= var_list
; iter
; iter
= iter
->next
) {
525 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
529 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
530 exprval_release(&exprval
);
534 V_VT(&val
) = VT_EMPTY
;
537 hres
= jsdisp_propput_name(ctx
->var_disp
, iter
->identifier
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
546 /* ECMA-262 3rd Edition 12.2 */
547 HRESULT
var_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
549 var_statement_t
*stat
= (var_statement_t
*)_stat
;
554 hres
= variable_list_eval(ctx
, stat
->variable_list
, &rt
->ei
);
558 V_VT(ret
) = VT_EMPTY
;
562 /* ECMA-262 3rd Edition 12.3 */
563 HRESULT
empty_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
567 V_VT(ret
) = VT_EMPTY
;
571 /* ECMA-262 3rd Edition 12.4 */
572 HRESULT
expression_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
574 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
581 hres
= expr_eval(ctx
, stat
->expr
, EXPR_NOVAL
, &rt
->ei
, &exprval
);
585 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
586 exprval_release(&exprval
);
591 TRACE("= %s\n", debugstr_variant(ret
));
595 /* ECMA-262 3rd Edition 12.5 */
596 HRESULT
if_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
598 if_statement_t
*stat
= (if_statement_t
*)_stat
;
605 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
609 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
610 exprval_release(&exprval
);
615 hres
= stat_eval(ctx
, stat
->if_stat
, rt
, ret
);
616 else if(stat
->else_stat
)
617 hres
= stat_eval(ctx
, stat
->else_stat
, rt
, ret
);
619 V_VT(ret
) = VT_EMPTY
;
624 /* ECMA-262 3rd Edition 12.6.2 */
625 HRESULT
while_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
627 while_statement_t
*stat
= (while_statement_t
*)_stat
;
636 V_VT(&val
) = VT_EMPTY
;
637 test_expr
= !stat
->do_while
;
641 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
645 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
646 exprval_release(&exprval
);
647 if(FAILED(hres
) || !b
)
653 hres
= stat_eval(ctx
, stat
->statement
, rt
, &tmp
);
660 if(rt
->type
== RT_CONTINUE
)
661 rt
->type
= RT_NORMAL
;
662 if(rt
->type
!= RT_NORMAL
)
671 if(rt
->type
== RT_BREAK
)
672 rt
->type
= RT_NORMAL
;
678 /* ECMA-262 3rd Edition 12.6.3 */
679 HRESULT
for_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
681 for_statement_t
*stat
= (for_statement_t
*)_stat
;
682 VARIANT val
, tmp
, retv
;
689 if(stat
->variable_list
) {
690 hres
= variable_list_eval(ctx
, stat
->variable_list
, &rt
->ei
);
693 }else if(stat
->begin_expr
) {
694 hres
= expr_eval(ctx
, stat
->begin_expr
, EXPR_NEWREF
, &rt
->ei
, &exprval
);
698 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
699 exprval_release(&exprval
);
706 V_VT(&retv
) = VT_EMPTY
;
710 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
714 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
715 exprval_release(&exprval
);
716 if(FAILED(hres
) || !b
)
720 hres
= stat_eval(ctx
, stat
->statement
, rt
, &tmp
);
727 if(rt
->type
== RT_CONTINUE
)
728 rt
->type
= RT_NORMAL
;
729 else if(rt
->type
!= RT_NORMAL
)
733 hres
= expr_eval(ctx
, stat
->end_expr
, 0, &rt
->ei
, &exprval
);
737 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
738 exprval_release(&exprval
);
751 if(rt
->type
== RT_BREAK
)
752 rt
->type
= RT_NORMAL
;
758 /* ECMA-262 3rd Edition 12.6.4 */
759 HRESULT
forin_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
761 forin_statement_t
*stat
= (forin_statement_t
*)_stat
;
762 VARIANT val
, name
, retv
, tmp
;
763 DISPID id
= DISPID_STARTENUM
;
764 BSTR str
, identifier
= NULL
;
772 hres
= variable_list_eval(ctx
, stat
->variable
, &rt
->ei
);
777 hres
= expr_eval(ctx
, stat
->in_expr
, EXPR_NEWREF
, &rt
->ei
, &exprval
);
781 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
782 exprval_release(&exprval
);
786 if(V_VT(&val
) != VT_DISPATCH
) {
787 TRACE("in vt %d\n", V_VT(&val
));
789 V_VT(ret
) = VT_EMPTY
;
793 hres
= IDispatch_QueryInterface(V_DISPATCH(&val
), &IID_IDispatchEx
, (void**)&in_obj
);
794 IDispatch_Release(V_DISPATCH(&val
));
796 FIXME("Object doesn't support IDispatchEx\n");
800 V_VT(&retv
) = VT_EMPTY
;
803 identifier
= SysAllocString(stat
->variable
->identifier
);
806 hres
= IDispatchEx_GetNextDispID(in_obj
, fdexEnumDefault
, id
, &id
);
807 if(FAILED(hres
) || hres
== S_FALSE
)
810 hres
= IDispatchEx_GetMemberName(in_obj
, id
, &str
);
814 TRACE("iter %s\n", debugstr_w(str
));
817 hres
= identifier_eval(ctx
, identifier
, 0, &exprval
);
819 hres
= expr_eval(ctx
, stat
->expr
, EXPR_NEWREF
, &rt
->ei
, &exprval
);
820 if(SUCCEEDED(hres
)) {
821 V_VT(&name
) = VT_BSTR
;
823 hres
= put_value(ctx
->parser
->script
, &exprval
, &name
, &rt
->ei
);
824 exprval_release(&exprval
);
830 hres
= stat_eval(ctx
, stat
->statement
, rt
, &tmp
);
837 if(rt
->type
== RT_CONTINUE
)
838 rt
->type
= RT_NORMAL
;
839 else if(rt
->type
!= RT_NORMAL
)
843 SysFreeString(identifier
);
844 IDispatchEx_Release(in_obj
);
850 if(rt
->type
== RT_BREAK
)
851 rt
->type
= RT_NORMAL
;
857 /* ECMA-262 3rd Edition 12.7 */
858 HRESULT
continue_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
860 branch_statement_t
*stat
= (branch_statement_t
*)_stat
;
864 if(stat
->identifier
) {
865 FIXME("indentifier not implemented\n");
869 rt
->type
= RT_CONTINUE
;
870 V_VT(ret
) = VT_EMPTY
;
874 /* ECMA-262 3rd Edition 12.8 */
875 HRESULT
break_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
877 branch_statement_t
*stat
= (branch_statement_t
*)_stat
;
881 if(stat
->identifier
) {
882 FIXME("indentifier not implemented\n");
887 V_VT(ret
) = VT_EMPTY
;
891 /* ECMA-262 3rd Edition 12.9 */
892 HRESULT
return_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
894 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
902 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
906 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, ret
);
907 exprval_release(&exprval
);
911 V_VT(ret
) = VT_EMPTY
;
914 TRACE("= %s\n", debugstr_variant(ret
));
915 rt
->type
= RT_RETURN
;
919 /* ECMA-262 3rd Edition 12.10 */
920 HRESULT
with_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
922 with_statement_t
*stat
= (with_statement_t
*)_stat
;
931 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
935 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
936 exprval_release(&exprval
);
940 hres
= to_object(ctx
, &val
, &disp
);
945 obj
= iface_to_jsdisp((IUnknown
*)disp
);
946 IDispatch_Release(disp
);
948 FIXME("disp id not jsdisp\n");
952 hres
= scope_push(ctx
->scope_chain
, obj
, &ctx
->scope_chain
);
956 hres
= stat_eval(ctx
, stat
->statement
, rt
, ret
);
958 scope_pop(&ctx
->scope_chain
);
962 /* ECMA-262 3rd Edition 12.12 */
963 HRESULT
labelled_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
969 /* ECMA-262 3rd Edition 12.13 */
970 HRESULT
switch_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
972 switch_statement_t
*stat
= (switch_statement_t
*)_stat
;
973 case_clausule_t
*iter
, *default_clausule
= NULL
;
974 statement_t
*stat_iter
;
982 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
986 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
987 exprval_release(&exprval
);
991 for(iter
= stat
->case_list
; iter
; iter
= iter
->next
) {
993 default_clausule
= iter
;
997 hres
= expr_eval(ctx
, iter
->expr
, 0, &rt
->ei
, &exprval
);
1001 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &cval
);
1002 exprval_release(&exprval
);
1006 hres
= equal2_values(&val
, &cval
, &b
);
1007 VariantClear(&cval
);
1008 if(FAILED(hres
) || b
)
1017 iter
= default_clausule
;
1019 V_VT(&val
) = VT_EMPTY
;
1023 for(stat_iter
= iter
->stat
; stat_iter
; stat_iter
= stat_iter
->next
) {
1024 hres
= stat_eval(ctx
, stat_iter
, rt
, &tmp
);
1031 if(rt
->type
!= RT_NORMAL
)
1041 if(rt
->type
== RT_BREAK
)
1042 rt
->type
= RT_NORMAL
;
1048 /* ECMA-262 3rd Edition 12.13 */
1049 HRESULT
throw_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
1051 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
1058 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
1062 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
1063 exprval_release(&exprval
);
1068 return DISP_E_EXCEPTION
;
1071 /* ECMA-262 3rd Edition 12.14 */
1072 static HRESULT
catch_eval(exec_ctx_t
*ctx
, catch_block_t
*block
, return_type_t
*rt
, VARIANT
*ret
)
1074 DispatchEx
*var_disp
;
1079 memset(&rt
->ei
, 0, sizeof(jsexcept_t
));
1081 hres
= create_dispex(ctx
->parser
->script
, NULL
, NULL
, &var_disp
);
1082 if(SUCCEEDED(hres
)) {
1083 hres
= jsdisp_propput_name(var_disp
, block
->identifier
, ctx
->parser
->script
->lcid
,
1084 &ex
, &rt
->ei
, NULL
/*FIXME*/);
1085 if(SUCCEEDED(hres
)) {
1086 hres
= scope_push(ctx
->scope_chain
, var_disp
, &ctx
->scope_chain
);
1087 if(SUCCEEDED(hres
)) {
1088 hres
= stat_eval(ctx
, block
->statement
, rt
, &val
);
1089 scope_pop(&ctx
->scope_chain
);
1093 jsdisp_release(var_disp
);
1104 /* ECMA-262 3rd Edition 12.14 */
1105 HRESULT
try_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
1107 try_statement_t
*stat
= (try_statement_t
*)_stat
;
1113 hres
= stat_eval(ctx
, stat
->try_statement
, rt
, &val
);
1115 TRACE("EXCEPTION\n");
1116 if(!stat
->catch_block
)
1119 hres
= catch_eval(ctx
, stat
->catch_block
, rt
, &val
);
1124 if(stat
->finally_statement
) {
1126 hres
= stat_eval(ctx
, stat
->finally_statement
, rt
, &val
);
1135 static HRESULT
return_bool(exprval_t
*ret
, DWORD b
)
1137 ret
->type
= EXPRVAL_VARIANT
;
1138 V_VT(&ret
->u
.var
) = VT_BOOL
;
1139 V_BOOL(&ret
->u
.var
) = b
? VARIANT_TRUE
: VARIANT_FALSE
;
1144 static HRESULT
get_binary_expr_values(exec_ctx_t
*ctx
, binary_expression_t
*expr
, jsexcept_t
*ei
, VARIANT
*lval
, VARIANT
*rval
)
1149 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1153 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, lval
);
1154 exprval_release(&exprval
);
1158 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1159 if(SUCCEEDED(hres
)) {
1160 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, rval
);
1161 exprval_release(&exprval
);
1172 typedef HRESULT (*oper_t
)(exec_ctx_t
*,VARIANT
*,VARIANT
*,jsexcept_t
*,VARIANT
*);
1174 static HRESULT
binary_expr_eval(exec_ctx_t
*ctx
, binary_expression_t
*expr
, oper_t oper
, jsexcept_t
*ei
,
1177 VARIANT lval
, rval
, retv
;
1180 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1184 hres
= oper(ctx
, &lval
, &rval
, ei
, &retv
);
1185 VariantClear(&lval
);
1186 VariantClear(&rval
);
1190 ret
->type
= EXPRVAL_VARIANT
;
1195 /* ECMA-262 3rd Edition 11.13.2 */
1196 static HRESULT
assign_oper_eval(exec_ctx_t
*ctx
, expression_t
*lexpr
, expression_t
*rexpr
, oper_t oper
,
1197 jsexcept_t
*ei
, exprval_t
*ret
)
1199 VARIANT retv
, lval
, rval
;
1200 exprval_t exprval
, exprvalr
;
1203 hres
= expr_eval(ctx
, lexpr
, EXPR_NEWREF
, ei
, &exprval
);
1207 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &lval
);
1208 if(SUCCEEDED(hres
)) {
1209 hres
= expr_eval(ctx
, rexpr
, 0, ei
, &exprvalr
);
1210 if(SUCCEEDED(hres
)) {
1211 hres
= exprval_value(ctx
->parser
->script
, &exprvalr
, ei
, &rval
);
1212 exprval_release(&exprvalr
);
1214 if(SUCCEEDED(hres
)) {
1215 hres
= oper(ctx
, &lval
, &rval
, ei
, &retv
);
1216 VariantClear(&rval
);
1218 VariantClear(&lval
);
1221 if(SUCCEEDED(hres
)) {
1222 hres
= put_value(ctx
->parser
->script
, &exprval
, &retv
, ei
);
1224 VariantClear(&retv
);
1226 exprval_release(&exprval
);
1231 ret
->type
= EXPRVAL_VARIANT
;
1236 /* ECMA-262 3rd Edition 13 */
1237 HRESULT
function_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1239 function_expression_t
*expr
= (function_expression_t
*)_expr
;
1246 hres
= create_source_function(ctx
->parser
, expr
->parameter_list
, expr
->source_elements
, ctx
->scope_chain
,
1247 expr
->src_str
, expr
->src_len
, &dispex
);
1251 V_VT(&var
) = VT_DISPATCH
;
1252 V_DISPATCH(&var
) = (IDispatch
*)_IDispatchEx_(dispex
);
1254 if(expr
->identifier
) {
1255 hres
= jsdisp_propput_name(ctx
->var_disp
, expr
->identifier
, ctx
->parser
->script
->lcid
, &var
, ei
, NULL
/*FIXME*/);
1257 jsdisp_release(dispex
);
1262 ret
->type
= EXPRVAL_VARIANT
;
1267 /* ECMA-262 3rd Edition 11.12 */
1268 HRESULT
conditional_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1270 conditional_expression_t
*expr
= (conditional_expression_t
*)_expr
;
1277 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1281 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, ei
, &b
);
1282 exprval_release(&exprval
);
1286 return expr_eval(ctx
, b
? expr
->true_expression
: expr
->false_expression
, flags
, ei
, ret
);
1289 /* ECMA-262 3rd Edition 11.2.1 */
1290 HRESULT
array_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1292 array_expression_t
*expr
= (array_expression_t
*)_expr
;
1294 VARIANT member
, val
;
1297 IDispatch
*obj
= NULL
;
1302 hres
= expr_eval(ctx
, expr
->member_expr
, EXPR_NEWREF
, ei
, &exprval
);
1306 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &member
);
1307 exprval_release(&exprval
);
1311 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
1312 if(SUCCEEDED(hres
)) {
1313 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1314 exprval_release(&exprval
);
1318 hres
= to_object(ctx
, &member
, &obj
);
1319 VariantClear(&member
);
1320 if(SUCCEEDED(hres
)) {
1321 hres
= to_string(ctx
->parser
->script
, &val
, ei
, &str
);
1322 if(SUCCEEDED(hres
)) {
1323 if(flags
& EXPR_STRREF
) {
1324 ret
->type
= EXPRVAL_NAMEREF
;
1325 ret
->u
.nameref
.disp
= obj
;
1326 ret
->u
.nameref
.name
= str
;
1330 hres
= disp_get_id(obj
, str
, flags
& EXPR_NEWREF
? fdexNameEnsure
: 0, &id
);
1333 if(SUCCEEDED(hres
)) {
1334 exprval_set_idref(ret
, obj
, id
);
1335 }else if(!(flags
& EXPR_NEWREF
) && hres
== DISP_E_UNKNOWNNAME
) {
1340 IDispatch_Release(obj
);
1346 /* ECMA-262 3rd Edition 11.2.1 */
1347 HRESULT
member_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1349 member_expression_t
*expr
= (member_expression_t
*)_expr
;
1350 IDispatch
*obj
= NULL
;
1359 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1363 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &member
);
1364 exprval_release(&exprval
);
1368 hres
= to_object(ctx
, &member
, &obj
);
1369 VariantClear(&member
);
1373 str
= SysAllocString(expr
->identifier
);
1374 if(flags
& EXPR_STRREF
) {
1375 ret
->type
= EXPRVAL_NAMEREF
;
1376 ret
->u
.nameref
.disp
= obj
;
1377 ret
->u
.nameref
.name
= str
;
1381 hres
= disp_get_id(obj
, str
, flags
& EXPR_NEWREF
? fdexNameEnsure
: 0, &id
);
1383 if(SUCCEEDED(hres
)) {
1384 exprval_set_idref(ret
, obj
, id
);
1385 }else if(!(flags
& EXPR_NEWREF
) && hres
== DISP_E_UNKNOWNNAME
) {
1390 IDispatch_Release(obj
);
1394 static void free_dp(DISPPARAMS
*dp
)
1398 for(i
=0; i
< dp
->cArgs
; i
++)
1399 VariantClear(dp
->rgvarg
+i
);
1400 heap_free(dp
->rgvarg
);
1403 static HRESULT
args_to_param(exec_ctx_t
*ctx
, argument_t
*args
, jsexcept_t
*ei
, DISPPARAMS
*dp
)
1409 HRESULT hres
= S_OK
;
1411 memset(dp
, 0, sizeof(*dp
));
1415 for(iter
= args
; iter
; iter
= iter
->next
)
1418 vargs
= heap_alloc_zero(cnt
* sizeof(*vargs
));
1420 return E_OUTOFMEMORY
;
1422 for(i
= cnt
, iter
= args
; iter
; iter
= iter
->next
) {
1423 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
1427 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, vargs
+ (--i
));
1428 exprval_release(&exprval
);
1443 /* ECMA-262 3rd Edition 11.2.2 */
1444 HRESULT
new_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1446 call_expression_t
*expr
= (call_expression_t
*)_expr
;
1448 VARIANT constr
, var
;
1454 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1458 hres
= args_to_param(ctx
, expr
->argument_list
, ei
, &dp
);
1460 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &constr
);
1461 exprval_release(&exprval
);
1465 if(V_VT(&constr
) != VT_DISPATCH
) {
1466 FIXME("throw TypeError\n");
1467 VariantClear(&constr
);
1471 hres
= disp_call(V_DISPATCH(&constr
), DISPID_VALUE
, ctx
->parser
->script
->lcid
,
1472 DISPATCH_CONSTRUCT
, &dp
, &var
, ei
, NULL
/*FIXME*/);
1473 IDispatch_Release(V_DISPATCH(&constr
));
1477 ret
->type
= EXPRVAL_VARIANT
;
1482 /* ECMA-262 3rd Edition 11.2.3 */
1483 HRESULT
call_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1485 call_expression_t
*expr
= (call_expression_t
*)_expr
;
1493 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1497 hres
= args_to_param(ctx
, expr
->argument_list
, ei
, &dp
);
1498 if(SUCCEEDED(hres
)) {
1499 switch(exprval
.type
) {
1501 hres
= disp_call(exprval
.u
.idref
.disp
, exprval
.u
.idref
.id
, ctx
->parser
->script
->lcid
, DISPATCH_METHOD
,
1502 &dp
, flags
& EXPR_NOVAL
? NULL
: &var
, ei
, NULL
/*FIXME*/);
1503 if(flags
& EXPR_NOVAL
)
1504 V_VT(&var
) = VT_EMPTY
;
1507 FIXME("unimplemented type %d\n", V_VT(&func
));
1514 exprval_release(&exprval
);
1518 TRACE("= %s\n", debugstr_variant(&var
));
1519 ret
->type
= EXPRVAL_VARIANT
;
1524 /* ECMA-262 3rd Edition 11.1.1 */
1525 HRESULT
this_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1529 ret
->type
= EXPRVAL_VARIANT
;
1530 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1531 V_DISPATCH(&ret
->u
.var
) = ctx
->this_obj
;
1532 IDispatch_AddRef(ctx
->this_obj
);
1536 /* ECMA-262 3rd Edition 10.1.4 */
1537 HRESULT
identifier_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1539 identifier_expression_t
*expr
= (identifier_expression_t
*)_expr
;
1545 identifier
= SysAllocString(expr
->identifier
);
1547 return E_OUTOFMEMORY
;
1549 hres
= identifier_eval(ctx
, identifier
, flags
, ret
);
1551 SysFreeString(identifier
);
1555 /* ECMA-262 3rd Edition 7.8 */
1556 HRESULT
literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1558 literal_expression_t
*expr
= (literal_expression_t
*)_expr
;
1564 hres
= literal_to_var(expr
->literal
, &var
);
1568 ret
->type
= EXPRVAL_VARIANT
;
1573 /* ECMA-262 3rd Edition 11.1.4 */
1574 HRESULT
array_literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1576 array_literal_expression_t
*expr
= (array_literal_expression_t
*)_expr
;
1577 DWORD length
= 0, i
= 0;
1578 array_element_t
*elem
;
1586 for(elem
= expr
->element_list
; elem
; elem
= elem
->next
)
1587 length
+= elem
->elision
+1;
1588 length
+= expr
->length
;
1590 hres
= create_array(ctx
->parser
->script
, length
, &array
);
1594 for(elem
= expr
->element_list
; elem
; elem
= elem
->next
) {
1597 hres
= expr_eval(ctx
, elem
->expr
, 0, ei
, &exprval
);
1601 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1602 exprval_release(&exprval
);
1606 hres
= jsdisp_propput_idx(array
, i
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
1615 jsdisp_release(array
);
1619 ret
->type
= EXPRVAL_VARIANT
;
1620 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1621 V_DISPATCH(&ret
->u
.var
) = (IDispatch
*)_IDispatchEx_(array
);
1625 /* ECMA-262 3rd Edition 11.1.5 */
1626 HRESULT
property_value_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1628 property_value_expression_t
*expr
= (property_value_expression_t
*)_expr
;
1638 hres
= create_object(ctx
->parser
->script
, NULL
, &obj
);
1642 for(iter
= expr
->property_list
; iter
; iter
= iter
->next
) {
1643 hres
= literal_to_var(iter
->name
, &tmp
);
1647 hres
= to_string(ctx
->parser
->script
, &tmp
, ei
, &name
);
1652 hres
= expr_eval(ctx
, iter
->value
, 0, ei
, &exprval
);
1653 if(SUCCEEDED(hres
)) {
1654 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1655 exprval_release(&exprval
);
1656 if(SUCCEEDED(hres
)) {
1657 hres
= jsdisp_propput_name(obj
, name
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
1662 SysFreeString(name
);
1668 jsdisp_release(obj
);
1672 ret
->type
= EXPRVAL_VARIANT
;
1673 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1674 V_DISPATCH(&ret
->u
.var
) = (IDispatch
*)_IDispatchEx_(obj
);
1678 /* ECMA-262 3rd Edition 11.14 */
1679 HRESULT
comma_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1681 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1687 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1691 VariantClear(&lval
);
1693 ret
->type
= EXPRVAL_VARIANT
;
1698 /* ECMA-262 3rd Edition 11.11 */
1699 HRESULT
logical_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1701 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1709 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1713 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1714 exprval_release(&exprval
);
1718 hres
= to_boolean(&val
, &b
);
1719 if(SUCCEEDED(hres
) && b
) {
1720 ret
->type
= EXPRVAL_VARIANT
;
1729 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1733 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1734 exprval_release(&exprval
);
1738 ret
->type
= EXPRVAL_VARIANT
;
1743 /* ECMA-262 3rd Edition 11.11 */
1744 HRESULT
logical_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1746 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1754 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1758 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1759 exprval_release(&exprval
);
1763 hres
= to_boolean(&val
, &b
);
1764 if(SUCCEEDED(hres
) && !b
) {
1765 ret
->type
= EXPRVAL_VARIANT
;
1774 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1778 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1779 exprval_release(&exprval
);
1783 ret
->type
= EXPRVAL_VARIANT
;
1788 /* ECMA-262 3rd Edition 11.10 */
1789 static HRESULT
bitor_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1794 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
1798 hres
= to_int32(ctx
->parser
->script
, rval
, ei
, &ri
);
1807 /* ECMA-262 3rd Edition 11.10 */
1808 HRESULT
binary_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1810 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1814 return binary_expr_eval(ctx
, expr
, bitor_eval
, ei
, ret
);
1817 /* ECMA-262 3rd Edition 11.10 */
1818 static HRESULT
xor_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1823 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
1827 hres
= to_int32(ctx
->parser
->script
, rval
, ei
, &ri
);
1836 /* ECMA-262 3rd Edition 11.10 */
1837 HRESULT
binary_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1839 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1843 return binary_expr_eval(ctx
, expr
, xor_eval
, ei
, ret
);
1846 /* ECMA-262 3rd Edition 11.10 */
1847 static HRESULT
bitand_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1852 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
1856 hres
= to_int32(ctx
->parser
->script
, rval
, ei
, &ri
);
1865 /* ECMA-262 3rd Edition 11.10 */
1866 HRESULT
binary_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1868 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1872 return binary_expr_eval(ctx
, expr
, bitand_eval
, ei
, ret
);
1875 /* ECMA-262 3rd Edition 11.8.6 */
1876 HRESULT
instanceof_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1882 /* ECMA-262 3rd Edition 11.8.7 */
1883 HRESULT
in_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1889 /* ECMA-262 3rd Edition 11.6.1 */
1890 static HRESULT
add_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1895 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &l
);
1899 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &r
);
1905 if(V_VT(&l
) == VT_BSTR
|| V_VT(&r
) == VT_BSTR
) {
1906 BSTR lstr
= NULL
, rstr
= NULL
;
1908 if(V_VT(&l
) == VT_BSTR
)
1911 hres
= to_string(ctx
->parser
->script
, &l
, ei
, &lstr
);
1913 if(SUCCEEDED(hres
)) {
1914 if(V_VT(&r
) == VT_BSTR
)
1917 hres
= to_string(ctx
->parser
->script
, &r
, ei
, &rstr
);
1920 if(SUCCEEDED(hres
)) {
1923 len1
= SysStringLen(lstr
);
1924 len2
= SysStringLen(rstr
);
1926 V_VT(retv
) = VT_BSTR
;
1927 V_BSTR(retv
) = SysAllocStringLen(NULL
, len1
+len2
);
1928 memcpy(V_BSTR(retv
), lstr
, len1
*sizeof(WCHAR
));
1929 memcpy(V_BSTR(retv
)+len1
, rstr
, (len2
+1)*sizeof(WCHAR
));
1932 if(lstr
&& V_VT(&l
) != VT_BSTR
)
1933 SysFreeString(lstr
);
1934 if(rstr
&& V_VT(&r
) != VT_BSTR
)
1935 SysFreeString(rstr
);
1939 hres
= to_number(ctx
->parser
->script
, &l
, ei
, &nl
);
1940 if(SUCCEEDED(hres
)) {
1941 hres
= to_number(ctx
->parser
->script
, &r
, ei
, &nr
);
1943 num_set_val(retv
, num_val(&nl
) + num_val(&nr
));
1952 /* ECMA-262 3rd Edition 11.6.1 */
1953 HRESULT
add_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1955 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1959 return binary_expr_eval(ctx
, expr
, add_eval
, ei
, ret
);
1962 /* ECMA-262 3rd Edition 11.6.2 */
1963 static HRESULT
sub_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1968 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
1972 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
1976 num_set_val(retv
, num_val(&lnum
) - num_val(&rnum
));
1980 /* ECMA-262 3rd Edition 11.6.2 */
1981 HRESULT
sub_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1983 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1987 return binary_expr_eval(ctx
, expr
, sub_eval
, ei
, ret
);
1990 /* ECMA-262 3rd Edition 11.5.1 */
1991 static HRESULT
mul_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1996 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2000 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2004 num_set_val(retv
, num_val(&lnum
) * num_val(&rnum
));
2008 /* ECMA-262 3rd Edition 11.5.1 */
2009 HRESULT
mul_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2011 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2015 return binary_expr_eval(ctx
, expr
, mul_eval
, ei
, ret
);
2018 /* ECMA-262 3rd Edition 11.5.2 */
2019 static HRESULT
div_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2024 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2028 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2032 num_set_val(retv
, num_val(&lnum
) / num_val(&rnum
));
2036 /* ECMA-262 3rd Edition 11.5.2 */
2037 HRESULT
div_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2039 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2043 return binary_expr_eval(ctx
, expr
, div_eval
, ei
, ret
);
2046 /* ECMA-262 3rd Edition 11.5.3 */
2047 HRESULT
mod_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2053 /* ECMA-262 3rd Edition 11.4.2 */
2054 HRESULT
delete_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2056 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2057 VARIANT_BOOL b
= VARIANT_FALSE
;
2063 hres
= expr_eval(ctx
, expr
->expression
, EXPR_STRREF
, ei
, &exprval
);
2067 switch(exprval
.type
) {
2068 case EXPRVAL_NAMEREF
: {
2069 IDispatchEx
*dispex
;
2071 hres
= IDispatch_QueryInterface(exprval
.u
.nameref
.disp
, &IID_IDispatchEx
, (void**)&dispex
);
2072 if(SUCCEEDED(hres
)) {
2073 hres
= IDispatchEx_DeleteMemberByName(dispex
, exprval
.u
.nameref
.name
, fdexNameCaseSensitive
);
2075 IDispatchEx_Release(dispex
);
2080 FIXME("unsupported type %d\n", exprval
.type
);
2084 exprval_release(&exprval
);
2088 return return_bool(ret
, b
);
2091 /* ECMA-262 3rd Edition 11.4.2 */
2092 HRESULT
void_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2094 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2101 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
2105 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &tmp
);
2106 exprval_release(&exprval
);
2112 ret
->type
= EXPRVAL_VARIANT
;
2113 V_VT(&ret
->u
.var
) = VT_EMPTY
;
2117 /* ECMA-262 3rd Edition 11.4.3 */
2118 HRESULT
typeof_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2120 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2126 static const WCHAR booleanW
[] = {'b','o','o','l','e','a','n',0};
2127 static const WCHAR functionW
[] = {'f','u','n','c','t','i','o','n',0};
2128 static const WCHAR numberW
[] = {'n','u','m','b','e','r',0};
2129 static const WCHAR objectW
[] = {'o','b','j','e','c','t',0};
2130 static const WCHAR stringW
[] = {'s','t','r','i','n','g',0};
2131 static const WCHAR undefinedW
[] = {'u','n','d','e','f','i','n','e','d',0};
2135 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
2139 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2140 exprval_release(&exprval
);
2144 switch(V_VT(&val
)) {
2164 dispex
= iface_to_jsdisp((IUnknown
*)V_DISPATCH(&val
));
2166 str
= dispex
->builtin_info
->class == JSCLASS_FUNCTION
? functionW
: objectW
;
2167 IDispatchEx_Release(_IDispatchEx_(dispex
));
2174 FIXME("unhandled vt %d\n", V_VT(&val
));
2182 ret
->type
= EXPRVAL_VARIANT
;
2183 V_VT(&ret
->u
.var
) = VT_BSTR
;
2184 V_BSTR(&ret
->u
.var
) = SysAllocString(str
);
2188 /* ECMA-262 3rd Edition 11.4.7 */
2189 HRESULT
minus_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2191 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2198 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
2202 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2203 exprval_release(&exprval
);
2207 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2212 ret
->type
= EXPRVAL_VARIANT
;
2213 num_set_val(&ret
->u
.var
, -num_val(&num
));
2217 /* ECMA-262 3rd Edition 11.4.6 */
2218 HRESULT
plus_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2220 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2227 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2231 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2232 exprval_release(&exprval
);
2236 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2240 ret
->type
= EXPRVAL_VARIANT
;
2245 /* ECMA-262 3rd Edition 11.3.1 */
2246 HRESULT
post_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2248 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2255 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2259 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2260 if(SUCCEEDED(hres
)) {
2261 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2265 if(SUCCEEDED(hres
)) {
2267 num_set_val(&inc
, num_val(&num
)+1.0);
2268 hres
= put_value(ctx
->parser
->script
, &exprval
, &inc
, ei
);
2271 exprval_release(&exprval
);
2275 ret
->type
= EXPRVAL_VARIANT
;
2280 /* ECMA-262 3rd Edition 11.3.2 */
2281 HRESULT
post_decrement_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2283 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2290 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2294 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2295 if(SUCCEEDED(hres
)) {
2296 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2300 if(SUCCEEDED(hres
)) {
2302 num_set_val(&dec
, num_val(&num
)-1.0);
2303 hres
= put_value(ctx
->parser
->script
, &exprval
, &dec
, ei
);
2306 exprval_release(&exprval
);
2310 ret
->type
= EXPRVAL_VARIANT
;
2315 /* ECMA-262 3rd Edition 11.4.4 */
2316 HRESULT
pre_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2318 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2325 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2329 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2330 if(SUCCEEDED(hres
)) {
2331 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2335 if(SUCCEEDED(hres
)) {
2336 num_set_val(&val
, num_val(&num
)+1.0);
2337 hres
= put_value(ctx
->parser
->script
, &exprval
, &val
, ei
);
2340 exprval_release(&exprval
);
2344 ret
->type
= EXPRVAL_VARIANT
;
2349 /* ECMA-262 3rd Edition 11.4.5 */
2350 HRESULT
pre_decrement_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2352 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2359 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2363 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2364 if(SUCCEEDED(hres
)) {
2365 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2369 if(SUCCEEDED(hres
)) {
2370 num_set_val(&val
, num_val(&num
)-1.0);
2371 hres
= put_value(ctx
->parser
->script
, &exprval
, &val
, ei
);
2374 exprval_release(&exprval
);
2378 ret
->type
= EXPRVAL_VARIANT
;
2383 /* ECMA-262 3rd Edition 11.9.3 */
2384 static HRESULT
equal_values(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, BOOL
*ret
)
2386 if(V_VT(lval
) == V_VT(rval
) || (is_num_vt(V_VT(lval
)) && is_num_vt(V_VT(rval
))))
2387 return equal2_values(lval
, rval
, ret
);
2389 /* FIXME: NULL disps should be handled in more general way */
2390 if(V_VT(lval
) == VT_DISPATCH
&& !V_DISPATCH(lval
)) {
2393 return equal_values(ctx
, &v
, rval
, ei
, ret
);
2396 if(V_VT(rval
) == VT_DISPATCH
&& !V_DISPATCH(rval
)) {
2399 return equal_values(ctx
, lval
, &v
, ei
, ret
);
2402 if((V_VT(lval
) == VT_NULL
&& V_VT(rval
) == VT_EMPTY
) ||
2403 (V_VT(lval
) == VT_EMPTY
&& V_VT(rval
) == VT_NULL
)) {
2408 if(V_VT(lval
) == VT_BSTR
&& is_num_vt(V_VT(rval
))) {
2412 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &v
);
2416 return equal_values(ctx
, &v
, rval
, ei
, ret
);
2419 if(V_VT(rval
) == VT_BSTR
&& is_num_vt(V_VT(lval
))) {
2423 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &v
);
2427 return equal_values(ctx
, lval
, &v
, ei
, ret
);
2430 if(V_VT(rval
) == VT_BOOL
) {
2434 V_I4(&v
) = V_BOOL(rval
) ? 1 : 0;
2435 return equal_values(ctx
, lval
, &v
, ei
, ret
);
2438 if(V_VT(lval
) == VT_BOOL
) {
2442 V_I4(&v
) = V_BOOL(lval
) ? 1 : 0;
2443 return equal_values(ctx
, &v
, rval
, ei
, ret
);
2447 if(V_VT(rval
) == VT_DISPATCH
&& (V_VT(lval
) == VT_BSTR
|| is_num_vt(V_VT(lval
)))) {
2451 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &v
);
2455 hres
= equal_values(ctx
, lval
, &v
, ei
, ret
);
2462 if(V_VT(lval
) == VT_DISPATCH
&& (V_VT(rval
) == VT_BSTR
|| is_num_vt(V_VT(rval
)))) {
2466 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &v
);
2470 hres
= equal_values(ctx
, &v
, rval
, ei
, ret
);
2481 /* ECMA-262 3rd Edition 11.9.1 */
2482 HRESULT
equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2484 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2491 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
2495 hres
= equal_values(ctx
, &rval
, &lval
, ei
, &b
);
2499 return return_bool(ret
, b
);
2502 /* ECMA-262 3rd Edition 11.9.4 */
2503 HRESULT
equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2505 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2512 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
2516 hres
= equal2_values(&rval
, &lval
, &b
);
2520 return return_bool(ret
, b
);
2523 /* ECMA-262 3rd Edition 11.9.2 */
2524 HRESULT
not_equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2526 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2533 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2537 hres
= equal_values(ctx
, &lval
, &rval
, ei
, &b
);
2541 return return_bool(ret
, !b
);
2544 /* ECMA-262 3rd Edition 11.9.5 */
2545 HRESULT
not_equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2547 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2554 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2558 hres
= equal2_values(&lval
, &rval
, &b
);
2562 return return_bool(ret
, !b
);
2565 /* ECMA-262 3rd Edition 11.8.5 */
2566 static HRESULT
less_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, BOOL
*ret
)
2568 VARIANT l
, r
, ln
, rn
;
2571 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &l
);
2575 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &r
);
2581 if(V_VT(&l
) == VT_BSTR
&& V_VT(&r
) == VT_BSTR
) {
2582 *ret
= strcmpW(V_BSTR(&l
), V_BSTR(&r
)) < 0;
2583 SysFreeString(V_BSTR(&l
));
2584 SysFreeString(V_BSTR(&r
));
2588 hres
= to_number(ctx
->parser
->script
, &l
, ei
, &ln
);
2591 hres
= to_number(ctx
->parser
->script
, &r
, ei
, &rn
);
2596 if(V_VT(&ln
) == VT_I4
&& V_VT(&rn
) == VT_I4
)
2597 *ret
= V_I4(&ln
) < V_I4(&rn
);
2599 *ret
= num_val(&ln
) < num_val(&rn
);
2604 /* ECMA-262 3rd Edition 11.8.1 */
2605 HRESULT
less_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2607 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2614 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2618 hres
= less_eval(ctx
, &lval
, &rval
, ei
, &b
);
2619 VariantClear(&lval
);
2620 VariantClear(&rval
);
2624 return return_bool(ret
, b
);
2627 /* ECMA-262 3rd Edition 11.8.3 */
2628 HRESULT
lesseq_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2630 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2637 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2641 hres
= less_eval(ctx
, &rval
, &lval
, ei
, &b
);
2642 VariantClear(&lval
);
2643 VariantClear(&rval
);
2647 return return_bool(ret
, !b
);
2650 /* ECMA-262 3rd Edition 11.8.2 */
2651 HRESULT
greater_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2653 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2660 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2664 hres
= less_eval(ctx
, &rval
, &lval
, ei
, &b
);
2665 VariantClear(&lval
);
2666 VariantClear(&rval
);
2670 return return_bool(ret
, b
);
2673 /* ECMA-262 3rd Edition 11.8.4 */
2674 HRESULT
greatereq_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2676 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2683 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2687 hres
= less_eval(ctx
, &lval
, &rval
, ei
, &b
);
2688 VariantClear(&lval
);
2689 VariantClear(&rval
);
2693 return return_bool(ret
, !b
);
2696 /* ECMA-262 3rd Edition 11.4.8 */
2697 HRESULT
binary_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2699 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2707 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2711 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2712 exprval_release(&exprval
);
2716 hres
= to_int32(ctx
->parser
->script
, &val
, ei
, &i
);
2720 ret
->type
= EXPRVAL_VARIANT
;
2721 V_VT(&ret
->u
.var
) = VT_I4
;
2722 V_I4(&ret
->u
.var
) = ~i
;
2726 /* ECMA-262 3rd Edition 11.4.9 */
2727 HRESULT
logical_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2729 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2736 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2740 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, ei
, &b
);
2741 exprval_release(&exprval
);
2745 return return_bool(ret
, !b
);
2748 /* ECMA-262 3rd Edition 11.7.1 */
2749 static HRESULT
lshift_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2755 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
2759 hres
= to_uint32(ctx
->parser
->script
, rval
, ei
, &ri
);
2764 V_I4(retv
) = li
<< (ri
&0x1f);
2768 /* ECMA-262 3rd Edition 11.7.1 */
2769 HRESULT
left_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2771 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2775 return binary_expr_eval(ctx
, expr
, lshift_eval
, ei
, ret
);
2778 /* ECMA-262 3rd Edition 11.7.2 */
2779 static HRESULT
rshift_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2785 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
2789 hres
= to_uint32(ctx
->parser
->script
, rval
, ei
, &ri
);
2794 V_I4(retv
) = li
>> (ri
&0x1f);
2798 /* ECMA-262 3rd Edition 11.7.2 */
2799 HRESULT
right_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2801 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2805 return binary_expr_eval(ctx
, expr
, rshift_eval
, ei
, ret
);
2808 /* ECMA-262 3rd Edition 11.7.3 */
2809 static HRESULT
rshift2_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2814 hres
= to_uint32(ctx
->parser
->script
, lval
, ei
, &li
);
2818 hres
= to_uint32(ctx
->parser
->script
, rval
, ei
, &ri
);
2823 V_I4(retv
) = li
>> (ri
&0x1f);
2827 /* ECMA-262 3rd Edition 11.7.3 */
2828 HRESULT
right2_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2830 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2834 return binary_expr_eval(ctx
, expr
, rshift2_eval
, ei
, ret
);
2837 /* ECMA-262 3rd Edition 11.13.1 */
2838 HRESULT
assign_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
;
2841 exprval_t exprval
, exprvalr
;
2847 hres
= expr_eval(ctx
, expr
->expression1
, EXPR_NEWREF
, ei
, &exprval
);
2851 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprvalr
);
2852 if(SUCCEEDED(hres
)) {
2853 hres
= exprval_to_value(ctx
->parser
->script
, &exprvalr
, ei
, &rval
);
2854 exprval_release(&exprvalr
);
2858 hres
= put_value(ctx
->parser
->script
, &exprval
, &rval
, ei
);
2860 exprval_release(&exprval
);
2862 VariantClear(&rval
);
2866 ret
->type
= EXPRVAL_VARIANT
;
2871 /* ECMA-262 3rd Edition 11.13.2 */
2872 HRESULT
assign_lshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2874 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2878 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, lshift_eval
, ei
, ret
);
2881 /* ECMA-262 3rd Edition 11.13.2 */
2882 HRESULT
assign_rshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2884 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2888 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, rshift_eval
, ei
, ret
);
2891 /* ECMA-262 3rd Edition 11.13.2 */
2892 HRESULT
assign_rrshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2894 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2898 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, rshift2_eval
, ei
, ret
);
2901 /* ECMA-262 3rd Edition 11.13.2 */
2902 HRESULT
assign_add_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2904 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2908 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, add_eval
, ei
, ret
);
2911 /* ECMA-262 3rd Edition 11.13.2 */
2912 HRESULT
assign_sub_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2914 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2918 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, sub_eval
, ei
, ret
);
2921 /* ECMA-262 3rd Edition 11.13.2 */
2922 HRESULT
assign_mul_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2924 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2928 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, mul_eval
, ei
, ret
);
2931 /* ECMA-262 3rd Edition 11.13.2 */
2932 HRESULT
assign_div_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2934 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2938 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, div_eval
, ei
, ret
);
2941 /* ECMA-262 3rd Edition 11.13.2 */
2942 HRESULT
assign_mod_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2948 /* ECMA-262 3rd Edition 11.13.2 */
2949 HRESULT
assign_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2951 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2955 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, bitand_eval
, ei
, ret
);
2958 /* ECMA-262 3rd Edition 11.13.2 */
2959 HRESULT
assign_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2961 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2965 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, bitor_eval
, ei
, ret
);
2968 /* ECMA-262 3rd Edition 11.13.2 */
2969 HRESULT
assign_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2971 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2975 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, xor_eval
, ei
, ret
);