Jacek Caban : jscript: Added String.concat implementation.
Alexandre Julliard
julliard at winehq.org
Mon Sep 22 07:04:28 CDT 2008
Module: wine
Branch: master
Commit: 6751644835cc374baf5e04b80d878cee9f69c956
URL: http://source.winehq.org/git/wine.git/?a=commit;h=6751644835cc374baf5e04b80d878cee9f69c956
Author: Jacek Caban <jacek at codeweavers.com>
Date: Sun Sep 21 15:44:13 2008 +0200
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 b56fd9e..9da1bfb 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 707eacf..cea936d 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");
More information about the wine-cvs
mailing list