static HRESULT create_function(script_ctx_t *ctx, const builtin_info_t *builtin_info, DWORD flags, BOOL funcprot, jsdisp_t *prototype, FunctionInstance **ret) { FunctionInstance *function; HRESULT hres; function = heap_alloc_zero(sizeof(FunctionInstance)); if(!function) return E_OUTOFMEMORY; if(funcprot) hres = init_dispex(&function->dispex, ctx, builtin_info, prototype); else if(builtin_info) hres = init_dispex_from_constr(&function->dispex, ctx, builtin_info, ctx->function_constr); else hres = init_dispex_from_constr(&function->dispex, ctx, &FunctionInst_info, ctx->function_constr); if(FAILED(hres)) { heap_free(function); return hres; } function->flags = flags; function->length = flags & PROPF_ARGMASK; *ret = function; return S_OK; }
static HRESULT create_arguments(script_ctx_t *ctx, FunctionInstance *calee, jsdisp_t *var_obj, unsigned argc, jsval_t *argv, jsdisp_t **ret) { ArgumentsInstance *args; unsigned i; HRESULT hres; static const WCHAR caleeW[] = {'c','a','l','l','e','e',0}; args = heap_alloc_zero(sizeof(*args)); if(!args) return E_OUTOFMEMORY; hres = init_dispex_from_constr(&args->jsdisp, ctx, &Arguments_info, ctx->object_constr); if(FAILED(hres)) { heap_free(args); return hres; } jsdisp_addref(&calee->dispex); args->function = calee; args->var_obj = jsdisp_addref(var_obj); /* Store unnamed arguments directly in arguments object */ for(i = calee->length; i < argc; i++) { WCHAR buf[12]; static const WCHAR formatW[] = {'%','d',0}; sprintfW(buf, formatW, i); hres = jsdisp_propput_dontenum(&args->jsdisp, buf, argv[i]); if(FAILED(hres)) break; } if(SUCCEEDED(hres)) { hres = jsdisp_propput_dontenum(&args->jsdisp, lengthW, jsval_number(argc)); if(SUCCEEDED(hres)) hres = jsdisp_propput_dontenum(&args->jsdisp, caleeW, jsval_disp(to_disp(&calee->dispex))); } if(FAILED(hres)) { jsdisp_release(&args->jsdisp); return hres; } *ret = &args->jsdisp; return S_OK; }
static HRESULT create_arguments(script_ctx_t *ctx, IDispatch *calee, DISPPARAMS *dp, jsexcept_t *ei, IServiceProvider *caller, DispatchEx **ret) { DispatchEx *args; VARIANT var; DWORD i; HRESULT hres; static const WCHAR caleeW[] = {'c','a','l','l','e','e',0}; args = heap_alloc_zero(sizeof(DispatchEx)); if(!args) return E_OUTOFMEMORY; hres = init_dispex_from_constr(args, ctx, &Arguments_info, ctx->object_constr); if(FAILED(hres)) { heap_free(args); return hres; } for(i=0; i < arg_cnt(dp); i++) { hres = jsdisp_propput_idx(args, i, get_arg(dp,i), ei, caller); if(FAILED(hres)) break; } if(SUCCEEDED(hres)) { V_VT(&var) = VT_I4; V_I4(&var) = arg_cnt(dp); hres = jsdisp_propput_name(args, lengthW, &var, ei, caller); if(SUCCEEDED(hres)) { V_VT(&var) = VT_DISPATCH; V_DISPATCH(&var) = calee; hres = jsdisp_propput_name(args, caleeW, &var, ei, caller); } } if(FAILED(hres)) { jsdisp_release(args); return hres; } *ret = args; return S_OK; }
HRESULT create_json(script_ctx_t *ctx, jsdisp_t **ret) { jsdisp_t *json; HRESULT hres; json = heap_alloc_zero(sizeof(*json)); if(!json) return E_OUTOFMEMORY; hres = init_dispex_from_constr(json, ctx, &JSON_info, ctx->object_constr); if(FAILED(hres)) { heap_free(json); return hres; } *ret = json; return S_OK; }
HRESULT create_math(script_ctx_t *ctx, jsdisp_t **ret) { jsdisp_t *math; unsigned i; VARIANT v; HRESULT hres; struct { const WCHAR *name; DOUBLE val; }constants[] = { {EW, M_E}, /* ECMA-262 3rd Edition 15.8.1.1 */ {LN10W, M_LN10}, /* ECMA-262 3rd Edition 15.8.1.2 */ {LN2W, M_LN2}, /* ECMA-262 3rd Edition 15.8.1.3 */ {LOG2EW, M_LOG2E}, /* ECMA-262 3rd Edition 15.8.1.4 */ {LOG10EW, M_LOG10E}, /* ECMA-262 3rd Edition 15.8.1.5 */ {PIW, M_PI}, /* ECMA-262 3rd Edition 15.8.1.6 */ {SQRT1_2W, M_SQRT1_2}, /* ECMA-262 3rd Edition 15.8.1.7 */ {SQRT2W, M_SQRT2}, /* ECMA-262 3rd Edition 15.8.1.8 */ }; math = heap_alloc_zero(sizeof(jsdisp_t)); if(!math) return E_OUTOFMEMORY; hres = init_dispex_from_constr(math, ctx, &Math_info, ctx->object_constr); if(FAILED(hres)) { heap_free(math); return hres; } V_VT(&v) = VT_R8; for(i=0; i < sizeof(constants)/sizeof(*constants); i++) { V_R8(&v) = constants[i].val; hres = jsdisp_propput_const(math, constants[i].name, &v); if(FAILED(hres)) { jsdisp_release(math); return hres; } } *ret = math; return S_OK; }
static HRESULT alloc_number(script_ctx_t *ctx, jsdisp_t *object_prototype, NumberInstance **ret) { NumberInstance *number; HRESULT hres; number = heap_alloc_zero(sizeof(NumberInstance)); if(!number) return E_OUTOFMEMORY; if(object_prototype) hres = init_dispex(&number->dispex, ctx, &Number_info, object_prototype); else hres = init_dispex_from_constr(&number->dispex, ctx, &Number_info, ctx->number_constr); if(FAILED(hres)) return hres; *ret = number; return S_OK; }
static HRESULT alloc_array(script_ctx_t *ctx, jsdisp_t *object_prototype, ArrayInstance **ret) { ArrayInstance *array; HRESULT hres; array = heap_alloc_zero(sizeof(ArrayInstance)); if(!array) return E_OUTOFMEMORY; if(object_prototype) hres = init_dispex(&array->dispex, ctx, &Array_info, object_prototype); else hres = init_dispex_from_constr(&array->dispex, ctx, &Array_info, ctx->array_constr); if(FAILED(hres)) { heap_free(array); return hres; } *ret = array; return S_OK; }
static HRESULT create_arguments(script_ctx_t *ctx, IDispatch *calee, unsigned argc, jsval_t *argv, jsdisp_t **ret) { jsdisp_t *args; DWORD i; HRESULT hres; static const WCHAR caleeW[] = {'c','a','l','l','e','e',0}; args = heap_alloc_zero(sizeof(jsdisp_t)); if(!args) return E_OUTOFMEMORY; hres = init_dispex_from_constr(args, ctx, &Arguments_info, ctx->object_constr); if(FAILED(hres)) { heap_free(args); return hres; } for(i=0; i < argc; i++) { hres = jsdisp_propput_idx(args, i, argv[i]); if(FAILED(hres)) break; } if(SUCCEEDED(hres)) { hres = jsdisp_propput_name(args, lengthW, jsval_number(argc)); if(SUCCEEDED(hres)) hres = jsdisp_propput_name(args, caleeW, jsval_disp(calee)); } if(FAILED(hres)) { jsdisp_release(args); return hres; } *ret = args; return S_OK; }
static HRESULT alloc_regexp(script_ctx_t *ctx, jsdisp_t *object_prototype, RegExpInstance **ret) { RegExpInstance *regexp; HRESULT hres; regexp = heap_alloc_zero(sizeof(RegExpInstance)); if(!regexp) return E_OUTOFMEMORY; if(object_prototype) hres = init_dispex(®exp->dispex, ctx, &RegExp_info, object_prototype); else hres = init_dispex_from_constr(®exp->dispex, ctx, &RegExpInst_info, ctx->regexp_constr); if(FAILED(hres)) { heap_free(regexp); return hres; } *ret = regexp; return S_OK; }
static HRESULT string_alloc(script_ctx_t *ctx, jsdisp_t *object_prototype, jsstr_t *str, StringInstance **ret) { StringInstance *string; HRESULT hres; string = heap_alloc_zero(sizeof(StringInstance)); if(!string) return E_OUTOFMEMORY; if(object_prototype) hres = init_dispex(&string->dispex, ctx, &String_info, object_prototype); else hres = init_dispex_from_constr(&string->dispex, ctx, &StringInst_info, ctx->string_constr); if(FAILED(hres)) { heap_free(string); return hres; } string->str = jsstr_addref(str); *ret = string; return S_OK; }
static HRESULT alloc_error(script_ctx_t *ctx, DispatchEx *prototype, DispatchEx *constr, ErrorInstance **ret) { ErrorInstance *err; HRESULT hres; err = heap_alloc_zero(sizeof(ErrorInstance)); if(!err) return E_OUTOFMEMORY; if(prototype) hres = init_dispex(&err->dispex, ctx, &Error_info, prototype); else hres = init_dispex_from_constr(&err->dispex, ctx, &ErrorInst_info, constr ? constr : ctx->error_constr); if(FAILED(hres)) { heap_free(err); return hres; } *ret = err; return S_OK; }
static HRESULT alloc_error(script_ctx_t *ctx, jsdisp_t *prototype, jsdisp_t *constr, jsdisp_t **ret) { jsdisp_t *err; HRESULT hres; err = heap_alloc_zero(sizeof(*err)); if(!err) return E_OUTOFMEMORY; if(prototype) hres = init_dispex(err, ctx, &Error_info, prototype); else hres = init_dispex_from_constr(err, ctx, &ErrorInst_info, constr ? constr : ctx->error_constr); if(FAILED(hres)) { heap_free(err); return hres; } *ret = err; return S_OK; }
static HRESULT create_function(script_ctx_t *ctx, DWORD flags, BOOL funcprot, DispatchEx *prototype, FunctionInstance **ret) { FunctionInstance *function; HRESULT hres; function = heap_alloc_zero(sizeof(FunctionInstance)); if(!function) return E_OUTOFMEMORY; if(funcprot) hres = init_dispex(&function->dispex, ctx, &Function_info, prototype); else hres = init_dispex_from_constr(&function->dispex, ctx, &Function_info, ctx->function_constr); if(FAILED(hres)) return hres; function->flags = flags; function->length = flags & PROPF_ARGMASK; if(prototype) { jsexcept_t jsexcept; VARIANT var; V_VT(&var) = VT_DISPATCH; V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(prototype); memset(&jsexcept, 0, sizeof(jsexcept)); hres = jsdisp_propput_name(&function->dispex, prototypeW, ctx->lcid, &var, &jsexcept, NULL/*FIXME*/); if(FAILED(hres)) { IDispatchEx_Release(_IDispatchEx_(&function->dispex)); return hres; } } *ret = function; return S_OK; }
static HRESULT alloc_enumerator(script_ctx_t *ctx, jsdisp_t *object_prototype, EnumeratorInstance **ret) { EnumeratorInstance *enumerator; HRESULT hres; enumerator = heap_alloc_zero(sizeof(EnumeratorInstance)); if(!enumerator) return E_OUTOFMEMORY; if(object_prototype) hres = init_dispex(&enumerator->dispex, ctx, &Enumerator_info, object_prototype); else hres = init_dispex_from_constr(&enumerator->dispex, ctx, &EnumeratorInst_info, ctx->enumerator_constr); if(FAILED(hres)) { heap_free(enumerator); return hres; } *ret = enumerator; return S_OK; }