static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { FunctionInstance *function; IDispatch *this_obj = NULL; unsigned cnt = 0; HRESULT hres; TRACE("\n"); if(!(function = function_this(jsthis))) return throw_type_error(ctx, JS_E_FUNCTION_EXPECTED, NULL); if(argc) { if(!is_undefined(argv[0]) && !is_null(argv[0])) { hres = to_object(ctx, argv[0], &this_obj); if(FAILED(hres)) return hres; } cnt = argc-1; } hres = call_function(ctx, function, this_obj, cnt, argv+1, r); if(this_obj) IDispatch_Release(this_obj); return hres; }
static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) { FunctionInstance *function; DISPPARAMS args = {NULL,NULL,0,0}; DWORD argc, i; IDispatch *this_obj = NULL; HRESULT hres = S_OK; TRACE("\n"); if(!(function = function_this(jsthis))) return throw_type_error(ctx, ei, JS_E_FUNCTION_EXPECTED, NULL); argc = arg_cnt(dp); if(argc) { VARIANT *v = get_arg(dp,0); if(V_VT(v) != VT_EMPTY && V_VT(v) != VT_NULL) { hres = to_object(ctx, v, &this_obj); if(FAILED(hres)) return hres; } } if(argc >= 2) { jsdisp_t *arg_array = NULL; if(V_VT(get_arg(dp,1)) == VT_DISPATCH) { arg_array = iface_to_jsdisp((IUnknown*)V_DISPATCH(get_arg(dp,1))); if(arg_array && (!is_class(arg_array, JSCLASS_ARRAY) && !is_class(arg_array, JSCLASS_ARGUMENTS) )) { jsdisp_release(arg_array); arg_array = NULL; } } if(arg_array) { hres = array_to_args(ctx, arg_array, ei, caller, &args); jsdisp_release(arg_array); }else { FIXME("throw TypeError\n"); hres = E_FAIL; } } if(SUCCEEDED(hres)) hres = call_function(ctx, function, this_obj, &args, retv, ei, caller); if(this_obj) IDispatch_Release(this_obj); for(i=0; i<args.cArgs; i++) VariantClear(args.rgvarg+i); heap_free(args.rgvarg); return hres; }
static HRESULT Function_apply(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { FunctionInstance *function; jsval_t *args = NULL; unsigned i, cnt = 0; IDispatch *this_obj = NULL; HRESULT hres = S_OK; TRACE("\n"); if(!(function = function_this(jsthis))) return throw_type_error(ctx, JS_E_FUNCTION_EXPECTED, NULL); if(argc) { if(!is_undefined(argv[0]) && !is_null(argv[0])) { hres = to_object(ctx, argv[0], &this_obj); if(FAILED(hres)) return hres; } } if(argc >= 2) { jsdisp_t *arg_array = NULL; if(is_object_instance(argv[1])) { arg_array = iface_to_jsdisp((IUnknown*)get_object(argv[1])); if(arg_array && (!is_class(arg_array, JSCLASS_ARRAY) && !is_class(arg_array, JSCLASS_ARGUMENTS) )) { jsdisp_release(arg_array); arg_array = NULL; } } if(arg_array) { hres = array_to_args(ctx, arg_array, &cnt, &args); jsdisp_release(arg_array); }else { FIXME("throw TypeError\n"); hres = E_FAIL; } } if(SUCCEEDED(hres)) hres = call_function(ctx, function, this_obj, cnt, args, r); if(this_obj) IDispatch_Release(this_obj); for(i=0; i < cnt; i++) jsval_release(args[i]); heap_free(args); return hres; }
static HRESULT Function_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { FunctionInstance *function; jsstr_t *str; HRESULT hres; TRACE("\n"); if(!(function = function_this(jsthis))) return throw_type_error(ctx, JS_E_FUNCTION_EXPECTED, NULL); hres = function_to_string(function, &str); if(FAILED(hres)) return hres; if(r) *r = jsval_string(str); else jsstr_release(str); return S_OK; }
static HRESULT Function_call(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) { FunctionInstance *function; DISPPARAMS args = {NULL,NULL,0,0}; IDispatch *this_obj = NULL; DWORD argc; HRESULT hres; TRACE("\n"); if(!(function = function_this(jsthis))) return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); argc = arg_cnt(dp); if(argc) { VARIANT *v = get_arg(dp,0); if(V_VT(v) != VT_EMPTY && V_VT(v) != VT_NULL) { hres = to_object(ctx, v, &this_obj); if(FAILED(hres)) return hres; } args.cArgs = argc-1; } if(args.cArgs) args.rgvarg = dp->rgvarg + dp->cArgs - args.cArgs-1; hres = call_function(ctx, function, this_obj, &args, retv, ei, caller); if(this_obj) IDispatch_Release(this_obj); return hres; }
static HRESULT Function_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { FunctionInstance *function; BSTR str; HRESULT hres; TRACE("\n"); if(!(function = function_this(jsthis))) return throw_type_error(ctx, ei, IDS_NOT_FUNC, NULL); hres = function_to_string(function, &str); if(FAILED(hres)) return hres; if(retv) { V_VT(retv) = VT_BSTR; V_BSTR(retv) = str; }else { SysFreeString(str); } return S_OK; }