porffor 0.55.17 → 0.55.19

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.
@@ -8,8 +8,7 @@ export const __Porffor_object_underlying = (obj: any): any => {
8
8
  t >= Porffor.TYPES.error,
9
9
  t <= Porffor.TYPES.todoerror
10
10
  )) {
11
- const remap: object = obj;
12
- return remap;
11
+ return obj as object;
13
12
  }
14
13
 
15
14
  if (Porffor.fastAnd(t > 0x05, t != Porffor.TYPES.undefined)) {
@@ -36,41 +35,38 @@ export const __Porffor_object_underlying = (obj: any): any => {
36
35
  }
37
36
 
38
37
  if (t == Porffor.TYPES.array) {
39
- const arr: any[] = obj;
40
- const len: i32 = arr.length;
38
+ const len: i32 = (obj as any[]).length;
41
39
 
42
40
  const key5: bytestring = 'length';
43
41
  __Porffor_object_expr_initWithFlags(underlying, key5, len, 0b1000);
44
42
 
45
43
  // todo: this should somehow be kept in sync?
46
44
  for (let i: i32 = 0; i < len; i++) {
47
- __Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i), arr[i], 0b1110);
45
+ __Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i), (obj as any[])[i], 0b1110);
48
46
  }
49
47
  }
50
48
 
51
49
  if (Porffor.fastOr(t == Porffor.TYPES.string, t == Porffor.TYPES.stringobject)) {
52
- const str: string = obj;
53
- const len: i32 = str.length;
50
+ const len: i32 = (obj as string).length;
54
51
 
55
52
  const key6: bytestring = 'length';
56
53
  __Porffor_object_expr_initWithFlags(underlying, key6, len, 0b0000);
57
54
 
58
55
  for (let i: i32 = 0; i < len; i++) {
59
- __Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i), str[i], 0b0100);
56
+ __Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i), (obj as string)[i], 0b0100);
60
57
  }
61
58
 
62
59
  if (t == Porffor.TYPES.string) Porffor.object.preventExtensions(underlying);
63
60
  }
64
61
 
65
62
  if (t == Porffor.TYPES.bytestring) {
66
- const str: bytestring = obj;
67
- const len: i32 = str.length;
63
+ const len: i32 = (obj as bytestring).length;
68
64
 
69
65
  const key7: bytestring = 'length';
70
66
  __Porffor_object_expr_initWithFlags(underlying, key7, len, 0b0000);
71
67
 
72
68
  for (let i: i32 = 0; i < len; i++) {
73
- __Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i), str[i], 0b0100);
69
+ __Porffor_object_expr_initWithFlags(underlying, __Number_prototype_toString(i), (obj as bytestring)[i], 0b0100);
74
70
  }
75
71
 
76
72
  Porffor.object.preventExtensions(underlying);
@@ -54,7 +54,6 @@ if 64
54
54
  v128.any_true
55
55
  if 64
56
56
  i32.const 0
57
- i32.const 2
58
57
  return
59
58
  end
60
59
 
@@ -87,7 +86,6 @@ if 64
87
86
  i64.ne
88
87
  if 64
89
88
  i32.const 0
90
- i32.const 2
91
89
  return
92
90
  end
93
91
 
@@ -120,7 +118,6 @@ if 64
120
118
  i32.ne
121
119
  if 64
122
120
  i32.const 0
123
- i32.const 2
124
121
  return
125
122
  end
126
123
 
@@ -200,7 +197,6 @@ if 64
200
197
  v128.any_true
201
198
  if 64
202
199
  i32.const 0
203
- i32.const 2
204
200
  return
205
201
  end
206
202
 
@@ -233,7 +229,6 @@ if 64
233
229
  i64.ne
234
230
  if 64
235
231
  i32.const 0
236
- i32.const 2
237
232
  return
238
233
  end
239
234
 
@@ -266,7 +261,6 @@ if 64
266
261
  i32.ne
267
262
  if 64
268
263
  i32.const 0
269
- i32.const 2
270
264
  return
271
265
  end
272
266
 
@@ -92,13 +92,11 @@ i64.shl
92
92
  local.get ${get}
