porffor 0.56.4 โ 0.56.6
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/compiler/builtins/array.ts +18 -21
- package/compiler/builtins/arraybuffer.ts +4 -6
- package/compiler/builtins/bigint.ts +1 -1
- package/compiler/builtins/dataview.ts +2 -3
- package/compiler/builtins/date.ts +2 -5
- package/compiler/builtins/json.ts +7 -8
- package/compiler/builtins/object.ts +16 -23
- package/compiler/builtins/reflect.ts +1 -2
- package/compiler/builtins/typedarray.js +63 -31
- package/compiler/builtins/z_ecma262.ts +17 -21
- package/compiler/builtins.js +183 -0
- package/compiler/builtins_precompiled.js +1192 -601
- package/compiler/codegen.js +92 -9
- package/compiler/encoding.js +1 -1
- package/compiler/index.js +2 -2
- package/compiler/types.js +1 -1
- package/compiler/wasmSpec.js +7 -1
- package/compiler/wrap.js +3 -1
- package/package.json +1 -1
- package/r.cjs +0 -1
- package/runner/index.js +1 -1
@@ -39,14 +39,12 @@ export const __Array_from = (arg: any, mapFn: any): any[] => {
|
|
39
39
|
if (arg == null) throw new TypeError('Argument cannot be nullish');
|
40
40
|
|
41
41
|
let out: any[] = Porffor.allocate();
|
42
|
-
let len: i32 = 0;
|
43
42
|
|
44
|
-
const type = Porffor.type(arg);
|
45
43
|
if (Porffor.fastOr(
|
46
|
-
type == Porffor.TYPES.array,
|
47
|
-
type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
|
48
|
-
type == Porffor.TYPES.set,
|
49
|
-
Porffor.fastAnd(type >= Porffor.TYPES.uint8array, type <= Porffor.TYPES.
|
44
|
+
Porffor.type(arg) == Porffor.TYPES.array,
|
45
|
+
Porffor.type(arg) == Porffor.TYPES.string, Porffor.type(arg) == Porffor.TYPES.bytestring,
|
46
|
+
Porffor.type(arg) == Porffor.TYPES.set,
|
47
|
+
Porffor.fastAnd(Porffor.type(arg) >= Porffor.TYPES.uint8array, Porffor.type(arg) <= Porffor.TYPES.biguint64array)
|
50
48
|
)) {
|
51
49
|
let i: i32 = 0;
|
52
50
|
if (Porffor.type(mapFn) != Porffor.TYPES.undefined) {
|
@@ -62,20 +60,23 @@ export const __Array_from = (arg: any, mapFn: any): any[] => {
|
|
62
60
|
}
|
63
61
|
}
|
64
62
|
|
65
|
-
|
63
|
+
out.length = i;
|
64
|
+
return out;
|
66
65
|
}
|
67
66
|
|
68
|
-
if (type == Porffor.TYPES.object) {
|
69
|
-
len = ecma262.ToIntegerOrInfinity((arg as object)['length']);
|
67
|
+
if (Porffor.type(arg) == Porffor.TYPES.object) {
|
68
|
+
let len = ecma262.ToIntegerOrInfinity((arg as object)['length']);
|
70
69
|
if (len > 4294967295) throw new RangeError('Invalid array length');
|
71
70
|
if (len < 0) len = 0;
|
72
71
|
|
73
72
|
for (let i: i32 = 0; i < len; i++) {
|
74
73
|
out[i] = (arg as object)[i];
|
75
74
|
}
|
75
|
+
|
76
|
+
out.length = len;
|
77
|
+
return out;
|
76
78
|
}
|
77
79
|
|
78
|
-
out.length = len;
|
79
80
|
return out;
|
80
81
|
};
|
81
82
|
|
@@ -646,16 +647,14 @@ export const __Array_prototype_sort = (_this: any[], callbackFn: any) => {
|
|
646
647
|
|
647
648
|
// 23.1.3.30.2 CompareArrayElements (x, y, comparefn)
|
648
649
|
// https://tc39.es/ecma262/#sec-comparearrayelements
|
649
|
-
const xt: i32 = Porffor.type(x);
|
650
|
-
const yt: i32 = Porffor.type(y);
|
651
650
|
let v: number;
|
652
651
|
|
653
652
|
// 1. If x and y are both undefined, return +0๐ฝ.
|
654
|
-
if (
|
653
|
+
if (Porffor.type(x) == Porffor.TYPES.undefined && Porffor.type(y) == Porffor.TYPES.undefined) v = 0;
|
655
654
|
// 2. If x is undefined, return 1๐ฝ.
|
656
|
-
else if (
|
655
|
+
else if (Porffor.type(x) == Porffor.TYPES.undefined) v = 1;
|
657
656
|
// 3. If y is undefined, return -1๐ฝ.
|
658
|
-
else if (
|
657
|
+
else if (Porffor.type(y) == Porffor.TYPES.undefined) v = -1;
|
659
658
|
else {
|
660
659
|
// 4. If comparefn is not undefined, then
|
661
660
|
// a. Let v be ? ToNumber(? Call(comparefn, undefined, ยซ x, y ยป)).
|
@@ -690,10 +689,9 @@ export const __Array_prototype_toString = (_this: any[]) => {
|
|
690
689
|
if (i > 0) Porffor.bytestring.appendChar(out, 44);
|
691
690
|
|
692
691
|
const element: any = _this[i++];
|
693
|
-
const type: i32 = Porffor.type(element);
|
694
692
|
if (element != 0 || Porffor.fastAnd(
|
695
|
-
type != Porffor.TYPES.undefined, // undefined
|
696
|
-
type != Porffor.TYPES.object // null
|
693
|
+
Porffor.type(element) != Porffor.TYPES.undefined, // undefined
|
694
|
+
Porffor.type(element) != Porffor.TYPES.object // null
|
697
695
|
)) {
|
698
696
|
Porffor.bytestring.appendStr(out, ecma262.ToString(element));
|
699
697
|
}
|
@@ -722,10 +720,9 @@ export const __Array_prototype_join = (_this: any[], _separator: any) => {
|
|
722
720
|
if (i > 0) Porffor.bytestring.appendStr(out, separator);
|
723
721
|
|
724
722
|
const element: any = _this[i++];
|
725
|
-
const type: i32 = Porffor.type(element);
|
726
723
|
if (element != 0 || Porffor.fastAnd(
|
727
|
-
type != Porffor.TYPES.undefined, // undefined
|
728
|
-
type != Porffor.TYPES.object // null
|
724
|
+
Porffor.type(element) != Porffor.TYPES.undefined, // undefined
|
725
|
+
Porffor.type(element) != Porffor.TYPES.object // null
|
729
726
|
)) {
|
730
727
|
Porffor.bytestring.appendStr(out, ecma262.ToString(element));
|
731
728
|
}
|
@@ -1,12 +1,10 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
3
|
export const __ArrayBuffer_isView = (value: any): boolean => {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
)) return true;
|
9
|
-
return false;
|
4
|
+
return Porffor.fastOr(
|
5
|
+
Porffor.type(value) == Porffor.TYPES.dataview,
|
6
|
+
Porffor.fastAnd(Porffor.type(value) >= Porffor.TYPES.uint8array, Porffor.type(value) <= Porffor.TYPES.biguint64array)
|
7
|
+
);
|
10
8
|
};
|
11
9
|
|
12
10
|
export const __Porffor_arraybuffer_detach = (buffer: any): void => {
|
@@ -9,10 +9,9 @@ export const DataView = function (arg: any, byteOffset: any, length: any): DataV
|
|
9
9
|
let len: i32 = 0;
|
10
10
|
let bufferPtr: i32;
|
11
11
|
|
12
|
-
const type: i32 = Porffor.type(arg);
|
13
12
|
if (Porffor.fastOr(
|
14
|
-
type == Porffor.TYPES.arraybuffer,
|
15
|
-
type == Porffor.TYPES.sharedarraybuffer
|
13
|
+
Porffor.type(arg) == Porffor.TYPES.arraybuffer,
|
14
|
+
Porffor.type(arg) == Porffor.TYPES.sharedarraybuffer
|
16
15
|
)) {
|
17
16
|
bufferPtr = Porffor.wasm`local.get ${arg}`;
|
18
17
|
|
@@ -1925,19 +1925,16 @@ export const Date = function (v0: unknown, v1: unknown, v2: unknown, v3: unknown
|
|
1925
1925
|
// 4. Else if numberOfArgs = 1, the n
|
1926
1926
|
// a. Let value be values[0].
|
1927
1927
|
const value: any = v0;
|
1928
|
-
|
1929
|
-
const valueType: i32 = Porffor.type(v0);
|
1930
|
-
|
1931
1928
|
let tv: number = 0;
|
1932
1929
|
|
1933
1930
|
// b. If value is an Object and value has a [[DateValue]] internal slot, then
|
1934
|
-
if (
|
1931
|
+
if (Porffor.type(v0) == Porffor.TYPES.date) {
|
1935
1932
|
// i. Let tv be value.[[DateValue]].
|
1936
1933
|
tv = __Porffor_date_read(value);
|
1937
1934
|
} else {
|
1938
1935
|
// c. Else,
|
1939
1936
|
// ii. If v is a String, then
|
1940
|
-
if (Porffor.fastOr(
|
1937
|
+
if (Porffor.fastOr(Porffor.type(v0) == Porffor.TYPES.string, Porffor.type(v0) == Porffor.TYPES.bytestring)) {
|
1941
1938
|
// 1. Assert: The next step never returns an abrupt completion because v is a String.
|
1942
1939
|
|
1943
1940
|
// 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).
|
@@ -6,10 +6,9 @@ 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.type(value);
|
10
9
|
if (Porffor.fastOr(
|
11
|
-
(
|
12
|
-
|
10
|
+
(Porffor.type(value) | 0b10000000) == Porffor.TYPES.bytestring,
|
11
|
+
Porffor.type(value) == Porffor.TYPES.stringobject
|
13
12
|
)) { // string
|
14
13
|
const out: bytestring = Porffor.allocate();
|
15
14
|
Porffor.bytestring.appendChar(out, 34); // start "
|
@@ -71,14 +70,14 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
71
70
|
}
|
72
71
|
|
73
72
|
if (Porffor.fastOr(
|
74
|
-
|
75
|
-
|
73
|
+
Porffor.type(value) == Porffor.TYPES.number,
|
74
|
+
Porffor.type(value) == Porffor.TYPES.numberobject
|
76
75
|
)) { // number
|
77
76
|
if (Number.isFinite(value)) return __Number_prototype_toString(value, 10);
|
78
77
|
return 'null';
|
79
78
|
}
|
80
79
|
|
81
|
-
if (
|
80
|
+
if (Porffor.type(value) == Porffor.TYPES.array) {
|
82
81
|
const out: bytestring = Porffor.allocate();
|
83
82
|
Porffor.bytestring.appendChar(out, 91); // [
|
84
83
|
|
@@ -115,7 +114,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
115
114
|
return out;
|
116
115
|
}
|
117
116
|
|
118
|
-
if (
|
117
|
+
if (Porffor.type(value) > 0x06) {
|
119
118
|
// non-function object
|
120
119
|
const out: bytestring = Porffor.allocate();
|
121
120
|
Porffor.bytestring.appendChar(out, 123); // {
|
@@ -167,7 +166,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
|
|
167
166
|
return out;
|
168
167
|
}
|
169
168
|
|
170
|
-
if (
|
169
|
+
if (Porffor.type(value) == 0x04) {
|
171
170
|
// bigint
|
172
171
|
throw new TypeError('Cannot serialize BigInts');
|
173
172
|
}
|
@@ -20,8 +20,7 @@ export const __Object_keys = (obj: any): any[] => {
|
|
20
20
|
const out: any[] = Porffor.allocate();
|
21
21
|
|
22
22
|
obj = __Porffor_object_underlying(obj);
|
23
|
-
|
24
|
-
if (t == Porffor.TYPES.object) {
|
23
|
+
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
25
24
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
26
25
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
27
26
|
|
@@ -76,8 +75,7 @@ export const __Object_values = (obj: any): any[] => {
|
|
76
75
|
const out: any[] = Porffor.allocate();
|
77
76
|
|
78
77
|
obj = __Porffor_object_underlying(obj);
|
79
|
-
|
80
|
-
if (t == Porffor.TYPES.object) {
|
78
|
+
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
81
79
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
82
80
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
83
81
|
|
@@ -146,8 +144,7 @@ export const __Object_prototype_hasOwnProperty = (_this: any, prop: any) => {
|
|
146
144
|
if (_this == null) throw new TypeError('Argument is nullish, expected object');
|
147
145
|
const p: any = ecma262.ToPropertyKey(prop);
|
148
146
|
|
149
|
-
|
150
|
-
if (t == Porffor.TYPES.object) {
|
147
|
+
if (Porffor.type(_this) == Porffor.TYPES.object) {
|
151
148
|
return Porffor.object.lookup(_this, p, __Porffor_object_hash(p)) != -1;
|
152
149
|
}
|
153
150
|
|
@@ -414,8 +411,7 @@ export const __Object_getOwnPropertyNames = (obj: any): any[] => {
|
|
414
411
|
const out: any[] = Porffor.allocate();
|
415
412
|
|
416
413
|
obj = __Porffor_object_underlying(obj);
|
417
|
-
|
418
|
-
if (t == Porffor.TYPES.object) {
|
414
|
+
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
419
415
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
420
416
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
421
417
|
|
@@ -469,8 +465,7 @@ export const __Object_getOwnPropertySymbols = (obj: any): any[] => {
|
|
469
465
|
const out: any[] = Porffor.allocate();
|
470
466
|
|
471
467
|
obj = __Porffor_object_underlying(obj);
|
472
|
-
|
473
|
-
if (t == Porffor.TYPES.object) {
|
468
|
+
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
474
469
|
let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
|
475
470
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
|
476
471
|
|
@@ -686,22 +681,20 @@ export const __Object_prototype_toString = (_this: any) => {
|
|
686
681
|
if (_this === null) return '[object Null]';
|
687
682
|
|
688
683
|
// todo: toStringTag support
|
689
|
-
|
690
|
-
|
691
|
-
if (t == Porffor.TYPES.array) return '[object Array]';
|
692
|
-
if (t == Porffor.TYPES.function) return '[object Function]';
|
684
|
+
if (Porffor.type(_this) == Porffor.TYPES.array) return '[object Array]';
|
685
|
+
if (Porffor.type(_this) == Porffor.TYPES.function) return '[object Function]';
|
693
686
|
if (Porffor.fastOr(
|
694
|
-
|
695
|
-
|
687
|
+
Porffor.type(_this) == Porffor.TYPES.boolean,
|
688
|
+
Porffor.type(_this) == Porffor.TYPES.booleanobject)) return '[object Boolean]';
|
696
689
|
if (Porffor.fastOr(
|
697
|
-
|
698
|
-
|
690
|
+
Porffor.type(_this) == Porffor.TYPES.number,
|
691
|
+
Porffor.type(_this) == Porffor.TYPES.numberobject)) return '[object Number]';
|
699
692
|
if (Porffor.fastOr(
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
if (
|
704
|
-
if (
|
693
|
+
Porffor.type(_this) == Porffor.TYPES.string,
|
694
|
+
Porffor.type(_this) == Porffor.TYPES.bytestring,
|
695
|
+
Porffor.type(_this) == Porffor.TYPES.stringobject)) return '[object String]';
|
696
|
+
if (Porffor.type(_this) == Porffor.TYPES.date) return '[object Date]';
|
697
|
+
if (Porffor.type(_this) == Porffor.TYPES.regexp) return '[object RegExp]';
|
705
698
|
|
706
699
|
return '[object Object]';
|
707
700
|
};
|
@@ -89,8 +89,7 @@ export const __Reflect_ownKeys = (target: any) => {
|
|
89
89
|
const out: any[] = Porffor.allocate();
|
90
90
|
|
91
91
|
target = __Porffor_object_underlying(target);
|
92
|
-
|
93
|
-
if (t == Porffor.TYPES.object) {
|
92
|
+
if (Porffor.type(target) == Porffor.TYPES.object) {
|
94
93
|
let ptr: i32 = Porffor.wasm`local.get ${target}` + 8;
|
95
94
|
const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(target, 0, 0) * 18;
|
96
95
|
|
@@ -9,7 +9,9 @@ export default async () => {
|
|
9
9
|
// bufferPtr (i32) - buffer + byteOffset
|
10
10
|
// byteOffset (i32) - only used for getter
|
11
11
|
|
12
|
-
const
|
12
|
+
for (const x of [ 'Uint8', 'Int8', 'Uint8Clamped', 'Uint16', 'Int16', 'Uint32', 'Int32', 'Float32', 'Float64', 'BigInt64', 'BigUint64' ]) {
|
13
|
+
const name = x + 'Array';
|
14
|
+
out += `export const ${name} = function (arg: any, byteOffset: any, length: any): ${name} {
|
13
15
|
if (!new.target) throw new TypeError("Constructor ${name} requires 'new'");
|
14
16
|
|
15
17
|
const out: ${name} = Porffor.allocateBytes(12);
|
@@ -18,10 +20,9 @@ export default async () => {
|
|
18
20
|
let len: i32 = 0;
|
19
21
|
let bufferPtr: i32;
|
20
22
|
|
21
|
-
const type: i32 = Porffor.type(arg);
|
22
23
|
if (Porffor.fastOr(
|
23
|
-
type == Porffor.TYPES.arraybuffer,
|
24
|
-
type == Porffor.TYPES.sharedarraybuffer
|
24
|
+
Porffor.type(arg) == Porffor.TYPES.arraybuffer,
|
25
|
+
Porffor.type(arg) == Porffor.TYPES.sharedarraybuffer
|
25
26
|
)) {
|
26
27
|
bufferPtr = Porffor.wasm\`local.get \${arg}\`;
|
27
28
|
|
@@ -45,17 +46,17 @@ export default async () => {
|
|
45
46
|
Porffor.wasm.i32.store(outPtr, bufferPtr, 0, 4);
|
46
47
|
|
47
48
|
if (Porffor.fastOr(
|
48
|
-
type == Porffor.TYPES.array,
|
49
|
-
type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
|
50
|
-
type == Porffor.TYPES.set,
|
51
|
-
Porffor.fastAnd(type >= Porffor.TYPES.uint8array, type <= Porffor.TYPES.
|
49
|
+
Porffor.type(arg) == Porffor.TYPES.array,
|
50
|
+
Porffor.type(arg) == Porffor.TYPES.string, Porffor.type(arg) == Porffor.TYPES.bytestring,
|
51
|
+
Porffor.type(arg) == Porffor.TYPES.set,
|
52
|
+
Porffor.fastAnd(Porffor.type(arg) >= Porffor.TYPES.uint8array, Porffor.type(arg) <= Porffor.TYPES.biguint64array)
|
52
53
|
)) {
|
53
54
|
let i: i32 = 0;
|
54
55
|
for (const x of arg) {
|
55
56
|
out[i++] = x;
|
56
57
|
}
|
57
58
|
len = i;
|
58
|
-
} else if (type == Porffor.TYPES.number) {
|
59
|
+
} else if (Porffor.type(arg) == Porffor.TYPES.number) {
|
59
60
|
len = Math.trunc(arg);
|
60
61
|
}
|
61
62
|
|
@@ -75,17 +76,14 @@ export const __${name}_from = (arg: any, mapFn: any): ${name} => {
|
|
75
76
|
const arr: any[] = Porffor.allocate();
|
76
77
|
let len: i32 = 0;
|
77
78
|
|
78
|
-
const type = Porffor.type(arg);
|
79
79
|
if (Porffor.fastOr(
|
80
|
-
type == Porffor.TYPES.array,
|
81
|
-
type == Porffor.TYPES.string, type == Porffor.TYPES.bytestring,
|
82
|
-
type == Porffor.TYPES.set,
|
83
|
-
Porffor.fastAnd(type >= Porffor.TYPES.uint8array, type <= Porffor.TYPES.
|
80
|
+
Porffor.type(arg) == Porffor.TYPES.array,
|
81
|
+
Porffor.type(arg) == Porffor.TYPES.string, Porffor.type(arg) == Porffor.TYPES.bytestring,
|
82
|
+
Porffor.type(arg) == Porffor.TYPES.set,
|
83
|
+
Porffor.fastAnd(Porffor.type(arg) >= Porffor.TYPES.uint8array, Porffor.type(arg) <= Porffor.TYPES.biguint64array)
|
84
84
|
)) {
|
85
|
-
const hasMapFn = Porffor.type(mapFn) != Porffor.TYPES.undefined;
|
86
|
-
|
87
85
|
let i: i32 = 0;
|
88
|
-
if (
|
86
|
+
if (Porffor.type(mapFn) != Porffor.TYPES.undefined) {
|
89
87
|
if (Porffor.type(mapFn) != Porffor.TYPES.function) throw new TypeError('Called Array.from with a non-function mapFn');
|
90
88
|
|
91
89
|
for (const x of arg) {
|
@@ -132,8 +130,6 @@ export const __${name}_prototype_at = (_this: ${name}, index: number) => {
|
|
132
130
|
|
133
131
|
export const __${name}_prototype_slice = (_this: ${name}, start: number, end: number) => {
|
134
132
|
const len: i32 = _this.length;
|
135
|
-
if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
|
136
|
-
|
137
133
|
start |= 0;
|
138
134
|
end |= 0;
|
139
135
|
|
@@ -162,18 +158,54 @@ export const __${name}_prototype_slice = (_this: ${name}, start: number, end: nu
|
|
162
158
|
return out;
|
163
159
|
};
|
164
160
|
|
165
|
-
${
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
161
|
+
export const __${name}_prototype_set = (_this: ${name}, array: any, offset: number) => {
|
162
|
+
const len: i32 = _this.length;
|
163
|
+
|
164
|
+
offset |= 0;
|
165
|
+
if (Porffor.fastOr(offset < 0, offset > len)) throw new RangeError('Offset out of bounds');
|
166
|
+
|
167
|
+
if (Porffor.fastOr(
|
168
|
+
Porffor.type(array) == Porffor.TYPES.array,
|
169
|
+
Porffor.type(array) == Porffor.TYPES.string, Porffor.type(array) == Porffor.TYPES.bytestring,
|
170
|
+
Porffor.type(array) == Porffor.TYPES.set,
|
171
|
+
Porffor.fastAnd(Porffor.type(array) >= Porffor.TYPES.uint8array, Porffor.type(array) <= Porffor.TYPES.biguint64array)
|
172
|
+
)) {
|
173
|
+
let i: i32 = offset;
|
174
|
+
for (const x of array) {
|
175
|
+
_this[i++] = Porffor.type(x) == Porffor.TYPES.number ? x : 0;
|
176
|
+
if (i > len) throw new RangeError('Array is too long for given offset');
|
177
|
+
}
|
178
|
+
}
|
179
|
+
};
|
180
|
+
|
181
|
+
export const __${name}_prototype_subarray = (_this: ${name}, start: number, end: any) => {
|
182
|
+
const len: i32 = _this.length;
|
183
|
+
if (Porffor.type(end) == Porffor.TYPES.undefined) end = len;
|
184
|
+
|
185
|
+
start |= 0;
|
186
|
+
end |= 0;
|
187
|
+
|
188
|
+
if (start < 0) {
|
189
|
+
start = len + start;
|
190
|
+
if (start < 0) start = 0;
|
191
|
+
}
|
192
|
+
if (start > len) start = len;
|
193
|
+
if (end < 0) {
|
194
|
+
end = len + end;
|
195
|
+
if (end < 0) end = 0;
|
196
|
+
}
|
197
|
+
if (end > len) end = len;
|
198
|
+
|
199
|
+
const out: ${name} = Porffor.allocateBytes(12);
|
200
|
+
Porffor.wasm.i32.store(out, end - start, 0, 0);
|
201
|
+
Porffor.wasm.i32.store(out, Porffor.wasm.i32.load(_this, 0, 4) + start * ${name}.BYTES_PER_ELEMENT, 0, 4);
|
202
|
+
Porffor.wasm.i32.store(out, Porffor.wasm.i32.load(_this, 0, 8) + start * ${name}.BYTES_PER_ELEMENT, 0, 8);
|
203
|
+
|
204
|
+
return out;
|
205
|
+
};
|
206
|
+
|
207
|
+
${typedArrayFuncs.reduce((acc, x) => acc + x.replace('// @porf-typed-array\n', '').replaceAll('Array', name).replaceAll('any[]', name) + '\n\n', '')}`;
|
208
|
+
};
|
177
209
|
|
178
210
|
return out;
|
179
211
|
};
|
@@ -28,20 +28,18 @@ export const __ecma262_ToPrimitive_String = (input: any): any => {
|
|
28
28
|
// 7.1.4 ToNumber (argument)
|
29
29
|
// https://tc39.es/ecma262/#sec-tonumber
|
30
30
|
export const __ecma262_ToNumber = (argument: unknown): number => {
|
31
|
-
const t: i32 = Porffor.type(argument);
|
32
|
-
|
33
31
|
// 1. If argument is a Number, return argument.
|
34
|
-
if (
|
32
|
+
if (Porffor.type(argument) == Porffor.TYPES.number) return argument;
|
35
33
|
|
36
34
|
// 2. If argument is either a Symbol or a BigInt, throw a TypeError exception.
|
37
35
|
if (Porffor.fastOr(
|
38
|
-
|
39
|
-
|
36
|
+
Porffor.type(argument) == Porffor.TYPES.symbol,
|
37
|
+
Porffor.type(argument) == Porffor.TYPES.bigint)) throw new TypeError('Cannot convert Symbol or BigInt to a number');
|
40
38
|
|
41
39
|
// 3. If argument is undefined, return NaN.
|
42
40
|
if (Porffor.fastOr(
|
43
|
-
|
44
|
-
|
41
|
+
Porffor.type(argument) == Porffor.TYPES.undefined,
|
42
|
+
Porffor.type(argument) == Porffor.TYPES.empty)) return NaN;
|
45
43
|
|
46
44
|
// 4. If argument is either null or false, return +0๐ฝ.
|
47
45
|
if (Porffor.fastOr(
|
@@ -54,8 +52,8 @@ export const __ecma262_ToNumber = (argument: unknown): number => {
|
|
54
52
|
|
55
53
|
// 6. If argument is a String, return StringToNumber(argument).
|
56
54
|
if (Porffor.fastOr(
|
57
|
-
|
58
|
-
|
55
|
+
Porffor.type(argument) == Porffor.TYPES.string,
|
56
|
+
Porffor.type(argument) == Porffor.TYPES.bytestring)) return __ecma262_StringToNumber(argument);
|
59
57
|
|
60
58
|
// 7. Assert: argument is an Object.
|
61
59
|
// 8. Let primValue be ? ToPrimitive(argument, number).
|
@@ -124,27 +122,25 @@ export const __ecma262_ToIndex = (value: unknown): number => {
|
|
124
122
|
// 7.1.17 ToString (argument)
|
125
123
|
// https://tc39.es/ecma262/#sec-tostring
|
126
124
|
export const __ecma262_ToString = (argument: unknown): any => {
|
127
|
-
const type: i32 = Porffor.type(argument);
|
128
|
-
|
129
125
|
// 1. If argument is a String, return argument.
|
130
126
|
if (Porffor.fastOr(
|
131
|
-
type == Porffor.TYPES.string,
|
132
|
-
type == Porffor.TYPES.bytestring)) return argument;
|
127
|
+
Porffor.type(argument) == Porffor.TYPES.string,
|
128
|
+
Porffor.type(argument) == Porffor.TYPES.bytestring)) return argument;
|
133
129
|
|
134
130
|
// 2. If argument is a Symbol, throw a TypeError exception.
|
135
|
-
if (type == Porffor.TYPES.symbol) throw new TypeError('Cannot convert a Symbol value to a string');
|
131
|
+
if (Porffor.type(argument) == Porffor.TYPES.symbol) throw new TypeError('Cannot convert a Symbol value to a string');
|
136
132
|
|
137
133
|
// 3. If argument is undefined, return "undefined".
|
138
134
|
if (Porffor.fastOr(
|
139
|
-
type == Porffor.TYPES.undefined,
|
140
|
-
type == Porffor.TYPES.empty)) return 'undefined';
|
135
|
+
Porffor.type(argument) == Porffor.TYPES.undefined,
|
136
|
+
Porffor.type(argument) == Porffor.TYPES.empty)) return 'undefined';
|
141
137
|
|
142
138
|
// 4. If argument is null, return "null".
|
143
139
|
if (Porffor.fastAnd(
|
144
|
-
type == Porffor.TYPES.object,
|
140
|
+
Porffor.type(argument) == Porffor.TYPES.object,
|
145
141
|
argument == 0)) return 'null';
|
146
142
|
|
147
|
-
if (type == Porffor.TYPES.boolean) {
|
143
|
+
if (Porffor.type(argument) == Porffor.TYPES.boolean) {
|
148
144
|
// 5. If argument is true, return "true".
|
149
145
|
if (argument == true) return 'true';
|
150
146
|
|
@@ -153,15 +149,15 @@ export const __ecma262_ToString = (argument: unknown): any => {
|
|
153
149
|
}
|
154
150
|
|
155
151
|
// 7. If argument is a Number, return Number::toString(argument, 10).
|
156
|
-
if (type == Porffor.TYPES.number) return __Number_prototype_toString(argument, 10);
|
152
|
+
if (Porffor.type(argument) == Porffor.TYPES.number) return __Number_prototype_toString(argument, 10);
|
157
153
|
|
158
154
|
// 8. If argument is a BigInt, return BigInt::toString(argument, 10).
|
159
155
|
if (Porffor.comptime.flag`hasType.bigint`) {
|
160
|
-
if (type == Porffor.TYPES.bigint) return __Porffor_bigint_toString(argument, 10);
|
156
|
+
if (Porffor.type(argument) == Porffor.TYPES.bigint) return __Porffor_bigint_toString(argument, 10);
|
161
157
|
}
|
162
158
|
|
163
159
|
// hack: StringObject -> String
|
164
|
-
if (type == Porffor.TYPES.stringobject) {
|
160
|
+
if (Porffor.type(argument) == Porffor.TYPES.stringobject) {
|
165
161
|
return argument as string;
|
166
162
|
}
|
167
163
|
|