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
;
42 FunctionInstance
*function
;
46 static inline FunctionInstance
*function_from_jsdisp(jsdisp_t
*jsdisp
)
48 return CONTAINING_RECORD(jsdisp
, FunctionInstance
, dispex
);
51 static inline FunctionInstance
*function_from_vdisp(vdisp_t
*vdisp
)
53 return function_from_jsdisp(vdisp
->u
.jsdisp
);
56 static inline FunctionInstance
*function_this(vdisp_t
*jsthis
)
58 return is_vclass(jsthis
, JSCLASS_FUNCTION
) ? function_from_vdisp(jsthis
) : NULL
;
61 static const WCHAR prototypeW
[] = {'p','r','o','t','o','t', 'y', 'p','e',0};
63 static const WCHAR lengthW
[] = {'l','e','n','g','t','h',0};
64 static const WCHAR toStringW
[] = {'t','o','S','t','r','i','n','g',0};
65 static const WCHAR applyW
[] = {'a','p','p','l','y',0};
66 static const WCHAR callW
[] = {'c','a','l','l',0};
67 static const WCHAR argumentsW
[] = {'a','r','g','u','m','e','n','t','s',0};
69 static HRESULT
init_parameters(jsdisp_t
*var_disp
, FunctionInstance
*function
, unsigned argc
, jsval_t
*argv
)
74 for(i
=0; i
< function
->func_code
->param_cnt
; i
++) {
75 hres
= jsdisp_propput_name(var_disp
, function
->func_code
->params
[i
],
76 i
< argc
? argv
[i
] : jsval_undefined());
84 static HRESULT
Arguments_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
91 static void Arguments_destructor(jsdisp_t
*jsdisp
)
93 ArgumentsInstance
*arguments
= (ArgumentsInstance
*)jsdisp
;
95 jsdisp_release(&arguments
->function
->dispex
);
96 jsdisp_release(arguments
->var_obj
);
100 static unsigned Arguments_idx_length(jsdisp_t
*jsdisp
)
102 ArgumentsInstance
*arguments
= (ArgumentsInstance
*)jsdisp
;
103 return arguments
->function
->length
;
106 static HRESULT
Arguments_idx_get(jsdisp_t
*jsdisp
, unsigned idx
, jsval_t
*res
)
108 ArgumentsInstance
*arguments
= (ArgumentsInstance
*)jsdisp
;
110 TRACE("%p[%u]\n", arguments
, idx
);
112 /* FIXME: Accessing by name won't work for duplicated argument names */
113 return jsdisp_propget_name(arguments
->var_obj
, arguments
->function
->func_code
->params
[idx
], res
);
116 static HRESULT
Arguments_idx_put(jsdisp_t
*jsdisp
, unsigned idx
, jsval_t val
)
118 ArgumentsInstance
*arguments
= (ArgumentsInstance
*)jsdisp
;
120 TRACE("%p[%u] = %s\n", arguments
, idx
, debugstr_jsval(val
));
122 /* FIXME: Accessing by name won't work for duplicated argument names */
123 return jsdisp_propput_name(arguments
->var_obj
, arguments
->function
->func_code
->params
[idx
], val
);
126 static const builtin_info_t Arguments_info
= {
128 {NULL
, Arguments_value
, 0},
130 Arguments_destructor
,
132 Arguments_idx_length
,
137 static HRESULT
create_arguments(script_ctx_t
*ctx
, FunctionInstance
*calee
, jsdisp_t
*var_obj
,
138 unsigned argc
, jsval_t
*argv
, jsdisp_t
**ret
)
140 ArgumentsInstance
*args
;
144 static const WCHAR caleeW
[] = {'c','a','l','l','e','e',0};
146 args
= heap_alloc_zero(sizeof(*args
));
148 return E_OUTOFMEMORY
;
150 hres
= init_dispex_from_constr(&args
->jsdisp
, ctx
, &Arguments_info
, ctx
->object_constr
);
156 jsdisp_addref(&calee
->dispex
);
157 args
->function
= calee
;
158 args
->var_obj
= jsdisp_addref(var_obj
);
160 /* Store unnamed arguments directly in arguments object */
161 for(i
= calee
->length
; i
< argc
; i
++) {
164 static const WCHAR formatW
[] = {'%','d',0};
166 sprintfW(buf
, formatW
, i
);
167 hres
= jsdisp_propput_dontenum(&args
->jsdisp
, buf
, argv
[i
]);
172 if(SUCCEEDED(hres
)) {
173 hres
= jsdisp_propput_dontenum(&args
->jsdisp
, lengthW
, jsval_number(argc
));
175 hres
= jsdisp_propput_dontenum(&args
->jsdisp
, caleeW
, jsval_disp(to_disp(&calee
->dispex
)));
178 jsdisp_release(&args
->jsdisp
);
182 *ret
= &args
->jsdisp
;
186 static HRESULT
create_var_disp(script_ctx_t
*ctx
, FunctionInstance
*function
, unsigned argc
, jsval_t
*argv
, jsdisp_t
**ret
)
191 hres
= create_dispex(ctx
, NULL
, NULL
, &var_disp
);
195 hres
= init_parameters(var_disp
, function
, argc
, argv
);
197 jsdisp_release(var_disp
);
205 static HRESULT
invoke_source(script_ctx_t
*ctx
, FunctionInstance
*function
, IDispatch
*this_obj
, unsigned argc
, jsval_t
*argv
,
208 jsdisp_t
*var_disp
, *arg_disp
;
209 exec_ctx_t
*exec_ctx
;
210 scope_chain_t
*scope
;
213 if(ctx
->state
== SCRIPTSTATE_UNINITIALIZED
|| ctx
->state
== SCRIPTSTATE_CLOSED
) {
214 WARN("Script engine state does not allow running code.\n");
218 if(!function
->func_code
) {
219 FIXME("no source\n");
223 hres
= create_var_disp(ctx
, function
, argc
, argv
, &var_disp
);
227 hres
= create_arguments(ctx
, function
, var_disp
, argc
, argv
, &arg_disp
);
229 jsdisp_release(var_disp
);
233 hres
= jsdisp_propput(var_disp
, argumentsW
, PROPF_DONTDELETE
, jsval_obj(arg_disp
));
235 jsdisp_release(arg_disp
);
236 jsdisp_release(var_disp
);
240 hres
= scope_push(function
->scope_chain
, var_disp
, to_disp(var_disp
), &scope
);
241 if(SUCCEEDED(hres
)) {
242 hres
= create_exec_ctx(ctx
, this_obj
, var_disp
, scope
, FALSE
, &exec_ctx
);
243 scope_release(scope
);
245 if(SUCCEEDED(hres
)) {
248 prev_args
= function
->arguments
;
249 function
->arguments
= arg_disp
;
250 hres
= exec_source(exec_ctx
, function
->code
, function
->func_code
, FALSE
, r
);
251 function
->arguments
= prev_args
;
253 exec_release(exec_ctx
);
257 /* Reset arguments value to cut the reference cycle. Note that since all activation contexts have
258 * their own arguments property, it's impossible to use prototype's one during name lookup */
259 jsdisp_propput_name(var_disp
, argumentsW
, jsval_undefined());
261 jsdisp_release(arg_disp
);
262 jsdisp_release(var_disp
);
266 static HRESULT
invoke_constructor(script_ctx_t
*ctx
, FunctionInstance
*function
, unsigned argc
, jsval_t
*argv
,
273 hres
= create_object(ctx
, &function
->dispex
, &this_obj
);
277 hres
= invoke_source(ctx
, function
, to_disp(this_obj
), argc
, argv
, &var
);
279 jsdisp_release(this_obj
);
283 if(is_object_instance(var
)) {
284 jsdisp_release(this_obj
);
288 *r
= jsval_obj(this_obj
);
293 static HRESULT
invoke_value_proc(script_ctx_t
*ctx
, FunctionInstance
*function
, IDispatch
*this_disp
, WORD flags
,
294 unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
300 set_disp(&vthis
, this_disp
);
301 else if(ctx
->host_global
)
302 set_disp(&vthis
, ctx
->host_global
);
304 set_jsdisp(&vthis
, ctx
->global
);
306 hres
= function
->value_proc(ctx
, &vthis
, flags
, argc
, argv
, r
);
308 vdisp_release(&vthis
);
312 static HRESULT
call_function(script_ctx_t
*ctx
, FunctionInstance
*function
, IDispatch
*this_obj
,
313 unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
315 if(function
->value_proc
)
316 return invoke_value_proc(ctx
, function
, this_obj
, DISPATCH_METHOD
, argc
, argv
, r
);
318 return invoke_source(ctx
, function
, this_obj
, argc
, argv
, r
);
321 static HRESULT
function_to_string(FunctionInstance
*function
, jsstr_t
**ret
)
325 static const WCHAR native_prefixW
[] = {'\n','f','u','n','c','t','i','o','n',' '};
326 static const WCHAR native_suffixW
[] =
327 {'(',')',' ','{','\n',' ',' ',' ',' ','[','n','a','t','i','v','e',' ','c','o','d','e',']','\n','}','\n'};
329 if(function
->value_proc
) {
333 name_len
= strlenW(function
->name
);
334 ptr
= jsstr_alloc_buf((sizeof(native_prefixW
)+sizeof(native_suffixW
))/sizeof(WCHAR
) + name_len
, &str
);
336 return E_OUTOFMEMORY
;
338 memcpy(ptr
, native_prefixW
, sizeof(native_prefixW
));
339 memcpy(ptr
+= sizeof(native_prefixW
)/sizeof(WCHAR
), function
->name
, name_len
*sizeof(WCHAR
));
340 memcpy(ptr
+ name_len
, native_suffixW
, sizeof(native_suffixW
));
342 str
= jsstr_alloc_len(function
->func_code
->source
, function
->func_code
->source_len
);
344 return E_OUTOFMEMORY
;
351 HRESULT
Function_invoke(jsdisp_t
*func_this
, IDispatch
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
353 FunctionInstance
*function
;
355 TRACE("func %p this %p\n", func_this
, jsthis
);
357 assert(is_class(func_this
, JSCLASS_FUNCTION
));
358 function
= (FunctionInstance
*)func_this
;
360 if(function
->value_proc
)
361 return invoke_value_proc(function
->dispex
.ctx
, function
, jsthis
, flags
, argc
, argv
, r
);
363 if(flags
== DISPATCH_CONSTRUCT
)
364 return invoke_constructor(function
->dispex
.ctx
, function
, argc
, argv
, r
);
366 assert(flags
== DISPATCH_METHOD
);
367 return invoke_source(function
->dispex
.ctx
, function
, jsthis
, argc
, argv
, r
);
370 static HRESULT
Function_get_length(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
372 TRACE("%p\n", jsthis
);
374 *r
= jsval_number(function_from_jsdisp(jsthis
)->length
);
378 static HRESULT
Function_set_length(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t value
)
384 static HRESULT
Function_toString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
387 FunctionInstance
*function
;
393 if(!(function
= function_this(jsthis
)))
394 return throw_type_error(ctx
, JS_E_FUNCTION_EXPECTED
, NULL
);
396 hres
= function_to_string(function
, &str
);
401 *r
= jsval_string(str
);
407 static HRESULT
array_to_args(script_ctx_t
*ctx
, jsdisp_t
*arg_array
, unsigned *argc
, jsval_t
**ret
)
413 hres
= jsdisp_propget_name(arg_array
, lengthW
, &val
);
417 hres
= to_uint32(ctx
, val
, &length
);
422 argv
= heap_alloc(length
* sizeof(*argv
));
424 return E_OUTOFMEMORY
;
426 for(i
=0; i
<length
; i
++) {
427 hres
= jsdisp_get_idx(arg_array
, i
, argv
+i
);
428 if(hres
== DISP_E_UNKNOWNNAME
) {
429 argv
[i
] = jsval_undefined();
430 }else if(FAILED(hres
)) {
432 jsval_release(argv
[i
]);
443 static HRESULT
Function_apply(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
445 FunctionInstance
*function
;
446 jsval_t
*args
= NULL
;
448 IDispatch
*this_obj
= NULL
;
453 if(!(function
= function_this(jsthis
)))
454 return throw_type_error(ctx
, JS_E_FUNCTION_EXPECTED
, NULL
);
457 if(!is_undefined(argv
[0]) && !is_null(argv
[0])) {
458 hres
= to_object(ctx
, argv
[0], &this_obj
);
465 jsdisp_t
*arg_array
= NULL
;
467 if(is_object_instance(argv
[1])) {
468 arg_array
= iface_to_jsdisp((IUnknown
*)get_object(argv
[1]));
470 (!is_class(arg_array
, JSCLASS_ARRAY
) && !is_class(arg_array
, JSCLASS_ARGUMENTS
) )) {
471 jsdisp_release(arg_array
);
477 hres
= array_to_args(ctx
, arg_array
, &cnt
, &args
);
478 jsdisp_release(arg_array
);
480 FIXME("throw TypeError\n");
486 hres
= call_function(ctx
, function
, this_obj
, cnt
, args
, r
);
489 IDispatch_Release(this_obj
);
490 for(i
=0; i
< cnt
; i
++)
491 jsval_release(args
[i
]);
496 static HRESULT
Function_call(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
499 FunctionInstance
*function
;
500 IDispatch
*this_obj
= NULL
;
506 if(!(function
= function_this(jsthis
)))
507 return throw_type_error(ctx
, JS_E_FUNCTION_EXPECTED
, NULL
);
510 if(!is_undefined(argv
[0]) && !is_null(argv
[0])) {
511 hres
= to_object(ctx
, argv
[0], &this_obj
);
519 hres
= call_function(ctx
, function
, this_obj
, cnt
, argv
+1, r
);
522 IDispatch_Release(this_obj
);
526 HRESULT
Function_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
529 FunctionInstance
*function
;
533 if(!is_vclass(jsthis
, JSCLASS_FUNCTION
)) {
534 ERR("dispex is not a function\n");
538 function
= (FunctionInstance
*)jsthis
->u
.jsdisp
;
540 assert(function
->value_proc
!= NULL
);
541 return invoke_value_proc(ctx
, function
, NULL
, flags
, argc
, argv
, r
);
544 HRESULT
Function_get_value(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
551 hres
= function_to_string(function_from_jsdisp(jsthis
), &str
);
555 *r
= jsval_string(str
);
559 static HRESULT
Function_get_arguments(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
561 FunctionInstance
*function
= function_from_jsdisp(jsthis
);
565 *r
= function
->arguments
? jsval_obj(jsdisp_addref(function
->arguments
)) : jsval_null();
569 static void Function_destructor(jsdisp_t
*dispex
)
571 FunctionInstance
*This
= (FunctionInstance
*)dispex
;
574 release_bytecode(This
->code
);
575 if(This
->scope_chain
)
576 scope_release(This
->scope_chain
);
580 static const builtin_prop_t Function_props
[] = {
581 {applyW
, Function_apply
, PROPF_METHOD
|2},
582 {argumentsW
, NULL
, 0, Function_get_arguments
, builtin_set_const
},
583 {callW
, Function_call
, PROPF_METHOD
|1},
584 {lengthW
, NULL
, 0, Function_get_length
, Function_set_length
},
585 {toStringW
, Function_toString
, PROPF_METHOD
}
588 static const builtin_info_t Function_info
= {
590 DEFAULT_FUNCTION_VALUE
,
591 sizeof(Function_props
)/sizeof(*Function_props
),
597 static const builtin_prop_t FunctionInst_props
[] = {
598 {argumentsW
, NULL
, 0, Function_get_arguments
, builtin_set_const
},
599 {lengthW
, NULL
, 0, Function_get_length
, Function_set_length
}
602 static const builtin_info_t FunctionInst_info
= {
604 DEFAULT_FUNCTION_VALUE
,
605 sizeof(FunctionInst_props
)/sizeof(*FunctionInst_props
),
611 static HRESULT
create_function(script_ctx_t
*ctx
, const builtin_info_t
*builtin_info
, DWORD flags
,
612 BOOL funcprot
, jsdisp_t
*prototype
, FunctionInstance
**ret
)
614 FunctionInstance
*function
;
617 function
= heap_alloc_zero(sizeof(FunctionInstance
));
619 return E_OUTOFMEMORY
;
622 hres
= init_dispex(&function
->dispex
, ctx
, builtin_info
, prototype
);
623 else if(builtin_info
)
624 hres
= init_dispex_from_constr(&function
->dispex
, ctx
, builtin_info
, ctx
->function_constr
);
626 hres
= init_dispex_from_constr(&function
->dispex
, ctx
, &FunctionInst_info
, ctx
->function_constr
);
632 function
->flags
= flags
;
633 function
->length
= flags
& PROPF_ARGMASK
;
639 static inline HRESULT
set_prototype(script_ctx_t
*ctx
, jsdisp_t
*dispex
, jsdisp_t
*prototype
)
641 return jsdisp_propput_dontenum(dispex
, prototypeW
, jsval_obj(prototype
));
644 HRESULT
create_builtin_function(script_ctx_t
*ctx
, builtin_invoke_t value_proc
, const WCHAR
*name
,
645 const builtin_info_t
*builtin_info
, DWORD flags
, jsdisp_t
*prototype
, jsdisp_t
**ret
)
647 FunctionInstance
*function
;
650 hres
= create_function(ctx
, builtin_info
, flags
, FALSE
, NULL
, &function
);
655 hres
= jsdisp_propput_const(&function
->dispex
, lengthW
, jsval_number(function
->length
));
657 hres
= set_prototype(ctx
, &function
->dispex
, prototype
);
659 jsdisp_release(&function
->dispex
);
663 function
->value_proc
= value_proc
;
664 function
->name
= name
;
666 *ret
= &function
->dispex
;
670 static HRESULT
set_constructor_prop(script_ctx_t
*ctx
, jsdisp_t
*constr
, jsdisp_t
*prot
)
672 static const WCHAR constructorW
[] = {'c','o','n','s','t','r','u','c','t','o','r',0};
674 return jsdisp_propput_dontenum(prot
, constructorW
, jsval_obj(constr
));
677 HRESULT
create_builtin_constructor(script_ctx_t
*ctx
, builtin_invoke_t value_proc
, const WCHAR
*name
,
678 const builtin_info_t
*builtin_info
, DWORD flags
, jsdisp_t
*prototype
, jsdisp_t
**ret
)
683 hres
= create_builtin_function(ctx
, value_proc
, name
, builtin_info
, flags
, prototype
, &constr
);
687 hres
= set_constructor_prop(ctx
, constr
, prototype
);
689 jsdisp_release(constr
);
697 HRESULT
create_source_function(script_ctx_t
*ctx
, bytecode_t
*code
, function_code_t
*func_code
,
698 scope_chain_t
*scope_chain
, jsdisp_t
**ret
)
700 FunctionInstance
*function
;
704 hres
= create_object(ctx
, NULL
, &prototype
);
708 hres
= create_function(ctx
, NULL
, PROPF_CONSTR
, FALSE
, NULL
, &function
);
709 if(SUCCEEDED(hres
)) {
710 hres
= set_prototype(ctx
, &function
->dispex
, prototype
);
712 hres
= set_constructor_prop(ctx
, &function
->dispex
, prototype
);
714 jsdisp_release(&function
->dispex
);
716 jsdisp_release(prototype
);
721 scope_addref(scope_chain
);
722 function
->scope_chain
= scope_chain
;
725 bytecode_addref(code
);
726 function
->code
= code
;
727 function
->func_code
= func_code
;
728 function
->length
= function
->func_code
->param_cnt
;
730 *ret
= &function
->dispex
;
734 static HRESULT
construct_function(script_ctx_t
*ctx
, unsigned argc
, jsval_t
*argv
, IDispatch
**ret
)
736 WCHAR
*str
= NULL
, *ptr
;
737 unsigned len
= 0, i
= 0;
740 jsstr_t
**params
= NULL
;
744 static const WCHAR function_anonymousW
[] = {'f','u','n','c','t','i','o','n',' ','a','n','o','n','y','m','o','u','s','('};
745 static const WCHAR function_beginW
[] = {')',' ','{','\n'};
746 static const WCHAR function_endW
[] = {'\n','}',0};
749 params
= heap_alloc(argc
*sizeof(*params
));
751 return E_OUTOFMEMORY
;
754 len
= (argc
-2)*2; /* separating commas */
755 for(i
=0; i
< argc
; i
++) {
756 hres
= to_string(ctx
, argv
[i
], params
+i
);
759 len
+= jsstr_length(params
[i
]);
763 if(SUCCEEDED(hres
)) {
764 len
+= (sizeof(function_anonymousW
) + sizeof(function_beginW
) + sizeof(function_endW
)) / sizeof(WCHAR
);
765 str
= heap_alloc(len
*sizeof(WCHAR
));
767 memcpy(str
, function_anonymousW
, sizeof(function_anonymousW
));
768 ptr
= str
+ sizeof(function_anonymousW
)/sizeof(WCHAR
);
771 ptr
+= jsstr_flush(params
[j
], ptr
);
778 memcpy(ptr
, function_beginW
, sizeof(function_beginW
));
779 ptr
+= sizeof(function_beginW
)/sizeof(WCHAR
);
781 ptr
+= jsstr_flush(params
[argc
-1], ptr
);
782 memcpy(ptr
, function_endW
, sizeof(function_endW
));
784 TRACE("%s\n", debugstr_w(str
));
786 hres
= E_OUTOFMEMORY
;
791 jsstr_release(params
[--i
]);
796 hres
= compile_script(ctx
, str
, NULL
, NULL
, FALSE
, FALSE
, &code
);
801 if(code
->global_code
.func_cnt
!= 1 || code
->global_code
.var_cnt
) {
802 ERR("Invalid parser result!\n");
803 release_bytecode(code
);
807 hres
= create_source_function(ctx
, code
, code
->global_code
.funcs
, NULL
, &function
);
808 release_bytecode(code
);
812 *ret
= to_disp(function
);
816 static HRESULT
FunctionConstr_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
824 case DISPATCH_CONSTRUCT
: {
827 hres
= construct_function(ctx
, argc
, argv
, &ret
);
831 *r
= jsval_disp(ret
);
835 FIXME("unimplemented flags %x\n", flags
);
842 static HRESULT
FunctionProt_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
849 HRESULT
init_function_constr(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
)
851 FunctionInstance
*prot
, *constr
;
854 static const WCHAR FunctionW
[] = {'F','u','n','c','t','i','o','n',0};
856 hres
= create_function(ctx
, &Function_info
, PROPF_CONSTR
, TRUE
, object_prototype
, &prot
);
860 prot
->value_proc
= FunctionProt_value
;
861 prot
->name
= prototypeW
;
863 hres
= create_function(ctx
, &FunctionInst_info
, PROPF_CONSTR
|1, TRUE
, &prot
->dispex
, &constr
);
864 if(SUCCEEDED(hres
)) {
865 constr
->value_proc
= FunctionConstr_value
;
866 constr
->name
= FunctionW
;
867 hres
= set_prototype(ctx
, &constr
->dispex
, &prot
->dispex
);
869 hres
= set_constructor_prop(ctx
, &constr
->dispex
, &prot
->dispex
);
871 jsdisp_release(&constr
->dispex
);
873 jsdisp_release(&prot
->dispex
);
877 ctx
->function_constr
= &constr
->dispex
;