93
93
  i64.extend_i32_u
94
94
  i64.or
95
-
96
95
  f64.reinterpret_i64
97
- i32.const 1
98
96
  return`;
99
97
  };
100
98
 
101
- export const __Porffor_object_accessorGet = (entryPtr: i32): Function => {
99
+ export const __Porffor_object_accessorGet = (entryPtr: i32): Function|undefined => {
102
100
  const out: Function = Porffor.wasm.i32.load(entryPtr, 0, 4);
103
101
 
104
102
  // no getter, return undefined
@@ -109,7 +107,7 @@ export const __Porffor_object_accessorGet = (entryPtr: i32): Function => {
109
107
  return out;
110
108
  };
111
109
 
112
- export const __Porffor_object_accessorSet = (entryPtr: i32): Function => {
110
+ export const __Porffor_object_accessorSet = (entryPtr: i32): Function|undefined => {
113
111
  const out: Function = Porffor.wasm.i32.load(entryPtr, 0, 8);
114
112
 
115
113
  // no setter, return undefined
@@ -137,7 +135,6 @@ export const __Porffor_object_lookup = (obj: any, target: any): i32 => {
137
135
 
138
136
  let out: boolean = false;
139
137
  if (targetType == Porffor.TYPES.symbol) {
140
- const targetSym: symbol = target;
141
138
  for (; ptr < endPtr; ptr += 14) {
142
139
  const keyRaw: i32 = Porffor.wasm.i32.load(ptr, 0, 0);
143
140
  if (keyRaw == 0) {
@@ -145,9 +142,9 @@ export const __Porffor_object_lookup = (obj: any, target: any): i32 => {
145
142
  out = true;
146
143
  }
147
144
 
148
- if (keyRaw >>> 30 == 3) { // MSB 1 and 2 set, symbol
149
- const keySym: symbol = keyRaw & 0x3FFFFFFF; // unset MSB
150
- if (keySym == targetSym) return ptr;
145
+ if (keyRaw >>> 30 == 3) { // MSB 1 and 2 set, symbol (unset MSB x2)
146
+ // todo: remove casts once weird bug which breaks unrelated things is fixed (https://github.com/CanadaHonk/porffor/commit/5747f0c1f3a4af95283ebef175cdacb21e332a52)
147
+ if ((keyRaw & 0x3FFFFFFF) as symbol == target as symbol) return ptr;
151
148
  }
152
149
  }
153
150
  } else {
@@ -161,12 +158,10 @@ export const __Porffor_object_lookup = (obj: any, target: any): i32 => {
161
158
  const msb: i32 = keyRaw >>> 30;
162
159
  if (msb == 0) {
163
160
  // bytestring
164
- const keyStr: bytestring = keyRaw;
165
- if (Porffor.strcmp(keyStr, target)) return ptr;
161
+ if (Porffor.strcmp(keyRaw as bytestring, target)) return ptr;
166
162
  } else if (msb == 2) {
167
- // string
168
- const keyStr: string = keyRaw & 0x7FFFFFFF; // unset MSB
169
- if (Porffor.strcmp(keyStr, target)) return ptr;
163
+ // string (unset MSB)
164
+ if (Porffor.strcmp((keyRaw & 0x7FFFFFFF) as string, target)) return ptr;
170
165
  }
171
166
  }
172
167
  }
@@ -497,8 +492,6 @@ local.get ${value}
497
492
  local.get ${value+1}
498
493
 
499
494
  call __Object_is
500
- drop
501
-
502
495
  i32.trunc_sat_f64_u
503
496
  i32.eqz
504
497
  local.set ${err}`;
@@ -35,7 +35,7 @@ export const __Porffor_compareStrings = (a: any, b: any): boolean => {
35
35
  return Porffor.strcmp(a, b);
36
36
  };
37
37
 
