porffor 0.61.1 → 0.61.2

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.
Files changed (36) hide show
  1. package/compiler/builtins/_internal_object.ts +1 -1
  2. package/compiler/builtins/annexb_string.js +5 -4
  3. package/compiler/builtins/array.ts +16 -16
  4. package/compiler/builtins/arraybuffer.ts +4 -4
  5. package/compiler/builtins/base64.ts +2 -2
  6. package/compiler/builtins/bigint.ts +5 -5
  7. package/compiler/builtins/crypto.ts +1 -1
  8. package/compiler/builtins/dataview.ts +1 -1
  9. package/compiler/builtins/date.ts +9 -9
  10. package/compiler/builtins/error.js +1 -1
  11. package/compiler/builtins/function.ts +1 -1
  12. package/compiler/builtins/json.ts +5 -5
  13. package/compiler/builtins/map.ts +5 -5
  14. package/compiler/builtins/number.ts +3 -3
  15. package/compiler/builtins/object.ts +8 -8
  16. package/compiler/builtins/porffor.d.ts +2 -2
  17. package/compiler/builtins/promise.ts +9 -9
  18. package/compiler/builtins/reflect.ts +1 -1
  19. package/compiler/builtins/regexp.ts +319 -388
  20. package/compiler/builtins/set.ts +2 -2
  21. package/compiler/builtins/string.ts +42 -42
  22. package/compiler/builtins/string_f64.ts +2 -2
  23. package/compiler/builtins/symbol.ts +2 -2
  24. package/compiler/builtins/typedarray.js +5 -5
  25. package/compiler/builtins/uint8array_base64.ts +2 -2
  26. package/compiler/builtins/uri.ts +145 -145
  27. package/compiler/builtins/weakmap.ts +3 -3
  28. package/compiler/builtins/weakref.ts +1 -1
  29. package/compiler/builtins/weakset.ts +1 -1
  30. package/compiler/builtins.js +43 -75
  31. package/compiler/builtins_precompiled.js +682 -676
  32. package/compiler/codegen.js +16 -11
  33. package/compiler/wrap.js +13 -0
  34. package/jsr.json +1 -1
  35. package/package.json +1 -1
  36. package/runtime/index.js +1 -1
