porffor 0.2.0-e04e26f → 0.2.0-e62542f

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]].
@@ -861,268 +1145,927 @@ export const ___date_prototype_setDate = (_this: Date, date: any) => {
861
1145
  return u;
862
1146
  };
863
1147
 
864
- // 21.4.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] )
865
-
866
- // This method performs the following steps when called:
867
-
868
- // 1. Let dateObject be the this value.
869
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
870
- // 3. Let t be dateObject.[[DateValue]].
871
- // 4. Let y be ? ToNumber(year).
872
- // 5. If t is NaN, set t to +0𝔽; otherwise, set t to LocalTime(t).
873
- // 6. If month is not present, let m be MonthFromTime(t); otherwise, let m be ? ToNumber(month).
874
- // 7. If date is not present, let dt be DateFromTime(t); otherwise, let dt be ? ToNumber(date).
875
- // 8. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)).
876
- // 9. Let u be TimeClip(UTC(newDate)).
877
- // 10. Set dateObject.[[DateValue]] to u.
878
- // 11. Return u.
879
-
880
- // The "length" property of this method is 3𝔽.
881
- // Note
882
-
883
- // If month is not present, this method behaves as if month was present with the value getMonth(). If date is not present, it behaves as if date was present with the value getDate().
884
- // 21.4.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] )
885
-
886
- // This method performs the following steps when called:
887
-
888
- // 1. Let dateObject be the this value.
889
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
890
- // 3. Let t be dateObject.[[DateValue]].
891
- // 4. Let h be ? ToNumber(hour).
892
- // 5. If min is present, let m be ? ToNumber(min).
893
- // 6. If sec is present, let s be ? ToNumber(sec).
894
- // 7. If ms is present, let milli be ? ToNumber(ms).
895
- // 8. If t is NaN, return NaN.
896
- // 9. Set t to LocalTime(t).
897
- // 10. If min is not present, let m be MinFromTime(t).
898
- // 11. If sec is not present, let s be SecFromTime(t).
899
- // 12. If ms is not present, let milli be msFromTime(t).
900
- // 13. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)).
901
- // 14. Let u be TimeClip(UTC(date)).
902
- // 15. Set dateObject.[[DateValue]] to u.
903
- // 16. Return u.
904
-
905
- // The "length" property of this method is 4𝔽.
906
- // Note
907
-
908
- // If min is not present, this method behaves as if min was present with the value getMinutes(). If sec is not present, it behaves as if sec was present with the value getSeconds(). If ms is not present, it behaves as if ms was present with the value getMilliseconds().
909
- // 21.4.4.23 Date.prototype.setMilliseconds ( ms )
910
-
911
- // This method performs the following steps when called:
912
-
913
- // 1. Let dateObject be the this value.
914
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
915
- // 3. Let t be dateObject.[[DateValue]].
916
- // 4. Set ms to ? ToNumber(ms).
917
- // 5. If t is NaN, return NaN.
918
- // 6. Set t to LocalTime(t).
919
- // 7. Let time be MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms).
920
- // 8. Let u be TimeClip(UTC(MakeDate(Day(t), time))).
921
- // 9. Set dateObject.[[DateValue]] to u.
922
- // 10. Return u.
923
-
924
- // 21.4.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] )
925
-
926
- // This method performs the following steps when called:
927
-
928
- // 1. Let dateObject be the this value.
929
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
930
- // 3. Let t be dateObject.[[DateValue]].
931
- // 4. Let m be ? ToNumber(min).
932
- // 5. If sec is present, let s be ? ToNumber(sec).
933
- // 6. If ms is present, let milli be ? ToNumber(ms).
934
- // 7. If t is NaN, return NaN.
935
- // 8. Set t to LocalTime(t).
936
- // 9. If sec is not present, let s be SecFromTime(t).
937
- // 10. If ms is not present, let milli be msFromTime(t).
938
- // 11. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)).
939
- // 12. Let u be TimeClip(UTC(date)).
940
- // 13. Set dateObject.[[DateValue]] to u.
941
- // 14. Return u.
942
-
943
- // The "length" property of this method is 3𝔽.
944
- // Note
945
-
946
- // If sec is not present, this method behaves as if sec was present with the value getSeconds(). If ms is not present, this behaves as if ms was present with the value getMilliseconds().
947
- // 21.4.4.25 Date.prototype.setMonth ( month [ , date ] )
948
-
949
- // This method performs the following steps when called:
950
-
951
- // 1. Let dateObject be the this value.
952
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
953
- // 3. Let t be dateObject.[[DateValue]].
954
- // 4. Let m be ? ToNumber(month).
955
- // 5. If date is present, let dt be ? ToNumber(date).
956
- // 6. If t is NaN, return NaN.
957
- // 7. Set t to LocalTime(t).
958
- // 8. If date is not present, let dt be DateFromTime(t).
959
- // 9. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), TimeWithinDay(t)).
960
- // 10. Let u be TimeClip(UTC(newDate)).
961
- // 11. Set dateObject.[[DateValue]] to u.
962
- // 12. Return u.
963
-
964
- // The "length" property of this method is 2𝔽.
965
- // Note
966
-
967
- // If date is not present, this method behaves as if date was present with the value getDate().
968
- // 21.4.4.26 Date.prototype.setSeconds ( sec [ , ms ] )
969
-
970
- // This method performs the following steps when called:
971
-
972
- // 1. Let dateObject be the this value.
973
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
974
- // 3. Let t be dateObject.[[DateValue]].
975
- // 4. Let s be ? ToNumber(sec).
976
- // 5. If ms is present, let milli be ? ToNumber(ms).
977
- // 6. If t is NaN, return NaN.
978
- // 7. Set t to LocalTime(t).
979
- // 8. If ms is not present, let milli be msFromTime(t).
980
- // 9. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, milli)).
981
- // 10. Let u be TimeClip(UTC(date)).
982
- // 11. Set dateObject.[[DateValue]] to u.
983
- // 12. Return u.
984
-
985
- // The "length" property of this method is 2𝔽.
986
- // Note
987
-
988
- // If ms is not present, this method behaves as if ms was present with the value getMilliseconds().
989
- // 21.4.4.27 Date.prototype.setTime ( time )
990
-
991
- // This method performs the following steps when called:
992
-
993
- // 1. Let dateObject be the this value.
994
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
995
- // 3. Let t be ? ToNumber(time).
996
- // 4. Let v be TimeClip(t).
997
- // 5. Set dateObject.[[DateValue]] to v.
998
- // 6. Return v.
999
-
1000
- // 21.4.4.28 Date.prototype.setUTCDate ( date )
1001
-
1002
- // This method performs the following steps when called:
1003
-
1004
- // 1. Let dateObject be the this value.
1005
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1006
- // 3. Let t be dateObject.[[DateValue]].
1007
- // 4. Let dt be ? ToNumber(date).
1008
- // 5. If t is NaN, return NaN.
1009
- // 6. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), TimeWithinDay(t)).
1010
- // 7. Let v be TimeClip(newDate).
1011
- // 8. Set dateObject.[[DateValue]] to v.
1012
- // 9. Return v.
1013
-
1014
- // 21.4.4.29 Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] )
1015
-
1016
- // This method performs the following steps when called:
1017
-
1018
- // 1. Let dateObject be the this value.
1019
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1020
- // 3. Let t be dateObject.[[DateValue]].
1021
- // 4. If t is NaN, set t to +0𝔽.
1022
- // 5. Let y be ? ToNumber(year).
1023
- // 6. If month is not present, let m be MonthFromTime(t); otherwise, let m be ? ToNumber(month).
1024
- // 7. If date is not present, let dt be DateFromTime(t); otherwise, let dt be ? ToNumber(date).
1025
- // 8. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)).
1026
- // 9. Let v be TimeClip(newDate).
1027
- // 10. Set dateObject.[[DateValue]] to v.
1028
- // 11. Return v.
1029
-
1030
- // The "length" property of this method is 3𝔽.
1031
- // Note
1032
-
1033
- // If month is not present, this method behaves as if month was present with the value getUTCMonth(). If date is not present, it behaves as if date was present with the value getUTCDate().
1034
- // 21.4.4.30 Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] )
1035
-
1036
- // This method performs the following steps when called:
1037
-
1038
- // 1. Let dateObject be the this value.
1039
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1040
- // 3. Let t be dateObject.[[DateValue]].
1041
- // 4. Let h be ? ToNumber(hour).
1042
- // 5. If min is present, let m be ? ToNumber(min).
1043
- // 6. If sec is present, let s be ? ToNumber(sec).
1044
- // 7. If ms is present, let milli be ? ToNumber(ms).
1045
- // 8. If t is NaN, return NaN.
1046
- // 9. If min is not present, let m be MinFromTime(t).
1047
- // 10. If sec is not present, let s be SecFromTime(t).
1048
- // 11. If ms is not present, let milli be msFromTime(t).
1049
- // 12. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)).
1050
- // 13. Let v be TimeClip(date).
1051
- // 14. Set dateObject.[[DateValue]] to v.
1052
- // 15. Return v.
1053
-
1054
- // The "length" property of this method is 4𝔽.
1055
- // Note
1056
-
1057
- // If min is not present, this method behaves as if min was present with the value getUTCMinutes(). If sec is not present, it behaves as if sec was present with the value getUTCSeconds(). If ms is not present, it behaves as if ms was present with the value getUTCMilliseconds().
1058
- // 21.4.4.31 Date.prototype.setUTCMilliseconds ( ms )
1059
-
1060
- // This method performs the following steps when called:
1061
-
1062
- // 1. Let dateObject be the this value.
1063
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1064
- // 3. Let t be dateObject.[[DateValue]].
1065
- // 4. Set ms to ? ToNumber(ms).
1066
- // 5. If t is NaN, return NaN.
1067
- // 6. Let time be MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms).
1068
- // 7. Let v be TimeClip(MakeDate(Day(t), time)).
1069
- // 8. Set dateObject.[[DateValue]] to v.
1070
- // 9. Return v.
1071
-
1072
- // 21.4.4.32 Date.prototype.setUTCMinutes ( min [ , sec [ , ms ] ] )
1073
-
1074
- // This method performs the following steps when called:
1075
-
1076
- // 1. Let dateObject be the this value.
1077
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1078
- // 3. Let t be dateObject.[[DateValue]].
1079
- // 4. Let m be ? ToNumber(min).
1080
- // 5. If sec is present, let s be ? ToNumber(sec).
1081
- // 6. If ms is present, let milli be ? ToNumber(ms).
1082
- // 7. If t is NaN, return NaN.
1083
- // 8. If sec is not present, let s be SecFromTime(t).
1084
- // 9. If ms is not present, let milli be msFromTime(t).
1085
- // 10. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)).
1086
- // 11. Let v be TimeClip(date).
1087
- // 12. Set dateObject.[[DateValue]] to v.
1088
- // 13. Return v.
1089
-
1090
- // The "length" property of this method is 3𝔽.
1091
- // Note
1092
-
1093
- // If sec is not present, this method behaves as if sec was present with the value getUTCSeconds(). If ms is not present, it behaves as if ms was present with the value return by getUTCMilliseconds().
1094
- // 21.4.4.33 Date.prototype.setUTCMonth ( month [ , date ] )
1095
-
1096
- // This method performs the following steps when called:
1097
-
1098
- // 1. Let dateObject be the this value.
1099
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1100
- // 3. Let t be dateObject.[[DateValue]].
1101
- // 4. Let m be ? ToNumber(month).
1102
- // 5. If date is present, let dt be ? ToNumber(date).
1103
- // 6. If t is NaN, return NaN.
1104
- // 7. If date is not present, let dt be DateFromTime(t).
1105
- // 8. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), TimeWithinDay(t)).
1106
- // 9. Let v be TimeClip(newDate).
1107
- // 10. Set dateObject.[[DateValue]] to v.
1108
- // 11. Return v.
1109
-
1110
- // The "length" property of this method is 2𝔽.
1111
- // Note
1112
-
1113
- // If date is not present, this method behaves as if date was present with the value getUTCDate().
1114
- // 21.4.4.34 Date.prototype.setUTCSeconds ( sec [ , ms ] )
1115
-
1116
- // This method performs the following steps when called:
1117
-
1118
- // 1. Let dateObject be the this value.
1119
- // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1120
- // 3. Let t be dateObject.[[DateValue]].
1121
- // 4. Let s be ? ToNumber(sec).
1122
- // 5. If ms is present, let milli be ? ToNumber(ms).
1123
- // 6. If t is NaN, return NaN.
1124
- // 7. If ms is not present, let milli be msFromTime(t).
1125
- // 8. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, milli)).
1126
- // 9. Let v be TimeClip(date).
1127
- // 10. Set dateObject.[[DateValue]] to v.
1128
- // 11. Return v.
1148
+ // 21.4.4.21 Date.prototype.setFullYear (year [, month [, date ]])
1149
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setfullyear
1150
+ export const __Date_prototype_setFullYear = (_this: Date, year: any, month: any, date: any) => {
1151
+ // 1. Let dateObject be the this value.
1152
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1153
+ // 3. Let t be dateObject.[[DateValue]].
1154
+ let t: number = __Porffor_date_read(_this);
1155
+
1156
+ // 4. Let y be ? ToNumber(year).
1157
+ const y: number = Number(year);
1158
+
1159
+ // 5. If t is NaN, set t to +0𝔽; otherwise, set t to LocalTime(t).
1160
+ if (Number.isNaN(t)) t = 0;
1161
+ else t = __ecma262_LocalTime(t);
1162
+
1163
+ // 6. If month is not present, let m be MonthFromTime(t); otherwise, let m be ? ToNumber(month).
1164
+ let m: number;
1165
+ if (Porffor.rawType(month) == Porffor.TYPES.undefined) m = __ecma262_MonthFromTime(t);
1166
+ else m = Number(month);
1167
+
1168
+ // 7. If date is not present, let dt be DateFromTime(t); otherwise, let dt be ? ToNumber(date).
1169
+ let dt: number;
1170
+ if (Porffor.rawType(date) == Porffor.TYPES.undefined) dt = __ecma262_DateFromTime(t);
1171
+ else dt = Number(date);
1172
+
1173
+ // 8. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)).
1174
+ const newDate: number = __ecma262_MakeDate(__ecma262_MakeDay(y, m, dt), __ecma262_TimeWithinDay(t));
1175
+
1176
+ // 9. Let u be TimeClip(UTC(newDate)).
1177
+ const u: number = __ecma262_TimeClip(__ecma262_UTC(newDate));
1178
+
1179
+ // 10. Set dateObject.[[DateValue]] to u.
1180
+ __Porffor_date_write(_this, u);
1181
+
1182
+ // 11. Return u.
1183
+ return u;
1184
+ };
1185
+
1186
+ // 21.4.4.22 Date.prototype.setHours (hour [, min [, sec [, ms ]]])
1187
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.sethours
1188
+ export const __Date_prototype_setHours = (_this: Date, hour: any, min: any, sec: any, ms: any) => {
1189
+ // 1. Let dateObject be the this value.
1190
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1191
+ // 3. Let t be dateObject.[[DateValue]].
1192
+ let t: number = __Porffor_date_read(_this);
1193
+
1194
+ // 4. Let h be ? ToNumber(hour).
1195
+ const h: number = Number(hour);
1196
+
1197
+ // we reorder the spec steps in this func for easier arg handling
1198
+
1199
+ // 8. If t is NaN, return NaN.
1200
+ if (Number.isNaN(t)) return NaN;
1201
+
1202
+ // 9. Set t to LocalTime(t).
1203
+ t = __ecma262_LocalTime(t);
1204
+
1205
+ // 5. If min is present, let m be ? ToNumber(min).
1206
+ let m: number;
1207
+ if (Porffor.rawType(min) != Porffor.TYPES.undefined) m = Number(min);
1208
+ // 10. If min is not present, let m be MinFromTime(t).
1209
+ else m = __ecma262_MinFromTime(t);
1210
+
1211
+ // 6. If sec is present, let s be ? ToNumber(sec).
1212
+ let s: number;
1213
+ if (Porffor.rawType(sec) != Porffor.TYPES.undefined) s = Number(sec);
1214
+ // 11. If sec is not present, let s be SecFromTime(t).
1215
+ else s = __ecma262_SecFromTime(t);
1216
+
1217
+ // 7. If ms is present, let milli be ? ToNumber(ms).
1218
+ let milli: number;
1219
+ if (Porffor.rawType(ms) != Porffor.TYPES.undefined) milli = Number(ms);
1220
+ // 12. If ms is not present, let milli be msFromTime(t).
1221
+ else milli = __ecma262_msFromTime(t);
1222
+
1223
+ // 13. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)).
1224
+ const date: number = __ecma262_MakeDate(__ecma262_Day(t), __ecma262_MakeTime(h, m, s, milli));
1225
+
1226
+ // 14. Let u be TimeClip(UTC(date)).
1227
+ const u: number = __ecma262_TimeClip(__ecma262_UTC(date));
1228
+
1229
+ // 15. Set dateObject.[[DateValue]] to u.
1230
+ __Porffor_date_write(_this, u);
1231
+
1232
+ // 16. Return u.
1233
+ return u;
1234
+ };
1235
+
1236
+ // 21.4.4.23 Date.prototype.setMilliseconds (ms)
1237
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setmilliseconds
1238
+ export const __Date_prototype_setMilliseconds = (_this: Date, ms: any) => {
1239
+ // 1. Let dateObject be the this value.
1240
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1241
+ // 3. Let t be dateObject.[[DateValue]].
1242
+ let t: number = __Porffor_date_read(_this);
1243
+
1244
+ // ignore old-style spec setting arg instead of having let
1245
+ // 4. Set ms to ? ToNumber(ms).
1246
+ const milli: number = Number(ms);
1247
+
1248
+ // 5. If t is NaN, return NaN.
1249
+ if (Number.isNaN(t)) return NaN;
1250
+
1251
+ // 6. Set t to LocalTime(t).
1252
+ t = __ecma262_LocalTime(t);
1253
+
1254
+ // 7. Let time be MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms).
1255
+ const time: number = __ecma262_MakeTime(__ecma262_HourFromTime(t), __ecma262_MinFromTime(t), __ecma262_SecFromTime(t), milli);
1256
+
1257
+ // 8. Let u be TimeClip(UTC(MakeDate(Day(t), time))).
1258
+ const u: number = __ecma262_TimeClip(__ecma262_UTC(__ecma262_MakeDate(__ecma262_Day(t), time)));
1259
+
1260
+ // 9. Set dateObject.[[DateValue]] to u.
1261
+ __Porffor_date_write(_this, u);
1262
+
1263
+ // 10. Return u.
1264
+ return u;
1265
+ };
1266
+
1267
+ // 21.4.4.24 Date.prototype.setMinutes (min [, sec [, ms ]])
1268
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setminutes
1269
+ export const __Date_prototype_setMinutes = (_this: Date, min: any, sec: any, ms: any) => {
1270
+ // 1. Let dateObject be the this value.
1271
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1272
+ // 3. Let t be dateObject.[[DateValue]].
1273
+ let t: number = __Porffor_date_read(_this);
1274
+
1275
+ // 4. Let m be ? ToNumber(min).
1276
+ const m: number = Number(min);
1277
+
1278
+ // we reorder the spec steps in this func for easier arg handling
1279
+
1280
+ // 7. If t is NaN, return NaN.
1281
+ if (Number.isNaN(t)) return NaN;
1282
+
1283
+ // 8. Set t to LocalTime(t).
1284
+ t = __ecma262_LocalTime(t);
1285
+
1286
+ // 5. If sec is present, let s be ? ToNumber(sec).
1287
+ let s: number;
1288
+ if (Porffor.rawType(sec) != Porffor.TYPES.undefined) s = Number(sec);
1289
+ // 9. If sec is not present, let s be SecFromTime(t).
1290
+ else s = __ecma262_SecFromTime(t);
1291
+
1292
+ // 6. If ms is present, let milli be ? ToNumber(ms).
1293
+ let milli: number;
1294
+ if (Porffor.rawType(ms) != Porffor.TYPES.undefined) milli = Number(ms);
1295
+ // 10. If ms is not present, let milli be msFromTime(t).
1296
+ else milli = __ecma262_msFromTime(t);
1297
+
1298
+ // 11. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)).
1299
+ const date: number = __ecma262_MakeDate(__ecma262_Day(t), __ecma262_MakeTime(__ecma262_HourFromTime(t), m, s, milli));
1300
+
1301
+ // 12. Let u be TimeClip(UTC(date)).
1302
+ const u: number = __ecma262_TimeClip(__ecma262_UTC(date));
1303
+
1304
+ // 13. Set dateObject.[[DateValue]] to u.
1305
+ __Porffor_date_write(_this, u);
1306
+
1307
+ // 14. Return u.
1308
+ return u;
1309
+ };
1310
+
1311
+ // 21.4.4.25 Date.prototype.setMonth (month [, date ])
1312
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setmonth
1313
+ export const __Date_prototype_setMonth = (_this: Date, month: any, date: any) => {
1314
+ // 1. Let dateObject be the this value.
1315
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1316
+ // 3. Let t be dateObject.[[DateValue]].
1317
+ let t: number = __Porffor_date_read(_this);
1318
+
1319
+ // 4. Let m be ? ToNumber(month).
1320
+ const m: number = Number(month);
1321
+
1322
+ // we reorder the spec steps in this func for easier arg handling
1323
+
1324
+ // 6. If t is NaN, return NaN.
1325
+ if (Number.isNaN(t)) return NaN;
1326
+
1327
+ // 7. Set t to LocalTime(t).
1328
+ t = __ecma262_LocalTime(t);
1329
+
1330
+ // 5. If date is present, let dt be ? ToNumber(date).
1331
+ let dt: number;
1332
+ if (Porffor.rawType(date) != Porffor.TYPES.undefined) dt = Number(date);
1333
+ // 8. If date is not present, let dt be DateFromTime(t).
1334
+ else dt = __ecma262_DateFromTime(t);
1335
+
1336
+ // 9. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), TimeWithinDay(t)).
1337
+ const newDate: number = __ecma262_MakeDate(__ecma262_MakeDay(__ecma262_YearFromTime(t), m, dt), __ecma262_TimeWithinDay(t));
1338
+
1339
+ // 10. Let u be TimeClip(UTC(newDate)).
1340
+ const u: number = __ecma262_TimeClip(__ecma262_UTC(newDate));
1341
+
1342
+ // 11. Set dateObject.[[DateValue]] to u.
1343
+ __Porffor_date_write(_this, u);
1344
+
1345
+ // 12. Return u.
1346
+ return u;
1347
+ };
1348
+
1349
+ // 21.4.4.26 Date.prototype.setSeconds (sec [, ms ])
1350
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setseconds
1351
+ export const __Date_prototype_setSeconds = (_this: Date, sec: any, ms: any) => {
1352
+ // 1. Let dateObject be the this value.
1353
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1354
+ // 3. Let t be dateObject.[[DateValue]].
1355
+ let t: number = __Porffor_date_read(_this);
1356
+
1357
+ // 4. Let s be ? ToNumber(sec).
1358
+ const s: number = Number(sec);
1359
+
1360
+ // we reorder the spec steps in this func for easier arg handling
1361
+
1362
+ // 6. If t is NaN, return NaN.
1363
+ if (Number.isNaN(t)) return NaN;
1364
+
1365
+ // 7. Set t to LocalTime(t).
1366
+ t = __ecma262_LocalTime(t);
1367
+
1368
+ // 5. If ms is present, let milli be ? ToNumber(ms).
1369
+ let milli: number;
1370
+ if (Porffor.rawType(ms) != Porffor.TYPES.undefined) milli = Number(ms);
1371
+ // 8. If ms is not present, let milli be msFromTime(t).
1372
+ else milli = __ecma262_msFromTime(t);
1373
+
1374
+ // 9. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, milli)).
1375
+ const date: number = __ecma262_MakeDate(__ecma262_Day(t), __ecma262_MakeTime(__ecma262_HourFromTime(t), __ecma262_MinFromTime(t), s, milli));
1376
+
1377
+ // 10. Let u be TimeClip(UTC(date)).
1378
+ const u: number = __ecma262_TimeClip(__ecma262_UTC(date));
1379
+
1380
+ // 11. Set dateObject.[[DateValue]] to u.
1381
+ __Porffor_date_write(_this, u);
1382
+
1383
+ // 12. Return u.
1384
+ return u;
1385
+ };
1386
+
1387
+
1388
+ // 21.4.4.27 Date.prototype.setTime (time)
1389
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.settime
1390
+ export const __Date_prototype_setTime = (_this: Date, time: any) => {
1391
+ // 1. Let dateObject be the this value.
1392
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1393
+ // 3. Let t be ? ToNumber(time).
1394
+ const t: number = Number(time);
1395
+
1396
+ // 4. Let v be TimeClip(t).
1397
+ const v: number = __ecma262_TimeClip(t);
1398
+
1399
+ // 5. Set dateObject.[[DateValue]] to v
1400
+ __Porffor_date_write(_this, v);
1401
+
1402
+ // 6. Return v.
1403
+ return v;
1404
+ };
1405
+
1406
+ // 21.4.4.28 Date.prototype.setUTCDate (date)
1407
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcdate
1408
+ export const __Date_prototype_setUTCDate = (_this: Date, date: any) => {
1409
+ // 1. Let dateObject be the this value.
1410
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1411
+ // 3. Let t be dateObject.[[DateValue]].
1412
+ const t: number = __Porffor_date_read(_this);
1413
+
1414
+ // 4. Let dt be ? ToNumber(date).
1415
+ const dt: number = Number(date);
1416
+
1417
+ // 5. If t is NaN, return NaN.
1418
+ if (Number.isNaN(t)) return NaN;
1419
+
1420
+ // 6. Let newDate be MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), TimeWithinDay(t)).
1421
+ const newDate: number = __ecma262_MakeDate(__ecma262_MakeDay(__ecma262_YearFromTime(t), __ecma262_MonthFromTime(t), dt), __ecma262_TimeWithinDay(t));
1422
+
1423
+ // 7. Let v be TimeClip(newDate).
1424
+ const v: number = __ecma262_TimeClip(newDate);
1425
+
1426
+ // 8. Set dateObject.[[DateValue]] to v.
1427
+ __Porffor_date_write(_this, v);
1428
+
1429
+ // 9. Return v.
1430
+ return v;
1431
+ };
1432
+
1433
+ // 21.4.4.29 Date.prototype.setUTCFullYear (year [, month [, date ]])
1434
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcfullyear
1435
+ export const __Date_prototype_setUTCFullYear = (_this: Date, year: any, month: any, date: any) => {
1436
+ // 1. Let dateObject be the this value.
1437
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1438
+ // 3. Let t be dateObject.[[DateValue]].
1439
+ let t: number = __Porffor_date_read(_this);
1440
+
1441
+ // 4. If t is NaN, set t to +0𝔽.
1442
+ if (Number.isNaN(t)) t = 0;
1443
+
1444
+ // 5. Let y be ? ToNumber(year).
1445
+ const y: number = Number(year);
1446
+
1447
+ // 6. If month is not present, let m be MonthFromTime(t); otherwise, let m be ? ToNumber(month).
1448
+ let m: number;
1449
+ if (Porffor.rawType(month) == Porffor.TYPES.undefined) m = __ecma262_MonthFromTime(t);
1450
+ else m = Number(month);
1451
+
1452
+ // 7. If date is not present, let dt be DateFromTime(t); otherwise, let dt be ? ToNumber(date).
1453
+ let dt: number;
1454
+ if (Porffor.rawType(date) == Porffor.TYPES.undefined) dt = __ecma262_DateFromTime(t);
1455
+ else dt = Number(date);
1456
+
1457
+ // 8. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)).
1458
+ const newDate: number = __ecma262_MakeDate(__ecma262_MakeDay(y, m, dt), __ecma262_TimeWithinDay(t));
1459
+
1460
+ // 9. Let v be TimeClip(newDate).
1461
+ const v: number = __ecma262_TimeClip(newDate);
1462
+
1463
+ // 10. Set dateObject.[[DateValue]] to v.
1464
+ __Porffor_date_write(_this, v);
1465
+
1466
+ // 11. Return v.
1467
+ return v;
1468
+ };
1469
+
1470
+ // 21.4.4.30 Date.prototype.setUTCHours (hour [, min [, sec [, ms ]]])
1471
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutchours
1472
+ export const __Date_prototype_setUTCHours = (_this: Date, hour: any, min: any, sec: any, ms: any) => {
1473
+ // 1. Let dateObject be the this value.
1474
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1475
+ // 3. Let t be dateObject.[[DateValue]].
1476
+ let t: number = __Porffor_date_read(_this);
1477
+
1478
+ // 4. Let h be ? ToNumber(hour).
1479
+ const h: number = Number(hour);
1480
+
1481
+ // we reorder the spec steps in this func for easier arg handling
1482
+
1483
+ // 8. If t is NaN, return NaN.
1484
+ if (Number.isNaN(t)) return NaN;
1485
+
1486
+ // 5. If min is present, let m be ? ToNumber(min).
1487
+ let m: number;
1488
+ if (Porffor.rawType(min) != Porffor.TYPES.undefined) m = Number(min);
1489
+ // 9. If min is not present, let m be MinFromTime(t).
1490
+ else m = __ecma262_MinFromTime(t);
1491
+
1492
+ // 6. If sec is present, let s be ? ToNumber(sec).
1493
+ let s: number;
1494
+ if (Porffor.rawType(sec) != Porffor.TYPES.undefined) s = Number(sec);
1495
+ // 10. If sec is not present, let s be SecFromTime(t).
1496
+ else s = __ecma262_SecFromTime(t);
1497
+
1498
+ // 7. If ms is present, let milli be ? ToNumber(ms).
1499
+ let milli: number;
1500
+ if (Porffor.rawType(ms) != Porffor.TYPES.undefined) milli = Number(ms);
1501
+ // 11. If ms is not present, let milli be msFromTime(t).
1502
+ else milli = __ecma262_msFromTime(t);
1503
+
1504
+ // 12. Let date be MakeDate(Day(t), MakeTime(h, m, s, milli)).
1505
+ const date: number = __ecma262_MakeDate(__ecma262_Day(t), __ecma262_MakeTime(h, m, s, milli));
1506
+
1507
+ // 13. Let v be TimeClip(date).
1508
+ const v: number = __ecma262_TimeClip(date);
1509
+
1510
+ // 14. Set dateObject.[[DateValue]] to v.
1511
+ __Porffor_date_write(_this, v);
1512
+
1513
+ // 15. Return v.
1514
+ return v;
1515
+ };
1516
+
1517
+ // 21.4.4.31 Date.prototype.setUTCMilliseconds (ms)
1518
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcmilliseconds
1519
+ export const __Date_prototype_setUTCMilliseconds = (_this: Date, ms: any) => {
1520
+ // 1. Let dateObject be the this value.
1521
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1522
+ // 3. Let t be dateObject.[[DateValue]].
1523
+ let t: number = __Porffor_date_read(_this);
1524
+
1525
+ // ignore old-style spec setting arg instead of having let
1526
+ // 4. Set ms to ? ToNumber(ms).
1527
+ const milli: number = Number(ms);
1528
+
1529
+ // 5. If t is NaN, return NaN.
1530
+ if (Number.isNaN(t)) return NaN;
1531
+
1532
+ // 6. Let time be MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms).
1533
+ const time: number = __ecma262_MakeTime(__ecma262_HourFromTime(t), __ecma262_MinFromTime(t), __ecma262_SecFromTime(t), milli);
1534
+
1535
+ // 7. Let v be TimeClip(MakeDate(Day(t), time)).
1536
+ const v: number = __ecma262_TimeClip(__ecma262_MakeDate(__ecma262_Day(t), time));
1537
+
1538
+ // 8. Set dateObject.[[DateValue]] to v.
1539
+ __Porffor_date_write(_this, v);
1540
+
1541
+ // 10. Return v.
1542
+ return v;
1543
+ };
1544
+
1545
+ // 21.4.4.32 Date.prototype.setUTCMinutes (min [, sec [, ms ]])
1546
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcminutes
1547
+ export const __Date_prototype_setUTCMinutes = (_this: Date, min: any, sec: any, ms: any) => {
1548
+ // 1. Let dateObject be the this value.
1549
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1550
+ // 3. Let t be dateObject.[[DateValue]].
1551
+ let t: number = __Porffor_date_read(_this);
1552
+
1553
+ // 4. Let m be ? ToNumber(min).
1554
+ const m: number = Number(min);
1555
+
1556
+ // we reorder the spec steps in this func for easier arg handling
1557
+
1558
+ // 7. If t is NaN, return NaN.
1559
+ if (Number.isNaN(t)) return NaN;
1560
+
1561
+ // 5. If sec is present, let s be ? ToNumber(sec).
1562
+ let s: number;
1563
+ if (Porffor.rawType(sec) != Porffor.TYPES.undefined) s = Number(sec);
1564
+ // 8. If sec is not present, let s be SecFromTime(t).
1565
+ else s = __ecma262_SecFromTime(t);
1566
+
1567
+ // 6. If ms is present, let milli be ? ToNumber(ms).
1568
+ let milli: number;
1569
+ if (Porffor.rawType(ms) != Porffor.TYPES.undefined) milli = Number(ms);
1570
+ // 9. If ms is not present, let milli be msFromTime(t).
1571
+ else milli = __ecma262_msFromTime(t);
1572
+
1573
+ // 10. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli)).
1574
+ const date: number = __ecma262_MakeDate(__ecma262_Day(t), __ecma262_MakeTime(__ecma262_HourFromTime(t), m, s, milli));
1575
+
1576
+ // 11. Let v be TimeClip(date).
1577
+ const v: number = __ecma262_TimeClip(date);
1578
+
1579
+ // 12. Set dateObject.[[DateValue]] to v.
1580
+ __Porffor_date_write(_this, v);
1581
+
1582
+ // 13. Return v.
1583
+ return v;
1584
+ };
1585
+
1586
+ // 21.4.4.33 Date.prototype.setUTCMonth (month [, date ])
1587
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcmonth
1588
+ export const __Date_prototype_setUTCMonth = (_this: Date, month: any, date: any) => {
1589
+ // 1. Let dateObject be the this value.
1590
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1591
+ // 3. Let t be dateObject.[[DateValue]].
1592
+ let t: number = __Porffor_date_read(_this);
1593
+
1594
+ // 4. Let m be ? ToNumber(month).
1595
+ const m: number = Number(month);
1596
+
1597
+ // we reorder the spec steps in this func for easier arg handling
1598
+
1599
+ // 6. If t is NaN, return NaN.
1600
+ if (Number.isNaN(t)) return NaN;
1601
+
1602
+ // 5. If date is present, let dt be ? ToNumber(date).
1603
+ let dt: number;
1604
+ if (Porffor.rawType(date) != Porffor.TYPES.undefined) dt = Number(date);
1605
+ // 7. If date is not present, let dt be DateFromTime(t).
1606
+ else dt = __ecma262_DateFromTime(t);
1607
+
1608
+ // 8. Let newDate be MakeDate(MakeDay(YearFromTime(t), m, dt), TimeWithinDay(t)).
1609
+ const newDate: number = __ecma262_MakeDate(__ecma262_MakeDay(__ecma262_YearFromTime(t), m, dt), __ecma262_TimeWithinDay(t));
1610
+
1611
+ // 9. Let v be TimeClip(newDate).
1612
+ const v: number = __ecma262_TimeClip(newDate);
1613
+
1614
+ // 10. Set dateObject.[[DateValue]] to v.
1615
+ __Porffor_date_write(_this, v);
1616
+
1617
+ // 11. Return v.
1618
+ return v;
1619
+ };
1620
+
1621
+ // 21.4.4.34 Date.prototype.setUTCSeconds (sec [, ms ])
1622
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setutcseconds
1623
+ export const __Date_prototype_setUTCSeconds = (_this: Date, sec: any, ms: any) => {
1624
+ // 1. Let dateObject be the this value.
1625
+ // 2. Perform ? RequireInternalSlot(dateObject, [[DateValue]]).
1626
+ // 3. Let t be dateObject.[[DateValue]].
1627
+ let t: number = __Porffor_date_read(_this);
1628
+
1629
+ // 4. Let s be ? ToNumber(sec).
1630
+ const s: number = Number(sec);
1631
+
1632
+ // we reorder the spec steps in this func for easier arg handling
1633
+
1634
+ // 6. If t is NaN, return NaN.
1635
+ if (Number.isNaN(t)) return NaN;
1636
+
1637
+ // 5. If ms is present, let milli be ? ToNumber(ms).
1638
+ let milli: number;
1639
+ if (Porffor.rawType(ms) != Porffor.TYPES.undefined) milli = Number(ms);
1640
+ // 7. If ms is not present, let milli be msFromTime(t).
1641
+ else milli = __ecma262_msFromTime(t);
1642
+
1643
+ // 8. Let date be MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, milli)).
1644
+ const date: number = __ecma262_MakeDate(__ecma262_Day(t), __ecma262_MakeTime(__ecma262_HourFromTime(t), __ecma262_MinFromTime(t), s, milli));
1645
+
1646
+ // 9. Let v be TimeClip(date).
1647
+ const v: number = __ecma262_TimeClip(date);
1648
+
1649
+ // 10. Set dateObject.[[DateValue]] to v.
1650
+ __Porffor_date_write(_this, v);
1651
+
1652
+ // 11. Return v.
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
+
2055
+ // 21.4.4.44 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
+
2064
+ // 21.4.2.1 Date (...values)
2065
+ // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date
2066
+ export const Date = (): bytestring => {
2067
+ // 1. If NewTarget is undefined, then
2068
+ // a. Let now be the time value (UTC) identifying the current time.
2069
+ // b. Return ToDateString(now).
2070
+ return __ecma262_ToDateString(__Date_now());
2071
+ };