Commit 67516448 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added String.concat implementation.

parent 1f134b41
...@@ -241,11 +241,62 @@ static HRESULT String_charCodeAt(DispatchEx *dispex, LCID lcid, WORD flags, DISP ...@@ -241,11 +241,62 @@ static HRESULT String_charCodeAt(DispatchEx *dispex, LCID lcid, WORD flags, DISP
return S_OK; return S_OK;
} }
/* ECMA-262 3rd Edition 15.5.4.6 */
static HRESULT String_concat(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, static HRESULT String_concat(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{ {
FIXME("\n"); BSTR *strs = NULL, ret = NULL;
return E_NOTIMPL; DWORD len = 0, i, l, str_cnt;
VARIANT var;
WCHAR *ptr;
HRESULT hres;
TRACE("\n");
str_cnt = arg_cnt(dp)+1;
strs = heap_alloc_zero(str_cnt * sizeof(BSTR));
if(!strs)
return E_OUTOFMEMORY;
V_VT(&var) = VT_DISPATCH;
V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(dispex);
hres = to_string(dispex->ctx, &var, ei, strs);
if(SUCCEEDED(hres)) {
for(i=0; i < arg_cnt(dp); i++) {
hres = to_string(dispex->ctx, get_arg(dp, i), ei, strs+i+1);
if(FAILED(hres))
break;
}
}
if(SUCCEEDED(hres)) {
for(i=0; i < str_cnt; i++)
len += SysStringLen(strs[i]);
ptr = ret = SysAllocStringLen(NULL, len);
for(i=0; i < str_cnt; i++) {
l = SysStringLen(strs[i]);
memcpy(ptr, strs[i], l*sizeof(WCHAR));
ptr += l;
}
}
for(i=0; i < str_cnt; i++)
SysFreeString(strs[i]);
heap_free(strs);
if(FAILED(hres))
return hres;
if(retv) {
V_VT(retv) = VT_BSTR;
V_BSTR(retv) = ret;
}else {
SysFreeString(ret);
}
return S_OK;
} }
static HRESULT String_fixed(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, static HRESULT String_fixed(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
......
...@@ -133,6 +133,13 @@ ok(tmp === "abcd", "'abcd'.slice() = " + tmp); ...@@ -133,6 +133,13 @@ ok(tmp === "abcd", "'abcd'.slice() = " + tmp);
tmp = "abcd".slice(1); tmp = "abcd".slice(1);
ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp); ok(tmp === "bcd", "'abcd'.slice(1) = " + tmp);
tmp = "abc".concat(["d",1],2,false);
ok(tmp === "abcd,12false", "concat returned " + tmp);
var arr = new Array(2,"a");
arr.concat = String.prototype.concat;
tmp = arr.concat("d");
ok(tmp === "2,ad", "arr.concat = " + tmp);
var arr = new Array(); var arr = new Array();
ok(typeof(arr) === "object", "arr () is not object"); ok(typeof(arr) === "object", "arr () is not object");
ok((arr.length === 0), "arr.length is not 0"); ok((arr.length === 0), "arr.length is not 0");
......
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