porffor 0.2.0-a6c01f5 → 0.2.0-a88bbe6

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.
@@ -1,5 +1,3 @@
1
- // @porf -funsafe-no-unlikely-proto-checks
2
-
3
1
  // 21.4.1.3 Day (t)
4
2
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-day
5
3
  // 1. Return 𝔽(floor(ℝ(t / msPerDay))).
@@ -259,17 +257,21 @@ export const __ecma262_UTC = (t: number): number => {
259
257
  // https://tc39.es/ecma262/multipage/abstract-operations.html#sec-tointegerorinfinity
260
258
  export const __ecma262_ToIntegerOrInfinity = (argument: unknown): number => {
261
259
  // 1. Let number be ? ToNumber(argument).
262
- const number: number = Number(argument);
260
+ let number: number = Number(argument);
263
261
 
264
262
  // 2. If number is one of NaN, +0𝔽, or -0𝔽, return 0.
265
263
  if (Number.isNaN(number)) return 0;
266
264
 
267
265
  // 3. If number is +∞𝔽, return +∞.
268
266
  // 4. If number is -∞𝔽, return -∞.
269
- // if (!Number.isFinite(number)) return number;
267
+ if (!Number.isFinite(number)) return number;
270
268
 
271
269
  // 5. Return truncate(ℝ(number)).
272
- return Math.trunc(number);
270
+ number = Math.trunc(number);
271
+
272
+ // return 0 for -0
273
+ if (number == 0) return 0;
274
+ return number;
273
275
  };
274
276
 
275
277
  // 21.4.1.27 MakeTime (hour, min, sec, ms)
@@ -355,7 +357,7 @@ export const __ecma262_MakeFullYear = (year: number): number => {
355
357
  const truncated: number = __ecma262_ToIntegerOrInfinity(year);
356
358
 
357
359
  // 3. If truncated is in the inclusive interval from 0 to 99, return 1900𝔽 + 𝔽(truncated).
358
- if (truncated >= 0 && truncated <= 99) return 1900 + truncated;
360
+ if (Porffor.fastAnd(truncated >= 0, truncated <= 99)) return 1900 + truncated;
359
361
 
360
362
  // 4. Return 𝔽(truncated).
361
363
  return truncated;
@@ -376,16 +378,343 @@ export const __ecma262_TimeClip = (time: number): number => {
376
378
  };
377
379
 
378
380
 
379
- // 21.4.2.1 Date (...values)
380
- // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date
381
- export const Date = (): bytestring => {
382
- // 1. If NewTarget is undefined, then
383
- // a. Let now be the time value (UTC) identifying the current time.
384
- // b. Return ToDateString(now).
385
- // return Date$constructor().toString();
386
- return '';
381
+ // 21.4.3.1 Date.now ()
382
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.now
383
+ // This function returns the time value designating the UTC date and time of the occurrence of the call to it.
384
+ export const __Date_now = (): number => Math.trunc(performance.timeOrigin + performance.now());
385
+
386
+ // 21.4.3.4 Date.UTC (year [, month [, date [, hours [, minutes [, seconds [, ms ]]]]]])
387
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.utc
388
+ export const __Date_UTC = (year: unknown, month: unknown, date: unknown, hours: unknown, minutes: unknown, seconds: unknown, ms: unknown): number => {
389
+ // todo: passing undefined to params should not act like no arg was passed
390
+
391
+ // 1. Let y be ? ToNumber(year).
392
+ const y: number = Number(year);
393
+
394
+ // 2. If month is present, let m be ? ToNumber(month); else let m be +0𝔽.
395
+ let m: number = 0;
396
+ if (Porffor.rawType(month) != Porffor.TYPES.undefined) m = Number(month);
397
+
398
+ // 3. If date is present, let dt be ? ToNumber(date); else let dt be 1𝔽.
399
+ let dt: number = 1;
400
+ if (Porffor.rawType(date) != Porffor.TYPES.undefined) dt = Number(date);
401
+
402
+ // 4. If hours is present, let h be ? ToNumber(hours); else let h be +0𝔽.
403
+ let h: number = 0;
404
+ if (Porffor.rawType(hours) != Porffor.TYPES.undefined) h = Number(hours);
405
+
406
+ // 5. If minutes is present, let min be ? ToNumber(minutes); else let min be +0𝔽.
407
+ let min: number = 0;
408
+ if (Porffor.rawType(minutes) != Porffor.TYPES.undefined) min = Number(minutes);
409
+
410
+ // 6. If seconds is present, let s be ? ToNumber(seconds); else let s be +0𝔽.
411
+ let s: number = 0;
412
+ if (Porffor.rawType(seconds) != Porffor.TYPES.undefined) s = Number(seconds);
413
+
414
+ // 7. If ms is present, let milli be ? ToNumber(ms); else let milli be +0𝔽.
415
+ let milli: number = 0;
416
+ if (Porffor.rawType(ms) != Porffor.TYPES.undefined) h = Number(ms);
417
+
418
+ // 8. Let yr be MakeFullYear(y).
419
+ const yr: number = __ecma262_MakeFullYear(y);
420
+
421
+ // 9. Return TimeClip(MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli))).
422
+ return __ecma262_TimeClip(__ecma262_MakeDate(__ecma262_MakeDay(yr, m, dt), __ecma262_MakeTime(h, min, s, milli)));
423
+ };
424
+
425
+
426
+ export const __ecma262_WeekDayName = (tv: number): bytestring => {
427
+ // Name of the entry in Table 62 with the Number WeekDay(tv).
428
+ // Table 62: Names of days of the week
429
+ // Number Name
430
+ // +0𝔽 "Sun"
431
+ // 1𝔽 "Mon"
432
+ // 2𝔽 "Tue"
433
+ // 3𝔽 "Wed"
434
+ // 4𝔽 "Thu"
435
+ // 5𝔽 "Fri"
436
+ // 6𝔽 "Sat"
437
+
438
+ const weekday: number = __ecma262_WeekDay(tv);
439
+
440
+ const lut: bytestring = 'SunMonTueWedThuFriSat';
441
+
442
+ let out: bytestring = '';
443
+ out.length = 3;
444
+
445
+ let outPtr: number = Porffor.wasm`local.get ${out}`;
446
+ let lutPtr: number = Porffor.wasm`local.get ${lut}` + (weekday * 3);
447
+
448
+ Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(lutPtr++, 0, 4), 0, 4);
449
+ Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(lutPtr++, 0, 4), 0, 4);
450
+ Porffor.wasm.i32.store8(outPtr, Porffor.wasm.i32.load8_u(lutPtr, 0, 4), 0, 4);
451
+
452
+ return out;
453
+ };
454
+
455
+ export const __ecma262_MonthName = (tv: number): bytestring => {
456
+ // Name of the entry in Table 63 with the Number MonthFromTime(tv).
457
+ // Table 63: Names of months of the year
458
+ // Number Name
459
+ // +0𝔽 "Jan"
460
+ // 1𝔽 "Feb"
461
+ // 2𝔽 "Mar"
462
+ // 3𝔽 "Apr"
463
+ // 4𝔽 "May"
464
+ // 5𝔽 "Jun"
465
+ // 6𝔽 "Jul"
466
+ // 7𝔽 "Aug"
467
+ // 8𝔽 "Sep"
468
+ // 9𝔽 "Oct"
469
+ // 10𝔽 "Nov"
470
+ // 11𝔽 "Dec"
471
+
472
+ const month: number = __ecma262_MonthFromTime(tv);
473
+
474
+ const lut: bytestring = 'JanFebMarAprMayJunJulAugSepOctNovDec';
475
+
476
+ let out: bytestring = '';
477
+ out.length = 3;
478
+
479
+ let outPtr: number = Porffor.wasm`local.get ${out}`;
480
+ let lutPtr: number = Porffor.wasm`local.get ${lut}` + (month * 3);
481
+
482
+ Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(lutPtr++, 0, 4), 0, 4);
483
+ Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(lutPtr++, 0, 4), 0, 4);
484
+ Porffor.wasm.i32.store8(outPtr, Porffor.wasm.i32.load8_u(lutPtr, 0, 4), 0, 4);
485
+
486
+ return out;
387
487
  };
