porffor 0.16.0-fa3914030 → 0.17.0-048c6f2ee
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/base64.ts +28 -24
- package/compiler/builtins/set.ts +5 -0
- package/compiler/builtins.js +1 -1
- package/compiler/codegen.js +71 -27
- package/compiler/generated_builtins.js +23 -3
- package/compiler/wrap.js +17 -7
- package/package.json +1 -1
@@ -2,17 +2,18 @@
|
|
2
2
|
import type {} from './porffor.d.ts';
|
3
3
|
|
4
4
|
export const btoa = (input: bytestring): bytestring => {
|
5
|
+
// todo: throw on invalid chars
|
6
|
+
|
5
7
|
const keyStr: bytestring = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
6
8
|
const keyStrPtr: i32 = Porffor.wasm`local.get ${keyStr}`;
|
7
9
|
|
8
10
|
let len: i32 = input.length;
|
9
11
|
let output: bytestring = '';
|
10
|
-
output.length = 4 * (len / 3 + !!(len % 3));
|
11
12
|
|
12
13
|
let i: i32 = Porffor.wasm`local.get ${input}`,
|
13
14
|
j: i32 = Porffor.wasm`local.get ${output}`;
|
14
15
|
|
15
|
-
// todo/perf: add some per 6 char variant using bitwise magic
|
16
|
+
// todo/perf: add some per 6 char variant using bitwise magic?
|
16
17
|
|
17
18
|
const endPtr = i + len;
|
18
19
|
while (i < endPtr) {
|
@@ -38,40 +39,43 @@ export const btoa = (input: bytestring): bytestring => {
|
|
38
39
|
Porffor.wasm.i32.store8(j++, Porffor.wasm.i32.load8_u(keyStrPtr + enc4, 0, 4), 0, 4);
|
39
40
|
}
|
40
41
|
|
42
|
+
output.length = j - Porffor.wasm`local.get ${output}`;
|
41
43
|
return output;
|
42
44
|
};
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
export const atob = (input: bytestring): bytestring => {
|
47
|
+
// todo: throw on non-base64 chars
|
48
|
+
|
49
|
+
const lut: bytestring = '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@>@@@?456789:;<=@@@@@@@\x00\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0B\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19@@@@@@\x1A\x1B\x1C\x1D\x1E\x1F !"#$%&\'()*+,-./0123';
|
50
|
+
const lutPtr: i32 = Porffor.wasm`local.get ${lut}`;
|
51
|
+
|
52
|
+
let output: bytestring = '';
|
47
53
|
|
48
|
-
let
|
49
|
-
|
50
|
-
let enc1, enc2, enc3, enc4;
|
51
|
-
let i = 0;
|
54
|
+
let i: i32 = Porffor.wasm`local.get ${input}`,
|
55
|
+
j: i32 = Porffor.wasm`local.get ${output}`;
|
52
56
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
57
|
+
const endPtr = i + input.length;
|
58
|
+
while (i < endPtr) {
|
59
|
+
const enc1: i32 = Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4);
|
60
|
+
const enc2: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
|
61
|
+
const enc3: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
|
62
|
+
const enc4: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
|
58
63
|
|
59
|
-
chr1 = (enc1 << 2) | (enc2 >> 4);
|
60
|
-
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
61
|
-
chr3 = ((enc3 & 3) << 6) | enc4;
|
64
|
+
const chr1: i32 = (enc1 << 2) | (enc2 == -1 ? 0 : (enc2 >> 4));
|
65
|
+
const chr2: i32 = ((enc2 & 15) << 4) | (enc3 == -1 ? 0 : (enc3 >> 2));
|
66
|
+
const chr3: i32 = ((enc3 & 3) << 6) | (enc4 == -1 ? 0 : enc4);
|
62
67
|
|
63
|
-
|
64
|
-
Porffor.bytestring.appendCharCode(output, chr1);
|
68
|
+
Porffor.wasm.i32.store8(j++, chr1, 0, 4);
|
65
69
|
|
66
70
|
if (enc3 != 64) {
|
67
|
-
|
68
|
-
Porffor.bytestring.appendCharCode(output, chr2);
|
71
|
+
Porffor.wasm.i32.store8(j++, chr2, 0, 4);
|
69
72
|
}
|
73
|
+
|
70
74
|
if (enc4 != 64) {
|
71
|
-
|
72
|
-
Porffor.bytestring.appendCharCode(output, chr3);
|
75
|
+
Porffor.wasm.i32.store8(j++, chr3, 0, 4);
|
73
76
|
}
|
74
77
|
}
|
75
78
|
|
79
|
+
output.length = j - Porffor.wasm`local.get ${output}`;
|
76
80
|
return output;
|
77
|
-
};
|
81
|
+
};
|
package/compiler/builtins/set.ts
CHANGED
package/compiler/builtins.js
CHANGED
@@ -150,7 +150,7 @@ export const BuiltinVars = function() {
|
|
150
150
|
this.Math = number(1);
|
151
151
|
|
152
152
|
// wintercg(tm)
|
153
|
-
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.
|
153
|
+
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.17.0`, false, '__navigator_userAgent');
|
154
154
|
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.bytestring : TYPES.string;
|
155
155
|
|
156
156
|
for (const x in TYPES) {
|
package/compiler/codegen.js
CHANGED
@@ -264,10 +264,12 @@ const internalThrow = (scope, constructor, message, expectsValue = Prefs.alwaysV
|
|
264
264
|
argument: {
|
265
265
|
type: 'NewExpression',
|
266
266
|
callee: {
|
267
|
+
type: 'Identifier',
|
267
268
|
name: constructor
|
268
269
|
},
|
269
270
|
arguments: [
|
270
271
|
{
|
272
|
+
type: 'Literal',
|
271
273
|
value: message
|
272
274
|
}
|
273
275
|
]
|
@@ -1826,7 +1828,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
1826
1828
|
if (indirectMode === 'strict') {
|
1827
1829
|
return typeSwitch(scope, getNodeType(scope, decl.callee), {
|
1828
1830
|
[TYPES.function]: [
|
1829
|
-
...
|
1831
|
+
...out,
|
1830
1832
|
[ global ? Opcodes.global_get : Opcodes.local_get, local.idx ],
|
1831
1833
|
Opcodes.i32_to_u,
|
1832
1834
|
[ Opcodes.call_indirect, args.length, 0 ],
|
@@ -3029,32 +3031,46 @@ const generateLabel = (scope, decl) => {
|
|
3029
3031
|
const generateThrow = (scope, decl) => {
|
3030
3032
|
scope.throws = true;
|
3031
3033
|
|
3032
|
-
|
3034
|
+
const exceptionMode = Prefs.exceptionMode ?? 'lut';
|
3035
|
+
if (exceptionMode === 'lut') {
|
3036
|
+
let message = decl.argument.value, constructor = null;
|
3033
3037
|
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
3038
|
-
|
3038
|
+
// support `throw (new)? Error(...)`
|
3039
|
+
if (!message && (decl.argument.type === 'NewExpression' || decl.argument.type === 'CallExpression')) {
|
3040
|
+
constructor = decl.argument.callee.name;
|
3041
|
+
message = decl.argument.arguments[0]?.value ?? '';
|
3042
|
+
}
|
3039
3043
|
|
3040
|
-
|
3041
|
-
|
3042
|
-
|
3043
|
-
|
3044
|
-
|
3044
|
+
if (tags.length === 0) tags.push({
|
3045
|
+
params: [ Valtype.i32 ],
|
3046
|
+
results: [],
|
3047
|
+
idx: tags.length
|
3048
|
+
});
|
3045
3049
|
|
3046
|
-
|
3047
|
-
let tagIdx = tags[0].idx;
|
3050
|
+
let exceptId = exceptions.push({ constructor, message }) - 1;
|
3048
3051
|
|
3049
|
-
|
3050
|
-
|
3052
|
+
scope.exceptions ??= [];
|
3053
|
+
scope.exceptions.push(exceptId);
|
3051
3054
|
|
3052
|
-
|
3055
|
+
return [
|
3056
|
+
[ Opcodes.i32_const, signedLEB128(exceptId) ],
|
3057
|
+
[ Opcodes.throw, tags[0].idx ]
|
3058
|
+
];
|
3059
|
+
}
|
3053
3060
|
|
3054
|
-
|
3055
|
-
|
3056
|
-
|
3057
|
-
|
3061
|
+
if (exceptionMode === 'stack') {
|
3062
|
+
if (tags.length === 0) tags.push({
|
3063
|
+
params: [ valtypeBinary, Valtype.i32 ],
|
3064
|
+
results: [],
|
3065
|
+
idx: tags.length
|
3066
|
+
});
|
3067
|
+
|
3068
|
+
return [
|
3069
|
+
...generate(scope, decl.argument),
|
3070
|
+
...getNodeType(scope, decl.argument),
|
3071
|
+
[ Opcodes.throw, tags[0].idx ]
|
3072
|
+
];
|
3073
|
+
}
|
3058
3074
|
};
|
3059
3075
|
|
3060
3076
|
const generateTry = (scope, decl) => {
|
@@ -3665,6 +3681,9 @@ const generateFunc = (scope, decl) => {
|
|
3665
3681
|
index: currentFuncIndex++
|
3666
3682
|
};
|
3667
3683
|
|
3684
|
+
funcIndex[name] = func.index;
|
3685
|
+
funcs.push(func);
|
3686
|
+
|
3668
3687
|
if (typedInput && decl.returnType) {
|
3669
3688
|
const { type } = extractTypeAnnotation(decl.returnType);
|
3670
3689
|
// if (type != null && !Prefs.indirectCalls) {
|
@@ -3674,12 +3693,26 @@ const generateFunc = (scope, decl) => {
|
|
3674
3693
|
}
|
3675
3694
|
}
|
3676
3695
|
|
3696
|
+
const defaultValues = {};
|
3677
3697
|
for (let i = 0; i < params.length; i++) {
|
3678
|
-
|
3698
|
+
let name;
|
3699
|
+
const x = params[i];
|
3700
|
+
switch (x.type) {
|
3701
|
+
case 'Identifier': {
|
3702
|
+
name = x.name;
|
3703
|
+
break;
|
3704
|
+
}
|
3705
|
+
|
3706
|
+
case 'AssignmentPattern': {
|
3707
|
+
name = x.left.name;
|
3708
|
+
defaultValues[name] = x.right;
|
3709
|
+
break;
|
3710
|
+
}
|
3711
|
+
}
|
3712
|
+
|
3679
3713
|
// if (name == null) return todo('non-identifier args are not supported');
|
3680
3714
|
|
3681
3715
|
allocVar(func, name, false);
|
3682
|
-
|
3683
3716
|
if (typedInput && params[i].typeAnnotation) {
|
3684
3717
|
addVarMetadata(func, name, false, extractTypeAnnotation(params[i]));
|
3685
3718
|
}
|
@@ -3696,11 +3729,22 @@ const generateFunc = (scope, decl) => {
|
|
3696
3729
|
};
|
3697
3730
|
}
|
3698
3731
|
|
3699
|
-
|
3700
|
-
|
3732
|
+
const prelude = [];
|
3733
|
+
for (const x in defaultValues) {
|
3734
|
+
prelude.push(
|
3735
|
+
...getType(func, x),
|
3736
|
+
...number(TYPES.undefined, Valtype.i32),
|
3737
|
+
[ Opcodes.i32_eq ],
|
3738
|
+
[ Opcodes.if, Blocktype.void ],
|
3739
|
+
...generate(func, defaultValues[x], false, x),
|
3740
|
+
[ Opcodes.local_set, func.locals[x].idx ],
|
3701
3741
|
|
3702
|
-
|
3703
|
-
|
3742
|
+
...setType(func, x, getNodeType(scope, defaultValues[x])),
|
3743
|
+
[ Opcodes.end ]
|
3744
|
+
);
|
3745
|
+
}
|
3746
|
+
|
3747
|
+
const wasm = func.wasm = prelude.concat(generate(func, body));
|
3704
3748
|
|
3705
3749
|
if (name === 'main') func.gotLastType = true;
|
3706
3750
|
|
@@ -409,15 +409,25 @@ export const BuiltinFuncs = function() {
|
|
409
409
|
data: [{"bytes":[1,0,0,0,44],"offset":0}],
|
410
410
|
};
|
411
411
|
this.btoa = {
|
412
|
-
wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: btoa/keyStr', 'i8') * pageSize, 127),[34,2],[33,3],[32,0],[40,1,0],[33,4],...number(allocPage(scope, 'bytestring: btoa/output', 'i8') * pageSize, 127),[
|
412
|
+
wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: btoa/keyStr', 'i8') * pageSize, 127),[34,2],[33,3],[32,0],[40,1,0],[33,4],...number(allocPage(scope, 'bytestring: btoa/output', 'i8') * pageSize, 127),[33,5],[32,0],[33,6],[32,5],[33,7],[32,6],[32,4],[106],[33,8],[65,0],[33,9],[3,64],[32,6],[32,8],[72],[4,64],[32,6],[32,6],[65,1],[106],[33,6],[45,0,4],[33,10],[32,6],[32,8],[72],[4,127],[32,6],[32,6],[65,1],[106],[33,6],[45,0,4],[65,0],[33,12],[5],[65,127],[65,0],[33,12],[11],[33,11],[32,6],[32,8],[72],[4,127],[32,6],[32,6],[65,1],[106],[33,6],[45,0,4],[65,0],[33,12],[5],[65,127],[65,0],[33,12],[11],[33,13],[32,10],[65,2],[117],[33,14],[32,10],[65,3],[113],[65,4],[116],[32,11],[65,127],[70],[4,127],[65,0],[65,0],[33,12],[5],[32,11],[65,4],[117],[65,0],[33,12],[11],[114],[33,15],[32,11],[65,15],[113],[65,2],[116],[32,13],[65,127],[70],[4,127],[65,0],[65,0],[33,12],[5],[32,13],[65,6],[117],[65,0],[33,12],[11],[114],[33,16],[32,13],[65,63],[113],[33,17],[32,11],[65,127],[70],[4,64],[65,192,0],[33,16],[65,192,0],[33,17],[5],[32,13],[65,127],[70],[4,64],[65,192,0],[33,17],[11],[11],[32,7],[32,7],[65,1],[106],[33,7],[32,3],[32,14],[106],[45,0,4],[58,0,4],[32,7],[32,7],[65,1],[106],[33,7],[32,3],[32,15],[106],[45,0,4],[58,0,4],[32,7],[32,7],[65,1],[106],[33,7],[32,3],[32,16],[106],[45,0,4],[58,0,4],[32,7],[32,7],[65,1],[106],[33,7],[32,3],[32,17],[106],[45,0,4],[58,0,4],[12,1],[11],[11],[32,5],[32,7],[32,5],[107],[34,18],[54,1,0],[32,5],[15]],
|
413
413
|
params: [127,127],
|
414
414
|
typedParams: true,
|
415
415
|
returns: [127],
|
416
416
|
returnType: 18,
|
417
417
|
locals: [127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127],
|
418
|
-
localNames: ["input","input#type","keyStr","keyStrPtr","len","output","
|
418
|
+
localNames: ["input","input#type","keyStr","keyStrPtr","len","output","i","j","endPtr","endPtr#type","chr1","chr2","#last_type","chr3","enc1","enc2","enc3","enc4","__length_setter_tmp"],
|
419
419
|
data: [{"bytes":[65,0,0,0,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47,61],"offset":0}],
|
420
420
|
};
|
421
|
+
this.atob = {
|
422
|
+
wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: atob/lut', 'i8') * pageSize, 127),[34,2],[33,3],...number(allocPage(scope, 'bytestring: atob/output', 'i8') * pageSize, 127),[33,4],[32,0],[33,5],[32,4],[33,6],[32,5],[32,0],[40,1,0],[106],[33,7],[65,0],[33,8],[3,64],[32,5],[32,7],[72],[4,64],[32,3],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[106],[45,0,4],[33,9],[32,5],[32,7],[72],[4,127],[32,3],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[106],[45,0,4],[65,0],[33,11],[5],[65,127],[65,0],[33,11],[11],[33,10],[32,5],[32,7],[72],[4,127],[32,3],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[106],[45,0,4],[65,0],[33,11],[5],[65,127],[65,0],[33,11],[11],[33,12],[32,5],[32,7],[72],[4,127],[32,3],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[106],[45,0,4],[65,0],[33,11],[5],[65,127],[65,0],[33,11],[11],[33,13],[32,9],[65,2],[116],[32,10],[65,127],[70],[4,127],[65,0],[65,0],[33,11],[5],[32,10],[65,4],[117],[65,0],[33,11],[11],[114],[33,14],[32,10],[65,15],[113],[65,4],[116],[32,12],[65,127],[70],[4,127],[65,0],[65,0],[33,11],[5],[32,12],[65,2],[117],[65,0],[33,11],[11],[114],[33,15],[32,12],[65,3],[113],[65,6],[116],[32,13],[65,127],[70],[4,127],[65,0],[65,0],[33,11],[5],[32,13],[65,0],[33,11],[11],[114],[33,16],[32,6],[32,6],[65,1],[106],[33,6],[32,14],[58,0,4],[32,12],[65,192,0],[71],[4,64],[32,6],[32,6],[65,1],[106],[33,6],[32,15],[58,0,4],[11],[32,13],[65,192,0],[71],[4,64],[32,6],[32,6],[65,1],[106],[33,6],[32,16],[58,0,4],[11],[12,1],[11],[11],[32,4],[32,6],[32,4],[107],[34,17],[54,1,0],[32,4],[15]],
|
423
|
+
params: [127,127],
|
424
|
+
typedParams: true,
|
425
|
+
returns: [127],
|
426
|
+
returnType: 18,
|
427
|
+
locals: [127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127],
|
428
|
+
localNames: ["input","input#type","lut","lutPtr","output","i","j","endPtr","endPtr#type","enc1","enc2","#last_type","enc3","enc4","chr1","chr2","chr3","__length_setter_tmp"],
|
429
|
+
data: [{"bytes":[123,0,0,0,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63,52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,64,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,64,64,64,64,64,64,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],"offset":0}],
|
430
|
+
};
|
421
431
|
this.__Boolean_prototype_toString = {
|
422
432
|
wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: __Boolean_prototype_toString/out', 'i8') * pageSize, 124),[33,2],[32,0],[252,3],[4,64],[32,2],[252,3],[34,3],[65,4],[54,1,0],[32,3],[65,244,0],[58,0,4],[32,3],[65,242,0],[58,0,5],[32,3],[65,245,0],[58,0,6],[32,3],[65,229,0],[58,0,7],[32,3],[184],[33,2],[5],[32,2],[252,3],[34,3],[65,5],[54,1,0],[32,3],[65,230,0],[58,0,4],[32,3],[65,225,0],[58,0,5],[32,3],[65,236,0],[58,0,6],[32,3],[65,243,0],[58,0,7],[32,3],[65,229,0],[58,0,8],[32,3],[184],[33,2],[11],[32,2],[65,18],[15]],
|
423
433
|
params: [124,127],
|
@@ -1776,6 +1786,16 @@ export const BuiltinFuncs = function() {
|
|
1776
1786
|
locals: [124,127,127,127,124,127,127,127],
|
1777
1787
|
localNames: ["_this","_this#type","other","other#type","out","forof_base_pointer","forof_length","forof_counter","x","x#type","#last_type","#typeswitch_tmp"],
|
1778
1788
|
};
|
1789
|
+
this.__Set_prototype_toString = {
|
1790
|
+
wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: __Set_prototype_toString/out', 'i8') * pageSize, 124),[34,2],[65,18],[15]],
|
1791
|
+
params: [124,127],
|
1792
|
+
typedParams: true,
|
1793
|
+
returns: [124,127],
|
1794
|
+
typedReturns: true,
|
1795
|
+
locals: [124],
|
1796
|
+
localNames: ["_this","_this#type","out"],
|
1797
|
+
data: [{"bytes":[12,0,0,0,91,111,98,106,101,99,116,32,83,101,116,93],"offset":0}],
|
1798
|
+
};
|
1779
1799
|
this.__String_fromCharCode = {
|
1780
1800
|
wasm: (scope, {allocPage,}) => [[32,0],[65,128,2],[72],[4,64],...number(allocPage(scope, 'bytestring: __String_fromCharCode/out', 'i8') * pageSize, 127),[34,2],[32,0],[58,0,4],[32,2],[65,18],[15],[11],[32,2],[34,3],[65,1],[54,1,0],[32,3],[65,46],[59,0,4],[32,3],[34,2],[32,0],[59,0,4],[32,2],[65,2],[15]],
|
1781
1801
|
params: [127,127],
|
@@ -2165,7 +2185,7 @@ export const BuiltinFuncs = function() {
|
|
2165
2185
|
localNames: ["argument","argument#type","number"],
|
2166
2186
|
};
|
2167
2187
|
this.__ecma262_ToString = {
|
2168
|
-
wasm: (scope, {allocPage,builtin,internalThrow,}) => [...number(allocPage(scope, 'bytestring: __ecma262_ToString/out', 'i8') * pageSize, 124),[33,2],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[34,3],[68,0,0,0,0,0,0,0,64],[97],[32,3],[68,0,0,0,0,0,0,50,64],[97],[114],[4,64],[32,0],[15],[11],[32,3],[68,0,0,0,0,0,0,24,64],[97],[4,64],...internalThrow(scope, 'TypeError', `Cannot convert a Symbol value to a string`),[11],[32,3],[68,0,0,0,0,0,0,8,64],[97],[4,64],[32,2],[252,3],[34,4],[65,9],[54,1,0],[32,4],[65,245,0],[58,0,4],[32,4],[65,238,0],[58,0,5],[32,4],[65,228,0],[58,0,6],[32,4],[65,229,0],[58,0,7],[32,4],[65,230,0],[58,0,8],[32,4],[65,233,0],[58,0,9],[32,4],[65,238,0],[58,0,10],[32,4],[65,229,0],[58,0,11],[32,4],[65,228,0],[58,0,12],[32,4],[184],[34,2],[15],[11],[32,3],[68,0,0,0,0,0,0,16,64],[97],[32,0],[68,0,0,0,0,0,0,0,0],[97],[113],[4,64],[32,2],[252,3],[34,4],[65,4],[54,1,0],[32,4],[65,238,0],[58,0,4],[32,4],[65,245,0],[58,0,5],[32,4],[65,236,0],[58,0,6],[32,4],[65,236,0],[58,0,7],[32,4],[184],[34,2],[15],[11],[32,3],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,2],[252,3],[34,4],[65,4],[54,1,0],[32,4],[65,244,0],[58,0,4],[32,4],[65,242,0],[58,0,5],[32,4],[65,245,0],[58,0,6],[32,4],[65,229,0],[58,0,7],[32,4],[184],[34,2],[15],[11],[32,2],[252,3],[34,4],[65,5],[54,1,0],[32,4],[65,230,0],[58,0,4],[32,4],[65,225,0],[58,0,5],[32,4],[65,236,0],[58,0,6],[32,4],[65,243,0],[58,0,7],[32,4],[65,229,0],[58,0,8],[32,4],[184],[34,2],[15],[11],[32,1],[33,6],[2,124],[32,6],[65,0],[70],[4,64,"TYPESWITCH|Number"],[32,0],[32,1],[68,0,0,0,0,0,0,0,0],[65,3],[16, builtin('__Number_prototype_toString')],[26],[12,1],[11],[32,6],[65,1],[70],[4,64,"TYPESWITCH|Boolean"],[32,0],[32,1],[16, builtin('__Boolean_prototype_toString')],[26],[12,1],[11],[32,6],[65,2],[70],[4,64,"TYPESWITCH|String"],[32,0],[252,2],[32,1],[16, builtin('__String_prototype_toString')],[26],[183],[12,1],[11],[32,6],[65,4],[70],[4,64,"TYPESWITCH|Object"],[32,0],[32,1],[16, builtin('__Object_prototype_toString')],[26],[12,1],[11],[32,6],[65,5],[70],[4,64,"TYPESWITCH|Function"],[32,0],[32,1],[16, builtin('__Function_prototype_toString')],[26],[12,1],[11],[32,6],[65,6],[70],[4,64,"TYPESWITCH|Symbol"],[32,0],[32,1],[16, builtin('__Symbol_prototype_toString')],[26],[12,1],[11],[32,6],[65,16],[70],[4,64,"TYPESWITCH|Array"],[32,0],[32,1],[16, builtin('__Array_prototype_toString')],[26],[12,1],[11],[32,6],[65,18],[70],[4,64,"TYPESWITCH|ByteString"],[32,0],[252,2],[32,1],[16, builtin('__ByteString_prototype_toString')],[26],[183],[12,1],[11],[32,6],[65,19],[70],[4,64,"TYPESWITCH|Date"],[32,0],[32,1],[16, builtin('__Date_prototype_toString')],[26],[12,1],[11],...internalThrow(scope, 'TypeError', `'toString' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[15]],
|
2188
|
+
wasm: (scope, {allocPage,builtin,internalThrow,}) => [...number(allocPage(scope, 'bytestring: __ecma262_ToString/out', 'i8') * pageSize, 124),[33,2],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[34,3],[68,0,0,0,0,0,0,0,64],[97],[32,3],[68,0,0,0,0,0,0,50,64],[97],[114],[4,64],[32,0],[15],[11],[32,3],[68,0,0,0,0,0,0,24,64],[97],[4,64],...internalThrow(scope, 'TypeError', `Cannot convert a Symbol value to a string`),[11],[32,3],[68,0,0,0,0,0,0,8,64],[97],[4,64],[32,2],[252,3],[34,4],[65,9],[54,1,0],[32,4],[65,245,0],[58,0,4],[32,4],[65,238,0],[58,0,5],[32,4],[65,228,0],[58,0,6],[32,4],[65,229,0],[58,0,7],[32,4],[65,230,0],[58,0,8],[32,4],[65,233,0],[58,0,9],[32,4],[65,238,0],[58,0,10],[32,4],[65,229,0],[58,0,11],[32,4],[65,228,0],[58,0,12],[32,4],[184],[34,2],[15],[11],[32,3],[68,0,0,0,0,0,0,16,64],[97],[32,0],[68,0,0,0,0,0,0,0,0],[97],[113],[4,64],[32,2],[252,3],[34,4],[65,4],[54,1,0],[32,4],[65,238,0],[58,0,4],[32,4],[65,245,0],[58,0,5],[32,4],[65,236,0],[58,0,6],[32,4],[65,236,0],[58,0,7],[32,4],[184],[34,2],[15],[11],[32,3],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,2],[252,3],[34,4],[65,4],[54,1,0],[32,4],[65,244,0],[58,0,4],[32,4],[65,242,0],[58,0,5],[32,4],[65,245,0],[58,0,6],[32,4],[65,229,0],[58,0,7],[32,4],[184],[34,2],[15],[11],[32,2],[252,3],[34,4],[65,5],[54,1,0],[32,4],[65,230,0],[58,0,4],[32,4],[65,225,0],[58,0,5],[32,4],[65,236,0],[58,0,6],[32,4],[65,243,0],[58,0,7],[32,4],[65,229,0],[58,0,8],[32,4],[184],[34,2],[15],[11],[32,1],[33,6],[2,124],[32,6],[65,0],[70],[4,64,"TYPESWITCH|Number"],[32,0],[32,1],[68,0,0,0,0,0,0,0,0],[65,3],[16, builtin('__Number_prototype_toString')],[26],[12,1],[11],[32,6],[65,1],[70],[4,64,"TYPESWITCH|Boolean"],[32,0],[32,1],[16, builtin('__Boolean_prototype_toString')],[26],[12,1],[11],[32,6],[65,2],[70],[4,64,"TYPESWITCH|String"],[32,0],[252,2],[32,1],[16, builtin('__String_prototype_toString')],[26],[183],[12,1],[11],[32,6],[65,4],[70],[4,64,"TYPESWITCH|Object"],[32,0],[32,1],[16, builtin('__Object_prototype_toString')],[26],[12,1],[11],[32,6],[65,5],[70],[4,64,"TYPESWITCH|Function"],[32,0],[32,1],[16, builtin('__Function_prototype_toString')],[26],[12,1],[11],[32,6],[65,6],[70],[4,64,"TYPESWITCH|Symbol"],[32,0],[32,1],[16, builtin('__Symbol_prototype_toString')],[26],[12,1],[11],[32,6],[65,16],[70],[4,64,"TYPESWITCH|Array"],[32,0],[32,1],[16, builtin('__Array_prototype_toString')],[26],[12,1],[11],[32,6],[65,18],[70],[4,64,"TYPESWITCH|ByteString"],[32,0],[252,2],[32,1],[16, builtin('__ByteString_prototype_toString')],[26],[183],[12,1],[11],[32,6],[65,19],[70],[4,64,"TYPESWITCH|Date"],[32,0],[32,1],[16, builtin('__Date_prototype_toString')],[26],[12,1],[11],[32,6],[65,20],[70],[4,64,"TYPESWITCH|Set"],[32,0],[32,1],[16, builtin('__Set_prototype_toString')],[26],[12,1],[11],...internalThrow(scope, 'TypeError', `'toString' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[15]],
|
2169
2189
|
params: [124,127],
|
2170
2190
|
typedParams: true,
|
2171
2191
|
returns: [124],
|
package/compiler/wrap.js
CHANGED
@@ -297,16 +297,26 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
297
297
|
return porfToJSValue({ memory, funcs, pages }, ret[0], ret[1]);
|
298
298
|
} catch (e) {
|
299
299
|
if (e.is && e.is(exceptTag)) {
|
300
|
-
const
|
301
|
-
|
300
|
+
const exceptionMode = Prefs.exceptionMode ?? 'lut';
|
301
|
+
if (exceptionMode === 'lut') {
|
302
|
+
const exceptId = e.getArg(exceptTag, 0);
|
303
|
+
const exception = exceptions[exceptId];
|
302
304
|
|
303
|
-
|
305
|
+
const constructorName = exception.constructor;
|
304
306
|
|
305
|
-
|
306
|
-
|
307
|
+
// no constructor, just throw message
|
308
|
+
if (!constructorName) throw exception.message;
|
307
309
|
|
308
|
-
|
309
|
-
|
310
|
+
const constructor = globalThis[constructorName] ?? eval(`class ${constructorName} extends Error { constructor(message) { super(message); this.name = "${constructorName}"; } }; ${constructorName}`);
|
311
|
+
throw new constructor(exception.message);
|
312
|
+
}
|
313
|
+
|
314
|
+
if (exceptionMode === 'stack') {
|
315
|
+
const value = e.getArg(exceptTag, 0);
|
316
|
+
const type = e.getArg(exceptTag, 1);
|
317
|
+
|
318
|
+
throw porfToJSValue({ memory, funcs, pages }, value, type);
|
319
|
+
}
|
310
320
|
}
|
311
321
|
|
312
322
|
if (e instanceof WebAssembly.RuntimeError) {
|
package/package.json
CHANGED