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
;
184 IDispatch_AddRef(this_obj
);
185 ctx
->this_obj
= this_obj
;
187 IDispatchEx_AddRef(_IDispatchEx_(var_disp
));
188 ctx
->var_disp
= var_disp
;
192 ctx
->scope_chain
= scope
;
199 void exec_release(exec_ctx_t
*ctx
)
205 scope_release(ctx
->scope_chain
);
207 IDispatchEx_Release(_IDispatchEx_(ctx
->var_disp
));
209 IDispatch_Release(ctx
->this_obj
);
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
);
227 hres
= IDispatchEx_GetDispID(dispex
, name
, flags
|fdexNameCaseSensitive
, id
);
228 IDispatchEx_Release(dispex
);
232 /* ECMA-262 3rd Edition 8.7.2 */
233 static HRESULT
put_value(script_ctx_t
*ctx
, exprval_t
*ref
, VARIANT
*v
, jsexcept_t
*ei
)
235 if(ref
->type
!= EXPRVAL_IDREF
)
236 return throw_reference_error(ctx
, ei
, IDS_ILLEGAL_ASSIGN
, NULL
);
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
, jsexcept_t
*ei
, 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 if(item
->flags
& SCRIPTITEM_GLOBALMEMBERS
) {
493 hres
= disp_get_id(item
->disp
, identifier
, 0, &id
);
500 exprval_set_idref(ret
, item
->disp
, id
);
504 hres
= jsdisp_get_id(ctx
->parser
->script
->script_disp
, identifier
, 0, &id
);
505 if(SUCCEEDED(hres
)) {
506 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->parser
->script
->script_disp
), id
);
510 if(flags
& EXPR_NEWREF
) {
511 hres
= jsdisp_get_id(ctx
->var_disp
, identifier
, fdexNameEnsure
, &id
);
515 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->var_disp
), id
);
519 return throw_type_error(ctx
->var_disp
->ctx
, ei
, IDS_UNDEFINED
, identifier
);
522 /* ECMA-262 3rd Edition 12.1 */
523 HRESULT
block_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
525 block_statement_t
*stat
= (block_statement_t
*)_stat
;
532 V_VT(&val
) = VT_EMPTY
;
533 for(iter
= stat
->stat_list
; iter
; iter
= iter
->next
) {
534 hres
= stat_eval(ctx
, iter
, rt
, &tmp
);
540 if(rt
->type
!= RT_NORMAL
)
553 /* ECMA-262 3rd Edition 12.2 */
554 static HRESULT
variable_list_eval(exec_ctx_t
*ctx
, variable_declaration_t
*var_list
, jsexcept_t
*ei
)
556 variable_declaration_t
*iter
;
559 for(iter
= var_list
; iter
; iter
= iter
->next
) {
566 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
570 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
571 exprval_release(&exprval
);
575 hres
= jsdisp_propput_name(ctx
->var_disp
, iter
->identifier
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
584 /* ECMA-262 3rd Edition 12.2 */
585 HRESULT
var_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
587 var_statement_t
*stat
= (var_statement_t
*)_stat
;
592 hres
= variable_list_eval(ctx
, stat
->variable_list
, &rt
->ei
);
596 V_VT(ret
) = VT_EMPTY
;
600 /* ECMA-262 3rd Edition 12.3 */
601 HRESULT
empty_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
605 V_VT(ret
) = VT_EMPTY
;
609 /* ECMA-262 3rd Edition 12.4 */
610 HRESULT
expression_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
612 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
619 hres
= expr_eval(ctx
, stat
->expr
, EXPR_NOVAL
, &rt
->ei
, &exprval
);
623 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
624 exprval_release(&exprval
);
629 TRACE("= %s\n", debugstr_variant(ret
));
633 /* ECMA-262 3rd Edition 12.5 */
634 HRESULT
if_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
636 if_statement_t
*stat
= (if_statement_t
*)_stat
;
643 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
647 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
648 exprval_release(&exprval
);
653 hres
= stat_eval(ctx
, stat
->if_stat
, rt
, ret
);
654 else if(stat
->else_stat
)
655 hres
= stat_eval(ctx
, stat
->else_stat
, rt
, ret
);
657 V_VT(ret
) = VT_EMPTY
;
662 /* ECMA-262 3rd Edition 12.6.2 */
663 HRESULT
while_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
665 while_statement_t
*stat
= (while_statement_t
*)_stat
;
674 V_VT(&val
) = VT_EMPTY
;
675 test_expr
= !stat
->do_while
;
679 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
683 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
684 exprval_release(&exprval
);
685 if(FAILED(hres
) || !b
)
691 hres
= stat_eval(ctx
, stat
->statement
, rt
, &tmp
);
698 if(rt
->type
== RT_CONTINUE
)
699 rt
->type
= RT_NORMAL
;
700 if(rt
->type
!= RT_NORMAL
)
709 if(rt
->type
== RT_BREAK
)
710 rt
->type
= RT_NORMAL
;
716 /* ECMA-262 3rd Edition 12.6.3 */
717 HRESULT
for_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
719 for_statement_t
*stat
= (for_statement_t
*)_stat
;
720 VARIANT val
, tmp
, retv
;
727 if(stat
->variable_list
) {
728 hres
= variable_list_eval(ctx
, stat
->variable_list
, &rt
->ei
);
731 }else if(stat
->begin_expr
) {
732 hres
= expr_eval(ctx
, stat
->begin_expr
, EXPR_NEWREF
, &rt
->ei
, &exprval
);
736 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
737 exprval_release(&exprval
);
744 V_VT(&retv
) = VT_EMPTY
;
748 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
752 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
753 exprval_release(&exprval
);
754 if(FAILED(hres
) || !b
)
758 hres
= stat_eval(ctx
, stat
->statement
, rt
, &tmp
);
765 if(rt
->type
== RT_CONTINUE
)
766 rt
->type
= RT_NORMAL
;
767 else if(rt
->type
!= RT_NORMAL
)
771 hres
= expr_eval(ctx
, stat
->end_expr
, 0, &rt
->ei
, &exprval
);
775 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
776 exprval_release(&exprval
);
789 if(rt
->type
== RT_BREAK
)
790 rt
->type
= RT_NORMAL
;
796 /* ECMA-262 3rd Edition 12.6.4 */
797 HRESULT
forin_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
799 forin_statement_t
*stat
= (forin_statement_t
*)_stat
;
800 VARIANT val
, name
, retv
, tmp
;
801 DISPID id
= DISPID_STARTENUM
;
802 BSTR str
, identifier
= NULL
;
810 hres
= variable_list_eval(ctx
, stat
->variable
, &rt
->ei
);
815 hres
= expr_eval(ctx
, stat
->in_expr
, EXPR_NEWREF
, &rt
->ei
, &exprval
);
819 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
820 exprval_release(&exprval
);
824 if(V_VT(&val
) != VT_DISPATCH
) {
825 TRACE("in vt %d\n", V_VT(&val
));
827 V_VT(ret
) = VT_EMPTY
;
831 hres
= IDispatch_QueryInterface(V_DISPATCH(&val
), &IID_IDispatchEx
, (void**)&in_obj
);
832 IDispatch_Release(V_DISPATCH(&val
));
834 FIXME("Object doesn't support IDispatchEx\n");
838 V_VT(&retv
) = VT_EMPTY
;
841 identifier
= SysAllocString(stat
->variable
->identifier
);
844 hres
= IDispatchEx_GetNextDispID(in_obj
, fdexEnumDefault
, id
, &id
);
845 if(FAILED(hres
) || hres
== S_FALSE
)
848 hres
= IDispatchEx_GetMemberName(in_obj
, id
, &str
);
852 TRACE("iter %s\n", debugstr_w(str
));
855 hres
= identifier_eval(ctx
, identifier
, 0, NULL
, &exprval
);
857 hres
= expr_eval(ctx
, stat
->expr
, EXPR_NEWREF
, &rt
->ei
, &exprval
);
858 if(SUCCEEDED(hres
)) {
859 V_VT(&name
) = VT_BSTR
;
861 hres
= put_value(ctx
->parser
->script
, &exprval
, &name
, &rt
->ei
);
862 exprval_release(&exprval
);
868 hres
= stat_eval(ctx
, stat
->statement
, rt
, &tmp
);
875 if(rt
->type
== RT_CONTINUE
)
876 rt
->type
= RT_NORMAL
;
877 else if(rt
->type
!= RT_NORMAL
)
881 SysFreeString(identifier
);
882 IDispatchEx_Release(in_obj
);
888 if(rt
->type
== RT_BREAK
)
889 rt
->type
= RT_NORMAL
;
895 /* ECMA-262 3rd Edition 12.7 */
896 HRESULT
continue_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
898 branch_statement_t
*stat
= (branch_statement_t
*)_stat
;
902 if(stat
->identifier
) {
903 FIXME("indentifier not implemented\n");
907 rt
->type
= RT_CONTINUE
;
908 V_VT(ret
) = VT_EMPTY
;
912 /* ECMA-262 3rd Edition 12.8 */
913 HRESULT
break_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
915 branch_statement_t
*stat
= (branch_statement_t
*)_stat
;
919 if(stat
->identifier
) {
920 FIXME("indentifier not implemented\n");
925 V_VT(ret
) = VT_EMPTY
;
929 /* ECMA-262 3rd Edition 12.9 */
930 HRESULT
return_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
932 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
940 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
944 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, ret
);
945 exprval_release(&exprval
);
949 V_VT(ret
) = VT_EMPTY
;
952 TRACE("= %s\n", debugstr_variant(ret
));
953 rt
->type
= RT_RETURN
;
957 /* ECMA-262 3rd Edition 12.10 */
958 HRESULT
with_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
960 with_statement_t
*stat
= (with_statement_t
*)_stat
;
969 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
973 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
974 exprval_release(&exprval
);
978 hres
= to_object(ctx
, &val
, &disp
);
983 obj
= iface_to_jsdisp((IUnknown
*)disp
);
984 IDispatch_Release(disp
);
986 FIXME("disp id not jsdisp\n");
990 hres
= scope_push(ctx
->scope_chain
, obj
, &ctx
->scope_chain
);
995 hres
= stat_eval(ctx
, stat
->statement
, rt
, ret
);
997 scope_pop(&ctx
->scope_chain
);
1001 /* ECMA-262 3rd Edition 12.12 */
1002 HRESULT
labelled_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
1008 /* ECMA-262 3rd Edition 12.13 */
1009 HRESULT
switch_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
1011 switch_statement_t
*stat
= (switch_statement_t
*)_stat
;
1012 case_clausule_t
*iter
, *default_clausule
= NULL
;
1013 statement_t
*stat_iter
;
1021 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
1025 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
1026 exprval_release(&exprval
);
1030 for(iter
= stat
->case_list
; iter
; iter
= iter
->next
) {
1032 default_clausule
= iter
;
1036 hres
= expr_eval(ctx
, iter
->expr
, 0, &rt
->ei
, &exprval
);
1040 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &cval
);
1041 exprval_release(&exprval
);
1045 hres
= equal2_values(&val
, &cval
, &b
);
1046 VariantClear(&cval
);
1047 if(FAILED(hres
) || b
)
1056 iter
= default_clausule
;
1058 V_VT(&val
) = VT_EMPTY
;
1062 for(stat_iter
= iter
->stat
; stat_iter
; stat_iter
= stat_iter
->next
) {
1063 hres
= stat_eval(ctx
, stat_iter
, rt
, &tmp
);
1070 if(rt
->type
!= RT_NORMAL
)
1080 if(rt
->type
== RT_BREAK
)
1081 rt
->type
= RT_NORMAL
;
1087 /* ECMA-262 3rd Edition 12.13 */
1088 HRESULT
throw_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
1090 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
1097 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
1101 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
1102 exprval_release(&exprval
);
1107 return DISP_E_EXCEPTION
;
1110 /* ECMA-262 3rd Edition 12.14 */
1111 static HRESULT
catch_eval(exec_ctx_t
*ctx
, catch_block_t
*block
, return_type_t
*rt
, VARIANT
*ret
)
1113 DispatchEx
*var_disp
;
1118 memset(&rt
->ei
, 0, sizeof(jsexcept_t
));
1120 hres
= create_dispex(ctx
->parser
->script
, NULL
, NULL
, &var_disp
);
1121 if(SUCCEEDED(hres
)) {
1122 hres
= jsdisp_propput_name(var_disp
, block
->identifier
, ctx
->parser
->script
->lcid
,
1123 &ex
, &rt
->ei
, NULL
/*FIXME*/);
1124 if(SUCCEEDED(hres
)) {
1125 hres
= scope_push(ctx
->scope_chain
, var_disp
, &ctx
->scope_chain
);
1126 if(SUCCEEDED(hres
)) {
1127 hres
= stat_eval(ctx
, block
->statement
, rt
, &val
);
1128 scope_pop(&ctx
->scope_chain
);
1132 jsdisp_release(var_disp
);
1143 /* ECMA-262 3rd Edition 12.14 */
1144 HRESULT
try_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
1146 try_statement_t
*stat
= (try_statement_t
*)_stat
;
1152 hres
= stat_eval(ctx
, stat
->try_statement
, rt
, &val
);
1154 TRACE("EXCEPTION\n");
1155 if(!stat
->catch_block
)
1158 hres
= catch_eval(ctx
, stat
->catch_block
, rt
, &val
);
1163 if(stat
->finally_statement
) {
1165 hres
= stat_eval(ctx
, stat
->finally_statement
, rt
, &val
);
1174 static HRESULT
return_bool(exprval_t
*ret
, DWORD b
)
1176 ret
->type
= EXPRVAL_VARIANT
;
1177 V_VT(&ret
->u
.var
) = VT_BOOL
;
1178 V_BOOL(&ret
->u
.var
) = b
? VARIANT_TRUE
: VARIANT_FALSE
;
1183 static HRESULT
get_binary_expr_values(exec_ctx_t
*ctx
, binary_expression_t
*expr
, jsexcept_t
*ei
, VARIANT
*lval
, VARIANT
*rval
)
1188 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1192 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, lval
);
1193 exprval_release(&exprval
);
1197 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1198 if(SUCCEEDED(hres
)) {
1199 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, rval
);
1200 exprval_release(&exprval
);
1211 typedef HRESULT (*oper_t
)(exec_ctx_t
*,VARIANT
*,VARIANT
*,jsexcept_t
*,VARIANT
*);
1213 static HRESULT
binary_expr_eval(exec_ctx_t
*ctx
, binary_expression_t
*expr
, oper_t oper
, jsexcept_t
*ei
,
1216 VARIANT lval
, rval
, retv
;
1219 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1223 hres
= oper(ctx
, &lval
, &rval
, ei
, &retv
);
1224 VariantClear(&lval
);
1225 VariantClear(&rval
);
1229 ret
->type
= EXPRVAL_VARIANT
;
1234 /* ECMA-262 3rd Edition 11.13.2 */
1235 static HRESULT
assign_oper_eval(exec_ctx_t
*ctx
, expression_t
*lexpr
, expression_t
*rexpr
, oper_t oper
,
1236 jsexcept_t
*ei
, exprval_t
*ret
)
1238 VARIANT retv
, lval
, rval
;
1239 exprval_t exprval
, exprvalr
;
1242 hres
= expr_eval(ctx
, lexpr
, EXPR_NEWREF
, ei
, &exprval
);
1246 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &lval
);
1247 if(SUCCEEDED(hres
)) {
1248 hres
= expr_eval(ctx
, rexpr
, 0, ei
, &exprvalr
);
1249 if(SUCCEEDED(hres
)) {
1250 hres
= exprval_value(ctx
->parser
->script
, &exprvalr
, ei
, &rval
);
1251 exprval_release(&exprvalr
);
1253 if(SUCCEEDED(hres
)) {
1254 hres
= oper(ctx
, &lval
, &rval
, ei
, &retv
);
1255 VariantClear(&rval
);
1257 VariantClear(&lval
);
1260 if(SUCCEEDED(hres
)) {
1261 hres
= put_value(ctx
->parser
->script
, &exprval
, &retv
, ei
);
1263 VariantClear(&retv
);
1265 exprval_release(&exprval
);
1270 ret
->type
= EXPRVAL_VARIANT
;
1275 /* ECMA-262 3rd Edition 13 */
1276 HRESULT
function_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1278 function_expression_t
*expr
= (function_expression_t
*)_expr
;
1284 if(expr
->identifier
) {
1285 hres
= jsdisp_propget_name(ctx
->var_disp
, expr
->identifier
, ctx
->parser
->script
->lcid
, &var
, ei
, NULL
/*FIXME*/);
1291 hres
= create_source_function(ctx
->parser
, expr
->parameter_list
, expr
->source_elements
, ctx
->scope_chain
,
1292 expr
->src_str
, expr
->src_len
, &dispex
);
1296 V_VT(&var
) = VT_DISPATCH
;
1297 V_DISPATCH(&var
) = (IDispatch
*)_IDispatchEx_(dispex
);
1300 ret
->type
= EXPRVAL_VARIANT
;
1305 /* ECMA-262 3rd Edition 11.12 */
1306 HRESULT
conditional_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1308 conditional_expression_t
*expr
= (conditional_expression_t
*)_expr
;
1315 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1319 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, ei
, &b
);
1320 exprval_release(&exprval
);
1324 return expr_eval(ctx
, b
? expr
->true_expression
: expr
->false_expression
, flags
, ei
, ret
);
1327 /* ECMA-262 3rd Edition 11.2.1 */
1328 HRESULT
array_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1330 array_expression_t
*expr
= (array_expression_t
*)_expr
;
1332 VARIANT member
, val
;
1335 IDispatch
*obj
= NULL
;
1340 hres
= expr_eval(ctx
, expr
->member_expr
, EXPR_NEWREF
, ei
, &exprval
);
1344 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &member
);
1345 exprval_release(&exprval
);
1349 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
1350 if(SUCCEEDED(hres
)) {
1351 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1352 exprval_release(&exprval
);
1356 hres
= to_object(ctx
, &member
, &obj
);
1357 VariantClear(&member
);
1358 if(SUCCEEDED(hres
)) {
1359 hres
= to_string(ctx
->parser
->script
, &val
, ei
, &str
);
1360 if(SUCCEEDED(hres
)) {
1361 if(flags
& EXPR_STRREF
) {
1362 ret
->type
= EXPRVAL_NAMEREF
;
1363 ret
->u
.nameref
.disp
= obj
;
1364 ret
->u
.nameref
.name
= str
;
1368 hres
= disp_get_id(obj
, str
, flags
& EXPR_NEWREF
? fdexNameEnsure
: 0, &id
);
1371 if(SUCCEEDED(hres
)) {
1372 exprval_set_idref(ret
, obj
, id
);
1373 }else if(!(flags
& EXPR_NEWREF
) && hres
== DISP_E_UNKNOWNNAME
) {
1378 IDispatch_Release(obj
);
1384 /* ECMA-262 3rd Edition 11.2.1 */
1385 HRESULT
member_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1387 member_expression_t
*expr
= (member_expression_t
*)_expr
;
1388 IDispatch
*obj
= NULL
;
1397 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1401 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &member
);
1402 exprval_release(&exprval
);
1406 hres
= to_object(ctx
, &member
, &obj
);
1407 VariantClear(&member
);
1411 str
= SysAllocString(expr
->identifier
);
1412 if(flags
& EXPR_STRREF
) {
1413 ret
->type
= EXPRVAL_NAMEREF
;
1414 ret
->u
.nameref
.disp
= obj
;
1415 ret
->u
.nameref
.name
= str
;
1419 hres
= disp_get_id(obj
, str
, flags
& EXPR_NEWREF
? fdexNameEnsure
: 0, &id
);
1421 if(SUCCEEDED(hres
)) {
1422 exprval_set_idref(ret
, obj
, id
);
1423 }else if(!(flags
& EXPR_NEWREF
) && hres
== DISP_E_UNKNOWNNAME
) {
1428 IDispatch_Release(obj
);
1432 static void free_dp(DISPPARAMS
*dp
)
1436 for(i
=0; i
< dp
->cArgs
; i
++)
1437 VariantClear(dp
->rgvarg
+i
);
1438 heap_free(dp
->rgvarg
);
1441 static HRESULT
args_to_param(exec_ctx_t
*ctx
, argument_t
*args
, jsexcept_t
*ei
, DISPPARAMS
*dp
)
1447 HRESULT hres
= S_OK
;
1449 memset(dp
, 0, sizeof(*dp
));
1453 for(iter
= args
; iter
; iter
= iter
->next
)
1456 vargs
= heap_alloc_zero(cnt
* sizeof(*vargs
));
1458 return E_OUTOFMEMORY
;
1460 for(i
= cnt
, iter
= args
; iter
; iter
= iter
->next
) {
1461 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
1465 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, vargs
+ (--i
));
1466 exprval_release(&exprval
);
1481 /* ECMA-262 3rd Edition 11.2.2 */
1482 HRESULT
new_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1484 call_expression_t
*expr
= (call_expression_t
*)_expr
;
1486 VARIANT constr
, var
;
1492 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1496 hres
= args_to_param(ctx
, expr
->argument_list
, ei
, &dp
);
1498 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &constr
);
1499 exprval_release(&exprval
);
1503 if(V_VT(&constr
) != VT_DISPATCH
) {
1504 FIXME("throw TypeError\n");
1505 VariantClear(&constr
);
1509 hres
= disp_call(V_DISPATCH(&constr
), DISPID_VALUE
, ctx
->parser
->script
->lcid
,
1510 DISPATCH_CONSTRUCT
, &dp
, &var
, ei
, NULL
/*FIXME*/);
1511 IDispatch_Release(V_DISPATCH(&constr
));
1515 ret
->type
= EXPRVAL_VARIANT
;
1520 /* ECMA-262 3rd Edition 11.2.3 */
1521 HRESULT
call_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1523 call_expression_t
*expr
= (call_expression_t
*)_expr
;
1531 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1535 hres
= args_to_param(ctx
, expr
->argument_list
, ei
, &dp
);
1536 if(SUCCEEDED(hres
)) {
1537 switch(exprval
.type
) {
1538 case EXPRVAL_VARIANT
:
1539 if(V_VT(&exprval
.u
.var
) != VT_DISPATCH
)
1540 return throw_type_error(ctx
->var_disp
->ctx
, ei
, IDS_NO_PROPERTY
, NULL
);
1542 hres
= disp_call(V_DISPATCH(&exprval
.u
.var
), DISPID_VALUE
, ctx
->parser
->script
->lcid
,
1543 DISPATCH_METHOD
, &dp
, flags
& EXPR_NOVAL
? NULL
: &var
, ei
, NULL
/*FIXME*/);
1546 hres
= disp_call(exprval
.u
.idref
.disp
, exprval
.u
.idref
.id
, ctx
->parser
->script
->lcid
,
1547 DISPATCH_METHOD
, &dp
, flags
& EXPR_NOVAL
? NULL
: &var
, ei
, NULL
/*FIXME*/);
1550 FIXME("unimplemented type %d\n", exprval
.type
);
1557 exprval_release(&exprval
);
1561 ret
->type
= EXPRVAL_VARIANT
;
1562 if(flags
& EXPR_NOVAL
) {
1563 V_VT(&ret
->u
.var
) = VT_EMPTY
;
1565 TRACE("= %s\n", debugstr_variant(&var
));
1571 /* ECMA-262 3rd Edition 11.1.1 */
1572 HRESULT
this_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1576 ret
->type
= EXPRVAL_VARIANT
;
1577 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1578 V_DISPATCH(&ret
->u
.var
) = ctx
->this_obj
;
1579 IDispatch_AddRef(ctx
->this_obj
);
1583 /* ECMA-262 3rd Edition 10.1.4 */
1584 HRESULT
identifier_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1586 identifier_expression_t
*expr
= (identifier_expression_t
*)_expr
;
1592 identifier
= SysAllocString(expr
->identifier
);
1594 return E_OUTOFMEMORY
;
1596 hres
= identifier_eval(ctx
, identifier
, flags
, ei
, ret
);
1598 SysFreeString(identifier
);
1602 /* ECMA-262 3rd Edition 7.8 */
1603 HRESULT
literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1605 literal_expression_t
*expr
= (literal_expression_t
*)_expr
;
1611 hres
= literal_to_var(expr
->literal
, &var
);
1615 ret
->type
= EXPRVAL_VARIANT
;
1620 /* ECMA-262 3rd Edition 11.1.4 */
1621 HRESULT
array_literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1623 array_literal_expression_t
*expr
= (array_literal_expression_t
*)_expr
;
1624 DWORD length
= 0, i
= 0;
1625 array_element_t
*elem
;
1633 for(elem
= expr
->element_list
; elem
; elem
= elem
->next
)
1634 length
+= elem
->elision
+1;
1635 length
+= expr
->length
;
1637 hres
= create_array(ctx
->parser
->script
, length
, &array
);
1641 for(elem
= expr
->element_list
; elem
; elem
= elem
->next
) {
1644 hres
= expr_eval(ctx
, elem
->expr
, 0, ei
, &exprval
);
1648 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1649 exprval_release(&exprval
);
1653 hres
= jsdisp_propput_idx(array
, i
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
1662 jsdisp_release(array
);
1666 ret
->type
= EXPRVAL_VARIANT
;
1667 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1668 V_DISPATCH(&ret
->u
.var
) = (IDispatch
*)_IDispatchEx_(array
);
1672 /* ECMA-262 3rd Edition 11.1.5 */
1673 HRESULT
property_value_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1675 property_value_expression_t
*expr
= (property_value_expression_t
*)_expr
;
1685 hres
= create_object(ctx
->parser
->script
, NULL
, &obj
);
1689 for(iter
= expr
->property_list
; iter
; iter
= iter
->next
) {
1690 hres
= literal_to_var(iter
->name
, &tmp
);
1694 hres
= to_string(ctx
->parser
->script
, &tmp
, ei
, &name
);
1699 hres
= expr_eval(ctx
, iter
->value
, 0, ei
, &exprval
);
1700 if(SUCCEEDED(hres
)) {
1701 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1702 exprval_release(&exprval
);
1703 if(SUCCEEDED(hres
)) {
1704 hres
= jsdisp_propput_name(obj
, name
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
1709 SysFreeString(name
);
1715 jsdisp_release(obj
);
1719 ret
->type
= EXPRVAL_VARIANT
;
1720 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1721 V_DISPATCH(&ret
->u
.var
) = (IDispatch
*)_IDispatchEx_(obj
);
1725 /* ECMA-262 3rd Edition 11.14 */
1726 HRESULT
comma_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1728 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1734 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1738 VariantClear(&lval
);
1740 ret
->type
= EXPRVAL_VARIANT
;
1745 /* ECMA-262 3rd Edition 11.11 */
1746 HRESULT
logical_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1748 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1756 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1760 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1761 exprval_release(&exprval
);
1765 hres
= to_boolean(&val
, &b
);
1766 if(SUCCEEDED(hres
) && b
) {
1767 ret
->type
= EXPRVAL_VARIANT
;
1776 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1780 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1781 exprval_release(&exprval
);
1785 ret
->type
= EXPRVAL_VARIANT
;
1790 /* ECMA-262 3rd Edition 11.11 */
1791 HRESULT
logical_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1793 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1801 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1805 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1806 exprval_release(&exprval
);
1810 hres
= to_boolean(&val
, &b
);
1811 if(SUCCEEDED(hres
) && !b
) {
1812 ret
->type
= EXPRVAL_VARIANT
;
1821 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1825 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1826 exprval_release(&exprval
);
1830 ret
->type
= EXPRVAL_VARIANT
;
1835 /* ECMA-262 3rd Edition 11.10 */
1836 static HRESULT
bitor_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1841 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
1845 hres
= to_int32(ctx
->parser
->script
, rval
, ei
, &ri
);
1854 /* ECMA-262 3rd Edition 11.10 */
1855 HRESULT
binary_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1857 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1861 return binary_expr_eval(ctx
, expr
, bitor_eval
, ei
, ret
);
1864 /* ECMA-262 3rd Edition 11.10 */
1865 static HRESULT
xor_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1870 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
1874 hres
= to_int32(ctx
->parser
->script
, rval
, ei
, &ri
);
1883 /* ECMA-262 3rd Edition 11.10 */
1884 HRESULT
binary_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1886 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1890 return binary_expr_eval(ctx
, expr
, xor_eval
, ei
, ret
);
1893 /* ECMA-262 3rd Edition 11.10 */
1894 static HRESULT
bitand_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1899 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
1903 hres
= to_int32(ctx
->parser
->script
, rval
, ei
, &ri
);
1912 /* ECMA-262 3rd Edition 11.10 */
1913 HRESULT
binary_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1915 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1919 return binary_expr_eval(ctx
, expr
, bitand_eval
, ei
, ret
);
1922 /* ECMA-262 3rd Edition 11.8.6 */
1923 HRESULT
instanceof_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1929 /* ECMA-262 3rd Edition 11.8.7 */
1930 HRESULT
in_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1936 /* ECMA-262 3rd Edition 11.6.1 */
1937 static HRESULT
add_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1942 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &l
, NO_HINT
);
1946 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &r
, NO_HINT
);
1952 if(V_VT(&l
) == VT_BSTR
|| V_VT(&r
) == VT_BSTR
) {
1953 BSTR lstr
= NULL
, rstr
= NULL
;
1955 if(V_VT(&l
) == VT_BSTR
)
1958 hres
= to_string(ctx
->parser
->script
, &l
, ei
, &lstr
);
1960 if(SUCCEEDED(hres
)) {
1961 if(V_VT(&r
) == VT_BSTR
)
1964 hres
= to_string(ctx
->parser
->script
, &r
, ei
, &rstr
);
1967 if(SUCCEEDED(hres
)) {
1970 len1
= SysStringLen(lstr
);
1971 len2
= SysStringLen(rstr
);
1973 V_VT(retv
) = VT_BSTR
;
1974 V_BSTR(retv
) = SysAllocStringLen(NULL
, len1
+len2
);
1975 memcpy(V_BSTR(retv
), lstr
, len1
*sizeof(WCHAR
));
1976 memcpy(V_BSTR(retv
)+len1
, rstr
, (len2
+1)*sizeof(WCHAR
));
1979 if(V_VT(&l
) != VT_BSTR
)
1980 SysFreeString(lstr
);
1981 if(V_VT(&r
) != VT_BSTR
)
1982 SysFreeString(rstr
);
1986 hres
= to_number(ctx
->parser
->script
, &l
, ei
, &nl
);
1987 if(SUCCEEDED(hres
)) {
1988 hres
= to_number(ctx
->parser
->script
, &r
, ei
, &nr
);
1990 num_set_val(retv
, num_val(&nl
) + num_val(&nr
));
1999 /* ECMA-262 3rd Edition 11.6.1 */
2000 HRESULT
add_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2002 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2006 return binary_expr_eval(ctx
, expr
, add_eval
, ei
, ret
);
2009 /* ECMA-262 3rd Edition 11.6.2 */
2010 static HRESULT
sub_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2015 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2019 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2023 num_set_val(retv
, num_val(&lnum
) - num_val(&rnum
));
2027 /* ECMA-262 3rd Edition 11.6.2 */
2028 HRESULT
sub_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2030 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2034 return binary_expr_eval(ctx
, expr
, sub_eval
, ei
, ret
);
2037 /* ECMA-262 3rd Edition 11.5.1 */
2038 static HRESULT
mul_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2043 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2047 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2051 num_set_val(retv
, num_val(&lnum
) * num_val(&rnum
));
2055 /* ECMA-262 3rd Edition 11.5.1 */
2056 HRESULT
mul_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2058 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2062 return binary_expr_eval(ctx
, expr
, mul_eval
, ei
, ret
);
2065 /* ECMA-262 3rd Edition 11.5.2 */
2066 static HRESULT
div_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2071 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2075 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2079 num_set_val(retv
, num_val(&lnum
) / num_val(&rnum
));
2083 /* ECMA-262 3rd Edition 11.5.2 */
2084 HRESULT
div_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2086 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2090 return binary_expr_eval(ctx
, expr
, div_eval
, ei
, ret
);
2093 /* ECMA-262 3rd Edition 11.5.3 */
2094 static HRESULT
mod_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2099 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &lnum
);
2103 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &rnum
);
2107 num_set_val(retv
, fmod(num_val(&lnum
), num_val(&rnum
)));
2111 /* ECMA-262 3rd Edition 11.5.3 */
2112 HRESULT
mod_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2114 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2118 return binary_expr_eval(ctx
, expr
, mod_eval
, ei
, ret
);
2121 /* ECMA-262 3rd Edition 11.4.2 */
2122 HRESULT
delete_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2124 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2125 VARIANT_BOOL b
= VARIANT_FALSE
;
2131 hres
= expr_eval(ctx
, expr
->expression
, EXPR_STRREF
, ei
, &exprval
);
2135 switch(exprval
.type
) {
2136 case EXPRVAL_IDREF
: {
2137 IDispatchEx
*dispex
;
2139 hres
= IDispatch_QueryInterface(exprval
.u
.nameref
.disp
, &IID_IDispatchEx
, (void**)&dispex
);
2140 if(SUCCEEDED(hres
)) {
2141 hres
= IDispatchEx_DeleteMemberByDispID(dispex
, exprval
.u
.idref
.id
);
2143 IDispatchEx_Release(dispex
);
2147 case EXPRVAL_NAMEREF
: {
2148 IDispatchEx
*dispex
;
2150 hres
= IDispatch_QueryInterface(exprval
.u
.nameref
.disp
, &IID_IDispatchEx
, (void**)&dispex
);
2151 if(SUCCEEDED(hres
)) {
2152 hres
= IDispatchEx_DeleteMemberByName(dispex
, exprval
.u
.nameref
.name
, fdexNameCaseSensitive
);
2154 IDispatchEx_Release(dispex
);
2159 FIXME("unsupported type %d\n", exprval
.type
);
2163 exprval_release(&exprval
);
2167 return return_bool(ret
, b
);
2170 /* ECMA-262 3rd Edition 11.4.2 */
2171 HRESULT
void_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2173 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2180 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
2184 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &tmp
);
2185 exprval_release(&exprval
);
2191 ret
->type
= EXPRVAL_VARIANT
;
2192 V_VT(&ret
->u
.var
) = VT_EMPTY
;
2196 /* ECMA-262 3rd Edition 11.4.3 */
2197 HRESULT
typeof_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2199 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2205 static const WCHAR booleanW
[] = {'b','o','o','l','e','a','n',0};
2206 static const WCHAR functionW
[] = {'f','u','n','c','t','i','o','n',0};
2207 static const WCHAR numberW
[] = {'n','u','m','b','e','r',0};
2208 static const WCHAR objectW
[] = {'o','b','j','e','c','t',0};
2209 static const WCHAR stringW
[] = {'s','t','r','i','n','g',0};
2210 static const WCHAR undefinedW
[] = {'u','n','d','e','f','i','n','e','d',0};
2214 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
2218 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2219 exprval_release(&exprval
);
2223 switch(V_VT(&val
)) {
2243 dispex
= iface_to_jsdisp((IUnknown
*)V_DISPATCH(&val
));
2245 str
= dispex
->builtin_info
->class == JSCLASS_FUNCTION
? functionW
: objectW
;
2246 IDispatchEx_Release(_IDispatchEx_(dispex
));
2253 FIXME("unhandled vt %d\n", V_VT(&val
));
2260 ret
->type
= EXPRVAL_VARIANT
;
2261 V_VT(&ret
->u
.var
) = VT_BSTR
;
2262 V_BSTR(&ret
->u
.var
) = SysAllocString(str
);
2266 /* ECMA-262 3rd Edition 11.4.7 */
2267 HRESULT
minus_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2269 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2276 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
2280 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2281 exprval_release(&exprval
);
2285 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2290 ret
->type
= EXPRVAL_VARIANT
;
2291 num_set_val(&ret
->u
.var
, -num_val(&num
));
2295 /* ECMA-262 3rd Edition 11.4.6 */
2296 HRESULT
plus_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2298 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2305 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2309 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2310 exprval_release(&exprval
);
2314 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2318 ret
->type
= EXPRVAL_VARIANT
;
2323 /* ECMA-262 3rd Edition 11.3.1 */
2324 HRESULT
post_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2326 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2333 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2337 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2338 if(SUCCEEDED(hres
)) {
2339 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2343 if(SUCCEEDED(hres
)) {
2345 num_set_val(&inc
, num_val(&num
)+1.0);
2346 hres
= put_value(ctx
->parser
->script
, &exprval
, &inc
, ei
);
2349 exprval_release(&exprval
);
2353 ret
->type
= EXPRVAL_VARIANT
;
2358 /* ECMA-262 3rd Edition 11.3.2 */
2359 HRESULT
post_decrement_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2361 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2368 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2372 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2373 if(SUCCEEDED(hres
)) {
2374 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2378 if(SUCCEEDED(hres
)) {
2380 num_set_val(&dec
, num_val(&num
)-1.0);
2381 hres
= put_value(ctx
->parser
->script
, &exprval
, &dec
, ei
);
2384 exprval_release(&exprval
);
2388 ret
->type
= EXPRVAL_VARIANT
;
2393 /* ECMA-262 3rd Edition 11.4.4 */
2394 HRESULT
pre_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2396 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2403 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2407 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2408 if(SUCCEEDED(hres
)) {
2409 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2413 if(SUCCEEDED(hres
)) {
2414 num_set_val(&val
, num_val(&num
)+1.0);
2415 hres
= put_value(ctx
->parser
->script
, &exprval
, &val
, ei
);
2418 exprval_release(&exprval
);
2422 ret
->type
= EXPRVAL_VARIANT
;
2427 /* ECMA-262 3rd Edition 11.4.5 */
2428 HRESULT
pre_decrement_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2430 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2437 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2441 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2442 if(SUCCEEDED(hres
)) {
2443 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
2447 if(SUCCEEDED(hres
)) {
2448 num_set_val(&val
, num_val(&num
)-1.0);
2449 hres
= put_value(ctx
->parser
->script
, &exprval
, &val
, ei
);
2452 exprval_release(&exprval
);
2456 ret
->type
= EXPRVAL_VARIANT
;
2461 /* ECMA-262 3rd Edition 11.9.3 */
2462 static HRESULT
equal_values(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, BOOL
*ret
)
2464 if(V_VT(lval
) == V_VT(rval
) || (is_num_vt(V_VT(lval
)) && is_num_vt(V_VT(rval
))))
2465 return equal2_values(lval
, rval
, ret
);
2467 /* FIXME: NULL disps should be handled in more general way */
2468 if(V_VT(lval
) == VT_DISPATCH
&& !V_DISPATCH(lval
)) {
2471 return equal_values(ctx
, &v
, rval
, ei
, ret
);
2474 if(V_VT(rval
) == VT_DISPATCH
&& !V_DISPATCH(rval
)) {
2477 return equal_values(ctx
, lval
, &v
, ei
, ret
);
2480 if((V_VT(lval
) == VT_NULL
&& V_VT(rval
) == VT_EMPTY
) ||
2481 (V_VT(lval
) == VT_EMPTY
&& V_VT(rval
) == VT_NULL
)) {
2486 if(V_VT(lval
) == VT_BSTR
&& is_num_vt(V_VT(rval
))) {
2490 hres
= to_number(ctx
->parser
->script
, lval
, ei
, &v
);
2494 return equal_values(ctx
, &v
, rval
, ei
, ret
);
2497 if(V_VT(rval
) == VT_BSTR
&& is_num_vt(V_VT(lval
))) {
2501 hres
= to_number(ctx
->parser
->script
, rval
, ei
, &v
);
2505 return equal_values(ctx
, lval
, &v
, ei
, ret
);
2508 if(V_VT(rval
) == VT_BOOL
) {
2512 V_I4(&v
) = V_BOOL(rval
) ? 1 : 0;
2513 return equal_values(ctx
, lval
, &v
, ei
, ret
);
2516 if(V_VT(lval
) == VT_BOOL
) {
2520 V_I4(&v
) = V_BOOL(lval
) ? 1 : 0;
2521 return equal_values(ctx
, &v
, rval
, ei
, ret
);
2525 if(V_VT(rval
) == VT_DISPATCH
&& (V_VT(lval
) == VT_BSTR
|| is_num_vt(V_VT(lval
)))) {
2529 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &v
, NO_HINT
);
2533 hres
= equal_values(ctx
, lval
, &v
, ei
, ret
);
2540 if(V_VT(lval
) == VT_DISPATCH
&& (V_VT(rval
) == VT_BSTR
|| is_num_vt(V_VT(rval
)))) {
2544 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &v
, NO_HINT
);
2548 hres
= equal_values(ctx
, &v
, rval
, ei
, ret
);
2559 /* ECMA-262 3rd Edition 11.9.1 */
2560 HRESULT
equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2562 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2569 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
2573 hres
= equal_values(ctx
, &rval
, &lval
, ei
, &b
);
2577 return return_bool(ret
, b
);
2580 /* ECMA-262 3rd Edition 11.9.4 */
2581 HRESULT
equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2583 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2590 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
2594 hres
= equal2_values(&rval
, &lval
, &b
);
2598 return return_bool(ret
, b
);
2601 /* ECMA-262 3rd Edition 11.9.2 */
2602 HRESULT
not_equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2604 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2611 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2615 hres
= equal_values(ctx
, &lval
, &rval
, ei
, &b
);
2619 return return_bool(ret
, !b
);
2622 /* ECMA-262 3rd Edition 11.9.5 */
2623 HRESULT
not_equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2625 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2632 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2636 hres
= equal2_values(&lval
, &rval
, &b
);
2640 return return_bool(ret
, !b
);
2643 /* ECMA-262 3rd Edition 11.8.5 */
2644 static HRESULT
less_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, BOOL greater
, jsexcept_t
*ei
, BOOL
*ret
)
2646 VARIANT l
, r
, ln
, rn
;
2649 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &l
, NO_HINT
);
2653 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &r
, NO_HINT
);
2659 if(V_VT(&l
) == VT_BSTR
&& V_VT(&r
) == VT_BSTR
) {
2660 *ret
= (strcmpW(V_BSTR(&l
), V_BSTR(&r
)) < 0) ^ greater
;
2661 SysFreeString(V_BSTR(&l
));
2662 SysFreeString(V_BSTR(&r
));
2666 hres
= to_number(ctx
->parser
->script
, &l
, ei
, &ln
);
2669 hres
= to_number(ctx
->parser
->script
, &r
, ei
, &rn
);
2674 if(V_VT(&ln
) == VT_I4
&& V_VT(&rn
) == VT_I4
) {
2675 *ret
= (V_I4(&ln
) < V_I4(&rn
)) ^ greater
;
2677 DOUBLE ld
= num_val(&ln
);
2678 DOUBLE rd
= num_val(&rn
);
2680 *ret
= !isnan(ld
) && !isnan(rd
) && ((ld
< rd
) ^ greater
);
2686 /* ECMA-262 3rd Edition 11.8.1 */
2687 HRESULT
less_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2689 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2696 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2700 hres
= less_eval(ctx
, &lval
, &rval
, FALSE
, ei
, &b
);
2701 VariantClear(&lval
);
2702 VariantClear(&rval
);
2706 return return_bool(ret
, b
);
2709 /* ECMA-262 3rd Edition 11.8.3 */
2710 HRESULT
lesseq_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2712 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2719 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2723 hres
= less_eval(ctx
, &rval
, &lval
, TRUE
, ei
, &b
);
2724 VariantClear(&lval
);
2725 VariantClear(&rval
);
2729 return return_bool(ret
, b
);
2732 /* ECMA-262 3rd Edition 11.8.2 */
2733 HRESULT
greater_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2735 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2742 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2746 hres
= less_eval(ctx
, &rval
, &lval
, FALSE
, ei
, &b
);
2747 VariantClear(&lval
);
2748 VariantClear(&rval
);
2752 return return_bool(ret
, b
);
2755 /* ECMA-262 3rd Edition 11.8.4 */
2756 HRESULT
greatereq_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2758 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2765 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
2769 hres
= less_eval(ctx
, &lval
, &rval
, TRUE
, ei
, &b
);
2770 VariantClear(&lval
);
2771 VariantClear(&rval
);
2775 return return_bool(ret
, b
);
2778 /* ECMA-262 3rd Edition 11.4.8 */
2779 HRESULT
binary_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2781 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2789 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2793 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
2794 exprval_release(&exprval
);
2798 hres
= to_int32(ctx
->parser
->script
, &val
, ei
, &i
);
2802 ret
->type
= EXPRVAL_VARIANT
;
2803 V_VT(&ret
->u
.var
) = VT_I4
;
2804 V_I4(&ret
->u
.var
) = ~i
;
2808 /* ECMA-262 3rd Edition 11.4.9 */
2809 HRESULT
logical_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2811 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
2818 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
2822 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, ei
, &b
);
2823 exprval_release(&exprval
);
2827 return return_bool(ret
, !b
);
2830 /* ECMA-262 3rd Edition 11.7.1 */
2831 static HRESULT
lshift_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2837 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
2841 hres
= to_uint32(ctx
->parser
->script
, rval
, ei
, &ri
);
2846 V_I4(retv
) = li
<< (ri
&0x1f);
2850 /* ECMA-262 3rd Edition 11.7.1 */
2851 HRESULT
left_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2853 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2857 return binary_expr_eval(ctx
, expr
, lshift_eval
, ei
, ret
);
2860 /* ECMA-262 3rd Edition 11.7.2 */
2861 static HRESULT
rshift_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2867 hres
= to_int32(ctx
->parser
->script
, lval
, ei
, &li
);
2871 hres
= to_uint32(ctx
->parser
->script
, rval
, ei
, &ri
);
2876 V_I4(retv
) = li
>> (ri
&0x1f);
2880 /* ECMA-262 3rd Edition 11.7.2 */
2881 HRESULT
right_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2883 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2887 return binary_expr_eval(ctx
, expr
, rshift_eval
, ei
, ret
);
2890 /* ECMA-262 3rd Edition 11.7.3 */
2891 static HRESULT
rshift2_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
2896 hres
= to_uint32(ctx
->parser
->script
, lval
, ei
, &li
);
2900 hres
= to_uint32(ctx
->parser
->script
, rval
, ei
, &ri
);
2905 V_I4(retv
) = li
>> (ri
&0x1f);
2909 /* ECMA-262 3rd Edition 11.7.3 */
2910 HRESULT
right2_shift_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
;
2916 return binary_expr_eval(ctx
, expr
, rshift2_eval
, ei
, ret
);
2919 /* ECMA-262 3rd Edition 11.13.1 */
2920 HRESULT
assign_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2922 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2923 exprval_t exprval
, exprvalr
;
2929 hres
= expr_eval(ctx
, expr
->expression1
, EXPR_NEWREF
, ei
, &exprval
);
2933 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprvalr
);
2934 if(SUCCEEDED(hres
)) {
2935 hres
= exprval_to_value(ctx
->parser
->script
, &exprvalr
, ei
, &rval
);
2936 exprval_release(&exprvalr
);
2940 hres
= put_value(ctx
->parser
->script
, &exprval
, &rval
, ei
);
2942 exprval_release(&exprval
);
2946 ret
->type
= EXPRVAL_VARIANT
;
2951 /* ECMA-262 3rd Edition 11.13.2 */
2952 HRESULT
assign_lshift_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
, lshift_eval
, ei
, ret
);
2961 /* ECMA-262 3rd Edition 11.13.2 */
2962 HRESULT
assign_rshift_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
, rshift_eval
, ei
, ret
);
2971 /* ECMA-262 3rd Edition 11.13.2 */
2972 HRESULT
assign_rrshift_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
, rshift2_eval
, ei
, ret
);
2981 /* ECMA-262 3rd Edition 11.13.2 */
2982 HRESULT
assign_add_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
, add_eval
, ei
, ret
);
2991 /* ECMA-262 3rd Edition 11.13.2 */
2992 HRESULT
assign_sub_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
, sub_eval
, ei
, ret
);
3001 /* ECMA-262 3rd Edition 11.13.2 */
3002 HRESULT
assign_mul_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
, mul_eval
, ei
, ret
);
3011 /* ECMA-262 3rd Edition 11.13.2 */
3012 HRESULT
assign_div_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
, div_eval
, ei
, ret
);
3021 /* ECMA-262 3rd Edition 11.13.2 */
3022 HRESULT
assign_mod_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
, mod_eval
, ei
, ret
);
3031 /* ECMA-262 3rd Edition 11.13.2 */
3032 HRESULT
assign_and_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
, bitand_eval
, ei
, ret
);
3041 /* ECMA-262 3rd Edition 11.13.2 */
3042 HRESULT
assign_or_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
, bitor_eval
, ei
, ret
);
3051 /* ECMA-262 3rd Edition 11.13.2 */
3052 HRESULT
assign_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
3054 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
3058 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, xor_eval
, ei
, ret
);