388
488
 
489
+ export const __ecma262_ParseMonthName = (ptr: number): number => {
490
+ const a: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 4);
491
+
492
+ if (a == 74) { // J
493
+ const b: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 5);
494
+
495
+ if (b == 97) return 0; // a - Jan
496
+ if (b == 117) { // u
497
+ const c: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 6);
498
+ if (c == 110) return 5; // n - Jun
499
+ if (c == 108) return 6; // l - Jul
500
+ }
501
+ }
502
+
503
+ if (a == 77) { // M
504
+ const b: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 5);
505
+ if (b == 97) { // a
506
+ const c: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 6);
507
+ if (c == 114) return 2; // r - Mar
508
+ if (c == 121) return 4; // y - May
509
+ }
510
+ }
511
+
512
+ if (a == 65) { // A
513
+ const b: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 5);
514
+ if (b == 112) return 3; // p - Apr
515
+ if (b == 117) return 7; // u - Aug
516
+ }
517
+
518
+ if (a == 70) return 1; // F - Feb
519
+ if (a == 83) return 8; // S - Sep
520
+ if (a == 79) return 9; // O - Oct
521
+ if (a == 78) return 10; // N - Nov
522
+ if (a == 68) return 11; // D - Dec
523
+
524
+ return -1;
525
+ };
526
+
527
+
528
+ // DTSF parser
529
+ export const __ecma262_ParseDTSF = (string: bytestring): number => {
530
+ // formats we need to support:
531
+ // > new Date().toISOString()
532
+ // '2024-05-12T02:44:01.529Z'
533
+
534
+ let y: number = 0;
535
+ let m: number = 0;
536
+ let dt: number = 1;
537
+ let h: number = 0;
538
+ let min: number = 0;
539
+ let s: number = 0;
540
+ let milli: number = 0;
541
+ let tzHour: number = 0;
542
+ let tzMin: number = 0;
543
+
544
+ let n: number = 0;
545
+ let nInd: number = 0;
546
+ let z: boolean = false;
547
+
548
+ const len: i32 = string.length;
549
+ const endPtr: i32 = Porffor.wasm`local.get ${string}` + len;
550
+ let ptr: i32 = Porffor.wasm`local.get ${string}`;
551
+
552
+ while (ptr <= endPtr) { // <= to include extra null byte to set last n
553
+ const chr: i32 = Porffor.wasm.i32.load8_u(ptr++, 0, 4);
554
+ if (Porffor.fastAnd(chr >= 48, chr <= 57)) { // 0-9
555
+ n *= 10;
556
+ n += chr - 48;
557
+ continue;
558
+ }
559
+
560
+ if (chr == 45) { // -
561
+ if (Porffor.fastOr(ptr == Porffor.wasm`local.get ${string}`, nInd == 7)) n = -n;
562
+ }
563
+
564
+ if (n > 0) {
565
+ if (nInd == 0) y = n;
566
+ else if (nInd == 1) m = n - 1;
567
+ else if (nInd == 2) dt = n;
568
+ else if (nInd == 3) h = n;
569
+ else if (nInd == 4) min = n;
570
+ else if (nInd == 5) s = n;
571
+ else if (nInd == 6) milli = n;
572
+ else if (nInd == 7) tzHour = n;
573
+ else if (nInd == 8) tzMin = n;
574
+
575
+ n = 0;
576
+ nInd++;
577
+ }
578
+
579
+ if (chr == 90) { // Z
580
+ if (ptr == len) z = true;
581
+ }
582
+ }
583
+
584
+ h += tzHour;
585
+ min += tzMin;
586
+
587
+ return __ecma262_TimeClip(__ecma262_MakeDate(__ecma262_MakeDay(y, m, dt), __ecma262_MakeTime(h, min, s, milli)));
588
+
589
+ // we do not support local time yet so useless check
590
+ // let t: number = __ecma262_TimeClip(__ecma262_MakeDate(__ecma262_MakeDay(y, m, dt), __ecma262_MakeTime(h, min, s, milli)));
591
+
592
+ // "When the time zone offset is absent, date-only forms are interpreted as a UTC time
593
+ // and date-time forms are interpreted as local time.
594
+ // This is due to a historical spec error that was not consistent with ISO 8601
595
+ // but could not be changed due to web compatibility." :))
596
+ // if (Porffor.fastAnd(
597
+ // nInd > 3, // not date-only
598
+ // z == false, // not utc (ending with Z)
599
+ // nInd < 8, // no time zone offset
600
+ // )) {
601
+ // t = __ecma262_UTC(t);
602
+ // }
603
+
604
+ // return t;
605
+ };
606
+
607
+ // RFC 7231 or Date.prototype.toString() parser
608
+ export const __ecma262_ParseRFC7231OrToString = (string: bytestring): number => {
609
+ // formats we need to support:
610
+ // > new Date().toUTCString()
611
+ // 'Sun, 12 May 2024 02:44:10 GMT'
612
+ // > new Date().toString()
613
+ // 'Sun May 12 2024 02:44:13 GMT+0000 (UTC)'
614
+
615
+ // skip week day
616
+ let ptr: i32 = Porffor.wasm`local.get ${string}` + 4;
617
+
618
+ // skip potential ' '
619
+ if (Porffor.wasm.i32.load8_u(ptr, 0, 4) == 32) ptr++;
620
+
621
+ let dt: number = 0;
622
+ let m: number = -1;
623
+
624
+ // check if date now via numerical
625
+ let chr: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 4);
626
+ if (Porffor.fastAnd(chr >= 48, chr <= 57)) { // 0-9
627
+ // date, month name
628
+ while (true) { // use >0 check instead of !=' ' to handle malformed
629
+ chr = Porffor.wasm.i32.load8_u(ptr++, 0, 4);
630
+ if (chr < 48) break;
631
+
632
+ dt *= 10;
633
+ dt += chr - 48;
634
+ }
635
+
636
+ m = __ecma262_ParseMonthName(ptr);
637
+ ptr += 3;
638
+ } else {
639
+ // month name, date
640
+ m = __ecma262_ParseMonthName(ptr);
641
+ ptr += 4;
642
+
643
+ while (true) { // use >0 check instead of !=' ' to handle malformed
644
+ chr = Porffor.wasm.i32.load8_u(ptr++, 0, 4);
645
+ if (chr < 48) break;
646
+
647
+ dt *= 10;
648
+ dt += chr - 48;
649
+ }
650
+ }
651
+
652
+ // check we parsed month and date correctly
653
+ if (Porffor.fastOr(m == -1, dt == 0, dt > 31)) {
654
+ return NaN;
655
+ }
656
+
657
+ let y: number = 0;
658
+ let h: number = 0;
659
+ let min: number = 0;
660
+ let s: number = 0;
661
+ let tz: number = 0;
662
+
663
+ let n: number = 0;
664
+ let nInd: number = 0;
665
+
666
+ const len: i32 = string.length;
667
+ const endPtr: i32 = Porffor.wasm`local.get ${string}` + len;
668
+
669
+ while (ptr <= endPtr) { // <= to include extra null byte to set last n
670
+ const chr: i32 = Porffor.wasm.i32.load8_u(ptr++, 0, 4);
671
+ if (Porffor.fastAnd(chr >= 48, chr <= 57)) { // 0-9
672
+ n *= 10;
673
+ n += chr - 48;
674
+ continue;
675
+ }
676
+
677
+ if (chr == 45) { // -
678
+ if (nInd == 4) n = -n;
679
+ }
680
+
681
+ if (n > 0) {
682
+ if (nInd == 0) y = n;
683
+ else if (nInd == 1) h = n;
684
+ else if (nInd == 2) min = n;
685
+ else if (nInd == 3) s = n;
686
+ else if (nInd == 4) tz = n;
687
+
688
+ n = 0;
689
+ nInd++;
690
+ }
691
+ }
692
+
693
+ return __ecma262_TimeClip(__ecma262_MakeDate(__ecma262_MakeDay(y, m, dt), __ecma262_MakeTime(h, min, s, 0)));
694
+ };
695
+
696
+ // 21.4.3.2 Date.parse (string)
697
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.parse
698
+ export const __Date_parse = (string: bytestring): number => {
699
+ // formats we need to support:
700
+ // > new Date().toISOString()
701
+ // '2024-05-12T02:44:01.529Z'
702
+ // > new Date().toUTCString()
703
+ // 'Sun, 12 May 2024 02:44:10 GMT'
704
+ // > new Date().toString()
705
+ // 'Sun May 12 2024 02:44:13 GMT+0000 (UTC)'
706
+
707
+ // if first char is numerical, use DTSF parser
708
+ const chr: i32 = Porffor.wasm.i32.load8_u(string, 0, 4);;
709
+ if (Porffor.fastAnd(chr >= 48, chr <= 57)) { // 0-9
710
+ return __ecma262_ParseDTSF(string);
711
+ }
712
+
713
+ // else, use RFC 7231 or Date.prototype.toString() parser
714
+ return __ecma262_ParseRFC7231OrToString(string);
715
+ };
716
+
717
+
389
718
  // dark wasm magic for a basic allocator, sorry.