@@ -6,18 +6,18 @@ export const escape = (input: any): bytestring => {
6
6
  input = __ecma262_ToString(input);
7
7
  const len: i32 = input.length;
8
8
  let outLength: i32 = 0;
9
-
9
+
10
10
  let i: i32 = Porffor.wasm`local.get ${input}`;
11
-
11
+
12
12
  // Check if input is bytestring or string
13
13
  if (Porffor.wasm`local.get ${input+1}` == Porffor.TYPES.bytestring) {
14
14
  // Handle bytestring input
15
15
  const endPtr: i32 = i + len;
16
-
16
+
17
17
  // First pass: calculate output length
18
18
  while (i < endPtr) {
19
19
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
20
-
20
+
21
21
  // Characters that should NOT be escaped: A-Z a-z 0-9 @ * + - . / _
22
22
  if ((chr >= 48 && chr <= 57) || // 0-9
23
23
  (chr >= 65 && chr <= 90) || // A-Z
@@ -28,17 +28,17 @@ export const escape = (input: any): bytestring => {
28
28
  outLength += 3; // %XX
29
29
  }
30
30
  }
31
-
31
+
32
32
  // Second pass: encode
33
- let output: bytestring = Porffor.allocate();
33
+ let output: bytestring = Porffor.malloc();
34
34
  output.length = outLength;
35
-
35
+
36
36
  i = Porffor.wasm`local.get ${input}`;
37
37
  let j: i32 = Porffor.wasm`local.get ${output}`;
38
-
38
+
39
39
  while (i < endPtr) {
40
40
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
41
-
41
+
42
42
  if ((chr >= 48 && chr <= 57) || // 0-9
43
43
  (chr >= 65 && chr <= 90) || // A-Z
44
44
  (chr >= 97 && chr <= 122) || // a-z
@@ -46,14 +46,14 @@ export const escape = (input: any): bytestring => {
46
46
  Porffor.wasm.i32.store8(j++, chr, 0, 4);
47
47
  } else {
48
48
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
49
-
49
+
50
50
  let nibble: i32 = chr >> 4;
51
51
  if (nibble < 10) {
52
52
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
53
53
  } else {
54
54
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
55
55
  }
56
-
56
+
57
57
  nibble = chr & 0x0F;
58
58
  if (nibble < 10) {
59
59
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
@@ -62,18 +62,18 @@ export const escape = (input: any): bytestring => {
62
62
  }
63
63
  }
64
64
  }
65
-
65
+
66
66
  return output;
67
67
  }
68
-
68
+
69
69
  // Handle string input (16-bit characters)
70
70
  const endPtr: i32 = i + len * 2;
71
-
71
+
72
72
  // First pass: calculate output length
73
73
  while (i < endPtr) {
74
74
  const chr: i32 = Porffor.wasm.i32.load16_u(i, 0, 4);
75
75
  i += 2;
76
-
76
+
77
77
  // Characters that should NOT be escaped: A-Z a-z 0-9 @ * + - . / _
78
78
  if ((chr >= 48 && chr <= 57) || // 0-9
79
79
  (chr >= 65 && chr <= 90) || // A-Z
@@ -86,18 +86,18 @@ export const escape = (input: any): bytestring => {
86
86
  outLength += 6; // %uXXXX
87
87
  }
88
88
  }
89
-
89
+
90
90
  // Second pass: encode
91
- let output: bytestring = Porffor.allocate();
91
+ let output: bytestring = Porffor.malloc();
92
92
  output.length = outLength;
93
-
93
+
94
94
  i = Porffor.wasm`local.get ${input}`;
95
95
  let j: i32 = Porffor.wasm`local.get ${output}`;
96
-
96
+
97
97
  while (i < endPtr) {
98
98
  const chr: i32 = Porffor.wasm.i32.load16_u(i, 0, 4);
99
99
  i += 2;
100
-
100
+
101
101
  if ((chr >= 48 && chr <= 57) || // 0-9
102
102
  (chr >= 65 && chr <= 90) || // A-Z
103
103
  (chr >= 97 && chr <= 122) || // a-z
@@ -105,14 +105,14 @@ export const escape = (input: any): bytestring => {
105
105
  Porffor.wasm.i32.store8(j++, chr, 0, 4);
106
106
  } else if (chr < 256) {
107
107
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
108
-
108
+
109
109
  let nibble: i32 = chr >> 4;
110
110
  if (nibble < 10) {
111
111
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
112
112
  } else {
113
113
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
114
114
  }
115
-
115
+
116
116
  nibble = chr & 0x0F;
117
117
  if (nibble < 10) {
118
118
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
@@ -123,28 +123,28 @@ export const escape = (input: any): bytestring => {
123
123
  // %uXXXX
124
124
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
125
125
  Porffor.wasm.i32.store8(j++, 117, 0, 4); // u
126
-
126
+
127
127
  let nibble: i32 = (chr >> 12) & 0x0F;
128
128
  if (nibble < 10) {
129
129
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
130
130
  } else {
131
131
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
132
132
  }
133
-
133
+
134
134
  nibble = (chr >> 8) & 0x0F;
135
135
  if (nibble < 10) {
136
136
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
137
137
  } else {
138
138
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
139
139
  }
140
-
140
+
141
141
  nibble = (chr >> 4) & 0x0F;
142
142
  if (nibble < 10) {
143
143
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
144
144
  } else {
145
145
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
146
146
  }
147
-
147
+
148
148
  nibble = chr & 0x0F;
149
149
  if (nibble < 10) {
150
150
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
@@ -153,7 +153,7 @@ export const escape = (input: any): bytestring => {
153
153
  }
154
154
  }
155
155
  }
156
-
156
+
157
157
  return output;
158
158
  };
159
159
 
@@ -162,11 +162,11 @@ export const unescape = (input: any): string => {
162
162
  input = __ecma262_ToString(input);
163
163
  const len: i32 = input.length;
164
164
  let outLength: i32 = 0;
165
-
165
+
166
166
  // First pass: calculate output length
167
167
  let i: i32 = Porffor.wasm`local.get ${input}`;
168
168
  const endPtr: i32 = i + len;
169
-
169
+
170
170
  while (i < endPtr) {
171
171
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
172
172
  if (chr == 37) { // %
@@ -178,17 +178,17 @@ export const unescape = (input: any): string => {
178
178
  }
179
179
  outLength += 1;
180
180
  }
181
-
181
+
182
182
  // Second pass: decode
183
- let output: string = Porffor.allocate();
183
+ let output: string = Porffor.malloc();
184
184
  output.length = outLength;
185
-
185
+
186
186
  i = Porffor.wasm`local.get ${input}`;
187
187
  let j: i32 = Porffor.wasm`local.get ${output}`;
188
-
188
+
189
189
  while (i < endPtr) {
190
190
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
191
-
191
+
192
192
  if (chr == 37) { // %
193
193
  if (i + 4 < endPtr && Porffor.wasm.i32.load8_u(i, 0, 4) == 117) { // u
194
194
  // %uXXXX
@@ -196,31 +196,31 @@ export const unescape = (input: any): string => {
196
196
  const d2: i32 = Porffor.wasm.i32.load8_u(i + 2, 0, 4);
197
197
  const d3: i32 = Porffor.wasm.i32.load8_u(i + 3, 0, 4);
198
198
  const d4: i32 = Porffor.wasm.i32.load8_u(i + 4, 0, 4);
199
-
199
+
200
200
  let n1: i32 = d1 - 48;
201
201
  if (n1 > 9) {
202
202
  n1 = d1 - 55;
203
203
  if (n1 > 15) n1 = d1 - 87;
204
204
  }
205
-
205
+
206
206
  let n2: i32 = d2 - 48;
207
207
  if (n2 > 9) {
208
208
  n2 = d2 - 55;
209
209
  if (n2 > 15) n2 = d2 - 87;
210
210
  }
211
-
211
+
212
212
  let n3: i32 = d3 - 48;
213
213
  if (n3 > 9) {
214
214
  n3 = d3 - 55;
215
215
  if (n3 > 15) n3 = d3 - 87;
216
216
  }
217
-
217
+
218
218
  let n4: i32 = d4 - 48;
219
219
  if (n4 > 9) {
220
220
  n4 = d4 - 55;
221
221
  if (n4 > 15) n4 = d4 - 87;
222
222
  }
223
-
223
+
224
224
  if (n1 >= 0 && n1 <= 15 && n2 >= 0 && n2 <= 15 && n3 >= 0 && n3 <= 15 && n4 >= 0 && n4 <= 15) {
225
225
  i += 5;
226
226
  const value: i32 = (n1 << 12) | (n2 << 8) | (n3 << 4) | n4;
@@ -232,19 +232,19 @@ export const unescape = (input: any): string => {
232
232
  // %XX
233
233
  const d1: i32 = Porffor.wasm.i32.load8_u(i, 0, 4);
234
234
  const d2: i32 = Porffor.wasm.i32.load8_u(i + 1, 0, 4);
235
-
235
+
236
236
  let n1: i32 = d1 - 48;
237
237
  if (n1 > 9) {
238
238
  n1 = d1 - 55;
239
239
  if (n1 > 15) n1 = d1 - 87;
240
240
  }
241
-
241
+
242
242
  let n2: i32 = d2 - 48;
243
243
  if (n2 > 9) {
244
244
  n2 = d2 - 55;
245
245
  if (n2 > 15) n2 = d2 - 87;
246
246
  }
247
-
247
+
248
248
  if (n1 >= 0 && n1 <= 15 && n2 >= 0 && n2 <= 15) {
249
249
  i += 2;
250
250
  const value: i32 = (n1 << 4) | n2;
@@ -258,10 +258,10 @@ export const unescape = (input: any): string => {
258
258
  } else {
259
259
  Porffor.wasm.i32.store16(j, chr, 0, 4);
260
260
  }
261
-
261
+
262
262
  j += 2;
263
263
  }
264
-
264
+
265
265
  return output;
266
266
  };
267
267
 
@@ -270,62 +270,62 @@ export const encodeURI = (input: any): bytestring => {
270
270
  input = __ecma262_ToString(input);
271
271
  const len: i32 = input.length;
272
272
  let outLength: i32 = 0;
273
-
273
+
274
274
  let i: i32 = Porffor.wasm`local.get ${input}`;
275
-
275
+
276
276
  // Check if input is bytestring or string
277
277
  if (Porffor.wasm`local.get ${input+1}` == Porffor.TYPES.bytestring) {
278
278
  // Handle bytestring input
279
279
  const endPtr: i32 = i + len;
280
-
280
+
281
281
  // First pass: calculate output length
282
282
  while (i < endPtr) {
283
283
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
284
-
284
+
285
285
  // Characters that should NOT be encoded for encodeURI
286
286
  if ((chr >= 48 && chr <= 57) || // 0-9
287
287
  (chr >= 65 && chr <= 90) || // A-Z
288
288
  (chr >= 97 && chr <= 122) || // a-z
289
- chr == 33 || chr == 35 || chr == 36 || chr == 38 || chr == 39 ||
290
- chr == 40 || chr == 41 || chr == 42 || chr == 43 || chr == 44 ||
291
- chr == 45 || chr == 46 || chr == 47 || chr == 58 || chr == 59 ||
292
- chr == 61 || chr == 63 || chr == 64 || chr == 91 || chr == 93 ||
289
+ chr == 33 || chr == 35 || chr == 36 || chr == 38 || chr == 39 ||
290
+ chr == 40 || chr == 41 || chr == 42 || chr == 43 || chr == 44 ||
291
+ chr == 45 || chr == 46 || chr == 47 || chr == 58 || chr == 59 ||
292
+ chr == 61 || chr == 63 || chr == 64 || chr == 91 || chr == 93 ||
293
293
  chr == 95 || chr == 126) {
294
294
  outLength += 1;
295
295
  } else {
296
296
  outLength += 3; // %XX
297
297
  }
298
298
  }
299
-
299
+
300
300
  // Second pass: encode
301
- let output: bytestring = Porffor.allocate();
301
+ let output: bytestring = Porffor.malloc();
302
302
  output.length = outLength;
303
-
303
+
304
304
  i = Porffor.wasm`local.get ${input}`;
305
305
  let j: i32 = Porffor.wasm`local.get ${output}`;
306
-
306
+
307
307
  while (i < endPtr) {
308
308
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
309
-
309
+
310
310
  if ((chr >= 48 && chr <= 57) || // 0-9
311
311
  (chr >= 65 && chr <= 90) || // A-Z
312
312
  (chr >= 97 && chr <= 122) || // a-z
313
- chr == 33 || chr == 35 || chr == 36 || chr == 38 || chr == 39 ||
314
- chr == 40 || chr == 41 || chr == 42 || chr == 43 || chr == 44 ||
315
- chr == 45 || chr == 46 || chr == 47 || chr == 58 || chr == 59 ||
316
- chr == 61 || chr == 63 || chr == 64 || chr == 91 || chr == 93 ||
313
+ chr == 33 || chr == 35 || chr == 36 || chr == 38 || chr == 39 ||
314
+ chr == 40 || chr == 41 || chr == 42 || chr == 43 || chr == 44 ||
315
+ chr == 45 || chr == 46 || chr == 47 || chr == 58 || chr == 59 ||
316
+ chr == 61 || chr == 63 || chr == 64 || chr == 91 || chr == 93 ||
317
317
  chr == 95 || chr == 126) {
318
318
  Porffor.wasm.i32.store8(j++, chr, 0, 4);
319
319
  } else {
320
320
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
321
-
321
+
322
322
  let nibble: i32 = chr >> 4;
323
323
  if (nibble < 10) {
324
324
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
325
325
  } else {
326
326
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
327
327
  }
328
-
328
+
329
329
  nibble = chr & 0x0F;
330
330
  if (nibble < 10) {
331
331
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
@@ -334,27 +334,27 @@ export const encodeURI = (input: any): bytestring => {
334
334
  }
335
335
  }
336
336
  }
337
-
337
+
338
338
  return output;
339
339
  }
340
-
340
+
341
341
  // Handle string input (16-bit characters)
342
342
  const endPtr: i32 = i + len * 2;
343
-
343
+
344
344
  // First pass: calculate output length
345
-
345
+
346
346
  while (i < endPtr) {
347
347
  const chr: i32 = Porffor.wasm.i32.load16_u(i, 0, 4);
348
348
  i += 2;
349
-
349
+
350
350
  // Characters that should NOT be encoded for encodeURI
351
351
  if ((chr >= 48 && chr <= 57) || // 0-9
352
352
  (chr >= 65 && chr <= 90) || // A-Z
353
353
  (chr >= 97 && chr <= 122) || // a-z
354
- chr == 33 || chr == 35 || chr == 36 || chr == 38 || chr == 39 ||
355
- chr == 40 || chr == 41 || chr == 42 || chr == 43 || chr == 44 ||
356
- chr == 45 || chr == 46 || chr == 47 || chr == 58 || chr == 59 ||
357
- chr == 61 || chr == 63 || chr == 64 || chr == 91 || chr == 93 ||
354
+ chr == 33 || chr == 35 || chr == 36 || chr == 38 || chr == 39 ||
355
+ chr == 40 || chr == 41 || chr == 42 || chr == 43 || chr == 44 ||
356
+ chr == 45 || chr == 46 || chr == 47 || chr == 58 || chr == 59 ||
357
+ chr == 61 || chr == 63 || chr == 64 || chr == 91 || chr == 93 ||
358
358
  chr == 95 || chr == 126) {
359
359
  outLength += 1;
360
360
  } else if (chr < 128) {
@@ -365,38 +365,38 @@ export const encodeURI = (input: any): bytestring => {
365
365
  outLength += 9; // %XX%XX%XX
366
366
  }
367
367
  }
368
-
368
+
369
369
  // Second pass: encode
370
- let output: bytestring = Porffor.allocate();
370
+ let output: bytestring = Porffor.malloc();
371
371
  output.length = outLength;
372
-
372
+
373
373
  i = Porffor.wasm`local.get ${input}`;
374
374
  let j: i32 = Porffor.wasm`local.get ${output}`;
375
-
375
+
376
376
  while (i < endPtr) {
377
377
  const chr: i32 = Porffor.wasm.i32.load16_u(i, 0, 4);
378
378
  i += 2;
379
-
379
+
380
380
  if ((chr >= 48 && chr <= 57) || // 0-9
381
381
  (chr >= 65 && chr <= 90) || // A-Z
382
382
  (chr >= 97 && chr <= 122) || // a-z
383
- chr == 33 || chr == 35 || chr == 36 || chr == 38 || chr == 39 ||
384
- chr == 40 || chr == 41 || chr == 42 || chr == 43 || chr == 44 ||
385
- chr == 45 || chr == 46 || chr == 47 || chr == 58 || chr == 59 ||
386
- chr == 61 || chr == 63 || chr == 64 || chr == 91 || chr == 93 ||
383
+ chr == 33 || chr == 35 || chr == 36 || chr == 38 || chr == 39 ||
384
+ chr == 40 || chr == 41 || chr == 42 || chr == 43 || chr == 44 ||
385
+ chr == 45 || chr == 46 || chr == 47 || chr == 58 || chr == 59 ||
386
+ chr == 61 || chr == 63 || chr == 64 || chr == 91 || chr == 93 ||
387
387
  chr == 95 || chr == 126) {
388
388
  Porffor.wasm.i32.store8(j++, chr, 0, 4);
389
389
  } else if (chr < 128) {
390
390
  // Single byte UTF-8
391
391
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
392
-
392
+
393
393
  let nibble: i32 = chr >> 4;
394
394
  if (nibble < 10) {
395
395
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
396
396
  } else {
397
397
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
398
398
  }
399
-
399
+
400
400
  nibble = chr & 0x0F;
401
401
  if (nibble < 10) {
402
402
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
@@ -407,7 +407,7 @@ export const encodeURI = (input: any): bytestring => {
407
407
  // Two byte UTF-8
408
408
  const byte1: i32 = 0xC0 | (chr >> 6);
409
409
  const byte2: i32 = 0x80 | (chr & 0x3F);
410
-
410
+
411
411
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
412
412
  let nibble: i32 = byte1 >> 4;
413
413
  if (nibble < 10) {
@@ -421,7 +421,7 @@ export const encodeURI = (input: any): bytestring => {
421
421
  } else {
422
422
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
423
423
  }
424
-
424
+
425
425
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
426
426
  nibble = byte2 >> 4;
427
427
  if (nibble < 10) {
@@ -440,7 +440,7 @@ export const encodeURI = (input: any): bytestring => {
440
440
  const byte1: i32 = 0xE0 | (chr >> 12);
441
441
  const byte2: i32 = 0x80 | ((chr >> 6) & 0x3F);
442
442
  const byte3: i32 = 0x80 | (chr & 0x3F);
443
-
443
+
444
444
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
445
445
  let nibble: i32 = byte1 >> 4;
446
446
  if (nibble < 10) {
@@ -454,7 +454,7 @@ export const encodeURI = (input: any): bytestring => {
454
454
  } else {
455
455
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
456
456
  }
457
-
457
+
458
458
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
459
459
  nibble = byte2 >> 4;
460
460
  if (nibble < 10) {
@@ -468,7 +468,7 @@ export const encodeURI = (input: any): bytestring => {
468
468
  } else {
469
469
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
470
470
  }
471
-
471
+
472
472
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
473
473
  nibble = byte3 >> 4;
474
474
  if (nibble < 10) {
@@ -484,7 +484,7 @@ export const encodeURI = (input: any): bytestring => {
484
484
  }
485
485
  }
486
486
  }
487
-
487
+
488
488
  return output;
489
489
  };
490
490
 
@@ -492,56 +492,56 @@ export const encodeURIComponent = (input: any): bytestring => {
492
492
  input = __ecma262_ToString(input);
493
493
  const len: i32 = input.length;
494
494
  let outLength: i32 = 0;
495
-
495
+
496
496
  let i: i32 = Porffor.wasm`local.get ${input}`;
497
-
497
+
498
498
  // Check if input is bytestring or string
499
499
  if (Porffor.wasm`local.get ${input+1}` == Porffor.TYPES.bytestring) {
500
500
  // Handle bytestring input
501
501
  const endPtr: i32 = i + len;
502
-
502
+
503
503
  // First pass: calculate output length
504
504
  while (i < endPtr) {
505
505
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
506
-
506
+
507
507
  // Characters that should NOT be encoded for encodeURIComponent
508
508
  if ((chr >= 48 && chr <= 57) || // 0-9
509
509
  (chr >= 65 && chr <= 90) || // A-Z
510
510
  (chr >= 97 && chr <= 122) || // a-z
511
- chr == 33 || chr == 39 || chr == 40 || chr == 41 || chr == 42 ||
511
+ chr == 33 || chr == 39 || chr == 40 || chr == 41 || chr == 42 ||
512
512
  chr == 45 || chr == 46 || chr == 95 || chr == 126) {
513
513
  outLength += 1;
514
514
  } else {
515
515
  outLength += 3; // %XX
516
516
  }
517
517
  }
518
-
518
+
519
519
  // Second pass: encode
520
- let output: bytestring = Porffor.allocate();
520
+ let output: bytestring = Porffor.malloc();
521
521
  output.length = outLength;
522
-
522
+
523
523
  i = Porffor.wasm`local.get ${input}`;
524
524
  let j: i32 = Porffor.wasm`local.get ${output}`;
525
-
525
+
526
526
  while (i < endPtr) {
527
527
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
528
-
528
+
529
529
  if ((chr >= 48 && chr <= 57) || // 0-9
530
530
  (chr >= 65 && chr <= 90) || // A-Z
531
531
  (chr >= 97 && chr <= 122) || // a-z
532
- chr == 33 || chr == 39 || chr == 40 || chr == 41 || chr == 42 ||
532
+ chr == 33 || chr == 39 || chr == 40 || chr == 41 || chr == 42 ||
533
533
  chr == 45 || chr == 46 || chr == 95 || chr == 126) {
534
534
  Porffor.wasm.i32.store8(j++, chr, 0, 4);
535
535
  } else {
536
536
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
537
-
537
+
538
538
  let nibble: i32 = chr >> 4;
539
539
  if (nibble < 10) {
540
540
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
541
541
  } else {
542
542
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
543
543
  }
544
-
544
+
545
545
  nibble = chr & 0x0F;
546
546
  if (nibble < 10) {
547
547
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
@@ -550,24 +550,24 @@ export const encodeURIComponent = (input: any): bytestring => {
550
550
  }
551
551
  }
552
552
  }
553
-
553
+
554
554
  return output;
555
555
  }
556
-
556
+
557
557
  // Handle string input (16-bit characters)
558
558
  const endPtr: i32 = i + len * 2;
559
-
559
+
560
560
  // First pass: calculate output length
561
-
561
+
562
562
  while (i < endPtr) {
563
563
  const chr: i32 = Porffor.wasm.i32.load16_u(i, 0, 4);
564
564
  i += 2;
565
-
565
+
566
566
  // Characters that should NOT be encoded for encodeURIComponent
567
567
  if ((chr >= 48 && chr <= 57) || // 0-9
568
568
  (chr >= 65 && chr <= 90) || // A-Z
569
569
  (chr >= 97 && chr <= 122) || // a-z
570
- chr == 33 || chr == 39 || chr == 40 || chr == 41 || chr == 42 ||
570
+ chr == 33 || chr == 39 || chr == 40 || chr == 41 || chr == 42 ||
571
571
  chr == 45 || chr == 46 || chr == 95 || chr == 126) {
572
572
  outLength += 1;
573
573
  } else if (chr < 128) {
@@ -578,35 +578,35 @@ export const encodeURIComponent = (input: any): bytestring => {
578
578
  outLength += 9; // %XX%XX%XX
579
579
  }
580
580
  }
581
-
581
+
582
582
  // Second pass: encode
583
- let output: bytestring = Porffor.allocate();
583
+ let output: bytestring = Porffor.malloc();
584
584
  output.length = outLength;
585
-
585
+
586
586
  i = Porffor.wasm`local.get ${input}`;
587
587
  let j: i32 = Porffor.wasm`local.get ${output}`;
588
-
588
+
589
589
  while (i < endPtr) {
590
590
  const chr: i32 = Porffor.wasm.i32.load16_u(i, 0, 4);
591
591
  i += 2;
592
-
592
+
593
593
  if ((chr >= 48 && chr <= 57) || // 0-9
594
594
  (chr >= 65 && chr <= 90) || // A-Z
595
595
  (chr >= 97 && chr <= 122) || // a-z
596
- chr == 33 || chr == 39 || chr == 40 || chr == 41 || chr == 42 ||
596
+ chr == 33 || chr == 39 || chr == 40 || chr == 41 || chr == 42 ||
597
597
  chr == 45 || chr == 46 || chr == 95 || chr == 126) {
598
598
  Porffor.wasm.i32.store8(j++, chr, 0, 4);
599
599
  } else if (chr < 128) {
600
600
  // Single byte UTF-8
601
601
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
602
-
602
+
603
603
  let nibble: i32 = chr >> 4;
604
604
  if (nibble < 10) {
605
605
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
606
606
  } else {
607
607
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
608
608
  }
609
-
609
+
610
610
  nibble = chr & 0x0F;
611
611
  if (nibble < 10) {
612
612
  Porffor.wasm.i32.store8(j++, nibble + 48, 0, 4);
@@ -617,7 +617,7 @@ export const encodeURIComponent = (input: any): bytestring => {
617
617
  // Two byte UTF-8
618
618
  const byte1: i32 = 0xC0 | (chr >> 6);
619
619
  const byte2: i32 = 0x80 | (chr & 0x3F);
620
-
620
+
621
621
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
622
622
  let nibble: i32 = byte1 >> 4;
623
623
  if (nibble < 10) {
@@ -631,7 +631,7 @@ export const encodeURIComponent = (input: any): bytestring => {
631
631
  } else {
632
632
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
633
633
  }
634
-
634
+
635
635
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
636
636
  nibble = byte2 >> 4;
637
637
  if (nibble < 10) {
@@ -650,7 +650,7 @@ export const encodeURIComponent = (input: any): bytestring => {
650
650
  const byte1: i32 = 0xE0 | (chr >> 12);
651
651
  const byte2: i32 = 0x80 | ((chr >> 6) & 0x3F);
652
652
  const byte3: i32 = 0x80 | (chr & 0x3F);
653
-
653
+
654
654
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
655
655
  let nibble: i32 = byte1 >> 4;
656
656
  if (nibble < 10) {
@@ -664,7 +664,7 @@ export const encodeURIComponent = (input: any): bytestring => {
664
664
  } else {
665
665
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
666
666
  }
667
-
667
+
668
668
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
669
669
  nibble = byte2 >> 4;
670
670
  if (nibble < 10) {
@@ -678,7 +678,7 @@ export const encodeURIComponent = (input: any): bytestring => {
678
678
  } else {
679
679
  Porffor.wasm.i32.store8(j++, nibble + 55, 0, 4);
680
680
  }
681
-
681
+
682
682
  Porffor.wasm.i32.store8(j++, 37, 0, 4); // %
683
683
  nibble = byte3 >> 4;
684
684
  if (nibble < 10) {
@@ -694,7 +694,7 @@ export const encodeURIComponent = (input: any): bytestring => {
694
694
  }
695
695
  }
696
696
  }
697
-
697
+
698
698
  return output;
699
699
  };
700
700
 
@@ -702,25 +702,25 @@ export const decodeURI = (input: any): string => {
702
702
  input = __ecma262_ToString(input);
703
703
  const len: i32 = input.length;
704
704
  let outLength: i32 = 0;
705
-
705
+
706
706
  // First pass: calculate output length
707
707
  let i: i32 = Porffor.wasm`local.get ${input}`;
708
708
  const endPtr: i32 = i + len;
709
-
709
+
710
710
  while (i < endPtr) {
711
711
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
712
712
  if (chr == 37 && i + 1 < endPtr) { // %
713
713
  const h1: i32 = Porffor.wasm.i32.load8_u(i, 0, 4);
714
714
  const h2: i32 = Porffor.wasm.i32.load8_u(i + 1, 0, 4);
715
-
715
+
716
716
  let n1: i32 = h1 - 48;
717
717
  if (n1 > 9) n1 = h1 - 55;
718
718
  if (n1 > 15) n1 = h1 - 87;
719
-
719
+
720
720
  let n2: i32 = h2 - 48;
721
721
  if (n2 > 9) n2 = h2 - 55;
722
722
  if (n2 > 15) n2 = h2 - 87;
723
-
723
+
724
724
  if (n1 >= 0 && n1 <= 15 && n2 >= 0 && n2 <= 15) {
725
725
  i += 2;
726
726
  const byte: i32 = (n1 << 4) | n2;
@@ -739,37 +739,37 @@ export const decodeURI = (input: any): string => {
739
739
  outLength += 1;
740
740
  }
741
741
  }
742
-
742
+
743
743
  // Second pass: decode
744
- let output: string = Porffor.allocate();
744
+ let output: string = Porffor.malloc();
745
745
  output.length = outLength;
746
-
746
+
747
747
  i = Porffor.wasm`local.get ${input}`;
748
748
  let j: i32 = Porffor.wasm`local.get ${output}`;
749
-
749
+
750
750
  while (i < endPtr) {
751
751
  const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
752
-
752
+
753
753
  if (chr == 37 && i + 1 < endPtr) { // %
754
754
  const h1: i32 = Porffor.wasm.i32.load8_u(i, 0, 4);
755
755
  const h2: i32 = Porffor.wasm.i32.load8_u(i + 1, 0, 4);
756
-
756
+
757
757
  let n1: i32 = h1 - 48;
758
758
  if (n1 > 9) {
759
759
  n1 = h1 - 55;
760
760
  if (n1 > 15) n1 = h1 - 87;
761
761
  }
762
-
762
+
763
763
  let n2: i32 = h2 - 48;
764
764
  if (n2 > 9) {
765
765
  n2 = h2 - 55;
766
766
  if (n2 > 15) n2 = h2 - 87;
767
767
  }
768
-
768
+
769
769
  if (n1 >= 0 && n1 <= 15 && n2 >= 0 && n2 <= 15) {
770
770
  i += 2;
771
771
  const byte1: i32 = (n1 << 4) | n2;
772
-
772
+
773
773
  if ((byte1 & 0x80) == 0) {
774
774
  // Single byte
775
775
  Porffor.wasm.i32.store16(j, byte1, 0, 4);
@@ -778,19 +778,19 @@ export const decodeURI = (input: any): string => {
778
778
  // Two byte UTF-8
779
779
  const h3: i32 = Porffor.wasm.i32.load8_u(i + 1, 0, 4);
780
780
  const h4: i32 = Porffor.wasm.i32.load8_u(i + 2, 0, 4);
781
-
781
+
782
782
  let n3: i32 = h3 - 48;
783
783
  if (n3 > 9) {
784
784
  n3 = h3 - 55;
785
785
  if (n3 > 15) n3 = h3 - 87;
786
786
  }
787
-
787
+
788
788
  let n4: i32 = h4 - 48;
789
789
  if (n4 > 9) {
790
790
  n4 = h4 - 55;
791
791
  if (n4 > 15) n4 = h4 - 87;
792
792
  }
793
-
793
+
794
794
  if (n3 >= 0 && n3 <= 15 && n4 >= 0 && n4 <= 15) {
795
795
  i += 3;
796
796
  const byte2: i32 = (n3 << 4) | n4;
@@ -808,31 +808,31 @@ export const decodeURI = (input: any): string => {
808
808
  const h4: i32 = Porffor.wasm.i32.load8_u(i + 2, 0, 4);
809
809
  const h5: i32 = Porffor.wasm.i32.load8_u(i + 4, 0, 4);
810
810
  const h6: i32 = Porffor.wasm.i32.load8_u(i + 5, 0, 4);
811
-
811
+
812
812
  let n3: i32 = h3 - 48;
813
813
  if (n3 > 9) {
814
814
  n3 = h3 - 55;
815
815
  if (n3 > 15) n3 = h3 - 87;
816
816
  }
817
-
817
+
818
818
  let n4: i32 = h4 - 48;
819
819
  if (n4 > 9) {
820
820
  n4 = h4 - 55;
821
821
  if (n4 > 15) n4 = h4 - 87;
822
822
  }
823
-
823
+
824
824
  let n5: i32 = h5 - 48;
825
825
  if (n5 > 9) {
826
826
  n5 = h5 - 55;
827
827
  if (n5 > 15) n5 = h5 - 87;
828
828
  }
829
-
829
+
830
830
  let n6: i32 = h6 - 48;
831
831
  if (n6 > 9) {
832
832
  n6 = h6 - 55;
833
833
  if (n6 > 15) n6 = h6 - 87;
834
834
  }
835
-
835
+
836
836
  if (n3 >= 0 && n3 <= 15 && n4 >= 0 && n4 <= 15 && n5 >= 0 && n5 <= 15 && n6 >= 0 && n6 <= 15) {
837
837
  i += 6;
838
838
  const byte2: i32 = (n3 << 4) | n4;
@@ -859,7 +859,7 @@ export const decodeURI = (input: any): string => {
859
859
  j += 2;
860
860
  }
861
861
  }
862
-
862
+
863
863
  return output;
864
864
  };
865
865