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
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
30 builtin_invoke_t value_proc
;
33 scope_chain_t
*scope_chain
;
35 function_code_t
*func_code
;
41 FunctionInstance
*function
;
45 static inline FunctionInstance
*function_from_jsdisp(jsdisp_t
*jsdisp
)
47 return CONTAINING_RECORD(jsdisp
, FunctionInstance
, dispex
);
50 static inline FunctionInstance
*function_from_vdisp(vdisp_t
*vdisp
)
52 return function_from_jsdisp(vdisp
->u
.jsdisp
);
55 static inline FunctionInstance
*function_this(vdisp_t
*jsthis
)
57 return is_vclass(jsthis
, JSCLASS_FUNCTION
) ? function_from_vdisp(jsthis
) : NULL
;
60 static const WCHAR prototypeW
[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
62 static const WCHAR lengthW
[] = {'l','e','n','g','t','h',0};
63 static const WCHAR toStringW
[] = {'t','o','S','t','r','i','n','g',0};
64 static const WCHAR applyW
[] = {'a','p','p','l','y',0};
65 static const WCHAR callW
[] = {'c','a','l','l',0};
66 static const WCHAR argumentsW
[] = {'a','r','g','u','m','e','n','t','s',0};
68 static HRESULT
init_parameters(jsdisp_t
*var_disp
, FunctionInstance
*function
, unsigned argc
, jsval_t
*argv
)
73 for(i
=0; i
< function
->func_code
->param_cnt
; i
++) {
74 hres
= jsdisp_propput_name(var_disp
, function
->func_code
->params
[i
],
75 i
< argc
? argv
[i
] : jsval_undefined());
83 static HRESULT
Arguments_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
90 static void Arguments_destructor(jsdisp_t
*jsdisp
)
92 ArgumentsInstance
*arguments
= (ArgumentsInstance
*)jsdisp
;
94 jsdisp_release(&arguments
->function
->dispex
);
95 jsdisp_release(arguments
->var_obj
);
99 static unsigned Arguments_idx_length(jsdisp_t
*jsdisp
)
101 ArgumentsInstance
*arguments
= (ArgumentsInstance
*)jsdisp
;
102 return arguments
->function
->length
;
105 static HRESULT
Arguments_idx_get(jsdisp_t
*jsdisp
, unsigned idx
, jsval_t
*res
)
107 ArgumentsInstance
*arguments
= (ArgumentsInstance
*)jsdisp
;
109 TRACE("%p[%u]\n", arguments
, idx
);
111 /* FIXME: Accessing by name won't work for duplicated argument names */
112 return jsdisp_propget_name(arguments
->var_obj
, arguments
->function
->func_code
->params
[idx
], res
);
115 static HRESULT
Arguments_idx_put(jsdisp_t
*jsdisp
, unsigned idx
, jsval_t val
)
117 ArgumentsInstance
*arguments
= (ArgumentsInstance
*)jsdisp
;
119 TRACE("%p[%u] = %s\n", arguments
, idx
, debugstr_jsval(val
));
121 /* FIXME: Accessing by name won't work for duplicated argument names */
122 return jsdisp_propput_name(arguments
->var_obj
, arguments
->function
->func_code
->params
[idx
], val
);
125 static const builtin_info_t Arguments_info
= {
127 {NULL
, Arguments_value
, 0},
129 Arguments_destructor
,
131 Arguments_idx_length
,
136 static HRESULT
create_arguments(script_ctx_t
*ctx
, FunctionInstance
*calee
, jsdisp_t
*var_obj
,
137 unsigned argc
, jsval_t
*argv
, jsdisp_t
**ret
)
139 ArgumentsInstance
*args
;
143 static const WCHAR caleeW
[] = {'c','a','l','l','e','e',0};
145 args
= heap_alloc_zero(sizeof(*args
));
147 return E_OUTOFMEMORY
;
149 hres
= init_dispex_from_constr(&args
->jsdisp
, ctx
, &Arguments_info
, ctx
->object_constr
);
155 jsdisp_addref(&calee
->dispex
);
156 args
->function
= calee
;
157 args
->var_obj
= jsdisp_addref(var_obj
);
159 /* Store unnamed arguments directly in arguments object */
160 for(i
= calee
->length
; i
< argc
; i
++) {
163 static const WCHAR formatW
[] = {'%','d',0};
165 sprintfW(buf
, formatW
, i
);
166 hres
= jsdisp_propput_dontenum(&args
->jsdisp
, buf
, argv
[i
]);
171 if(SUCCEEDED(hres
)) {
172 hres
= jsdisp_propput_dontenum(&args
->jsdisp
, lengthW
, jsval_number(argc
));
174 hres
= jsdisp_propput_dontenum(&args
->jsdisp
, caleeW
, jsval_disp(to_disp(&calee
->dispex
)));
177 jsdisp_release(&args
->jsdisp
);
181 *ret
= &args
->jsdisp
;
185 static HRESULT
create_var_disp(script_ctx_t
*ctx
, FunctionInstance
*function
, unsigned argc
, jsval_t
*argv
, jsdisp_t
**ret
)
190 hres
= create_dispex(ctx
, NULL
, NULL
, &var_disp
);
194 hres
= init_parameters(var_disp
, function
, argc
, argv
);
196 jsdisp_release(var_disp
);
204 static HRESULT
invoke_source(script_ctx_t
*ctx
, FunctionInstance
*function
, IDispatch
*this_obj
, unsigned argc
, jsval_t
*argv
,
205 BOOL is_constructor
, BOOL caller_execs_source
, jsval_t
*r
)
207 jsdisp_t
*var_disp
, *arg_disp
;
208 scope_chain_t
*scope
;
211 if(ctx
->state
== SCRIPTSTATE_UNINITIALIZED
|| ctx
->state
== SCRIPTSTATE_CLOSED
) {
212 WARN("Script engine state does not allow running code.\n");
216 if(!function
->func_code
) {
217 FIXME("no source\n");
221 hres
= create_var_disp(ctx
, function
, argc
, argv
, &var_disp
);
225 hres
= create_arguments(ctx
, function
, var_disp
, argc
, argv
, &arg_disp
);
227 jsdisp_release(var_disp
);
231 hres
= jsdisp_propput(var_disp
, argumentsW
, PROPF_DONTDELETE
, jsval_obj(arg_disp
));
233 jsdisp_release(arg_disp
);
234 jsdisp_release(var_disp
);
238 hres
= scope_push(function
->scope_chain
, var_disp
, to_disp(var_disp
), &scope
);
239 if(SUCCEEDED(hres
)) {
240 DWORD exec_flags
= 0;
242 if(caller_execs_source
)
243 exec_flags
|= EXEC_RETURN_TO_INTERP
;
245 exec_flags
|= EXEC_CONSTRUCTOR
;
246 hres
= exec_source(ctx
, exec_flags
, function
->code
, function
->func_code
, scope
, this_obj
,
247 &function
->dispex
, var_disp
, arg_disp
, r
);
249 scope_release(scope
);
252 jsdisp_release(arg_disp
);
253 jsdisp_release(var_disp
);
257 static HRESULT
invoke_value_proc(script_ctx_t
*ctx
, FunctionInstance
*function
, IDispatch
*this_disp
, WORD flags
,
258 unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
264 set_disp(&vthis
, this_disp
);
265 else if(ctx
->host_global
)
266 set_disp(&vthis
, ctx
->host_global
);
268 set_jsdisp(&vthis
, ctx
->global
);
270 hres
= function
->value_proc(ctx
, &vthis
, flags
, argc
, argv
, r
);
272 vdisp_release(&vthis
);
276 static HRESULT
call_function(script_ctx_t
*ctx
, FunctionInstance
*function
, IDispatch
*this_obj
,
277 unsigned argc
, jsval_t
*argv
, BOOL caller_execs_source
, jsval_t
*r
)
279 if(function
->value_proc
)
280 return invoke_value_proc(ctx
, function
, this_obj
, DISPATCH_METHOD
, argc
, argv
, r
);
282 return invoke_source(ctx
, function
, this_obj
, argc
, argv
, FALSE
, caller_execs_source
, r
);
285 static HRESULT
function_to_string(FunctionInstance
*function
, jsstr_t
**ret
)
289 static const WCHAR native_prefixW
[] = {'\n','f','u','n','c','t','i','o','n',' '};
290 static const WCHAR native_suffixW
[] =
291 {'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
293 if(function
->value_proc
) {
297 name_len
= strlenW(function
->name
);
298 ptr
= jsstr_alloc_buf((sizeof(native_prefixW
)+sizeof(native_suffixW
))/sizeof(WCHAR
) + name_len
, &str
);
300 return E_OUTOFMEMORY
;
302 memcpy(ptr
, native_prefixW
, sizeof(native_prefixW
));
303 memcpy(ptr
+= sizeof(native_prefixW
)/sizeof(WCHAR
), function
->name
, name_len
*sizeof(WCHAR
));
304 memcpy(ptr
+ name_len
, native_suffixW
, sizeof(native_suffixW
));
306 str
= jsstr_alloc_len(function
->func_code
->source
, function
->func_code
->source_len
);
308 return E_OUTOFMEMORY
;
315 HRESULT
Function_invoke(jsdisp_t
*func_this
, IDispatch
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
317 const BOOL caller_execs_source
= (flags
& DISPATCH_JSCRIPT_CALLEREXECSSOURCE
) != 0;
318 FunctionInstance
*function
;
320 TRACE("func %p this %p\n", func_this
, jsthis
);
322 assert(is_class(func_this
, JSCLASS_FUNCTION
));
323 function
= (FunctionInstance
*)func_this
;
325 flags
&= ~DISPATCH_JSCRIPT_INTERNAL_MASK
;
326 if(function
->value_proc
)
327 return invoke_value_proc(function
->dispex
.ctx
, function
, jsthis
, flags
, argc
, argv
, r
);
329 if(flags
== DISPATCH_CONSTRUCT
) {
333 hres
= create_object(function
->dispex
.ctx
, &function
->dispex
, &this_obj
);
337 hres
= invoke_source(function
->dispex
.ctx
, function
, to_disp(this_obj
), argc
, argv
, TRUE
, caller_execs_source
, r
);
338 jsdisp_release(this_obj
);
342 assert(flags
== DISPATCH_METHOD
);
343 return invoke_source(function
->dispex
.ctx
, function
, jsthis
, argc
, argv
, FALSE
, caller_execs_source
, r
);
346 static HRESULT
Function_get_length(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
348 TRACE("%p\n", jsthis
);
350 *r
= jsval_number(function_from_jsdisp(jsthis
)->length
);
354 static HRESULT
Function_set_length(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t value
)
360 static HRESULT
Function_toString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
363 FunctionInstance
*function
;
369 if(!(function
= function_this(jsthis
)))
370 return throw_type_error(ctx
, JS_E_FUNCTION_EXPECTED
, NULL
);
372 hres
= function_to_string(function
, &str
);
377 *r
= jsval_string(str
);
383 static HRESULT
array_to_args(script_ctx_t
*ctx
, jsdisp_t
*arg_array
, unsigned *argc
, jsval_t
**ret
)
389 hres
= jsdisp_propget_name(arg_array
, lengthW
, &val
);
393 hres
= to_uint32(ctx
, val
, &length
);
398 argv
= heap_alloc(length
* sizeof(*argv
));
400 return E_OUTOFMEMORY
;
402 for(i
=0; i
<length
; i
++) {
403 hres
= jsdisp_get_idx(arg_array
, i
, argv
+i
);
404 if(hres
== DISP_E_UNKNOWNNAME
) {
405 argv
[i
] = jsval_undefined();
406 }else if(FAILED(hres
)) {
408 jsval_release(argv
[i
]);
419 static HRESULT
Function_apply(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
421 FunctionInstance
*function
;
422 jsval_t
*args
= NULL
;
424 IDispatch
*this_obj
= NULL
;
429 if(!(function
= function_this(jsthis
)))
430 return throw_type_error(ctx
, JS_E_FUNCTION_EXPECTED
, NULL
);
433 if(!is_undefined(argv
[0]) && !is_null(argv
[0])) {
434 hres
= to_object(ctx
, argv
[0], &this_obj
);
441 jsdisp_t
*arg_array
= NULL
;
443 if(is_object_instance(argv
[1])) {
444 arg_array
= iface_to_jsdisp((IUnknown
*)get_object(argv
[1]));
446 (!is_class(arg_array
, JSCLASS_ARRAY
) && !is_class(arg_array
, JSCLASS_ARGUMENTS
) )) {
447 jsdisp_release(arg_array
);
453 hres
= array_to_args(ctx
, arg_array
, &cnt
, &args
);
454 jsdisp_release(arg_array
);
456 FIXME("throw TypeError\n");
462 hres
= call_function(ctx
, function
, this_obj
, cnt
, args
, (flags
& DISPATCH_JSCRIPT_CALLEREXECSSOURCE
) != 0, r
);
465 IDispatch_Release(this_obj
);
466 for(i
=0; i
< cnt
; i
++)
467 jsval_release(args
[i
]);
472 static HRESULT
Function_call(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
475 FunctionInstance
*function
;
476 IDispatch
*this_obj
= NULL
;
482 if(!(function
= function_this(jsthis
)))
483 return throw_type_error(ctx
, JS_E_FUNCTION_EXPECTED
, NULL
);
486 if(!is_undefined(argv
[0]) && !is_null(argv
[0])) {
487 hres
= to_object(ctx
, argv
[0], &this_obj
);
495 hres
= call_function(ctx
, function
, this_obj
, cnt
, argv
+1, (flags
& DISPATCH_JSCRIPT_CALLEREXECSSOURCE
) != 0, r
);
498 IDispatch_Release(this_obj
);
502 HRESULT
Function_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
505 FunctionInstance
*function
;
509 if(!is_vclass(jsthis
, JSCLASS_FUNCTION
)) {
510 ERR("dispex is not a function\n");
514 function
= (FunctionInstance
*)jsthis
->u
.jsdisp
;
516 assert(function
->value_proc
!= NULL
);
517 return invoke_value_proc(ctx
, function
, NULL
, flags
, argc
, argv
, r
);
520 HRESULT
Function_get_value(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
527 hres
= function_to_string(function_from_jsdisp(jsthis
), &str
);
531 *r
= jsval_string(str
);
535 static HRESULT
Function_get_arguments(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
537 FunctionInstance
*function
= function_from_jsdisp(jsthis
);
542 for(frame
= ctx
->call_ctx
; frame
; frame
= frame
->prev_frame
) {
543 if(frame
->function_instance
== &function
->dispex
) {
544 *r
= jsval_obj(jsdisp_addref(frame
->arguments_obj
));
553 static void Function_destructor(jsdisp_t
*dispex
)
555 FunctionInstance
*This
= (FunctionInstance
*)dispex
;
558 release_bytecode(This
->code
);
559 if(This
->scope_chain
)
560 scope_release(This
->scope_chain
);
564 static const builtin_prop_t Function_props
[] = {
565 {applyW
, Function_apply
, PROPF_METHOD
|2},
566 {argumentsW
, NULL
, 0, Function_get_arguments
, builtin_set_const
},
567 {callW
, Function_call
, PROPF_METHOD
|1},
568 {lengthW
, NULL
, 0, Function_get_length
, Function_set_length
},
569 {toStringW
, Function_toString
, PROPF_METHOD
}
572 static const builtin_info_t Function_info
= {
574 DEFAULT_FUNCTION_VALUE
,
575 sizeof(Function_props
)/sizeof(*Function_props
),
581 static const builtin_prop_t FunctionInst_props
[] = {
582 {argumentsW
, NULL
, 0, Function_get_arguments
, builtin_set_const
},
583 {lengthW
, NULL
, 0, Function_get_length
, Function_set_length
}
586 static const builtin_info_t FunctionInst_info
= {
588 DEFAULT_FUNCTION_VALUE
,
589 sizeof(FunctionInst_props
)/sizeof(*FunctionInst_props
),
595 static HRESULT
create_function(script_ctx_t
*ctx
, const builtin_info_t
*builtin_info
, DWORD flags
,
596 BOOL funcprot
, jsdisp_t
*prototype
, FunctionInstance
**ret
)
598 FunctionInstance
*function
;
601 function
= heap_alloc_zero(sizeof(FunctionInstance
));
603 return E_OUTOFMEMORY
;
606 hres
= init_dispex(&function
->dispex
, ctx
, builtin_info
, prototype
);
607 else if(builtin_info
)
608 hres
= init_dispex_from_constr(&function
->dispex
, ctx
, builtin_info
, ctx
->function_constr
);
610 hres
= init_dispex_from_constr(&function
->dispex
, ctx
, &FunctionInst_info
, ctx
->function_constr
);
616 function
->flags
= flags
;
617 function
->length
= flags
& PROPF_ARGMASK
;
623 static inline HRESULT
set_prototype(script_ctx_t
*ctx
, jsdisp_t
*dispex
, jsdisp_t
*prototype
)
625 return jsdisp_propput_dontenum(dispex
, prototypeW
, jsval_obj(prototype
));
628 HRESULT
create_builtin_function(script_ctx_t
*ctx
, builtin_invoke_t value_proc
, const WCHAR
*name
,
629 const builtin_info_t
*builtin_info
, DWORD flags
, jsdisp_t
*prototype
, jsdisp_t
**ret
)
631 FunctionInstance
*function
;
634 hres
= create_function(ctx
, builtin_info
, flags
, FALSE
, NULL
, &function
);
639 hres
= jsdisp_propput_const(&function
->dispex
, lengthW
, jsval_number(function
->length
));
641 hres
= set_prototype(ctx
, &function
->dispex
, prototype
);
643 jsdisp_release(&function
->dispex
);
647 function
->value_proc
= value_proc
;
648 function
->name
= name
;
650 *ret
= &function
->dispex
;
654 static HRESULT
set_constructor_prop(script_ctx_t
*ctx
, jsdisp_t
*constr
, jsdisp_t
*prot
)
656 static const WCHAR constructorW
[] = {'c','o','n','s','t','r','u','c','t','o','r',0};
658 return jsdisp_propput_dontenum(prot
, constructorW
, jsval_obj(constr
));
661 HRESULT
create_builtin_constructor(script_ctx_t
*ctx
, builtin_invoke_t value_proc
, const WCHAR
*name
,
662 const builtin_info_t
*builtin_info
, DWORD flags
, jsdisp_t
*prototype
, jsdisp_t
**ret
)
667 hres
= create_builtin_function(ctx
, value_proc
, name
, builtin_info
, flags
, prototype
, &constr
);
671 hres
= set_constructor_prop(ctx
, constr
, prototype
);
673 jsdisp_release(constr
);
681 HRESULT
create_source_function(script_ctx_t
*ctx
, bytecode_t
*code
, function_code_t
*func_code
,
682 scope_chain_t
*scope_chain
, jsdisp_t
**ret
)
684 FunctionInstance
*function
;
688 hres
= create_object(ctx
, NULL
, &prototype
);
692 hres
= create_function(ctx
, NULL
, PROPF_CONSTR
, FALSE
, NULL
, &function
);
693 if(SUCCEEDED(hres
)) {
694 hres
= set_prototype(ctx
, &function
->dispex
, prototype
);
696 hres
= set_constructor_prop(ctx
, &function
->dispex
, prototype
);
698 jsdisp_release(&function
->dispex
);
700 jsdisp_release(prototype
);
705 scope_addref(scope_chain
);
706 function
->scope_chain
= scope_chain
;
709 bytecode_addref(code
);
710 function
->code
= code
;
711 function
->func_code
= func_code
;
712 function
->length
= function
->func_code
->param_cnt
;
714 *ret
= &function
->dispex
;
718 static HRESULT
construct_function(script_ctx_t
*ctx
, unsigned argc
, jsval_t
*argv
, IDispatch
**ret
)
720 WCHAR
*str
= NULL
, *ptr
;
721 unsigned len
= 0, i
= 0;
724 jsstr_t
**params
= NULL
;
728 static const WCHAR function_anonymousW
[] = {'f','u','n','c','t','i','o','n',' ','a','n','o','n','y','m','o','u','s','('};
729 static const WCHAR function_beginW
[] = {')',' ','{','\n'};
730 static const WCHAR function_endW
[] = {'\n','}',0};
733 params
= heap_alloc(argc
*sizeof(*params
));
735 return E_OUTOFMEMORY
;
738 len
= (argc
-2)*2; /* separating commas */
739 for(i
=0; i
< argc
; i
++) {
740 hres
= to_string(ctx
, argv
[i
], params
+i
);
743 len
+= jsstr_length(params
[i
]);
747 if(SUCCEEDED(hres
)) {
748 len
+= (sizeof(function_anonymousW
) + sizeof(function_beginW
) + sizeof(function_endW
)) / sizeof(WCHAR
);
749 str
= heap_alloc(len
*sizeof(WCHAR
));
751 memcpy(str
, function_anonymousW
, sizeof(function_anonymousW
));
752 ptr
= str
+ sizeof(function_anonymousW
)/sizeof(WCHAR
);
755 ptr
+= jsstr_flush(params
[j
], ptr
);
762 memcpy(ptr
, function_beginW
, sizeof(function_beginW
));
763 ptr
+= sizeof(function_beginW
)/sizeof(WCHAR
);
765 ptr
+= jsstr_flush(params
[argc
-1], ptr
);
766 memcpy(ptr
, function_endW
, sizeof(function_endW
));
768 TRACE("%s\n", debugstr_w(str
));
770 hres
= E_OUTOFMEMORY
;
775 jsstr_release(params
[--i
]);
780 hres
= compile_script(ctx
, str
, NULL
, NULL
, FALSE
, FALSE
, &code
);
785 if(code
->global_code
.func_cnt
!= 1 || code
->global_code
.var_cnt
) {
786 ERR("Invalid parser result!\n");
787 release_bytecode(code
);
791 hres
= create_source_function(ctx
, code
, code
->global_code
.funcs
, NULL
, &function
);
792 release_bytecode(code
);
796 *ret
= to_disp(function
);
800 static HRESULT
FunctionConstr_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
808 case DISPATCH_METHOD
:
809 case DISPATCH_CONSTRUCT
: {
812 hres
= construct_function(ctx
, argc
, argv
, &ret
);
816 *r
= jsval_disp(ret
);
820 FIXME("unimplemented flags %x\n", flags
);
827 static HRESULT
FunctionProt_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
834 HRESULT
init_function_constr(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
)
836 FunctionInstance
*prot
, *constr
;
839 static const WCHAR FunctionW
[] = {'F','u','n','c','t','i','o','n',0};
841 hres
= create_function(ctx
, &Function_info
, PROPF_CONSTR
, TRUE
, object_prototype
, &prot
);
845 prot
->value_proc
= FunctionProt_value
;
846 prot
->name
= prototypeW
;
848 hres
= create_function(ctx
, &FunctionInst_info
, PROPF_CONSTR
|1, TRUE
, &prot
->dispex
, &constr
);
849 if(SUCCEEDED(hres
)) {
850 constr
->value_proc
= FunctionConstr_value
;
851 constr
->name
= FunctionW
;
852 hres
= set_prototype(ctx
, &constr
->dispex
, &prot
->dispex
);
854 hres
= set_constructor_prop(ctx
, &constr
->dispex
, &prot
->dispex
);
856 jsdisp_release(&constr
->dispex
);
858 jsdisp_release(&prot
->dispex
);
862 ctx
->function_constr
= &constr
->dispex
;