2 * Copyright 2008,2011 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"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
32 static const WCHAR booleanW
[] = {'b','o','o','l','e','a','n',0};
33 static const WCHAR functionW
[] = {'f','u','n','c','t','i','o','n',0};
34 static const WCHAR numberW
[] = {'n','u','m','b','e','r',0};
35 static const WCHAR objectW
[] = {'o','b','j','e','c','t',0};
36 static const WCHAR stringW
[] = {'s','t','r','i','n','g',0};
37 static const WCHAR undefinedW
[] = {'u','n','d','e','f','i','n','e','d',0};
38 static const WCHAR unknownW
[] = {'u','n','k','n','o','w','n',0};
40 struct _except_frame_t
{
67 static HRESULT
stack_push(script_ctx_t
*ctx
, jsval_t v
)
69 if(!ctx
->stack_size
) {
70 ctx
->stack
= heap_alloc(16*sizeof(*ctx
->stack
));
74 }else if(ctx
->stack_size
== ctx
->stack_top
) {
77 new_stack
= heap_realloc(ctx
->stack
, ctx
->stack_size
*2*sizeof(*new_stack
));
83 ctx
->stack
= new_stack
;
87 ctx
->stack
[ctx
->stack_top
++] = v
;
91 static inline HRESULT
stack_push_string(script_ctx_t
*ctx
, const WCHAR
*str
)
99 return stack_push(ctx
, jsval_string(v
));
102 static inline jsval_t
stack_top(script_ctx_t
*ctx
)
104 assert(ctx
->stack_top
> ctx
->call_ctx
->stack_base
);
105 return ctx
->stack
[ctx
->stack_top
-1];
108 static inline jsval_t
*stack_top_ref(script_ctx_t
*ctx
, unsigned n
)
110 assert(ctx
->stack_top
> ctx
->call_ctx
->stack_base
+n
);
111 return ctx
->stack
+ctx
->stack_top
-1-n
;
114 static inline jsval_t
stack_topn(script_ctx_t
*ctx
, unsigned n
)
116 return *stack_top_ref(ctx
, n
);
119 static inline jsval_t
*stack_args(script_ctx_t
*ctx
, unsigned n
)
123 assert(ctx
->stack_top
> ctx
->call_ctx
->stack_base
+n
-1);
124 return ctx
->stack
+ ctx
->stack_top
-n
;
127 static inline jsval_t
stack_pop(script_ctx_t
*ctx
)
129 assert(ctx
->stack_top
> ctx
->call_ctx
->stack_base
);
130 return ctx
->stack
[--ctx
->stack_top
];
133 static void stack_popn(script_ctx_t
*ctx
, unsigned n
)
136 jsval_release(stack_pop(ctx
));
139 static HRESULT
stack_pop_number(script_ctx_t
*ctx
, double *r
)
145 hres
= to_number(ctx
, v
, r
);
150 static HRESULT
stack_pop_object(script_ctx_t
*ctx
, IDispatch
**r
)
156 if(is_object_instance(v
)) {
158 return throw_type_error(ctx
, JS_E_OBJECT_REQUIRED
, NULL
);
163 hres
= to_object(ctx
, v
, r
);
168 static inline HRESULT
stack_pop_int(script_ctx_t
*ctx
, INT
*r
)
170 return to_int32(ctx
, stack_pop(ctx
), r
);
173 static inline HRESULT
stack_pop_uint(script_ctx_t
*ctx
, DWORD
*r
)
175 return to_uint32(ctx
, stack_pop(ctx
), r
);
178 static inline unsigned local_off(call_frame_t
*frame
, int ref
)
181 ? frame
->arguments_off
- ref
-1
182 : frame
->variables_off
+ ref
;
185 static inline BSTR
local_name(call_frame_t
*frame
, int ref
)
187 return ref
< 0 ? frame
->function
->params
[-ref
-1] : frame
->function
->variables
[ref
].name
;
190 /* Steals input reference even on failure. */
191 static HRESULT
stack_push_exprval(script_ctx_t
*ctx
, exprval_t
*val
)
199 hres
= stack_push(ctx
, jsval_disp(val
->u
.idref
.disp
));
201 hres
= stack_push(ctx
, jsval_number(val
->u
.idref
.id
));
203 IDispatch_Release(val
->u
.idref
.disp
);
205 case EXPRVAL_STACK_REF
:
206 hres
= stack_push(ctx
, jsval_number(val
->u
.off
));
208 hres
= stack_push(ctx
, jsval_undefined());
210 case EXPRVAL_INVALID
:
211 hres
= stack_push(ctx
, jsval_undefined());
213 hres
= stack_push(ctx
, jsval_number(val
->u
.hres
));
221 static BOOL
stack_topn_exprval(script_ctx_t
*ctx
, unsigned n
, exprval_t
*r
)
223 jsval_t v
= stack_topn(ctx
, n
+1);
225 switch(jsval_type(v
)) {
227 call_frame_t
*frame
= ctx
->call_ctx
;
228 unsigned off
= get_number(v
);
230 if(!frame
->base_scope
->frame
&& off
>= frame
->arguments_off
) {
235 /* Got stack reference in deoptimized code. Need to convert it back to variable object reference. */
237 assert(off
< frame
->variables_off
+ frame
->function
->var_cnt
);
238 name
= off
>= frame
->variables_off
239 ? frame
->function
->variables
[off
- frame
->variables_off
].name
240 : frame
->function
->params
[off
- frame
->arguments_off
];
241 hres
= jsdisp_get_id(ctx
->call_ctx
->base_scope
->jsobj
, name
, 0, &id
);
243 r
->type
= EXPRVAL_INVALID
;
248 *stack_top_ref(ctx
, n
+1) = jsval_obj(jsdisp_addref(frame
->base_scope
->jsobj
));
249 *stack_top_ref(ctx
, n
) = jsval_number(id
);
250 r
->type
= EXPRVAL_IDREF
;
251 r
->u
.idref
.disp
= frame
->base_scope
->obj
;
256 r
->type
= EXPRVAL_STACK_REF
;
261 r
->type
= EXPRVAL_IDREF
;
262 r
->u
.idref
.disp
= get_object(v
);
263 assert(is_number(stack_topn(ctx
, n
)));
264 r
->u
.idref
.id
= get_number(stack_topn(ctx
, n
));
267 r
->type
= EXPRVAL_INVALID
;
268 assert(is_number(stack_topn(ctx
, n
)));
269 r
->u
.hres
= get_number(stack_topn(ctx
, n
));
277 static inline BOOL
stack_pop_exprval(script_ctx_t
*ctx
, exprval_t
*r
)
279 BOOL ret
= stack_topn_exprval(ctx
, 0, r
);
284 static HRESULT
exprval_propput(script_ctx_t
*ctx
, exprval_t
*ref
, jsval_t v
)
287 case EXPRVAL_STACK_REF
: {
288 jsval_t
*r
= ctx
->stack
+ ref
->u
.off
;
290 return jsval_copy(v
, r
);
293 return disp_propput(ctx
, ref
->u
.idref
.disp
, ref
->u
.idref
.id
, v
);
300 static HRESULT
exprval_propget(script_ctx_t
*ctx
, exprval_t
*ref
, jsval_t
*r
)
303 case EXPRVAL_STACK_REF
:
304 return jsval_copy(ctx
->stack
[ref
->u
.off
], r
);
306 return disp_propget(ctx
, ref
->u
.idref
.disp
, ref
->u
.idref
.id
, r
);
313 static HRESULT
exprval_call(script_ctx_t
*ctx
, exprval_t
*ref
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
316 case EXPRVAL_STACK_REF
: {
317 jsval_t v
= ctx
->stack
[ref
->u
.off
];
319 if(!is_object_instance(v
)) {
320 FIXME("invoke %s\n", debugstr_jsval(v
));
324 return disp_call_value(ctx
, get_object(v
), NULL
, flags
, argc
, argv
, r
);
327 return disp_call(ctx
, ref
->u
.idref
.disp
, ref
->u
.idref
.id
, flags
, argc
, argv
, r
);
334 /* ECMA-262 3rd Edition 8.7.1 */
335 /* Steals input reference. */
336 static HRESULT
exprval_to_value(script_ctx_t
*ctx
, exprval_t
*ref
, jsval_t
*r
)
340 if(ref
->type
== EXPRVAL_JSVAL
) {
345 hres
= exprval_propget(ctx
, ref
, r
);
347 if(ref
->type
== EXPRVAL_IDREF
)
348 IDispatch_Release(ref
->u
.idref
.disp
);
352 static void exprval_release(exprval_t
*val
)
356 jsval_release(val
->u
.val
);
359 if(val
->u
.idref
.disp
)
360 IDispatch_Release(val
->u
.idref
.disp
);
362 case EXPRVAL_STACK_REF
:
363 case EXPRVAL_INVALID
:
368 static inline void exprval_set_exception(exprval_t
*val
, HRESULT hres
)
370 val
->type
= EXPRVAL_INVALID
;
374 static inline void exprval_set_disp_ref(exprval_t
*ref
, IDispatch
*obj
, DISPID id
)
376 ref
->type
= EXPRVAL_IDREF
;
377 IDispatch_AddRef(ref
->u
.idref
.disp
= obj
);
378 ref
->u
.idref
.id
= id
;
381 static inline jsval_t
steal_ret(call_frame_t
*frame
)
383 jsval_t r
= frame
->ret
;
384 frame
->ret
= jsval_undefined();
388 static inline void clear_ret(call_frame_t
*frame
)
390 jsval_release(steal_ret(frame
));
393 static HRESULT
scope_push(scope_chain_t
*scope
, jsdisp_t
*jsobj
, IDispatch
*obj
, scope_chain_t
**ret
)
395 scope_chain_t
*new_scope
;
397 new_scope
= heap_alloc(sizeof(scope_chain_t
));
399 return E_OUTOFMEMORY
;
403 IDispatch_AddRef(obj
);
404 new_scope
->jsobj
= jsobj
;
405 new_scope
->obj
= obj
;
406 new_scope
->frame
= NULL
;
407 new_scope
->next
= scope
? scope_addref(scope
) : NULL
;
413 static void scope_pop(scope_chain_t
**scope
)
422 void clear_ei(script_ctx_t
*ctx
)
424 memset(&ctx
->ei
.ei
, 0, sizeof(ctx
->ei
.ei
));
425 jsval_release(ctx
->ei
.val
);
426 ctx
->ei
.val
= jsval_undefined();
429 void scope_release(scope_chain_t
*scope
)
435 scope_release(scope
->next
);
437 IDispatch_Release(scope
->obj
);
441 static HRESULT
disp_get_id(script_ctx_t
*ctx
, IDispatch
*disp
, const WCHAR
*name
, BSTR name_bstr
, DWORD flags
, DISPID
*id
)
448 jsdisp
= iface_to_jsdisp(disp
);
450 hres
= jsdisp_get_id(jsdisp
, name
, flags
, id
);
451 jsdisp_release(jsdisp
);
458 bstr
= SysAllocString(name
);
460 return E_OUTOFMEMORY
;
464 hres
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
465 if(SUCCEEDED(hres
)) {
466 hres
= IDispatchEx_GetDispID(dispex
, bstr
, make_grfdex(ctx
, flags
|fdexNameCaseSensitive
), id
);
467 IDispatchEx_Release(dispex
);
469 TRACE("using IDispatch\n");
470 hres
= IDispatch_GetIDsOfNames(disp
, &IID_NULL
, &bstr
, 1, 0, id
);
473 if(name_bstr
!= bstr
)
478 static HRESULT
disp_cmp(IDispatch
*disp1
, IDispatch
*disp2
, BOOL
*ret
)
480 IObjectIdentity
*identity
;
481 IUnknown
*unk1
, *unk2
;
489 if(!disp1
|| !disp2
) {
494 hres
= IDispatch_QueryInterface(disp1
, &IID_IUnknown
, (void**)&unk1
);
498 hres
= IDispatch_QueryInterface(disp2
, &IID_IUnknown
, (void**)&unk2
);
500 IUnknown_Release(unk1
);
507 hres
= IUnknown_QueryInterface(unk1
, &IID_IObjectIdentity
, (void**)&identity
);
508 if(SUCCEEDED(hres
)) {
509 hres
= IObjectIdentity_IsEqualObject(identity
, unk2
);
510 IObjectIdentity_Release(identity
);
517 IUnknown_Release(unk1
);
518 IUnknown_Release(unk2
);
522 /* ECMA-262 3rd Edition 11.9.6 */
523 static HRESULT
equal2_values(jsval_t lval
, jsval_t rval
, BOOL
*ret
)
525 jsval_type_t type
= jsval_type(lval
);
529 if(type
!= jsval_type(rval
)) {
530 if(is_null_instance(lval
))
531 *ret
= is_null_instance(rval
);
543 return disp_cmp(get_object(lval
), get_object(rval
), ret
);
545 *ret
= jsstr_eq(get_string(lval
), get_string(rval
));
548 *ret
= get_number(lval
) == get_number(rval
);
551 *ret
= !get_bool(lval
) == !get_bool(rval
);
554 FIXME("VARIANT not implemented\n");
562 * Transfers local variables from stack to variable object.
563 * It's slow, so we want to avoid it as much as possible.
565 static HRESULT
detach_variable_object(script_ctx_t
*ctx
, call_frame_t
*frame
, BOOL from_release
)
570 if(!frame
->base_scope
|| !frame
->base_scope
->frame
)
573 TRACE("detaching %p\n", frame
);
575 assert(frame
== frame
->base_scope
->frame
);
576 assert(frame
->variable_obj
== frame
->base_scope
->jsobj
);
578 if(!from_release
&& !frame
->arguments_obj
) {
579 hres
= setup_arguments_object(ctx
, frame
);
584 frame
->base_scope
->frame
= NULL
;
586 for(i
= 0; i
< frame
->function
->locals_cnt
; i
++) {
587 hres
= jsdisp_propput_name(frame
->variable_obj
, frame
->function
->locals
[i
].name
,
588 ctx
->stack
[local_off(frame
, frame
->function
->locals
[i
].ref
)]);
596 static BOOL
lookup_global_members(script_ctx_t
*ctx
, BSTR identifier
, exprval_t
*ret
)
602 for(item
= ctx
->named_items
; item
; item
= item
->next
) {
603 if(item
->flags
& SCRIPTITEM_GLOBALMEMBERS
) {
604 hres
= disp_get_id(ctx
, item
->disp
, identifier
, identifier
, 0, &id
);
605 if(SUCCEEDED(hres
)) {
607 exprval_set_disp_ref(ret
, item
->disp
, id
);
616 static int local_ref_cmp(const void *key
, const void *ref
)
618 return strcmpW((const WCHAR
*)key
, ((const local_ref_t
*)ref
)->name
);
621 local_ref_t
*lookup_local(const function_code_t
*function
, const WCHAR
*identifier
)
623 return bsearch(identifier
, function
->locals
, function
->locals_cnt
, sizeof(*function
->locals
), local_ref_cmp
);
626 /* ECMA-262 3rd Edition 10.1.4 */
627 static HRESULT
identifier_eval(script_ctx_t
*ctx
, BSTR identifier
, exprval_t
*ret
)
629 scope_chain_t
*scope
;
634 TRACE("%s\n", debugstr_w(identifier
));
637 for(scope
= ctx
->call_ctx
->scope
; scope
; scope
= scope
->next
) {
639 function_code_t
*func
= scope
->frame
->function
;
640 local_ref_t
*ref
= lookup_local(func
, identifier
);
641 static const WCHAR argumentsW
[] = {'a','r','g','u','m','e','n','t','s',0};
644 ret
->type
= EXPRVAL_STACK_REF
;
645 ret
->u
.off
= local_off(scope
->frame
, ref
->ref
);
646 TRACE("returning ref %d for %d\n", ret
->u
.off
, ref
->ref
);
650 if(!strcmpW(identifier
, argumentsW
)) {
651 hres
= detach_variable_object(ctx
, scope
->frame
, FALSE
);
657 hres
= jsdisp_get_id(scope
->jsobj
, identifier
, fdexNameImplicit
, &id
);
659 hres
= disp_get_id(ctx
, scope
->obj
, identifier
, identifier
, fdexNameImplicit
, &id
);
660 if(SUCCEEDED(hres
)) {
661 exprval_set_disp_ref(ret
, scope
->obj
, id
);
667 hres
= jsdisp_get_id(ctx
->global
, identifier
, 0, &id
);
668 if(SUCCEEDED(hres
)) {
669 exprval_set_disp_ref(ret
, to_disp(ctx
->global
), id
);
673 for(item
= ctx
->named_items
; item
; item
= item
->next
) {
674 if((item
->flags
& SCRIPTITEM_ISVISIBLE
) && !strcmpW(item
->name
, identifier
)) {
681 hres
= IActiveScriptSite_GetItemInfo(ctx
->site
, identifier
,
682 SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
684 WARN("GetItemInfo failed: %08x\n", hres
);
688 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&item
->disp
);
689 IUnknown_Release(unk
);
691 WARN("object does not implement IDispatch\n");
696 IDispatch_AddRef(item
->disp
);
697 ret
->type
= EXPRVAL_JSVAL
;
698 ret
->u
.val
= jsval_disp(item
->disp
);
703 if(lookup_global_members(ctx
, identifier
, ret
))
706 exprval_set_exception(ret
, JS_E_UNDEFINED_VARIABLE
);
710 static inline BSTR
get_op_bstr(script_ctx_t
*ctx
, int i
)
712 call_frame_t
*frame
= ctx
->call_ctx
;
713 return frame
->bytecode
->instrs
[frame
->ip
].u
.arg
[i
].bstr
;
716 static inline unsigned get_op_uint(script_ctx_t
*ctx
, int i
)
718 call_frame_t
*frame
= ctx
->call_ctx
;
719 return frame
->bytecode
->instrs
[frame
->ip
].u
.arg
[i
].uint
;
722 static inline unsigned get_op_int(script_ctx_t
*ctx
, int i
)
724 call_frame_t
*frame
= ctx
->call_ctx
;
725 return frame
->bytecode
->instrs
[frame
->ip
].u
.arg
[i
].lng
;
728 static inline jsstr_t
*get_op_str(script_ctx_t
*ctx
, int i
)
730 call_frame_t
*frame
= ctx
->call_ctx
;
731 return frame
->bytecode
->instrs
[frame
->ip
].u
.arg
[i
].str
;
734 static inline double get_op_double(script_ctx_t
*ctx
)
736 call_frame_t
*frame
= ctx
->call_ctx
;
737 return frame
->bytecode
->instrs
[frame
->ip
].u
.dbl
;
740 static inline void jmp_next(script_ctx_t
*ctx
)
745 static inline void jmp_abs(script_ctx_t
*ctx
, unsigned dst
)
747 ctx
->call_ctx
->ip
= dst
;
750 /* ECMA-262 3rd Edition 12.6.4 */
751 static HRESULT
interp_forin(script_ctx_t
*ctx
)
753 const HRESULT arg
= get_op_uint(ctx
, 0);
754 IDispatch
*obj
= NULL
;
763 assert(is_number(stack_top(ctx
)));
764 id
= get_number(stack_top(ctx
));
766 if(!stack_topn_exprval(ctx
, 1, &prop_ref
)) {
767 FIXME("invalid ref: %08x\n", prop_ref
.u
.hres
);
771 if(is_object_instance(stack_topn(ctx
, 3)))
772 obj
= get_object(stack_topn(ctx
, 3));
775 hres
= IDispatch_QueryInterface(obj
, &IID_IDispatchEx
, (void**)&dispex
);
776 if(SUCCEEDED(hres
)) {
777 hres
= IDispatchEx_GetNextDispID(dispex
, fdexEnumDefault
, id
, &id
);
779 hres
= IDispatchEx_GetMemberName(dispex
, id
, &name
);
780 IDispatchEx_Release(dispex
);
784 TRACE("No IDispatchEx\n");
791 str
= jsstr_alloc_len(name
, SysStringLen(name
));
794 return E_OUTOFMEMORY
;
797 stack_push(ctx
, jsval_number(id
)); /* safe, just after pop() */
799 hres
= exprval_propput(ctx
, &prop_ref
, jsval_string(str
));
812 /* ECMA-262 3rd Edition 12.10 */
813 static HRESULT
interp_push_scope(script_ctx_t
*ctx
)
822 hres
= to_object(ctx
, v
, &disp
);
827 hres
= scope_push(ctx
->call_ctx
->scope
, to_jsdisp(disp
), disp
, &ctx
->call_ctx
->scope
);
828 IDispatch_Release(disp
);
832 /* ECMA-262 3rd Edition 12.10 */
833 static HRESULT
interp_pop_scope(script_ctx_t
*ctx
)
837 scope_pop(&ctx
->call_ctx
->scope
);
841 /* ECMA-262 3rd Edition 12.13 */
842 static HRESULT
interp_case(script_ctx_t
*ctx
)
844 const unsigned arg
= get_op_uint(ctx
, 0);
852 hres
= equal2_values(stack_top(ctx
), v
, &b
);
866 /* ECMA-262 3rd Edition 12.13 */
867 static HRESULT
interp_throw(script_ctx_t
*ctx
)
871 jsval_release(ctx
->ei
.val
);
872 ctx
->ei
.val
= stack_pop(ctx
);
873 return DISP_E_EXCEPTION
;
876 static HRESULT
interp_throw_ref(script_ctx_t
*ctx
)
878 const HRESULT arg
= get_op_uint(ctx
, 0);
880 TRACE("%08x\n", arg
);
882 return throw_reference_error(ctx
, arg
, NULL
);
885 static HRESULT
interp_throw_type(script_ctx_t
*ctx
)
887 const HRESULT hres
= get_op_uint(ctx
, 0);
888 jsstr_t
*str
= get_op_str(ctx
, 1);
891 TRACE("%08x %s\n", hres
, debugstr_jsstr(str
));
893 ptr
= jsstr_flatten(str
);
894 return ptr
? throw_type_error(ctx
, hres
, ptr
) : E_OUTOFMEMORY
;
897 /* ECMA-262 3rd Edition 12.14 */
898 static HRESULT
interp_push_except(script_ctx_t
*ctx
)
900 const unsigned catch_off
= get_op_uint(ctx
, 0);
901 const unsigned finally_off
= get_op_uint(ctx
, 1);
902 call_frame_t
*frame
= ctx
->call_ctx
;
903 except_frame_t
*except
;
907 except
= heap_alloc(sizeof(*except
));
909 return E_OUTOFMEMORY
;
911 except
->stack_top
= ctx
->stack_top
;
912 except
->scope
= frame
->scope
;
913 except
->catch_off
= catch_off
;
914 except
->finally_off
= finally_off
;
915 except
->next
= frame
->except_frame
;
916 frame
->except_frame
= except
;
920 /* ECMA-262 3rd Edition 12.14 */
921 static HRESULT
interp_pop_except(script_ctx_t
*ctx
)
923 const unsigned ret_off
= get_op_uint(ctx
, 0);
924 call_frame_t
*frame
= ctx
->call_ctx
;
925 except_frame_t
*except
;
926 unsigned finally_off
;
928 TRACE("%u\n", ret_off
);
930 except
= frame
->except_frame
;
931 assert(except
!= NULL
);
933 finally_off
= except
->finally_off
;
934 frame
->except_frame
= except
->next
;
940 hres
= stack_push(ctx
, jsval_number(ret_off
));
943 hres
= stack_push(ctx
, jsval_bool(TRUE
));
946 frame
->ip
= finally_off
;
954 /* ECMA-262 3rd Edition 12.14 */
955 static HRESULT
interp_end_finally(script_ctx_t
*ctx
)
957 call_frame_t
*frame
= ctx
->call_ctx
;
966 TRACE("passing exception\n");
968 ctx
->ei
.val
= stack_pop(ctx
);
969 return DISP_E_EXCEPTION
;
973 assert(is_number(v
));
974 frame
->ip
= get_number(v
);
978 static HRESULT
interp_enter_catch(script_ctx_t
*ctx
)
980 const BSTR ident
= get_op_bstr(ctx
, 0);
985 hres
= create_dispex(ctx
, NULL
, NULL
, &scope_obj
);
990 hres
= jsdisp_propput_name(scope_obj
, ident
, v
);
993 hres
= scope_push(ctx
->call_ctx
->scope
, scope_obj
, to_disp(scope_obj
), &ctx
->call_ctx
->scope
);
994 jsdisp_release(scope_obj
);
998 /* ECMA-262 3rd Edition 13 */
999 static HRESULT
interp_func(script_ctx_t
*ctx
)
1001 unsigned func_idx
= get_op_uint(ctx
, 0);
1002 call_frame_t
*frame
= ctx
->call_ctx
;
1006 TRACE("%d\n", func_idx
);
1008 hres
= create_source_function(ctx
, frame
->bytecode
, frame
->function
->funcs
+func_idx
,
1009 frame
->scope
, &dispex
);
1013 return stack_push(ctx
, jsval_obj(dispex
));
1016 /* ECMA-262 3rd Edition 11.2.1 */
1017 static HRESULT
interp_array(script_ctx_t
*ctx
)
1028 namev
= stack_pop(ctx
);
1030 hres
= stack_pop_object(ctx
, &obj
);
1032 jsval_release(namev
);
1036 hres
= to_flat_string(ctx
, namev
, &name_str
, &name
);
1037 jsval_release(namev
);
1039 IDispatch_Release(obj
);
1043 hres
= disp_get_id(ctx
, obj
, name
, NULL
, 0, &id
);
1044 jsstr_release(name_str
);
1045 if(SUCCEEDED(hres
)) {
1046 hres
= disp_propget(ctx
, obj
, id
, &v
);
1047 }else if(hres
== DISP_E_UNKNOWNNAME
) {
1048 v
= jsval_undefined();
1051 IDispatch_Release(obj
);
1055 return stack_push(ctx
, v
);
1058 /* ECMA-262 3rd Edition 11.2.1 */
1059 static HRESULT
interp_member(script_ctx_t
*ctx
)
1061 const BSTR arg
= get_op_bstr(ctx
, 0);
1069 hres
= stack_pop_object(ctx
, &obj
);
1073 hres
= disp_get_id(ctx
, obj
, arg
, arg
, 0, &id
);
1074 if(SUCCEEDED(hres
)) {
1075 hres
= disp_propget(ctx
, obj
, id
, &v
);
1076 }else if(hres
== DISP_E_UNKNOWNNAME
) {
1077 v
= jsval_undefined();
1080 IDispatch_Release(obj
);
1084 return stack_push(ctx
, v
);
1087 /* ECMA-262 3rd Edition 11.2.1 */
1088 static HRESULT
interp_memberid(script_ctx_t
*ctx
)
1090 const unsigned arg
= get_op_uint(ctx
, 0);
1091 jsval_t objv
, namev
;
1101 namev
= stack_pop(ctx
);
1102 objv
= stack_pop(ctx
);
1104 hres
= to_object(ctx
, objv
, &obj
);
1105 jsval_release(objv
);
1106 if(SUCCEEDED(hres
)) {
1107 hres
= to_flat_string(ctx
, namev
, &name_str
, &name
);
1109 IDispatch_Release(obj
);
1111 jsval_release(namev
);
1115 hres
= disp_get_id(ctx
, obj
, name
, NULL
, arg
, &id
);
1116 jsstr_release(name_str
);
1117 if(SUCCEEDED(hres
)) {
1118 ref
.type
= EXPRVAL_IDREF
;
1119 ref
.u
.idref
.disp
= obj
;
1120 ref
.u
.idref
.id
= id
;
1122 IDispatch_Release(obj
);
1123 if(hres
== DISP_E_UNKNOWNNAME
&& !(arg
& fdexNameEnsure
)) {
1124 exprval_set_exception(&ref
, JS_E_INVALID_PROPERTY
);
1127 ERR("failed %08x\n", hres
);
1132 return stack_push_exprval(ctx
, &ref
);
1135 /* ECMA-262 3rd Edition 11.2.1 */
1136 static HRESULT
interp_refval(script_ctx_t
*ctx
)
1144 if(!stack_topn_exprval(ctx
, 0, &ref
))
1145 return throw_reference_error(ctx
, JS_E_ILLEGAL_ASSIGN
, NULL
);
1147 hres
= exprval_propget(ctx
, &ref
, &v
);
1151 return stack_push(ctx
, v
);
1154 /* ECMA-262 3rd Edition 11.2.2 */
1155 static HRESULT
interp_new(script_ctx_t
*ctx
)
1157 const unsigned argc
= get_op_uint(ctx
, 0);
1158 call_frame_t
*frame
= ctx
->call_ctx
;
1161 TRACE("%d\n", argc
);
1163 constr
= stack_topn(ctx
, argc
);
1165 /* NOTE: Should use to_object here */
1168 return throw_type_error(ctx
, JS_E_OBJECT_EXPECTED
, NULL
);
1169 else if(!is_object_instance(constr
))
1170 return throw_type_error(ctx
, JS_E_INVALID_ACTION
, NULL
);
1171 else if(!get_object(constr
))
1172 return throw_type_error(ctx
, JS_E_INVALID_PROPERTY
, NULL
);
1175 return disp_call_value(ctx
, get_object(constr
), NULL
, DISPATCH_CONSTRUCT
| DISPATCH_JSCRIPT_CALLEREXECSSOURCE
,
1176 argc
, stack_args(ctx
, argc
), &frame
->ret
);
1179 /* ECMA-262 3rd Edition 11.2.3 */
1180 static HRESULT
interp_call(script_ctx_t
*ctx
)
1182 const unsigned argn
= get_op_uint(ctx
, 0);
1183 const int do_ret
= get_op_int(ctx
, 1);
1184 call_frame_t
*frame
= ctx
->call_ctx
;
1187 TRACE("%d %d\n", argn
, do_ret
);
1189 obj
= stack_topn(ctx
, argn
);
1190 if(!is_object_instance(obj
))
1191 return throw_type_error(ctx
, JS_E_INVALID_PROPERTY
, NULL
);
1194 return disp_call_value(ctx
, get_object(obj
), NULL
, DISPATCH_METHOD
| DISPATCH_JSCRIPT_CALLEREXECSSOURCE
,
1195 argn
, stack_args(ctx
, argn
), do_ret
? &frame
->ret
: NULL
);
1198 /* ECMA-262 3rd Edition 11.2.3 */
1199 static HRESULT
interp_call_member(script_ctx_t
*ctx
)
1201 const unsigned argn
= get_op_uint(ctx
, 0);
1202 const int do_ret
= get_op_int(ctx
, 1);
1203 call_frame_t
*frame
= ctx
->call_ctx
;
1206 TRACE("%d %d\n", argn
, do_ret
);
1208 if(!stack_topn_exprval(ctx
, argn
, &ref
))
1209 return throw_type_error(ctx
, ref
.u
.hres
, NULL
);
1212 return exprval_call(ctx
, &ref
, DISPATCH_METHOD
| DISPATCH_JSCRIPT_CALLEREXECSSOURCE
,
1213 argn
, stack_args(ctx
, argn
), do_ret
? &frame
->ret
: NULL
);
1216 /* ECMA-262 3rd Edition 11.1.1 */
1217 static HRESULT
interp_this(script_ctx_t
*ctx
)
1219 call_frame_t
*frame
= ctx
->call_ctx
;
1223 IDispatch_AddRef(frame
->this_obj
);
1224 return stack_push(ctx
, jsval_disp(frame
->this_obj
));
1227 static HRESULT
interp_identifier_ref(script_ctx_t
*ctx
, BSTR identifier
, unsigned flags
)
1232 hres
= identifier_eval(ctx
, identifier
, &exprval
);
1236 if(exprval
.type
== EXPRVAL_INVALID
&& (flags
& fdexNameEnsure
)) {
1239 hres
= jsdisp_get_id(ctx
->global
, identifier
, fdexNameEnsure
, &id
);
1243 exprval_set_disp_ref(&exprval
, to_disp(ctx
->global
), id
);
1246 if(exprval
.type
== EXPRVAL_JSVAL
|| exprval
.type
== EXPRVAL_INVALID
) {
1247 WARN("invalid ref\n");
1248 exprval_release(&exprval
);
1249 exprval_set_exception(&exprval
, JS_E_OBJECT_EXPECTED
);
1252 return stack_push_exprval(ctx
, &exprval
);
1255 static HRESULT
identifier_value(script_ctx_t
*ctx
, BSTR identifier
)
1261 hres
= identifier_eval(ctx
, identifier
, &exprval
);
1265 if(exprval
.type
== EXPRVAL_INVALID
)
1266 return throw_type_error(ctx
, exprval
.u
.hres
, identifier
);
1268 hres
= exprval_to_value(ctx
, &exprval
, &v
);
1272 return stack_push(ctx
, v
);
1275 static HRESULT
interp_local_ref(script_ctx_t
*ctx
)
1277 const int arg
= get_op_int(ctx
, 0);
1278 const unsigned flags
= get_op_uint(ctx
, 1);
1279 call_frame_t
*frame
= ctx
->call_ctx
;
1284 if(!frame
->base_scope
|| !frame
->base_scope
->frame
)
1285 return interp_identifier_ref(ctx
, local_name(frame
, arg
), flags
);
1287 ref
.type
= EXPRVAL_STACK_REF
;
1288 ref
.u
.off
= local_off(frame
, arg
);
1289 return stack_push_exprval(ctx
, &ref
);
1292 static HRESULT
interp_local(script_ctx_t
*ctx
)
1294 const int arg
= get_op_int(ctx
, 0);
1295 call_frame_t
*frame
= ctx
->call_ctx
;
1301 if(!frame
->base_scope
|| !frame
->base_scope
->frame
)
1302 return identifier_value(ctx
, local_name(frame
, arg
));
1304 hres
= jsval_copy(ctx
->stack
[local_off(frame
, arg
)], ©
);
1308 return stack_push(ctx
, copy
);
1311 /* ECMA-262 3rd Edition 10.1.4 */
1312 static HRESULT
interp_ident(script_ctx_t
*ctx
)
1314 const BSTR arg
= get_op_bstr(ctx
, 0);
1316 TRACE("%s\n", debugstr_w(arg
));
1318 return identifier_value(ctx
, arg
);
1321 /* ECMA-262 3rd Edition 10.1.4 */
1322 static HRESULT
interp_identid(script_ctx_t
*ctx
)
1324 const BSTR arg
= get_op_bstr(ctx
, 0);
1325 const unsigned flags
= get_op_uint(ctx
, 1);
1327 TRACE("%s %x\n", debugstr_w(arg
), flags
);
1329 return interp_identifier_ref(ctx
, arg
, flags
);
1332 /* ECMA-262 3rd Edition 7.8.1 */
1333 static HRESULT
interp_null(script_ctx_t
*ctx
)
1337 return stack_push(ctx
, jsval_null());
1340 /* ECMA-262 3rd Edition 7.8.2 */
1341 static HRESULT
interp_bool(script_ctx_t
*ctx
)
1343 const int arg
= get_op_int(ctx
, 0);
1345 TRACE("%s\n", arg
? "true" : "false");
1347 return stack_push(ctx
, jsval_bool(arg
));
1350 /* ECMA-262 3rd Edition 7.8.3 */
1351 static HRESULT
interp_int(script_ctx_t
*ctx
)
1353 const int arg
= get_op_int(ctx
, 0);
1357 return stack_push(ctx
, jsval_number(arg
));
1360 /* ECMA-262 3rd Edition 7.8.3 */
1361 static HRESULT
interp_double(script_ctx_t
*ctx
)
1363 const double arg
= get_op_double(ctx
);
1365 TRACE("%lf\n", arg
);
1367 return stack_push(ctx
, jsval_number(arg
));
1370 /* ECMA-262 3rd Edition 7.8.4 */
1371 static HRESULT
interp_str(script_ctx_t
*ctx
)
1373 jsstr_t
*str
= get_op_str(ctx
, 0);
1375 TRACE("%s\n", debugstr_jsstr(str
));
1377 return stack_push(ctx
, jsval_string(jsstr_addref(str
)));
1380 /* ECMA-262 3rd Edition 7.8 */
1381 static HRESULT
interp_regexp(script_ctx_t
*ctx
)
1383 jsstr_t
*source
= get_op_str(ctx
, 0);
1384 const unsigned flags
= get_op_uint(ctx
, 1);
1388 TRACE("%s %x\n", debugstr_jsstr(source
), flags
);
1390 hres
= create_regexp(ctx
, source
, flags
, ®exp
);
1394 return stack_push(ctx
, jsval_obj(regexp
));
1397 /* ECMA-262 3rd Edition 11.1.4 */
1398 static HRESULT
interp_carray(script_ctx_t
*ctx
)
1400 const unsigned arg
= get_op_uint(ctx
, 0);
1408 hres
= create_array(ctx
, arg
, &array
);
1414 val
= stack_pop(ctx
);
1415 hres
= jsdisp_propput_idx(array
, i
, val
);
1418 jsdisp_release(array
);
1423 return stack_push(ctx
, jsval_obj(array
));
1426 /* ECMA-262 3rd Edition 11.1.5 */
1427 static HRESULT
interp_new_obj(script_ctx_t
*ctx
)
1434 hres
= create_object(ctx
, NULL
, &obj
);
1438 return stack_push(ctx
, jsval_obj(obj
));
1441 /* ECMA-262 3rd Edition 11.1.5 */
1442 static HRESULT
interp_obj_prop(script_ctx_t
*ctx
)
1444 const BSTR name
= get_op_bstr(ctx
, 0);
1449 TRACE("%s\n", debugstr_w(name
));
1451 val
= stack_pop(ctx
);
1453 assert(is_object_instance(stack_top(ctx
)));
1454 obj
= as_jsdisp(get_object(stack_top(ctx
)));
1456 hres
= jsdisp_propput_name(obj
, name
, val
);
1461 /* ECMA-262 3rd Edition 11.11 */
1462 static HRESULT
interp_cnd_nz(script_ctx_t
*ctx
)
1464 const unsigned arg
= get_op_uint(ctx
, 0);
1470 hres
= to_boolean(stack_top(ctx
), &b
);
1483 /* ECMA-262 3rd Edition 11.11 */
1484 static HRESULT
interp_cnd_z(script_ctx_t
*ctx
)
1486 const unsigned arg
= get_op_uint(ctx
, 0);
1492 hres
= to_boolean(stack_top(ctx
), &b
);
1505 /* ECMA-262 3rd Edition 11.10 */
1506 static HRESULT
interp_or(script_ctx_t
*ctx
)
1513 hres
= stack_pop_int(ctx
, &r
);
1517 hres
= stack_pop_int(ctx
, &l
);
1521 return stack_push(ctx
, jsval_number(l
|r
));
1524 /* ECMA-262 3rd Edition 11.10 */
1525 static HRESULT
interp_xor(script_ctx_t
*ctx
)
1532 hres
= stack_pop_int(ctx
, &r
);
1536 hres
= stack_pop_int(ctx
, &l
);
1540 return stack_push(ctx
, jsval_number(l
^r
));
1543 /* ECMA-262 3rd Edition 11.10 */
1544 static HRESULT
interp_and(script_ctx_t
*ctx
)
1551 hres
= stack_pop_int(ctx
, &r
);
1555 hres
= stack_pop_int(ctx
, &l
);
1559 return stack_push(ctx
, jsval_number(l
&r
));
1562 /* ECMA-262 3rd Edition 11.8.6 */
1563 static HRESULT
interp_instanceof(script_ctx_t
*ctx
)
1565 jsdisp_t
*obj
, *iter
, *tmp
= NULL
;
1570 static const WCHAR prototypeW
[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
1573 if(!is_object_instance(v
) || !get_object(v
)) {
1575 return throw_type_error(ctx
, JS_E_FUNCTION_EXPECTED
, NULL
);
1578 obj
= iface_to_jsdisp(get_object(v
));
1579 IDispatch_Release(get_object(v
));
1581 FIXME("non-jsdisp objects not supported\n");
1585 if(is_class(obj
, JSCLASS_FUNCTION
)) {
1586 hres
= jsdisp_propget_name(obj
, prototypeW
, &prot
);
1588 hres
= throw_type_error(ctx
, JS_E_FUNCTION_EXPECTED
, NULL
);
1590 jsdisp_release(obj
);
1596 if(is_object_instance(prot
)) {
1597 if(is_object_instance(v
))
1598 tmp
= iface_to_jsdisp(get_object(v
));
1599 for(iter
= tmp
; !ret
&& iter
; iter
= iter
->prototype
) {
1600 hres
= disp_cmp(get_object(prot
), to_disp(iter
), &ret
);
1606 jsdisp_release(tmp
);
1608 FIXME("prototype is not an object\n");
1612 jsval_release(prot
);
1617 return stack_push(ctx
, jsval_bool(ret
));
1620 /* ECMA-262 3rd Edition 11.8.7 */
1621 static HRESULT
interp_in(script_ctx_t
*ctx
)
1632 obj
= stack_pop(ctx
);
1633 if(!is_object_instance(obj
) || !get_object(obj
)) {
1635 return throw_type_error(ctx
, JS_E_OBJECT_EXPECTED
, NULL
);
1639 hres
= to_flat_string(ctx
, v
, &jsstr
, &str
);
1642 IDispatch_Release(get_object(obj
));
1646 hres
= disp_get_id(ctx
, get_object(obj
), str
, NULL
, 0, &id
);
1647 IDispatch_Release(get_object(obj
));
1648 jsstr_release(jsstr
);
1651 else if(hres
== DISP_E_UNKNOWNNAME
)
1656 return stack_push(ctx
, jsval_bool(ret
));
1659 /* ECMA-262 3rd Edition 11.6.1 */
1660 static HRESULT
add_eval(script_ctx_t
*ctx
, jsval_t lval
, jsval_t rval
, jsval_t
*ret
)
1665 hres
= to_primitive(ctx
, lval
, &l
, NO_HINT
);
1669 hres
= to_primitive(ctx
, rval
, &r
, NO_HINT
);
1675 if(is_string(l
) || is_string(r
)) {
1676 jsstr_t
*lstr
, *rstr
= NULL
;
1678 hres
= to_string(ctx
, l
, &lstr
);
1680 hres
= to_string(ctx
, r
, &rstr
);
1682 if(SUCCEEDED(hres
)) {
1685 ret_str
= jsstr_concat(lstr
, rstr
);
1687 *ret
= jsval_string(ret_str
);
1689 hres
= E_OUTOFMEMORY
;
1692 jsstr_release(lstr
);
1694 jsstr_release(rstr
);
1698 hres
= to_number(ctx
, l
, &nl
);
1699 if(SUCCEEDED(hres
)) {
1700 hres
= to_number(ctx
, r
, &nr
);
1702 *ret
= jsval_number(nl
+nr
);
1711 /* ECMA-262 3rd Edition 11.6.1 */
1712 static HRESULT
interp_add(script_ctx_t
*ctx
)
1720 TRACE("%s + %s\n", debugstr_jsval(l
), debugstr_jsval(r
));
1722 hres
= add_eval(ctx
, l
, r
, &ret
);
1728 return stack_push(ctx
, ret
);
1731 /* ECMA-262 3rd Edition 11.6.2 */
1732 static HRESULT
interp_sub(script_ctx_t
*ctx
)
1739 hres
= stack_pop_number(ctx
, &r
);
1743 hres
= stack_pop_number(ctx
, &l
);
1747 return stack_push(ctx
, jsval_number(l
-r
));
1750 /* ECMA-262 3rd Edition 11.5.1 */
1751 static HRESULT
interp_mul(script_ctx_t
*ctx
)
1758 hres
= stack_pop_number(ctx
, &r
);
1762 hres
= stack_pop_number(ctx
, &l
);
1766 return stack_push(ctx
, jsval_number(l
*r
));
1769 /* ECMA-262 3rd Edition 11.5.2 */
1770 static HRESULT
interp_div(script_ctx_t
*ctx
)
1777 hres
= stack_pop_number(ctx
, &r
);
1781 hres
= stack_pop_number(ctx
, &l
);
1785 return stack_push(ctx
, jsval_number(l
/r
));
1788 /* ECMA-262 3rd Edition 11.5.3 */
1789 static HRESULT
interp_mod(script_ctx_t
*ctx
)
1796 hres
= stack_pop_number(ctx
, &r
);
1800 hres
= stack_pop_number(ctx
, &l
);
1804 return stack_push(ctx
, jsval_number(fmod(l
, r
)));
1807 /* ECMA-262 3rd Edition 11.4.2 */
1808 static HRESULT
interp_delete(script_ctx_t
*ctx
)
1810 jsval_t objv
, namev
;
1818 namev
= stack_pop(ctx
);
1819 objv
= stack_pop(ctx
);
1821 hres
= to_object(ctx
, objv
, &obj
);
1822 jsval_release(objv
);
1824 jsval_release(namev
);
1828 hres
= to_string(ctx
, namev
, &name
);
1829 jsval_release(namev
);
1831 IDispatch_Release(obj
);
1835 hres
= disp_delete_name(ctx
, obj
, name
, &ret
);
1836 IDispatch_Release(obj
);
1837 jsstr_release(name
);
1841 return stack_push(ctx
, jsval_bool(ret
));
1844 /* ECMA-262 3rd Edition 11.4.2 */
1845 static HRESULT
interp_delete_ident(script_ctx_t
*ctx
)
1847 const BSTR arg
= get_op_bstr(ctx
, 0);
1852 TRACE("%s\n", debugstr_w(arg
));
1854 hres
= identifier_eval(ctx
, arg
, &exprval
);
1858 switch(exprval
.type
) {
1859 case EXPRVAL_STACK_REF
:
1863 hres
= disp_delete(exprval
.u
.idref
.disp
, exprval
.u
.idref
.id
, &ret
);
1864 IDispatch_Release(exprval
.u
.idref
.disp
);
1868 case EXPRVAL_INVALID
:
1872 FIXME("Unsupported exprval\n");
1873 exprval_release(&exprval
);
1878 return stack_push(ctx
, jsval_bool(ret
));
1881 /* ECMA-262 3rd Edition 11.4.2 */
1882 static HRESULT
interp_void(script_ctx_t
*ctx
)
1887 return stack_push(ctx
, jsval_undefined());
1890 /* ECMA-262 3rd Edition 11.4.3 */
1891 static HRESULT
typeof_string(jsval_t v
, const WCHAR
**ret
)
1893 switch(jsval_type(v
)) {
1903 if(get_object(v
) && (dispex
= iface_to_jsdisp(get_object(v
)))) {
1904 *ret
= is_class(dispex
, JSCLASS_FUNCTION
) ? functionW
: objectW
;
1905 jsdisp_release(dispex
);
1921 FIXME("unhandled variant %s\n", debugstr_variant(get_variant(v
)));
1928 /* ECMA-262 3rd Edition 11.4.3 */
1929 static HRESULT
interp_typeofid(script_ctx_t
*ctx
)
1938 if(!stack_pop_exprval(ctx
, &ref
))
1939 return stack_push(ctx
, jsval_string(jsstr_undefined()));
1941 hres
= exprval_propget(ctx
, &ref
, &v
);
1942 exprval_release(&ref
);
1944 return stack_push_string(ctx
, unknownW
);
1946 hres
= typeof_string(v
, &ret
);
1951 return stack_push_string(ctx
, ret
);
1954 /* ECMA-262 3rd Edition 11.4.3 */
1955 static HRESULT
interp_typeofident(script_ctx_t
*ctx
)
1957 const BSTR arg
= get_op_bstr(ctx
, 0);
1963 TRACE("%s\n", debugstr_w(arg
));
1965 hres
= identifier_eval(ctx
, arg
, &exprval
);
1969 if(exprval
.type
== EXPRVAL_INVALID
)
1970 return stack_push(ctx
, jsval_string(jsstr_undefined()));
1972 hres
= exprval_to_value(ctx
, &exprval
, &v
);
1976 hres
= typeof_string(v
, &ret
);
1981 return stack_push_string(ctx
, ret
);
1984 /* ECMA-262 3rd Edition 11.4.3 */
1985 static HRESULT
interp_typeof(script_ctx_t
*ctx
)
1994 hres
= typeof_string(v
, &ret
);
1999 return stack_push_string(ctx
, ret
);
2002 /* ECMA-262 3rd Edition 11.4.7 */
2003 static HRESULT
interp_minus(script_ctx_t
*ctx
)
2010 hres
= stack_pop_number(ctx
, &n
);
2014 return stack_push(ctx
, jsval_number(-n
));
2017 /* ECMA-262 3rd Edition 11.4.6 */
2018 static HRESULT
interp_tonum(script_ctx_t
*ctx
)
2027 hres
= to_number(ctx
, v
, &n
);
2032 return stack_push(ctx
, jsval_number(n
));
2035 /* ECMA-262 3rd Edition 11.3.1 */
2036 static HRESULT
interp_postinc(script_ctx_t
*ctx
)
2038 const int arg
= get_op_int(ctx
, 0);
2045 if(!stack_pop_exprval(ctx
, &ref
))
2046 return throw_type_error(ctx
, JS_E_OBJECT_EXPECTED
, NULL
);
2048 hres
= exprval_propget(ctx
, &ref
, &v
);
2049 if(SUCCEEDED(hres
)) {
2052 hres
= to_number(ctx
, v
, &n
);
2054 hres
= exprval_propput(ctx
, &ref
, jsval_number(n
+(double)arg
));
2058 exprval_release(&ref
);
2062 return stack_push(ctx
, v
);
2065 /* ECMA-262 3rd Edition 11.4.4, 11.4.5 */
2066 static HRESULT
interp_preinc(script_ctx_t
*ctx
)
2068 const int arg
= get_op_int(ctx
, 0);
2076 if(!stack_pop_exprval(ctx
, &ref
))
2077 return throw_type_error(ctx
, JS_E_OBJECT_EXPECTED
, NULL
);
2079 hres
= exprval_propget(ctx
, &ref
, &v
);
2080 if(SUCCEEDED(hres
)) {
2083 hres
= to_number(ctx
, v
, &n
);
2085 if(SUCCEEDED(hres
)) {
2086 ret
= n
+(double)arg
;
2087 hres
= exprval_propput(ctx
, &ref
, jsval_number(ret
));
2090 exprval_release(&ref
);
2094 return stack_push(ctx
, jsval_number(ret
));
2097 /* ECMA-262 3rd Edition 11.9.3 */
2098 static HRESULT
equal_values(script_ctx_t
*ctx
, jsval_t lval
, jsval_t rval
, BOOL
*ret
)
2100 if(jsval_type(lval
) == jsval_type(rval
) || (is_number(lval
) && is_number(rval
)))
2101 return equal2_values(lval
, rval
, ret
);
2103 /* FIXME: NULL disps should be handled in more general way */
2104 if(is_object_instance(lval
) && !get_object(lval
))
2105 return equal_values(ctx
, jsval_null(), rval
, ret
);
2106 if(is_object_instance(rval
) && !get_object(rval
))
2107 return equal_values(ctx
, lval
, jsval_null(), ret
);
2109 if((is_null(lval
) && is_undefined(rval
)) || (is_undefined(lval
) && is_null(rval
))) {
2114 if(is_string(lval
) && is_number(rval
)) {
2118 hres
= to_number(ctx
, lval
, &n
);
2122 /* FIXME: optimize */
2123 return equal_values(ctx
, jsval_number(n
), rval
, ret
);
2126 if(is_string(rval
) && is_number(lval
)) {
2130 hres
= to_number(ctx
, rval
, &n
);
2134 /* FIXME: optimize */
2135 return equal_values(ctx
, lval
, jsval_number(n
), ret
);
2139 return equal_values(ctx
, lval
, jsval_number(get_bool(rval
) ? 1 : 0), ret
);
2142 return equal_values(ctx
, jsval_number(get_bool(lval
) ? 1 : 0), rval
, ret
);
2145 if(is_object_instance(rval
) && (is_string(lval
) || is_number(lval
))) {
2149 hres
= to_primitive(ctx
, rval
, &prim
, NO_HINT
);
2153 hres
= equal_values(ctx
, lval
, prim
, ret
);
2154 jsval_release(prim
);
2159 if(is_object_instance(lval
) && (is_string(rval
) || is_number(rval
))) {
2163 hres
= to_primitive(ctx
, lval
, &prim
, NO_HINT
);
2167 hres
= equal_values(ctx
, prim
, rval
, ret
);
2168 jsval_release(prim
);
2177 /* ECMA-262 3rd Edition 11.9.1 */
2178 static HRESULT
interp_eq(script_ctx_t
*ctx
)
2187 TRACE("%s == %s\n", debugstr_jsval(l
), debugstr_jsval(r
));
2189 hres
= equal_values(ctx
, l
, r
, &b
);
2195 return stack_push(ctx
, jsval_bool(b
));
2198 /* ECMA-262 3rd Edition 11.9.2 */
2199 static HRESULT
interp_neq(script_ctx_t
*ctx
)
2208 TRACE("%s != %s\n", debugstr_jsval(l
), debugstr_jsval(r
));
2210 hres
= equal_values(ctx
, l
, r
, &b
);
2216 return stack_push(ctx
, jsval_bool(!b
));
2219 /* ECMA-262 3rd Edition 11.9.4 */
2220 static HRESULT
interp_eq2(script_ctx_t
*ctx
)
2229 TRACE("%s === %s\n", debugstr_jsval(l
), debugstr_jsval(r
));
2231 hres
= equal2_values(r
, l
, &b
);
2237 return stack_push(ctx
, jsval_bool(b
));
2240 /* ECMA-262 3rd Edition 11.9.5 */
2241 static HRESULT
interp_neq2(script_ctx_t
*ctx
)
2252 hres
= equal2_values(r
, l
, &b
);
2258 return stack_push(ctx
, jsval_bool(!b
));
2261 /* ECMA-262 3rd Edition 11.8.5 */
2262 static HRESULT
less_eval(script_ctx_t
*ctx
, jsval_t lval
, jsval_t rval
, BOOL greater
, BOOL
*ret
)
2268 hres
= to_primitive(ctx
, lval
, &l
, NO_HINT
);
2272 hres
= to_primitive(ctx
, rval
, &r
, NO_HINT
);
2278 if(is_string(l
) && is_string(r
)) {
2279 *ret
= (jsstr_cmp(get_string(l
), get_string(r
)) < 0) ^ greater
;
2280 jsstr_release(get_string(l
));
2281 jsstr_release(get_string(r
));
2285 hres
= to_number(ctx
, l
, &ln
);
2288 hres
= to_number(ctx
, r
, &rn
);
2293 *ret
= !isnan(ln
) && !isnan(rn
) && ((ln
< rn
) ^ greater
);
2297 /* ECMA-262 3rd Edition 11.8.1 */
2298 static HRESULT
interp_lt(script_ctx_t
*ctx
)
2307 TRACE("%s < %s\n", debugstr_jsval(l
), debugstr_jsval(r
));
2309 hres
= less_eval(ctx
, l
, r
, FALSE
, &b
);
2315 return stack_push(ctx
, jsval_bool(b
));
2318 /* ECMA-262 3rd Edition 11.8.1 */
2319 static HRESULT
interp_lteq(script_ctx_t
*ctx
)
2328 TRACE("%s <= %s\n", debugstr_jsval(l
), debugstr_jsval(r
));
2330 hres
= less_eval(ctx
, r
, l
, TRUE
, &b
);
2336 return stack_push(ctx
, jsval_bool(b
));
2339 /* ECMA-262 3rd Edition 11.8.2 */
2340 static HRESULT
interp_gt(script_ctx_t
*ctx
)
2349 TRACE("%s > %s\n", debugstr_jsval(l
), debugstr_jsval(r
));
2351 hres
= less_eval(ctx
, r
, l
, FALSE
, &b
);
2357 return stack_push(ctx
, jsval_bool(b
));
2360 /* ECMA-262 3rd Edition 11.8.4 */
2361 static HRESULT
interp_gteq(script_ctx_t
*ctx
)
2370 TRACE("%s >= %s\n", debugstr_jsval(l
), debugstr_jsval(r
));
2372 hres
= less_eval(ctx
, l
, r
, TRUE
, &b
);
2378 return stack_push(ctx
, jsval_bool(b
));
2381 /* ECMA-262 3rd Edition 11.4.8 */
2382 static HRESULT
interp_bneg(script_ctx_t
*ctx
)
2391 hres
= to_int32(ctx
, v
, &i
);
2396 return stack_push(ctx
, jsval_number(~i
));
2399 /* ECMA-262 3rd Edition 11.4.9 */
2400 static HRESULT
interp_neg(script_ctx_t
*ctx
)
2409 hres
= to_boolean(v
, &b
);
2414 return stack_push(ctx
, jsval_bool(!b
));
2417 /* ECMA-262 3rd Edition 11.7.1 */
2418 static HRESULT
interp_lshift(script_ctx_t
*ctx
)
2424 hres
= stack_pop_uint(ctx
, &r
);
2428 hres
= stack_pop_int(ctx
, &l
);
2432 return stack_push(ctx
, jsval_number(l
<< (r
&0x1f)));
2435 /* ECMA-262 3rd Edition 11.7.2 */
2436 static HRESULT
interp_rshift(script_ctx_t
*ctx
)
2442 hres
= stack_pop_uint(ctx
, &r
);
2446 hres
= stack_pop_int(ctx
, &l
);
2450 return stack_push(ctx
, jsval_number(l
>> (r
&0x1f)));
2453 /* ECMA-262 3rd Edition 11.7.3 */
2454 static HRESULT
interp_rshift2(script_ctx_t
*ctx
)
2459 hres
= stack_pop_uint(ctx
, &r
);
2463 hres
= stack_pop_uint(ctx
, &l
);
2467 return stack_push(ctx
, jsval_number(l
>> (r
&0x1f)));
2470 /* ECMA-262 3rd Edition 11.13.1 */
2471 static HRESULT
interp_assign(script_ctx_t
*ctx
)
2481 if(!stack_pop_exprval(ctx
, &ref
)) {
2483 return throw_reference_error(ctx
, JS_E_ILLEGAL_ASSIGN
, NULL
);
2486 hres
= exprval_propput(ctx
, &ref
, v
);
2487 exprval_release(&ref
);
2493 return stack_push(ctx
, v
);
2496 /* JScript extension */
2497 static HRESULT
interp_assign_call(script_ctx_t
*ctx
)
2499 const unsigned argc
= get_op_uint(ctx
, 0);
2504 TRACE("%u\n", argc
);
2506 if(!stack_topn_exprval(ctx
, argc
+1, &ref
))
2507 return throw_reference_error(ctx
, JS_E_ILLEGAL_ASSIGN
, NULL
);
2509 hres
= exprval_call(ctx
, &ref
, DISPATCH_PROPERTYPUT
, argc
+1, stack_args(ctx
, argc
+1), NULL
);
2514 stack_popn(ctx
, argc
+2);
2515 return stack_push(ctx
, v
);
2518 static HRESULT
interp_undefined(script_ctx_t
*ctx
)
2522 return stack_push(ctx
, jsval_undefined());
2525 static HRESULT
interp_jmp(script_ctx_t
*ctx
)
2527 const unsigned arg
= get_op_uint(ctx
, 0);
2535 static HRESULT
interp_jmp_z(script_ctx_t
*ctx
)
2537 const unsigned arg
= get_op_uint(ctx
, 0);
2545 hres
= to_boolean(v
, &b
);
2557 static HRESULT
interp_pop(script_ctx_t
*ctx
)
2559 const unsigned arg
= get_op_uint(ctx
, 0);
2563 stack_popn(ctx
, arg
);
2567 static HRESULT
interp_ret(script_ctx_t
*ctx
)
2569 const unsigned clear_ret
= get_op_uint(ctx
, 0);
2570 call_frame_t
*frame
= ctx
->call_ctx
;
2575 jsval_release(steal_ret(frame
));
2577 if((frame
->flags
& EXEC_CONSTRUCTOR
) && !is_object_instance(frame
->ret
)) {
2578 jsval_release(frame
->ret
);
2579 IDispatch_AddRef(frame
->this_obj
);
2580 frame
->ret
= jsval_disp(frame
->this_obj
);
2587 static HRESULT
interp_setret(script_ctx_t
*ctx
)
2589 call_frame_t
*frame
= ctx
->call_ctx
;
2593 jsval_release(frame
->ret
);
2594 frame
->ret
= stack_pop(ctx
);
2598 static HRESULT
interp_push_ret(script_ctx_t
*ctx
)
2600 call_frame_t
*frame
= ctx
->call_ctx
;
2605 hres
= stack_push(ctx
, frame
->ret
);
2607 frame
->ret
= jsval_undefined();
2611 typedef HRESULT (*op_func_t
)(script_ctx_t
*);
2613 static const op_func_t op_funcs
[] = {
2614 #define X(x,a,b,c) interp_##x,
2619 static const unsigned op_move
[] = {
2620 #define X(a,x,b,c) x,
2625 static void pop_call_frame(script_ctx_t
*ctx
)
2627 call_frame_t
*frame
= ctx
->call_ctx
;
2629 frame
->stack_base
-= frame
->pop_locals
+ frame
->pop_variables
;
2631 assert(frame
->scope
== frame
->base_scope
);
2633 /* If current scope will be kept alive, we need to transfer local variables to its variable object. */
2634 if(frame
->scope
&& frame
->scope
->ref
> 1) {
2635 HRESULT hres
= detach_variable_object(ctx
, frame
, TRUE
);
2637 ERR("Failed to detach variable object: %08x\n", hres
);
2640 if(frame
->arguments_obj
)
2641 detach_arguments_object(frame
->arguments_obj
);
2643 scope_release(frame
->scope
);
2645 if(frame
->pop_variables
)
2646 stack_popn(ctx
, frame
->pop_variables
);
2647 stack_popn(ctx
, frame
->pop_locals
);
2649 ctx
->call_ctx
= frame
->prev_frame
;
2651 if(frame
->function_instance
)
2652 jsdisp_release(frame
->function_instance
);
2653 if(frame
->variable_obj
)
2654 jsdisp_release(frame
->variable_obj
);
2656 IDispatch_Release(frame
->this_obj
);
2657 jsval_release(frame
->ret
);
2658 release_bytecode(frame
->bytecode
);
2662 static void print_backtrace(script_ctx_t
*ctx
)
2664 unsigned depth
= 0, i
;
2665 call_frame_t
*frame
;
2667 for(frame
= ctx
->call_ctx
; frame
; frame
= frame
->prev_frame
) {
2668 WARN("%u\t", depth
);
2671 if(frame
->this_obj
&& frame
->this_obj
!= to_disp(ctx
->global
) && frame
->this_obj
!= ctx
->host_global
)
2672 WARN("%p->", frame
->this_obj
);
2673 WARN("%s(", frame
->function
->name
? debugstr_w(frame
->function
->name
) : "[unnamed]");
2674 if(frame
->base_scope
&& frame
->base_scope
->frame
) {
2675 for(i
=0; i
< frame
->argc
; i
++) {
2676 if(i
< frame
->function
->param_cnt
)
2677 WARN("%s%s=%s", i
? ", " : "", debugstr_w(frame
->function
->params
[i
]),
2678 debugstr_jsval(ctx
->stack
[local_off(frame
, -i
-1)]));
2680 WARN("%s%s", i
? ", " : "", debugstr_jsval(ctx
->stack
[local_off(frame
, -i
-1)]));
2683 WARN("[detached frame]");
2687 if(!(frame
->flags
& EXEC_RETURN_TO_INTERP
)) {
2688 WARN("%u\t[native code]\n", depth
);
2694 static HRESULT
unwind_exception(script_ctx_t
*ctx
, HRESULT exception_hres
)
2696 except_frame_t
*except_frame
;
2697 call_frame_t
*frame
;
2702 if(WARN_ON(jscript
)) {
2703 jsdisp_t
*error_obj
;
2706 static const WCHAR messageW
[] = {'m','e','s','s','a','g','e',0};
2708 WARN("Exception %08x %s", exception_hres
, debugstr_jsval(ctx
->ei
.val
));
2709 if(jsval_type(ctx
->ei
.val
) == JSV_OBJECT
) {
2710 error_obj
= to_jsdisp(get_object(ctx
->ei
.val
));
2712 hres
= jsdisp_propget_name(error_obj
, messageW
, &msg
);
2713 if(SUCCEEDED(hres
)) {
2714 WARN(" (message %s)", debugstr_jsval(msg
));
2721 print_backtrace(ctx
);
2724 for(frame
= ctx
->call_ctx
; !frame
->except_frame
; frame
= ctx
->call_ctx
) {
2727 while(frame
->scope
!= frame
->base_scope
)
2728 scope_pop(&frame
->scope
);
2730 stack_popn(ctx
, ctx
->stack_top
-frame
->stack_base
);
2732 flags
= frame
->flags
;
2733 pop_call_frame(ctx
);
2734 if(!(flags
& EXEC_RETURN_TO_INTERP
))
2735 return exception_hres
;
2738 except_frame
= frame
->except_frame
;
2739 catch_off
= except_frame
->catch_off
;
2741 assert(except_frame
->stack_top
<= ctx
->stack_top
);
2742 stack_popn(ctx
, ctx
->stack_top
- except_frame
->stack_top
);
2744 while(except_frame
->scope
!= frame
->scope
)
2745 scope_pop(&frame
->scope
);
2747 frame
->ip
= catch_off
? catch_off
: except_frame
->finally_off
;
2748 if(catch_off
) assert(frame
->bytecode
->instrs
[frame
->ip
].op
== OP_enter_catch
);
2750 except_val
= ctx
->ei
.val
;
2751 ctx
->ei
.val
= jsval_undefined();
2754 /* keep current except_frame if we're entering catch block with finally block associated */
2755 if(catch_off
&& except_frame
->finally_off
) {
2756 except_frame
->catch_off
= 0;
2758 frame
->except_frame
= except_frame
->next
;
2759 heap_free(except_frame
);
2762 hres
= stack_push(ctx
, except_val
);
2767 hres
= stack_push(ctx
, jsval_bool(FALSE
));
2771 static HRESULT
enter_bytecode(script_ctx_t
*ctx
, jsval_t
*r
)
2773 call_frame_t
*frame
;
2775 HRESULT hres
= S_OK
;
2780 frame
= ctx
->call_ctx
;
2781 op
= frame
->bytecode
->instrs
[frame
->ip
].op
;
2782 hres
= op_funcs
[op
](ctx
);
2784 hres
= unwind_exception(ctx
, hres
);
2787 }else if(frame
->ip
== -1) {
2788 const DWORD return_to_interp
= frame
->flags
& EXEC_RETURN_TO_INTERP
;
2790 assert(ctx
->stack_top
== frame
->stack_base
);
2791 assert(frame
->scope
== frame
->base_scope
);
2793 if(return_to_interp
) {
2794 clear_ret(frame
->prev_frame
);
2795 frame
->prev_frame
->ret
= steal_ret(frame
);
2797 *r
= steal_ret(frame
);
2799 pop_call_frame(ctx
);
2800 if(!return_to_interp
)
2803 frame
->ip
+= op_move
[op
];
2810 static HRESULT
bind_event_target(script_ctx_t
*ctx
, function_code_t
*func
, jsdisp_t
*func_obj
)
2812 IBindEventHandler
*target
;
2818 hres
= identifier_eval(ctx
, func
->event_target
, &exprval
);
2822 hres
= exprval_to_value(ctx
, &exprval
, &v
);
2826 if(!is_object_instance(v
)) {
2827 FIXME("Can't bind to %s\n", debugstr_jsval(v
));
2831 disp
= get_object(v
);
2832 hres
= IDispatch_QueryInterface(disp
, &IID_IBindEventHandler
, (void**)&target
);
2833 if(SUCCEEDED(hres
)) {
2834 hres
= IBindEventHandler_BindHandler(target
, func
->name
, (IDispatch
*)&func_obj
->IDispatchEx_iface
);
2835 IBindEventHandler_Release(target
);
2837 WARN("BindEvent failed: %08x\n", hres
);
2839 FIXME("No IBindEventHandler, not yet supported binding\n");
2842 IDispatch_Release(disp
);
2846 static HRESULT
setup_scope(script_ctx_t
*ctx
, call_frame_t
*frame
, scope_chain_t
*scope_chain
, jsdisp_t
*variable_object
, unsigned argc
, jsval_t
*argv
)
2848 const unsigned orig_stack
= ctx
->stack_top
;
2849 scope_chain_t
*scope
;
2854 /* If arguments are already on the stack, we may use them. */
2855 if(argv
+ argc
== ctx
->stack
+ ctx
->stack_top
) {
2856 frame
->arguments_off
= argv
- ctx
->stack
;
2859 frame
->arguments_off
= ctx
->stack_top
;
2860 for(i
= 0; i
< argc
; i
++) {
2861 hres
= jsval_copy(argv
[i
], &v
);
2863 hres
= stack_push(ctx
, v
);
2871 /* If fewer than declared arguments were passed, fill remaining with undefined value. */
2872 for(; i
< frame
->function
->param_cnt
; i
++) {
2873 hres
= stack_push(ctx
, jsval_undefined());
2875 stack_popn(ctx
, ctx
->stack_top
- orig_stack
);
2880 frame
->pop_locals
= ctx
->stack_top
- orig_stack
;
2882 frame
->variables_off
= ctx
->stack_top
;
2884 for(i
= 0; i
< frame
->function
->var_cnt
; i
++) {
2885 hres
= stack_push(ctx
, jsval_undefined());
2887 stack_popn(ctx
, ctx
->stack_top
- orig_stack
);
2892 frame
->pop_variables
= i
;
2894 hres
= scope_push(scope_chain
, variable_object
, to_disp(variable_object
), &scope
);
2896 stack_popn(ctx
, ctx
->stack_top
- orig_stack
);
2900 for(i
= 0; i
< frame
->function
->func_cnt
; i
++) {
2901 if(frame
->function
->funcs
[i
].name
&& !frame
->function
->funcs
[i
].event_target
) {
2905 hres
= create_source_function(ctx
, frame
->bytecode
, frame
->function
->funcs
+i
, scope
, &func_obj
);
2907 stack_popn(ctx
, ctx
->stack_top
- orig_stack
);
2908 scope_release(scope
);
2912 off
= local_off(frame
, frame
->function
->funcs
[i
].local_ref
);
2913 jsval_release(ctx
->stack
[off
]);
2914 ctx
->stack
[off
] = jsval_obj(func_obj
);
2918 scope
->frame
= frame
;
2919 frame
->base_scope
= frame
->scope
= scope
;
2923 HRESULT
exec_source(script_ctx_t
*ctx
, DWORD flags
, bytecode_t
*bytecode
, function_code_t
*function
, scope_chain_t
*scope
,
2924 IDispatch
*this_obj
, jsdisp_t
*function_instance
, jsdisp_t
*variable_obj
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
2926 call_frame_t
*frame
;
2930 for(i
= 0; i
< function
->func_cnt
; i
++) {
2933 if(!function
->funcs
[i
].event_target
)
2936 hres
= create_source_function(ctx
, bytecode
, function
->funcs
+i
, scope
, &func_obj
);
2940 hres
= bind_event_target(ctx
, function
->funcs
+i
, func_obj
);
2941 jsdisp_release(func_obj
);
2946 if(flags
& (EXEC_GLOBAL
| EXEC_EVAL
)) {
2947 for(i
=0; i
< function
->var_cnt
; i
++) {
2948 TRACE("[%d] %s %d\n", i
, debugstr_w(function
->variables
[i
].name
), function
->variables
[i
].func_id
);
2949 if(function
->variables
[i
].func_id
!= -1) {
2952 hres
= create_source_function(ctx
, bytecode
, function
->funcs
+function
->variables
[i
].func_id
, scope
, &func_obj
);
2956 hres
= jsdisp_propput_name(variable_obj
, function
->variables
[i
].name
, jsval_obj(func_obj
));
2957 jsdisp_release(func_obj
);
2958 }else if(!(flags
& EXEC_GLOBAL
) || !lookup_global_members(ctx
, function
->variables
[i
].name
, NULL
)) {
2961 hres
= jsdisp_get_id(variable_obj
, function
->variables
[i
].name
, fdexNameEnsure
, &id
);
2968 /* ECMA-262 3rd Edition 11.2.3.7 */
2972 jsthis
= iface_to_jsdisp(this_obj
);
2974 if(jsthis
->builtin_info
->class == JSCLASS_GLOBAL
|| jsthis
->builtin_info
->class == JSCLASS_NONE
)
2976 jsdisp_release(jsthis
);
2980 if(ctx
->call_ctx
&& (flags
& EXEC_EVAL
)) {
2981 hres
= detach_variable_object(ctx
, ctx
->call_ctx
, FALSE
);
2986 frame
= heap_alloc_zero(sizeof(*frame
));
2988 return E_OUTOFMEMORY
;
2990 frame
->function
= function
;
2991 frame
->ret
= jsval_undefined();
2993 frame
->bytecode
= bytecode_addref(bytecode
);
2995 if(!(flags
& (EXEC_GLOBAL
|EXEC_EVAL
))) {
2996 hres
= setup_scope(ctx
, frame
, scope
, variable_obj
, argc
, argv
);
2998 release_bytecode(frame
->bytecode
);
3003 frame
->base_scope
= frame
->scope
= scope_addref(scope
);
3006 frame
->ip
= function
->instr_off
;
3007 frame
->stack_base
= ctx
->stack_top
;
3009 frame
->this_obj
= this_obj
;
3010 else if(ctx
->host_global
)
3011 frame
->this_obj
= ctx
->host_global
;
3013 frame
->this_obj
= to_disp(ctx
->global
);
3014 IDispatch_AddRef(frame
->this_obj
);
3016 if(function_instance
)
3017 frame
->function_instance
= jsdisp_addref(function_instance
);
3019 frame
->flags
= flags
;
3020 frame
->variable_obj
= jsdisp_addref(variable_obj
);
3022 frame
->prev_frame
= ctx
->call_ctx
;
3023 ctx
->call_ctx
= frame
;
3025 if(flags
& EXEC_RETURN_TO_INTERP
) {
3027 * We're called directly from interpreter, so we may just setup call frame and return.
3028 * Already running interpreter will take care of execution.
3031 *r
= jsval_undefined();
3035 return enter_bytecode(ctx
, r
);