390
719
  export const __Porffor_date_allocate = (): Date => {
391
720
  const hack: bytestring = '';
@@ -413,7 +742,8 @@ export const __Porffor_date_write = (ptr: Date, val: number) => {
413
742
  Porffor.wasm.f64.store(ptr, val, 0, 0);
414
743
  };
415
744
 
416
-
745
+ // 21.4.2.1 Date (...values)
746
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date
417
747
  export const Date$constructor = (v0: unknown, v1: unknown, v2: unknown, v3: unknown, v4: unknown, v5: unknown, v6: unknown): Date => {
418
748
  // todo: passing undefined to params should not act like no arg was passed
419
749
 
@@ -444,17 +774,17 @@ export const Date$constructor = (v0: unknown, v1: unknown, v2: unknown, v3: unkn
444
774
  let tv: number = 0;
445
775
 
446
776
  // b. If value is an Object and value has a [[DateValue]] internal slot, then
447
- if (valueType == Porffor.TYPES._date) {
777
+ if (valueType == Porffor.TYPES.date) {
448
778
  // i. Let tv be value.[[DateValue]].
449
779
  tv = __Porffor_date_read(value);
450
780
  } else {
451
781
  // c. Else,
452
782
  // ii. If v is a String, then
453
- if (valueType == Porffor.TYPES.string || valueType == Porffor.TYPES._bytestring) {
783
+ if (Porffor.fastOr(valueType == Porffor.TYPES.string, valueType == Porffor.TYPES.bytestring)) {
454
784
  // 1. Assert: The next step never returns an abrupt completion because v is a String.
455
785
 
456
786
  // 2. Let tv be the result of parsing v as a date, in exactly the same manner as for the parse method (21.4.3.2).
457
- // todo
787
+ tv = __Date_parse(value);
458
788
  } else {
459
789
  // iii. Else,
460
790
  // 1. Let tv be ? ToNumber(v).
@@ -515,60 +845,12 @@ export const Date$constructor = (v0: unknown, v1: unknown, v2: unknown, v3: unkn
515
845
  };
516
846
 
517
847
 
518
- // 21.4.3.1 Date.now ()
519
- // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.now
520
- // This function returns the time value designating the UTC date and time of the occurrence of the call to it.
521
- export const __Date_now = (): number => Math.trunc(performance.timeOrigin + performance.now());
522
-
523
- // 21.4.3.2 Date.parse (string)
524
- // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.parse
525
- // todo
526
-
527
- // 21.4.3.4 Date.UTC (year [, month [, date [, hours [, minutes [, seconds [, ms ]]]]]])
528
- // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.utc
529
- export const __Date_UTC = (year: unknown, month: unknown, date: unknown, hours: unknown, minutes: unknown, seconds: unknown, ms: unknown): number => {
530
- // todo: passing undefined to params should not act like no arg was passed
531
-
532
- // 1. Let y be ? ToNumber(year).
533
- const y: number = Number(year);
534
-
535
- // 2. If month is present, let m be ? ToNumber(month); else let m be +0𝔽.
536
- let m: number = 0;
537
- if (Porffor.rawType(month) != Porffor.TYPES.undefined) m = Number(month);
538
-
539
- // 3. If date is present, let dt be ? ToNumber(date); else let dt be 1𝔽.
540
- let dt: number = 1;
541
- if (Porffor.rawType(date) != Porffor.TYPES.undefined) dt = Number(date);
542
-
543
- // 4. If hours is present, let h be ? ToNumber(hours); else let h be +0𝔽.
544
- let h: number = 0;
545
- if (Porffor.rawType(hours) != Porffor.TYPES.undefined) h = Number(hours);
546
-
547
- // 5. If minutes is present, let min be ? ToNumber(minutes); else let min be +0𝔽.
548
- let min: number = 0;
549
- if (Porffor.rawType(minutes) != Porffor.TYPES.undefined) min = Number(minutes);
550
-
551
- // 6. If seconds is present, let s be ? ToNumber(seconds); else let s be +0𝔽.
552
- let s: number = 0;
553
- if (Porffor.rawType(seconds) != Porffor.TYPES.undefined) s = Number(seconds);
554
-
555
- // 7. If ms is present, let milli be ? ToNumber(ms); else let milli be +0𝔽.
556
- let milli: number = 0;
557
- if (Porffor.rawType(ms) != Porffor.TYPES.undefined) h = Number(ms);
558
-
559
- // 8. Let yr be MakeFullYear(y).
560
- const yr: number = __ecma262_MakeFullYear(y);
561
-
562
- // 9. Return TimeClip(MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli))).
563
- return __ecma262_TimeClip(__ecma262_MakeDate(__ecma262_MakeDay(yr, m, dt), __ecma262_MakeTime(h, min, s, milli)));
564
- };
565
-
566
848
  // 21.4.4 Properties of the Date Prototype Object
567
849
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-properties-of-the-date-prototype-object
568
850
 
569
851
  // 21.4.4.2 Date.prototype.getDate ()
570
852
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getdate
571
- export const ___date_prototype_getDate = (_this: Date) => {
853
+ export const __Date_prototype_getDate = (_this: Date) => {
572
854
  // 1. Let dateObject be the this value.
573
855
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
574
856
  // 3. Let t be dateObject.[[DateValue]].
@@ -583,7 +865,7 @@ export const ___date_prototype_getDate = (_this: Date) => {
583
865
 
584
866
  // 21.4.4.3 Date.prototype.getDay ()
585
867
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getday
586
- export const ___date_prototype_getDay = (_this: Date) => {
868
+ export const __Date_prototype_getDay = (_this: Date) => {
587
869
  // 1. Let dateObject be the this value.
588
870
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
589
871
  // 3. Let t be dateObject.[[DateValue]].
@@ -598,7 +880,7 @@ export const ___date_prototype_getDay = (_this: Date) => {
598
880
 
599
881
  // 21.4.4.4 Date.prototype.getFullYear ()
600
882
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getfullyear
601
- export const ___date_prototype_getFullYear = (_this: Date) => {
883
+ export const __Date_prototype_getFullYear = (_this: Date) => {
602
884
  // 1. Let dateObject be the this value.
603
885
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
604
886
  // 3. Let t be dateObject.[[DateValue]].
@@ -613,7 +895,7 @@ export const ___date_prototype_getFullYear = (_this: Date) => {
613
895
 
614
896
  // 21.4.4.5 Date.prototype.getHours ()
615
897
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.gethours
616
- export const ___date_prototype_getHours = (_this: Date) => {
898
+ export const __Date_prototype_getHours = (_this: Date) => {
617
899
  // 1. Let dateObject be the this value.
618
900
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
619
901
  // 3. Let t be dateObject.[[DateValue]].
@@ -628,7 +910,7 @@ export const ___date_prototype_getHours = (_this: Date) => {
628
910
 
629
911
  // 21.4.4.6 Date.prototype.getMilliseconds ()
630
912
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getmilliseconds
631
- export const ___date_prototype_getMilliseconds = (_this: Date) => {
913
+ export const __Date_prototype_getMilliseconds = (_this: Date) => {
632
914
  // 1. Let dateObject be the this value.
633
915
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
634
916
  // 3. Let t be dateObject.[[DateValue]].
@@ -643,7 +925,7 @@ export const ___date_prototype_getMilliseconds = (_this: Date) => {
643
925
 
644
926
  // 21.4.4.7 Date.prototype.getMinutes ()
645
927
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getminutes
646
- export const ___date_prototype_getMinutes = (_this: Date) => {
928
+ export const __Date_prototype_getMinutes = (_this: Date) => {
647
929
  // 1. Let dateObject be the this value.
648
930
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
649
931
  // 3. Let t be dateObject.[[DateValue]].
@@ -658,7 +940,7 @@ export const ___date_prototype_getMinutes = (_this: Date) => {
658
940
 
659
941
  // 21.4.4.8 Date.prototype.getMonth ()
660
942
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getmonth
661
- export const ___date_prototype_getMonth = (_this: Date) => {
943
+ export const __Date_prototype_getMonth = (_this: Date) => {
662
944
  // 1. Let dateObject be the this value.
663
945
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
664
946
  // 3. Let t be dateObject.[[DateValue]].
@@ -673,7 +955,7 @@ export const ___date_prototype_getMonth = (_this: Date) => {
673
955
 
674
956
  // 21.4.4.9 Date.prototype.getSeconds ()
675
957
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getseconds
676
- export const ___date_prototype_getSeconds = (_this: Date) => {
958
+ export const __Date_prototype_getSeconds = (_this: Date) => {
677
959
  // 1. Let dateObject be the this value.
678
960
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
679
961
  // 3. Let t be dateObject.[[DateValue]].
@@ -688,7 +970,7 @@ export const ___date_prototype_getSeconds = (_this: Date) => {
688
970
 
689
971
  // 21.4.4.10 Date.prototype.getTime ()
690
972
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.gettime
691
- export const ___date_prototype_getTime = (_this: Date) => {
973
+ export const __Date_prototype_getTime = (_this: Date) => {
692
974
  // 1. Let dateObject be the this value.
693
975
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
694
976
  // 3. Return dateObject.[[DateValue]].
@@ -697,7 +979,7 @@ export const ___date_prototype_getTime = (_this: Date) => {
697
979
 
698
980
  // 21.4.4.11 Date.prototype.getTimezoneOffset ()
699
981
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.gettimezoneoffset
700
- export const ___date_prototype_getTimezoneOffset = (_this: Date) => {
982
+ export const __Date_prototype_getTimezoneOffset = (_this: Date) => {
701
983
  // 1. Let dateObject be the this value.
702
984
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
703
985
  // 3. Let t be dateObject.[[DateValue]].
@@ -712,7 +994,7 @@ export const ___date_prototype_getTimezoneOffset = (_this: Date) => {
712
994
 
713
995
  // 21.4.4.12 Date.prototype.getUTCDate ()
714
996
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcdate
715
- export const ___date_prototype_getUTCDate = (_this: Date) => {
997
+ export const __Date_prototype_getUTCDate = (_this: Date) => {
716
998
  // 1. Let dateObject be the this value.
717
999
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
718
1000
  // 3. Let t be dateObject.[[DateValue]].
@@ -727,7 +1009,7 @@ export const ___date_prototype_getUTCDate = (_this: Date) => {
727
1009
 
728
1010
  // 21.4.4.13 Date.prototype.getUTCDay ()
729
1011
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcday
730
- export const ___date_prototype_getUTCDay = (_this: Date) => {
1012
+ export const __Date_prototype_getUTCDay = (_this: Date) => {
731
1013
  // 1. Let dateObject be the this value.
732
1014
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
733
1015
  // 3. Let t be dateObject.[[DateValue]].
@@ -742,7 +1024,7 @@ export const ___date_prototype_getUTCDay = (_this: Date) => {
742
1024
 
743
1025
  // 21.4.4.14 Date.prototype.getUTCFullYear ()
744
1026
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcfullyear
745
- export const ___date_prototype_getUTCFullYear = (_this: Date) => {
1027
+ export const __Date_prototype_getUTCFullYear = (_this: Date) => {
746
1028
  // 1. Let dateObject be the this value.
747
1029
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
748
1030
  // 3. Let t be dateObject.[[DateValue]].
@@ -757,7 +1039,7 @@ export const ___date_prototype_getUTCFullYear = (_this: Date) => {
757
1039
 
758
1040
  // 21.4.4.15 Date.prototype.getUTCHours ()
759
1041
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutchours
760
- export const ___date_prototype_getUTCHours = (_this: Date) => {
1042
+ export const __Date_prototype_getUTCHours = (_this: Date) => {
761
1043
  // 1. Let dateObject be the this value.
762
1044
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
763
1045
  // 3. Let t be dateObject.[[DateValue]].
@@ -772,7 +1054,7 @@ export const ___date_prototype_getUTCHours = (_this: Date) => {
772
1054
 
773
1055
  // 21.4.4.16 Date.prototype.getUTCMilliseconds ()
774
1056
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcmilliseconds
775
- export const ___date_prototype_getUTCMilliseconds = (_this: Date) => {
1057
+ export const __Date_prototype_getUTCMilliseconds = (_this: Date) => {
776
1058
  // 1. Let dateObject be the this value.
777
1059
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
778
1060
  // 3. Let t be dateObject.[[DateValue]].
@@ -787,7 +1069,7 @@ export const ___date_prototype_getUTCMilliseconds = (_this: Date) => {
787
1069
 
788
1070
  // 21.4.4.17 Date.prototype.getUTCMinutes ()
789
1071
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcminutes
790
- export const ___date_prototype_getUTCMinutes = (_this: Date) => {
1072
+ export const __Date_prototype_getUTCMinutes = (_this: Date) => {
791
1073
  // 1. Let dateObject be the this value.
792
1074
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
793
1075
  // 3. Let t be dateObject.[[DateValue]].
@@ -802,7 +1084,7 @@ export const ___date_prototype_getUTCMinutes = (_this: Date) => {
802
1084
 
803
1085
  // 21.4.4.18 Date.prototype.getUTCMonth ()
804
1086
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcmonth
805
- export const ___date_prototype_getUTCMonth = (_this: Date) => {
1087
+ export const __Date_prototype_getUTCMonth = (_this: Date) => {
806
1088
  // 1. Let dateObject be the this value.
807
1089
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
808
1090
  // 3. Let t be dateObject.[[DateValue]].
@@ -817,7 +1099,7 @@ export const ___date_prototype_getUTCMonth = (_this: Date) => {
817
1099
 
818
1100
  // 21.4.4.19 Date.prototype.getUTCSeconds ()
819
1101
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getutcseconds
820
- export const ___date_prototype_getUTCSeconds = (_this: Date) => {
1102
+ export const __Date_prototype_getUTCSeconds = (_this: Date) => {
821
1103
  // 1. Let dateObject be the this value.
822
1104
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
823
1105
  // 3. Let t be dateObject.[[DateValue]].
@@ -833,7 +1115,7 @@ export const ___date_prototype_getUTCSeconds = (_this: Date) => {
833
1115
 
834
1116
  // 21.4.4.20 Date.prototype.setDate (date)
835
1117
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setdate
836
- export const ___date_prototype_setDate = (_this: Date, date: any) => {
1118
+ export const __Date_prototype_setDate = (_this: Date, date: any) => {
837
1119
  // 1. Let dateObject be the this value.
838
1120
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
839
1121
  // 3. Let t be dateObject.[[DateValue]].
@@ -863,7 +1145,7 @@ export const ___date_prototype_setDate = (_this: Date, date: any) => {
863
1145
 
864
1146
  // 21.4.4.21 Date.prototype.setFullYear (year [, month [, date ]])
865
1147
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setfullyear
866
- export const ___date_prototype_setFullYear = (_this: Date, year: any, month: any, date: any) => {
1148
+ export const __Date_prototype_setFullYear = (_this: Date, year: any, month: any, date: any) => {
867
1149
  // 1. Let dateObject be the this value.
868
1150
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
869
1151
  // 3. Let t be dateObject.[[DateValue]].
@@ -901,7 +1183,7 @@ export const ___date_prototype_setFullYear = (_this: Date, year: any, month: any
901
1183
 
902
1184
  // 21.4.4.22 Date.prototype.setHours (hour [, min [, sec [, ms ]]])
903
1185
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.sethours
904
- export const ___date_prototype_setHours = (_this: Date, hour: any, min: any, sec: any, ms: any) => {
1186
+ export const __Date_prototype_setHours = (_this: Date, hour: any, min: any, sec: any, ms: any) => {
905
1187
  // 1. Let dateObject be the this value.
906
1188
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
907
1189
  // 3. Let t be dateObject.[[DateValue]].
@@ -951,7 +1233,7 @@ export const ___date_prototype_setHours = (_this: Date, hour: any, min: any, sec
951
1233
 
952
1234
  // 21.4.4.23 Date.prototype.setMilliseconds (ms)
953
1235
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setmilliseconds
954
- export const ___date_prototype_setMilliseconds = (_this: Date, ms: any) => {
1236
+ export const __Date_prototype_setMilliseconds = (_this: Date, ms: any) => {
955
1237
  // 1. Let dateObject be the this value.
956
1238
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
957
1239
  // 3. Let t be dateObject.[[DateValue]].
@@ -982,7 +1264,7 @@ export const ___date_prototype_setMilliseconds = (_this: Date, ms: any) => {
982
1264
 
983
1265
  // 21.4.4.24 Date.prototype.setMinutes (min [, sec [, ms ]])
984
1266
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setminutes
985
- export const ___date_prototype_setMinutes = (_this: Date, min: any, sec: any, ms: any) => {
1267
+ export const __Date_prototype_setMinutes = (_this: Date, min: any, sec: any, ms: any) => {
986
1268
  // 1. Let dateObject be the this value.
987
1269
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
988
1270
  // 3. Let t be dateObject.[[DateValue]].
@@ -1026,7 +1308,7 @@ export const ___date_prototype_setMinutes = (_this: Date, min: any, sec: any, ms
1026
1308
 
1027
1309
  // 21.4.4.25 Date.prototype.setMonth (month [, date ])
1028
1310
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setmonth
1029
- export const ___date_prototype_setMonth = (_this: Date, month: any, date: any) => {
1311
+ export const __Date_prototype_setMonth = (_this: Date, month: any, date: any) => {
1030
1312
  // 1. Let dateObject be the this value.
1031
1313
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1032
1314
  // 3. Let t be dateObject.[[DateValue]].
@@ -1064,7 +1346,7 @@ export const ___date_prototype_setMonth = (_this: Date, month: any, date: any) =
1064
1346
 
1065
1347
  // 21.4.4.26 Date.prototype.setSeconds (sec [, ms ])
1066
1348
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setseconds
1067
- export const ___date_prototype_setSeconds = (_this: Date, sec: any, ms: any) => {
1349
+ export const __Date_prototype_setSeconds = (_this: Date, sec: any, ms: any) => {
1068
1350
  // 1. Let dateObject be the this value.
1069
1351
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1070
1352
  // 3. Let t be dateObject.[[DateValue]].
@@ -1103,7 +1385,7 @@ export const ___date_prototype_setSeconds = (_this: Date, sec: any, ms: any) =>
1103
1385
 
1104
1386
  // 21.4.4.27 Date.prototype.setTime (time)
1105
1387
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.settime
1106
- export const ___date_prototype_setTime = (_this: Date, time: any) => {
1388
+ export const __Date_prototype_setTime = (_this: Date, time: any) => {
1107
1389
  // 1. Let dateObject be the this value.
1108
1390
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1109
1391
  // 3. Let t be ? ToNumber(time).
@@ -1121,7 +1403,7 @@ export const ___date_prototype_setTime = (_this: Date, time: any) => {
1121
1403
 
1122
1404
  // 21.4.4.28 Date.prototype.setUTCDate (date)
1123
1405
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcdate
1124
- export const ___date_prototype_setUTCDate = (_this: Date, date: any) => {
1406
+ export const __Date_prototype_setUTCDate = (_this: Date, date: any) => {
1125
1407
  // 1. Let dateObject be the this value.
1126
1408
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1127
1409
  // 3. Let t be dateObject.[[DateValue]].
@@ -1134,7 +1416,7 @@ export const ___date_prototype_setUTCDate = (_this: Date, date: any) => {
1134
1416
  if (Number.isNaN(t)) return NaN;
1135
1417
 
1136
1418
  // 6. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), TimeWithinDay(t)).
1137
- const newDate = __ecma262_MakeDate(__ecma262_MakeDay(__ecma262_YearFromTime(t), __ecma262_MonthFromTime(t), dt), __ecma262_TimeWithinDay(t));
1419
+ const newDate: number = __ecma262_MakeDate(__ecma262_MakeDay(__ecma262_YearFromTime(t), __ecma262_MonthFromTime(t), dt), __ecma262_TimeWithinDay(t));
1138
1420
 
1139
1421
  // 7. Let v be TimeClip(newDate).
1140
1422
  const v: number = __ecma262_TimeClip(newDate);
@@ -1148,7 +1430,7 @@ export const ___date_prototype_setUTCDate = (_this: Date, date: any) => {
1148
1430
 
1149
1431
  // 21.4.4.29 Date.prototype.setUTCFullYear (year [, month [, date ]])
1150
1432
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcfullyear
1151
- export const ___date_prototype_setUTCFullYear = (_this: Date, year: any, month: any, date: any) => {
1433
+ export const __Date_prototype_setUTCFullYear = (_this: Date, year: any, month: any, date: any) => {
1152
1434
  // 1. Let dateObject be the this value.
1153
1435
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1154
1436
  // 3. Let t be dateObject.[[DateValue]].
@@ -1185,7 +1467,7 @@ export const ___date_prototype_setUTCFullYear = (_this: Date, year: any, month:
1185
1467
 
1186
1468
  // 21.4.4.30 Date.prototype.setUTCHours (hour [, min [, sec [, ms ]]])
1187
1469
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutchours
1188
- export const ___date_prototype_setUTCHours = (_this: Date, hour: any, min: any, sec: any, ms: any) => {
1470
+ export const __Date_prototype_setUTCHours = (_this: Date, hour: any, min: any, sec: any, ms: any) => {
1189
1471
  // 1. Let dateObject be the this value.
1190
1472
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1191
1473
  // 3. Let t be dateObject.[[DateValue]].
@@ -1232,7 +1514,7 @@ export const ___date_prototype_setUTCHours = (_this: Date, hour: any, min: any,
1232
1514
 
1233
1515
  // 21.4.4.31 Date.prototype.setUTCMilliseconds (ms)
1234
1516
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcmilliseconds
1235
- export const ___date_prototype_setUTCMilliseconds = (_this: Date, ms: any) => {
1517
+ export const __Date_prototype_setUTCMilliseconds = (_this: Date, ms: any) => {
1236
1518
  // 1. Let dateObject be the this value.
1237
1519
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1238
1520
  // 3. Let t be dateObject.[[DateValue]].
@@ -1260,7 +1542,7 @@ export const ___date_prototype_setUTCMilliseconds = (_this: Date, ms: any) => {
1260
1542
 
1261
1543
  // 21.4.4.32 Date.prototype.setUTCMinutes (min [, sec [, ms ]])
1262
1544
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcminutes
1263
- export const ___date_prototype_setUTCMinutes = (_this: Date, min: any, sec: any, ms: any) => {
1545
+ export const __Date_prototype_setUTCMinutes = (_this: Date, min: any, sec: any, ms: any) => {
1264
1546
  // 1. Let dateObject be the this value.
1265
1547
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1266
1548
  // 3. Let t be dateObject.[[DateValue]].
@@ -1301,7 +1583,7 @@ export const ___date_prototype_setUTCMinutes = (_this: Date, min: any, sec: any,
1301
1583
 
1302
1584
  // 21.4.4.33 Date.prototype.setUTCMonth (month [, date ])
1303
1585
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcmonth
1304
- export const ___date_prototype_setUTCMonth = (_this: Date, month: any, date: any) => {
1586
+ export const __Date_prototype_setUTCMonth = (_this: Date, month: any, date: any) => {
1305
1587
  // 1. Let dateObject be the this value.
1306
1588
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1307
1589
  // 3. Let t be dateObject.[[DateValue]].
@@ -1336,7 +1618,7 @@ export const ___date_prototype_setUTCMonth = (_this: Date, month: any, date: any
1336
1618
 
1337
1619
  // 21.4.4.34 Date.prototype.setUTCSeconds (sec [, ms ])
1338
1620
  // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcseconds
1339
- export const ___date_prototype_setUTCSeconds = (_this: Date, sec: any, ms: any) => {
1621
+ export const __Date_prototype_setUTCSeconds = (_this: Date, sec: any, ms: any) => {
1340
1622
  // 1. Let dateObject be the this value.
1341
1623
  // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1342
1624
  // 3. Let t be dateObject.[[DateValue]].
@@ -1367,4 +1649,419 @@ export const ___date_prototype_setUTCSeconds = (_this: Date, sec: any, ms: any)
1367
1649
 
1368
1650
  // 11. Return v.
1369
1651
  return v;
1652
+ };
1653
+
1654
+
1655
+ // 21.4.1.32 Date Time String Format
1656
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date-time-string-format
1657
+ // The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ
1658
+ // YYYY is the year in the proleptic Gregorian calendar as four decimal digits from 0000 to 9999, or as an expanded year of "+" or "-" followed by six decimal digits.
1659
+ // - "-" (hyphen) appears literally twice in the string.
1660
+ // MM is the month of the year as two decimal digits from 01 (January) to 12 (December).
1661
+ // DD is the day of the month as two decimal digits from 01 to 31.
1662
+ // T "T" appears literally in the string, to indicate the beginning of the time element.
1663
+ // HH is the number of complete hours that have passed since midnight as two decimal digits from 00 to 24.
1664
+ // : ":" (colon) appears literally twice in the string.
1665
+ // mm is the number of complete minutes since the start of the hour as two decimal digits from 00 to 59.
1666
+ // ss is the number of complete seconds since the start of the minute as two decimal digits from 00 to 59.
1667
+ // . "." (dot) appears literally in the string.
1668
+ // sss is the number of complete milliseconds since the start of the second as three decimal digits.
1669
+ // Z is the UTC offset representation specified as "Z" (for UTC with no offset) or as either "+" or "-" followed by a time expression HH:mm (a subset of the time zone offset string format for indicating local time ahead of or behind UTC, respectively)
1670
+
1671
+ // fast appending string
1672
+ export const __Porffor_bytestring_appendStr = (str: bytestring, appendage: bytestring): i32 => {
1673
+ const strLen: i32 = str.length;
1674
+ const appendageLen: i32 = appendage.length;
1675
+ let strPtr: i32 = Porffor.wasm`local.get ${str}` + strLen;
1676
+ let appendagePtr: i32 = Porffor.wasm`local.get ${appendage}`;
1677
+ let endPtr: i32 = appendagePtr + appendageLen;
1678
+
1679
+ while (appendagePtr < endPtr) {
1680
+ Porffor.wasm.i32.store8(strPtr++, Porffor.wasm.i32.load8_u(appendagePtr++, 0, 4), 0, 4);
1681
+ }
1682
+
1683
+ str.length = strLen + appendageLen;
1684
+ return 1;
1685
+ };
1686
+
1687
+ // fast appending single character
1688
+ export const __Porffor_bytestring_appendChar = (str: bytestring, char: i32): i32 => {
1689
+ const len: i32 = str.length;
1690
+ Porffor.wasm.i32.store8(Porffor.wasm`local.get ${str}` + len, char, 0, 4);
1691
+ str.length = len + 1;
1692
+ return 1;
1693
+ };
1694
+
1695
+ // fast appending padded number
1696
+ export const __Porffor_bytestring_appendPadNum = (str: bytestring, num: number, len: number): i32 => {
1697
+ let numStr: bytestring = Number.prototype.toFixed(num, 0);
1698
+
1699
+ let strPtr: i32 = Porffor.wasm`local.get ${str}` + str.length;
1700
+
1701
+ let numStrLen: i32 = numStr.length;
1702
+ const strPtrEnd: i32 = strPtr + (len - numStrLen);
1703
+ while (strPtr < strPtrEnd) {
1704
+ Porffor.wasm.i32.store8(strPtr++, 48, 0, 4);
1705
+ }
1706
+
1707
+ let numPtr: i32 = Porffor.wasm`local.get ${numStr}`;
1708
+ const numPtrEnd: i32 = numPtr + numStrLen;
1709
+ while (numPtr < numPtrEnd) {
1710
+ Porffor.wasm.i32.store8(strPtr++, Porffor.wasm.i32.load8_u(numPtr++, 0, 4), 0, 4);
1711
+ }
1712
+
1713
+ str.length = strPtr - Porffor.wasm`local.get ${str}`;
1714
+
1715
+ return 1;
1716
+ };
1717
+
1718
+ // Timestamp to UTC DTSF
1719
+ export const __ecma262_ToUTCDTSF = (t: number): bytestring => {
1720
+ const year: number = __ecma262_YearFromTime(t);
1721
+
1722
+ let out: bytestring = '';
1723
+ out.length = 0;
1724
+
1725
+ if (Porffor.fastOr(year < 0, year >= 10000)) {
1726
+ // extended year format
1727
+ // sign
1728
+ __Porffor_bytestring_appendChar(out, year > 0 ? 43 : 45);
1729
+
1730
+ // 6 digit year
1731
+ __Porffor_bytestring_appendPadNum(out, year, 6);
1732
+ } else {
1733
+ // 4 digit year
1734
+ __Porffor_bytestring_appendPadNum(out, year, 4);
1735
+ }
1736
+ __Porffor_bytestring_appendChar(out, 45); // -
1737
+
1738
+ // 2 digit month (01-12)
1739
+ __Porffor_bytestring_appendPadNum(out, __ecma262_MonthFromTime(t) + 1, 2);
1740
+ __Porffor_bytestring_appendChar(out, 45); // -
1741
+
1742
+ // 2 digit day of the month
1743
+ __Porffor_bytestring_appendPadNum(out, __ecma262_DateFromTime(t), 2);
1744
+ __Porffor_bytestring_appendChar(out, 84); // T
1745
+
1746
+ // 2 digit hour
1747
+ __Porffor_bytestring_appendPadNum(out, __ecma262_HourFromTime(t), 2);
1748
+ __Porffor_bytestring_appendChar(out, 58); // :
1749
+
1750
+ // 2 digit minute
1751
+ __Porffor_bytestring_appendPadNum(out, __ecma262_MinFromTime(t), 2);
1752
+ __Porffor_bytestring_appendChar(out, 58); // :
1753
+
1754
+ // 2 digit second
1755
+ __Porffor_bytestring_appendPadNum(out, __ecma262_SecFromTime(t), 2);
1756
+ __Porffor_bytestring_appendChar(out, 46); // .
1757
+
1758
+ // 3 digit millisecond
1759
+ __Porffor_bytestring_appendPadNum(out, __ecma262_msFromTime(t), 3);
1760
+ __Porffor_bytestring_appendChar(out, 90); // Z
1761
+
1762
+ return out;
1763
+ };
1764
+
1765
+ // 21.4.4.36 Date.prototype.toISOString ()
1766
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.toisostring
1767
+ export const __Date_prototype_toISOString = (_this: Date) => {
1768
+ // 1. Let dateObject be the this value.
1769
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1770
+ // 3. Let tv be dateObject.[[DateValue]].
1771
+ const tv: number = __Porffor_date_read(_this);
1772
+
1773
+ // 4. If tv is NaN, throw a RangeError exception.
1774
+ if (Number.isNaN(tv)) {
1775
+ throw new RangeError('Invalid time value');
1776
+ }
1777
+
1778
+ // 5. Assert: tv is an integral Number.
1779
+
1780
+ // 6. If tv corresponds with a year that cannot be represented in the Date Time String Format, throw a RangeError exception.
1781
+ // todo
1782
+
1783
+ // 7. Return a String representation of tv in the Date Time String Format on the UTC time scale, including all format elements and the UTC offset representation "Z".
1784
+ return __ecma262_ToUTCDTSF(tv);
1785
+ };
1786
+
1787
+ // 21.4.4.37 Date.prototype.toJSON (key)
1788
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tojson
1789
+ export const __Date_prototype_toJSON = (_this: Date, key: any) => {
1790
+ // 1. Let O be ? ToObject(this value).
1791
+ // 2. Let tv be ? ToPrimitive(O, number).
1792
+ // todo: use generic Number() once it supports Date
1793
+ const tv: number = __Porffor_date_read(_this);
1794
+
1795
+ // 3. If tv is a Number and tv is not finite, return null.
1796
+ if (!Number.isFinite(tv)) return null;
1797
+
1798
+ // 4. Return ? Invoke(O, "toISOString").
1799
+ return __Date_prototype_toISOString(_this);
1800
+ };
1801
+
1802
+
1803
+ // 21.4.4.41.1 TimeString (tv)
1804
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-timestring
1805
+ export const __ecma262_TimeString = (tv: number): bytestring => {
1806
+ // we do not follow spec exactly by using number vars and appending at the end
1807
+
1808
+ // 1. Let hour be ToZeroPaddedDecimalString(ℝ(HourFromTime(tv)), 2).
1809
+ const hour: number = __ecma262_HourFromTime(tv);
1810
+
1811
+ // 2. Let minute be ToZeroPaddedDecimalString(ℝ(MinFromTime(tv)), 2).
1812
+ const minute: number = __ecma262_MinFromTime(tv);
1813
+
1814
+ // 3. Let second be ToZeroPaddedDecimalString(ℝ(SecFromTime(tv)), 2).
1815
+ const second: number = __ecma262_SecFromTime(tv);
1816
+
1817
+ // 4. Return the string-concatenation of hour, ":", minute, ":", second, the code unit 0x0020 (SPACE), and "GMT".
1818
+ let out: bytestring = '';
1819
+ out.length = 0;
1820
+
1821
+ __Porffor_bytestring_appendPadNum(out, hour, 2);
1822
+ __Porffor_bytestring_appendChar(out, 58); // ':'
1823
+
1824
+ __Porffor_bytestring_appendPadNum(out, minute, 2);
1825
+ __Porffor_bytestring_appendChar(out, 58); // ':'
1826
+
1827
+ __Porffor_bytestring_appendPadNum(out, second, 2);
1828
+
1829
+ __Porffor_bytestring_appendChar(out, 32); // ' '
1830
+ __Porffor_bytestring_appendChar(out, 71); // 'G'
1831
+ __Porffor_bytestring_appendChar(out, 77); // 'M'
1832
+ __Porffor_bytestring_appendChar(out, 84); // 'T'
1833
+
1834
+ return out;
1835
+ };
1836
+
1837
+ // 21.4.4.41.2 DateString (tv)
1838
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-datestring
1839
+ export const __ecma262_DateString = (tv: number): bytestring => {
1840
+ // we do not follow spec exactly by using number vars and appending at the end
1841
+
1842
+ // 1. Let weekday be the Name of the entry in Table 62 with the Number WeekDay(tv).
1843
+ const weekday: bytestring = __ecma262_WeekDayName(tv);
1844
+
1845
+ // 2. Let month be the Name of the entry in Table 63 with the Number MonthFromTime(tv).
1846
+ const month: bytestring = __ecma262_MonthName(tv);
1847
+
1848
+ // 3. Let day be ToZeroPaddedDecimalString(ℝ(DateFromTime(tv)), 2).
1849
+ const day: number = __ecma262_DateFromTime(tv);
1850
+
1851
+ // 4. Let yv be YearFromTime(tv).
1852
+ const yv: number = __ecma262_YearFromTime(tv);
1853
+
1854
+ // 5. If yv is +0𝔽 or yv > +0𝔽, let yearSign be the empty String; otherwise, let yearSign be "-".
1855
+ // 6. Let paddedYear be ToZeroPaddedDecimalString(abs(ℝ(yv)), 4).
1856
+ // 7. Return the string-concatenation of weekday, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE), day, the code unit 0x0020 (SPACE), yearSign, and paddedYear.
1857
+ let out: bytestring = '';
1858
+ out.length = 0;
1859
+
1860
+ // weekday
1861
+ __Porffor_bytestring_appendStr(out, weekday);
1862
+ __Porffor_bytestring_appendChar(out, 32); // ' '
1863
+
1864
+ // month
1865
+ __Porffor_bytestring_appendStr(out, month);
1866
+ __Porffor_bytestring_appendChar(out, 32); // ' '
1867
+
1868
+ // day
1869
+ __Porffor_bytestring_appendPadNum(out, day, 2);
1870
+ __Porffor_bytestring_appendChar(out, 32); // ' '
1871
+
1872
+ // year
1873
+ if (yv < 0) __Porffor_bytestring_appendChar(out, 45); // sign
1874
+ __Porffor_bytestring_appendPadNum(out, yv, 4);
1875
+
1876
+ return out;
1877
+ };
1878
+
1879
+ // 21.4.4.41.3 TimeZoneString (tv)
1880
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-timezonestring
1881
+ export const __ecma262_TimeZoneString = (tv: number) => {
1882
+ // todo: time zone support
1883
+ let out: bytestring = '+0000 (UTC)';
1884
+ return out;
1885
+ };
1886
+
1887
+ // 21.4.4.41.4 ToDateString (tv)
1888
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-todatestring
1889
+ export const __ecma262_ToDateString = (tv: number) => {
1890
+ let out: bytestring = '';
1891
+ out.length = 0;
1892
+
1893
+ // 1. If tv is NaN, return "Invalid Date".
1894
+ if (Number.isNaN(tv)) {
1895
+ out = 'Invalid Date';
1896
+ return out;
1897
+ }
1898
+
1899
+ // 2. Let t be LocalTime(tv).
1900
+ const t: number = __ecma262_LocalTime(tv);
1901
+
1902
+ // 3. Return the string-concatenation of DateString(t), the code unit 0x0020 (SPACE), TimeString(t), and TimeZoneString(tv).
1903
+ __Porffor_bytestring_appendStr(out, __ecma262_DateString(t));
1904
+ __Porffor_bytestring_appendChar(out, 32);
1905
+
1906
+ __Porffor_bytestring_appendStr(out, __ecma262_TimeString(t));
1907
+
1908
+ __Porffor_bytestring_appendStr(out, __ecma262_TimeZoneString(tv));
1909
+
1910
+ return out;
1911
+ };
1912
+
1913
+ // 21.4.4.41 Date.prototype.toString ()
1914
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tostring
1915
+ export const __Date_prototype_toString = (_this: Date) => {
1916
+ // 1. Let dateObject be the this value.
1917
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1918
+ // 3. Let tv be dateObject.[[DateValue]].
1919
+ const tv: number = __Porffor_date_read(_this);
1920
+
1921
+ // 4. Return ToDateString(tv).
1922
+ return __ecma262_ToDateString(tv);
1923
+ };
1924
+
1925
+ // 21.4.4.42 Date.prototype.toTimeString ()
1926
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.totimestring
1927
+ export const __Date_prototype_toTimeString = (_this: Date) => {
1928
+ // 1. Let dateObject be the this value.
1929
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1930
+ // 3. Let tv be dateObject.[[DateValue]].
1931
+ const tv: number = __Porffor_date_read(_this);
1932
+
1933
+ // 4. If tv is NaN, return "Invalid Date".
1934
+ let out: bytestring = '';
1935
+ out.length = 0;
1936
+
1937
+ if (Number.isNaN(tv)) {
1938
+ out = 'Invalid Date';
1939
+ return out;
1940
+ }
1941
+
1942
+ // 5. Let t be LocalTime(tv).
1943
+ const t: number = __ecma262_LocalTime(tv);
1944
+
1945
+ // 6. Return the string-concatenation of TimeString(t) and TimeZoneString(tv).
1946
+ __Porffor_bytestring_appendStr(out, __ecma262_TimeString(t));
1947
+ __Porffor_bytestring_appendStr(out, __ecma262_TimeZoneString(tv));
1948
+
1949
+ return out;
1950
+ };
1951
+
1952
+
1953
+ // 21.4.4.35 Date.prototype.toDateString ()
1954
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.todatestring
1955
+ export const __Date_prototype_toDateString = (_this: Date) => {
1956
+ // 1. Let dateObject be the this value.
1957
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1958
+ // 3. Let tv be dateObject.[[DateValue]].
1959
+ const tv: number = __Porffor_date_read(_this);
1960
+
1961
+ // 4. If tv is NaN, return "Invalid Date".
1962
+ let out: bytestring = '';
1963
+ out.length = 0;
1964
+
1965
+ if (Number.isNaN(tv)) {
1966
+ out = 'Invalid Date';
1967
+ return out;
1968
+ }
1969
+
1970
+ // 5. Let t be LocalTime(tv).
1971
+ const t: number = __ecma262_LocalTime(tv);
1972
+
1973
+ // 6. Return DateString(t).
1974
+ out = __ecma262_DateString(t);
1975
+ return out;
1976
+ };
1977
+
1978
+ // 21.4.4.43 Date.prototype.toUTCString ()
1979
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.toutcstring
1980
+ export const __Date_prototype_toUTCString = (_this: Date) => {
1981
+ // 1. Let dateObject be the this value.
1982
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1983
+ // 3. Let tv be dateObject.[[DateValue]].
1984
+ const tv: number = __Porffor_date_read(_this);
1985
+
1986
+ // 4. If tv is NaN, return "Invalid Date".
1987
+ let out: bytestring = '';
1988
+ out.length = 0;
1989
+
1990
+ if (Number.isNaN(tv)) {
1991
+ out = 'Invalid Date';
1992
+ return out;
1993
+ }
1994
+
1995
+ // 5. Let weekday be the Name of the entry in Table 62 with the Number WeekDay(tv).
1996
+ const weekday: bytestring = __ecma262_WeekDayName(tv);
1997
+
1998
+ // 6. Let month be the Name of the entry in Table 63 with the Number MonthFromTime(tv).
1999
+ const month: bytestring = __ecma262_MonthName(tv);
2000
+
2001
+ // 7. Let day be ToZeroPaddedDecimalString(ℝ(DateFromTime(tv)), 2).
2002
+ const day: number = __ecma262_DateFromTime(tv);
2003
+
2004
+ // 8. Let yv be YearFromTime(tv).
2005
+ const yv: number = __ecma262_YearFromTime(tv);
2006
+
2007
+ // 9. If yv is +0𝔽 or yv > +0𝔽, let yearSign be the empty String; otherwise, let yearSign be "-".
2008
+ // 10. Let paddedYear be ToZeroPaddedDecimalString(abs(ℝ(yv)), 4).
2009
+ // 11. Return the string-concatenation of weekday, ",", the code unit 0x0020 (SPACE), day, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE), yearSign, paddedYear, the code unit 0x0020 (SPACE), and TimeString(tv).
2010
+ // weekday
2011
+ __Porffor_bytestring_appendStr(out, weekday);
2012
+ __Porffor_bytestring_appendChar(out, 44); // ','
2013
+ __Porffor_bytestring_appendChar(out, 32); // ' '
2014
+
2015
+ // day
2016
+ __Porffor_bytestring_appendPadNum(out, day, 2);
2017
+ __Porffor_bytestring_appendChar(out, 32); // ' '
2018
+
2019
+ // month
2020
+ __Porffor_bytestring_appendStr(out, month);
2021
+ __Porffor_bytestring_appendChar(out, 32); // ' '
2022
+
2023
+ // year
2024
+ if (yv < 0) __Porffor_bytestring_appendChar(out, 45); // sign
2025
+ __Porffor_bytestring_appendPadNum(out, yv, 4);
2026
+
2027
+ __Porffor_bytestring_appendChar(out, 32); // ' '
2028
+ __Porffor_bytestring_appendStr(out, __ecma262_TimeString(tv));
2029
+
2030
+ return out;
2031
+ };
2032
+
2033
+ // 21.4.4.38 Date.prototype.toLocaleDateString ([ reserved1 [, reserved2 ]])
2034
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tolocaledatestring
2035
+ export const __Date_prototype_toLocaleDateString = (_this: Date, reserved1: any, reserved2: any) => {
2036
+ return __Date_prototype_toDateString(_this);
2037
+ };
2038
+
2039
+ // 21.4.4.39 Date.prototype.toLocaleString ([ reserved1 [, reserved2 ]])
2040
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tolocalestring
2041
+ export const __Date_prototype_toLocaleString = (_this: Date, reserved1: any, reserved2: any) => {
2042
+ return __Date_prototype_toString(_this);
2043
+ };
2044
+
2045
+ // 21.4.4.40 Date.prototype.toLocaleTimeString ([ reserved1 [, reserved2 ]])
2046
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tolocaletimestring
2047
+ export const __Date_prototype_toLocaleTimeString = (_this: Date, reserved1: any, reserved2: any) => {
2048
+ return __Date_prototype_toTimeString(_this);
2049
+ };
2050
+
2051
+ // 21.4.4.44 Date.prototype.valueOf ()
2052
+ // https://tc39.es/ecma262/#sec-date.prototype.valueof
2053
+ export const __Date_prototype_valueOf = (_this: Date) => {
2054
+ // 1. Let dateObject be the this value.
2055
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
2056
+ // 3. Return dateObject.[[DateValue]].
2057
+ return __Porffor_date_read(_this);
2058
+ };
2059
+
2060
+ // 21.4.2.1 Date (...values)
2061
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date
2062
+ export const Date = (): bytestring => {
2063
+ // 1. If NewTarget is undefined, then
2064
+ // a. Let now be the time value (UTC) identifying the current time.
2065
+ // b. Return ToDateString(now).
2066
+ return __ecma262_ToDateString(__Date_now());
1370
2067
  };