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 VariantClear(&val
->u
.var
);
48 IDispatch_Release(val
->u
.idref
.disp
);
51 if(val
->u
.nameref
.disp
)
52 IDispatch_Release(val
->u
.nameref
.disp
);
53 SysFreeString(val
->u
.nameref
.name
);
57 /* ECMA-262 3rd Edition 8.7.1 */
58 static HRESULT
exprval_value(script_ctx_t
*ctx
, exprval_t
*val
, jsexcept_t
*ei
, VARIANT
*ret
)
64 return VariantCopy(ret
, &val
->u
.var
);
66 if(!val
->u
.idref
.disp
) {
67 FIXME("throw ReferenceError\n");
71 return disp_propget(val
->u
.idref
.disp
, val
->u
.idref
.id
, ctx
->lcid
, ret
, ei
, NULL
/*FIXME*/);
73 ERR("type %d\n", val
->type
);
78 static HRESULT
exprval_to_value(script_ctx_t
*ctx
, exprval_t
*val
, jsexcept_t
*ei
, VARIANT
*ret
)
80 if(val
->type
== EXPRVAL_VARIANT
) {
82 V_VT(&val
->u
.var
) = VT_EMPTY
;
86 return exprval_value(ctx
, val
, ei
, ret
);
89 static HRESULT
exprval_to_boolean(script_ctx_t
*ctx
, exprval_t
*exprval
, jsexcept_t
*ei
, VARIANT_BOOL
*b
)
91 if(exprval
->type
!= EXPRVAL_VARIANT
) {
95 hres
= exprval_to_value(ctx
, exprval
, ei
, &val
);
99 hres
= to_boolean(&val
, b
);
104 return to_boolean(&exprval
->u
.var
, b
);
107 static void exprval_init(exprval_t
*val
)
109 val
->type
= EXPRVAL_VARIANT
;
110 V_VT(&val
->u
.var
) = VT_EMPTY
;
113 static void exprval_set_idref(exprval_t
*val
, IDispatch
*disp
, DISPID id
)
115 val
->type
= EXPRVAL_IDREF
;
116 val
->u
.idref
.disp
= disp
;
117 val
->u
.idref
.id
= id
;
120 IDispatch_AddRef(disp
);
123 HRESULT
scope_push(scope_chain_t
*scope
, DispatchEx
*obj
, scope_chain_t
**ret
)
125 scope_chain_t
*new_scope
;
127 new_scope
= heap_alloc(sizeof(scope_chain_t
));
129 return E_OUTOFMEMORY
;
133 IDispatchEx_AddRef(_IDispatchEx_(obj
));
134 new_scope
->obj
= obj
;
138 new_scope
->next
= scope
;
140 new_scope
->next
= NULL
;
147 static void scope_pop(scope_chain_t
**scope
)
156 void scope_release(scope_chain_t
*scope
)
162 scope_release(scope
->next
);
164 IDispatchEx_Release(_IDispatchEx_(scope
->obj
));
168 HRESULT
create_exec_ctx(IDispatch
*this_obj
, DispatchEx
*var_disp
, scope_chain_t
*scope
, exec_ctx_t
**ret
)
172 ctx
= heap_alloc_zero(sizeof(exec_ctx_t
));
174 return E_OUTOFMEMORY
;
176 IDispatch_AddRef(this_obj
);
177 ctx
->this_obj
= this_obj
;
179 IDispatchEx_AddRef(_IDispatchEx_(var_disp
));
180 ctx
->var_disp
= var_disp
;
184 ctx
->scope_chain
= scope
;
191 void exec_release(exec_ctx_t
*ctx
)
197 scope_release(ctx
->scope_chain
);
199 IDispatchEx_Release(_IDispatchEx_(ctx
->var_disp
));
201 IDispatch_Release(ctx
->this_obj
);
205 static HRESULT
dispex_get_id(IDispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*id
)
209 return IDispatchEx_GetDispID(dispex
, name
, flags
|fdexNameCaseSensitive
, id
);
212 static HRESULT
disp_get_id(IDispatch
*disp
, BSTR name
, DWORD flags
, DISPID
*id
)
217 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
219 TRACE("unsing IDispatch\n");
222 return IDispatch_GetIDsOfNames(disp
, &IID_NULL
, &name
, 1, 0, id
);
225 hres
= dispex_get_id(dispex
, name
, flags
, id
);
226 IDispatchEx_Release(dispex
);
230 /* ECMA-262 3rd Edition 8.7.2 */
231 static HRESULT
put_value(script_ctx_t
*ctx
, exprval_t
*ref
, VARIANT
*v
, jsexcept_t
*ei
)
233 if(ref
->type
!= EXPRVAL_IDREF
) {
234 FIXME("throw ReferemceError\n");
238 return disp_propput(ref
->u
.idref
.disp
, ref
->u
.idref
.id
, ctx
->lcid
, v
, ei
, NULL
/*FIXME*/);
241 static HRESULT
disp_cmp(IDispatch
*disp1
, IDispatch
*disp2
, BOOL
*ret
)
243 IObjectIdentity
*identity
;
244 IUnknown
*unk1
, *unk2
;
252 hres
= IDispatch_QueryInterface(disp1
, &IID_IUnknown
, (void**)&unk1
);
256 hres
= IDispatch_QueryInterface(disp2
, &IID_IUnknown
, (void**)&unk2
);
258 IUnknown_Release(unk1
);
265 hres
= IUnknown_QueryInterface(unk1
, &IID_IObjectIdentity
, (void**)&identity
);
266 if(SUCCEEDED(hres
)) {
267 hres
= IObjectIdentity_IsEqualObject(identity
, unk2
);
268 IObjectIdentity_Release(identity
);
275 IUnknown_Release(unk1
);
276 IUnknown_Release(unk2
);
280 static inline BOOL
is_num_vt(enum VARENUM vt
)
282 return vt
== VT_I4
|| vt
== VT_R8
;
285 static inline DOUBLE
num_val(const VARIANT
*v
)
287 return V_VT(v
) == VT_I4
? V_I4(v
) : V_R8(v
);
290 static inline void num_set_val(VARIANT
*v
, DOUBLE d
)
292 if(d
== (DOUBLE
)(INT
)d
) {
301 /* ECMA-262 3rd Edition 11.9.6 */
302 HRESULT
equal2_values(VARIANT
*lval
, VARIANT
*rval
, BOOL
*ret
)
306 if(V_VT(lval
) != V_VT(rval
)) {
307 if(is_num_vt(V_VT(lval
)) && is_num_vt(V_VT(rval
))) {
308 *ret
= num_val(lval
) == num_val(rval
);
322 *ret
= V_I4(lval
) == V_I4(rval
);
325 *ret
= V_R8(lval
) == V_R8(rval
);
328 *ret
= !strcmpW(V_BSTR(lval
), V_BSTR(rval
));
331 return disp_cmp(V_DISPATCH(lval
), V_DISPATCH(rval
), ret
);
333 *ret
= !V_BOOL(lval
) == !V_BOOL(rval
);
336 FIXME("unimplemented vt %d\n", V_VT(lval
));
343 static HRESULT
literal_to_var(literal_t
*literal
, VARIANT
*v
)
345 V_VT(v
) = literal
->vt
;
352 V_I4(v
) = literal
->u
.lval
;
355 V_R8(v
) = literal
->u
.dval
;
358 V_BSTR(v
) = SysAllocString(literal
->u
.wstr
);
361 V_BOOL(v
) = literal
->u
.bval
;
364 IDispatch_AddRef(literal
->u
.disp
);
365 V_DISPATCH(v
) = literal
->u
.disp
;
368 ERR("wrong type %d\n", V_VT(v
));
375 HRESULT
exec_source(exec_ctx_t
*ctx
, parser_ctx_t
*parser
, source_elements_t
*source
, jsexcept_t
*ei
, VARIANT
*retv
)
377 script_ctx_t
*script
= parser
->script
;
378 function_declaration_t
*func
;
379 parser_ctx_t
*prev_parser
;
382 exec_ctx_t
*prev_ctx
;
386 for(func
= source
->functions
; func
; func
= func
->next
) {
387 DispatchEx
*func_obj
;
390 hres
= create_source_function(parser
, func
->parameter_list
, func
->source_elements
, ctx
->scope_chain
, &func_obj
);
394 V_VT(&var
) = VT_DISPATCH
;
395 V_DISPATCH(&var
) = (IDispatch
*)_IDispatchEx_(func_obj
);
396 hres
= jsdisp_propput_name(ctx
->var_disp
, func
->identifier
, script
->lcid
, &var
, ei
, NULL
);
397 IDispatchEx_Release(_IDispatchEx_(func_obj
));
402 prev_ctx
= script
->exec_ctx
;
403 script
->exec_ctx
= ctx
;
405 prev_parser
= ctx
->parser
;
406 ctx
->parser
= parser
;
408 V_VT(&val
) = VT_EMPTY
;
409 memset(&rt
, 0, sizeof(rt
));
412 for(stat
= source
->statement
; stat
; stat
= stat
->next
) {
413 hres
= stat_eval(ctx
, stat
, &rt
, &tmp
);
419 if(rt
.type
!= RT_NORMAL
)
423 script
->exec_ctx
= prev_ctx
;
424 ctx
->parser
= prev_parser
;
426 if(rt
.type
!= RT_NORMAL
&& rt
.type
!= RT_RETURN
) {
427 FIXME("wrong rt %d\n", rt
.type
);
444 /* ECMA-262 3rd Edition 10.1.4 */
445 static HRESULT
identifier_eval(exec_ctx_t
*ctx
, BSTR identifier
, DWORD flags
, exprval_t
*ret
)
447 scope_chain_t
*scope
;
452 TRACE("%s\n", debugstr_w(identifier
));
454 for(scope
= ctx
->scope_chain
; scope
; scope
= scope
->next
) {
455 hres
= dispex_get_id(_IDispatchEx_(scope
->obj
), identifier
, 0, &id
);
461 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(scope
->obj
), id
);
465 hres
= dispex_get_id(_IDispatchEx_(ctx
->parser
->script
->global
), identifier
, 0, &id
);
466 if(SUCCEEDED(hres
)) {
467 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->parser
->script
->global
), id
);
471 for(item
= ctx
->parser
->script
->named_items
; item
; item
= item
->next
) {
472 hres
= disp_get_id(item
->disp
, identifier
, 0, &id
);
478 exprval_set_idref(ret
, (IDispatch
*)item
->disp
, id
);
482 hres
= dispex_get_id(_IDispatchEx_(ctx
->parser
->script
->script_disp
), identifier
, 0, &id
);
483 if(SUCCEEDED(hres
)) {
484 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->parser
->script
->script_disp
), id
);
488 if(flags
& EXPR_NEWREF
) {
489 hres
= dispex_get_id(_IDispatchEx_(ctx
->var_disp
), identifier
, fdexNameEnsure
, &id
);
493 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->var_disp
), id
);
497 WARN("Could not find identifier %s\n", debugstr_w(identifier
));
501 /* ECMA-262 3rd Edition 12.1 */
502 HRESULT
block_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
504 block_statement_t
*stat
= (block_statement_t
*)_stat
;
511 V_VT(&val
) = VT_EMPTY
;
512 for(iter
= stat
->stat_list
; iter
; iter
= iter
->next
) {
513 hres
= stat_eval(ctx
, iter
, rt
, &tmp
);
519 if(rt
->type
!= RT_NORMAL
)
532 /* ECMA-262 3rd Edition 12.2 */
533 static HRESULT
variable_list_eval(exec_ctx_t
*ctx
, variable_declaration_t
*var_list
, jsexcept_t
*ei
)
535 variable_declaration_t
*iter
;
538 for(iter
= var_list
; iter
; iter
= iter
->next
) {
544 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
548 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
549 exprval_release(&exprval
);
553 V_VT(&val
) = VT_EMPTY
;
556 hres
= jsdisp_propput_name(ctx
->var_disp
, iter
->identifier
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
565 /* ECMA-262 3rd Edition 12.2 */
566 HRESULT
var_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
568 var_statement_t
*stat
= (var_statement_t
*)_stat
;
573 hres
= variable_list_eval(ctx
, stat
->variable_list
, &rt
->ei
);
577 V_VT(ret
) = VT_EMPTY
;
581 /* ECMA-262 3rd Edition 12.3 */
582 HRESULT
empty_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
586 V_VT(ret
) = VT_EMPTY
;
590 /* ECMA-262 3rd Edition 12.4 */
591 HRESULT
expression_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
593 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
600 hres
= expr_eval(ctx
, stat
->expr
, EXPR_NOVAL
, &rt
->ei
, &exprval
);
604 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
605 exprval_release(&exprval
);
610 TRACE("= %s\n", debugstr_variant(ret
));
614 /* ECMA-262 3rd Edition 12.5 */
615 HRESULT
if_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
617 if_statement_t
*stat
= (if_statement_t
*)_stat
;
624 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
628 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, &rt
->ei
, &b
);
629 exprval_release(&exprval
);
634 hres
= stat_eval(ctx
, stat
->if_stat
, rt
, ret
);
635 else if(stat
->else_stat
)
636 hres
= stat_eval(ctx
, stat
->else_stat
, rt
, ret
);
638 V_VT(ret
) = VT_EMPTY
;
643 HRESULT
dowhile_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
649 HRESULT
while_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
655 HRESULT
for_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
661 HRESULT
forin_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
667 HRESULT
continue_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
673 HRESULT
break_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
679 /* ECMA-262 3rd Edition 12.9 */
680 HRESULT
return_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
682 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
690 hres
= expr_eval(ctx
, stat
->expr
, 0, &rt
->ei
, &exprval
);
694 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, ret
);
695 exprval_release(&exprval
);
699 V_VT(ret
) = VT_EMPTY
;
702 TRACE("= %s\n", debugstr_variant(ret
));
703 rt
->type
= RT_RETURN
;
707 HRESULT
with_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
713 HRESULT
labelled_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
719 HRESULT
switch_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
725 HRESULT
throw_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
731 /* ECMA-262 3rd Edition 12.14 */
732 static HRESULT
catch_eval(exec_ctx_t
*ctx
, catch_block_t
*block
, return_type_t
*rt
, VARIANT
*ret
)
734 DispatchEx
*var_disp
;
739 memset(&rt
->ei
, 0, sizeof(jsexcept_t
));
741 hres
= create_dispex(ctx
->parser
->script
, NULL
, NULL
, &var_disp
);
742 if(SUCCEEDED(hres
)) {
743 hres
= jsdisp_propput_name(var_disp
, block
->identifier
, ctx
->parser
->script
->lcid
,
744 &ex
, &rt
->ei
, NULL
/*FIXME*/);
745 if(SUCCEEDED(hres
)) {
746 hres
= scope_push(ctx
->scope_chain
, var_disp
, &ctx
->scope_chain
);
747 if(SUCCEEDED(hres
)) {
748 hres
= stat_eval(ctx
, block
->statement
, rt
, &val
);
749 scope_pop(&ctx
->scope_chain
);
753 jsdisp_release(var_disp
);
764 /* ECMA-262 3rd Edition 12.14 */
765 HRESULT
try_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
767 try_statement_t
*stat
= (try_statement_t
*)_stat
;
773 hres
= stat_eval(ctx
, stat
->try_statement
, rt
, &val
);
775 TRACE("EXCEPTION\n");
776 if(!stat
->catch_block
)
779 hres
= catch_eval(ctx
, stat
->catch_block
, rt
, &val
);
784 if(stat
->finally_statement
) {
786 hres
= stat_eval(ctx
, stat
->finally_statement
, rt
, &val
);
795 static HRESULT
return_bool(exprval_t
*ret
, DWORD b
)
797 ret
->type
= EXPRVAL_VARIANT
;
798 V_VT(&ret
->u
.var
) = VT_BOOL
;
799 V_BOOL(&ret
->u
.var
) = b
? VARIANT_TRUE
: VARIANT_FALSE
;
804 static HRESULT
get_binary_expr_values(exec_ctx_t
*ctx
, binary_expression_t
*expr
, jsexcept_t
*ei
, VARIANT
*lval
, VARIANT
*rval
)
809 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
813 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, lval
);
814 exprval_release(&exprval
);
818 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
819 if(SUCCEEDED(hres
)) {
820 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, rval
);
821 exprval_release(&exprval
);
832 typedef HRESULT (*oper_t
)(exec_ctx_t
*,VARIANT
*,VARIANT
*,jsexcept_t
*,VARIANT
*);
834 static HRESULT
binary_expr_eval(exec_ctx_t
*ctx
, binary_expression_t
*expr
, oper_t oper
, jsexcept_t
*ei
,
837 VARIANT lval
, rval
, retv
;
840 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
844 hres
= oper(ctx
, &lval
, &rval
, ei
, &retv
);
850 ret
->type
= EXPRVAL_VARIANT
;
855 /* ECMA-262 3rd Edition 11.13.2 */
856 static HRESULT
assign_oper_eval(exec_ctx_t
*ctx
, expression_t
*lexpr
, expression_t
*rexpr
, oper_t oper
,
857 jsexcept_t
*ei
, exprval_t
*ret
)
859 VARIANT retv
, lval
, rval
;
860 exprval_t exprval
, exprvalr
;
863 hres
= expr_eval(ctx
, lexpr
, EXPR_NEWREF
, ei
, &exprval
);
867 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &lval
);
868 if(SUCCEEDED(hres
)) {
869 hres
= expr_eval(ctx
, rexpr
, 0, ei
, &exprvalr
);
870 if(SUCCEEDED(hres
)) {
871 hres
= exprval_value(ctx
->parser
->script
, &exprvalr
, ei
, &rval
);
872 exprval_release(&exprvalr
);
874 if(SUCCEEDED(hres
)) {
875 hres
= oper(ctx
, &lval
, &rval
, ei
, &retv
);
881 if(SUCCEEDED(hres
)) {
882 hres
= put_value(ctx
->parser
->script
, &exprval
, &retv
, ei
);
886 exprval_release(&exprval
);
891 ret
->type
= EXPRVAL_VARIANT
;
896 /* ECMA-262 3rd Edition 13 */
897 HRESULT
function_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
899 function_expression_t
*expr
= (function_expression_t
*)_expr
;
906 hres
= create_source_function(ctx
->parser
, expr
->parameter_list
, expr
->source_elements
, ctx
->scope_chain
, &dispex
);
910 V_VT(&var
) = VT_DISPATCH
;
911 V_DISPATCH(&var
) = (IDispatch
*)_IDispatchEx_(dispex
);
913 if(expr
->identifier
) {
914 hres
= jsdisp_propput_name(ctx
->var_disp
, expr
->identifier
, ctx
->parser
->script
->lcid
, &var
, ei
, NULL
/*FIXME*/);
916 jsdisp_release(dispex
);
921 ret
->type
= EXPRVAL_VARIANT
;
926 /* ECMA-262 3rd Edition 11.12 */
927 HRESULT
conditional_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
929 conditional_expression_t
*expr
= (conditional_expression_t
*)_expr
;
936 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
940 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, ei
, &b
);
941 exprval_release(&exprval
);
945 return expr_eval(ctx
, b
? expr
->true_expression
: expr
->false_expression
, flags
, ei
, ret
);
948 /* ECMA-262 3rd Edition 11.2.1 */
949 HRESULT
array_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
951 array_expression_t
*expr
= (array_expression_t
*)_expr
;
956 IDispatch
*obj
= NULL
;
961 hres
= expr_eval(ctx
, expr
->member_expr
, EXPR_NEWREF
, ei
, &exprval
);
965 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &member
);
966 exprval_release(&exprval
);
970 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
971 if(SUCCEEDED(hres
)) {
972 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
973 exprval_release(&exprval
);
977 hres
= to_object(ctx
, &member
, &obj
);
978 VariantClear(&member
);
979 if(SUCCEEDED(hres
)) {
980 hres
= to_string(ctx
->parser
->script
, &val
, ei
, &str
);
981 if(SUCCEEDED(hres
)) {
982 if(flags
& EXPR_STRREF
) {
983 ret
->type
= EXPRVAL_NAMEREF
;
984 ret
->u
.nameref
.disp
= obj
;
985 ret
->u
.nameref
.name
= str
;
989 hres
= disp_get_id(obj
, str
, flags
& EXPR_NEWREF
? fdexNameEnsure
: 0, &id
);
992 if(SUCCEEDED(hres
)) {
993 exprval_set_idref(ret
, obj
, id
);
994 }else if(!(flags
& EXPR_NEWREF
) && hres
== DISP_E_UNKNOWNNAME
) {
999 IDispatch_Release(obj
);
1005 /* ECMA-262 3rd Edition 11.2.1 */
1006 HRESULT
member_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1008 member_expression_t
*expr
= (member_expression_t
*)_expr
;
1009 IDispatch
*obj
= NULL
;
1018 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1022 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &member
);
1023 exprval_release(&exprval
);
1027 hres
= to_object(ctx
, &member
, &obj
);
1028 VariantClear(&member
);
1032 str
= SysAllocString(expr
->identifier
);
1033 if(flags
& EXPR_STRREF
) {
1034 ret
->type
= EXPRVAL_NAMEREF
;
1035 ret
->u
.nameref
.disp
= obj
;
1036 ret
->u
.nameref
.name
= str
;
1040 hres
= disp_get_id(obj
, str
, flags
& EXPR_NEW
? fdexNameEnsure
: 0, &id
);
1042 if(SUCCEEDED(hres
)) {
1043 exprval_set_idref(ret
, obj
, id
);
1044 }else if(!(flags
& EXPR_NEWREF
) && hres
== DISP_E_UNKNOWNNAME
) {
1049 IDispatch_Release(obj
);
1053 static void free_dp(DISPPARAMS
*dp
)
1057 for(i
=0; i
< dp
->cArgs
; i
++)
1058 VariantClear(dp
->rgvarg
+i
);
1059 heap_free(dp
->rgvarg
);
1062 static HRESULT
args_to_param(exec_ctx_t
*ctx
, argument_t
*args
, jsexcept_t
*ei
, DISPPARAMS
*dp
)
1068 HRESULT hres
= S_OK
;
1070 memset(dp
, 0, sizeof(*dp
));
1072 for(iter
= args
; iter
; iter
= iter
->next
)
1077 vargs
= heap_alloc_zero(cnt
* sizeof(*vargs
));
1079 return E_OUTOFMEMORY
;
1081 for(i
= cnt
, iter
= args
; iter
; iter
= iter
->next
) {
1082 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
1086 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, vargs
+ (--i
));
1087 exprval_release(&exprval
);
1102 /* ECMA-262 3rd Edition 11.2.2 */
1103 HRESULT
member_new_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1105 call_expression_t
*expr
= (call_expression_t
*)_expr
;
1107 VARIANT constr
, var
;
1113 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1117 hres
= args_to_param(ctx
, expr
->argument_list
, ei
, &dp
);
1119 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &constr
);
1120 exprval_release(&exprval
);
1124 if(V_VT(&constr
) != VT_DISPATCH
) {
1125 FIXME("throw TypeError\n");
1126 VariantClear(&constr
);
1130 hres
= disp_call(V_DISPATCH(&constr
), DISPID_VALUE
, ctx
->parser
->script
->lcid
,
1131 DISPATCH_CONSTRUCT
, &dp
, &var
, ei
, NULL
/*FIXME*/);
1132 IDispatch_Release(V_DISPATCH(&constr
));
1136 ret
->type
= EXPRVAL_VARIANT
;
1141 HRESULT
call_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1143 call_expression_t
*expr
= (call_expression_t
*)_expr
;
1151 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1155 hres
= args_to_param(ctx
, expr
->argument_list
, ei
, &dp
);
1156 if(SUCCEEDED(hres
)) {
1157 switch(exprval
.type
) {
1159 hres
= disp_call(exprval
.u
.idref
.disp
, exprval
.u
.idref
.id
, ctx
->parser
->script
->lcid
, DISPATCH_METHOD
,
1160 &dp
, flags
& EXPR_NOVAL
? NULL
: &var
, ei
, NULL
/*FIXME*/);
1161 if(flags
& EXPR_NOVAL
)
1162 V_VT(&var
) = VT_EMPTY
;
1165 FIXME("unimplemented type %d\n", V_VT(&func
));
1172 exprval_release(&exprval
);
1176 TRACE("= %s\n", debugstr_variant(&var
));
1177 ret
->type
= EXPRVAL_VARIANT
;
1182 HRESULT
this_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1186 ret
->type
= EXPRVAL_VARIANT
;
1187 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1188 V_DISPATCH(&ret
->u
.var
) = ctx
->this_obj
;
1189 IDispatch_AddRef(ctx
->this_obj
);
1193 /* ECMA-262 3rd Edition 10.1.4 */
1194 HRESULT
identifier_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1196 identifier_expression_t
*expr
= (identifier_expression_t
*)_expr
;
1202 identifier
= SysAllocString(expr
->identifier
);
1204 return E_OUTOFMEMORY
;
1206 hres
= identifier_eval(ctx
, identifier
, flags
, ret
);
1208 SysFreeString(identifier
);
1212 /* ECMA-262 3rd Edition 7.8 */
1213 HRESULT
literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1215 literal_expression_t
*expr
= (literal_expression_t
*)_expr
;
1221 hres
= literal_to_var(expr
->literal
, &var
);
1225 ret
->type
= EXPRVAL_VARIANT
;
1230 HRESULT
array_literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1236 /* ECMA-262 3rd Edition 11.1.5 */
1237 HRESULT
property_value_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1239 property_value_expression_t
*expr
= (property_value_expression_t
*)_expr
;
1249 hres
= create_object(ctx
->parser
->script
, NULL
, &obj
);
1253 for(iter
= expr
->property_list
; iter
; iter
= iter
->next
) {
1254 hres
= literal_to_var(iter
->name
, &tmp
);
1258 hres
= to_string(ctx
->parser
->script
, &tmp
, ei
, &name
);
1263 hres
= expr_eval(ctx
, iter
->value
, 0, ei
, &exprval
);
1264 if(SUCCEEDED(hres
)) {
1265 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1266 exprval_release(&exprval
);
1267 if(SUCCEEDED(hres
)) {
1268 hres
= jsdisp_propput_name(obj
, name
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
1273 SysFreeString(name
);
1279 jsdisp_release(obj
);
1283 ret
->type
= EXPRVAL_VARIANT
;
1284 V_VT(&ret
->u
.var
) = VT_DISPATCH
;
1285 V_DISPATCH(&ret
->u
.var
) = (IDispatch
*)_IDispatchEx_(obj
);
1289 HRESULT
comma_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1295 /* ECMA-262 3rd Edition 11.11 */
1296 HRESULT
logical_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1298 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1306 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1310 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1311 exprval_release(&exprval
);
1315 hres
= to_boolean(&val
, &b
);
1316 if(SUCCEEDED(hres
) && b
) {
1317 ret
->type
= EXPRVAL_VARIANT
;
1326 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1330 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1331 exprval_release(&exprval
);
1335 ret
->type
= EXPRVAL_VARIANT
;
1340 /* ECMA-262 3rd Edition 11.11 */
1341 HRESULT
logical_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1343 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1351 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
1355 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1356 exprval_release(&exprval
);
1360 hres
= to_boolean(&val
, &b
);
1361 if(SUCCEEDED(hres
) && !b
) {
1362 ret
->type
= EXPRVAL_VARIANT
;
1371 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
1375 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1376 exprval_release(&exprval
);
1380 ret
->type
= EXPRVAL_VARIANT
;
1385 HRESULT
binary_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1391 HRESULT
binary_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1397 HRESULT
binary_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1403 HRESULT
instanceof_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1409 HRESULT
in_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1415 /* ECMA-262 3rd Edition 11.6.1 */
1416 static HRESULT
add_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, VARIANT
*retv
)
1421 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &l
);
1425 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &r
);
1431 if(V_VT(&l
) == VT_BSTR
|| V_VT(&r
) == VT_BSTR
) {
1432 BSTR lstr
= NULL
, rstr
= NULL
;
1434 if(V_VT(&l
) == VT_BSTR
)
1437 hres
= to_string(ctx
->parser
->script
, &l
, ei
, &lstr
);
1439 if(SUCCEEDED(hres
)) {
1440 if(V_VT(&r
) == VT_BSTR
)
1443 hres
= to_string(ctx
->parser
->script
, &r
, ei
, &rstr
);
1446 if(SUCCEEDED(hres
)) {
1449 len1
= SysStringLen(lstr
);
1450 len2
= SysStringLen(rstr
);
1452 V_VT(retv
) = VT_BSTR
;
1453 V_BSTR(retv
) = SysAllocStringLen(NULL
, len1
+len2
);
1454 memcpy(V_BSTR(retv
), lstr
, len1
*sizeof(WCHAR
));
1455 memcpy(V_BSTR(retv
)+len1
, rstr
, (len2
+1)*sizeof(WCHAR
));
1458 if(lstr
&& V_VT(&l
) != VT_BSTR
)
1459 SysFreeString(lstr
);
1460 if(rstr
&& V_VT(&r
) != VT_BSTR
)
1461 SysFreeString(rstr
);
1465 hres
= to_number(ctx
->parser
->script
, &l
, ei
, &nl
);
1466 if(SUCCEEDED(hres
)) {
1467 hres
= to_number(ctx
->parser
->script
, &r
, ei
, &nr
);
1469 num_set_val(retv
, num_val(&nl
) + num_val(&nr
));
1478 /* ECMA-262 3rd Edition 11.6.1 */
1479 HRESULT
add_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1481 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1485 return binary_expr_eval(ctx
, expr
, add_eval
, ei
, ret
);
1488 HRESULT
sub_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1494 HRESULT
mul_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1500 HRESULT
div_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1506 HRESULT
mod_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1512 HRESULT
delete_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1518 HRESULT
void_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1524 HRESULT
typeof_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1526 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
1532 static const WCHAR booleanW
[] = {'b','o','o','l','e','a','n',0};
1533 static const WCHAR functionW
[] = {'f','u','n','c','t','i','o','n',0};
1534 static const WCHAR numberW
[] = {'n','u','m','b','e','r',0};
1535 static const WCHAR objectW
[] = {'o','b','j','e','c','t',0};
1536 static const WCHAR stringW
[] = {'s','t','r','i','n','g',0};
1537 static const WCHAR undefinedW
[] = {'u','n','d','e','f','i','n','e','d',0};
1541 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
1545 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1546 exprval_release(&exprval
);
1550 switch(V_VT(&val
)) {
1570 dispex
= iface_to_jsdisp((IUnknown
*)V_DISPATCH(&val
));
1572 str
= dispex
->builtin_info
->class == JSCLASS_FUNCTION
? functionW
: objectW
;
1573 IDispatchEx_Release(_IDispatchEx_(dispex
));
1580 FIXME("unhandled vt %d\n", V_VT(&val
));
1588 ret
->type
= EXPRVAL_VARIANT
;
1589 V_VT(&ret
->u
.var
) = VT_BSTR
;
1590 V_BSTR(&ret
->u
.var
) = SysAllocString(str
);
1594 HRESULT
minus_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1600 HRESULT
plus_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1606 /* ECMA-262 3rd Edition 11.3.1 */
1607 HRESULT
post_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1609 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
1616 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
1620 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1621 if(SUCCEEDED(hres
)) {
1622 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
1626 if(SUCCEEDED(hres
)) {
1628 num_set_val(&inc
, num_val(&num
)+1.0);
1629 hres
= put_value(ctx
->parser
->script
, &exprval
, &inc
, ei
);
1632 exprval_release(&exprval
);
1636 ret
->type
= EXPRVAL_VARIANT
;
1641 /* ECMA-262 3rd Edition 11.3.2 */
1642 HRESULT
post_decrement_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1644 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
1651 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
1655 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1656 if(SUCCEEDED(hres
)) {
1657 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
1661 if(SUCCEEDED(hres
)) {
1663 num_set_val(&dec
, num_val(&num
)-1.0);
1664 hres
= put_value(ctx
->parser
->script
, &exprval
, &dec
, ei
);
1667 exprval_release(&exprval
);
1671 ret
->type
= EXPRVAL_VARIANT
;
1676 /* ECMA-262 3rd Edition 11.4.4 */
1677 HRESULT
pre_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1679 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
1686 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
1690 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1691 if(SUCCEEDED(hres
)) {
1692 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
1696 if(SUCCEEDED(hres
)) {
1697 num_set_val(&val
, num_val(&num
)+1.0);
1698 hres
= put_value(ctx
->parser
->script
, &exprval
, &val
, ei
);
1701 exprval_release(&exprval
);
1705 ret
->type
= EXPRVAL_VARIANT
;
1710 /* ECMA-262 3rd Edition 11.4.5 */
1711 HRESULT
pre_decrement_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1713 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
1720 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
1724 hres
= exprval_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
1725 if(SUCCEEDED(hres
)) {
1726 hres
= to_number(ctx
->parser
->script
, &val
, ei
, &num
);
1730 if(SUCCEEDED(hres
)) {
1731 num_set_val(&val
, num_val(&num
)-1.0);
1732 hres
= put_value(ctx
->parser
->script
, &exprval
, &val
, ei
);
1735 exprval_release(&exprval
);
1739 ret
->type
= EXPRVAL_VARIANT
;
1744 HRESULT
new_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1750 HRESULT
equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1756 /* ECMA-262 3rd Edition 11.9.4 */
1757 HRESULT
equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1759 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1766 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
1770 hres
= equal2_values(&rval
, &lval
, &b
);
1774 return return_bool(ret
, b
);
1777 HRESULT
not_equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1784 /* ECMA-262 3rd Edition 11.9.5 */
1785 HRESULT
not_equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1787 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1794 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
1798 hres
= equal2_values(&rval
, &lval
, &b
);
1802 return return_bool(ret
, !b
);
1805 /* ECMA-262 3rd Edition 11.8.5 */
1806 static HRESULT
less_eval(exec_ctx_t
*ctx
, VARIANT
*lval
, VARIANT
*rval
, jsexcept_t
*ei
, BOOL
*ret
)
1808 VARIANT l
, r
, ln
, rn
;
1811 hres
= to_primitive(ctx
->parser
->script
, lval
, ei
, &l
);
1815 hres
= to_primitive(ctx
->parser
->script
, rval
, ei
, &r
);
1821 if(V_VT(&l
) == VT_BSTR
&& V_VT(&r
) == VT_BSTR
) {
1822 *ret
= strcmpW(V_BSTR(&l
), V_BSTR(&r
)) < 0;
1823 SysFreeString(V_BSTR(&l
));
1824 SysFreeString(V_BSTR(&r
));
1828 hres
= to_number(ctx
->parser
->script
, &l
, ei
, &ln
);
1831 hres
= to_number(ctx
->parser
->script
, &r
, ei
, &rn
);
1836 if(V_VT(&ln
) == VT_I4
&& V_VT(&rn
) == VT_I4
)
1837 *ret
= V_I4(&ln
) < V_I4(&rn
);
1839 *ret
= num_val(&ln
) < num_val(&rn
);
1844 /* ECMA-262 3rd Edition 11.8.1 */
1845 HRESULT
less_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1847 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1854 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1858 hres
= less_eval(ctx
, &lval
, &rval
, ei
, &b
);
1859 VariantClear(&lval
);
1860 VariantClear(&rval
);
1864 return return_bool(ret
, b
);
1867 /* ECMA-262 3rd Edition 11.8.3 */
1868 HRESULT
lesseq_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1870 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1877 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1881 hres
= less_eval(ctx
, &rval
, &lval
, ei
, &b
);
1882 VariantClear(&lval
);
1883 VariantClear(&rval
);
1887 return return_bool(ret
, !b
);
1890 /* ECMA-262 3rd Edition 11.8.2 */
1891 HRESULT
greater_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1893 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1900 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1904 hres
= less_eval(ctx
, &rval
, &lval
, ei
, &b
);
1905 VariantClear(&lval
);
1906 VariantClear(&rval
);
1910 return return_bool(ret
, b
);
1913 /* ECMA-262 3rd Edition 11.8.4 */
1914 HRESULT
greatereq_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1916 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1923 hres
= get_binary_expr_values(ctx
, expr
, ei
, &lval
, &rval
);
1927 hres
= less_eval(ctx
, &lval
, &rval
, ei
, &b
);
1928 VariantClear(&lval
);
1929 VariantClear(&rval
);
1933 return return_bool(ret
, !b
);
1936 HRESULT
binary_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1942 /* ECMA-262 3rd Edition 11.4.9 */
1943 HRESULT
logical_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1945 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
1952 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
1956 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, ei
, &b
);
1957 exprval_release(&exprval
);
1961 return return_bool(ret
, !b
);
1964 HRESULT
left_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1970 HRESULT
right_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1976 HRESULT
right2_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1982 /* ECMA-262 3rd Edition 11.13.1 */
1983 HRESULT
assign_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1985 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1986 exprval_t exprval
, exprvalr
;
1992 hres
= expr_eval(ctx
, expr
->expression1
, EXPR_NEWREF
, ei
, &exprval
);
1996 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprvalr
);
1997 if(SUCCEEDED(hres
)) {
1998 hres
= exprval_to_value(ctx
->parser
->script
, &exprvalr
, ei
, &rval
);
1999 exprval_release(&exprvalr
);
2003 hres
= put_value(ctx
->parser
->script
, &exprval
, &rval
, ei
);
2005 exprval_release(&exprval
);
2007 VariantClear(&rval
);
2011 ret
->type
= EXPRVAL_VARIANT
;
2016 HRESULT
assign_lshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2022 HRESULT
assign_rshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2028 HRESULT
assign_rrshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2034 /* ECMA-262 3rd Edition 11.13.2 */
2035 HRESULT
assign_add_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2037 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
2041 return assign_oper_eval(ctx
, expr
->expression1
, expr
->expression2
, add_eval
, ei
, ret
);
2044 HRESULT
assign_sub_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2050 HRESULT
assign_mul_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2056 HRESULT
assign_div_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2062 HRESULT
assign_mod_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2068 HRESULT
assign_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2074 HRESULT
assign_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
2080 HRESULT
assign_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)