From 6751644835cc374baf5e04b80d878cee9f69c956 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sun, 21 Sep 2008 15:44:13 +0200 Subject: [PATCH] jscript: Added String.concat implementation. --- dlls/jscript/string.c | 55 +++++++++++++++++++++++++++++++++++++-- dlls/jscript/tests/api.js | 7 +++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index b56fd9eedc7..9da1bfb9db2 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -241,11 +241,62 @@ static HRESULT String_charCodeAt(DispatchEx *dispex, LCID lcid, WORD flags, DISP return S_OK; } +/* ECMA-262 3rd Edition 15.5.4.6 */ static HRESULT String_concat(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { - FIXME("\n"); - return E_NOTIMPL; + BSTR *strs = NULL, ret = NULL; + 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, diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 707eacfe36b..cea936dc2c1 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -133,6 +133,13 @@ ok(tmp === "abcd", "'abcd'.slice() = " + tmp); tmp = "abcd".slice(1); 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(); ok(typeof(arr) === "object", "arr () is not object"); ok((arr.length === 0), "arr.length is not 0");