jscript: Make String_slice generic.

This commit is contained in:
Piotr Caban 2009-07-12 19:51:36 +02:00 committed by Alexandre Julliard
parent 54a3fa842b
commit 2f28956f06
1 changed files with 29 additions and 10 deletions

View File

@ -982,6 +982,7 @@ static HRESULT String_slice(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{ {
const WCHAR *str; const WCHAR *str;
BSTR val_str = NULL;
DWORD length; DWORD length;
INT start=0, end; INT start=0, end;
VARIANT v; VARIANT v;
@ -989,20 +990,32 @@ static HRESULT String_slice(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
TRACE("\n"); TRACE("\n");
if(is_class(dispex, JSCLASS_STRING)) { if(!is_class(dispex, JSCLASS_STRING)) {
StringInstance *string = (StringInstance*)dispex; VARIANT this;
str = string->str; V_VT(&this) = VT_DISPATCH;
length = string->length; V_DISPATCH(&this) = (IDispatch*)_IDispatchEx_(dispex);
}else {
FIXME("this is not a string class\n"); hres = to_string(dispex->ctx, &this, ei, &val_str);
return E_NOTIMPL; if(FAILED(hres))
return hres;
str = val_str;
length = SysStringLen(val_str);
}
else {
StringInstance *this = (StringInstance*)dispex;
str = this->str;
length = this->length;
} }
if(arg_cnt(dp)) { if(arg_cnt(dp)) {
hres = to_integer(dispex->ctx, dp->rgvarg + dp->cArgs-1, ei, &v); hres = to_integer(dispex->ctx, dp->rgvarg + dp->cArgs-1, ei, &v);
if(FAILED(hres)) if(FAILED(hres)) {
SysFreeString(val_str);
return hres; return hres;
}
if(V_VT(&v) == VT_I4) { if(V_VT(&v) == VT_I4) {
start = V_I4(&v); start = V_I4(&v);
@ -1022,8 +1035,10 @@ static HRESULT String_slice(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
if(arg_cnt(dp) >= 2) { if(arg_cnt(dp) >= 2) {
hres = to_integer(dispex->ctx, dp->rgvarg + dp->cArgs-2, ei, &v); hres = to_integer(dispex->ctx, dp->rgvarg + dp->cArgs-2, ei, &v);
if(FAILED(hres)) if(FAILED(hres)) {
SysFreeString(val_str);
return hres; return hres;
}
if(V_VT(&v) == VT_I4) { if(V_VT(&v) == VT_I4) {
end = V_I4(&v); end = V_I4(&v);
@ -1046,12 +1061,16 @@ static HRESULT String_slice(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
if(retv) { if(retv) {
BSTR retstr = SysAllocStringLen(str+start, end-start); BSTR retstr = SysAllocStringLen(str+start, end-start);
if(!str) if(!retstr) {
SysFreeString(val_str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
}
V_VT(retv) = VT_BSTR; V_VT(retv) = VT_BSTR;
V_BSTR(retv) = retstr; V_BSTR(retv) = retstr;
} }
SysFreeString(val_str);
return S_OK; return S_OK;
} }