From 42c044ae7170ea5f3bb92c47f62d28378cf8cee7 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 19 Jan 2021 14:33:52 +0100 Subject: [PATCH] jscript: Support VT_DATE to string conversion. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/date.c | 25 +++++++++++++++++++++++++ dlls/jscript/jscript.h | 1 + dlls/jscript/jsutils.c | 14 +++++++++++--- dlls/jscript/tests/lang.js | 3 +++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/dlls/jscript/date.c b/dlls/jscript/date.c index c0264c26bb8..96d366c6245 100644 --- a/dlls/jscript/date.c +++ b/dlls/jscript/date.c @@ -2483,3 +2483,28 @@ HRESULT variant_date_to_number(double date, double *ret) make_time(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds)); return S_OK; } + +HRESULT variant_date_to_string(script_ctx_t *ctx, double date, jsstr_t **r) +{ + DateInstance *date_obj; + jsval_t val; + double time; + HRESULT hres; + + hres = variant_date_to_number(date, &time); + if(FAILED(hres)) + return hres; + + hres = create_date(ctx, NULL, time, &date_obj); + if(FAILED(hres)) + return hres; + + hres = dateobj_to_string(date_obj, &val); + jsdisp_release(&date_obj->dispex); + if(FAILED(hres)) + return hres; + + assert(is_string(val)); + *r = get_string(val); + return hres; +} diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 7cc194b84b9..b590e1a7441 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -361,6 +361,7 @@ HRESULT jsval_strict_equal(jsval_t,jsval_t,BOOL*) DECLSPEC_HIDDEN; HRESULT variant_change_type(script_ctx_t*,VARIANT*,VARIANT*,VARTYPE) DECLSPEC_HIDDEN; HRESULT variant_date_to_number(double,double*) DECLSPEC_HIDDEN; +HRESULT variant_date_to_string(script_ctx_t*,double,jsstr_t**) DECLSPEC_HIDDEN; HRESULT decode_source(WCHAR*) DECLSPEC_HIDDEN; diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index a77c70ad01d..bfecdc75c4a 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -773,9 +773,17 @@ HRESULT to_string(script_ctx_t *ctx, jsval_t val, jsstr_t **str) case JSV_BOOL: *str = jsstr_alloc(get_bool(val) ? L"true" : L"false"); break; - default: - FIXME("unsupported %s\n", debugstr_jsval(val)); - return E_NOTIMPL; + default: { + const VARIANT *v = get_variant(val); + switch(V_VT(v)) + { + case VT_DATE: + return variant_date_to_string(ctx, V_DATE(v), str); + default: + FIXME("unsupported %s\n", debugstr_variant(v)); + return E_NOTIMPL; + } + } } return *str ? S_OK : E_OUTOFMEMORY; diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index d6973099b7c..7bcb121131e 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -200,14 +200,17 @@ ok(tmp === 3, "tmp = " + tmp); ok(getVT(+d) === "VT_R8", "vt +v_date(0) = " + getVT(d)); ok(getVT(d / d) === "VT_I4", "vt v_date(0) / v_date(0) = " + getVT(d / d)); ok((+d) === e, "+v_date(0) = " + (+d) + " expected " + e); + ok(("" + d).match(/^Sat Dec 30 00:00:00 .* 1899$/) != null, "+v_date(0) = " + d); d = v_date(2.5); e = Date.parse("Mon Jan 1 12:00:00 1900"); ok((+d) === e, "+v_date(2.5) = " + (+d)); + ok(("" + d).match(/^Mon Jan 1 12:00:00 .* 1900$/) != null, "+v_date(2.5) = " + d); d = v_date(42091); e = Date.parse("Sat Mar 28 00:00:00 2015"); ok((+d) === e, "+v_date(2015y) = " + (+d) + " expected " + e); + ok(("" + d).match(/^Sat Mar 28 00:00:00 .* 2015$/) != null, "+v_date(2015y) = " + d); })(); function testRecFunc(x) {