1515 */
1616
1717#include " ecma-alloc.h"
18+ #include " ecma-builtin-helpers.h"
19+ #include " ecma-exceptions.h"
1820#include " ecma-globals.h"
1921#include " ecma-helpers.h"
22+ #include " ecma-objects.h"
23+ #include " ecma-try-catch-macro.h"
2024
2125#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN
2226
@@ -139,7 +143,7 @@ ecma_builtin_date_prototype_to_locale_time_string (ecma_value_t this_arg) /**< t
139143static ecma_completion_value_t
140144ecma_builtin_date_prototype_value_of (ecma_value_t this_arg) /* *< this argument */
141145{
142- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
146+ return ecma_builtin_date_prototype_get_time (this_arg);
143147} /* ecma_builtin_date_prototype_value_of */
144148
145149/* *
@@ -154,263 +158,93 @@ ecma_builtin_date_prototype_value_of (ecma_value_t this_arg) /**< this argument
154158static ecma_completion_value_t
155159ecma_builtin_date_prototype_get_time (ecma_value_t this_arg) /* *< this argument */
156160{
157- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
158- } /* ecma_builtin_date_prototype_get_time */
161+ if (ecma_is_value_object (this_arg))
162+ {
163+ ecma_object_t *obj_p = ecma_get_object_from_value (this_arg);
164+ if (ecma_object_get_class_name (obj_p) == LIT_MAGIC_STRING_DATE_UL)
165+ {
166+ ecma_property_t *prim_value_prop_p = ecma_get_internal_property (obj_p,
167+ ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
159168
160- /* *
161- * The Date.prototype object's 'getFullYear' routine
162- *
163- * See also:
164- * ECMA-262 v5, 15.9.5.10
165- *
166- * @return completion value
167- * Returned value must be freed with ecma_free_completion_value.
168- */
169- static ecma_completion_value_t
170- ecma_builtin_date_prototype_get_full_year (ecma_value_t this_arg) /* *< this argument */
171- {
172- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
173- } /* ecma_builtin_date_prototype_get_full_year */
169+ ecma_number_t *prim_value_num_p = ECMA_GET_NON_NULL_POINTER (ecma_number_t ,
170+ prim_value_prop_p->u .internal_property .value );
174171
175- /* *
176- * The Date.prototype object's 'getUTCFullYear' routine
177- *
178- * See also:
179- * ECMA-262 v5, 15.9.5.11
180- *
181- * @return completion value
182- * Returned value must be freed with ecma_free_completion_value.
183- */
184- static ecma_completion_value_t
185- ecma_builtin_date_prototype_get_utc_full_year (ecma_value_t this_arg) /* *< this argument */
186- {
187- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
188- } /* ecma_builtin_date_prototype_get_utc_full_year */
172+ ecma_number_t *ret_num_p = ecma_alloc_number ();
173+ *ret_num_p = *prim_value_num_p;
189174
190- /* *
191- * The Date.prototype object's 'getMonth' routine
192- *
193- * See also:
194- * ECMA-262 v5, 15.9.5.12
195- *
196- * @return completion value
197- * Returned value must be freed with ecma_free_completion_value.
198- */
199- static ecma_completion_value_t
200- ecma_builtin_date_prototype_get_month (ecma_value_t this_arg) /* *< this argument */
201- {
202- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
203- } /* ecma_builtin_date_prototype_get_month */
175+ return ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p));
176+ }
177+ }
204178
205- /* *
206- * The Date.prototype object's 'getUTCMonth' routine
207- *
208- * See also:
209- * ECMA-262 v5, 15.9.5.13
210- *
211- * @return completion value
212- * Returned value must be freed with ecma_free_completion_value.
213- */
214- static ecma_completion_value_t
215- ecma_builtin_date_prototype_get_utc_month (ecma_value_t this_arg) /* *< this argument */
216- {
217- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
218- } /* ecma_builtin_date_prototype_get_utc_month */
219-
220- /* *
221- * The Date.prototype object's 'getDate' routine
222- *
223- * See also:
224- * ECMA-262 v5, 15.9.5.14
225- *
226- * @return completion value
227- * Returned value must be freed with ecma_free_completion_value.
228- */
229- static ecma_completion_value_t
230- ecma_builtin_date_prototype_get_date (ecma_value_t this_arg) /* *< this argument */
231- {
232- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
233- } /* ecma_builtin_date_prototype_get_date */
234-
235- /* *
236- * The Date.prototype object's 'getUTCDate' routine
237- *
238- * See also:
239- * ECMA-262 v5, 15.9.5.15
240- *
241- * @return completion value
242- * Returned value must be freed with ecma_free_completion_value.
243- */
244- static ecma_completion_value_t
245- ecma_builtin_date_prototype_get_utc_date (ecma_value_t this_arg) /* *< this argument */
246- {
247- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
248- } /* ecma_builtin_date_prototype_get_utc_date */
249-
250- /* *
251- * The Date.prototype object's 'getDay' routine
252- *
253- * See also:
254- * ECMA-262 v5, 15.9.5.16
255- *
256- * @return completion value
257- * Returned value must be freed with ecma_free_completion_value.
258- */
259- static ecma_completion_value_t
260- ecma_builtin_date_prototype_get_day (ecma_value_t this_arg) /* *< this argument */
261- {
262- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
263- } /* ecma_builtin_date_prototype_get_day */
264-
265- /* *
266- * The Date.prototype object's 'getUTCDay' routine
267- *
268- * See also:
269- * ECMA-262 v5, 15.9.5.17
270- *
271- * @return completion value
272- * Returned value must be freed with ecma_free_completion_value.
273- */
274- static ecma_completion_value_t
275- ecma_builtin_date_prototype_get_utc_day (ecma_value_t this_arg) /* *< this argument */
276- {
277- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
278- } /* ecma_builtin_date_prototype_get_utc_day */
279-
280- /* *
281- * The Date.prototype object's 'getHours' routine
282- *
283- * See also:
284- * ECMA-262 v5, 15.9.5.18
285- *
286- * @return completion value
287- * Returned value must be freed with ecma_free_completion_value.
288- */
289- static ecma_completion_value_t
290- ecma_builtin_date_prototype_get_hours (ecma_value_t this_arg) /* *< this argument */
291- {
292- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
293- } /* ecma_builtin_date_prototype_get_hours */
294-
295- /* *
296- * The Date.prototype object's 'getUTCHours' routine
297- *
298- * See also:
299- * ECMA-262 v5, 15.9.5.19
300- *
301- * @return completion value
302- * Returned value must be freed with ecma_free_completion_value.
303- */
304- static ecma_completion_value_t
305- ecma_builtin_date_prototype_get_utc_hours (ecma_value_t this_arg) /* *< this argument */
306- {
307- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
308- } /* ecma_builtin_date_prototype_get_utc_hours */
309-
310- /* *
311- * The Date.prototype object's 'getMinutes' routine
312- *
313- * See also:
314- * ECMA-262 v5, 15.9.5.20
315- *
316- * @return completion value
317- * Returned value must be freed with ecma_free_completion_value.
318- */
319- static ecma_completion_value_t
320- ecma_builtin_date_prototype_get_minutes (ecma_value_t this_arg) /* *< this argument */
321- {
322- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
323- } /* ecma_builtin_date_prototype_get_minutes */
324-
325- /* *
326- * The Date.prototype object's 'getUTCMinutes' routine
327- *
328- * See also:
329- * ECMA-262 v5, 15.9.5.21
330- *
331- * @return completion value
332- * Returned value must be freed with ecma_free_completion_value.
333- */
334- static ecma_completion_value_t
335- ecma_builtin_date_prototype_get_utc_minutes (ecma_value_t this_arg) /* *< this argument */
336- {
337- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
338- } /* ecma_builtin_date_prototype_get_utc_minutes */
339-
340- /* *
341- * The Date.prototype object's 'getSeconds' routine
342- *
343- * See also:
344- * ECMA-262 v5, 15.9.5.22
345- *
346- * @return completion value
347- * Returned value must be freed with ecma_free_completion_value.
348- */
349- static ecma_completion_value_t
350- ecma_builtin_date_prototype_get_seconds (ecma_value_t this_arg) /* *< this argument */
351- {
352- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
353- } /* ecma_builtin_date_prototype_get_seconds */
354-
355- /* *
356- * The Date.prototype object's 'getUTCSeconds' routine
357- *
358- * See also:
359- * ECMA-262 v5, 15.9.5.23
360- *
361- * @return completion value
362- * Returned value must be freed with ecma_free_completion_value.
363- */
364- static ecma_completion_value_t
365- ecma_builtin_date_prototype_get_utc_seconds (ecma_value_t this_arg) /* *< this argument */
366- {
367- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
368- } /* ecma_builtin_date_prototype_get_utc_seconds */
369-
370- /* *
371- * The Date.prototype object's 'getMilliseconds' routine
372- *
373- * See also:
374- * ECMA-262 v5, 15.9.5.24
375- *
376- * @return completion value
377- * Returned value must be freed with ecma_free_completion_value.
378- */
379- static ecma_completion_value_t
380- ecma_builtin_date_prototype_get_milliseconds (ecma_value_t this_arg) /* *< this argument */
381- {
382- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
383- } /* ecma_builtin_date_prototype_get_milliseconds */
384-
385- /* *
386- * The Date.prototype object's 'getUTCMilliseconds' routine
387- *
388- * See also:
389- * ECMA-262 v5, 15.9.5.25
390- *
391- * @return completion value
392- * Returned value must be freed with ecma_free_completion_value.
393- */
394- static ecma_completion_value_t
395- ecma_builtin_date_prototype_get_utc_milliseconds (ecma_value_t this_arg) /* *< this argument */
396- {
397- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
398- } /* ecma_builtin_date_prototype_get_utc_milliseconds */
179+ return ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_TYPE));
180+ } /* ecma_builtin_date_prototype_get_time */
399181
400182/* *
401- * The Date.prototype object's 'getTimezoneOffset' routine
402- *
403- * See also:
404- * ECMA-262 v5, 15.9.5.26
405- *
406- * @return completion value
407- * Returned value must be freed with ecma_free_completion_value.
408- */
409- static ecma_completion_value_t
410- ecma_builtin_date_prototype_get_timezone_offset (ecma_value_t this_arg) /* *< this argument */
411- {
412- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
413- } /* ecma_builtin_date_prototype_get_timezone_offset */
183+ * Helper macro, define the getter function argument to use
184+ * UTC time, passing the argument as is.
185+ */
186+ #define DEFINE_GETTER_ARGUMENT_utc (this_num ) (this_num)
187+
188+ /* *
189+ * Helper macro, define the getter function argument to use
190+ * local time, passing the argument to 'ecma_date_local_time' function.
191+ */
192+ #define DEFINE_GETTER_ARGUMENT_local (this_num ) (ecma_date_local_time (this_num))
193+
194+ /* *
195+ * Implementation of Data.prototype built-in's getter routines
196+ *
197+ * @return completion value
198+ * Returned value must be freed with ecma_free_completion_value.
199+ */
200+ #define DEFINE_GETTER (_ecma_paragraph, _routine_name, _getter_name, _timezone ) \
201+ static ecma_completion_value_t \
202+ ecma_builtin_date_prototype_get_ ## _routine_name (ecma_value_t this_arg) /* *< this argument */ \
203+ { \
204+ ecma_completion_value_t ret_value = ecma_make_empty_completion_value (); \
205+ \
206+ /* 1. */ \
207+ ECMA_TRY_CATCH (value, ecma_builtin_date_prototype_get_time (this_arg), ret_value); \
208+ ecma_number_t *this_num_p = ecma_get_number_from_value (value); \
209+ /* 2. */ \
210+ if (ecma_number_is_nan (*this_num_p)) \
211+ { \
212+ ecma_string_t *nan_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_NAN); \
213+ ret_value = ecma_make_normal_completion_value (ecma_make_string_value (nan_str_p)); \
214+ } \
215+ else \
216+ { \
217+ /* 3. */ \
218+ ecma_number_t *ret_num_p = ecma_alloc_number (); \
219+ *ret_num_p = _getter_name (DEFINE_GETTER_ARGUMENT_ ## _timezone (*this_num_p)); \
220+ ret_value = ecma_make_normal_completion_value (ecma_make_number_value (ret_num_p)); \
221+ } \
222+ ECMA_FINALIZE (value); \
223+ \
224+ return ret_value; \
225+ }
226+
227+ DEFINE_GETTER (ECMA-262 v5 15.9.5.10 , full_year, ecma_date_year_from_time, local)
228+ DEFINE_GETTER (ECMA-262 v5 15.9.5.11 , utc_full_year, ecma_date_year_from_time, utc)
229+ DEFINE_GETTER (ECMA-262 v5 15.9.5.12 , month, ecma_date_month_from_time, local)
230+ DEFINE_GETTER (ECMA-262 v5 15.9.5.13 , utc_month, ecma_date_month_from_time, utc)
231+ DEFINE_GETTER (ECMA-262 v5 15.9.5.14 , date, ecma_date_date_from_time, local)
232+ DEFINE_GETTER (ECMA-262 v5 15.9.5.15 , utc_date, ecma_date_date_from_time, utc)
233+ DEFINE_GETTER (ECMA-262 v5 15.9.5.16 , day, ecma_date_week_day, local)
234+ DEFINE_GETTER (ECMA-262 v5 15.9.5.17 , utc_day, ecma_date_week_day, utc)
235+ DEFINE_GETTER (ECMA-262 v5 15.9.5.18 , hours, ecma_date_hour_from_time, local)
236+ DEFINE_GETTER (ECMA-262 v5 15.9.5.19 , utc_hours, ecma_date_hour_from_time, utc)
237+ DEFINE_GETTER (ECMA-262 v5 15.9.5.20 , minutes, ecma_date_min_from_time, local)
238+ DEFINE_GETTER (ECMA-262 v5 15.9.5.21 , utc_minutes, ecma_date_min_from_time, utc)
239+ DEFINE_GETTER (ECMA-262 v5 15.9.5.22 , seconds, ecma_date_sec_from_time, local)
240+ DEFINE_GETTER (ECMA-262 v5 15.9.5.23 , utc_seconds, ecma_date_sec_from_time, utc)
241+ DEFINE_GETTER (ECMA-262 v5 15.9.5.24 , milliseconds, ecma_date_ms_from_time , local)
242+ DEFINE_GETTER (ECMA-262 v5 15.9.5.25 , utc_milliseconds, ecma_date_ms_from_time , utc)
243+ DEFINE_GETTER (ECMA-262 v5 15.9.5.26 , timezone_offset, ecma_date_timezone_offset, utc)
244+
245+ #undef DEFINE_GETTER_ARGUMENT_utc
246+ #undef DEFINE_GETTER_ARGUMENT_local
247+ #undef DEFINE_GETTER
414248
415249/* *
416250 * The Date.prototype object's 'setTime' routine
0 commit comments