jseption 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +191 -2
  3. package/dist/atoms.d.ts +255 -0
  4. package/dist/atoms.js +445 -0
  5. package/dist/atoms.js.map +1 -0
  6. package/dist/builtins/array.d.ts +3 -0
  7. package/dist/builtins/array.js +116 -0
  8. package/dist/builtins/array.js.map +1 -0
  9. package/dist/builtins/bigint.d.ts +3 -0
  10. package/dist/builtins/bigint.js +122 -0
  11. package/dist/builtins/bigint.js.map +1 -0
  12. package/dist/builtins/boolean.d.ts +2 -0
  13. package/dist/builtins/boolean.js +26 -0
  14. package/dist/builtins/boolean.js.map +1 -0
  15. package/dist/builtins/date.d.ts +3 -0
  16. package/dist/builtins/date.js +1046 -0
  17. package/dist/builtins/date.js.map +1 -0
  18. package/dist/builtins/error.d.ts +2 -0
  19. package/dist/builtins/error.js +154 -0
  20. package/dist/builtins/error.js.map +1 -0
  21. package/dist/builtins/function.d.ts +5 -0
  22. package/dist/builtins/function.js +164 -0
  23. package/dist/builtins/function.js.map +1 -0
  24. package/dist/builtins/global.d.ts +2 -0
  25. package/dist/builtins/global.js +29 -0
  26. package/dist/builtins/global.js.map +1 -0
  27. package/dist/builtins/index.d.ts +3 -0
  28. package/dist/builtins/index.js +139 -0
  29. package/dist/builtins/index.js.map +1 -0
  30. package/dist/builtins/json.d.ts +6 -0
  31. package/dist/builtins/json.js +984 -0
  32. package/dist/builtins/json.js.map +1 -0
  33. package/dist/builtins/mapset.d.ts +4 -0
  34. package/dist/builtins/mapset.js +234 -0
  35. package/dist/builtins/mapset.js.map +1 -0
  36. package/dist/builtins/math.d.ts +2 -0
  37. package/dist/builtins/math.js +62 -0
  38. package/dist/builtins/math.js.map +1 -0
  39. package/dist/builtins/native.d.ts +22 -0
  40. package/dist/builtins/native.js +250 -0
  41. package/dist/builtins/native.js.map +1 -0
  42. package/dist/builtins/number.d.ts +4 -0
  43. package/dist/builtins/number.js +76 -0
  44. package/dist/builtins/number.js.map +1 -0
  45. package/dist/builtins/object.d.ts +12 -0
  46. package/dist/builtins/object.js +575 -0
  47. package/dist/builtins/object.js.map +1 -0
  48. package/dist/builtins/promise.d.ts +13 -0
  49. package/dist/builtins/promise.js +582 -0
  50. package/dist/builtins/promise.js.map +1 -0
  51. package/dist/builtins/proxy.d.ts +3 -0
  52. package/dist/builtins/proxy.js +226 -0
  53. package/dist/builtins/proxy.js.map +1 -0
  54. package/dist/builtins/reflect.d.ts +2 -0
  55. package/dist/builtins/reflect.js +109 -0
  56. package/dist/builtins/reflect.js.map +1 -0
  57. package/dist/builtins/regexp.d.ts +2 -0
  58. package/dist/builtins/regexp.js +203 -0
  59. package/dist/builtins/regexp.js.map +1 -0
  60. package/dist/builtins/string.d.ts +4 -0
  61. package/dist/builtins/string.js +135 -0
  62. package/dist/builtins/string.js.map +1 -0
  63. package/dist/builtins/symbol.d.ts +3 -0
  64. package/dist/builtins/symbol.js +98 -0
  65. package/dist/builtins/symbol.js.map +1 -0
  66. package/dist/builtins/typedarray.d.ts +15 -0
  67. package/dist/builtins/typedarray.js +1838 -0
  68. package/dist/builtins/typedarray.js.map +1 -0
  69. package/dist/builtins/weakref.d.ts +18 -0
  70. package/dist/builtins/weakref.js +130 -0
  71. package/dist/builtins/weakref.js.map +1 -0
  72. package/dist/dump.d.ts +2 -0
  73. package/dist/dump.js +124 -0
  74. package/dist/dump.js.map +1 -0
  75. package/dist/embed.d.ts +18 -0
  76. package/dist/embed.js +286 -0
  77. package/dist/embed.js.map +1 -0
  78. package/dist/interpreter.d.ts +81 -0
  79. package/dist/interpreter.js +3768 -0
  80. package/dist/interpreter.js.map +1 -0
  81. package/dist/jit.d.ts +59 -0
  82. package/dist/jit.js +3440 -0
  83. package/dist/jit.js.map +1 -0
  84. package/dist/jit_hook.d.ts +21 -0
  85. package/dist/jit_hook.js +4 -0
  86. package/dist/jit_hook.js.map +1 -0
  87. package/dist/jit_runtime.d.ts +104 -0
  88. package/dist/jit_runtime.js +721 -0
  89. package/dist/jit_runtime.js.map +1 -0
  90. package/dist/jit_stack.d.ts +24 -0
  91. package/dist/jit_stack.js +227 -0
  92. package/dist/jit_stack.js.map +1 -0
  93. package/dist/jseption.d.ts +15 -0
  94. package/dist/jseption.js +61 -0
  95. package/dist/jseption.js.map +1 -0
  96. package/dist/opcodes.d.ts +347 -0
  97. package/dist/opcodes.js +322 -0
  98. package/dist/opcodes.js.map +1 -0
  99. package/dist/parser.d.ts +283 -0
  100. package/dist/parser.js +9752 -0
  101. package/dist/parser.js.map +1 -0
  102. package/dist/qjs.d.ts +2 -0
  103. package/dist/qjs.js +122 -0
  104. package/dist/qjs.js.map +1 -0
  105. package/dist/quickjs.d.ts +460 -0
  106. package/dist/quickjs.js +3408 -0
  107. package/dist/quickjs.js.map +1 -0
  108. package/dist/std.d.ts +4 -0
  109. package/dist/std.js +273 -0
  110. package/dist/std.js.map +1 -0
  111. package/dist/values.d.ts +447 -0
  112. package/dist/values.js +461 -0
  113. package/dist/values.js.map +1 -0
  114. package/package.json +59 -4
