2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/debug.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
25 static const WCHAR NaNW[] = {'N','a','N',0};
26 static const WCHAR InfinityW[] = {'I','n','f','i','n','i','t','y',0};
27 static const WCHAR ArrayW[] = {'A','r','r','a','y',0};
28 static const WCHAR BooleanW[] = {'B','o','o','l','e','a','n',0};
29 static const WCHAR DateW[] = {'D','a','t','e',0};
30 static const WCHAR FunctionW[] = {'F','u','n','c','t','i','o','n',0};
31 static const WCHAR NumberW[] = {'N','u','m','b','e','r',0};
32 static const WCHAR ObjectW[] = {'O','b','j','e','c','t',0};
33 static const WCHAR StringW[] = {'S','t','r','i','n','g',0};
34 static const WCHAR RegExpW[] = {'R','e','g','E','x','p',0};
35 static const WCHAR ActiveXObjectW[] = {'A','c','t','i','v','e','X','O','b','j','e','c','t',0};
36 static const WCHAR VBArrayW[] = {'V','B','A','r','r','a','y',0};
37 static const WCHAR EnumeratorW[] = {'E','n','u','m','e','r','a','t','o','r',0};
38 static const WCHAR escapeW[] = {'e','s','c','a','p','e',0};
39 static const WCHAR evalW[] = {'e','v','a','l',0};
40 static const WCHAR isNaNW[] = {'i','s','N','a','N',0};
41 static const WCHAR isFiniteW[] = {'i','s','F','i','n','i','t','e',0};
42 static const WCHAR parseIntW[] = {'p','a','r','s','e','I','n','t',0};
43 static const WCHAR parseFloatW[] = {'p','a','r','s','e','F','l','o','a','t',0};
44 static const WCHAR unescapeW[] = {'u','n','e','s','c','a','p','e',0};
45 static const WCHAR GetObjectW[] = {'G','e','t','O','b','j','e','c','t',0};
46 static const WCHAR ScriptEngineW[] = {'S','c','r','i','p','t','E','n','g','i','n','e',0};
47 static const WCHAR ScriptEngineMajorVersionW[] =
48 {'S','c','r','i','p','t','E','n','g','i','n','e','M','a','j','o','r','V','e','r','s','i','o','n',0};
49 static const WCHAR ScriptEngineMinorVersionW[] =
50 {'S','c','r','i','p','t','E','n','g','i','n','e','M','i','n','o','r','V','e','r','s','i','o','n',0};
51 static const WCHAR ScriptEngineBuildVersionW[] =
52 {'S','c','r','i','p','t','E','n','g','i','n','e','B','u','i','l','d','V','e','r','s','i','o','n',0};
53 static const WCHAR CollectGarbageW[] = {'C','o','l','l','e','c','t','G','a','r','b','a','g','e',0};
54 static const WCHAR MathW[] = {'M','a','t','h',0};
56 static HRESULT constructor_call(DispatchEx *constr, LCID lcid, WORD flags, DISPPARAMS *dp,
57 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
59 if(flags != DISPATCH_PROPERTYGET)
60 return jsdisp_call_value(constr, lcid, flags, dp, retv, ei, sp);
62 V_VT(retv) = VT_DISPATCH;
63 V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(constr);
64 IDispatchEx_AddRef(_IDispatchEx_(constr));
68 static HRESULT JSGlobal_NaN(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
69 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
75 static HRESULT JSGlobal_Infinity(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
76 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
82 static HRESULT JSGlobal_Array(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
83 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
87 return constructor_call(dispex->ctx->array_constr, lcid, flags, dp, retv, ei, sp);
90 static HRESULT JSGlobal_Boolean(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
91 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
95 return constructor_call(dispex->ctx->bool_constr, lcid, flags, dp, retv, ei, sp);
98 static HRESULT JSGlobal_Date(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
99 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
105 static HRESULT JSGlobal_Function(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
106 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
112 static HRESULT JSGlobal_Number(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
113 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
117 return constructor_call(dispex->ctx->number_constr, lcid, flags, dp, retv, ei, sp);
120 static HRESULT JSGlobal_Object(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
121 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
125 return constructor_call(dispex->ctx->object_constr, lcid, flags, dp, retv, ei, sp);
128 static HRESULT JSGlobal_String(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
129 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
133 return constructor_call(dispex->ctx->string_constr, lcid, flags, dp, retv, ei, sp);
136 static HRESULT JSGlobal_RegExp(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
137 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
141 return constructor_call(dispex->ctx->regexp_constr, lcid, flags, dp, retv, ei, sp);
144 static HRESULT JSGlobal_ActiveXObject(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
145 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
151 static HRESULT JSGlobal_VBArray(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
152 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
158 static HRESULT JSGlobal_Enumerator(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
159 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
165 static HRESULT JSGlobal_escape(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
166 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
172 static HRESULT JSGlobal_eval(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
173 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
179 static HRESULT JSGlobal_isNaN(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
180 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
186 static HRESULT JSGlobal_isFinite(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
187 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
193 static HRESULT JSGlobal_parseInt(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
194 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
199 static HRESULT JSGlobal_parseFloat(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
200 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
206 static HRESULT JSGlobal_unescape(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
207 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
213 static HRESULT JSGlobal_GetObject(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
214 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
220 static HRESULT JSGlobal_ScriptEngine(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
221 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
227 static HRESULT JSGlobal_ScriptEngineMajorVersion(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
228 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
234 static HRESULT JSGlobal_ScriptEngineMinorVersion(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
235 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
241 static HRESULT JSGlobal_ScriptEngineBuildVersion(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
242 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
248 static HRESULT JSGlobal_CollectGarbage(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
249 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
255 static const builtin_prop_t JSGlobal_props[] = {
256 {ActiveXObjectW, JSGlobal_ActiveXObject, PROPF_METHOD},
257 {ArrayW, JSGlobal_Array, PROPF_CONSTR},
258 {BooleanW, JSGlobal_Boolean, PROPF_CONSTR},
259 {CollectGarbageW, JSGlobal_CollectGarbage, PROPF_METHOD},
260 {DateW, JSGlobal_Date, PROPF_CONSTR},
261 {EnumeratorW, JSGlobal_Enumerator, PROPF_METHOD},
262 {FunctionW, JSGlobal_Function, PROPF_CONSTR},
263 {GetObjectW, JSGlobal_GetObject, PROPF_METHOD},
264 {InfinityW, JSGlobal_Infinity, 0},
265 /* {MathW, JSGlobal_Math, 0}, */
266 {NaNW, JSGlobal_NaN, 0},
267 {NumberW, JSGlobal_Number, PROPF_CONSTR},
268 {ObjectW, JSGlobal_Object, PROPF_CONSTR},
269 {RegExpW, JSGlobal_RegExp, PROPF_CONSTR},
270 {ScriptEngineW, JSGlobal_ScriptEngine, PROPF_METHOD},
271 {ScriptEngineBuildVersionW, JSGlobal_ScriptEngineBuildVersion, PROPF_METHOD},
272 {ScriptEngineMajorVersionW, JSGlobal_ScriptEngineMajorVersion, PROPF_METHOD},
273 {ScriptEngineMinorVersionW, JSGlobal_ScriptEngineMinorVersion, PROPF_METHOD},
274 {StringW, JSGlobal_String, PROPF_CONSTR},
275 {VBArrayW, JSGlobal_VBArray, PROPF_METHOD},
276 {escapeW, JSGlobal_escape, PROPF_METHOD},
277 {evalW, JSGlobal_eval, PROPF_METHOD},
278 {isFiniteW, JSGlobal_isFinite, PROPF_METHOD},
279 {isNaNW, JSGlobal_isNaN, PROPF_METHOD},
280 {parseFloatW, JSGlobal_parseFloat, PROPF_METHOD},
281 {parseIntW, JSGlobal_parseInt, PROPF_METHOD|2},
282 {unescapeW, JSGlobal_unescape, PROPF_METHOD}
285 static const builtin_info_t JSGlobal_info = {
288 sizeof(JSGlobal_props)/sizeof(*JSGlobal_props),
294 static HRESULT init_constructors(script_ctx_t *ctx)
298 hres = create_array_constr(ctx, &ctx->array_constr);
302 hres = create_bool_constr(ctx, &ctx->bool_constr);
306 hres = create_number_constr(ctx, &ctx->number_constr);
310 hres = create_object_constr(ctx, &ctx->object_constr);
314 hres = create_object_constr(ctx, &ctx->regexp_constr);
318 hres = create_string_constr(ctx, &ctx->string_constr);
325 HRESULT init_global(script_ctx_t *ctx)
334 hres = init_constructors(ctx);
338 hres = create_dispex(ctx, &JSGlobal_info, NULL, &ctx->global);
342 hres = create_math(ctx, &math);
346 V_VT(&var) = VT_DISPATCH;
347 V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(math);
348 hres = jsdisp_propput_name(ctx->global, MathW, ctx->lcid, &var, NULL/*FIXME*/, NULL/*FIXME*/);
349 jsdisp_release(math);