38
- export const __Porffor_concatStrings = (a: any, b: any): boolean => {
38
+ export const __Porffor_concatStrings = (a: any, b: any): any => {
39
39
  let at: i32 = Porffor.rawType(a);
40
40
  let bt: i32 = Porffor.rawType(b);
41
41
 
@@ -66,15 +66,13 @@ export const __Array_from = (arg: any, mapFn: any): any[] => {
66
66
  }
67
67
 
68
68
  if (type == Porffor.TYPES.object) {
69
- const obj: object = arg;
70
-
71
69
  const lengthKey: bytestring = 'length';
72
- len = ecma262.ToIntegerOrInfinity(obj[lengthKey]);
70
+ len = ecma262.ToIntegerOrInfinity((arg as object)[lengthKey]);
73
71
  if (len > 4294967295) throw new RangeError('Invalid array length');
74
72
  if (len < 0) len = 0;
75
73
 
76
74
  for (let i: i32 = 0; i < len; i++) {
77
- out[i] = obj[i];
75
+ out[i] = (arg as object)[i];
78
76
  }
79
77
  }
80
78
 
@@ -6,21 +6,42 @@ export const __Porffor_bigint_fromDigits = (negative: boolean, digits: i32[]): b
6
6
  if (len > 16383) throw new RangeError('Maximum BigInt size exceeded'); // (65536 - 4) / 4
7
7
 
8
8
  // const ptr: i32 = Porffor.allocate();
9
- const ptr: i32 = Porffor.wasm`local.get ${digits}`;
9
+ let ptr: i32 = Porffor.wasm`local.get ${digits}`;
10
10
 
11
11
  Porffor.wasm.i32.store8(ptr, negative ? 1 : 0, 0, 0);
12
12
  Porffor.wasm.i32.store16(ptr, len, 0, 2);
13
13
 
14
+ let allZero: boolean = true;
14
15
  for (let i: i32 = 0; i < len; i++) {
15
- Porffor.wasm.i32.store(ptr + i * 4, digits[i], 0, 4);
16
+ const d: i32 = digits[i];
17
+ if (d != 0) allZero = false;
18
+
19
+ Porffor.wasm.i32.store(ptr + i * 4, d, 0, 4);
16
20
  }
17
21
 
18
- const out: bigint = ptr;
19
- return out;
22
+ if (allZero) {
23
+ // todo: free ptr
24
+ ptr = 0;
25
+ }
26
+
27
+ return (ptr + 0x8000000000000) as bigint;
20
28
  };
21
29
 
30
+ // store small (abs(n) < 2^51 (0x8000000000000)) values inline (no allocation)
31
+ // like a ~s52 (s53 exc 2^51+(0-2^32) for u32 as pointer) inside a f64
32
+ export const __Porffor_bigint_inlineToDigitForm = (n: number): number => {
33
+ const ptr: i32 = Porffor.allocateBytes(4); // 4 meta + 1 digit
34
+ Porffor.wasm.i32.store8(ptr, n < 0, 0, 0);
35
+ Porffor.wasm.i32.store16(ptr, 1, 0, 2);
36
+ Porffor.wasm.i32.store(ptr, Math.abs(n), 0, 4);
37
+
38
+ return ptr;
39
+ };
40
+
41
+
22
42
  export const __Porffor_bigint_fromNumber = (n: number): bigint => {
23
- if (!Number.isInteger(n) || !Number.isFinite(n)) throw new RangeError('Cannot convert non-integer to BigInt');
43
+ if (!Number.isInteger(n) || !Number.isFinite(n)) throw new RangeError('Cannot use non-integer as BigInt');
44
+ if (Math.abs(n) < 0x8000000000000) return n as bigint;
24
45
 
25
46
  const negative: boolean = n < 0;
26
47
  n = Math.abs(n);
@@ -34,13 +55,16 @@ export const __Porffor_bigint_fromNumber = (n: number): bigint => {
34
55
  return __Porffor_bigint_fromDigits(negative, digits);
35
56
  };
36
57
 
37
- export const __Porffor_bigint_toNumber = (ptr: i32): number => {
38
- const negative: boolean = Porffor.wasm.i32.load8_u(ptr, 0, 0) != 0;
39
- const len: i32 = Porffor.wasm.i32.load16_u(ptr, 0, 2);
58
+ export const __Porffor_bigint_toNumber = (x: number): number => {
59
+ if (Math.abs(x) < 0x8000000000000) return x as number;
60
+ x -= 0x8000000000000;
61
+
62
+ const negative: boolean = Porffor.wasm.i32.load8_u(x, 0, 0) != 0;
63
+ const len: i32 = Porffor.wasm.i32.load16_u(x, 0, 2);
40
64
 
41
65
  let out: number = 0;
42
66
  for (let i: i32 = 0; i < len; i++) {
43
- const d: i32 = Porffor.wasm.i32.load(ptr + i * 4, 0, 4);
67
+ const d: i32 = Porffor.wasm.i32.load(x + i * 4, 0, 4);
44
68
  out = out * 0x100000000 + d;
45
69
  }
46
70
 
@@ -71,38 +95,61 @@ export const __Porffor_bigint_fromString = (n: string|bytestring): bigint => {
71
95
  // 9007199254740994 -> [ 2097152, 2 ]
72
96
  // 9007199254740995 -> [ 2097152, 3 ]
73
97
 
74
- const digits: i32[] = Porffor.allocate();
75
-
76
- const base = 0x100000000; // 2^32
98
+ let acc: number = 0;
99
+ let digits: i32[];
100
+ const BASE: i32 = 0x100000000; // 2^32
77
101
 
78
102
  for (let i: i32 = end; i < len; i++) {
79
103
  const char: i32 = n.charCodeAt(i);
80
104
  const digit: i32 = char - 48;
81
- if (digit < 0 || digit > 9) throw new SyntaxError('Invalid characters in BigInt string');
82
-
83
- // Multiply current digits by 10 and add the new digit
84
- let carry: i32 = digit;
85
- for (let j: i32 = 0; j < digits.length; j++) {
86
- const value: i32 = digits[j] * 10 + carry;
87
- digits[j] = value % base;
88
- carry = Math.trunc(value / base);
89
- }
105
+ if (digit < 0 || digit > 9) throw new SyntaxError('Invalid character in BigInt string');
106
+
107
+ if (acc == -1) {
108
+ let carry: i32 = digit;
109
+ for (let j: i32 = 0; j < digits.length; j++) {
110
+ const value: i32 = digits[j] * BASE + carry;
111
+ digits[j] = value % BASE;
112
+ carry = Math.trunc(value / BASE);
113
+ }
90
114
 
91
- // If there's a carry left, push it as a new digit
92
- if (carry > 0) {
93
- digits.push(carry);
115
+ if (carry > 0) digits.push(carry);
116
+ } else {
117
+ acc = acc * 10 + digit;
118
+ if (acc >= BASE) {
119
+ digits = Porffor.allocate();
120
+ digits.length = 2;
121
+ digits[0] = Math.floor(acc / BASE);
122
+ digits[1] = acc % BASE;
123
+ acc = -1;
124
+ }
94
125
  }
95
126
  }
96
127
 
97
- return __Porffor_bigint_fromDigits(negative, digits);
128
+ if (acc == -1) return __Porffor_bigint_fromDigits(negative, digits);
129
+ return (negative ? -acc : acc) as bigint;
98
130
  };
99
131
 
100
- export const __Porffor_bigint_toString = (ptr: i32, radix: number): string => {
101
- // todo
102
- // return '';
132
+ export const __Porffor_bigint_toString = (x: number, radix: any): string => {
133
+ // todo: actually use bigint
134
+ return __Number_prototype_toFixed(__Porffor_bigint_toNumber(x), radix);
103
135
  };
104
136
 
105
- export const __Porffor_bigint_add = (a: i32, b: i32, sub: boolean): bigint => {
137
+ // todo: hook up all funcs below to codegen
138
+ export const __Porffor_bigint_add = (a: number, b: number, sub: boolean): bigint => {
139
+ if (Math.abs(a) < 0x8000000000000) {
140
+ if (Math.abs(b) < 0x8000000000000) {
141
+ if (sub) b = -b;
142
+ return __Porffor_bigint_fromNumber(Math.trunc(a + b));
143
+ }
144
+
145
+ a = __Porffor_bigint_inlineToDigitForm(a);
146
+ } else if (Math.abs(b) < 0x8000000000000) {
147
+ b = __Porffor_bigint_inlineToDigitForm(b);
148
+ }
149
+
150
+ a -= 0x8000000000000;
151
+ b -= 0x8000000000000;
152
+
106
153
  const aNegative: boolean = Porffor.wasm.i32.load8_u(a, 0, 0) != 0;
107
154
  const aLen: i32 = Porffor.wasm.i32.load16_u(a, 0, 2);
108
155
 
@@ -191,22 +238,18 @@ export const __Porffor_bigint_sub = (a: i32, b: i32): bigint => {
191
238
 
192
239
  export const __Porffor_bigint_mul = (a: i32, b: i32): bigint => {
193
240
  // todo
194
- // return 0n;
195
241
  };
196
242
 
197
243
  export const __Porffor_bigint_div = (a: i32, b: i32): bigint => {
198
244
  // todo
199
- // return 0n;
200
245
  };
201
246
 
202
247
  export const __Porffor_bigint_rem = (a: i32, b: i32): bigint => {
203
248
  // todo
204
- // return 0n;
205
249
  };
206
250
 
207
251
  export const __Porffor_bigint_eq = (a: i32, b: i32): boolean => {
208
252
  // todo
209
- // return false;
210
253
  };
211
254
 
212
255
  export const __Porffor_bigint_ne = (a: i32, b: i32): boolean => {
@@ -215,12 +258,10 @@ export const __Porffor_bigint_ne = (a: i32, b: i32): boolean => {
215
258
 
216
259
  export const __Porffor_bigint_gt = (a: i32, b: i32): boolean => {
217
260
  // todo
218
- // return false;
219
261
  };
220
262
 
221
263
  export const __Porffor_bigint_ge = (a: i32, b: i32): boolean => {
222
264
  // todo
223
- // return false;
224
265
  };
225
266
 
226
267
  export const __Porffor_bigint_lt = (a: i32, b: i32): boolean => {
@@ -231,3 +272,58 @@ export const __Porffor_bigint_le = (a: i32, b: i32): boolean => {
231
272
  return !__Porffor_bigint_gt(a, b);
232
273
  };
233
274
 
275
+ // 7.1.13 ToBigInt (argument)
276
+ // https://tc39.es/ecma262/#sec-tobigint
277
+ export const __ecma262_ToBigInt = (argument: any): bigint => {
278
+ // 1. Let prim be ? ToPrimitive(argument, number).
279
+ const prim: any = ecma262.ToPrimitive.Number(argument);
280
+
281
+ // 2. Return the value that prim corresponds to in Table 12.
282
+ // Table 12: BigInt Conversions
283
+ // Argument Type Result
284
+ // BigInt Return prim.
285
+ if (Porffor.rawType(prim) == Porffor.TYPES.bigint) return prim;
286
+
287
+ // String
288
+ // 1. Let n be StringToBigInt(prim).
289
+ // 2. If n is undefined, throw a SyntaxError exception.
290
+ // 3. Return n.
291
+ if ((Porffor.rawType(prim) | 0b10000000) == Porffor.TYPES.bytestring) return __Porffor_bigint_fromString(prim);
292
+
293
+ // Boolean Return 1n if prim is true and 0n if prim is false.
294
+ if (Porffor.rawType(prim) == Porffor.TYPES.boolean) return prim ? 1n : 0n;
295
+
296
+ // Number Throw a TypeError exception.
297
+ // Symbol Throw a TypeError exception.
298
+ // Undefined Throw a TypeError exception.
299
+ // Null Throw a TypeError exception.
300
+ throw new TypeError('Cannot convert to BigInt');
301
+ };
302
+
303
+ // 21.2.1.1 BigInt (value)
304
+ // https://tc39.es/ecma262/#sec-bigint-constructor-number-value
305
+ export const BigInt = (value: any): bigint => {
306
+ // 1. If NewTarget is not undefined, throw a TypeError exception.
307
+ // 2. Let prim be ? ToPrimitive(value, number).
308
+ const prim: any = ecma262.ToPrimitive.Number(value);
309
+
310
+ // 3. If prim is a Number, return ? NumberToBigInt(prim).
311
+ if (Porffor.rawType(prim) == Porffor.TYPES.number) return __Porffor_bigint_fromNumber(prim);
312
+
313
+ // 4. Otherwise, return ? ToBigInt(prim).
314
+ return __ecma262_ToBigInt(prim);
315
+ };
316
+
317
+ export const __BigInt_prototype_toString = (_this: bigint, radix: any) => {
318
+ return __Porffor_bigint_toString(_this, radix);
319
+ };
320
+
321
+ export const __BigInt_prototype_toLocaleString = (_this: bigint) => {
322
+ return __Porffor_bigint_toString(_this, 10);
323
+ };
324
+
325
+ export const __BigInt_prototype_valueOf = (_this: bigint) => {
326
+ return _this;
327
+ };
328
+
329
+ // todo: asIntN, asUintN
@@ -9,8 +9,7 @@ export const Boolean = function (value: any): boolean|BooleanObject {
9
9
  // 2. If NewTarget is undefined, return b.
10
10
  if (!new.target) return b;
11
11
 
12
- const O: BooleanObject = b;
13
- return O;
12
+ return b as BooleanObject;
14
13
  };
15
14
 
16
15
  // 20.3.3.2 Boolean.prototype.toString ()
@@ -1,8 +1,7 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
3
  export const __Porffor_Generator = (values: any[]): __Porffor_Generator => {
4
- const gen: __Porffor_Generator = values;
5
- return gen;
4
+ return values as __Porffor_Generator;
6
5
  };
7
6
 
8
7
  export const __Porffor_Generator_yield = (vals: any[], value: any): void => {
@@ -16,11 +15,10 @@ export const __Porffor_Generator_return = (vals: any[], value: any): __Porffor_G
16
15
  vals.length = 1;
17
16
  vals[0] = value;
18
17
 
19
- const gen: __Porffor_Generator = vals;
20
- return gen;
18
+ return vals as __Porffor_Generator;
21
19
  };
22
20
 
23
- export const __Porffor_Generator_prototype_next = (vals: any[]): object => {
21
+ export const __Porffor_Generator_prototype_next = (vals: any[]) => {
24
22
  const obj: object = {};
25
23
  obj.value = vals.shift();
26
24
  obj.done = vals.length == 0;
@@ -28,22 +26,21 @@ export const __Porffor_Generator_prototype_next = (vals: any[]): object => {
28
26
  return obj;
29
27
  };
30
28
 
31
- export const __Porffor_Generator_prototype_return = (vals: any[], value: any): object => {
29
+ export const __Porffor_Generator_prototype_return = (vals: any[], value: any) => {
32
30
  vals.length = 1;
33
31
  vals[0] = value;
34
32
 
35
33
  return __Porffor_Generator_prototype_next(vals);
36
34
  };
37
35
 
38
- export const __Porffor_Generator_prototype_throw = (vals: any[], value: any): object => {
36
+ export const __Porffor_Generator_prototype_throw = (vals: any[], value: any) => {
39
37
  vals.length = 0;
40
38
  throw value;
41
39
  };
42
40
 
43
41
 
44
42
  export const __Porffor_AsyncGenerator = (values: any[]): __Porffor_AsyncGenerator => {
45
- const gen: __Porffor_AsyncGenerator = values;
46
- return gen;
43
+ return values as __Porffor_AsyncGenerator;
47
44
  };
48
45
 
49
46
  export const __Porffor_AsyncGenerator_yield = (vals: any[], value: any): void => {
@@ -57,11 +54,10 @@ export const __Porffor_AsyncGenerator_return = (vals: any[], value: any): __Porf
57
54
  vals.length = 1;
58
55
  vals[0] = value;
59
56
 
60
- const gen: __Porffor_AsyncGenerator = vals;
61
- return gen;
57
+ return vals as __Porffor_AsyncGenerator;
62
58
  };
63
59
 
64
- export const __Porffor_AsyncGenerator_prototype_next = async (vals: any[]): object => {
60
+ export const __Porffor_AsyncGenerator_prototype_next = async (vals: any[]) => {
65
61
  const obj: object = {};
66
62
  obj.value = await vals.shift();
67
63
  obj.done = vals.length == 0;
@@ -69,14 +65,14 @@ export const __Porffor_AsyncGenerator_prototype_next = async (vals: any[]): obje
69
65
  return obj;
70
66
  };
71
67
 
72
- export const __Porffor_AsyncGenerator_prototype_return = async (vals: any[], value: any): object => {
68
+ export const __Porffor_AsyncGenerator_prototype_return = async (vals: any[], value: any) => {
73
69
  vals.length = 1;
74
70
  vals[0] = await value;
75
71
 
76
72
  return await __Porffor_AsyncGenerator_prototype_next(vals);
77
73
  };
78
74
 
79
- export const __Porffor_AsyncGenerator_prototype_throw = async (vals: any[], value: any): object => {
75
+ export const __Porffor_AsyncGenerator_prototype_throw = async (vals: any[], value: any) => {
80
76
  vals.length = 0;
81
77
  throw await value;
82
78
  };
@@ -85,8 +85,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
85
85
  const hasSpace: boolean = space !== undefined;
86
86
  depth += 1;
87
87
 
88
- const arr: any[] = value;
89
- for (const x of arr) {
88
+ for (const x of (value as any[])) {
90
89
  if (hasSpace) {
91
90
  Porffor.bytestring.appendChar(out, 10); // \n
92
91
  for (let i: i32 = 0; i < depth; i++) Porffor.bytestring.appendStr(out, space);
@@ -124,13 +123,12 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
124
123
  const hasSpace: boolean = space !== undefined;
125
124
  depth += 1;
126
125
 
127
- const obj: object = value;
128
- for (const key in obj) {
126
+ for (const key in (value as object)) {
129
127
  // skip symbol keys
130
128
  if (Porffor.rawType(key) == Porffor.TYPES.symbol) continue;
131
129
 
132
130
  // skip non-serializable values (functions, etc)
133
- const val: bytestring|undefined = __Porffor_json_serialize(obj[key], depth, space);
131
+ const val: bytestring|undefined = __Porffor_json_serialize((value as object)[key], depth, space);
134
132
  if (val == null) continue;
135
133
 
136
134
  if (hasSpace) {
@@ -169,6 +167,11 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
169
167
  return out;
170
168
  }
171
169
 
170
+ if (t == 0x04) {
171
+ // bigint
172
+ throw new TypeError('Cannot serialize BigInts');
173
+ }
174
+
172
175
  return undefined;
173
176
  };
174
177
 
@@ -9,10 +9,15 @@ export const Number = function (value: any): number|NumberObject {
9
9
  // todo: handle undefined (NaN) and not present (0) args differently
10
10
  if (Porffor.rawType(value) != Porffor.TYPES.undefined) {
11
11
  // a. Let prim be ? ToNumeric(value).
12
+ n = ecma262.ToNumeric(value);
13
+
12
14
  // b. If prim is a BigInt, let n be 𝔽(ℝ(prim)).
13
- // todo: handle when bigints exist
15
+ if (Porffor.comptime.flag`hasType.bigint`) {
16
+ if (Porffor.rawType(n) == Porffor.TYPES.bigint)
17
+ n = Porffor.bigint.toNumber(n);
18
+ }
19
+
14
20
  // c. Otherwise, let n be prim.
15
- n = ecma262.ToNumeric(value);
16
21
  }
17
22
 
18
23
  // 2. Else,
@@ -25,8 +30,7 @@ export const Number = function (value: any): number|NumberObject {
25
30
  // 4. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Number.prototype%", « [[NumberData]] »).
26
31
  // 5. Set O.[[NumberData]] to n.
27
32
  // 6. Return O.
28
- const O: NumberObject = n;
29
- return O;
33
+ return n as NumberObject;
30
34
  };
31
35
 
32
36
  // radix: number|any for rawType check