@@ -0,0 +1,1046 @@
1
+ /*
2
+ * Date objects (port of the Date part of quickjs.c)
3
+ *
4
+ * The calendar computations (get_date_fields / set_date_fields / string
5
+ * parsing) are ported from the C version; the host Date is only used to
6
+ * obtain the current time and the local time zone offset.
7
+ */
8
+ import * as Q from "../quickjs.js";
9
+ import { JS_EXCEPTION, JS_IsException, JS_IsUndefined, JS_IsObject, JS_IsFunction, JS_NewObject, js_create_from_ctor, JS_ThrowTypeError, JS_ThrowTypeErrorNotAnObject, JS_ThrowRangeError, JS_GetPropertyStr, JS_Call, JS_ToFloat64, JS_ToString, JS_ToObject, JS_ToPrimitive, JS_ValueToAtom, HINT_NUMBER, HINT_STRING, HINT_NONE, HINT_FORCE_ORDINARY, JS_ATOM_NULL, JS_ATOM_number, JS_ATOM_integer, JS_ATOM_string, JS_ATOM_default, JS_ATOM_Symbol_toPrimitive, JS_SetPropertyFunctionList, JS_NewGlobalCConstructor, JS_CFUNC_DEF, JS_CFUNC_MAGIC_DEF, JS_ALIAS_DEF, } from "../quickjs.js";
10
+ /* ---------------------------------------------------------------------
11
+ helpers
12
+ --------------------------------------------------------------------- */
13
+ /* the C functions receive the real argument count: argv is not padded
14
+ (missing arguments read as undefined) */
15
+ function js_argc(ctx, argv, fn) {
16
+ return argv.length;
17
+ }
18
+ function math_mod(a, b) {
19
+ /* return positive modulo */
20
+ const m = a % b;
21
+ return m + (m < 0 ? b : 0);
22
+ }
23
+ function floor_div(a, b) {
24
+ /* integer division rounding toward -Infinity */
25
+ const m = a % b;
26
+ return (a - (m + (m < 0 ? b : 0))) / b;
27
+ }
28
+ /* OS dependent: return the local time zone offset in minutes (positive
29
+ west of GMT) for the UTC time 'time' in ms */
30
+ function getTimezoneOffset(time) {
31
+ const d = new Date(time);
32
+ const off = d.getTimezoneOffset();
33
+ if (Number.isNaN(off)) {
34
+ /* out of the host range: use the offset of the clamped time */
35
+ const t = Math.max(-8.64e15, Math.min(8.64e15, time));
36
+ const off2 = new Date(t).getTimezoneOffset();
37
+ return Number.isNaN(off2) ? 0 : off2;
38
+ }
39
+ return off;
40
+ }
41
+ function JS_ThisTimeValue(ctx, this_val) {
42
+ if (Q.JS_IsObject(this_val)) {
43
+ if (Q.JS_GetClassID(this_val) === 10 /* JSClassID.DATE */ && typeof Q.JS_GetAnyOpaque(this_val) === 'number')
44
+ return Q.JS_GetAnyOpaque(this_val);
45
+ }
46
+ return JS_ThrowTypeError(ctx, 'not a Date object');
47
+ }
48
+ function JS_SetThisTimeValue(ctx, this_val, v) {
49
+ if (Q.JS_IsObject(this_val)) {
50
+ if (Q.JS_GetClassID(this_val) === 10 /* JSClassID.DATE */) {
51
+ Q.JS_SetOpaque(this_val, v);
52
+ return v;
53
+ }
54
+ }
55
+ return JS_ThrowTypeError(ctx, 'not a Date object');
56
+ }
57
+ function days_from_year(y) {
58
+ return 365 * (y - 1970) + floor_div(y - 1969, 4) - floor_div(y - 1901, 100) + floor_div(y - 1601, 400);
59
+ }
60
+ function days_in_year(y) {
61
+ return 365 + (y % 4 === 0 ? 1 : 0) - (y % 100 === 0 ? 1 : 0) + (y % 400 === 0 ? 1 : 0);
62
+ }
63
+ /* return the year, update days */
64
+ function year_from_days(pdays) {
65
+ let d = pdays.days;
66
+ let y = floor_div(d * 10000, 3652425) + 1970;
67
+ /* the initial approximation is very good, so only a few
68
+ iterations are necessary */
69
+ let d1;
70
+ for (;;) {
71
+ d1 = d - days_from_year(y);
72
+ if (d1 < 0) {
73
+ y--;
74
+ d1 += days_in_year(y);
75
+ }
76
+ else {
77
+ const nd = days_in_year(y);
78
+ if (d1 < nd)
79
+ break;
80
+ d1 -= nd;
81
+ y++;
82
+ }
83
+ }
84
+ pdays.days = d1;
85
+ return y;
86
+ }
87
+ const month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
88
+ const month_names = 'JanFebMarAprMayJunJulAugSepOctNovDec';
89
+ const day_names = 'SunMonTueWedThuFriSat';
90
+ /* fields: [year, month, day, hours, minutes, seconds, ms, weekday, tz]
91
+ returns -1 if exception, 0 if NaN (and !force), 1 otherwise */
92
+ function get_date_fields(ctx, obj, fields, is_local, force) {
93
+ const dval = JS_ThisTimeValue(ctx, obj);
94
+ if (JS_IsException(dval))
95
+ return -1;
96
+ let d;
97
+ let tz = 0;
98
+ if (Number.isNaN(dval)) {
99
+ if (!force)
100
+ return 0; /* NaN */
101
+ d = 0; /* initialize all fields to 0 */
102
+ }
103
+ else {
104
+ d = dval; /* assuming -8.64e15 <= dval <= -8.64e15 */
105
+ if (is_local) {
106
+ tz = -getTimezoneOffset(d);
107
+ d += tz * 60000;
108
+ }
109
+ }
110
+ /* result is >= 0, we can use % */
111
+ let h = math_mod(d, 86400000);
112
+ const pdays = { days: (d - h) / 86400000 };
113
+ const ms = h % 1000;
114
+ h = (h - ms) / 1000;
115
+ const s = h % 60;
116
+ h = (h - s) / 60;
117
+ const m = h % 60;
118
+ h = (h - m) / 60;
119
+ const wd = math_mod(pdays.days + 4, 7); /* week day */
120
+ const y = year_from_days(pdays);
121
+ let i;
122
+ for (i = 0; i < 11; i++) {
123
+ let md = month_days[i];
124
+ if (i === 1)
125
+ md += days_in_year(y) - 365;
126
+ if (pdays.days < md)
127
+ break;
128
+ pdays.days -= md;
129
+ }
130
+ fields[0] = y;
131
+ fields[1] = i;
132
+ fields[2] = pdays.days + 1;
133
+ fields[3] = h;
134
+ fields[4] = m;
135
+ fields[5] = s;
136
+ fields[6] = ms;
137
+ fields[7] = wd;
138
+ fields[8] = tz;
139
+ return 1;
140
+ }
141
+ function time_clip(t) {
142
+ if (t >= -8.64e15 && t <= 8.64e15)
143
+ return Math.trunc(t) + 0; /* convert -0 to +0 */
144
+ return NaN;
145
+ }
146
+ /* The spec mandates the use of 'double' and it specifies the order
147
+ of the operations */
148
+ function set_date_fields(fields, is_local) {
149
+ /* emulate 21.4.1.15 MakeDay ( year, month, date ) */
150
+ const y = fields[0];
151
+ let m = fields[1];
152
+ const dt = fields[2];
153
+ const ym = y + Math.floor(m / 12);
154
+ let mn = m % 12;
155
+ if (mn < 0)
156
+ mn += 12;
157
+ if (ym < -271821 || ym > 275760)
158
+ return NaN;
159
+ const yi = ym;
160
+ const mi = mn;
161
+ let days = days_from_year(yi);
162
+ for (let i = 0; i < mi; i++) {
163
+ days += month_days[i];
164
+ if (i === 1)
165
+ days += days_in_year(yi) - 365;
166
+ }
167
+ const day = days + dt - 1;
168
+ /* emulate 21.4.1.14 MakeTime ( hour, min, sec, ms ) */
169
+ const h = fields[3];
170
+ m = fields[4];
171
+ const s = fields[5];
172
+ const milli = fields[6];
173
+ let time = h * 3600000;
174
+ time += m * 60000;
175
+ time += s * 1000;
176
+ time += milli;
177
+ /* emulate 21.4.1.16 MakeDate ( day, time ) */
178
+ let tv = (day * 86400000) + time;
179
+ if (!Number.isFinite(tv))
180
+ return NaN;
181
+ /* adjust for local time and clip */
182
+ if (is_local) {
183
+ tv += getTimezoneOffset(tv) * 60000;
184
+ }
185
+ return time_clip(tv);
186
+ }
187
+ function get_date_field(ctx, this_val, argv, magic) {
188
+ // get_date_field(obj, n, is_local)
189
+ const fields = new Array(9).fill(0);
190
+ const is_local = (magic & 0x0f) !== 0;
191
+ const n = (magic >> 4) & 0x0f;
192
+ const res = get_date_fields(ctx, this_val, fields, is_local, false);
193
+ if (res < 0)
194
+ return JS_EXCEPTION;
195
+ if (!res)
196
+ return NaN;
197
+ if (magic & 0x100) { // getYear
198
+ fields[0] -= 1900;
199
+ }
200
+ return fields[n];
201
+ }
202
+ function set_date_field(ctx, this_val, argv, magic) {
203
+ // _field(obj, first_field, end_field, args, is_local)
204
+ return set_date_field_argc(ctx, this_val, argv, js_argc(ctx, argv, set_date_field), magic);
205
+ }
206
+ /* set_date_field with an explicit argument count */
207
+ function set_date_field_argc(ctx, this_val, argv, argc, magic) {
208
+ const fields = new Array(9).fill(0);
209
+ let d = NaN;
210
+ const first_field = (magic >> 8) & 0x0f;
211
+ const end_field = (magic >> 4) & 0x0f;
212
+ const is_local = (magic & 0x0f) !== 0;
213
+ let res = get_date_fields(ctx, this_val, fields, is_local, first_field === 0);
214
+ if (res < 0)
215
+ return JS_EXCEPTION;
216
+ const res1 = res;
217
+ // Argument coercion is observable and must be done unconditionally.
218
+ const n = Math.min(argc, end_field - first_field);
219
+ for (let i = 0; i < n; i++) {
220
+ const a = JS_ToFloat64(ctx, argv[i]);
221
+ if (JS_IsException(a))
222
+ return JS_EXCEPTION;
223
+ if (!Number.isFinite(a))
224
+ res = 0;
225
+ fields[first_field + i] = Math.trunc(a);
226
+ }
227
+ if (!res1)
228
+ return NaN; /* thisTimeValue is NaN */
229
+ if (res && argc > 0)
230
+ d = set_date_fields(fields, is_local);
231
+ return JS_SetThisTimeValue(ctx, this_val, d);
232
+ }
233
+ function pad(n, width) {
234
+ return String(n).padStart(width, '0');
235
+ }
236
+ /* %0*d with width 4 + (y < 0): the sign is included in the width */
237
+ function fmt_year(y) {
238
+ if (y < 0)
239
+ return '-' + pad(-y, 4);
240
+ return pad(y, 4);
241
+ }
242
+ /* fmt:
243
+ 0: toUTCString: "Tue, 02 Jan 2018 23:04:46 GMT"
244
+ 1: toString: "Wed Jan 03 2018 00:05:22 GMT+0100 (CET)"
245
+ 2: toISOString: "2018-01-02T23:02:56.927Z"
246
+ 3: toLocaleString: "1/2/2018, 11:40:40 PM"
247
+ part: 1=date, 2=time 3=all
248
+ XXX: should use a variant of strftime().
249
+ */
250
+ function get_date_string(ctx, this_val, argv, magic) {
251
+ // _string(obj, fmt, part)
252
+ const fields = new Array(9).fill(0);
253
+ const fmt = (magic >> 4) & 0x0f;
254
+ const part = magic & 0x0f;
255
+ const res = get_date_fields(ctx, this_val, fields, (fmt & 1) !== 0, false);
256
+ if (res < 0)
257
+ return JS_EXCEPTION;
258
+ if (!res) {
259
+ if (fmt === 2)
260
+ return JS_ThrowRangeError(ctx, 'Date value is NaN');
261
+ return 'Invalid Date';
262
+ }
263
+ const y = fields[0];
264
+ const mon = fields[1];
265
+ const d = fields[2];
266
+ const h = fields[3];
267
+ const m = fields[4];
268
+ const s = fields[5];
269
+ const ms = fields[6];
270
+ const wd = fields[7];
271
+ let tz = fields[8];
272
+ let buf = '';
273
+ if (part & 1) { /* date part */
274
+ switch (fmt) {
275
+ case 0:
276
+ buf += `${day_names.substring(wd * 3, wd * 3 + 3)}, ${pad(d, 2)} ${month_names.substring(mon * 3, mon * 3 + 3)} ${fmt_year(y)} `;
277
+ break;
278
+ case 1:
279
+ buf += `${day_names.substring(wd * 3, wd * 3 + 3)} ${month_names.substring(mon * 3, mon * 3 + 3)} ${pad(d, 2)} ${fmt_year(y)}`;
280
+ if (part === 3)
281
+ buf += ' ';
282
+ break;
283
+ case 2:
284
+ if (y >= 0 && y <= 9999) {
285
+ buf += pad(y, 4);
286
+ }
287
+ else {
288
+ buf += (y < 0 ? '-' : '+') + pad(Math.abs(y), 6);
289
+ }
290
+ buf += `-${pad(mon + 1, 2)}-${pad(d, 2)}T`;
291
+ break;
292
+ case 3:
293
+ buf += `${pad(mon + 1, 2)}/${pad(d, 2)}/${fmt_year(y)}`;
294
+ if (part === 3)
295
+ buf += ', ';
296
+ break;
297
+ }
298
+ }
299
+ if (part & 2) { /* time part */
300
+ switch (fmt) {
301
+ case 0:
302
+ buf += `${pad(h, 2)}:${pad(m, 2)}:${pad(s, 2)} GMT`;
303
+ break;
304
+ case 1:
305
+ buf += `${pad(h, 2)}:${pad(m, 2)}:${pad(s, 2)} GMT`;
306
+ if (tz < 0) {
307
+ buf += '-';
308
+ tz = -tz;
309
+ }
310
+ else {
311
+ buf += '+';
312
+ }
313
+ /* tz is >= 0, can use % */
314
+ buf += `${pad(Math.trunc(tz / 60), 2)}${pad(tz % 60, 2)}`;
315
+ /* XXX: tack the time zone code? */
316
+ break;
317
+ case 2:
318
+ buf += `${pad(h, 2)}:${pad(m, 2)}:${pad(s, 2)}.${pad(ms, 3)}Z`;
319
+ break;
320
+ case 3:
321
+ buf += `${pad((h + 11) % 12 + 1, 2)}:${pad(m, 2)}:${pad(s, 2)} ${h < 12 ? 'A' : 'P'}M`;
322
+ break;
323
+ }
324
+ }
325
+ return buf;
326
+ }
327
+ /* OS dependent: return the UTC time in ms since 1970. */
328
+ function date_now() {
329
+ return Date.now();
330
+ }
331
+ function js_date_constructor(ctx, new_target, argv) {
332
+ // Date(y, mon, d, h, m, s, ms)
333
+ let argc = js_argc(ctx, argv, js_date_constructor);
334
+ let val;
335
+ if (JS_IsUndefined(new_target)) {
336
+ /* invoked as function */
337
+ argc = 0;
338
+ }
339
+ let n = argc;
340
+ if (n === 0) {
341
+ val = date_now();
342
+ }
343
+ else if (n === 1) {
344
+ let has_val = false;
345
+ val = NaN;
346
+ if (Q.JS_IsObject(argv[0])) {
347
+ const p = argv[0];
348
+ if (Q.JS_GetClassID(p) === 10 /* JSClassID.DATE */ && typeof Q.JS_GetAnyOpaque(p) === 'number') {
349
+ val = time_clip(Q.JS_GetAnyOpaque(p));
350
+ has_val = true;
351
+ }
352
+ }
353
+ if (!has_val) {
354
+ const v = JS_ToPrimitive(ctx, argv[0], HINT_NONE);
355
+ if (JS_IsException(v))
356
+ return JS_EXCEPTION;
357
+ if (typeof v === 'string') {
358
+ const dv = js_Date_parse(ctx, undefined, [v]);
359
+ if (JS_IsException(dv))
360
+ return JS_EXCEPTION;
361
+ const r = JS_ToFloat64(ctx, dv);
362
+ if (JS_IsException(r))
363
+ return JS_EXCEPTION;
364
+ val = r;
365
+ }
366
+ else {
367
+ const r = JS_ToFloat64(ctx, v);
368
+ if (JS_IsException(r))
369
+ return JS_EXCEPTION;
370
+ val = r;
371
+ }
372
+ val = time_clip(val);
373
+ }
374
+ }
375
+ else {
376
+ const fields = [0, 0, 1, 0, 0, 0, 0];
377
+ if (n > 7)
378
+ n = 7;
379
+ let i;
380
+ for (i = 0; i < n; i++) {
381
+ const a = JS_ToFloat64(ctx, argv[i]);
382
+ if (JS_IsException(a))
383
+ return JS_EXCEPTION;
384
+ if (!Number.isFinite(a))
385
+ break;
386
+ fields[i] = Math.trunc(a);
387
+ if (i === 0 && fields[0] >= 0 && fields[0] < 100)
388
+ fields[0] += 1900;
389
+ }
390
+ val = (i === n) ? set_date_fields(fields, true) : NaN;
391
+ }
392
+ let rv = js_create_from_ctor(ctx, new_target, 10 /* JSClassID.DATE */);
393
+ if (JS_IsException(rv))
394
+ return rv;
395
+ Q.JS_SetOpaque(rv, val);
396
+ if (JS_IsUndefined(new_target)) {
397
+ /* invoked as a function, return (new Date()).toString(); */
398
+ rv = get_date_string(ctx, rv, [], 0x13);
399
+ }
400
+ return rv;
401
+ }
402
+ function js_Date_UTC(ctx, this_val, argv) {
403
+ // UTC(y, mon, d, h, m, s, ms)
404
+ const fields = [0, 0, 1, 0, 0, 0, 0];
405
+ let n = js_argc(ctx, argv, js_Date_UTC);
406
+ if (n === 0)
407
+ return NaN;
408
+ if (n > 7)
409
+ n = 7;
410
+ for (let i = 0; i < n; i++) {
411
+ const a = JS_ToFloat64(ctx, argv[i]);
412
+ if (JS_IsException(a))
413
+ return JS_EXCEPTION;
414
+ if (!Number.isFinite(a))
415
+ return NaN;
416
+ fields[i] = Math.trunc(a);
417
+ if (i === 0 && fields[0] >= 0 && fields[0] < 100)
418
+ fields[0] += 1900;
419
+ }
420
+ return set_date_fields(fields, false);
421
+ }
422
+ /* ---------------------------------------------------------------------
423
+ Date string parsing
424
+ --------------------------------------------------------------------- */
425
+ /* the string is converted to a NUL terminated byte array like in the C
426
+ version: 'sp' has a trailing 0 and reads past the end return 0 */
427
+ class DateParser {
428
+ sp;
429
+ p = 0;
430
+ constructor(sp) { this.sp = sp; }
431
+ at(i) { return i < this.sp.length ? this.sp[i] : 0; }
432
+ cur() { return this.at(this.p); }
433
+ }
434
+ function string_skip_char(s, c) {
435
+ if (s.cur() === c) {
436
+ s.p += 1;
437
+ return true;
438
+ }
439
+ return false;
440
+ }
441
+ /* skip spaces, update offset, return next char */
442
+ function string_skip_spaces(s) {
443
+ let c;
444
+ while ((c = s.cur()) === 32)
445
+ s.p += 1;
446
+ return c;
447
+ }
448
+ /* skip dashes dots and commas */
449
+ function string_skip_separators(s) {
450
+ let c;
451
+ while ((c = s.cur()) === 45 /* - */ || c === 47 /* / */ || c === 46 /* . */ || c === 44 /* , */)
452
+ s.p += 1;
453
+ return c;
454
+ }
455
+ /* skip a word, stop on spaces, digits and separators, update offset
456
+ (strchr matches the NUL terminator, so the end of string stops too) */
457
+ function string_skip_until(s, stoplist) {
458
+ let c;
459
+ while ((c = s.cur()) !== 0 && stoplist.indexOf(String.fromCharCode(c)) < 0)
460
+ s.p += 1;
461
+ return c;
462
+ }
463
+ /* parse a numeric field (max_digits = 0 -> no maximum) */
464
+ function string_get_digits(s, pval, min_digits, max_digits) {
465
+ let v = 0;
466
+ let c;
467
+ let p = s.p;
468
+ const p_start = p;
469
+ while ((c = s.at(p)) >= 48 && c <= 57) {
470
+ /* arbitrary limit to 9 digits */
471
+ if (v >= 100000000)
472
+ return false;
473
+ v = v * 10 + c - 48;
474
+ p++;
475
+ if (p - p_start === max_digits)
476
+ break;
477
+ }
478
+ if (p - p_start < min_digits)
479
+ return false;
480
+ pval.v = v;
481
+ s.p = p;
482
+ return true;
483
+ }
484
+ function string_get_milliseconds(s, pval) {
485
+ /* parse optional fractional part as milliseconds and truncate. */
486
+ /* spec does not indicate which rounding should be used */
487
+ let mul = 100, ms = 0, c;
488
+ let p = s.p;
489
+ c = s.at(p);
490
+ if (c === 46 /* . */ || c === 44 /* , */) {
491
+ p++;
492
+ const p_start = p;
493
+ while ((c = s.at(p)) >= 48 && c <= 57) {
494
+ ms += (c - 48) * mul;
495
+ mul = Math.trunc(mul / 10);
496
+ p++;
497
+ if (p - p_start === 9)
498
+ break;
499
+ }
500
+ if (p > p_start) {
501
+ /* only consume the separator if digits are present */
502
+ pval.v = ms;
503
+ s.p = p;
504
+ }
505
+ }
506
+ return true;
507
+ }
508
+ function upper_ascii(c) {
509
+ return c >= 97 && c <= 122 ? c - 97 + 65 : c;
510
+ }
511
+ function string_get_tzoffset(s, tzp, strict) {
512
+ let tz = 0, hh, mm;
513
+ let p = s.p;
514
+ const sgn = s.at(p++);
515
+ if (sgn === 43 /* + */ || sgn === 45 /* - */) {
516
+ const sub = new DateParser(s.sp);
517
+ sub.p = p;
518
+ let n = p;
519
+ const r = { v: 0 };
520
+ if (!string_get_digits(sub, r, 1, 0))
521
+ return false;
522
+ p = sub.p;
523
+ hh = r.v;
524
+ n = p - n;
525
+ if (strict && n !== 2 && n !== 4)
526
+ return false;
527
+ while (n > 4) {
528
+ n -= 2;
529
+ hh = Math.trunc(hh / 100);
530
+ }
531
+ if (n > 2) {
532
+ mm = hh % 100;
533
+ hh = Math.trunc(hh / 100);
534
+ }
535
+ else {
536
+ mm = 0;
537
+ sub.p = p;
538
+ if (string_skip_char(sub, 58 /* : */)) { /* optional separator */
539
+ const r2 = { v: 0 };
540
+ if (!string_get_digits(sub, r2, 2, 2))
541
+ return false;
542
+ mm = r2.v;
543
+ }
544
+ p = sub.p;
545
+ }
546
+ if (hh > 23 || mm > 59)
547
+ return false;
548
+ tz = hh * 60 + mm;
549
+ if (sgn !== 43)
550
+ tz = -tz;
551
+ }
552
+ else if (sgn !== 90 /* Z */) {
553
+ return false;
554
+ }
555
+ s.p = p;
556
+ tzp.v = tz;
557
+ return true;
558
+ }
559
+ function string_match(s, str) {
560
+ let p = s.p;
561
+ for (let i = 0; i < str.length; i++) {
562
+ if (upper_ascii(s.at(p)) !== upper_ascii(str.charCodeAt(i)))
563
+ return false;
564
+ p++;
565
+ }
566
+ s.p = p;
567
+ return true;
568
+ }
569
+ function find_abbrev(s, p, list, count) {
570
+ for (let n = 0; n < count; n++) {
571
+ for (let i = 0;; i++) {
572
+ if (upper_ascii(s.at(p + i)) !== upper_ascii(list.charCodeAt(n * 3 + i)))
573
+ break;
574
+ if (i === 2)
575
+ return n;
576
+ }
577
+ }
578
+ return -1;
579
+ }
580
+ function string_get_month(s, pval) {
581
+ const n = find_abbrev(s, s.p, month_names, 12);
582
+ if (n < 0)
583
+ return false;
584
+ pval.v = n + 1;
585
+ s.p += 3;
586
+ return true;
587
+ }
588
+ /* parse toISOString format */
589
+ function js_date_parse_isostring(sp, fields, pis_local) {
590
+ const s = new DateParser(sp);
591
+ const r = { v: 0 };
592
+ /* initialize fields to the beginning of the Epoch */
593
+ for (let i = 0; i < 9; i++)
594
+ fields[i] = (i === 2) ? 1 : 0;
595
+ pis_local.v = false;
596
+ /* year is either yyyy digits or [+-]yyyyyy */
597
+ const sgn = s.cur();
598
+ if (sgn === 45 /* - */ || sgn === 43 /* + */) {
599
+ s.p++;
600
+ if (!string_get_digits(s, r, 6, 6))
601
+ return false;
602
+ fields[0] = r.v;
603
+ if (sgn === 45) {
604
+ if (fields[0] === 0)
605
+ return false; // reject -000000
606
+ fields[0] = -fields[0];
607
+ }
608
+ }
609
+ else {
610
+ if (!string_get_digits(s, r, 4, 4))
611
+ return false;
612
+ fields[0] = r.v;
613
+ }
614
+ if (string_skip_char(s, 45 /* - */)) {
615
+ if (!string_get_digits(s, r, 2, 2))
616
+ return false; /* month */
617
+ fields[1] = r.v;
618
+ if (fields[1] < 1)
619
+ return false;
620
+ fields[1] -= 1;
621
+ if (string_skip_char(s, 45)) {
622
+ if (!string_get_digits(s, r, 2, 2))
623
+ return false; /* day */
624
+ fields[2] = r.v;
625
+ if (fields[2] < 1)
626
+ return false;
627
+ }
628
+ }
629
+ if (string_skip_char(s, 84 /* T */)) {
630
+ pis_local.v = true;
631
+ if (!string_get_digits(s, r, 2, 2)) { /* hour */
632
+ fields[3] = 100; // reject unconditionally
633
+ return true;
634
+ }
635
+ fields[3] = r.v;
636
+ if (!string_skip_char(s, 58 /* : */) || !string_get_digits(s, r, 2, 2)) { /* minute */
637
+ fields[3] = 100; // reject unconditionally
638
+ return true;
639
+ }
640
+ fields[4] = r.v;
641
+ if (string_skip_char(s, 58)) {
642
+ if (!string_get_digits(s, r, 2, 2))
643
+ return false; /* second */
644
+ fields[5] = r.v;
645
+ const rms = { v: fields[6] };
646
+ string_get_milliseconds(s, rms);
647
+ fields[6] = rms.v;
648
+ }
649
+ }
650
+ /* parse the time zone offset if present: [+-]HH:mm or [+-]HHmm */
651
+ if (s.cur()) {
652
+ pis_local.v = false;
653
+ const rtz = { v: 0 };
654
+ if (!string_get_tzoffset(s, rtz, true))
655
+ return false;
656
+ fields[8] = rtz.v;
657
+ }
658
+ /* error if extraneous characters */
659
+ return s.cur() === 0;
660
+ }
661
+ const js_tzabbr = [
662
+ ['GMT', 0], // Greenwich Mean Time
663
+ ['UTC', 0], // Coordinated Universal Time
664
+ ['UT', 0], // Universal Time
665
+ ['Z', 0], // Zulu Time
666
+ ['EDT', -4 * 60], // Eastern Daylight Time
667
+ ['EST', -5 * 60], // Eastern Standard Time
668
+ ['CDT', -5 * 60], // Central Daylight Time
669
+ ['CST', -6 * 60], // Central Standard Time
670
+ ['MDT', -6 * 60], // Mountain Daylight Time
671
+ ['MST', -7 * 60], // Mountain Standard Time
672
+ ['PDT', -7 * 60], // Pacific Daylight Time
673
+ ['PST', -8 * 60], // Pacific Standard Time
674
+ ['WET', +0 * 60], // Western European Time
675
+ ['WEST', +1 * 60], // Western European Summer Time
676
+ ['CET', +1 * 60], // Central European Time
677
+ ['CEST', +2 * 60], // Central European Summer Time
678
+ ['EET', +2 * 60], // Eastern European Time
679
+ ['EEST', +3 * 60], // Eastern European Summer Time
680
+ ];
681
+ function string_get_tzabbr(s, offset) {
682
+ for (const [name, off] of js_tzabbr) {
683
+ if (string_match(s, name)) {
684
+ offset.v = off;
685
+ return true;
686
+ }
687
+ }
688
+ return false;
689
+ }
690
+ /* parse toString, toUTCString and other formats */
691
+ function js_date_parse_otherstring(sp, fields, pis_local) {
692
+ const s = new DateParser(sp);
693
+ let c;
694
+ const num = [0, 0, 0];
695
+ let has_year = false;
696
+ let has_mon = false;
697
+ let has_time = false;
698
+ let num_index = 0;
699
+ const r = { v: 0 };
700
+ /* initialize fields to the beginning of 2001-01-01 */
701
+ fields[0] = 2001;
702
+ fields[1] = 1;
703
+ fields[2] = 1;
704
+ for (let i = 3; i < 9; i++)
705
+ fields[i] = 0;
706
+ pis_local.v = true;
707
+ while (string_skip_spaces(s)) {
708
+ const p_start = s.p;
709
+ if ((c = s.cur()) === 43 /* + */ || c === 45 /* - */) {
710
+ const rtz = { v: 0 };
711
+ if (has_time && string_get_tzoffset(s, rtz, false)) {
712
+ fields[8] = rtz.v;
713
+ pis_local.v = false;
714
+ }
715
+ else {
716
+ s.p++;
717
+ if (string_get_digits(s, r, 1, 0)) {
718
+ let val = r.v;
719
+ if (c === 45) {
720
+ if (val === 0)
721
+ return false;
722
+ val = -val;
723
+ }
724
+ fields[0] = val;
725
+ has_year = true;
726
+ }
727
+ }
728
+ }
729
+ else if (string_get_digits(s, r, 1, 0)) {
730
+ const val = r.v;
731
+ if (string_skip_char(s, 58 /* : */)) {
732
+ /* time part */
733
+ fields[3] = val;
734
+ if (!string_get_digits(s, r, 1, 2))
735
+ return false;
736
+ fields[4] = r.v;
737
+ if (string_skip_char(s, 58)) {
738
+ if (!string_get_digits(s, r, 1, 2))
739
+ return false;
740
+ fields[5] = r.v;
741
+ const rms = { v: fields[6] };
742
+ string_get_milliseconds(s, rms);
743
+ fields[6] = rms.v;
744
+ }
745
+ has_time = true;
746
+ }
747
+ else {
748
+ if (s.p - p_start > 2) {
749
+ fields[0] = val;
750
+ has_year = true;
751
+ }
752
+ else if (val < 1 || val > 31) {
753
+ fields[0] = val + (val < 100 ? 1900 : 0) + (val < 50 ? 100 : 0);
754
+ has_year = true;
755
+ }
756
+ else {
757
+ if (num_index === 3)
758
+ return false;
759
+ num[num_index++] = val;
760
+ }
761
+ }
762
+ }
763
+ else if (string_get_month(s, r)) {
764
+ fields[1] = r.v;
765
+ has_mon = true;
766
+ string_skip_until(s, '0123456789 -/(');
767
+ }
768
+ else if (has_time && string_match(s, 'PM')) {
769
+ if (fields[3] < 12)
770
+ fields[3] += 12;
771
+ continue;
772
+ }
773
+ else if (has_time && string_match(s, 'AM')) {
774
+ if (fields[3] === 12)
775
+ fields[3] -= 12;
776
+ continue;
777
+ }
778
+ else if (string_get_tzabbr(s, r)) {
779
+ fields[8] = r.v;
780
+ pis_local.v = false;
781
+ continue;
782
+ }
783
+ else if (c === 40 /* ( */) { /* skip parenthesized phrase */
784
+ let level = 0;
785
+ while ((c = s.cur()) !== 0) {
786
+ s.p++;
787
+ level += (c === 40) ? 1 : 0;
788
+ level -= (c === 41) ? 1 : 0;
789
+ if (!level)
790
+ break;
791
+ }
792
+ if (level > 0)
793
+ return false;
794
+ }
795
+ else if (c === 41 /* ) */) {
796
+ return false;
797
+ }
798
+ else {
799
+ if ((has_year ? 1 : 0) + (has_mon ? 1 : 0) + (has_time ? 1 : 0) + num_index)
800
+ return false;
801
+ /* skip a word */
802
+ string_skip_until(s, ' -/(');
803
+ }
804
+ string_skip_separators(s);
805
+ }
806
+ if (num_index + (has_year ? 1 : 0) + (has_mon ? 1 : 0) > 3)
807
+ return false;
808
+ switch (num_index) {
809
+ case 0:
810
+ if (!has_year)
811
+ return false;
812
+ break;
813
+ case 1:
814
+ if (has_mon)
815
+ fields[2] = num[0];
816
+ else
817
+ fields[1] = num[0];
818
+ break;
819
+ case 2:
820
+ if (has_year) {
821
+ fields[1] = num[0];
822
+ fields[2] = num[1];
823
+ }
824
+ else if (has_mon) {
825
+ fields[0] = num[1] + (num[1] < 100 ? 1900 : 0) + (num[1] < 50 ? 100 : 0);
826
+ fields[2] = num[0];
827
+ }
828
+ else {
829
+ fields[1] = num[0];
830
+ fields[2] = num[1];
831
+ }
832
+ break;
833
+ case 3:
834
+ fields[0] = num[2] + (num[2] < 100 ? 1900 : 0) + (num[2] < 50 ? 100 : 0);
835
+ fields[1] = num[0];
836
+ fields[2] = num[1];
837
+ break;
838
+ default:
839
+ return false;
840
+ }
841
+ if (fields[1] < 1 || fields[2] < 1)
842
+ return false;
843
+ fields[1] -= 1;
844
+ return true;
845
+ }
846
+ function js_Date_parse(ctx, this_val, argv) {
847
+ let rv = NaN;
848
+ const s = JS_ToString(ctx, argv[0]);
849
+ if (JS_IsException(s))
850
+ return JS_EXCEPTION;
851
+ const str = s;
852
+ /* convert the string as a byte array */
853
+ const n = Math.min(str.length, 127);
854
+ const buf = new Uint8Array(n + 1);
855
+ for (let i = 0; i < n; i++) {
856
+ let c = str.charCodeAt(i);
857
+ if (c > 255)
858
+ c = (c === 0x2212) ? 45 /* - */ : 120 /* x */;
859
+ buf[i] = c;
860
+ }
861
+ buf[n] = 0;
862
+ const fields = new Array(9).fill(0);
863
+ const is_local = { v: false };
864
+ if (js_date_parse_isostring(buf, fields, is_local) || js_date_parse_otherstring(buf, fields, is_local)) {
865
+ const field_max = [0, 11, 31, 24, 59, 59];
866
+ let valid = true;
867
+ /* check field maximum values */
868
+ for (let i = 1; i < 6; i++) {
869
+ if (fields[i] > field_max[i])
870
+ valid = false;
871
+ }
872
+ /* special case 24:00:00.000 */
873
+ if (fields[3] === 24 && (fields[4] | fields[5] | fields[6]))
874
+ valid = false;
875
+ if (valid) {
876
+ const fields1 = [];
877
+ for (let i = 0; i < 7; i++)
878
+ fields1[i] = fields[i];
879
+ rv = set_date_fields(fields1, is_local.v) - fields[8] * 60000;
880
+ }
881
+ }
882
+ return rv;
883
+ }
884
+ function js_Date_now(ctx, this_val, argv) {
885
+ // now()
886
+ return date_now();
887
+ }
888
+ function js_date_Symbol_toPrimitive(ctx, this_val, argv) {
889
+ // Symbol_toPrimitive(hint)
890
+ const obj = this_val;
891
+ let hint = JS_ATOM_NULL;
892
+ let hint_num;
893
+ if (!JS_IsObject(obj))
894
+ return JS_ThrowTypeErrorNotAnObject(ctx);
895
+ if (typeof argv[0] === 'string') {
896
+ hint = JS_ValueToAtom(ctx, argv[0]);
897
+ if (hint === JS_ATOM_NULL)
898
+ return JS_EXCEPTION;
899
+ }
900
+ switch (hint) {
901
+ case JS_ATOM_number:
902
+ case JS_ATOM_integer:
903
+ hint_num = HINT_NUMBER;
904
+ break;
905
+ case JS_ATOM_string:
906
+ case JS_ATOM_default:
907
+ hint_num = HINT_STRING;
908
+ break;
909
+ default:
910
+ return JS_ThrowTypeError(ctx, 'invalid hint');
911
+ }
912
+ return JS_ToPrimitive(ctx, obj, hint_num | HINT_FORCE_ORDINARY);
913
+ }
914
+ function js_date_getTimezoneOffset(ctx, this_val, argv) {
915
+ // getTimezoneOffset()
916
+ const v = JS_ThisTimeValue(ctx, this_val);
917
+ if (JS_IsException(v))
918
+ return JS_EXCEPTION;
919
+ if (Number.isNaN(v))
920
+ return NaN;
921
+ /* assuming -8.64e15 <= v <= -8.64e15 */
922
+ return getTimezoneOffset(Math.trunc(v));
923
+ }
924
+ function js_date_getTime(ctx, this_val, argv) {
925
+ // getTime()
926
+ const v = JS_ThisTimeValue(ctx, this_val);
927
+ if (JS_IsException(v))
928
+ return JS_EXCEPTION;
929
+ return v;
930
+ }
931
+ function js_date_setTime(ctx, this_val, argv) {
932
+ // setTime(v)
933
+ const tv = JS_ThisTimeValue(ctx, this_val);
934
+ if (JS_IsException(tv))
935
+ return JS_EXCEPTION;
936
+ const v = JS_ToFloat64(ctx, argv[0]);
937
+ if (JS_IsException(v))
938
+ return JS_EXCEPTION;
939
+ return JS_SetThisTimeValue(ctx, this_val, time_clip(v));
940
+ }
941
+ function js_date_setYear(ctx, this_val, argv) {
942
+ // setYear(y)
943
+ const tv = JS_ThisTimeValue(ctx, this_val);
944
+ if (JS_IsException(tv))
945
+ return JS_EXCEPTION;
946
+ const r = JS_ToFloat64(ctx, argv[0]);
947
+ if (JS_IsException(r))
948
+ return JS_EXCEPTION;
949
+ let y = +r;
950
+ if (Number.isFinite(y)) {
951
+ y = Math.trunc(y);
952
+ if (y >= 0 && y < 100)
953
+ y += 1900;
954
+ }
955
+ return set_date_field_argc(ctx, this_val, [y], 1, 0x011);
956
+ }
957
+ function js_date_toJSON(ctx, this_val, argv) {
958
+ // toJSON(key)
959
+ const obj = JS_ToObject(ctx, this_val);
960
+ if (JS_IsException(obj))
961
+ return JS_EXCEPTION;
962
+ const tv = JS_ToPrimitive(ctx, obj, HINT_NUMBER);
963
+ if (JS_IsException(tv))
964
+ return JS_EXCEPTION;
965
+ if (typeof tv === 'number') {
966
+ if (!Number.isFinite(tv))
967
+ return null;
968
+ }
969
+ const method = JS_GetPropertyStr(ctx, obj, 'toISOString');
970
+ if (JS_IsException(method))
971
+ return JS_EXCEPTION;
972
+ if (!JS_IsFunction(ctx, method)) {
973
+ return JS_ThrowTypeError(ctx, 'object needs toISOString method');
974
+ }
975
+ return JS_Call(ctx, method, obj, []);
976
+ }
977
+ const js_date_funcs = [
978
+ JS_CFUNC_DEF('now', 0, js_Date_now),
979
+ JS_CFUNC_DEF('parse', 1, js_Date_parse),
980
+ JS_CFUNC_DEF('UTC', 7, js_Date_UTC),
981
+ ];
982
+ const js_date_proto_funcs = [
983
+ JS_CFUNC_DEF('valueOf', 0, js_date_getTime),
984
+ JS_CFUNC_MAGIC_DEF('toString', 0, get_date_string, 0x13),
985
+ JS_CFUNC_DEF(JS_ATOM_Symbol_toPrimitive, 1, js_date_Symbol_toPrimitive),
986
+ JS_CFUNC_MAGIC_DEF('toUTCString', 0, get_date_string, 0x03),
987
+ JS_ALIAS_DEF('toGMTString', 'toUTCString'),
988
+ JS_CFUNC_MAGIC_DEF('toISOString', 0, get_date_string, 0x23),
989
+ JS_CFUNC_MAGIC_DEF('toDateString', 0, get_date_string, 0x11),
990
+ JS_CFUNC_MAGIC_DEF('toTimeString', 0, get_date_string, 0x12),
991
+ JS_CFUNC_MAGIC_DEF('toLocaleString', 0, get_date_string, 0x33),
992
+ JS_CFUNC_MAGIC_DEF('toLocaleDateString', 0, get_date_string, 0x31),
993
+ JS_CFUNC_MAGIC_DEF('toLocaleTimeString', 0, get_date_string, 0x32),
994
+ JS_CFUNC_DEF('getTimezoneOffset', 0, js_date_getTimezoneOffset),
995
+ JS_CFUNC_DEF('getTime', 0, js_date_getTime),
996
+ JS_CFUNC_MAGIC_DEF('getYear', 0, get_date_field, 0x101),
997
+ JS_CFUNC_MAGIC_DEF('getFullYear', 0, get_date_field, 0x01),
998
+ JS_CFUNC_MAGIC_DEF('getUTCFullYear', 0, get_date_field, 0x00),
999
+ JS_CFUNC_MAGIC_DEF('getMonth', 0, get_date_field, 0x11),
1000
+ JS_CFUNC_MAGIC_DEF('getUTCMonth', 0, get_date_field, 0x10),
1001
+ JS_CFUNC_MAGIC_DEF('getDate', 0, get_date_field, 0x21),
1002
+ JS_CFUNC_MAGIC_DEF('getUTCDate', 0, get_date_field, 0x20),
1003
+ JS_CFUNC_MAGIC_DEF('getHours', 0, get_date_field, 0x31),
1004
+ JS_CFUNC_MAGIC_DEF('getUTCHours', 0, get_date_field, 0x30),
1005
+ JS_CFUNC_MAGIC_DEF('getMinutes', 0, get_date_field, 0x41),
1006
+ JS_CFUNC_MAGIC_DEF('getUTCMinutes', 0, get_date_field, 0x40),
1007
+ JS_CFUNC_MAGIC_DEF('getSeconds', 0, get_date_field, 0x51),
1008
+ JS_CFUNC_MAGIC_DEF('getUTCSeconds', 0, get_date_field, 0x50),
1009
+ JS_CFUNC_MAGIC_DEF('getMilliseconds', 0, get_date_field, 0x61),
1010
+ JS_CFUNC_MAGIC_DEF('getUTCMilliseconds', 0, get_date_field, 0x60),
1011
+ JS_CFUNC_MAGIC_DEF('getDay', 0, get_date_field, 0x71),
1012
+ JS_CFUNC_MAGIC_DEF('getUTCDay', 0, get_date_field, 0x70),
1013
+ JS_CFUNC_DEF('setTime', 1, js_date_setTime),
1014
+ JS_CFUNC_MAGIC_DEF('setMilliseconds', 1, set_date_field, 0x671),
1015
+ JS_CFUNC_MAGIC_DEF('setUTCMilliseconds', 1, set_date_field, 0x670),
1016
+ JS_CFUNC_MAGIC_DEF('setSeconds', 2, set_date_field, 0x571),
1017
+ JS_CFUNC_MAGIC_DEF('setUTCSeconds', 2, set_date_field, 0x570),
1018
+ JS_CFUNC_MAGIC_DEF('setMinutes', 3, set_date_field, 0x471),
1019
+ JS_CFUNC_MAGIC_DEF('setUTCMinutes', 3, set_date_field, 0x470),
1020
+ JS_CFUNC_MAGIC_DEF('setHours', 4, set_date_field, 0x371),
1021
+ JS_CFUNC_MAGIC_DEF('setUTCHours', 4, set_date_field, 0x370),
1022
+ JS_CFUNC_MAGIC_DEF('setDate', 1, set_date_field, 0x231),
1023
+ JS_CFUNC_MAGIC_DEF('setUTCDate', 1, set_date_field, 0x230),
1024
+ JS_CFUNC_MAGIC_DEF('setMonth', 2, set_date_field, 0x131),
1025
+ JS_CFUNC_MAGIC_DEF('setUTCMonth', 2, set_date_field, 0x130),
1026
+ JS_CFUNC_DEF('setYear', 1, js_date_setYear),
1027
+ JS_CFUNC_MAGIC_DEF('setFullYear', 3, set_date_field, 0x031),
1028
+ JS_CFUNC_MAGIC_DEF('setUTCFullYear', 3, set_date_field, 0x030),
1029
+ JS_CFUNC_DEF('toJSON', 1, js_date_toJSON),
1030
+ ];
1031
+ export function JS_NewDate(ctx, epoch_ms) {
1032
+ const obj = js_create_from_ctor(ctx, undefined, 10 /* JSClassID.DATE */);
1033
+ if (JS_IsException(obj))
1034
+ return JS_EXCEPTION;
1035
+ Q.JS_SetOpaque(obj, time_clip(epoch_ms));
1036
+ return obj;
1037
+ }
1038
+ export function JS_AddIntrinsicDate(ctx) {
1039
+ /* Date */
1040
+ const proto = JS_NewObject(ctx);
1041
+ ctx.class_proto[10 /* JSClassID.DATE */] = proto;
1042
+ JS_SetPropertyFunctionList(ctx, proto, js_date_proto_funcs);
1043
+ const obj = JS_NewGlobalCConstructor(ctx, 'Date', js_date_constructor, 7, proto);
1044
+ JS_SetPropertyFunctionList(ctx, obj, js_date_funcs);
1045
+ }
1046
+ //# sourceMappingURL=date.js.map