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 void scope_release(scope_chain_t
*scope
)
129 scope_release(scope
->next
);
131 IDispatchEx_Release(_IDispatchEx_(scope
->obj
));
135 HRESULT
create_exec_ctx(DispatchEx
*var_disp
, scope_chain_t
*scope
, exec_ctx_t
**ret
)
139 ctx
= heap_alloc_zero(sizeof(exec_ctx_t
));
141 return E_OUTOFMEMORY
;
143 IDispatchEx_AddRef(_IDispatchEx_(var_disp
));
144 ctx
->var_disp
= var_disp
;
148 ctx
->scope_chain
= scope
;
155 void exec_release(exec_ctx_t
*ctx
)
161 scope_release(ctx
->scope_chain
);
163 IDispatchEx_Release(_IDispatchEx_(ctx
->var_disp
));
167 static HRESULT
dispex_get_id(IDispatchEx
*dispex
, BSTR name
, DWORD flags
, DISPID
*id
)
171 return IDispatchEx_GetDispID(dispex
, name
, flags
|fdexNameCaseSensitive
, id
);
174 static HRESULT
disp_get_id(IDispatch
*disp
, BSTR name
, DWORD flags
, DISPID
*id
)
179 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
181 TRACE("unsing IDispatch\n");
184 return IDispatch_GetIDsOfNames(disp
, &IID_NULL
, &name
, 1, 0, id
);
187 hres
= dispex_get_id(dispex
, name
, flags
, id
);
188 IDispatchEx_Release(dispex
);
192 /* ECMA-262 3rd Edition 8.7.2 */
193 static HRESULT
put_value(script_ctx_t
*ctx
, exprval_t
*ref
, VARIANT
*v
, jsexcept_t
*ei
)
195 if(ref
->type
!= EXPRVAL_IDREF
) {
196 FIXME("throw ReferemceError\n");
200 return disp_propput(ref
->u
.idref
.disp
, ref
->u
.idref
.id
, ctx
->lcid
, v
, ei
, NULL
/*FIXME*/);
203 static HRESULT
disp_cmp(IDispatch
*disp1
, IDispatch
*disp2
, BOOL
*ret
)
205 IObjectIdentity
*identity
;
206 IUnknown
*unk1
, *unk2
;
214 hres
= IDispatch_QueryInterface(disp1
, &IID_IUnknown
, (void**)&unk1
);
218 hres
= IDispatch_QueryInterface(disp2
, &IID_IUnknown
, (void**)&unk2
);
220 IUnknown_Release(unk1
);
227 hres
= IUnknown_QueryInterface(unk1
, &IID_IObjectIdentity
, (void**)&identity
);
228 if(SUCCEEDED(hres
)) {
229 hres
= IObjectIdentity_IsEqualObject(identity
, unk2
);
230 IObjectIdentity_Release(identity
);
237 IUnknown_Release(unk1
);
238 IUnknown_Release(unk2
);
242 static inline BOOL
is_num_vt(enum VARENUM vt
)
244 return vt
== VT_I4
|| vt
== VT_R8
;
247 static inline DOUBLE
num_val(const VARIANT
*v
)
249 return V_VT(v
) == VT_I4
? V_I4(v
) : V_R8(v
);
252 /* ECMA-262 3rd Edition 11.9.6 */
253 HRESULT
equal2_values(VARIANT
*lval
, VARIANT
*rval
, BOOL
*ret
)
257 if(V_VT(lval
) != V_VT(rval
)) {
258 if(is_num_vt(V_VT(lval
)) && is_num_vt(V_VT(rval
))) {
259 *ret
= num_val(lval
) == num_val(rval
);
273 *ret
= V_I4(lval
) == V_I4(rval
);
276 *ret
= V_R8(lval
) == V_R8(rval
);
279 *ret
= !strcmpW(V_BSTR(lval
), V_BSTR(rval
));
282 return disp_cmp(V_DISPATCH(lval
), V_DISPATCH(rval
), ret
);
284 *ret
= !V_BOOL(lval
) == !V_BOOL(rval
);
287 FIXME("unimplemented vt %d\n", V_VT(lval
));
294 static HRESULT
literal_to_var(literal_t
*literal
, VARIANT
*v
)
296 V_VT(v
) = literal
->vt
;
303 V_I4(v
) = literal
->u
.lval
;
306 V_R8(v
) = literal
->u
.dval
;
309 V_BSTR(v
) = SysAllocString(literal
->u
.wstr
);
312 V_BOOL(v
) = literal
->u
.bval
;
315 IDispatch_AddRef(literal
->u
.disp
);
316 V_DISPATCH(v
) = literal
->u
.disp
;
319 ERR("wrong type %d\n", V_VT(v
));
326 HRESULT
exec_source(exec_ctx_t
*ctx
, parser_ctx_t
*parser
, source_elements_t
*source
, jsexcept_t
*ei
, VARIANT
*retv
)
328 script_ctx_t
*script
= parser
->script
;
329 function_declaration_t
*func
;
330 parser_ctx_t
*prev_parser
;
333 exec_ctx_t
*prev_ctx
;
337 for(func
= source
->functions
; func
; func
= func
->next
) {
338 DispatchEx
*func_obj
;
341 hres
= create_source_function(parser
, func
->parameter_list
, func
->source_elements
, ctx
->scope_chain
, &func_obj
);
345 V_VT(&var
) = VT_DISPATCH
;
346 V_DISPATCH(&var
) = (IDispatch
*)_IDispatchEx_(func_obj
);
347 hres
= jsdisp_propput_name(ctx
->var_disp
, func
->identifier
, script
->lcid
, &var
, ei
, NULL
);
348 IDispatchEx_Release(_IDispatchEx_(func_obj
));
353 prev_ctx
= script
->exec_ctx
;
354 script
->exec_ctx
= ctx
;
356 prev_parser
= ctx
->parser
;
357 ctx
->parser
= parser
;
359 V_VT(&val
) = VT_EMPTY
;
360 memset(&rt
, 0, sizeof(rt
));
363 for(stat
= source
->statement
; stat
; stat
= stat
->next
) {
364 hres
= stat_eval(ctx
, stat
, &rt
, &tmp
);
370 if(rt
.type
!= RT_NORMAL
)
374 script
->exec_ctx
= prev_ctx
;
375 ctx
->parser
= prev_parser
;
377 if(rt
.type
!= RT_NORMAL
&& rt
.type
!= RT_RETURN
) {
378 FIXME("wrong rt %d\n", rt
.type
);
395 /* ECMA-262 3rd Edition 10.1.4 */
396 static HRESULT
identifier_eval(exec_ctx_t
*ctx
, BSTR identifier
, DWORD flags
, exprval_t
*ret
)
398 scope_chain_t
*scope
;
403 TRACE("%s\n", debugstr_w(identifier
));
405 for(scope
= ctx
->scope_chain
; scope
; scope
= scope
->next
) {
406 hres
= dispex_get_id(_IDispatchEx_(scope
->obj
), identifier
, 0, &id
);
412 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(scope
->obj
), id
);
416 hres
= dispex_get_id(_IDispatchEx_(ctx
->parser
->script
->global
), identifier
, 0, &id
);
417 if(SUCCEEDED(hres
)) {
418 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->parser
->script
->global
), id
);
422 for(item
= ctx
->parser
->script
->named_items
; item
; item
= item
->next
) {
423 hres
= disp_get_id(item
->disp
, identifier
, 0, &id
);
429 exprval_set_idref(ret
, (IDispatch
*)item
->disp
, id
);
433 hres
= dispex_get_id(_IDispatchEx_(ctx
->parser
->script
->script_disp
), identifier
, 0, &id
);
434 if(SUCCEEDED(hres
)) {
435 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->parser
->script
->script_disp
), id
);
439 if(flags
& EXPR_NEWREF
) {
440 hres
= dispex_get_id(_IDispatchEx_(ctx
->var_disp
), identifier
, fdexNameEnsure
, &id
);
444 exprval_set_idref(ret
, (IDispatch
*)_IDispatchEx_(ctx
->var_disp
), id
);
448 WARN("Could not find identifier %s\n", debugstr_w(identifier
));
452 HRESULT
block_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
458 /* ECMA-262 3rd Edition 12.2 */
459 static HRESULT
variable_list_eval(exec_ctx_t
*ctx
, variable_declaration_t
*var_list
, jsexcept_t
*ei
)
461 variable_declaration_t
*iter
;
464 for(iter
= var_list
; iter
; iter
= iter
->next
) {
470 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
474 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
475 exprval_release(&exprval
);
479 V_VT(&val
) = VT_EMPTY
;
482 hres
= jsdisp_propput_name(ctx
->var_disp
, iter
->identifier
, ctx
->parser
->script
->lcid
, &val
, ei
, NULL
/*FIXME*/);
491 /* ECMA-262 3rd Edition 12.2 */
492 HRESULT
var_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
494 var_statement_t
*stat
= (var_statement_t
*)_stat
;
499 hres
= variable_list_eval(ctx
, stat
->variable_list
, &rt
->ei
);
503 V_VT(ret
) = VT_EMPTY
;
507 /* ECMA-262 3rd Edition 12.3 */
508 HRESULT
empty_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
512 V_VT(ret
) = VT_EMPTY
;
516 /* ECMA-262 3rd Edition 12.4 */
517 HRESULT
expression_statement_eval(exec_ctx_t
*ctx
, statement_t
*_stat
, return_type_t
*rt
, VARIANT
*ret
)
519 expression_statement_t
*stat
= (expression_statement_t
*)_stat
;
526 hres
= expr_eval(ctx
, stat
->expr
, EXPR_NOVAL
, &rt
->ei
, &exprval
);
530 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, &rt
->ei
, &val
);
531 exprval_release(&exprval
);
536 TRACE("= %s\n", debugstr_variant(ret
));
540 HRESULT
if_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
546 HRESULT
dowhile_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
552 HRESULT
while_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
558 HRESULT
for_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
564 HRESULT
forin_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
570 HRESULT
continue_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
576 HRESULT
break_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
582 HRESULT
return_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
588 HRESULT
with_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
594 HRESULT
labelled_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
600 HRESULT
switch_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
606 HRESULT
throw_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
612 HRESULT
try_statement_eval(exec_ctx_t
*ctx
, statement_t
*stat
, return_type_t
*rt
, VARIANT
*ret
)
618 static HRESULT
return_bool(exprval_t
*ret
, DWORD b
)
620 ret
->type
= EXPRVAL_VARIANT
;
621 V_VT(&ret
->u
.var
) = VT_BOOL
;
622 V_BOOL(&ret
->u
.var
) = b
? VARIANT_TRUE
: VARIANT_FALSE
;
627 static HRESULT
get_binary_expr_values(exec_ctx_t
*ctx
, binary_expression_t
*expr
, jsexcept_t
*ei
, VARIANT
*lval
, VARIANT
*rval
)
632 hres
= expr_eval(ctx
, expr
->expression1
, 0, ei
, &exprval
);
636 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, lval
);
637 exprval_release(&exprval
);
641 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprval
);
642 if(SUCCEEDED(hres
)) {
643 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, rval
);
644 exprval_release(&exprval
);
655 HRESULT
function_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
661 HRESULT
conditional_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
667 HRESULT
array_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
673 /* ECMA-262 3rd Edition 11.2.1 */
674 HRESULT
member_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
676 member_expression_t
*expr
= (member_expression_t
*)_expr
;
677 IDispatch
*obj
= NULL
;
686 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
690 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &member
);
691 exprval_release(&exprval
);
695 hres
= to_object(ctx
, &member
, &obj
);
696 VariantClear(&member
);
700 str
= SysAllocString(expr
->identifier
);
701 if(flags
& EXPR_STRREF
) {
702 ret
->type
= EXPRVAL_NAMEREF
;
703 ret
->u
.nameref
.disp
= obj
;
704 ret
->u
.nameref
.name
= str
;
708 hres
= disp_get_id(obj
, str
, flags
& EXPR_NEW
? fdexNameEnsure
: 0, &id
);
710 if(SUCCEEDED(hres
)) {
711 exprval_set_idref(ret
, obj
, id
);
712 }else if(!(flags
& EXPR_NEWREF
) && hres
== DISP_E_UNKNOWNNAME
) {
717 IDispatch_Release(obj
);
721 static void free_dp(DISPPARAMS
*dp
)
725 for(i
=0; i
< dp
->cArgs
; i
++)
726 VariantClear(dp
->rgvarg
+i
);
727 heap_free(dp
->rgvarg
);
730 static HRESULT
args_to_param(exec_ctx_t
*ctx
, argument_t
*args
, jsexcept_t
*ei
, DISPPARAMS
*dp
)
738 memset(dp
, 0, sizeof(*dp
));
740 for(iter
= args
; iter
; iter
= iter
->next
)
745 vargs
= heap_alloc_zero(cnt
* sizeof(*vargs
));
747 return E_OUTOFMEMORY
;
749 for(i
= cnt
, iter
= args
; iter
; iter
= iter
->next
) {
750 hres
= expr_eval(ctx
, iter
->expr
, 0, ei
, &exprval
);
754 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, vargs
+ (--i
));
755 exprval_release(&exprval
);
770 HRESULT
member_new_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
776 HRESULT
call_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
778 call_expression_t
*expr
= (call_expression_t
*)_expr
;
786 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
790 hres
= args_to_param(ctx
, expr
->argument_list
, ei
, &dp
);
791 if(SUCCEEDED(hres
)) {
792 switch(exprval
.type
) {
794 hres
= disp_call(exprval
.u
.idref
.disp
, exprval
.u
.idref
.id
, ctx
->parser
->script
->lcid
, DISPATCH_METHOD
,
795 &dp
, flags
& EXPR_NOVAL
? NULL
: &var
, ei
, NULL
/*FIXME*/);
796 if(flags
& EXPR_NOVAL
)
797 V_VT(&var
) = VT_EMPTY
;
800 FIXME("unimplemented type %d\n", V_VT(&func
));
807 exprval_release(&exprval
);
811 TRACE("= %s\n", debugstr_variant(&var
));
812 ret
->type
= EXPRVAL_VARIANT
;
817 HRESULT
this_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
823 /* ECMA-262 3rd Edition 10.1.4 */
824 HRESULT
identifier_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
826 identifier_expression_t
*expr
= (identifier_expression_t
*)_expr
;
832 identifier
= SysAllocString(expr
->identifier
);
834 return E_OUTOFMEMORY
;
836 hres
= identifier_eval(ctx
, identifier
, flags
, ret
);
838 SysFreeString(identifier
);
842 /* ECMA-262 3rd Edition 7.8 */
843 HRESULT
literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
845 literal_expression_t
*expr
= (literal_expression_t
*)_expr
;
851 hres
= literal_to_var(expr
->literal
, &var
);
855 ret
->type
= EXPRVAL_VARIANT
;
860 HRESULT
array_literal_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
866 HRESULT
property_value_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
872 HRESULT
comma_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
878 HRESULT
logical_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
884 HRESULT
logical_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
890 HRESULT
binary_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
896 HRESULT
binary_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
902 HRESULT
binary_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
908 HRESULT
instanceof_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
914 HRESULT
in_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
920 HRESULT
add_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
926 HRESULT
sub_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
932 HRESULT
mul_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
938 HRESULT
div_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
944 HRESULT
mod_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
950 HRESULT
delete_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
956 HRESULT
void_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
962 HRESULT
typeof_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
964 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
970 static const WCHAR booleanW
[] = {'b','o','o','l','e','a','n',0};
971 static const WCHAR functionW
[] = {'f','u','n','c','t','i','o','n',0};
972 static const WCHAR numberW
[] = {'n','u','m','b','e','r',0};
973 static const WCHAR objectW
[] = {'o','b','j','e','c','t',0};
974 static const WCHAR stringW
[] = {'s','t','r','i','n','g',0};
975 static const WCHAR undefinedW
[] = {'u','n','d','e','f','i','n','e','d',0};
979 hres
= expr_eval(ctx
, expr
->expression
, 0, ei
, &exprval
);
983 hres
= exprval_to_value(ctx
->parser
->script
, &exprval
, ei
, &val
);
984 exprval_release(&exprval
);
1008 dispex
= iface_to_jsdisp((IUnknown
*)V_DISPATCH(&val
));
1010 str
= dispex
->builtin_info
->class == JSCLASS_FUNCTION
? functionW
: objectW
;
1011 IDispatchEx_Release(_IDispatchEx_(dispex
));
1018 FIXME("unhandled vt %d\n", V_VT(&val
));
1026 ret
->type
= EXPRVAL_VARIANT
;
1027 V_VT(&ret
->u
.var
) = VT_BSTR
;
1028 V_BSTR(&ret
->u
.var
) = SysAllocString(str
);
1032 HRESULT
minus_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1038 HRESULT
plus_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1044 HRESULT
post_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1050 HRESULT
post_decrement_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1056 HRESULT
pre_increment_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1062 HRESULT
pre_decrement_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1068 HRESULT
new_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1074 HRESULT
equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1080 /* ECMA-262 3rd Edition 11.9.4 */
1081 HRESULT
equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1083 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1090 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
1094 hres
= equal2_values(&rval
, &lval
, &b
);
1098 return return_bool(ret
, b
);
1101 HRESULT
not_equal_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1108 /* ECMA-262 3rd Edition 11.9.5 */
1109 HRESULT
not_equal2_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1111 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1118 hres
= get_binary_expr_values(ctx
, expr
, ei
, &rval
, &lval
);
1122 hres
= equal2_values(&rval
, &lval
, &b
);
1126 return return_bool(ret
, !b
);
1129 HRESULT
less_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1135 HRESULT
lesseq_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1141 HRESULT
greater_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1147 HRESULT
greatereq_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1153 HRESULT
binary_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1159 /* ECMA-262 3rd Edition 11.4.9 */
1160 HRESULT
logical_negation_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1162 unary_expression_t
*expr
= (unary_expression_t
*)_expr
;
1169 hres
= expr_eval(ctx
, expr
->expression
, EXPR_NEWREF
, ei
, &exprval
);
1173 hres
= exprval_to_boolean(ctx
->parser
->script
, &exprval
, ei
, &b
);
1174 exprval_release(&exprval
);
1178 return return_bool(ret
, !b
);
1181 HRESULT
left_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1187 HRESULT
right_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1193 HRESULT
right2_shift_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1199 /* ECMA-262 3rd Edition 11.13.1 */
1200 HRESULT
assign_expression_eval(exec_ctx_t
*ctx
, expression_t
*_expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1202 binary_expression_t
*expr
= (binary_expression_t
*)_expr
;
1203 exprval_t exprval
, exprvalr
;
1209 hres
= expr_eval(ctx
, expr
->expression1
, EXPR_NEWREF
, ei
, &exprval
);
1213 hres
= expr_eval(ctx
, expr
->expression2
, 0, ei
, &exprvalr
);
1214 if(SUCCEEDED(hres
)) {
1215 hres
= exprval_to_value(ctx
->parser
->script
, &exprvalr
, ei
, &rval
);
1216 exprval_release(&exprvalr
);
1220 hres
= put_value(ctx
->parser
->script
, &exprval
, &rval
, ei
);
1222 exprval_release(&exprval
);
1224 VariantClear(&rval
);
1228 ret
->type
= EXPRVAL_VARIANT
;
1233 HRESULT
assign_lshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1239 HRESULT
assign_rshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1245 HRESULT
assign_rrshift_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1251 HRESULT
assign_add_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1257 HRESULT
assign_sub_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1263 HRESULT
assign_mul_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1269 HRESULT
assign_div_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1275 HRESULT
assign_mod_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1281 HRESULT
assign_and_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1287 HRESULT
assign_or_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)
1293 HRESULT
assign_xor_expression_eval(exec_ctx_t
*ctx
, expression_t
*expr
, DWORD flags
, jsexcept_t
*ei
, exprval_t
*ret
)