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);
29 static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
30 static const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
31 static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
32 static const WCHAR propertyIsEnumerableW[] =
33 {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
34 static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
35 static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
36 static const WCHAR toUTCStringW[] = {'t','o','U','T','C','S','t','r','i','n','g',0};
37 static const WCHAR toDateStringW[] = {'t','o','D','a','t','e','S','t','r','i','n','g',0};
38 static const WCHAR toTimeStringW[] = {'t','o','T','i','m','e','S','t','r','i','n','g',0};
39 static const WCHAR toLocaleDateStringW[] = {'t','o','L','o','c','a','l','e','D','a','t','e','S','t','r','i','n','g',0};
40 static const WCHAR toLocaleTimeStringW[] = {'t','o','L','o','c','a','l','e','T','i','m','e','S','t','r','i','n','g',0};
41 static const WCHAR getTimeW[] = {'g','e','t','T','i','m','e',0};
42 static const WCHAR getFullYearW[] = {'g','e','t','F','u','l','l','Y','e','a','r',0};
43 static const WCHAR getUTCFullYearW[] = {'g','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
44 static const WCHAR getMonthW[] = {'g','e','t','M','o','n','t','h',0};
45 static const WCHAR getUTCMonthW[] = {'g','e','t','U','T','C','M','o','n','t','h',0};
46 static const WCHAR getDateW[] = {'g','e','t','D','a','t','e',0};
47 static const WCHAR getUTCDateW[] = {'g','e','t','U','T','C','D','a','t','e',0};
48 static const WCHAR getDayW[] = {'g','e','t','D','a','y',0};
49 static const WCHAR getUTCDayW[] = {'g','e','t','U','T','C','D','a','y',0};
50 static const WCHAR getHoursW[] = {'g','e','t','H','o','u','r','s',0};
51 static const WCHAR getUTCHoursW[] = {'g','e','t','U','T','C','H','o','u','r','s',0};
52 static const WCHAR getMinutesW[] = {'g','e','t','M','i','n','u','t','e','s',0};
53 static const WCHAR getUTCMinutesW[] = {'g','e','t','U','T','C','M','i','n','u','t','e','s',0};
54 static const WCHAR getSecondsW[] = {'g','e','t','S','e','c','o','n','d','s',0};
55 static const WCHAR getUTCSecondsW[] = {'g','e','t','U','T','C','S','e','c','o','n','d','s',0};
56 static const WCHAR getMilisecondsW[] = {'g','e','t','M','i','l','i','s','e','c','o','n','d','s',0};
57 static const WCHAR getUTCMilisecondsW[] = {'g','e','t','U','T','C','M','i','l','i','s','e','c','o','n','d','s',0};
58 static const WCHAR getTimezoneOffsetW[] = {'g','e','t','T','i','m','e','z','o','n','e','O','f','f','s','e','t',0};
59 static const WCHAR setTimeW[] = {'s','e','t','T','i','m','e',0};
60 static const WCHAR setMilisecondsW[] = {'s','e','t','M','i','l','i','s','e','c','o','n','d','s',0};
61 static const WCHAR setUTCMilisecondsW[] = {'s','e','t','U','T','C','M','i','l','i','s','e','c','o','n','d','s',0};
62 static const WCHAR setSecondsW[] = {'s','e','t','S','e','c','o','n','d','s',0};
63 static const WCHAR setUTCSecondsW[] = {'s','e','t','U','T','C','S','e','c','o','n','d','s',0};
64 static const WCHAR setMinutesW[] = {'s','e','t','M','i','n','u','t','e','s',0};
65 static const WCHAR setUTCMinutesW[] = {'s','e','t','U','T','C','M','i','n','u','t','e','s',0};
66 static const WCHAR setHoursW[] = {'s','e','t','H','o','u','r','s',0};
67 static const WCHAR setUTCHoursW[] = {'s','e','t','H','o','u','r','s',0};
68 static const WCHAR setDateW[] = {'s','e','t','D','a','t','e',0};
69 static const WCHAR setUTCDateW[] = {'s','e','t','U','T','C','D','a','t','e',0};
70 static const WCHAR setMonthW[] = {'s','e','t','M','o','n','t','h',0};
71 static const WCHAR setUTCMonthW[] = {'s','e','t','U','T','C','M','o','n','t','h',0};
72 static const WCHAR setFullYearW[] = {'s','e','t','F','u','l','l','Y','e','a','r',0};
73 static const WCHAR setUTCFullYearW[] = {'s','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
75 static inline HRESULT systime_to_time(const SYSTEMTIME *st, FILETIME *time)
77 return SystemTimeToFileTime(st, time) ? S_OK : HRESULT_FROM_WIN32(GetLastError());
80 static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
81 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
87 static HRESULT Date_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
88 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
94 static HRESULT Date_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
95 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
101 static HRESULT Date_propertyIsEnumerable(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
102 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
108 static HRESULT Date_isPrototypeOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
109 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
115 static HRESULT Date_valueOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
116 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
122 static HRESULT Date_toUTCString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
123 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
129 static HRESULT Date_toDateString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
130 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
136 static HRESULT Date_toTimeString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
137 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
143 static HRESULT Date_toLocaleDateString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
144 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
150 static HRESULT Date_toLocaleTimeString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
151 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
157 static HRESULT Date_getTime(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
158 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
164 static HRESULT Date_getFullYear(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
165 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
171 static HRESULT Date_getUTCFullYear(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
172 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
178 static HRESULT Date_getMonth(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
179 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
185 static HRESULT Date_getUTCMonth(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
186 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
192 static HRESULT Date_getDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
193 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
199 static HRESULT Date_getUTCDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
200 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
206 static HRESULT Date_getDay(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
207 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
213 static HRESULT Date_getUTCDay(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
214 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
220 static HRESULT Date_getHours(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
221 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
227 static HRESULT Date_getUTCHours(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
228 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
234 static HRESULT Date_getMinutes(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
235 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
241 static HRESULT Date_getUTCMinutes(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
242 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
248 static HRESULT Date_getSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
249 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
255 static HRESULT Date_getUTCSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
256 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
262 static HRESULT Date_getMiliseconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
263 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
269 static HRESULT Date_getUTCMiliseconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
270 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
276 static HRESULT Date_getTimezoneOffset(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
277 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
283 static HRESULT Date_setTime(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
284 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
290 static HRESULT Date_setMiliseconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
291 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
297 static HRESULT Date_setUTCMiliseconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
298 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
304 static HRESULT Date_setSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
305 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
311 static HRESULT Date_setUTCSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
312 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
318 static HRESULT Date_setMinutes(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
319 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
325 static HRESULT Date_setUTCMinutes(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
326 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
332 static HRESULT Date_setHours(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
333 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
339 static HRESULT Date_setUTCHours(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
340 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
346 static HRESULT Date_setDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
347 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
353 static HRESULT Date_setUTCDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
354 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
360 static HRESULT Date_setMonth(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
361 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
367 static HRESULT Date_setUTCMonth(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
368 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
374 static HRESULT Date_setFullYear(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
375 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
381 static HRESULT Date_setUTCFullYear(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
382 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
388 static HRESULT Date_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
389 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
395 static const builtin_prop_t Date_props[] = {
396 {getDateW, Date_getDate, PROPF_METHOD},
397 {getDayW, Date_getDay, PROPF_METHOD},
398 {getFullYearW, Date_getFullYear, PROPF_METHOD},
399 {getHoursW, Date_getHours, PROPF_METHOD},
400 {getMilisecondsW, Date_getMiliseconds, PROPF_METHOD},
401 {getMinutesW, Date_getMinutes, PROPF_METHOD},
402 {getMonthW, Date_getMonth, PROPF_METHOD},
403 {getSecondsW, Date_getSeconds, PROPF_METHOD},
404 {getTimeW, Date_getTime, PROPF_METHOD},
405 {getTimezoneOffsetW, Date_getTimezoneOffset, PROPF_METHOD},
406 {getUTCDateW, Date_getUTCDate, PROPF_METHOD},
407 {getUTCDayW, Date_getUTCDay, PROPF_METHOD},
408 {getUTCFullYearW, Date_getUTCFullYear, PROPF_METHOD},
409 {getUTCHoursW, Date_getUTCHours, PROPF_METHOD},
410 {getUTCMilisecondsW, Date_getUTCMiliseconds, PROPF_METHOD},
411 {getUTCMinutesW, Date_getUTCMinutes, PROPF_METHOD},
412 {getUTCMonthW, Date_getUTCMonth, PROPF_METHOD},
413 {getUTCSecondsW, Date_getUTCSeconds, PROPF_METHOD},
414 {hasOwnPropertyW, Date_hasOwnProperty, PROPF_METHOD},
415 {isPrototypeOfW, Date_isPrototypeOf, PROPF_METHOD},
416 {propertyIsEnumerableW, Date_propertyIsEnumerable, PROPF_METHOD},
417 {setDateW, Date_setDate, PROPF_METHOD},
418 {setFullYearW, Date_setFullYear, PROPF_METHOD},
419 {setHoursW, Date_setHours, PROPF_METHOD},
420 {setMilisecondsW, Date_setMiliseconds, PROPF_METHOD},
421 {setMinutesW, Date_setMinutes, PROPF_METHOD},
422 {setMonthW, Date_setMonth, PROPF_METHOD},
423 {setSecondsW, Date_setSeconds, PROPF_METHOD},
424 {setTimeW, Date_setTime, PROPF_METHOD},
425 {setUTCDateW, Date_setUTCDate, PROPF_METHOD},
426 {setUTCFullYearW, Date_setUTCFullYear, PROPF_METHOD},
427 {setUTCHoursW, Date_setUTCHours, PROPF_METHOD},
428 {setUTCMilisecondsW, Date_setUTCMiliseconds, PROPF_METHOD},
429 {setUTCMinutesW, Date_setUTCMinutes, PROPF_METHOD},
430 {setUTCMonthW, Date_setUTCMonth, PROPF_METHOD},
431 {setUTCSecondsW, Date_setUTCSeconds, PROPF_METHOD},
432 {toDateStringW, Date_toDateString, PROPF_METHOD},
433 {toLocaleDateStringW, Date_toLocaleDateString, PROPF_METHOD},
434 {toLocaleStringW, Date_toLocaleString, PROPF_METHOD},
435 {toLocaleTimeStringW, Date_toLocaleTimeString, PROPF_METHOD},
436 {toStringW, Date_toString, PROPF_METHOD},
437 {toTimeStringW, Date_toTimeString, PROPF_METHOD},
438 {toUTCStringW, Date_toUTCString, PROPF_METHOD},
439 {valueOfW, Date_valueOf, PROPF_METHOD},
442 static const builtin_info_t Date_info = {
444 {NULL, Date_value, 0},
445 sizeof(Date_props)/sizeof(*Date_props),
451 static HRESULT create_date(script_ctx_t *ctx, BOOL use_constr, DispatchEx **ret)
456 date = heap_alloc_zero(sizeof(DateInstance));
458 return E_OUTOFMEMORY;
461 hres = init_dispex_from_constr(&date->dispex, ctx, &Date_info, ctx->date_constr);
463 hres = init_dispex(&date->dispex, ctx, &Date_info, NULL);
469 *ret = &date->dispex;
473 static HRESULT DateConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
474 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
480 HRESULT create_date_constr(script_ctx_t *ctx, DispatchEx **ret)
485 hres = create_date(ctx, FALSE, &date);
489 hres = create_builtin_function(ctx, DateConstr_value, PROPF_CONSTR, date, ret);
491 jsdisp_release(date);