jscript: Added more to_string implementation.

This commit is contained in:
Jacek Caban 2008-09-19 00:46:05 +02:00 committed by Alexandre Julliard
parent 3435603520
commit 4778c06903
2 changed files with 29 additions and 1 deletions

View File

@ -320,15 +320,39 @@ static BSTR int_to_bstr(INT i)
/* ECMA-262 3rd Edition 9.8 */
HRESULT to_string(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, BSTR *str)
{
const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
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};
switch(V_VT(v)) {
case VT_EMPTY:
*str = SysAllocString(undefinedW);
break;
case VT_NULL:
*str = SysAllocString(nullW);
break;
case VT_I4:
*str = int_to_bstr(V_I4(v));
break;
case VT_BSTR:
*str = SysAllocString(V_BSTR(v));
break;
case VT_DISPATCH: {
VARIANT prim;
HRESULT hres;
hres = to_primitive(ctx, v, ei, &prim);
if(FAILED(hres))
return hres;
hres = to_string(ctx, &prim, ei, str);
VariantClear(&prim);
return hres;
}
case VT_BOOL:
*str = SysAllocString(V_BOOL(v) ? trueW : falseW);
break;
default:
FIXME("unsupported vt %d\n", V_VT(v));
return E_NOTIMPL;

View File

@ -342,6 +342,10 @@ ok(+null === 0, "+null !== 0");
ok("" + 0 === "0", "\"\" + 0 !== \"0\"");
ok("" + 123 === "123", "\"\" + 123 !== \"123\"");
ok("" + (-5) === "-5", "\"\" + (-5) !== \"-5\"");
ok("" + null === "null", "\"\" + null !== \"null\"");
ok("" + undefined === "undefined", "\"\" + undefined !== \"undefined\"");
ok("" + true === "true", "\"\" + true !== \"true\"");
ok("" + false === "false", "\"\" + false !== \"false\"");
ok(1 < 3.4, "1 < 3.4 failed");
ok(!(3.4 < 1), "3.4 < 1");