Jacek Caban : jscript: Added to_string(VT_I4) implementation.
Alexandre Julliard
julliard at winehq.org
Thu Sep 18 07:55:53 CDT 2008
Module: wine
Branch: master
Commit: c1372814695510564f53645346c1eab8b1dc0d0c
URL: http://source.winehq.org/git/wine.git/?a=commit;h=c1372814695510564f53645346c1eab8b1dc0d0c
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Sep 17 23:34:56 2008 +0200
jscript: Added to_string(VT_I4) implementation.
---
dlls/jscript/jsutils.c | 39 +++++++++++++++++++++++++++++++++++++--
dlls/jscript/tests/lang.js | 5 +++++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c
index 19c3b8d..7184cb9 100644
--- a/dlls/jscript/jsutils.c
+++ b/dlls/jscript/jsutils.c
@@ -253,19 +253,54 @@ HRESULT to_int32(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, INT *ret)
return S_OK;
}
+static BSTR int_to_bstr(INT i)
+{
+ WCHAR buf[12], *p;
+ BOOL neg = FALSE;
+
+ if(!i) {
+ static const WCHAR zeroW[] = {'0',0};
+ return SysAllocString(zeroW);
+ }
+
+ if(i < 0) {
+ neg = TRUE;
+ i = -i;
+ }
+
+ p = buf + sizeof(buf)/sizeof(*buf)-1;
+ *p-- = 0;
+ while(i) {
+ *p-- = i%10 + '0';
+ i /= 10;
+ }
+
+ if(neg)
+ *p = '-';
+ else
+ p++;
+
+ return SysAllocString(p);
+}
+
/* ECMA-262 3rd Edition 9.8 */
HRESULT to_string(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, BSTR *str)
{
switch(V_VT(v)) {
+ case VT_I4:
+ *str = int_to_bstr(V_I4(v));
+ break;
+
case VT_BSTR:
*str = SysAllocString(V_BSTR(v));
- return S_OK;
+ break;
default:
FIXME("unsupported vt %d\n", V_VT(v));
+ return E_NOTIMPL;
}
- return E_NOTIMPL;
+ return *str ? S_OK : E_OUTOFMEMORY;
}
/* ECMA-262 3rd Edition 9.9 */
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index afb71bf..e2b5800 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -312,6 +312,10 @@ ok(+true === 1, "+true !== 1");
ok(+false === 0, "+false !== 0");
ok(+null === 0, "+null !== 0");
+ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
+ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
+ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
+
ok(1 < 3.4, "1 < 3.4 failed");
ok(!(3.4 < 1), "3.4 < 1");
ok("abc" < "abcd", "abc < abcd failed");
@@ -544,5 +548,6 @@ ok(tmp.length === 7, "tmp.length !== 7");
ok(tmp["0"] === undefined, "tmp[0] is not undefined");
ok(tmp["3"] === 2, "tmp[3] !== 2");
ok(tmp["6"] === true, "tmp[6] !== true");
+ok(tmp[2] === 1, "tmp[2] !== 1");
reportSuccess();
More information about the wine-cvs
mailing list