From 7a3d60e9130aca54b0561c5cadc0468c27fd38d8 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 10 Sep 2008 02:34:33 +0200 Subject: [PATCH] jscript: Added Number constructor object implementation. --- dlls/jscript/Makefile.in | 1 + dlls/jscript/global.c | 9 +- dlls/jscript/jscript.h | 3 + dlls/jscript/number.c | 167 +++++++++++++++++++++++++++++++++++++ dlls/jscript/tests/lang.js | 1 + 5 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 dlls/jscript/number.c diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in index 1fb34d03c81..72d908c9a08 100644 --- a/dlls/jscript/Makefile.in +++ b/dlls/jscript/Makefile.in @@ -18,6 +18,7 @@ C_SRCS = \ jscript_main.c \ jsutils.c \ lex.c \ + number.c \ object.c \ string.c diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index 2f782313110..b90991b166b 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -112,8 +112,9 @@ static HRESULT JSGlobal_Function(DispatchEx *dispex, LCID lcid, WORD flags, DISP static HRESULT JSGlobal_Number(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { - FIXME("\n"); - return E_NOTIMPL; + TRACE("\n"); + + return constructor_call(dispex->ctx->number_constr, lcid, flags, dp, retv, ei, sp); } static HRESULT JSGlobal_Object(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, @@ -308,6 +309,10 @@ static HRESULT init_constructors(script_ctx_t *ctx) if(FAILED(hres)) return hres; + hres = create_number_constr(ctx, &ctx->number_constr); + if(FAILED(hres)) + return hres; + hres = create_object_constr(ctx, &ctx->object_constr); if(FAILED(hres)) return hres; diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 9515c511995..9f91290a578 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -53,6 +53,7 @@ typedef enum { JSCLASS_BOOLEAN, JSCLASS_FUNCTION, JSCLASS_GLOBAL, + JSCLASS_NUMBER, JSCLASS_OBJECT, JSCLASS_STRING } jsclass_t; @@ -132,6 +133,7 @@ struct _script_ctx_t { DispatchEx *global; DispatchEx *array_constr; DispatchEx *bool_constr; + DispatchEx *number_constr; DispatchEx *object_constr; DispatchEx *string_constr; }; @@ -147,6 +149,7 @@ HRESULT init_global(script_ctx_t*); HRESULT create_array_constr(script_ctx_t*,DispatchEx**); HRESULT create_bool_constr(script_ctx_t*,DispatchEx**); +HRESULT create_number_constr(script_ctx_t*,DispatchEx**); HRESULT create_object_constr(script_ctx_t*,DispatchEx**); HRESULT create_string_constr(script_ctx_t*,DispatchEx**); diff --git a/dlls/jscript/number.c b/dlls/jscript/number.c new file mode 100644 index 00000000000..b4db8639a31 --- /dev/null +++ b/dlls/jscript/number.c @@ -0,0 +1,167 @@ +/* + * 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); + +typedef struct { + DispatchEx dispex; +} NumberInstance; + +static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0}; +static const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0}; +static const WCHAR toFixedW[] = {'t','o','F','i','x','e','d',0}; +static const WCHAR toExponentialW[] = {'t','o','E','x','p','o','n','e','n','t','i','a','l',0}; +static const WCHAR toPrecisionW[] = {'t','o','P','r','e','c','i','s','i','o','n',0}; +static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0}; +static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0}; +static const WCHAR propertyIsEnumerableW[] = + {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0}; +static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0}; + +static HRESULT Number_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Number_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Number_toFixed(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Number_toExponential(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Number_toPrecision(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Number_valueOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Number_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Number_propertyIsEnumerable(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Number_isPrototypeOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT Number_value(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 Number_props[] = { + {hasOwnPropertyW, Number_hasOwnProperty, PROPF_METHOD}, + {isPrototypeOfW, Number_isPrototypeOf, PROPF_METHOD}, + {propertyIsEnumerableW, Number_propertyIsEnumerable, PROPF_METHOD}, + {toExponentialW, Number_toExponential, PROPF_METHOD}, + {toFixedW, Number_toFixed, PROPF_METHOD}, + {toLocaleStringW, Number_toLocaleString, PROPF_METHOD}, + {toPrecisionW, Number_toPrecision, PROPF_METHOD}, + {toStringW, Number_toString, PROPF_METHOD}, + {valueOfW, Number_valueOf, PROPF_METHOD} +}; + +static const builtin_info_t Number_info = { + JSCLASS_NUMBER, + {NULL, Number_value, 0}, + sizeof(Number_props)/sizeof(*Number_props), + Number_props, + NULL, + NULL +}; + +static HRESULT NumberConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, + VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) +{ + FIXME("\n"); + return E_NOTIMPL; +} + +static HRESULT alloc_number(script_ctx_t *ctx, BOOL use_constr, NumberInstance **ret) +{ + NumberInstance *number = heap_alloc_zero(sizeof(NumberInstance)); + HRESULT hres; + + if(use_constr) + hres = init_dispex_from_constr(&number->dispex, ctx, &Number_info, ctx->number_constr); + else + hres = init_dispex(&number->dispex, ctx, &Number_info, NULL); + if(FAILED(hres)) + return hres; + + *ret = number; + return S_OK; +} + +HRESULT create_number_constr(script_ctx_t *ctx, DispatchEx **ret) +{ + NumberInstance *number; + HRESULT hres; + + hres = alloc_number(ctx, FALSE, &number); + if(FAILED(hres)) + return hres; + + hres = create_builtin_function(ctx, NumberConstr_value, PROPF_CONSTR, &number->dispex, ret); + + jsdisp_release(&number->dispex); + return hres; +} diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index e6587cf6100..1f20e50e728 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -51,5 +51,6 @@ ok(Object.prototype.prototype === undefined, "Object.prototype is not undefined" ok(String.prototype !== undefined, "String.prototype is undefined"); ok(Array.prototype !== undefined, "Array.prototype is undefined"); ok(Boolean.prototype !== undefined, "Boolean.prototype is undefined"); +ok(Number.prototype !== undefined, "Number.prototype is undefined"); reportSuccess();