porffor 0.55.31 → 0.55.33
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.
- package/bun.lock +36 -0
- package/compiler/2c.js +3 -4
- package/compiler/builtins/_internal_object.ts +317 -237
- package/compiler/builtins/_internal_string.ts +4 -4
- package/compiler/builtins/annexb_string.js +12 -11
- package/compiler/builtins/array.ts +21 -22
- package/compiler/builtins/arraybuffer.ts +4 -4
- package/compiler/builtins/bigint.ts +4 -4
- package/compiler/builtins/console.ts +9 -9
- package/compiler/builtins/dataview.ts +3 -3
- package/compiler/builtins/date.ts +46 -52
- package/compiler/builtins/error.js +1 -1
- package/compiler/builtins/json.ts +6 -6
- package/compiler/builtins/math.ts +1 -1
- package/compiler/builtins/number.ts +9 -9
- package/compiler/builtins/object.ts +32 -32
- package/compiler/builtins/object_prototypeWithHidden.js +1 -1
- package/compiler/builtins/porffor.d.ts +4 -3
- package/compiler/builtins/promise.ts +6 -6
- package/compiler/builtins/reflect.ts +1 -1
- package/compiler/builtins/set.ts +7 -7
- package/compiler/builtins/string_f64.ts +2 -2
- package/compiler/builtins/symbol.ts +2 -2
- package/compiler/builtins/typedarray.js +7 -7
- package/compiler/builtins/z_ecma262.ts +7 -7
- package/compiler/builtins.js +5 -6
- package/compiler/builtins_objects.js +27 -5
- package/compiler/builtins_precompiled.js +519 -520
- package/compiler/codegen.js +29 -39
- package/compiler/index.js +2 -5
- package/compiler/precompile.js +4 -3
- package/package.json +2 -2
- package/r.cjs +2 -9
- package/runner/index.js +1 -1
- package/compiler/builtins/__internal_object.ts +0 -83
@@ -372,27 +372,27 @@ export const __Date_UTC = (year: unknown, month: unknown, date: unknown, hours:
|
|
372
372
|
|
373
373
|
// 2. If month is present, let m be ? ToNumber(month); else let m be +0𝔽.
|
374
374
|
let m: number = 0;
|
375
|
-
if (Porffor.
|
375
|
+
if (Porffor.type(month) != Porffor.TYPES.undefined) m = ecma262.ToNumber(month);
|
376
376
|
|
377
377
|
// 3. If date is present, let dt be ? ToNumber(date); else let dt be 1𝔽.
|
378
378
|
let dt: number = 1;
|
379
|
-
if (Porffor.
|
379
|
+
if (Porffor.type(date) != Porffor.TYPES.undefined) dt = ecma262.ToNumber(date);
|
380
380
|
|
381
381
|
// 4. If hours is present, let h be ? ToNumber(hours); else let h be +0𝔽.
|
382
382
|
let h: number = 0;
|
383
|
-
if (Porffor.
|
383
|
+
if (Porffor.type(hours) != Porffor.TYPES.undefined) h = ecma262.ToNumber(hours);
|
384
384
|
|
385
385
|
// 5. If minutes is present, let min be ? ToNumber(minutes); else let min be +0𝔽.
|
386
386
|
let min: number = 0;
|
387
|
-
if (Porffor.
|
387
|
+
if (Porffor.type(minutes) != Porffor.TYPES.undefined) min = ecma262.ToNumber(minutes);
|
388
388
|
|
389
389
|
// 6. If seconds is present, let s be ? ToNumber(seconds); else let s be +0𝔽.
|
390
390
|
let s: number = 0;
|
391
|
-
if (Porffor.
|
391
|
+
if (Porffor.type(seconds) != Porffor.TYPES.undefined) s = ecma262.ToNumber(seconds);
|
392
392
|
|
393
393
|
// 7. If ms is present, let milli be ? ToNumber(ms); else let milli be +0𝔽.
|
394
394
|
let milli: number = 0;
|
395
|
-
if (Porffor.
|
395
|
+
if (Porffor.type(ms) != Porffor.TYPES.undefined) h = ecma262.ToNumber(ms);
|
396
396
|
|
397
397
|
// 8. Let yr be MakeFullYear(y).
|
398
398
|
const yr: number = __ecma262_MakeFullYear(y);
|
@@ -413,10 +413,8 @@ export const __ecma262_WeekDayName = (tv: number): bytestring => {
|
|
413
413
|
// 4𝔽 "Thu"
|
414
414
|
// 5𝔽 "Fri"
|
415
415
|
// 6𝔽 "Sat"
|
416
|
-
|
417
|
-
const weekday: number = __ecma262_WeekDay(tv);
|
418
|
-
|
419
416
|
const lut: bytestring = 'SunMonTueWedThuFriSat';
|
417
|
+
const weekday: number = __ecma262_WeekDay(tv);
|
420
418
|
|
421
419
|
let out: bytestring = Porffor.allocateBytes(7);
|
422
420
|
out.length = 3;
|
@@ -447,10 +445,8 @@ export const __ecma262_MonthName = (tv: number): bytestring => {
|
|
447
445
|
// 9𝔽 "Oct"
|
448
446
|
// 10𝔽 "Nov"
|
449
447
|
// 11𝔽 "Dec"
|
450
|
-
|
451
|
-
const month: number = __ecma262_MonthFromTime(tv);
|
452
|
-
|
453
448
|
const lut: bytestring = 'JanFebMarAprMayJunJulAugSepOctNovDec';
|
449
|
+
const month: number = __ecma262_MonthFromTime(tv);
|
454
450
|
|
455
451
|
let out: bytestring = Porffor.allocateBytes(7);
|
456
452
|
out.length = 3;
|
@@ -1015,12 +1011,12 @@ export const __Date_prototype_setFullYear = (_this: Date, year: any, month: any,
|
|
1015
1011
|
|
1016
1012
|
// 6. If month is not present, let m be MonthFromTime(t); otherwise, let m be ? ToNumber(month).
|
1017
1013
|
let m: number;
|
1018
|
-
if (Porffor.
|
1014
|
+
if (Porffor.type(month) == Porffor.TYPES.undefined) m = __ecma262_MonthFromTime(t);
|
1019
1015
|
else m = ecma262.ToNumber(month);
|
1020
1016
|
|
1021
1017
|
// 7. If date is not present, let dt be DateFromTime(t); otherwise, let dt be ? ToNumber(date).
|
1022
1018
|
let dt: number;
|
1023
|
-
if (Porffor.
|
1019
|
+
if (Porffor.type(date) == Porffor.TYPES.undefined) dt = __ecma262_DateFromTime(t);
|
1024
1020
|
else dt = ecma262.ToNumber(date);
|
1025
1021
|
|
1026
1022
|
// 8. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)).
|
@@ -1057,19 +1053,19 @@ export const __Date_prototype_setHours = (_this: Date, hour: any, min: any, sec:
|
|
1057
1053
|
|
1058
1054
|
// 5. If min is present, let m be ? ToNumber(min).
|
1059
1055
|
let m: number;
|
1060
|
-
if (Porffor.
|
1056
|
+
if (Porffor.type(min) != Porffor.TYPES.undefined) m = ecma262.ToNumber(min);
|
1061
1057
|
// 10. If min is not present, let m be MinFromTime(t).
|
1062
1058
|
else m = __ecma262_MinFromTime(t);
|
1063
1059
|
|
1064
1060
|
// 6. If sec is present, let s be ? ToNumber(sec).
|
1065
1061
|
let s: number;
|
1066
|
-
if (Porffor.
|
1062
|
+
if (Porffor.type(sec) != Porffor.TYPES.undefined) s = ecma262.ToNumber(sec);
|
1067
1063
|
// 11. If sec is not present, let s be SecFromTime(t).
|
1068
1064
|
else s = __ecma262_SecFromTime(t);
|
1069
1065
|
|
1070
1066
|
// 7. If ms is present, let milli be ? ToNumber(ms).
|
1071
1067
|
let milli: number;
|
1072
|
-
if (Porffor.
|
1068
|
+
if (Porffor.type(ms) != Porffor.TYPES.undefined) milli = ecma262.ToNumber(ms);
|
1073
1069
|
// 12. If ms is not present, let milli be msFromTime(t).
|
1074
1070
|
else milli = __ecma262_msFromTime(t);
|
1075
1071
|
|
@@ -1138,13 +1134,13 @@ export const __Date_prototype_setMinutes = (_this: Date, min: any, sec: any, ms:
|
|
1138
1134
|
|
1139
1135
|
// 5. If sec is present, let s be ? ToNumber(sec).
|
1140
1136
|
let s: number;
|
1141
|
-
if (Porffor.
|
1137
|
+
if (Porffor.type(sec) != Porffor.TYPES.undefined) s = ecma262.ToNumber(sec);
|
1142
1138
|
// 9. If sec is not present, let s be SecFromTime(t).
|
1143
1139
|
else s = __ecma262_SecFromTime(t);
|
1144
1140
|
|
1145
1141
|
// 6. If ms is present, let milli be ? ToNumber(ms).
|
1146
1142
|
let milli: number;
|
1147
|
-
if (Porffor.
|
1143
|
+
if (Porffor.type(ms) != Porffor.TYPES.undefined) milli = ecma262.ToNumber(ms);
|
1148
1144
|
// 10. If ms is not present, let milli be msFromTime(t).
|
1149
1145
|
else milli = __ecma262_msFromTime(t);
|
1150
1146
|
|
@@ -1182,7 +1178,7 @@ export const __Date_prototype_setMonth = (_this: Date, month: any, date: any) =>
|
|
1182
1178
|
|
1183
1179
|
// 5. If date is present, let dt be ? ToNumber(date).
|
1184
1180
|
let dt: number;
|
1185
|
-
if (Porffor.
|
1181
|
+
if (Porffor.type(date) != Porffor.TYPES.undefined) dt = ecma262.ToNumber(date);
|
1186
1182
|
// 8. If date is not present, let dt be DateFromTime(t).
|
1187
1183
|
else dt = __ecma262_DateFromTime(t);
|
1188
1184
|
|
@@ -1220,7 +1216,7 @@ export const __Date_prototype_setSeconds = (_this: Date, sec: any, ms: any) => {
|
|
1220
1216
|
|
1221
1217
|
// 5. If ms is present, let milli be ? ToNumber(ms).
|
1222
1218
|
let milli: number;
|
1223
|
-
if (Porffor.
|
1219
|
+
if (Porffor.type(ms) != Porffor.TYPES.undefined) milli = ecma262.ToNumber(ms);
|
1224
1220
|
// 8. If ms is not present, let milli be msFromTime(t).
|
1225
1221
|
else milli = __ecma262_msFromTime(t);
|
1226
1222
|
|
@@ -1299,12 +1295,12 @@ export const __Date_prototype_setUTCFullYear = (_this: Date, year: any, month: a
|
|
1299
1295
|
|
1300
1296
|
// 6. If month is not present, let m be MonthFromTime(t); otherwise, let m be ? ToNumber(month).
|
1301
1297
|
let m: number;
|
1302
|
-
if (Porffor.
|
1298
|
+
if (Porffor.type(month) == Porffor.TYPES.undefined) m = __ecma262_MonthFromTime(t);
|
1303
1299
|
else m = ecma262.ToNumber(month);
|
1304
1300
|
|
1305
1301
|
// 7. If date is not present, let dt be DateFromTime(t); otherwise, let dt be ? ToNumber(date).
|
1306
1302
|
let dt: number;
|
1307
|
-
if (Porffor.
|
1303
|
+
if (Porffor.type(date) == Porffor.TYPES.undefined) dt = __ecma262_DateFromTime(t);
|
1308
1304
|
else dt = ecma262.ToNumber(date);
|
1309
1305
|
|
1310
1306
|
// 8. Let newDate be MakeDate(MakeDay(y, m, dt), TimeWithinDay(t)).
|
@@ -1338,19 +1334,19 @@ export const __Date_prototype_setUTCHours = (_this: Date, hour: any, min: any, s
|
|
1338
1334
|
|
1339
1335
|
// 5. If min is present, let m be ? ToNumber(min).
|
1340
1336
|
let m: number;
|
1341
|
-
if (Porffor.
|
1337
|
+
if (Porffor.type(min) != Porffor.TYPES.undefined) m = ecma262.ToNumber(min);
|
1342
1338
|
// 9. If min is not present, let m be MinFromTime(t).
|
1343
1339
|
else m = __ecma262_MinFromTime(t);
|
1344
1340
|
|
1345
1341
|
// 6. If sec is present, let s be ? ToNumber(sec).
|
1346
1342
|
let s: number;
|
1347
|
-
if (Porffor.
|
1343
|
+
if (Porffor.type(sec) != Porffor.TYPES.undefined) s = ecma262.ToNumber(sec);
|
1348
1344
|
// 10. If sec is not present, let s be SecFromTime(t).
|
1349
1345
|
else s = __ecma262_SecFromTime(t);
|
1350
1346
|
|
1351
1347
|
// 7. If ms is present, let milli be ? ToNumber(ms).
|
1352
1348
|
let milli: number;
|
1353
|
-
if (Porffor.
|
1349
|
+
if (Porffor.type(ms) != Porffor.TYPES.undefined) milli = ecma262.ToNumber(ms);
|
1354
1350
|
// 11. If ms is not present, let milli be msFromTime(t).
|
1355
1351
|
else milli = __ecma262_msFromTime(t);
|
1356
1352
|
|
@@ -1413,13 +1409,13 @@ export const __Date_prototype_setUTCMinutes = (_this: Date, min: any, sec: any,
|
|
1413
1409
|
|
1414
1410
|
// 5. If sec is present, let s be ? ToNumber(sec).
|
1415
1411
|
let s: number;
|
1416
|
-
if (Porffor.
|
1412
|
+
if (Porffor.type(sec) != Porffor.TYPES.undefined) s = ecma262.ToNumber(sec);
|
1417
1413
|
// 8. If sec is not present, let s be SecFromTime(t).
|
1418
1414
|
else s = __ecma262_SecFromTime(t);
|
1419
1415
|
|
1420
1416
|
// 6. If ms is present, let milli be ? ToNumber(ms).
|
1421
1417
|
let milli: number;
|
1422
|
-
if (Porffor.
|
1418
|
+
if (Porffor.type(ms) != Porffor.TYPES.undefined) milli = ecma262.ToNumber(ms);
|
1423
1419
|
// 9. If ms is not present, let milli be msFromTime(t).
|
1424
1420
|
else milli = __ecma262_msFromTime(t);
|
1425
1421
|
|
@@ -1454,7 +1450,7 @@ export const __Date_prototype_setUTCMonth = (_this: Date, month: any, date: any)
|
|
1454
1450
|
|
1455
1451
|
// 5. If date is present, let dt be ? ToNumber(date).
|
1456
1452
|
let dt: number;
|
1457
|
-
if (Porffor.
|
1453
|
+
if (Porffor.type(date) != Porffor.TYPES.undefined) dt = ecma262.ToNumber(date);
|
1458
1454
|
// 7. If date is not present, let dt be DateFromTime(t).
|
1459
1455
|
else dt = __ecma262_DateFromTime(t);
|
1460
1456
|
|
@@ -1489,7 +1485,7 @@ export const __Date_prototype_setUTCSeconds = (_this: Date, sec: any, ms: any) =
|
|
1489
1485
|
|
1490
1486
|
// 5. If ms is present, let milli be ? ToNumber(ms).
|
1491
1487
|
let milli: number;
|
1492
|
-
if (Porffor.
|
1488
|
+
if (Porffor.type(ms) != Porffor.TYPES.undefined) milli = ecma262.ToNumber(ms);
|
1493
1489
|
// 7. If ms is not present, let milli be msFromTime(t).
|
1494
1490
|
else milli = __ecma262_msFromTime(t);
|
1495
1491
|
|
@@ -1746,13 +1742,13 @@ export const __ecma262_TimeZoneString = (tv: number) => {
|
|
1746
1742
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-todatestring
|
1747
1743
|
export const __ecma262_ToDateString = (tv: number) => {
|
1748
1744
|
// 1. If tv is NaN, return "Invalid Date".
|
1749
|
-
|
1750
|
-
if (Number.isNaN(tv)) return out = 'Invalid Date';
|
1745
|
+
if (Number.isNaN(tv)) return 'Invalid Date';
|
1751
1746
|
|
1752
1747
|
// 2. Let t be LocalTime(tv).
|
1753
1748
|
const t: number = __ecma262_LocalTime(tv);
|
1754
1749
|
|
1755
1750
|
// 3. Return the string-concatenation of DateString(t), the code unit 0x0020 (SPACE), TimeString(t), and TimeZoneString(tv).
|
1751
|
+
const out: bytestring = Porffor.allocateBytes(44);
|
1756
1752
|
__Porffor_bytestring_appendStr(out, __ecma262_DateString(t));
|
1757
1753
|
__Porffor_bytestring_appendChar(out, 32);
|
1758
1754
|
|
@@ -1784,13 +1780,13 @@ export const __Date_prototype_toTimeString = (_this: Date) => {
|
|
1784
1780
|
const tv: number = __Porffor_date_read(_this);
|
1785
1781
|
|
1786
1782
|
// 4. If tv is NaN, return "Invalid Date".
|
1787
|
-
|
1788
|
-
if (Number.isNaN(tv)) return out = 'Invalid Date';
|
1783
|
+
if (Number.isNaN(tv)) return 'Invalid Date';
|
1789
1784
|
|
1790
1785
|
// 5. Let t be LocalTime(tv).
|
1791
1786
|
const t: number = __ecma262_LocalTime(tv);
|
1792
1787
|
|
1793
1788
|
// 6. Return the string-concatenation of TimeString(t) and TimeZoneString(tv).
|
1789
|
+
const out: bytestring = Porffor.allocateBytes(27);
|
1794
1790
|
__Porffor_bytestring_appendStr(out, __ecma262_TimeString(t));
|
1795
1791
|
__Porffor_bytestring_appendStr(out, __ecma262_TimeZoneString(tv));
|
1796
1792
|
|
@@ -1807,15 +1803,13 @@ export const __Date_prototype_toDateString = (_this: Date) => {
|
|
1807
1803
|
const tv: number = __Porffor_date_read(_this);
|
1808
1804
|
|
1809
1805
|
// 4. If tv is NaN, return "Invalid Date".
|
1810
|
-
|
1811
|
-
if (Number.isNaN(tv)) return out = 'Invalid Date';
|
1806
|
+
if (Number.isNaN(tv)) return 'Invalid Date';
|
1812
1807
|
|
1813
1808
|
// 5. Let t be LocalTime(tv).
|
1814
1809
|
const t: number = __ecma262_LocalTime(tv);
|
1815
1810
|
|
1816
1811
|
// 6. Return DateString(t).
|
1817
|
-
|
1818
|
-
return out;
|
1812
|
+
return __ecma262_DateString(t);
|
1819
1813
|
};
|
1820
1814
|
|
1821
1815
|
// 21.4.4.43 Date.prototype.toUTCString ()
|
@@ -1827,11 +1821,7 @@ export const __Date_prototype_toUTCString = (_this: Date) => {
|
|
1827
1821
|
const tv: number = __Porffor_date_read(_this);
|
1828
1822
|
|
1829
1823
|
// 4. If tv is NaN, return "Invalid Date".
|
1830
|
-
|
1831
|
-
if (Number.isNaN(tv)) {
|
1832
|
-
out = 'Invalid Date';
|
1833
|
-
return out;
|
1834
|
-
}
|
1824
|
+
if (Number.isNaN(tv)) return 'Invalid Date';
|
1835
1825
|
|
1836
1826
|
// 5. Let weekday be the Name of the entry in Table 62 with the Number WeekDay(tv).
|
1837
1827
|
const weekday: bytestring = __ecma262_WeekDayName(tv);
|
@@ -1847,7 +1837,11 @@ export const __Date_prototype_toUTCString = (_this: Date) => {
|
|
1847
1837
|
|
1848
1838
|
// 9. If yv is +0𝔽 or yv > +0𝔽, let yearSign be the empty String; otherwise, let yearSign be "-".
|
1849
1839
|
// 10. Let paddedYear be ToZeroPaddedDecimalString(abs(ℝ(yv)), 4).
|
1850
|
-
// 11. Return the string-concatenation of weekday, ",", the code unit 0x0020 (SPACE),
|
1840
|
+
// 11. Return the string-concatenation of weekday, ",", the code unit 0x0020 (SPACE),
|
1841
|
+
// day, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE),
|
1842
|
+
// yearSign, paddedYear, the code unit 0x0020 (SPACE), and TimeString(tv).
|
1843
|
+
const out: bytestring = Porffor.allocateBytes(34);
|
1844
|
+
|
1851
1845
|
// weekday
|
1852
1846
|
__Porffor_bytestring_appendStr(out, weekday);
|
1853
1847
|
__Porffor_bytestring_appendChar(out, 44); // ','
|
@@ -1913,13 +1907,13 @@ export const Date = function (v0: unknown, v1: unknown, v2: unknown, v3: unknown
|
|
1913
1907
|
// 2. Let numberOfArgs be the number of elements in values.
|
1914
1908
|
// sorry.
|
1915
1909
|
const numberOfArgs: i32 =
|
1916
|
-
(Porffor.
|
1917
|
-
(Porffor.
|
1918
|
-
(Porffor.
|
1919
|
-
(Porffor.
|
1920
|
-
(Porffor.
|
1921
|
-
(Porffor.
|
1922
|
-
(Porffor.
|
1910
|
+
(Porffor.type(v0) != Porffor.TYPES.undefined) +
|
1911
|
+
(Porffor.type(v1) != Porffor.TYPES.undefined) +
|
1912
|
+
(Porffor.type(v2) != Porffor.TYPES.undefined) +
|
1913
|
+
(Porffor.type(v3) != Porffor.TYPES.undefined) +
|
1914
|
+
(Porffor.type(v4) != Porffor.TYPES.undefined) +
|
1915
|
+
(Porffor.type(v5) != Porffor.TYPES.undefined) +
|
1916
|
+
(Porffor.type(v6) != Porffor.TYPES.undefined);
|
1923
1917
|
|
1924
1918
|
let dv: number = 0;
|
1925
1919
|
|
@@ -1932,7 +1926,7 @@ export const Date = function (v0: unknown, v1: unknown, v2: unknown, v3: unknown
|
|
1932
1926
|
// a. Let value be values[0].
|
1933
1927
|
const value: any = v0;
|
1934
1928
|
|
1935
|
-
const valueType: i32 = Porffor.
|
1929
|
+
const valueType: i32 = Porffor.type(v0);
|
1936
1930
|
|
1937
1931
|
let tv: number = 0;
|
1938
1932
|
|
@@ -43,7 +43,7 @@ export const __Test262Error_thrower = message => {
|
|
43
43
|
throw new Test262Error(message);
|
44
44
|
};
|
45
45
|
|
46
|
-
export const __Error_isError = (x: unknown): boolean => Porffor.fastOr(${errors.map(x => `Porffor.
|
46
|
+
export const __Error_isError = (x: unknown): boolean => Porffor.fastOr(${errors.map(x => `Porffor.type(x) == Porffor.TYPES.${x.toLowerCase()}`).join(', ')});`;
|
47
47
|
|
48
48
|
return out;
|
49
49
|
};
|
@@ -6,7 +6,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
6
6
|
if (value === true) return 'true';
|
7
7
|
if (value === false) return 'false';
|
8
8
|
|
9
|
-
const t: i32 = Porffor.
|
9
|
+
const t: i32 = Porffor.type(value);
|
10
10
|
if (Porffor.fastOr(
|
11
11
|
(t | 0b10000000) == Porffor.TYPES.bytestring,
|
12
12
|
t == Porffor.TYPES.stringobject
|
@@ -125,7 +125,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
125
125
|
|
126
126
|
for (const key in (value as object)) {
|
127
127
|
// skip symbol keys
|
128
|
-
if (Porffor.
|
128
|
+
if (Porffor.type(key) == Porffor.TYPES.symbol) continue;
|
129
129
|
|
130
130
|
// skip non-serializable values (functions, etc)
|
131
131
|
const val: bytestring|undefined = __Porffor_json_serialize((value as object)[key], depth, space);
|
@@ -180,8 +180,8 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
|
|
180
180
|
|
181
181
|
if (space !== undefined) {
|
182
182
|
if (Porffor.fastOr(
|
183
|
-
Porffor.
|
184
|
-
Porffor.
|
183
|
+
Porffor.type(space) == Porffor.TYPES.number,
|
184
|
+
Porffor.type(space) == Porffor.TYPES.numberobject
|
185
185
|
)) {
|
186
186
|
space = Math.min(Math.trunc(space), 10);
|
187
187
|
Porffor.print(space); Porffor.printStatic('\n');
|
@@ -195,8 +195,8 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
|
|
195
195
|
space = spaceStr;
|
196
196
|
}
|
197
197
|
} else if (Porffor.fastOr(
|
198
|
-
(Porffor.
|
199
|
-
Porffor.
|
198
|
+
(Porffor.type(space) | 0b10000000) == Porffor.TYPES.bytestring,
|
199
|
+
Porffor.type(space) == Porffor.TYPES.stringobject
|
200
200
|
)) {
|
201
201
|
// if empty, make it undefined
|
202
202
|
const len: i32 = space.length;
|
@@ -480,7 +480,7 @@ export const __Math_sumPrecise = (values: any[]): number => {
|
|
480
480
|
const large: Float64Array = new Float64Array(LARGE_SLOTS);
|
481
481
|
|
482
482
|
for (const _ of values) {
|
483
|
-
if (Porffor.
|
483
|
+
if (Porffor.type(_) != Porffor.TYPES.number) throw new TypeError('Math.sumPrecise must have only numbers in values');
|
484
484
|
|
485
485
|
const v: number = _;
|
486
486
|
if (v == 0) continue;
|
@@ -7,13 +7,13 @@ export const Number = function (value: any): number|NumberObject {
|
|
7
7
|
|
8
8
|
// 1. If value is present, then
|
9
9
|
// todo: handle undefined (NaN) and not present (0) args differently
|
10
|
-
if (Porffor.
|
10
|
+
if (Porffor.type(value) != Porffor.TYPES.undefined) {
|
11
11
|
// a. Let prim be ? ToNumeric(value).
|
12
12
|
n = ecma262.ToNumeric(value);
|
13
13
|
|
14
14
|
// b. If prim is a BigInt, let n be 𝔽(ℝ(prim)).
|
15
15
|
if (Porffor.comptime.flag`hasType.bigint`) {
|
16
|
-
if (Porffor.
|
16
|
+
if (Porffor.type(n) == Porffor.TYPES.bigint)
|
17
17
|
n = Porffor.bigint.toNumber(n);
|
18
18
|
}
|
19
19
|
|
@@ -33,9 +33,9 @@ export const Number = function (value: any): number|NumberObject {
|
|
33
33
|
return n as NumberObject;
|
34
34
|
};
|
35
35
|
|
36
|
-
// radix: number|any for
|
36
|
+
// radix: number|any for type check
|
37
37
|
export const __Number_prototype_toString = (_this: number, radix: number|any) => {
|
38
|
-
if (Porffor.
|
38
|
+
if (Porffor.type(radix) != Porffor.TYPES.number) {
|
39
39
|
// todo: string to number
|
40
40
|
radix = 10;
|
41
41
|
}
|
@@ -355,7 +355,7 @@ export const __Number_prototype_toFixed = (_this: number, fractionDigits: number
|
|
355
355
|
|
356
356
|
export const __Number_prototype_toLocaleString = (_this: number) => __Number_prototype_toString(_this, 10);
|
357
357
|
|
358
|
-
// fractionDigits: number|any for
|
358
|
+
// fractionDigits: number|any for type check
|
359
359
|
export const __Number_prototype_toExponential = (_this: number, fractionDigits: number|any) => {
|
360
360
|
if (!Number.isFinite(_this)) {
|
361
361
|
if (Number.isNaN(_this)) return 'NaN';
|
@@ -363,7 +363,7 @@ export const __Number_prototype_toExponential = (_this: number, fractionDigits:
|
|
363
363
|
return '-Infinity';
|
364
364
|
}
|
365
365
|
|
366
|
-
if (Porffor.
|
366
|
+
if (Porffor.type(fractionDigits) != Porffor.TYPES.number) {
|
367
367
|
// todo: string to number
|
368
368
|
fractionDigits = undefined;
|
369
369
|
} else {
|
@@ -404,7 +404,7 @@ export const __Number_prototype_toExponential = (_this: number, fractionDigits:
|
|
404
404
|
Porffor.wasm.i32.store8(outPtr++, 43, 0, 4); // +
|
405
405
|
} else if (_this < 1) {
|
406
406
|
// small exponential
|
407
|
-
if (Porffor.
|
407
|
+
if (Porffor.type(fractionDigits) != Porffor.TYPES.number) {
|
408
408
|
e = 1;
|
409
409
|
while (true) {
|
410
410
|
i *= 10;
|
@@ -461,7 +461,7 @@ export const __Number_prototype_toExponential = (_this: number, fractionDigits:
|
|
461
461
|
e++;
|
462
462
|
}
|
463
463
|
|
464
|
-
if (Porffor.
|
464
|
+
if (Porffor.type(fractionDigits) != Porffor.TYPES.number) {
|
465
465
|
while (true) {
|
466
466
|
i *= 10;
|
467
467
|
|
@@ -582,7 +582,7 @@ export const parseInt = (input: any, radix: any): f64 => {
|
|
582
582
|
|
583
583
|
let negative: boolean = false;
|
584
584
|
|
585
|
-
if (Porffor.
|
585
|
+
if (Porffor.type(input) == Porffor.TYPES.bytestring) {
|
586
586
|
const endPtr: i32 = i + len;
|
587
587
|
|
588
588
|
// check start of string
|