Commit 2f28956f authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

jscript: Make String_slice generic.

parent 54a3fa84
...@@ -982,6 +982,7 @@ static HRESULT String_slice(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment