From 083c95449ec28435a3888f7b99b28b4126e6a96f Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 10 Sep 2008 02:35:43 +0200 Subject: [PATCH] jscript: Added Math object stub implementation. --- dlls/jscript/Makefile.in | 1 + dlls/jscript/global.c | 26 ++-- dlls/jscript/jscript.h | 3 + dlls/jscript/math.c | 275 +++++++++++++++++++++++++++++++++++++ dlls/jscript/tests/lang.js | 2 + 5 files changed, 298 insertions(+), 9 deletions(-) create mode 100644 dlls/jscript/math.c diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in index cdb878c53be..ee3f7e56ed4 100644 --- a/dlls/jscript/Makefile.in +++ b/dlls/jscript/Makefile.in @@ -18,6 +18,7 @@ C_SRCS = \ jscript_main.c \ jsutils.c \ lex.c \ + math.c \ number.c \ object.c \ regexp.c \ diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index 6f6ca94e3f6..a347101bfb0 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -252,13 +252,6 @@ static HRESULT JSGlobal_CollectGarbage(DispatchEx *dispex, LCID lcid, WORD flags return E_NOTIMPL; } -static HRESULT JSGlobal_Math(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, - VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) -{ - FIXME("\n"); - return E_NOTIMPL; -} - static const builtin_prop_t JSGlobal_props[] = { {ActiveXObjectW, JSGlobal_ActiveXObject, PROPF_METHOD}, {ArrayW, JSGlobal_Array, PROPF_CONSTR}, @@ -269,7 +262,7 @@ static const builtin_prop_t JSGlobal_props[] = { {FunctionW, JSGlobal_Function, PROPF_CONSTR}, {GetObjectW, JSGlobal_GetObject, PROPF_METHOD}, {InfinityW, JSGlobal_Infinity, 0}, - {MathW, JSGlobal_Math, 0}, +/* {MathW, JSGlobal_Math, 0}, */ {NaNW, JSGlobal_NaN, 0}, {NumberW, JSGlobal_Number, PROPF_CONSTR}, {ObjectW, JSGlobal_Object, PROPF_CONSTR}, @@ -331,6 +324,8 @@ static HRESULT init_constructors(script_ctx_t *ctx) HRESULT init_global(script_ctx_t *ctx) { + DispatchEx *math; + VARIANT var; HRESULT hres; if(ctx->global) @@ -340,5 +335,18 @@ HRESULT init_global(script_ctx_t *ctx) if(FAILED(hres)) return hres; - return create_dispex(ctx, &JSGlobal_info, NULL, &ctx->global); + hres = create_dispex(ctx, &JSGlobal_info, NULL, &ctx->global); + if(FAILED(hres)) + return hres; + + hres = create_math(ctx, &math); + if(FAILED(hres)) + return hres; + + V_VT(&var) = VT_DISPATCH; + V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(math); + hres = jsdisp_propput_name(ctx->global, MathW, ctx->lcid, &var, NULL/*FIXME*/, NULL/*FIXME*/); + jsdisp_release(math); + + return hres; } diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index d9b1c46d8b8..2869fc31ed2 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -53,6 +53,7 @@ typedef enum { JSCLASS_BOOLEAN, JSCLASS_FUNCTION, JSCLASS_GLOBAL, + JSCLASS_MATH, JSCLASS_NUMBER, JSCLASS_OBJECT, JSCLASS_REGEXP, @@ -112,6 +113,8 @@ HRESULT jsdisp_set_prototype(DispatchEx*,DispatchEx*); HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,DWORD,DispatchEx*,DispatchEx**); +HRESULT create_math(script_ctx_t*,DispatchEx**); + HRESULT to_boolean(VARIANT*,VARIANT_BOOL*); HRESULT to_object(exec_ctx_t*,VARIANT*,IDispatch**); diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c new file mode 100644 index 00000000000..8454cfa87e3 --- /dev/null +++ b/dlls/jscript/math.c @@ -0,0 +1,275 @@ +/* + * Copyright 2008 Jacek Caban for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "jscript.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(jscript); + +static const WCHAR EW[] = {'E',0}; +static const WCHAR LOG2EW[] = {'L','O','G','2','E',0}; +static const WCHAR LOG10EW[] = {'L','O','G','1','0',0}; +static const WCHAR LN2W[] = {'L','N','2',0}; +static const WCHAR LN10W[] = {'L','N','1','0',0}; +static const WCHAR PIW[] = {'P','I',0}; +static const WCHAR SQRT2W[] = {'S','Q','R','T','2',0}; +static const WCHAR SQRT1_2W[] = {'S','Q','R','T','1','_','2',0}; +static const WCHAR absW[] = {'a','b','s',0}; +static const WCHAR acosW[] = {'a','c','o','s',0}; +static const WCHAR asinW[] = {'a','s','i','n',0}; +static const WCHAR atanW[] = {'a','t','a','n',0}; +static const WCHAR atan2W[] = {'a','t','a','n','2',0}; +static const WCHAR ceilW[] = {'c','e','i','l',0}; +static const WCHAR cosW[] = {'c','o','s',0}; +static const WCHAR expW[] = {'e','x','p',0}; +static const WCHAR floorW[] = {'f','l','o','o','r',0}; +static const WCHAR logW[] = {'l','o','g',0}; +static const WCHAR maxW[] = {'m','a','x',0}; +static const WCHAR minW[] = {'m','i','n',0}; +static const WCHAR powW[] = {'p','o','w',0}; +static const WCHAR randomW[] = {'r','a','n','d','o','m',0}; +static const WCHAR roundW[] = {'r','o','u','n','d',0}; +static const WCHAR sinW[] = {'s','i','n',0}; +static const WCHAR sqrtW[] = {'s','q','r','t',0}; +static const WCHAR tanW[] = {'t','a','n',0}; + +static HRESULT Math_E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_LOG2E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_LOG10E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_LN2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_LN10(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_PI(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_SQRT2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_SQRT1_2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_abs(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_acos(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_asin(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_atan(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_atan2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_ceil(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_cos(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_exp(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_floor(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_log(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_max(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_min(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_pow(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_random(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_round(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_sin(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_sqrt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Math_tan(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static const builtin_prop_t Math_props[] = { + {EW, Math_E, 0}, + {LOG2EW, Math_LOG2E, 0}, + {LOG10EW, Math_LOG10E, 0}, + {LN2W, Math_LN2, 0}, + {LN10W, Math_LN10, 0}, + {PIW, Math_PI, 0}, + {SQRT1_2W, Math_SQRT1_2, 0}, + {SQRT2W, Math_SQRT2, 0}, + {absW, Math_abs, PROPF_METHOD}, + {acosW, Math_acos, PROPF_METHOD}, + {asinW, Math_asin, PROPF_METHOD}, + {atanW, Math_atan, PROPF_METHOD}, + {atan2W, Math_atan2, PROPF_METHOD}, + {ceilW, Math_ceil, PROPF_METHOD}, + {cosW, Math_cos, PROPF_METHOD}, + {expW, Math_exp, PROPF_METHOD}, + {floorW, Math_floor, PROPF_METHOD}, + {logW, Math_log, PROPF_METHOD}, + {maxW, Math_max, PROPF_METHOD}, + {minW, Math_min, PROPF_METHOD}, + {powW, Math_pow, PROPF_METHOD}, + {randomW, Math_random, PROPF_METHOD}, + {roundW, Math_round, PROPF_METHOD}, + {sinW, Math_sin, PROPF_METHOD}, + {sqrtW, Math_sqrt, PROPF_METHOD}, + {tanW, Math_tan, PROPF_METHOD} +}; + +static const builtin_info_t Math_info = { + JSCLASS_MATH, + {NULL, NULL, 0}, + sizeof(Math_props)/sizeof(*Math_props), + Math_props, + NULL, + NULL +}; + +HRESULT create_math(script_ctx_t *ctx, DispatchEx **ret) +{ + return create_dispex(ctx, &Math_info, NULL, ret); +} diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index 1799c4aaa03..96ecdb496e3 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -53,5 +53,7 @@ ok(Array.prototype !== undefined, "Array.prototype is undefined"); ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined"); ok(Number.prototype !== undefined, "Number.prototype is undefined"); ok(RegExp.prototype !== undefined, "RegExp.prototype is undefined"); +ok(Math !== undefined, "Math is undefined"); +ok(Math.prototype === undefined, "Math.prototype is not undefined"); reportSuccess();