Piotr Caban : jscript: Improve to_string implementation.
Alexandre Julliard
julliard at winehq.org
Wed Jul 15 09:46:41 CDT 2009
Module: wine
Branch: master
Commit: 15b07c2a36eee94ecbd3bf94df7cd9717a945a27
URL: http://source.winehq.org/git/wine.git/?a=commit;h=15b07c2a36eee94ecbd3bf94df7cd9717a945a27
Author: Piotr Caban <piotr.caban at gmail.com>
Date: Wed Jul 15 12:50:43 2009 +0200
jscript: Improve to_string implementation.
---
dlls/jscript/jsutils.c | 27 ++++++++++++++++++---------
dlls/jscript/tests/api.js | 7 +++++++
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c
index 4a885a5..d5ffa7f 100644
--- a/dlls/jscript/jsutils.c
+++ b/dlls/jscript/jsutils.c
@@ -512,6 +512,8 @@ HRESULT to_string(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, BSTR *str)
const WCHAR nullW[] = {'n','u','l','l',0};
const WCHAR trueW[] = {'t','r','u','e',0};
const WCHAR falseW[] = {'f','a','l','s','e',0};
+ const WCHAR NaNW[] = {'N','a','N',0};
+ const WCHAR InfinityW[] = {'-','I','n','f','i','n','i','t','y',0};
switch(V_VT(v)) {
case VT_EMPTY:
@@ -524,16 +526,23 @@ HRESULT to_string(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, BSTR *str)
*str = int_to_bstr(V_I4(v));
break;
case VT_R8: {
- VARIANT strv;
- HRESULT hres;
-
- V_VT(&strv) = VT_EMPTY;
- hres = VariantChangeTypeEx(&strv, v, MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), 0, VT_BSTR);
- if(FAILED(hres))
- return hres;
+ if(isnan(V_R8(v)))
+ *str = SysAllocString(NaNW);
+ else if(isinf(V_R8(v)))
+ *str = SysAllocString(V_R8(v)<0 ? InfinityW : InfinityW+1);
+ else {
+ VARIANT strv;
+ HRESULT hres;
+
+ V_VT(&strv) = VT_EMPTY;
+ hres = VariantChangeTypeEx(&strv, v, MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT), 0, VT_BSTR);
+ if(FAILED(hres))
+ return hres;
- *str = V_BSTR(&strv);
- return S_OK;
+ *str = V_BSTR(&strv);
+ return S_OK;
+ }
+ break;
}
case VT_BSTR:
*str = SysAllocString(V_BSTR(v));
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index cf70ebc..f4dd74b 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -566,6 +566,13 @@ ok(tmp === 0, "(new Number()).valueOf = " + tmp);
tmp = Number.prototype.valueOf();
ok(tmp === 0, "Number.prototype.valueOf = " + tmp);
+num = new Number(NaN);
+ok(num.toString() === "NaN", "num.toString() = " + num.toString());
+num = new Number(-Infinity);
+ok(num.toString() === "-Infinity", "num.toString() = " + num.toString());
+num = new Number(Infinity);
+ok(num.toString() === "Infinity", "num.toString() = " + num.toString());
+
tmp = Math.min(1);
ok(tmp === 1, "Math.min(1) = " + tmp);
More information about the wine-cvs
mailing list