• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_BUILTINS_BUILTINS_DATE_H
17 #define ECMASCRIPT_BUILTINS_BUILTINS_DATE_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/js_date.h"
21 
22 namespace panda::ecmascript::builtins {
23 class BuiltinsDate : public base::BuiltinsBase {
24 public:
25     // 20.4.2 The Date Constructor
26     static JSTaggedValue DateConstructor(EcmaRuntimeCallInfo *argv);
27 
28     // 20.4.3.1 Date.now ( )
29     static JSTaggedValue Now(EcmaRuntimeCallInfo *argv);
30 
31     // 20.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] )
32     static JSTaggedValue UTC(EcmaRuntimeCallInfo *argv);
33 
34     static JSTaggedValue Parse(EcmaRuntimeCallInfo *argv);
35 
36     // 20.4.4.2 Date.prototype.getDate ( )
37     GET_DATE_VALUE(GetDate, DAYS, true);
38 
39     // 20.4.4.3 Date.prototype.getDay ( )
40     GET_DATE_VALUE(GetDay, WEEKDAY, true);
41 
42     // 20.4.4.4 Date.prototype.getFullYear ( )
43     GET_DATE_VALUE(GetFullYear, YEAR, true);
44 
45     // 20.4.4.5 Date.prototype.getHours ( )
46     GET_DATE_VALUE(GetHours, HOUR, true);
47 
48     // 20.4.4.6 Date.prototype.getMilliseconds ( )
49     GET_DATE_VALUE(GetMilliseconds, MS, true);
50 
51     // 20.4.4.7 Date.prototype.getMinutes ( )
52     GET_DATE_VALUE(GetMinutes, MIN, true);
53 
54     // 20.4.4.8 Date.prototype.getMonth ( )
55     GET_DATE_VALUE(GetMonth, MONTH, true);
56 
57     // 20.4.4.9 Date.prototype.getSeconds ( )
58     GET_DATE_VALUE(GetSeconds, SEC, true);
59 
60     // 20.4.4.10 Date.prototype.getTime ( )
61     static JSTaggedValue GetTime(EcmaRuntimeCallInfo *argv);
62 
63     // 20.4.4.11 Date.prototype.getTimezoneOffset ( )
64     GET_DATE_VALUE(GetTimezoneOffset, TIMEZONE, true);
65 
66     // 20.4.4.12 Date.prototype.getUTCDate ( )
67     GET_DATE_VALUE(GetUTCDate, DAYS, false);
68 
69     // 20.4.4.13 Date.prototype.getUTCDay ( )
70     GET_DATE_VALUE(GetUTCDay, WEEKDAY, false);
71 
72     // 20.4.4.14 Date.prototype.getUTCFullYear ( )
73     GET_DATE_VALUE(GetUTCFullYear, YEAR, false);
74 
75     // 20.4.4.15 Date.prototype.getUTCHours ( )
76     GET_DATE_VALUE(GetUTCHours, HOUR, false);
77 
78     // 20.4.4.16 Date.prototype.getUTCMilliseconds ( )
79     GET_DATE_VALUE(GetUTCMilliseconds, MS, false);
80 
81     // 20.4.4.17 Date.prototype.getUTCMinutes ( )
82     GET_DATE_VALUE(GetUTCMinutes, MIN, false);
83 
84     // 20.4.4.18 Date.prototype.getUTCMonth ( )
85     GET_DATE_VALUE(GetUTCMonth, MONTH, false);
86 
87     // 20.4.4.19 Date.prototype.getUTCSeconds ( )
88     GET_DATE_VALUE(GetUTCSeconds, SEC, false);
89 
90     // 20.3.4.20 Date.prototype.setDate ( date )
91     SET_DATE_VALUE(SetDate, CODE_SET_DATE, true);
92 
93     // 20.3.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] )
94     SET_DATE_VALUE(SetFullYear, CODE_SET_FULL_YEAR, true);
95 
96     // 20.3.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] )
97     SET_DATE_VALUE(SetHours, CODE_SET_HOURS, true);
98 
99     // 20.3.4.23 Date.prototype.setMilliseconds ( ms )
100     SET_DATE_VALUE(SetMilliseconds, CODE_SET_MILLISECONDS, true);
101 
102     // 20.3.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] )
103     SET_DATE_VALUE(SetMinutes, CODE_SET_MINUTES, true);
104 
105     // 20.3.4.25 Date.prototype.setMonth ( month [ , date ] )
106     SET_DATE_VALUE(SetMonth, CODE_SET_MONTH, true);
107 
108     // 20.3.4.26 Date.prototype.setSeconds ( sec [ , ms ] )
109     SET_DATE_VALUE(SetSeconds, CODE_SET_SECONDS, true);
110 
111     // 20.3.4.27 Date.prototype.setTime ( time )
112     static JSTaggedValue SetTime(EcmaRuntimeCallInfo *argv);
113 
114     // 20.3.4.28 Date.prototype.setUTCDate ( date )
115     SET_DATE_VALUE(SetUTCDate, CODE_SET_DATE, false);
116 
117     // 20.3.4.29 Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] )
118     SET_DATE_VALUE(SetUTCFullYear, CODE_SET_FULL_YEAR, false);
119 
120     // 20.3.4.30 Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] )
121     SET_DATE_VALUE(SetUTCHours, CODE_SET_HOURS, false);
122 
123     // 20.3.4.31 Date.prototype.setUTCMilliseconds ( ms )
124     SET_DATE_VALUE(SetUTCMilliseconds, CODE_SET_MILLISECONDS, false);
125 
126     // 20.3.4.32 Date.prototype.setUTCMinutes ( min [ , sec [, ms ] ] )
127     SET_DATE_VALUE(SetUTCMinutes, CODE_SET_MINUTES, false);
128 
129     // 20.3.4.33 Date.prototype.setUTCMonth ( month [ , date ] )
130     SET_DATE_VALUE(SetUTCMonth, CODE_SET_MONTH, false);
131 
132     // 20.3.4.34 Date.prototype.setUTCSeconds ( sec [ , ms ] )
133     SET_DATE_VALUE(SetUTCSeconds, CODE_SET_SECONDS, false);
134 
135     // 20.4.4.35 Date.prototype.toDateString ( )
136     DATE_STRING(ToDateString);
137 
138     // 20.4.4.36 Date.prototype.toISOString ( )
139     DATE_TO_STRING(ToISOString);
140 
141     // 20.4.4.37 Date.prototype.toJSON ( key )
142     static JSTaggedValue ToJSON(EcmaRuntimeCallInfo *argv);
143 
144     // 20.4.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] )
145     static JSTaggedValue ToLocaleDateString(EcmaRuntimeCallInfo *argv);
146 
147     // 20.4.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
148     static JSTaggedValue ToLocaleString(EcmaRuntimeCallInfo *argv);
149 
150     // 20.4.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] )
151     static JSTaggedValue ToLocaleTimeString(EcmaRuntimeCallInfo *argv);
152 
153     // 20.4.4.41 Date.prototype.toString ( )
154     DATE_STRING(ToString);
155 
156     // 20.4.4.42 Date.prototype.toTimeString ( )
157     DATE_STRING(ToTimeString);
158 
159     // 20.4.4.43 Date.prototype.toUTCString ( )
160     DATE_STRING(ToUTCString);
161 
162     // 20.4.4.44 Date.prototype.valueOf ( )
163     static JSTaggedValue ValueOf(EcmaRuntimeCallInfo *argv);
164 
165     // 20.4.4.45 Date.prototype [ @@toPrimitive ]
166     static JSTaggedValue ToPrimitive(EcmaRuntimeCallInfo *argv);
167 
168 private:
169     // definition for set data code.
170     static constexpr uint32_t CODE_SET_DATE = 0x32;
171     static constexpr uint32_t CODE_SET_MILLISECONDS = 0x76;
172     static constexpr uint32_t CODE_SET_SECONDS = 0x75;
173     static constexpr uint32_t CODE_SET_MINUTES = 0x74;
174     static constexpr uint32_t CODE_SET_HOURS = 0x73;
175     static constexpr uint32_t CODE_SET_MONTH = 0x31;
176     static constexpr uint32_t CODE_SET_FULL_YEAR = 0x30;
177     static constexpr uint8_t CONSTRUCTOR_MAX_LENGTH = 7;
178 };
179 }  // namespace panda::ecmascript::builtins
180 #endif  // ECMASCRIPT_BUILTINS_BUILTINS_DATE_H
181