porffor 0.57.31 → 0.57.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { Blocktype, Opcodes, Valtype } from './wasmSpec.js';
2
2
  import { TYPES } from './types.js';
3
3
  import { number } from './encoding.js';
4
4
 
5
- export default function({ builtinFuncs }, Prefs) {
5
+ export default function ({ builtinFuncs }, Prefs) {
6
6
  const makePrefix = name => (name.startsWith('__') ? '' : '__') + name + '_';
7
7
 
8
8
  const done = new Set();
@@ -72,16 +72,15 @@ export default function({ builtinFuncs }, Prefs) {
72
72
  continue;
73
73
  }
74
74
 
75
- let flags = 0b0000;
75
+ let add = true;
76
+ if (existingFunc && (x === 'prototype' || x === 'constructor')) add = false;
76
77
 
78
+ let flags = 0b0000;
77
79
  const d = props[x];
78
80
  if (d.configurable) flags |= 0b0010;
79
81
  if (d.enumerable) flags |= 0b0100;
80
82
  if (d.writable) flags |= 0b1000;
81
83
 
82
- // hack: do not generate objects inside of objects as it causes issues atm
83
- if (this[prefix + x]?.type === TYPES.object && this[prefix + x] !== this.null) value = { type: 'ObjectExpression', properties: [] };
84
-
85
84
  out.push(
86
85
  [ Opcodes.local_get, 0 ],
87
86
  number(TYPES.object, Valtype.i32),
@@ -96,7 +95,7 @@ export default function({ builtinFuncs }, Prefs) {
96
95
  number(flags, Valtype.i32),
97
96
  number(TYPES.number, Valtype.i32),
98
97
 
99
- [ Opcodes.call, builtin('__Porffor_object_fastAdd') ]
98
+ [ Opcodes.call, builtin(add ? '__Porffor_object_fastAdd' : '__Porffor_object_define') ]
100
99
  );
101
100
  }
102
101
 
@@ -170,11 +169,20 @@ export default function({ builtinFuncs }, Prefs) {
170
169
  const prefix = makePrefix(name);
171
170
  return builtinFuncKeys.filter(x => x.startsWith(prefix)).map(x => x.slice(prefix.length)).filter(x => !x.startsWith('prototype_'));
172
171
  };
173
- const autoFuncs = name => props({
174
- writable: true,
175
- enumerable: false,
176
- configurable: true
177
- }, autoFuncKeys(name));
172
+ const autoFuncs = name => ({
173
+ ...props({
174
+ writable: true,
175
+ enumerable: false,
176
+ configurable: true
177
+ }, autoFuncKeys(name)),
178
+ ...(this[`__${name}_prototype`] ? {
179
+ prototype: {
180
+ writable: false,
181
+ enumerable: false,
182
+ configurable: false
183
+ }
184
+ } : {})
185
+ });
178
186
 
179
187
  object('Math', {
180
188
  ...props({
@@ -248,28 +256,16 @@ export default function({ builtinFuncs }, Prefs) {
248
256
  NaN: NaN,
249
257
  POSITIVE_INFINITY: Infinity,
250
258
  NEGATIVE_INFINITY: -Infinity,
251
-
252
259
  MAX_VALUE: valtype === 'i32' ? 2147483647 : 1.7976931348623157e+308,
253
260
  MIN_VALUE: valtype === 'i32' ? -2147483648 : 5e-324,
254
-
255
261
  MAX_SAFE_INTEGER: valtype === 'i32' ? 2147483647 : 9007199254740991,
256
262
  MIN_SAFE_INTEGER: valtype === 'i32' ? -2147483648 : -9007199254740991,
257
-
258
263
  EPSILON: 2.220446049250313e-16
259
264
  }),
260
265
 
261
266
  ...autoFuncs('Number')
262
267
  });
263
268
 
264
- object('Reflect', autoFuncs('Reflect'));
265
- object('Object', autoFuncs('Object'));
266
- object('JSON', autoFuncs('JSON'));
267
- object('Promise', autoFuncs('Promise'));
268
- object('Array', autoFuncs('Array'));
269
- object('Symbol', autoFuncs('Symbol'));
270
- object('Date', autoFuncs('Date'));
271
- object('Atomics', autoFuncs('Atomics'));
272
-
273
269
  // these technically not spec compliant as it should be classes or non-enumerable but eh
274
270
  object('navigator', {
275
271
  ...props({
@@ -286,13 +282,15 @@ export default function({ builtinFuncs }, Prefs) {
286
282
  'crypto',
287
283
  'performance',
288
284
  ]) {
289
- object(x, {
290
- ...props({
291
- writable: true,
292
- enumerable: true,
293
- configurable: true
294
- }, autoFuncKeys(x).slice(0, 12))
295
- });
285
+ object(x, props({
286
+ writable: true,
287
+ enumerable: true,
288
+ configurable: true
289
+ }, autoFuncKeys(x).slice(0, 12)));
290
+ }
291
+
292
+ for (const x of [ 'Array', 'ArrayBuffer', 'Atomics', 'Date', 'Error', 'JSON', 'Object', 'Promise', 'Reflect', 'String', 'Symbol', 'Uint8Array', 'Int8Array', 'Uint8ClampedArray', 'Uint16Array', 'Int16Array', 'Uint32Array', 'Int32Array', 'Float32Array', 'Float64Array', 'BigInt64Array', 'BigUint64Array', 'SharedArrayBuffer', 'BigInt', 'Boolean', 'DataView', 'AggregateError', 'TypeError', 'ReferenceError', 'SyntaxError', 'RangeError', 'EvalError', 'URIError', 'Function', 'Map', 'RegExp', 'Set', 'WeakMap', 'WeakRef', 'WeakSet' ]) {
293
+ object(x, autoFuncs(x));
296
294
  }
297
295
 
298
296
  const enumerableGlobals = [ 'atob', 'btoa', 'performance', 'crypto', 'navigator' ];
@@ -334,7 +332,6 @@ export default function({ builtinFuncs }, Prefs) {
334
332
 
335
333
  if (Prefs.logMissingObjects) for (const x of Object.keys(builtinFuncs).concat(Object.keys(this))) {
336
334
  if (!x.startsWith('__')) continue;
337
-
338
335
  const name = x.split('_').slice(2, -1).join('_');
339
336
 
340
337
  let t = globalThis;
@@ -133,13 +133,13 @@ locals:[127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127],loc
133
133
  table:1,usesTag:1,
134
134
  }
135
135
  this.__Porffor_object_setStrict = {
136
- wasm:(_,{i32ify,t,makeString,builtin,internalThrow})=>eval("[[32,0],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property of null`),[26],[11],[32,1],[65,7],[71],[4,64],[32,0],[183],[32,1],[16,builtin('__Porffor_object_underlying')],[34,6],[33,1],[33,0],[32,1],[65,7],[71],[4,64],[32,4],[32,5],[15],[26],[11],[11],[32,2],[32,3],[16,builtin('__Porffor_object_hash')],[33,7],[32,0],[32,1],[32,2],[32,3],[32,7],[65,1],[16,builtin('__Porffor_object_lookup')],[34,8],[65,127],[70],[4,64],[32,7],[65,248,187,246,154,2],[70],[4,64],[32,2],[32,3],...i32ify(makeString(_,\"__proto__\",1)),[65,195,1],[16,builtin('__Porffor_strcmp')],[4,64],[32,0],[32,1],[32,4],[252,2],[32,5],[16,builtin('__Porffor_object_setPrototype')],[32,4],[32,5],[15],[26],[11],[11],[32,0],[32,1],[16,builtin('__Porffor_object_getPrototype')],[34,6],[33,11],[34,10],[33,12],[32,11],[33,13],[2,127],...t([0,128],()=>[[32,13],[69],[32,13],[65,128,1],[70],[114],[4,64],[65,1],[12,1],[11]]),...t([7],()=>[[32,13],[65,7],[70],[4,64],[32,12],[69],[12,1],[11]]),[65,0],[11],[69],[4,64],[32,11],[65,7],[71],[4,64],[32,10],[183],[32,11],[16,builtin('__Porffor_object_underlying')],[34,6],[33,11],[33,10],[11],[32,10],[33,14],[32,11],[33,15],[3,64],[65,1],[4,64],[32,10],[32,11],[32,2],[32,3],[32,7],[65,1],[16,builtin('__Porffor_object_lookup')],[34,8],[65,127],[71],[4,64],[12,1],[26],[11],[32,10],[32,11],[16,builtin('__Porffor_object_getPrototype')],[34,6],[33,11],[33,10],[32,11],[65,7],[71],[4,64],[32,10],[183],[32,11],[16,builtin('__Porffor_object_underlying')],[34,6],[33,11],[33,10],[11],[32,10],[33,12],[32,11],[33,13],[2,127],...t([0,128],()=>[[32,13],[69],[32,13],[65,128,1],[70],[114],[4,64],[65,1],[12,1],[11]]),...t([7],()=>[[32,13],[65,7],[70],[4,64],[32,12],[69],[12,1],[11]]),[65,0],[11],[32,10],[32,14],[70],[114],[4,64],[12,1],[26],[11],[32,10],[33,14],[32,11],[33,15],[12,1],[11],[11],[32,8],[65,127],[71],[4,64],[32,8],[47,0,16],[34,16],[65,1],[113],[4,64],[32,8],[65,1],[16,builtin('__Porffor_object_accessorSet')],[33,6],[34,17],[69],[4,64],[32,4],[32,5],[15],[26],[11],[32,17],[33,20],[65,0],[65,128,1],[33,21],[183],[32,21],[32,0],[34,18],[32,1],[34,19],[33,21],[183],[32,21],[32,4],[32,5],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[32,20],[17,12,0],[33,6],[252,2],[26],[32,4],[32,5],[15],[26],[11],[11],[11],[32,0],[32,1],[16,builtin('__Porffor_object_isInextensible')],[4,64],...internalThrow(_,'TypeError',`Cannot add property to inextensible object`),[26],[11],[32,0],[47,0,0],[33,22],[32,0],[32,22],[65,1],[106],[59,0,0],[32,0],[65,8],[106],[32,22],[65,18],[108],[106],[34,8],[65,1],[32,2],[32,3],[32,7],[65,1],[16,builtin('__Porffor_object_writeKey')],[65,14],[33,9],[5],[32,8],[47,0,16],[34,16],[65,1],[113],[4,64],[32,8],[65,1],[16,builtin('__Porffor_object_accessorSet')],[33,6],[34,17],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property with no setter of object`),[26],[11],[32,17],[33,23],[65,0],[65,128,1],[33,21],[183],[32,21],[32,0],[34,18],[32,1],[34,19],[33,21],[183],[32,21],[32,4],[32,5],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[32,23],[17,12,0],[33,6],[252,2],[26],[32,4],[32,5],[15],[26],[11],[32,16],[65,8],[113],[69],[4,64],...internalThrow(_,'TypeError',`Cannot modify read-only property of object`),[26],[11],[32,16],[65,255,1],[113],[33,9],[11],[32,8],[32,4],[57,0,8],[32,8],[32,9],[32,5],[65,8],[116],[106],[59,0,16],[32,4],[32,5],[15]]"),
136
+ wasm:(_,{i32ify,t,makeString,builtin,internalThrow})=>eval("[[32,0],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property of null`),[26],[11],[32,1],[65,7],[71],[4,64],[32,0],[183],[32,1],[16,builtin('__Porffor_object_underlying')],[34,6],[33,1],[33,0],[32,1],[65,7],[71],[4,64],[32,4],[32,5],[15],[26],[11],[11],[32,2],[32,3],[16,builtin('__Porffor_object_hash')],[33,7],[32,0],[32,1],[32,2],[32,3],[32,7],[65,1],[16,builtin('__Porffor_object_lookup')],[34,8],[65,127],[70],[4,64],[32,7],[65,248,187,246,154,2],[70],[4,64],[32,2],[32,3],...i32ify(makeString(_,\"__proto__\",1)),[65,195,1],[16,builtin('__Porffor_strcmp')],[4,64],[32,0],[32,1],[32,4],[252,2],[32,5],[16,builtin('__Porffor_object_setPrototype')],[32,4],[32,5],[15],[26],[11],[11],[32,0],[32,1],[16,builtin('__Porffor_object_getPrototype')],[34,6],[33,11],[34,10],[33,12],[32,11],[33,13],[2,127],...t([0,128],()=>[[32,13],[69],[32,13],[65,128,1],[70],[114],[4,64],[65,1],[12,1],[11]]),...t([7],()=>[[32,13],[65,7],[70],[4,64],[32,12],[69],[12,1],[11]]),[65,0],[11],[69],[4,64],[32,11],[65,7],[71],[4,64],[32,10],[183],[32,11],[16,builtin('__Porffor_object_underlying')],[34,6],[33,11],[33,10],[11],[32,10],[33,14],[32,11],[33,15],[3,64],[65,1],[4,64],[32,10],[32,11],[32,2],[32,3],[32,7],[65,1],[16,builtin('__Porffor_object_lookup')],[34,8],[65,127],[71],[4,64],[12,1],[26],[11],[32,10],[32,11],[16,builtin('__Porffor_object_getPrototype')],[34,6],[33,11],[33,10],[32,11],[65,7],[71],[4,64],[32,10],[183],[32,11],[16,builtin('__Porffor_object_underlying')],[34,6],[33,11],[33,10],[11],[32,10],[33,12],[32,11],[33,13],[2,127],...t([0,128],()=>[[32,13],[69],[32,13],[65,128,1],[70],[114],[4,64],[65,1],[12,1],[11]]),...t([7],()=>[[32,13],[65,7],[70],[4,64],[32,12],[69],[12,1],[11]]),[65,0],[11],[32,10],[32,14],[70],[114],[4,64],[12,1],[26],[11],[32,10],[33,14],[32,11],[33,15],[12,1],[11],[11],[32,8],[65,127],[71],[4,64],[32,8],[47,0,16],[34,16],[65,1],[113],[4,64],[32,8],[65,1],[16,builtin('__Porffor_object_accessorSet')],[33,6],[34,17],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property with only getter`),[26],[11],[32,17],[33,20],[65,0],[65,128,1],[33,21],[183],[32,21],[32,0],[34,18],[32,1],[34,19],[33,21],[183],[32,21],[32,4],[32,5],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[32,20],[17,12,0],[33,6],[252,2],[26],[32,4],[32,5],[15],[26],[11],[11],[11],[32,0],[32,1],[16,builtin('__Porffor_object_isInextensible')],[4,64],...internalThrow(_,'TypeError',`Cannot add property to inextensible object`),[26],[11],[32,0],[47,0,0],[33,22],[32,0],[32,22],[65,1],[106],[59,0,0],[32,0],[65,8],[106],[32,22],[65,18],[108],[106],[34,8],[65,1],[32,2],[32,3],[32,7],[65,1],[16,builtin('__Porffor_object_writeKey')],[65,14],[33,9],[5],[32,8],[47,0,16],[34,16],[65,1],[113],[4,64],[32,8],[65,1],[16,builtin('__Porffor_object_accessorSet')],[33,6],[34,17],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property with only getter`),[26],[11],[32,17],[33,23],[65,0],[65,128,1],[33,21],[183],[32,21],[32,0],[34,18],[32,1],[34,19],[33,21],[183],[32,21],[32,4],[32,5],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[32,23],[17,12,0],[33,6],[252,2],[26],[32,4],[32,5],[15],[26],[11],[32,16],[65,8],[113],[69],[4,64],...internalThrow(_,'TypeError',`Cannot modify read-only property of object`),[26],[11],[32,16],[65,255,1],[113],[33,9],[11],[32,8],[32,4],[57,0,8],[32,8],[32,9],[32,5],[65,8],[116],[106],[59,0,16],[32,4],[32,5],[15]]"),
137
137
  params:[127,127,127,127,124,127],typedParams:1,returns:[124,127],
138
138
  locals:[127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127],localNames:["obj","obj#type","key","key#type","value","value#type","#last_type","hash","entryPtr","flags","proto","proto#type","#logicinner_tmp","#typeswitch_tmp1","lastProto","lastProto#type","tail","set","#call_val","#call_type","#indirect_8_callee","#swap","size","#indirect_9_callee"],
139
139
  table:1,usesTag:1,
140
140
  }
141
141
  this.__Porffor_object_setStrict_withHash = {
142
- wasm:(_,{t,builtin,internalThrow})=>eval("[[32,0],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property of null`),[26],[11],[32,1],[65,7],[71],[4,64],[32,0],[183],[32,1],[16,builtin('__Porffor_object_underlying')],[34,8],[33,1],[33,0],[32,1],[65,7],[71],[4,64],[32,4],[32,5],[15],[26],[11],[11],[32,0],[32,1],[32,2],[32,3],[32,6],[65,1],[16,builtin('__Porffor_object_lookup')],[34,9],[65,127],[70],[4,64],[32,0],[32,1],[16,builtin('__Porffor_object_getPrototype')],[34,8],[33,12],[34,11],[33,13],[32,12],[33,14],[2,127],...t([0,128],()=>[[32,14],[69],[32,14],[65,128,1],[70],[114],[4,64],[65,1],[12,1],[11]]),...t([7],()=>[[32,14],[65,7],[70],[4,64],[32,13],[69],[12,1],[11]]),[65,0],[11],[69],[4,64],[32,12],[65,7],[71],[4,64],[32,11],[183],[32,12],[16,builtin('__Porffor_object_underlying')],[34,8],[33,12],[33,11],[11],[32,11],[33,15],[32,12],[33,16],[3,64],[65,1],[4,64],[32,11],[32,12],[32,2],[32,3],[32,6],[65,1],[16,builtin('__Porffor_object_lookup')],[34,9],[65,127],[71],[4,64],[12,1],[26],[11],[32,11],[32,12],[16,builtin('__Porffor_object_getPrototype')],[34,8],[33,12],[33,11],[32,12],[65,7],[71],[4,64],[32,11],[183],[32,12],[16,builtin('__Porffor_object_underlying')],[34,8],[33,12],[33,11],[11],[32,11],[33,13],[32,12],[33,14],[2,127],...t([0,128],()=>[[32,14],[69],[32,14],[65,128,1],[70],[114],[4,64],[65,1],[12,1],[11]]),...t([7],()=>[[32,14],[65,7],[70],[4,64],[32,13],[69],[12,1],[11]]),[65,0],[11],[32,11],[32,15],[70],[114],[4,64],[12,1],[26],[11],[32,11],[33,15],[32,12],[33,16],[12,1],[11],[11],[32,9],[65,127],[71],[4,64],[32,9],[47,0,16],[34,17],[65,1],[113],[4,64],[32,9],[65,1],[16,builtin('__Porffor_object_accessorSet')],[33,8],[34,18],[69],[4,64],[32,4],[32,5],[15],[26],[11],[32,18],[33,21],[65,0],[65,128,1],[33,22],[183],[32,22],[32,0],[34,19],[32,1],[34,20],[33,22],[183],[32,22],[32,4],[32,5],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[32,21],[17,12,0],[33,8],[252,2],[26],[32,4],[32,5],[15],[26],[11],[11],[11],[32,0],[32,1],[16,builtin('__Porffor_object_isInextensible')],[4,64],...internalThrow(_,'TypeError',`Cannot add property to inextensible object`),[26],[11],[32,0],[47,0,0],[33,23],[32,0],[32,23],[65,1],[106],[59,0,0],[32,0],[65,8],[106],[32,23],[65,18],[108],[106],[34,9],[65,1],[32,2],[32,3],[32,6],[65,1],[16,builtin('__Porffor_object_writeKey')],[65,14],[33,10],[5],[32,9],[47,0,16],[34,17],[65,1],[113],[4,64],[32,9],[65,1],[16,builtin('__Porffor_object_accessorSet')],[33,8],[34,18],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property with no setter of object`),[26],[11],[32,18],[33,24],[65,0],[65,128,1],[33,22],[183],[32,22],[32,0],[34,19],[32,1],[34,20],[33,22],[183],[32,22],[32,4],[32,5],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[32,24],[17,12,0],[33,8],[252,2],[26],[32,4],[32,5],[15],[26],[11],[32,17],[65,8],[113],[69],[4,64],...internalThrow(_,'TypeError',`Cannot modify read-only property of object`),[26],[11],[32,17],[65,255,1],[113],[33,10],[11],[32,9],[32,4],[57,0,8],[32,9],[32,10],[32,5],[65,8],[116],[106],[59,0,16],[32,4],[32,5],[15]]"),
142
+ wasm:(_,{t,builtin,internalThrow})=>eval("[[32,0],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property of null`),[26],[11],[32,1],[65,7],[71],[4,64],[32,0],[183],[32,1],[16,builtin('__Porffor_object_underlying')],[34,8],[33,1],[33,0],[32,1],[65,7],[71],[4,64],[32,4],[32,5],[15],[26],[11],[11],[32,0],[32,1],[32,2],[32,3],[32,6],[65,1],[16,builtin('__Porffor_object_lookup')],[34,9],[65,127],[70],[4,64],[32,0],[32,1],[16,builtin('__Porffor_object_getPrototype')],[34,8],[33,12],[34,11],[33,13],[32,12],[33,14],[2,127],...t([0,128],()=>[[32,14],[69],[32,14],[65,128,1],[70],[114],[4,64],[65,1],[12,1],[11]]),...t([7],()=>[[32,14],[65,7],[70],[4,64],[32,13],[69],[12,1],[11]]),[65,0],[11],[69],[4,64],[32,12],[65,7],[71],[4,64],[32,11],[183],[32,12],[16,builtin('__Porffor_object_underlying')],[34,8],[33,12],[33,11],[11],[32,11],[33,15],[32,12],[33,16],[3,64],[65,1],[4,64],[32,11],[32,12],[32,2],[32,3],[32,6],[65,1],[16,builtin('__Porffor_object_lookup')],[34,9],[65,127],[71],[4,64],[12,1],[26],[11],[32,11],[32,12],[16,builtin('__Porffor_object_getPrototype')],[34,8],[33,12],[33,11],[32,12],[65,7],[71],[4,64],[32,11],[183],[32,12],[16,builtin('__Porffor_object_underlying')],[34,8],[33,12],[33,11],[11],[32,11],[33,13],[32,12],[33,14],[2,127],...t([0,128],()=>[[32,14],[69],[32,14],[65,128,1],[70],[114],[4,64],[65,1],[12,1],[11]]),...t([7],()=>[[32,14],[65,7],[70],[4,64],[32,13],[69],[12,1],[11]]),[65,0],[11],[32,11],[32,15],[70],[114],[4,64],[12,1],[26],[11],[32,11],[33,15],[32,12],[33,16],[12,1],[11],[11],[32,9],[65,127],[71],[4,64],[32,9],[47,0,16],[34,17],[65,1],[113],[4,64],[32,9],[65,1],[16,builtin('__Porffor_object_accessorSet')],[33,8],[34,18],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property with only getter`),[26],[11],[32,18],[33,21],[65,0],[65,128,1],[33,22],[183],[32,22],[32,0],[34,19],[32,1],[34,20],[33,22],[183],[32,22],[32,4],[32,5],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[32,21],[17,12,0],[33,8],[252,2],[26],[32,4],[32,5],[15],[26],[11],[11],[11],[32,0],[32,1],[16,builtin('__Porffor_object_isInextensible')],[4,64],...internalThrow(_,'TypeError',`Cannot add property to inextensible object`),[26],[11],[32,0],[47,0,0],[33,23],[32,0],[32,23],[65,1],[106],[59,0,0],[32,0],[65,8],[106],[32,23],[65,18],[108],[106],[34,9],[65,1],[32,2],[32,3],[32,6],[65,1],[16,builtin('__Porffor_object_writeKey')],[65,14],[33,10],[5],[32,9],[47,0,16],[34,17],[65,1],[113],[4,64],[32,9],[65,1],[16,builtin('__Porffor_object_accessorSet')],[33,8],[34,18],[69],[4,64],...internalThrow(_,'TypeError',`Cannot set property with only getter`),[26],[11],[32,18],[33,24],[65,0],[65,128,1],[33,22],[183],[32,22],[32,0],[34,19],[32,1],[34,20],[33,22],[183],[32,22],[32,4],[32,5],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[65,0],[183],[65,128,1],[32,24],[17,12,0],[33,8],[252,2],[26],[32,4],[32,5],[15],[26],[11],[32,17],[65,8],[113],[69],[4,64],...internalThrow(_,'TypeError',`Cannot modify read-only property of object`),[26],[11],[32,17],[65,255,1],[113],[33,10],[11],[32,9],[32,4],[57,0,8],[32,9],[32,10],[32,5],[65,8],[116],[106],[59,0,16],[32,4],[32,5],[15]]"),
143
143
  params:[127,127,127,127,124,127,127,127],typedParams:1,returns:[124,127],
144
144
  locals:[127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127],localNames:["obj","obj#type","key","key#type","value","value#type","hash","hash#type","#last_type","entryPtr","flags","proto","proto#type","#logicinner_tmp","#typeswitch_tmp1","lastProto","lastProto#type","tail","set","#call_val","#call_type","#indirect_10_callee","#swap","size","#indirect_11_callee"],
145
145
  table:1,usesTag:1,
@@ -1631,7 +1631,7 @@ locals:[127,124],localNames:["#newtarget","#newtarget#type","#this","#this#type"
1631
1631
  constr:1,
1632
1632
  }
1633
1633
  this.__Error_prototype_constructor$get = {
1634
- wasm:(_,{funcRef})=>eval("[...funcRef('Error'),[65,6],[15]]"),
1634
+ wasm:(_,{builtin})=>eval("[[16,builtin('#get_Error')],[184],[65,6],[15]]"),
1635
1635
  params:[124,127],typedParams:1,returns:[124,127],
1636
1636
  locals:[],localNames:["_this","_this#type"],
1637
1637
  }
@@ -1657,7 +1657,7 @@ locals:[127,124],localNames:["#newtarget","#newtarget#type","#this","#this#type"
1657
1657
  constr:1,
1658
1658
  }
1659
1659
  this.__AggregateError_prototype_constructor$get = {
1660
- wasm:(_,{funcRef})=>eval("[...funcRef('AggregateError'),[65,6],[15]]"),
1660
+ wasm:(_,{builtin})=>eval("[[16,builtin('#get_AggregateError')],[184],[65,6],[15]]"),
1661
1661
  params:[124,127],typedParams:1,returns:[124,127],
1662
1662
  locals:[],localNames:["_this","_this#type"],
1663
1663
  }
@@ -1683,7 +1683,7 @@ locals:[127,124],localNames:["#newtarget","#newtarget#type","#this","#this#type"
1683
1683
  constr:1,
1684
1684
  }
1685
1685
  this.__TypeError_prototype_constructor$get = {
1686
- wasm:(_,{funcRef})=>eval("[...funcRef('TypeError'),[65,6],[15]]"),
1686
+ wasm:(_,{builtin})=>eval("[[16,builtin('#get_TypeError')],[184],[65,6],[15]]"),
1687
1687
  params:[124,127],typedParams:1,returns:[124,127],
1688
1688
  locals:[],localNames:["_this","_this#type"],
1689
1689
  }
@@ -1709,7 +1709,7 @@ locals:[127,124],localNames:["#newtarget","#newtarget#type","#this","#this#type"
1709
1709
  constr:1,
1710
1710
  }
1711
1711
  this.__ReferenceError_prototype_constructor$get = {
1712
- wasm:(_,{funcRef})=>eval("[...funcRef('ReferenceError'),[65,6],[15]]"),
1712
+ wasm:(_,{builtin})=>eval("[[16,builtin('#get_ReferenceError')],[184],[65,6],[15]]"),
1713
1713
  params:[124,127],typedParams:1,returns:[124,127],
1714
1714
  locals:[],localNames:["_this","_this#type"],
1715
1715
  }
@@ -1735,7 +1735,7 @@ locals:[127,124],localNames:["#newtarget","#newtarget#type","#this","#this#type"
1735
1735
  constr:1,
1736
1736
  }
1737
1737
  this.__SyntaxError_prototype_constructor$get = {
1738
- wasm:(_,{funcRef})=>eval("[...funcRef('SyntaxError'),[65,6],[15]]"),
1738
+ wasm:(_,{builtin})=>eval("[[16,builtin('#get_SyntaxError')],[184],[65,6],[15]]"),
1739
1739
  params:[124,127],typedParams:1,returns:[124,127],
1740
1740
  locals:[],localNames:["_this","_this#type"],
1741
1741
  }
@@ -1761,7 +1761,7 @@ locals:[127,124],localNames:["#newtarget","#newtarget#type","#this","#this#type"
1761
1761
  constr:1,
1762
1762
  }
1763
1763
  this.__RangeError_prototype_constructor$get = {
1764
- wasm:(_,{funcRef})=>eval("[...funcRef('RangeError'),[65,6],[15]]"),
1764
+ wasm:(_,{builtin})=>eval("[[16,builtin('#get_RangeError')],[184],[65,6],[15]]"),
1765
1765
  params:[124,127],typedParams:1,returns:[124,127],
1766
1766
  locals:[],localNames:["_this","_this#type"],
1767
1767
  }
@@ -1787,7 +1787,7 @@ locals:[127,124],localNames:["#newtarget","#newtarget#type","#this","#this#type"
1787
1787
  constr:1,
1788
1788
  }
1789
1789
  this.__EvalError_prototype_constructor$get = {
1790
- wasm:(_,{funcRef})=>eval("[...funcRef('EvalError'),[65,6],[15]]"),
1790
+ wasm:(_,{builtin})=>eval("[[16,builtin('#get_EvalError')],[184],[65,6],[15]]"),
1791
1791
  params:[124,127],typedParams:1,returns:[124,127],
1792
1792
  locals:[],localNames:["_this","_this#type"],
1793
1793
  }
@@ -1813,7 +1813,7 @@ locals:[127,124],localNames:["#newtarget","#newtarget#type","#this","#this#type"
1813
1813
  constr:1,
1814
1814
  }
1815
1815
  this.__URIError_prototype_constructor$get = {
1816
- wasm:(_,{funcRef})=>eval("[...funcRef('URIError'),[65,6],[15]]"),
1816
+ wasm:(_,{builtin})=>eval("[[16,builtin('#get_URIError')],[184],[65,6],[15]]"),
1817
1817
  params:[124,127],typedParams:1,returns:[124,127],
1818
1818
  locals:[],localNames:["_this","_this#type"],
1819
1819
  }
@@ -1294,15 +1294,21 @@ const asmFuncToAsm = (scope, func, extra) => func(scope, {
1294
1294
  scope.initedGlobals ??= new Set();
1295
1295
  if (!scope.initedGlobals.has(name)) {
1296
1296
  scope.initedGlobals.add(name);
1297
- if (scope.globalInits?.[name]) out.unshift(
1298
- [ Opcodes.global_get, globals[globalName + '#glbl_inited'].idx ],
1299
- [ Opcodes.i32_eqz ],
1300
- [ Opcodes.if, Blocktype.void ],
1301
- ...asmFuncToAsm(scope, scope.globalInits[name]),
1302
- number(1, Valtype.i32),
1303
- [ Opcodes.global_set, globals[globalName + '#glbl_inited'].idx ],
1304
- [ Opcodes.end ]
1305
- );
1297
+ if (scope.globalInits?.[name]) {
1298
+ if (typeof scope.globalInits[name] === 'function') {
1299
+ out.unshift(
1300
+ [ Opcodes.global_get, globals[globalName + '#glbl_inited'].idx ],
1301
+ [ Opcodes.i32_eqz ],
1302
+ [ Opcodes.if, Blocktype.void ],
1303
+ ...asmFuncToAsm(scope, scope.globalInits[name]),
1304
+ number(1, Valtype.i32),
1305
+ [ Opcodes.global_set, globals[globalName + '#glbl_inited'].idx ],
1306
+ [ Opcodes.end ]
1307
+ );
1308
+ } else {
1309
+ globals[globalName].init = scope.globalInits[name];
1310
+ }
1311
+ }
1306
1312
  }
1307
1313
 
1308
1314
  return out;
@@ -1332,7 +1338,7 @@ const asmFuncToAsm = (scope, func, extra) => func(scope, {
1332
1338
  allocPage: (scope, name) => allocPage({ scope, pages }, name)
1333
1339
  }, extra);
1334
1340
 
1335
- const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTypes = [], globals: globalTypes = [], globalInits = [], returns = [], returnType, localNames = [], globalNames = [], table = false, constr = false, hasRestArgument = false, usesTag = false, usesImports = false, returnTypes } = {}) => {
1341
+ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTypes = [], globalInits = {}, returns = [], returnType, localNames = [], globalNames = [], table = false, constr = false, hasRestArgument = false, usesTag = false, usesImports = false, returnTypes } = {}) => {
1336
1342
  if (wasm == null) { // called with no built-in
1337
1343
  log.warning('codegen', `${name} has no built-in!`);
1338
1344
  wasm = [];
@@ -1364,28 +1370,8 @@ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTy
1364
1370
  funcs.push(func);
1365
1371
  funcIndex[name] = func.index;
1366
1372
 
1367
- if (typeof wasm === 'function') {
1368
- if (globalThis.precompile) wasm = [];
1369
- else wasm = asmFuncToAsm(func, wasm);
1370
- }
1371
-
1372
- if (globalTypes.length !== 0) {
1373
- // offset global ops for base global idx
1374
- let baseGlobalIdx, i = 0;
1375
- for (const type of globalTypes) {
1376
- if (baseGlobalIdx === undefined) baseGlobalIdx = globals['#ind'];
1377
-
1378
- globals[globalNames[i] ?? `${name}_global_${i}`] = { idx: globals['#ind']++, type, init: globalInits[i] ?? 0 };
1379
- i++;
1380
- }
1381
-
1382
- for (let i = 0; i < wasm.length; i++) {
1383
- const inst = wasm[i];
1384
- if (inst[0] === Opcodes.global_get || inst[0] === Opcodes.global_set) {
1385
- inst[1] += baseGlobalIdx;
1386
- }
1387
- }
1388
- }
1373
+ if (globalThis.precompile) wasm = [];
1374
+ else wasm = asmFuncToAsm(func, wasm);
1389
1375
 
1390
1376
  if (table) funcs.table = true;
1391
1377
  if (usesTag) {
@@ -2546,14 +2532,13 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2546
2532
  [ Opcodes.local_get, calleeLocal ],
2547
2533
  Opcodes.i32_to_u,
2548
2534
  [ Opcodes.call_indirect, args.length + 2, 0 ],
2549
- ...setLastType(scope),
2550
- ...(globalThis.precompile && valtypeBinary === Valtype.i32 ? [ Opcodes.i32_trunc_sat_f64_s ] : [])
2535
+ ...setLastType(scope)
2551
2536
  ],
2552
2537
 
2553
- default: decl.optional ? withType(scope, [ number(UNDEFINED) ], TYPES.undefined)
2538
+ default: decl.optional ? withType(scope, [ number(UNDEFINED, Valtype.f64) ], TYPES.undefined)
2554
2539
  : internalThrow(scope, 'TypeError', `${unhackName(name)} is not a function`, Valtype.f64)
2555
2540
  }, Valtype.f64),
2556
- ...(valtypeBinary === Valtype.i32 && scope.returns[0] !== Valtype.f64 ? [ [ Opcodes.f64_convert_i32_s ] ] : [])
2541
+ ...(valtypeBinary === Valtype.i32 ? [ Opcodes.i32_trunc_sat_f64_s ] : [])
2557
2542
  ];
2558
2543
  }
2559
2544
 
@@ -3639,6 +3624,71 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3639
3624
 
3640
3625
  const op = decl.operator.slice(0, -1) || '=';
3641
3626
 
3627
+ // short-circuit behavior for logical assignment operators
3628
+ if (op === '||' || op === '&&' || op === '??') {
3629
+ // for logical assignment ops, it is not left @= right -> left = left @ right
3630
+ // instead, left @ (left = right)
3631
+ // eg, x &&= y -> x && (x = y)
3632
+ if (local !== undefined) {
3633
+ // fast path: just assigning to a local
3634
+ setInferred(scope, name, knownType(scope, getNodeType(scope, decl)), isGlobal);
3635
+ return [
3636
+ ...performOp(scope, op, [
3637
+ [ isGlobal ? Opcodes.global_get : Opcodes.local_get, local.idx ]
3638
+ ], [
3639
+ ...generate(scope, decl.right, isGlobal, name),
3640
+ [ isGlobal ? Opcodes.global_set : Opcodes.local_set, local.idx ],
3641
+ [ isGlobal ? Opcodes.global_get : Opcodes.local_get, local.idx ]
3642
+ ], getType(scope, name), getNodeType(scope, decl.right)),
3643
+ ...setType(scope, name, getLastType(scope), true)
3644
+ ];
3645
+ } else if (type === 'MemberExpression' && decl.left.computed) {
3646
+ // special path: cache properties for computed members so they are not evaluated twice
3647
+ // eg, x[y] &&= z -> (a = y, x[a] = (x[a] = z))
3648
+ const propTmp = localTmp(scope, '#logical_prop');
3649
+ const propTypeTmp = localTmp(scope, '#logical_prop#type', Valtype.i32);
3650
+
3651
+ const member = {
3652
+ type: 'MemberExpression',
3653
+ object: decl.left.object,
3654
+ property: { type: 'Identifier', name: '#logical_prop' },
3655
+ computed: true
3656
+ };
3657
+
3658
+ return [
3659
+ ...generate(scope, decl.left.property),
3660
+ [ Opcodes.local_set, propTmp ],
3661
+ ...getNodeType(scope, decl.left.property),
3662
+ [ Opcodes.local_set, propTypeTmp ],
3663
+
3664
+ ...generate(scope, {
3665
+ type: 'LogicalExpression',
3666
+ operator: op,
3667
+ left: member,
3668
+ right: {
3669
+ type: 'AssignmentExpression',
3670
+ operator: '=',
3671
+ left: member,
3672
+ right: decl.right
3673
+ }
3674
+ }, _global, _name, valueUnused)
3675
+ ];
3676
+ } else {
3677
+ // other: generate as LogicalExpression
3678
+ return generate(scope, {
3679
+ type: 'LogicalExpression',
3680
+ operator: op,
3681
+ left: decl.left,
3682
+ right: {
3683
+ type: 'AssignmentExpression',
3684
+ operator: '=',
3685
+ left: decl.left,
3686
+ right: decl.right
3687
+ }
3688
+ }, _global, _name, valueUnused);
3689
+ }
3690
+ }
3691
+
3642
3692
  // hack: .length setter
3643
3693
  if (type === 'MemberExpression' && decl.left.property.name === 'length' && !decl._internalAssign) {
3644
3694
  const newValueTmp = !valueUnused && localTmp(scope, '__length_setter_tmp');
@@ -4074,27 +4124,6 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
4074
4124
  return out;
4075
4125
  }
4076
4126
 
4077
- if (op === '||' || op === '&&' || op === '??') {
4078
- // todo: is this needed?
4079
- // for logical assignment ops, it is not left @= right ~= left = left @ right
4080
- // instead, left @ (left = right)
4081
- // eg, x &&= y ~= x && (x = y)
4082
-
4083
- setInferred(scope, name, knownType(scope, getNodeType(scope, decl)), isGlobal);
4084
-
4085
- return [
4086
- ...performOp(scope, op, [
4087
- [ isGlobal ? Opcodes.global_get : Opcodes.local_get, local.idx ]
4088
- ], [
4089
- ...generate(scope, decl.right, isGlobal, name),
4090
- [ isGlobal ? Opcodes.global_set : Opcodes.local_set, local.idx ],
4091
- [ isGlobal ? Opcodes.global_get : Opcodes.local_get, local.idx ]
4092
- ], getType(scope, name), getNodeType(scope, decl.right)),
4093
-
4094
- ...setType(scope, name, getLastType(scope), true)
4095
- ];
4096
- }
4097
-
4098
4127
  const out = setLocalWithType(
4099
4128
  scope, name, isGlobal,
4100
4129
  performOp(scope, op, [
@@ -7089,7 +7118,7 @@ const internalConstrs = {
7089
7118
  }
7090
7119
  };
7091
7120
 
7092
- let globals, tags, exceptions, funcs, indirectFuncs, funcIndex, currentFuncIndex, depth, pages, data, typeswitchDepth, usedTypes, coctc, globalInfer, builtinFuncs, builtinVars, prototypeFuncs;
7121
+ let globals, tags, exceptions, funcs, indirectFuncs, funcIndex, currentFuncIndex, depth, pages, data, typeswitchDepth, usedTypes, coctc, globalInfer, builtinFuncs, builtinVars, prototypeFuncs, lastValtype;
7093
7122
  export default program => {
7094
7123
  globals = { ['#ind']: 0 };
7095
7124
  tags = [];
@@ -7119,12 +7148,16 @@ export default program => {
7119
7148
  Opcodes.load = valtypeBinary === Valtype.i32 ? Opcodes.i32_load : Opcodes.f64_load;
7120
7149
  Opcodes.store = valtypeBinary === Valtype.i32 ? Opcodes.i32_store : Opcodes.f64_store;
7121
7150
 
7122
- builtinFuncs = new BuiltinFuncs();
7123
- builtinVars = new BuiltinVars({ builtinFuncs });
7124
- prototypeFuncs = new PrototypeFuncs();
7151
+ // keep builtins between compiles as much as possible
7152
+ if (lastValtype !== valtypeBinary) {
7153
+ lastValtype = valtypeBinary;
7154
+ builtinFuncs = new BuiltinFuncs();
7155
+ builtinVars = new BuiltinVars({ builtinFuncs });
7156
+ prototypeFuncs = new PrototypeFuncs();
7125
7157
 
7126
- const getObjectName = x => x.startsWith('__') && x.slice(2, x.indexOf('_', 2));
7127
- objectHackers = ['assert', 'compareArray', 'Test262Error', ...new Set(Object.keys(builtinFuncs).map(getObjectName).concat(Object.keys(builtinVars).map(getObjectName)).filter(x => x))];
7158
+ const getObjectName = x => x.startsWith('__') && x.slice(2, x.indexOf('_', 2));
7159
+ objectHackers = ['assert', 'compareArray', 'Test262Error', ...new Set(Object.keys(builtinFuncs).map(getObjectName).concat(Object.keys(builtinVars).map(getObjectName)).filter(x => x))];
7160
+ }
7128
7161
 
7129
7162
  const [ main ] = generateFunc({}, {
7130
7163
  type: 'Program',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "An ahead-of-time JavaScript compiler",
4
- "version": "0.57.31",
4
+ "version": "0.57.33",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runtime/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.57.31';
3
+ globalThis.version = '0.57.33';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
@@ -68,7 +68,7 @@ if (process.argv.includes('--help') || process.argv.includes('-h')) {
68
68
  'exception-mode': 'Exception mode to use (lut|\x1B[1mstack\x1B[0m)',
69
69
  'fast-length': 'Non-compliant optimization to make .length faster',
70
70
  'profile-compiler': 'Log general compiler performance (on by default when compiling to a file)',
71
- prng: 'PRNG algorithm to use (lcg32|xorshift32+|xorshift64+|\x1B[1mxorshift128+\x1B[0m|xoroshiro128+|xoshiro128+)'
71
+ prng: 'PRNG algorithm to use (xorshift32+|xorshift64+|\x1B[1mxorshift128+\x1B[0m|xoroshiro128+|xoshiro128+)'
72
72
  })) {
73
73
  flag = '-' + flag;
74
74
  if (flag.length > 3) flag = '-' + flag;