static HRESULT run_exec(script_ctx_t *ctx, vdisp_t *jsthis, jsval_t arg, jsstr_t **input, match_state_t **result, BOOL *ret) { RegExpInstance *regexp; match_state_t *match; DWORD last_index = 0; const WCHAR *string; jsstr_t *jsstr; HRESULT hres; if(!is_vclass(jsthis, JSCLASS_REGEXP)) { FIXME("Not a RegExp\n"); return E_NOTIMPL; } regexp = regexp_from_vdisp(jsthis); hres = to_flat_string(ctx, arg, &jsstr, &string); if(FAILED(hres)) return hres; if(regexp->jsregexp->flags & REG_GLOB) { if(regexp->last_index < 0) { jsstr_release(jsstr); set_last_index(regexp, 0); *ret = FALSE; if(input) *input = jsstr_empty(); return S_OK; } last_index = regexp->last_index; } match = alloc_match_state(regexp->jsregexp, &ctx->tmp_heap, string+last_index); if(!match) { jsstr_release(jsstr); return E_OUTOFMEMORY; } hres = regexp_match_next(ctx, ®exp->dispex, REM_RESET_INDEX, jsstr, &match); if(FAILED(hres)) { jsstr_release(jsstr); return hres; } *result = match; *ret = hres == S_OK; if(input) *input = jsstr; else jsstr_release(jsstr); return S_OK; }
HRESULT Function_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) { FunctionInstance *function; TRACE("\n"); if(!is_vclass(jsthis, JSCLASS_FUNCTION)) { ERR("dispex is not a function\n"); return E_FAIL; } function = (FunctionInstance*)jsthis->u.jsdisp; switch(flags) { case DISPATCH_METHOD: if(function->value_proc) return invoke_value_proc(ctx, function, get_this(dp), flags, dp, retv, ei, caller); return invoke_source(ctx, function, get_this(dp), dp, retv, ei, caller); case DISPATCH_PROPERTYGET: { HRESULT hres; BSTR str; hres = function_to_string(function, &str); if(FAILED(hres)) return hres; V_VT(retv) = VT_BSTR; V_BSTR(retv) = str; break; } case DISPATCH_CONSTRUCT: if(function->value_proc) return invoke_value_proc(ctx, function, get_this(dp), flags, dp, retv, ei, caller); return invoke_constructor(ctx, function, dp, retv, ei, caller); default: FIXME("not implemented flags %x\n", flags); return E_NOTIMPL; } return S_OK; }
HRESULT Function_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { FunctionInstance *function; TRACE("\n"); if(!is_vclass(jsthis, JSCLASS_FUNCTION)) { ERR("dispex is not a function\n"); return E_FAIL; } function = (FunctionInstance*)jsthis->u.jsdisp; assert(function->value_proc != NULL); return invoke_value_proc(ctx, function, NULL, flags, argc, argv, r); }
HRESULT Function_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r) { FunctionInstance *function; TRACE("\n"); if(!is_vclass(jsthis, JSCLASS_FUNCTION)) { ERR("dispex is not a function\n"); return E_FAIL; } function = (FunctionInstance*)jsthis->u.jsdisp; switch(flags) { case DISPATCH_METHOD: assert(function->value_proc != NULL); return invoke_value_proc(ctx, function, NULL, flags, argc, argv, r); case DISPATCH_PROPERTYGET: { HRESULT hres; jsstr_t *str; hres = function_to_string(function, &str); if(FAILED(hres)) return hres; *r = jsval_string(str); break; } case DISPATCH_CONSTRUCT: assert(function->value_proc != NULL); return invoke_value_proc(ctx, function, NULL, flags, argc, argv, r); default: FIXME("not implemented flags %x\n", flags); return E_NOTIMPL; } return S_OK; }
static inline FunctionInstance *function_this(vdisp_t *jsthis) { return is_vclass(jsthis, JSCLASS_FUNCTION) ? function_from_vdisp(jsthis) : NULL; }
static inline ArrayInstance *array_this(vdisp_t *jsthis) { return is_vclass(jsthis, JSCLASS_ARRAY) ? array_from_vdisp(jsthis) : NULL; }
static inline ErrorInstance *error_this(vdisp_t *jsthis) { return is_vclass(jsthis, JSCLASS_ERROR) ? error_from_vdisp(jsthis) : NULL; }
static inline BoolInstance *bool_this(vdisp_t *jsthis) { return is_vclass(jsthis, JSCLASS_BOOLEAN) ? (BoolInstance*)jsthis->u.jsdisp : NULL; }
static inline NumberInstance *number_this(vdisp_t *jsthis) { return is_vclass(jsthis, JSCLASS_NUMBER) ? number_from_vdisp(jsthis) : NULL; }
static inline EnumeratorInstance *enumerator_this(vdisp_t *jsthis) { return is_vclass(jsthis, JSCLASS_ENUMERATOR) ? enumerator_from_vdisp(jsthis) : NULL; }
static inline StringInstance *string_this(vdisp_t *jsthis) { return is_vclass(jsthis, JSCLASS_STRING) ? string_from_vdisp(jsthis) : NULL; }