Jacek Caban : jscript: Added Math.abs implementation.
Alexandre Julliard
julliard at winehq.org
Mon Sep 22 07:04:32 CDT 2008
Module: wine
Branch: master
Commit: 2149494c9dfbfe7cf0d90090a6c2929cf8d79ef6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=2149494c9dfbfe7cf0d90090a6c2929cf8d79ef6
Author: Jacek Caban <jacek at codeweavers.com>
Date: Sun Sep 21 15:45:49 2008 +0200
jscript: Added Math.abs implementation.
---
dlls/jscript/math.c | 22 ++++++++++++++++++++--
dlls/jscript/tests/api.js | 12 ++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c
index 2bcf5ad..74c01d1 100644
--- a/dlls/jscript/math.c
+++ b/dlls/jscript/math.c
@@ -107,11 +107,29 @@ static HRESULT Math_SQRT1_2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
return E_NOTIMPL;
}
+/* ECMA-262 3rd Edition 15.8.2.12 */
static HRESULT Math_abs(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
- FIXME("\n");
- return E_NOTIMPL;
+ VARIANT v;
+ DOUBLE d;
+ HRESULT hres;
+
+ TRACE("\n");
+
+ if(!arg_cnt(dp)) {
+ FIXME("arg_cnt = 0\n");
+ return E_NOTIMPL;
+ }
+
+ hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v);
+ if(FAILED(hres))
+ return hres;
+
+ d = num_val(&v);
+ if(retv)
+ num_set_val(retv, d < 0.0 ? -d : d);
+ return S_OK;
}
static HRESULT Math_acos(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 34a6456..65c4992 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -270,4 +270,16 @@ ok(tmp === 1, "Math.round(true) = " + tmp);
tmp = Math.round(1.1, 3, 4);
ok(tmp === 1, "Math.round(1.1, 3, 4) = " + tmp);
+tmp = Math.abs(3);
+ok(tmp === 3, "Math.abs(3) = " + tmp);
+
+tmp = Math.abs(-3);
+ok(tmp === 3, "Math.abs(-3) = " + tmp);
+
+tmp = Math.abs(true);
+ok(tmp === 1, "Math.abs(true) = " + tmp);
+
+tmp = Math.abs(-3, 2);
+ok(tmp === 3, "Math.abs(-3, 2) = " + tmp);
+
reportSuccess();
More information about the wine-cvs
mailing list