porffor 0.2.0-a6c01f5 → 0.2.0-ae8cbb8

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