static HRESULT create_error(script_ctx_t *ctx, jsdisp_t *constr, UINT number, jsstr_t *msg, jsdisp_t **ret) { jsdisp_t *err; HRESULT hres; hres = alloc_error(ctx, NULL, constr, &err); if(FAILED(hres)) return hres; hres = jsdisp_propput_dontenum(err, numberW, jsval_number((INT)number)); if(FAILED(hres)) { jsdisp_release(err); return hres; } hres = jsdisp_propput_name(err, messageW, jsval_string(msg)); if(SUCCEEDED(hres)) hres = jsdisp_propput_dontenum(err, descriptionW, jsval_string(msg)); if(FAILED(hres)) { jsdisp_release(err); return hres; } *ret = err; 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; }
HRESULT init_error_constr(script_ctx_t *ctx, jsdisp_t *object_prototype) { static const WCHAR ErrorW[] = {'E','r','r','o','r',0}; static const WCHAR EvalErrorW[] = {'E','v','a','l','E','r','r','o','r',0}; static const WCHAR RangeErrorW[] = {'R','a','n','g','e','E','r','r','o','r',0}; static const WCHAR ReferenceErrorW[] = {'R','e','f','e','r','e','n','c','e','E','r','r','o','r',0}; static const WCHAR RegExpErrorW[] = {'R','e','g','E','x','p','E','r','r','o','r',0}; static const WCHAR SyntaxErrorW[] = {'S','y','n','t','a','x','E','r','r','o','r',0}; static const WCHAR TypeErrorW[] = {'T','y','p','e','E','r','r','o','r',0}; static const WCHAR URIErrorW[] = {'U','R','I','E','r','r','o','r',0}; static const WCHAR *names[] = {ErrorW, EvalErrorW, RangeErrorW, ReferenceErrorW, RegExpErrorW, SyntaxErrorW, TypeErrorW, URIErrorW}; jsdisp_t **constr_addr[] = {&ctx->error_constr, &ctx->eval_error_constr, &ctx->range_error_constr, &ctx->reference_error_constr, &ctx->regexp_error_constr, &ctx->syntax_error_constr, &ctx->type_error_constr, &ctx->uri_error_constr}; static builtin_invoke_t constr_val[] = {ErrorConstr_value, EvalErrorConstr_value, RangeErrorConstr_value, ReferenceErrorConstr_value, RegExpErrorConstr_value, SyntaxErrorConstr_value, TypeErrorConstr_value, URIErrorConstr_value}; jsdisp_t *err; unsigned int i; jsstr_t *str; HRESULT hres; for(i=0; i < sizeof(names)/sizeof(names[0]); i++) { hres = alloc_error(ctx, i==0 ? object_prototype : NULL, NULL, &err); if(FAILED(hres)) return hres; str = jsstr_alloc(names[i]); if(!str) { jsdisp_release(err); return E_OUTOFMEMORY; } hres = jsdisp_propput_dontenum(err, nameW, jsval_string(str)); jsstr_release(str); if(SUCCEEDED(hres)) hres = create_builtin_constructor(ctx, constr_val[i], names[i], NULL, PROPF_CONSTR|1, err, constr_addr[i]); jsdisp_release(err); if(FAILED(hres)) return hres; } return S_OK; }
static HRESULT set_constructor_prop(script_ctx_t *ctx, jsdisp_t *constr, jsdisp_t *prot) { static const WCHAR constructorW[] = {'c','o','n','s','t','r','u','c','t','o','r',0}; return jsdisp_propput_dontenum(prot, constructorW, jsval_obj(constr)); }
static inline HRESULT set_prototype(script_ctx_t *ctx, jsdisp_t *dispex, jsdisp_t *prototype) { return jsdisp_propput_dontenum(dispex, prototypeW, jsval_obj(prototype)); }