ReactOS 0.4.17-dev-357-ga8f14ff
function.c
Go to the documentation of this file.
1/*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include <assert.h>
20
21#include "jscript.h"
22#include "engine.h"
23
24#include "wine/debug.h"
25
27
29
30typedef struct {
36
43};
44
45typedef struct {
51
52typedef struct {
55 const WCHAR *name;
57
58typedef struct {
61 jsval_t this;
62 unsigned argc;
65
66typedef struct {
68 const WCHAR *name;
73
74typedef struct {
78
79typedef struct {
83 unsigned argc;
85
87
89{
90 return S_OK;
91}
92
94{
95 return CONTAINING_RECORD(jsdisp, FunctionInstance, dispex);
96}
97
99{
100 jsdisp_t *jsdisp = is_object_instance(vthis) ? to_jsdisp(get_object(vthis)) : NULL;
101 return (jsdisp && is_class(jsdisp, JSCLASS_FUNCTION)) ? function_from_jsdisp(jsdisp) : NULL;
102}
103
105{
106 return CONTAINING_RECORD(jsdisp, ArgumentsInstance, jsdisp);
107}
108
110 jsval_t *r)
111{
112 FIXME("\n");
113 return E_NOTIMPL;
114}
115
116static void Arguments_destructor(jsdisp_t *jsdisp)
117{
118 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
119
120 TRACE("(%p)\n", arguments);
121
122 if(arguments->buf) {
123 unsigned i;
124 for(i = 0; i < arguments->argc; i++)
125 jsval_release(arguments->buf[i]);
126 free(arguments->buf);
127 }
128
129 if(arguments->scope)
130 scope_release(arguments->scope);
131}
132
133static HRESULT Arguments_lookup_prop(jsdisp_t *jsdisp, const WCHAR *name, unsigned flags, struct property_info *desc)
134{
135 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
136 return jsdisp_index_lookup(&arguments->jsdisp, name, arguments->argc, desc);
137}
138
139static HRESULT Arguments_next_prop(jsdisp_t *jsdisp, unsigned id, struct property_info *desc)
140{
141 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
142 return jsdisp_next_index(&arguments->jsdisp, arguments->argc, id, desc);
143}
144
145static jsval_t *get_argument_ref(ArgumentsInstance *arguments, unsigned idx)
146{
147 if(arguments->buf)
148 return arguments->buf + idx;
149 if(!arguments->scope->detached_vars)
150 return arguments->jsdisp.ctx->stack + arguments->scope->frame->arguments_off + idx;
151 return arguments->scope->detached_vars->var + idx;
152}
153
154static HRESULT Arguments_prop_get(jsdisp_t *jsdisp, unsigned idx, jsval_t *r)
155{
156 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
157
158 TRACE("%p[%u]\n", arguments, idx);
159
160 return jsval_copy(*get_argument_ref(arguments, idx), r);
161}
162
164{
165 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
166 jsval_t copy, *ref;
168
169 TRACE("%p[%u] = %s\n", arguments, idx, debugstr_jsval(val));
170
171 hres = jsval_copy(val, &copy);
172 if(FAILED(hres))
173 return hres;
174
175 ref = get_argument_ref(arguments, idx);
177 *ref = copy;
178 return S_OK;
179}
180
182{
183 ArgumentsInstance *arguments = arguments_from_jsdisp(jsdisp);
185 unsigned i;
186
187 if(arguments->buf) {
188 for(i = 0; i < arguments->argc; i++) {
189 hres = gc_process_linked_val(gc_ctx, op, jsdisp, &arguments->buf[i]);
190 if(FAILED(hres))
191 return hres;
192 }
193 }
194
195 if(arguments->scope) {
196 hres = gc_process_linked_obj(gc_ctx, op, jsdisp, &arguments->scope->dispex, (void**)&arguments->scope);
197 if(FAILED(hres))
198 return hres;
199 }
200
201 return S_OK;
202}
203
205{
206 ArgumentsInstance *arguments = arguments_from_jsdisp(jsthis);
207 call_frame_t *frame;
209
210 TRACE("\n");
211
212 for(frame = ctx->call_ctx; frame; frame = frame->prev_frame) {
213 if(frame->arguments_obj == &arguments->jsdisp) {
214 frame = frame->prev_frame;
215 if(!frame || !frame->function_instance)
216 break;
217 if(!frame->arguments_obj) {
219 if(FAILED(hres))
220 return hres;
221 }
223 return S_OK;
224 }
225 }
226
227 *r = jsval_null();
228 return S_OK;
229}
230
232 {L"caller", NULL, 0, Arguments_get_caller},
233};
234
237 .call = Arguments_value,
238 .props_cnt = ARRAY_SIZE(Arguments_props),
239 .props = Arguments_props,
240 .destructor = Arguments_destructor,
241 .lookup_prop = Arguments_lookup_prop,
242 .next_prop = Arguments_next_prop,
243 .prop_get = Arguments_prop_get,
244 .prop_put = Arguments_prop_put,
245 .gc_traverse = Arguments_gc_traverse
246};
247
250 .call = Arguments_value,
251 .destructor = Arguments_destructor,
252 .lookup_prop = Arguments_lookup_prop,
253 .next_prop = Arguments_next_prop,
254 .prop_get = Arguments_prop_get,
255 .prop_put = Arguments_prop_put,
256 .gc_traverse = Arguments_gc_traverse
257};
258
260{
263
264 args = calloc(1, sizeof(*args));
265 if(!args)
266 return E_OUTOFMEMORY;
267
269 if(FAILED(hres)) {
270 free(args);
271 return hres;
272 }
273
274 args->argc = frame->argc;
275 args->scope = scope_addref(frame->base_scope);
276
278 jsval_number(args->argc));
279 if(SUCCEEDED(hres))
282 if(SUCCEEDED(hres))
283 hres = jsdisp_propput(as_jsdisp(frame->base_scope->obj), L"arguments", PROPF_WRITABLE, TRUE, jsval_obj(&args->jsdisp));
284 if(FAILED(hres)) {
285 jsdisp_release(&args->jsdisp);
286 return hres;
287 }
288
289 frame->arguments_obj = &args->jsdisp;
290 return S_OK;
291}
292
294{
296 scope_chain_t *scope = arguments->scope;
297 const BOOL on_stack = scope->frame == frame;
298 jsdisp_t *jsobj = as_jsdisp(scope->obj);
299
300 /* Reset arguments value to cut the reference cycle. Note that since all activation contexts have
301 * their own arguments property, it's impossible to use prototype's one during name lookup */
302 jsdisp_propput_name(jsobj, L"arguments", jsval_undefined());
303
304 /* Don't bother coppying arguments if call frame holds the last reference. */
305 if(arguments->jsdisp.ref > 1 && !arguments->jsdisp.ctx->html_mode) {
306 arguments->buf = malloc(arguments->argc * sizeof(*arguments->buf));
307 if(arguments->buf) {
308 const jsval_t *args = on_stack ? arguments->jsdisp.ctx->stack + frame->arguments_off : scope->detached_vars->var;
309 int i;
310
311 for(i = 0; i < arguments->argc ; i++) {
312 if(FAILED(jsval_copy(args[i], &arguments->buf[i])))
313 arguments->buf[i] = jsval_undefined();
314 }
315 }else {
316 ERR("out of memory\n");
317 arguments->argc = 0;
318 }
319
320 arguments->scope = NULL;
321 scope_release(scope);
322 }
323
324 jsdisp_release(&arguments->jsdisp);
325}
326
328{
329 FunctionInstance *function;
330
331 TRACE("func %p this %s\n", func_this, debugstr_jsval(vthis));
332
333 assert(is_class(func_this, JSCLASS_FUNCTION));
334 function = function_from_jsdisp(func_this);
335
336 if(function->dispex.ctx->state == SCRIPTSTATE_UNINITIALIZED || function->dispex.ctx->state == SCRIPTSTATE_CLOSED) {
337 WARN("Script engine state does not allow running code.\n");
338 return E_UNEXPECTED;
339 }
340
341 return function->vtbl->call(function->dispex.ctx, function, vthis, flags, argc, argv, r);
342}
343
345{
346 FunctionInstance *function = function_from_jsdisp(jsthis);
347 call_frame_t *frame;
348
349 TRACE("%p\n", jsthis);
350
351 for(frame = ctx->call_ctx; frame; frame = frame->prev_frame) {
352 if(frame->function_instance == &function->dispex) {
353 if(!frame->prev_frame || !frame->prev_frame->function_instance)
354 break;
355 *r = jsval_obj(jsdisp_addref(frame->prev_frame->function_instance));
356 return S_OK;
357 }
358 }
359
360 *r = jsval_null();
361 return S_OK;
362}
363
365{
366 TRACE("%p\n", jsthis);
367
369 return S_OK;
370}
371
373{
374 DWORD name_len;
375 jsstr_t *str;
376 WCHAR *ptr;
377
378 static const WCHAR native_prefixW[] = L"\nfunction ";
379 static const WCHAR native_suffixW[] = L"() {\n [native code]\n}\n";
380
381 name_len = name ? lstrlenW(name) : 0;
382 str = jsstr_alloc_buf(ARRAY_SIZE(native_prefixW) + ARRAY_SIZE(native_suffixW) + name_len - 2, &ptr);
383 if(!str)
384 return E_OUTOFMEMORY;
385
386 memcpy(ptr, native_prefixW, sizeof(native_prefixW));
387 ptr += ARRAY_SIZE(native_prefixW) - 1;
388 memcpy(ptr, name, name_len * sizeof(WCHAR));
389 ptr += name_len;
390 memcpy(ptr, native_suffixW, sizeof(native_suffixW));
391
392 *ret = str;
393 return S_OK;
394}
395
397 jsval_t *r)
398{
399 FunctionInstance *function;
400 jsstr_t *str;
402
403 TRACE("\n");
404
405 if(!(function = function_this(vthis)))
407
408 hres = function->vtbl->toString(function, &str);
409 if(FAILED(hres))
410 return hres;
411
412 if(r)
413 *r = jsval_string(str);
414 else
416 return S_OK;
417}
418
419static HRESULT array_to_args(script_ctx_t *ctx, jsdisp_t *arg_array, unsigned *argc, jsval_t **ret)
420{
421 jsval_t *argv, val;
422 UINT32 length, i;
424
425 hres = jsdisp_propget_name(arg_array, L"length", &val);
426 if(FAILED(hres))
427 return hres;
428
431 if(FAILED(hres))
432 return hres;
433
434 argv = malloc(length * sizeof(*argv));
435 if(!argv)
436 return E_OUTOFMEMORY;
437
438 for(i=0; i<length; i++) {
439 hres = jsdisp_get_idx(arg_array, i, argv+i);
440 if(hres == DISP_E_UNKNOWNNAME) {
442 }else if(FAILED(hres)) {
443 while(i--)
445 free(argv);
446 return hres;
447 }
448 }
449
450 *argc = length;
451 *ret = argv;
452 return S_OK;
453}
454
456{
457 jsval_t this_val = jsval_undefined();
458 FunctionInstance *function;
459 jsval_t *args = NULL;
460 unsigned i, cnt = 0;
461 HRESULT hres = S_OK;
462
463 TRACE("\n");
464
465 if(is_null_disp(vthis))
467 if(!is_object_instance(vthis) || (!(function = function_this(vthis)) && to_jsdisp(get_object(vthis))))
469
470 if(argc) {
471 if(ctx->version < SCRIPTLANGUAGEVERSION_ES5 && !is_undefined(argv[0]) && !is_null(argv[0])) {
472 IDispatch *this_obj;
473 hres = to_object(ctx, argv[0], &this_obj);
474 if(FAILED(hres))
475 return hres;
476 this_val = jsval_disp(this_obj);
477 }else {
478 hres = jsval_copy(argv[0], &this_val);
479 if(FAILED(hres))
480 return hres;
481 }
482 }
483
484 if(argc >= 2) {
485 jsdisp_t *arg_array = NULL;
486
487 if(is_object_instance(argv[1])) {
488 arg_array = iface_to_jsdisp(get_object(argv[1]));
489 if(arg_array &&
490 (!is_class(arg_array, JSCLASS_ARRAY) && !is_class(arg_array, JSCLASS_ARGUMENTS) )) {
491 jsdisp_release(arg_array);
492 arg_array = NULL;
493 }
494 }
495
496 if(arg_array) {
497 hres = array_to_args(ctx, arg_array, &cnt, &args);
498 jsdisp_release(arg_array);
499 }else {
500 FIXME("throw TypeError\n");
501 hres = E_FAIL;
502 }
503 }
504
505 if(SUCCEEDED(hres)) {
506 if(function) {
507 hres = function->vtbl->call(ctx, function, this_val, flags, cnt, args, r);
508 }else {
509 jsval_t res;
510 hres = disp_call_value(ctx, get_object(vthis), this_val, DISPATCH_METHOD, cnt, args, &res);
511 if(SUCCEEDED(hres)) {
512 if(r)
513 *r = res;
514 else
516 }
517 }
518 }
519
520 jsval_release(this_val);
521 for(i=0; i < cnt; i++)
523 free(args);
524 return hres;
525}
526
528 jsval_t *r)
529{
530 jsval_t this_val = jsval_undefined();
531 FunctionInstance *function;
532 unsigned cnt = 0;
534
535 TRACE("\n");
536
537 if(is_null_disp(vthis))
539 if(!(function = function_this(vthis)))
541
542 if(argc) {
543 if(ctx->version < SCRIPTLANGUAGEVERSION_ES5 && !is_undefined(argv[0]) && !is_null(argv[0])) {
544 IDispatch *this_obj;
545 hres = to_object(ctx, argv[0], &this_obj);
546 if(FAILED(hres))
547 return hres;
548 this_val = jsval_disp(this_obj);
549 }else {
550 hres = jsval_copy(argv[0], &this_val);
551 if(FAILED(hres))
552 return hres;
553 }
554 cnt = argc-1;
555 }
556
557 hres = function->vtbl->call(ctx, function, this_val, flags, cnt, argv + 1, r);
558
559 jsval_release(this_val);
560 return hres;
561}
562
564 jsval_t *r)
565{
566 jsval_t bound_this = jsval_undefined();
567 FunctionInstance *function;
568 jsdisp_t *new_function;
570
571 TRACE("\n");
572
573 if(!(function = function_this(vthis)))
575
576 if(argc < 1) {
577 argc = 1;
578 }else if(is_null(argv[0])) {
579 bound_this = argv[0];
580 }else if(!is_undefined(argv[0])) {
581 IDispatch *obj;
582 hres = to_object(ctx, argv[0], &obj);
583 if(FAILED(hres))
584 return hres;
585 bound_this = jsval_disp(obj);
586 }
587
588 hres = create_bind_function(ctx, function, bound_this, argc - 1, argv + 1, &new_function);
589 jsval_release(bound_this);
590 if(FAILED(hres))
591 return hres;
592
593 if(r)
594 *r = jsval_obj(new_function);
595 else
596 jsdisp_release(new_function);
597 return S_OK;
598}
599
601 jsval_t *r)
602{
603 FunctionInstance *function;
604
605 TRACE("\n");
606
607 if(!(function = function_this(vthis))) {
608 ERR("dispex is not a function\n");
609 return E_FAIL;
610 }
611
612 return function->vtbl->call(ctx, function, vthis, flags, argc, argv, r);
613}
614
616{
617 FunctionInstance *function = function_from_jsdisp(jsthis);
618 jsstr_t *str;
620
621 TRACE("\n");
622
623 hres = function->vtbl->toString(function, &str);
624 if(FAILED(hres))
625 return hres;
626
627 *r = jsval_string(str);
628 return S_OK;
629}
630
632{
633 FunctionInstance *function = function_from_jsdisp(jsthis);
634 call_frame_t *frame;
636
637 TRACE("\n");
638
639 for(frame = ctx->call_ctx; frame; frame = frame->prev_frame) {
640 if(frame->function_instance == &function->dispex) {
641 if(!frame->arguments_obj) {
643 if(FAILED(hres))
644 return hres;
645 }
647 return S_OK;
648 }
649 }
650
651 *r = jsval_null();
652 return S_OK;
653}
654
656{
657 FunctionInstance *function;
658
660 function = function_from_jsdisp(jsthis);
661
662 return function->vtbl->get_code(function);
663}
664
665static void Function_destructor(jsdisp_t *dispex)
666{
667 FunctionInstance *function = function_from_jsdisp(dispex);
668 function->vtbl->destructor(function);
669}
670
672{
673 FunctionInstance *function = function_from_jsdisp(dispex);
674 return function->vtbl->gc_traverse(gc_ctx, op, function);
675}
676
678 {L"apply", Function_apply, PROPF_METHOD|2},
679 {L"arguments", NULL, PROPF_HTML, Function_get_arguments},
681 {L"call", Function_call, PROPF_METHOD|1},
683 {L"length", NULL, 0, Function_get_length},
684 {L"toString", Function_toString, PROPF_METHOD}
685};
686
689 .call = Function_value,
690 .props_cnt = ARRAY_SIZE(Function_props),
691 .props = Function_props,
692 .destructor = Function_destructor,
693 .gc_traverse = Function_gc_traverse
694};
695
697 {L"arguments", NULL, 0, Function_get_arguments},
699 {L"length", NULL, 0, Function_get_length}
700};
701
704 .call = Function_value,
705 .props_cnt = ARRAY_SIZE(FunctionInst_props),
706 .props = FunctionInst_props,
707 .destructor = Function_destructor,
708 .gc_traverse = Function_gc_traverse
709};
710
711static HRESULT create_function(script_ctx_t *ctx, const builtin_info_t *builtin_info, const function_vtbl_t *vtbl, size_t size,
712 DWORD flags, BOOL funcprot, jsdisp_t *prototype, void **ret)
713{
714 FunctionInstance *function;
716
717 function = calloc(1, size);
718 if(!function)
719 return E_OUTOFMEMORY;
720
721 if(funcprot)
722 hres = init_dispex(&function->dispex, ctx, builtin_info, prototype);
723 else if(builtin_info)
724 hres = init_dispex_from_constr(&function->dispex, ctx, builtin_info, ctx->function_constr);
725 else
726 hres = init_dispex_from_constr(&function->dispex, ctx, &FunctionInst_info, ctx->function_constr);
727 if(FAILED(hres)) {
728 free(function);
729 return hres;
730 }
731
732 function->vtbl = vtbl;
733 function->flags = flags;
734 function->length = flags & PROPF_ARGMASK;
735
736 *ret = function;
737 return S_OK;
738}
739
741 unsigned argc, jsval_t *argv, jsval_t *r)
742{
743 NativeFunction *function = (NativeFunction*)func;
744
745 if((flags & DISPATCH_CONSTRUCT) && !(function->function.flags & PROPF_CONSTR))
746 return JS_E_INVALID_ACTION;
747 return function->proc(ctx, vthis, flags & ~DISPATCH_JSCRIPT_INTERNAL_MASK, argc, argv, r);
748}
749
751{
752 NativeFunction *function = (NativeFunction*)func;
753 return native_function_string(function->name, ret);
754}
755
757{
758 return NULL;
759}
760
762{
763}
764
771};
772
774 const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
775{
776 NativeFunction *function;
778
779 if(!ctx->function_constr)
780 return E_UNEXPECTED;
781
782 hres = create_function(ctx, builtin_info, &NativeFunctionVtbl, sizeof(NativeFunction), flags, FALSE, NULL, (void**)&function);
783 if(FAILED(hres))
784 return hres;
785
786 if(builtin_info)
787 hres = jsdisp_define_data_property(&function->function.dispex, L"length", 0,
788 jsval_number(function->function.length));
789 if(SUCCEEDED(hres))
790 hres = jsdisp_define_data_property(&function->function.dispex, L"prototype", 0, prototype ? jsval_obj(prototype) : jsval_null());
791 if(FAILED(hres)) {
792 jsdisp_release(&function->function.dispex);
793 return hres;
794 }
795
796 function->proc = value_proc;
797 function->name = name;
798
799 *ret = &function->function.dispex;
800 return S_OK;
801}
802
804{
806 jsval_obj(constr));
807}
808
810 const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
811{
812 jsdisp_t *constr;
814
815 hres = create_builtin_function(ctx, value_proc, name, builtin_info, flags, prototype, &constr);
816 if(FAILED(hres))
817 return hres;
818
819 hres = set_constructor_prop(ctx, constr, prototype);
820 if(FAILED(hres)) {
821 jsdisp_release(constr);
822 return hres;
823 }
824
825 *ret = constr;
826 return S_OK;
827}
828
829/*
830 * Create the actual prototype on demand, since it is a circular ref, which prevents the vast
831 * majority of functions from being released quickly, leading to unnecessary scope detach.
832 */
834{
835 jsdisp_t *prototype;
837
838 hres = create_object(ctx, NULL, &prototype);
839 if(FAILED(hres))
840 return hres;
841
842 hres = jsdisp_define_data_property(jsthis, L"prototype", PROPF_WRITABLE, jsval_obj(prototype));
843 if(SUCCEEDED(hres))
844 hres = set_constructor_prop(ctx, jsthis, prototype);
845 if(FAILED(hres)) {
846 jsdisp_release(prototype);
847 return hres;
848 }
849
850 *r = jsval_obj(prototype);
851 return S_OK;
852}
853
855{
856 return jsdisp_define_data_property(jsthis, L"prototype", PROPF_WRITABLE, value);
857}
858
860 {L"arguments", NULL, 0, Function_get_arguments},
862 {L"length", NULL, 0, Function_get_length},
864};
865
868 .call = Function_value,
871 .destructor = Function_destructor,
872 .gc_traverse = Function_gc_traverse
873};
874
876 unsigned argc, jsval_t *argv, jsval_t *r)
877{
879 IDispatch *this_obj = NULL;
880 DWORD exec_flags = 0;
881 jsdisp_t *new_obj;
883
884 TRACE("%p\n", function);
885
886 if(flags & DISPATCH_CONSTRUCT) {
887 hres = create_object(ctx, &function->function.dispex, &new_obj);
888 if(FAILED(hres))
889 return hres;
890 this_obj = to_disp(new_obj);
891 }else if(is_object_instance(vthis)) {
892 this_obj = get_object(vthis);
893 IDispatch_AddRef(this_obj);
894 }else if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5 && !is_undefined(vthis) && !is_null(vthis)) {
895 hres = to_object(ctx, vthis, &this_obj);
896 if(FAILED(hres))
897 return hres;
898 }
899
901 exec_flags |= EXEC_RETURN_TO_INTERP;
902 if(flags & DISPATCH_CONSTRUCT)
903 exec_flags |= EXEC_CONSTRUCTOR;
904 hres = exec_source(ctx, exec_flags, function->code, function->func_code, function->scope_chain, this_obj,
905 &function->function.dispex, argc, argv, r);
906 if(this_obj)
907 IDispatch_Release(this_obj);
908 return hres;
909}
910
912{
914
915 *ret = jsstr_alloc_len(function->func_code->source, function->func_code->source_len);
916 return *ret ? S_OK : E_OUTOFMEMORY;
917}
918
920{
922
923 return function->func_code;
924}
925
927{
929
930 release_bytecode(function->code);
931 if(function->scope_chain)
932 scope_release(function->scope_chain);
933}
934
936{
938
939 if(!function->scope_chain)
940 return S_OK;
941 return gc_process_linked_obj(gc_ctx, op, &function->function.dispex, &function->scope_chain->dispex,
942 (void**)&function->scope_chain);
943}
944
951};
952
954 scope_chain_t *scope_chain, jsdisp_t **ret)
955{
956 InterpretedFunction *function;
958
960 PROPF_CONSTR, FALSE, NULL, (void**)&function);
961 if(FAILED(hres))
962 return hres;
963
964 if(scope_chain) {
965 scope_addref(scope_chain);
966 function->scope_chain = scope_chain;
967 }
968
970 function->code = code;
971 function->func_code = func_code;
972 function->function.length = function->func_code->param_cnt;
973
974 *ret = &function->function.dispex;
975 return S_OK;
976}
977
980 .call = Function_value,
981 .destructor = Function_destructor,
982 .gc_traverse = Function_gc_traverse
983};
984
986 unsigned argc, jsval_t *argv, jsval_t *r)
987{
988 HostFunction *function = (HostFunction*)func;
989 VARIANT buf[6], retv;
990 DISPPARAMS dp = { .cArgs = argc, .rgvarg = buf };
992 EXCEPINFO ei = { 0 };
993 IDispatch *this_obj;
994 HRESULT hres = S_OK;
995 unsigned i;
996
997 if(flags & DISPATCH_CONSTRUCT)
998 return E_UNEXPECTED;
999
1000 if(is_object_instance(vthis))
1001 this_obj = get_object(vthis);
1002 else if(is_undefined(vthis) || is_null(vthis))
1003 this_obj = lookup_global_host(ctx);
1004 else
1005 return E_UNEXPECTED;
1006
1007 obj = get_host_dispatch(this_obj);
1008 if(!obj) {
1009 TRACE("no host dispatch\n");
1010 return E_UNEXPECTED;
1011 }
1012
1013 if(argc > ARRAYSIZE(buf) && !(dp.rgvarg = malloc(argc * sizeof(*dp.rgvarg)))) {
1014 IWineJSDispatchHost_Release(obj);
1015 return E_OUTOFMEMORY;
1016 }
1017
1018 for(i = 0; i < argc; i++) {
1019 hres = jsval_to_variant(argv[i], &dp.rgvarg[dp.cArgs - i - 1]);
1020 if(FAILED(hres))
1021 break;
1022 }
1023
1024 if(SUCCEEDED(hres)) {
1025 V_VT(&retv) = VT_EMPTY;
1026 hres = IWineJSDispatchHost_CallFunction(obj, function->id, function->iid, function->flags, &dp,
1027 r ? &retv : NULL, &ei, &ctx->jscaller->IServiceProvider_iface);
1028 if(hres == DISP_E_EXCEPTION)
1030 if(SUCCEEDED(hres) && r) {
1031 hres = variant_to_jsval(ctx, &retv, r);
1032 VariantClear(&retv);
1033 }
1034 }
1035
1036 while(i--)
1037 VariantClear(&dp.rgvarg[dp.cArgs - i - 1]);
1038 if(dp.rgvarg != buf)
1039 free(dp.rgvarg);
1040 IWineJSDispatchHost_Release(obj);
1041 return hres;
1042}
1043
1045{
1046 HostFunction *function = (HostFunction*)func;
1047 return native_function_string(function->name, ret);
1048}
1049
1051{
1052 return NULL;
1053}
1054
1056{
1057}
1058
1060{
1061 return S_OK;
1062}
1063
1070};
1071
1073{
1074 HostFunction *function;
1075 HRESULT hres;
1076
1077 if(!ctx->function_constr)
1078 return E_UNEXPECTED;
1079
1081 FALSE, NULL, (void**)&function);
1082 if(FAILED(hres))
1083 return hres;
1084
1085 function->name = desc->name;
1086 function->id = desc->id;
1087 function->iid = desc->iid;
1088 function->flags = flags;
1089 *ret = &function->function.dispex;
1090 return S_OK;
1091}
1092
1094{
1095 HostConstructor *constr = (HostConstructor*)jsdisp;
1096 return IWineJSDispatchHost_AddRef(constr->host_iface);
1097}
1098
1100{
1101 HostConstructor *constr = (HostConstructor*)jsdisp;
1102 return IWineJSDispatchHost_Release(constr->host_iface);
1103}
1104
1106{
1107 HostConstructor *constr = (HostConstructor*)jsdisp;
1108 HRESULT hres = IWineJSDispatchHost_LookupProperty(constr->host_iface, name, flags, desc);
1109 assert(hres != S_OK || (desc->flags & PROPF_METHOD)); /* external properties are not allowed */
1110 return hres;
1111}
1112
1115 .addref = HostConstructor_addref,
1116 .release = HostConstructor_release,
1117 .call = Function_value,
1118 .destructor = Function_destructor,
1119 .gc_traverse = Function_gc_traverse,
1120 .lookup_prop = HostConstructor_lookup_prop,
1121};
1122
1124 unsigned argc, jsval_t *argv, jsval_t *r)
1125{
1126 HostConstructor *function = (HostConstructor*)func;
1127 VARIANT buf[6], ret;
1128 DISPPARAMS dp = { .cArgs = argc, .rgvarg = buf };
1129 EXCEPINFO ei = { 0 };
1130 HRESULT hres = S_OK;
1131 unsigned i;
1132
1133 flags &= ~DISPATCH_JSCRIPT_INTERNAL_MASK;
1134 if(argc > ARRAYSIZE(buf) && !(dp.rgvarg = malloc(argc * sizeof(*dp.rgvarg))))
1135 return E_OUTOFMEMORY;
1136
1137 for(i = 0; i < argc; i++) {
1138 hres = jsval_to_variant(argv[i], &dp.rgvarg[dp.cArgs - i - 1]);
1139 if(FAILED(hres))
1140 break;
1141 }
1142
1143 if(SUCCEEDED(hres)) {
1144 V_VT(&ret) = VT_EMPTY;
1145 hres = IWineJSDispatchHost_Construct(function->host_iface, ctx->lcid, flags, &dp, &ret, &ei,
1146 &ctx->jscaller->IServiceProvider_iface);
1147 if(hres == DISP_E_EXCEPTION)
1149 if(SUCCEEDED(hres) && r) {
1151 VariantClear(&ret);
1152 }
1153 }
1154
1155 while(i--)
1156 VariantClear(&dp.rgvarg[dp.cArgs - i - 1]);
1157 if(dp.rgvarg != buf)
1158 free(dp.rgvarg);
1159 return hres;
1160}
1161
1163{
1164 *ret = jsstr_alloc(L"\nfunction() {\n [native code]\n}\n");
1165 return *ret ? S_OK : E_OUTOFMEMORY;
1166}
1167
1169{
1170 return NULL;
1171}
1172
1174{
1175}
1176
1178{
1179 return S_OK;
1180}
1181
1188};
1189
1192{
1193 HostConstructor *function;
1194 HRESULT hres;
1195
1197 FALSE, NULL, (void**)&function);
1198 if(FAILED(hres))
1199 return hres;
1200 function->host_iface = host_constr;
1201
1203 jsval_disp((IDispatch *)prototype));
1204 if(FAILED(hres)) {
1205 IWineJSDispatch_Free(&function->function.dispex.IWineJSDispatch_iface);
1206 return hres;
1207 }
1208
1210 return S_OK;
1211}
1212
1214{
1215 return JS_E_INVALID_ACTION;
1216}
1217
1219{
1220 return JS_E_INVALID_ACTION;
1221}
1222
1224 {L"arguments", NULL, 0, BindFunction_get_arguments},
1225 {L"caller", NULL, 0, BindFunction_get_caller},
1226 {L"length", NULL, 0, Function_get_length}
1227};
1228
1231 .call = Function_value,
1232 .props_cnt = ARRAY_SIZE(BindFunction_props),
1233 .props = BindFunction_props,
1234 .destructor = Function_destructor,
1235 .gc_traverse = Function_gc_traverse
1236};
1237
1239 unsigned argc, jsval_t *argv, jsval_t *r)
1240{
1241 BindFunction *function = (BindFunction*)func;
1242 jsval_t *call_args = NULL;
1243 unsigned call_argc;
1244 HRESULT hres;
1245
1246 TRACE("%p\n", function);
1247
1248 call_argc = function->argc + argc;
1249 if(call_argc) {
1250 call_args = malloc(call_argc * sizeof(*call_args));
1251 if(!call_args)
1252 return E_OUTOFMEMORY;
1253
1254 if(function->argc)
1255 memcpy(call_args, function->args, function->argc * sizeof(*call_args));
1256 if(argc)
1257 memcpy(call_args + function->argc, argv, argc * sizeof(*call_args));
1258 }
1259
1260 hres = function->target->vtbl->call(ctx, function->target, function->this, flags, call_argc, call_args, r);
1261
1262 free(call_args);
1263 return hres;
1264}
1265
1267{
1268 *ret = jsstr_alloc(L"\nfunction() {\n [native code]\n}\n");
1269 return *ret ? S_OK : E_OUTOFMEMORY;
1270}
1271
1273{
1274 return NULL;
1275}
1276
1278{
1279 BindFunction *function = (BindFunction*)func;
1280 unsigned i;
1281
1282 TRACE("%p\n", function);
1283
1284 for(i = 0; i < function->argc; i++)
1285 jsval_release(function->args[i]);
1286 if(function->target)
1287 jsdisp_release(&function->target->dispex);
1288 jsval_release(function->this);
1289}
1290
1292{
1293 BindFunction *function = (BindFunction*)func;
1294 HRESULT hres;
1295 unsigned i;
1296
1297 for(i = 0; i < function->argc; i++) {
1298 hres = gc_process_linked_val(gc_ctx, op, &function->function.dispex, &function->args[i]);
1299 if(FAILED(hres))
1300 return hres;
1301 }
1302
1303 hres = gc_process_linked_obj(gc_ctx, op, &function->function.dispex, &function->target->dispex, (void**)&function->target);
1304 if(FAILED(hres))
1305 return hres;
1306
1307 return gc_process_linked_val(gc_ctx, op, &function->function.dispex, &function->this);
1308}
1309
1316};
1317
1320{
1321 BindFunction *function;
1322 HRESULT hres;
1323
1325 FALSE, NULL, (void**)&function);
1326 if(FAILED(hres))
1327 return hres;
1328
1329 jsdisp_addref(&target->dispex);
1330 function->target = target;
1331
1332 hres = jsval_copy(bound_this, &function->this);
1333 if(FAILED(hres)) {
1334 jsdisp_release(&function->function.dispex);
1335 return hres;
1336 }
1337
1338 for(function->argc = 0; function->argc < argc; function->argc++) {
1339 hres = jsval_copy(argv[function->argc], function->args + function->argc);
1340 if(FAILED(hres)) {
1341 jsdisp_release(&function->function.dispex);
1342 return hres;
1343 }
1344 }
1345
1346 function->function.length = target->length > argc ? target->length - argc : 0;
1347
1348 *ret = &function->function.dispex;
1349 return S_OK;
1350}
1351
1353{
1354 WCHAR *str = NULL, *ptr;
1355 unsigned len = 0, i = 0;
1357 jsdisp_t *function;
1358 jsstr_t **params = NULL;
1359 int j = 0;
1360 HRESULT hres = S_OK;
1361
1362 static const WCHAR function_anonymousW[] = L"function anonymous(";
1363 static const WCHAR function_beginW[] = L") {\n";
1364 static const WCHAR function_endW[] = L"\n}";
1365
1366 if(argc) {
1367 params = malloc(argc*sizeof(*params));
1368 if(!params)
1369 return E_OUTOFMEMORY;
1370
1371 if(argc > 2)
1372 len = (argc-2)*2; /* separating commas */
1373 for(i=0; i < argc; i++) {
1374 hres = to_string(ctx, argv[i], params+i);
1375 if(FAILED(hres))
1376 break;
1377 len += jsstr_length(params[i]);
1378 }
1379 }
1380
1381 if(SUCCEEDED(hres)) {
1382 len += ARRAY_SIZE(function_anonymousW) + ARRAY_SIZE(function_beginW) + ARRAY_SIZE(function_endW) - 2;
1383 str = malloc(len*sizeof(WCHAR));
1384 if(str) {
1385 memcpy(str, function_anonymousW, sizeof(function_anonymousW));
1386 ptr = str + ARRAY_SIZE(function_anonymousW) - 1;
1387 if(argc > 1) {
1388 while(1) {
1389 ptr += jsstr_flush(params[j], ptr);
1390 if(++j == argc-1)
1391 break;
1392 *ptr++ = ',';
1393 *ptr++ = ' ';
1394 }
1395 }
1396 memcpy(ptr, function_beginW, sizeof(function_beginW));
1397 ptr += ARRAY_SIZE(function_beginW) - 1;
1398 if(argc)
1399 ptr += jsstr_flush(params[argc-1], ptr);
1400 memcpy(ptr, function_endW, sizeof(function_endW));
1401
1402 TRACE("%s\n", debugstr_w(str));
1403 }else {
1405 }
1406 }
1407
1408 while(i)
1410 free(params);
1411 if(FAILED(hres))
1412 return hres;
1413
1415 ctx->call_ctx ? ctx->call_ctx->bytecode->named_item : NULL, &code);
1416 free(str);
1417 if(FAILED(hres))
1418 return hres;
1419
1420 if(code->global_code.func_cnt != 1 || code->global_code.var_cnt != 1) {
1421 ERR("Invalid parser result!\n");
1423 return E_UNEXPECTED;
1424 }
1425
1426 hres = create_source_function(ctx, code, code->global_code.funcs, NULL, &function);
1428 if(FAILED(hres))
1429 return hres;
1430
1431 *ret = to_disp(function);
1432 return S_OK;
1433}
1434
1436 jsval_t *r)
1437{
1438 HRESULT hres;
1439
1440 TRACE("\n");
1441
1442 switch(flags) {
1443 case DISPATCH_METHOD:
1444 case DISPATCH_CONSTRUCT: {
1445 IDispatch *ret;
1446
1448 if(FAILED(hres))
1449 return hres;
1450
1451 if(r) *r = jsval_disp(ret);
1452 else IDispatch_Release(ret);
1453 break;
1454 }
1455 default:
1456 FIXME("unimplemented flags %x\n", flags);
1457 return E_NOTIMPL;
1458 }
1459
1460 return S_OK;
1461}
1462
1464 jsval_t *r)
1465{
1466 FIXME("\n");
1467 return E_NOTIMPL;
1468}
1469
1471{
1472 return is_class(jsdisp, JSCLASS_FUNCTION) && function_from_jsdisp(jsdisp)->vtbl == &NativeFunctionVtbl &&
1474}
1475
1477{
1478 NativeFunction *prot, *constr;
1479 HRESULT hres;
1480
1482 TRUE, object_prototype, (void**)&prot);
1483 if(FAILED(hres))
1484 return hres;
1485
1486 prot->proc = FunctionProt_value;
1487 prot->name = L"prototype";
1488
1490 TRUE, &prot->function.dispex, (void**)&constr);
1491 if(SUCCEEDED(hres)) {
1492 constr->proc = FunctionConstr_value;
1493 constr->name = L"Function";
1494 hres = jsdisp_define_data_property(&constr->function.dispex, L"prototype", 0, jsval_obj(&prot->function.dispex));
1495 if(SUCCEEDED(hres))
1497 if(FAILED(hres))
1498 jsdisp_release(&constr->function.dispex);
1499 }
1501 if(FAILED(hres))
1502 return hres;
1503
1504 ctx->function_constr = &constr->function.dispex;
1505 return S_OK;
1506}
@ SCRIPTSTATE_UNINITIALIZED
Definition: activscp.idl:57
@ SCRIPTSTATE_CLOSED
Definition: activscp.idl:61
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:20
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UINT op
Definition: effect.c:236
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
unsigned int idx
Definition: utils.c:41
@ VT_EMPTY
Definition: compat.h:2295
#define lstrlenW
Definition: compat.h:750
void handle_dispatch_exception(script_ctx_t *ctx, EXCEPINFO *ei)
Definition: error.c:409
static const builtin_prop_t InterpretedFunction_props[]
Definition: function.c:859
static const builtin_info_t FunctionInst_info
Definition: function.c:702
static FunctionInstance * function_from_jsdisp(jsdisp_t *jsdisp)
Definition: function.c:93
BOOL is_builtin_eval_func(jsdisp_t *jsdisp)
Definition: function.c:1470
static function_code_t * HostFunction_get_code(FunctionInstance *function)
Definition: function.c:1050
static const builtin_info_t Function_info
Definition: function.c:687
static HRESULT InterpretedFunction_get_prototype(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:833
static HRESULT BindFunction_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op, FunctionInstance *func)
Definition: function.c:1291
static HRESULT Function_apply(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:455
static ULONG HostConstructor_addref(jsdisp_t *jsdisp)
Definition: function.c:1093
static const function_vtbl_t HostConstructorVtbl
Definition: function.c:1182
static HRESULT no_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op, FunctionInstance *function)
Definition: function.c:88
static void BindFunction_destructor(FunctionInstance *func)
Definition: function.c:1277
static HRESULT set_constructor_prop(script_ctx_t *ctx, jsdisp_t *constr, jsdisp_t *prot)
Definition: function.c:803
static FunctionInstance * function_this(jsval_t vthis)
Definition: function.c:98
static HRESULT FunctionConstr_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:1435
static const builtin_prop_t Arguments_props[]
Definition: function.c:231
static HRESULT Function_get_caller(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:344
static HRESULT HostFunction_call(script_ctx_t *ctx, FunctionInstance *func, jsval_t vthis, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:985
static HRESULT Arguments_prop_put(jsdisp_t *jsdisp, unsigned idx, jsval_t val)
Definition: function.c:163
HRESULT setup_arguments_object(script_ctx_t *ctx, call_frame_t *frame)
Definition: function.c:259
static HRESULT create_bind_function(script_ctx_t *, FunctionInstance *, jsval_t, unsigned, jsval_t *, jsdisp_t **r)
Definition: function.c:1318
static HRESULT native_function_string(const WCHAR *name, jsstr_t **ret)
Definition: function.c:372
static HRESULT HostFunction_toString(FunctionInstance *func, jsstr_t **ret)
Definition: function.c:1044
static HRESULT array_to_args(script_ctx_t *ctx, jsdisp_t *arg_array, unsigned *argc, jsval_t **ret)
Definition: function.c:419
static HRESULT Function_get_arguments(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:631
static const function_vtbl_t HostFunctionVtbl
Definition: function.c:1064
static const builtin_prop_t Function_props[]
Definition: function.c:677
static HRESULT Arguments_prop_get(jsdisp_t *jsdisp, unsigned idx, jsval_t *r)
Definition: function.c:154
static void NativeFunction_destructor(FunctionInstance *function)
Definition: function.c:761
function_code_t * Function_get_code(jsdisp_t *jsthis)
Definition: function.c:655
static HRESULT BindFunction_get_caller(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:1218
static HRESULT Arguments_get_caller(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:204
static const builtin_info_t Arguments_info
Definition: function.c:235
HRESULT init_host_constructor(script_ctx_t *ctx, IWineJSDispatchHost *host_constr, IWineJSDispatch *prototype, IWineJSDispatch **ret)
Definition: function.c:1190
static const function_vtbl_t InterpretedFunctionVtbl
Definition: function.c:945
static HRESULT BindFunction_get_arguments(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:1213
static const builtin_info_t InterpretedFunction_info
Definition: function.c:866
HRESULT create_source_function(script_ctx_t *ctx, bytecode_t *code, function_code_t *func_code, scope_chain_t *scope_chain, jsdisp_t **ret)
Definition: function.c:953
static HRESULT HostFunction_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op, FunctionInstance *func)
Definition: function.c:1059
static HRESULT NativeFunction_toString(FunctionInstance *func, jsstr_t **ret)
Definition: function.c:750
static const function_vtbl_t BindFunctionVtbl
Definition: function.c:1310
static ArgumentsInstance * arguments_from_jsdisp(jsdisp_t *jsdisp)
Definition: function.c:104
static const builtin_info_t HostFunction_info
Definition: function.c:978
static const builtin_prop_t FunctionInst_props[]
Definition: function.c:696
static HRESULT InterpretedFunction_toString(FunctionInstance *func, jsstr_t **ret)
Definition: function.c:911
static HRESULT InterpretedFunction_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op, FunctionInstance *func)
Definition: function.c:935
static function_code_t * NativeFunction_get_code(FunctionInstance *function)
Definition: function.c:756
static const builtin_info_t HostConstructor_info
Definition: function.c:1113
static HRESULT Arguments_lookup_prop(jsdisp_t *jsdisp, const WCHAR *name, unsigned flags, struct property_info *desc)
Definition: function.c:133
static HRESULT HostConstructor_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op, FunctionInstance *func)
Definition: function.c:1177
static HRESULT HostConstructor_call(script_ctx_t *ctx, FunctionInstance *func, jsval_t vthis, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:1123
static void Function_destructor(jsdisp_t *dispex)
Definition: function.c:665
static void HostConstructor_destructor(FunctionInstance *func)
Definition: function.c:1173
static HRESULT Function_call(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:527
static const builtin_info_t Arguments_ES5_info
Definition: function.c:248
HRESULT Function_invoke(jsdisp_t *func_this, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:327
static function_code_t * BindFunction_get_code(FunctionInstance *function)
Definition: function.c:1272
static void InterpretedFunction_destructor(FunctionInstance *func)
Definition: function.c:926
HRESULT Function_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:615
static HRESULT create_function(script_ctx_t *ctx, const builtin_info_t *builtin_info, const function_vtbl_t *vtbl, size_t size, DWORD flags, BOOL funcprot, jsdisp_t *prototype, void **ret)
Definition: function.c:711
static HRESULT HostConstructor_lookup_prop(jsdisp_t *jsdisp, const WCHAR *name, unsigned flags, struct property_info *desc)
Definition: function.c:1105
static const function_vtbl_t NativeFunctionVtbl
Definition: function.c:765
static HRESULT Function_bind(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:563
static HRESULT Function_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:396
static void Arguments_destructor(jsdisp_t *jsdisp)
Definition: function.c:116
static HRESULT Arguments_next_prop(jsdisp_t *jsdisp, unsigned id, struct property_info *desc)
Definition: function.c:139
static ULONG HostConstructor_release(jsdisp_t *jsdisp)
Definition: function.c:1099
static HRESULT Function_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op, jsdisp_t *dispex)
Definition: function.c:671
static function_code_t * HostConstructor_get_code(FunctionInstance *function)
Definition: function.c:1168
HRESULT create_host_function(script_ctx_t *ctx, const struct property_info *desc, DWORD flags, jsdisp_t **ret)
Definition: function.c:1072
HRESULT init_function_constr(script_ctx_t *ctx, jsdisp_t *object_prototype)
Definition: function.c:1476
static HRESULT BindFunction_toString(FunctionInstance *function, jsstr_t **ret)
Definition: function.c:1266
static HRESULT construct_function(script_ctx_t *ctx, unsigned argc, jsval_t *argv, IDispatch **ret)
Definition: function.c:1352
HRESULT create_builtin_constructor(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
Definition: function.c:809
static void HostFunction_destructor(FunctionInstance *func)
Definition: function.c:1055
static HRESULT Arguments_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op, jsdisp_t *jsdisp)
Definition: function.c:181
static HRESULT Arguments_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:109
void detach_arguments_object(call_frame_t *frame)
Definition: function.c:293
HRESULT Function_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:600
static HRESULT Function_get_length(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
Definition: function.c:364
static HRESULT NativeFunction_call(script_ctx_t *ctx, FunctionInstance *func, jsval_t vthis, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:740
static const builtin_prop_t BindFunction_props[]
Definition: function.c:1223
static HRESULT InterpretedFunction_set_prototype(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t value)
Definition: function.c:854
static HRESULT InterpretedFunction_call(script_ctx_t *ctx, FunctionInstance *func, jsval_t vthis, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:875
static HRESULT HostConstructor_toString(FunctionInstance *function, jsstr_t **ret)
Definition: function.c:1162
static jsval_t * get_argument_ref(ArgumentsInstance *arguments, unsigned idx)
Definition: function.c:145
static HRESULT FunctionProt_value(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:1463
static HRESULT BindFunction_call(script_ctx_t *ctx, FunctionInstance *func, jsval_t vthis, unsigned flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: function.c:1238
HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc, const WCHAR *name, const builtin_info_t *builtin_info, DWORD flags, jsdisp_t *prototype, jsdisp_t **ret)
Definition: function.c:773
static function_code_t * InterpretedFunction_get_code(FunctionInstance *func)
Definition: function.c:919
static const builtin_info_t BindFunction_info
Definition: function.c:1229
MonoAssembly int argc
Definition: metahost.c:107
#define assert(_expr)
Definition: assert.h:32
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
IDispatch * lookup_global_host(script_ctx_t *ctx)
Definition: engine.c:845
HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, function_code_t *function, scope_chain_t *scope, IDispatch *this_obj, jsdisp_t *function_instance, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: engine.c:3425
static scope_chain_t * scope_addref(scope_chain_t *scope)
Definition: engine.h:242
static void scope_release(scope_chain_t *scope)
Definition: engine.h:248
#define EXEC_RETURN_TO_INTERP
Definition: engine.h:307
#define EXEC_CONSTRUCTOR
Definition: engine.h:306
static bytecode_t * bytecode_addref(bytecode_t *code)
Definition: engine.h:221
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum func
Definition: glext.h:6028
GLuint res
Definition: glext.h:9613
GLsizeiptr size
Definition: glext.h:5919
GLenum const GLfloat * params
Definition: glext.h:5645
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static HRESULT to_string(VARIANT *src, BSTR *dst)
Definition: host.c:46
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
void release_bytecode(bytecode_t *code)
Definition: compile.c:2459
HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, UINT64 source_context, unsigned start_line, const WCHAR *args, const WCHAR *delimiter, BOOL from_eval, BOOL use_decode, named_item_t *named_item, bytecode_t **ret)
Definition: compile.c:2725
HRESULT jsdisp_define_data_property(jsdisp_t *obj, const WCHAR *name, unsigned flags, jsval_t value)
Definition: dispex.c:3349
HRESULT jsdisp_propput_name(jsdisp_t *obj, const WCHAR *name, jsval_t val)
Definition: dispex.c:2859
HRESULT jsdisp_propput(jsdisp_t *obj, const WCHAR *name, DWORD flags, BOOL throw, jsval_t val)
Definition: dispex.c:2842
HRESULT init_dispex_from_constr(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *constr)
Definition: dispex.c:2512
jsdisp_t * iface_to_jsdisp(IDispatch *iface)
Definition: dispex.c:2543
HRESULT gc_process_linked_val(struct gc_ctx *gc_ctx, enum gc_traverse_op op, jsdisp_t *obj, jsval_t *link)
Definition: dispex.c:1139
ULONG jsdisp_release(jsdisp_t *obj)
Definition: dispex.c:1911
HRESULT gc_process_linked_obj(struct gc_ctx *gc_ctx, enum gc_traverse_op op, jsdisp_t *obj, jsdisp_t *link, void **unlink_ref)
Definition: dispex.c:1124
HRESULT jsdisp_index_lookup(jsdisp_t *obj, const WCHAR *name, unsigned length, struct property_info *desc)
Definition: dispex.c:481
jsdisp_t * as_jsdisp(IDispatch *disp)
Definition: dispex.c:2441
HRESULT jsdisp_get_idx(jsdisp_t *obj, DWORD idx, jsval_t *r)
Definition: dispex.c:2963
IWineJSDispatchHost * get_host_dispatch(IDispatch *disp)
Definition: dispex.c:3584
HRESULT init_dispex(jsdisp_t *dispex, script_ctx_t *ctx, const builtin_info_t *builtin_info, jsdisp_t *prototype)
Definition: dispex.c:2454
HRESULT jsdisp_propget_name(jsdisp_t *obj, const WCHAR *name, jsval_t *val)
Definition: dispex.c:2946
jsdisp_t * jsdisp_addref(jsdisp_t *obj)
Definition: dispex.c:1902
jsdisp_t * to_jsdisp(IDispatch *disp)
Definition: dispex.c:2447
HRESULT jsdisp_next_index(jsdisp_t *obj, unsigned length, unsigned id, struct property_info *desc)
Definition: dispex.c:504
HRESULT JSGlobal_eval(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: global.c:180
#define DISPATCH_JSCRIPT_CALLEREXECSSOURCE
Definition: jscript.h:98
#define PROPF_ES5
Definition: jscript.h:90
#define PROPF_ARGMASK
Definition: jscript.h:86
#define JS_E_OBJECT_REQUIRED
Definition: jscript.h:530
HRESULT create_object(script_ctx_t *, jsdisp_t *, jsdisp_t **)
Definition: object.c:1131
HRESULT to_uint32(script_ctx_t *, jsval_t, UINT32 *)
Definition: jsutils.c:754
#define SCRIPTLANGUAGEVERSION_ES5
Definition: jscript.h:53
#define JS_E_FUNCTION_EXPECTED
Definition: jscript.h:552
HRESULT(* builtin_invoke_t)(script_ctx_t *, jsval_t, WORD, unsigned, jsval_t *, jsval_t *)
Definition: jscript.h:129
static HRESULT disp_call_value(script_ctx_t *ctx, IDispatch *disp, jsval_t vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
Definition: jscript.h:518
static IDispatch * to_disp(jsdisp_t *jsdisp)
Definition: jscript.h:222
const char * debugstr_jsval(const jsval_t)
Definition: jsutils.c:35
HRESULT to_object(script_ctx_t *, jsval_t, IDispatch **)
Definition: jsutils.c:864
@ JSCLASS_ARGUMENTS
Definition: jscript.h:116
@ JSCLASS_FUNCTION
Definition: jscript.h:109
@ JSCLASS_ARRAY
Definition: jscript.h:104
gc_traverse_op
Definition: jscript.h:161
#define JS_E_INVALID_ACTION
Definition: jscript.h:533
struct _jsval_t jsval_t
Definition: jscript.h:56
#define PROPF_HTML
Definition: jscript.h:89
static BOOL is_class(jsdisp_t *jsdisp, jsclass_t class)
Definition: jscript.h:503
#define DISPATCH_JSCRIPT_INTERNAL_MASK
Definition: jscript.h:99
const unsigned int PROPF_WRITABLE
Definition: jsdisp.idl:37
const unsigned int PROPF_CONFIGURABLE
Definition: jsdisp.idl:38
const unsigned int PROPF_METHOD
Definition: jsdisp.idl:33
const unsigned int PROPF_CONSTR
Definition: jsdisp.idl:34
jsstr_t * jsstr_alloc_len(const WCHAR *buf, unsigned len)
Definition: jsstr.c:86
jsstr_t * jsstr_alloc_buf(unsigned len, WCHAR **buf)
Definition: jsstr.c:69
static void jsstr_release(jsstr_t *str)
Definition: jsstr.h:107
static unsigned jsstr_length(jsstr_t *str)
Definition: jsstr.h:55
static unsigned jsstr_flush(jsstr_t *str, WCHAR *buf)
Definition: jsstr.h:145
static jsstr_t * jsstr_alloc(const WCHAR *str)
Definition: jsstr.h:100
HRESULT jsval_copy(jsval_t v, jsval_t *r)
Definition: jsutils.c:225
HRESULT variant_to_jsval(script_ctx_t *ctx, VARIANT *var, jsval_t *r)
Definition: jsutils.c:251
void jsval_release(jsval_t val)
Definition: jsutils.c:186
HRESULT jsval_to_variant(jsval_t val, VARIANT *retv)
Definition: jsutils.c:367
static jsval_t jsval_null(void)
Definition: jsval.h:130
static jsval_t jsval_string(jsstr_t *str)
Definition: jsval.h:109
static jsval_t jsval_undefined(void)
Definition: jsval.h:146
static jsval_t jsval_obj(jsdisp_t *obj)
Definition: jsval.h:125
static BOOL is_null_disp(jsval_t v)
Definition: jsval.h:190
static BOOL is_undefined(jsval_t v)
Definition: jsval.h:180
static jsval_t jsval_disp(IDispatch *obj)
Definition: jsval.h:117
static IDispatch * get_object(jsval_t v)
Definition: jsval.h:228
static BOOL is_object_instance(jsval_t v)
Definition: jsval.h:175
static BOOL is_null(jsval_t v)
Definition: jsval.h:185
static jsval_t jsval_number(double n)
Definition: jsval.h:153
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1204
HRESULT hres
Definition: protocol.c:465
static unsigned(__cdecl *hash_bstr)(bstr_t s)
#define argv
Definition: mplay32.c:18
#define DISPATCH_METHOD
Definition: oleauto.h:1006
#define V_VT(A)
Definition: oleauto.h:211
static HANDLE proc()
Definition: pdb.c:32
short WCHAR
Definition: pedump.c:58
#define calloc
Definition: rosglue.h:14
const WCHAR * str
#define args
Definition: format.c:66
#define TRACE(s)
Definition: solgame.cpp:4
scope_chain_t * scope
Definition: function.c:82
jsdisp_t jsdisp
Definition: function.c:80
jsval_t * buf
Definition: function.c:81
unsigned argc
Definition: function.c:83
unsigned argc
Definition: function.c:62
jsval_t this
Definition: function.c:61
FunctionInstance * target
Definition: function.c:60
FunctionInstance function
Definition: function.c:59
jsval_t args[1]
Definition: function.c:63
const function_vtbl_t * vtbl
Definition: function.c:32
jsdisp_t dispex
Definition: function.c:31
FunctionInstance function
Definition: function.c:75
IWineJSDispatchHost * host_iface
Definition: function.c:76
UINT32 iid
Definition: function.c:70
const WCHAR * name
Definition: function.c:68
UINT32 id
Definition: function.c:69
UINT32 flags
Definition: function.c:71
FunctionInstance function
Definition: function.c:67
FunctionInstance function
Definition: function.c:46
bytecode_t * code
Definition: function.c:48
function_code_t * func_code
Definition: function.c:49
scope_chain_t * scope_chain
Definition: function.c:47
FunctionInstance function
Definition: function.c:53
const WCHAR * name
Definition: function.c:55
builtin_invoke_t proc
Definition: function.c:54
struct _call_frame_t * prev_frame
Definition: engine.h:302
unsigned argc
Definition: engine.h:293
jsdisp_t * arguments_obj
Definition: engine.h:290
scope_chain_t * base_scope
Definition: engine.h:283
unsigned arguments_off
Definition: engine.h:295
jsdisp_t * function_instance
Definition: engine.h:288
unsigned source_len
Definition: engine.h:166
unsigned param_cnt
Definition: engine.h:177
const WCHAR * source
Definition: engine.h:165
HRESULT(* gc_traverse)(struct gc_ctx *, enum gc_traverse_op, FunctionInstance *)
Definition: function.c:42
HRESULT(* toString)(FunctionInstance *, jsstr_t **)
Definition: function.c:39
function_code_t *(* get_code)(FunctionInstance *)
Definition: function.c:40
HRESULT(* call)(script_ctx_t *, FunctionInstance *, jsval_t, unsigned, unsigned, jsval_t *, jsval_t *)
Definition: function.c:38
void(* destructor)(FunctionInstance *)
Definition: function.c:41
Definition: jsstr.h:36
Definition: jsval.h:54
IDispatch * obj
Definition: engine.h:235
struct _call_frame_t * frame
Definition: engine.h:238
struct vars_buffer * detached_vars
Definition: engine.h:237
jsdisp_t dispex
Definition: engine.h:234
BOOL html_mode
Definition: jscript.h:396
SCRIPTSTATE state
Definition: jscript.h:386
jsval_t * stack
Definition: jscript.h:404
Definition: match.c:390
jsclass_t class
Definition: jscript.h:183
Definition: inflate.c:139
Definition: dispex.c:889
LONG ref
Definition: jscript.h:204
IWineJSDispatch IWineJSDispatch_iface
Definition: jscript.h:202
script_ctx_t * ctx
Definition: jscript.h:214
Definition: name.c:39
Definition: send.c:48
Definition: tools.h:99
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t UINT32
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59
Definition: pdh_main.c:96
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
_In_ size_t cnt
Definition: wcstombs.cpp:43
#define HRESULT
Definition: msvc.h:7
#define E_UNEXPECTED
Definition: winerror.h:3528
#define DISP_E_EXCEPTION
Definition: winerror.h:3621
#define DISP_E_UNKNOWNNAME
Definition: winerror.h:3618