porffor 0.30.12 → 0.30.13

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.
@@ -398,6 +398,7 @@ const generateReturn = (scope, decl) => {
398
398
  !globalThis.precompile // skip in precompiled built-ins, we should not require this and handle it ourselves
399
399
  ) {
400
400
  // ignore return value and return this if being constructed
401
+ // todo: only do this when trying to return a primitive?
401
402
  out.push(
402
403
  // ...truthy(scope, [ [ Opcodes.local_get, '#newtarget' ] ], [ [ Opcodes.local_get, '#newtarget#type' ] ], false, true),
403
404
  [ Opcodes.local_get, '#newtarget' ],
@@ -1804,7 +1805,6 @@ const generateExp = (scope, decl) => {
1804
1805
  if (expression.value === 'use strict') {
1805
1806
  scope.strict = true;
1806
1807
  }
1807
- return [];
1808
1808
  }
1809
1809
 
1810
1810
  const out = generate(scope, expression, undefined, undefined, Prefs.optUnused);
@@ -1999,9 +1999,10 @@ const createThisArg = (scope, decl, knownThis = undefined) => {
1999
1999
  ];
2000
2000
  }
2001
2001
 
2002
+ // do not generate globalThis for builtins
2002
2003
  return [
2003
- ...generate(scope, { type: 'Identifier', name: 'globalThis' }),
2004
- ...getType(scope, 'globalThis')
2004
+ ...number(NULL),
2005
+ ...number(TYPES.object, Valtype.i32)
2005
2006
  ];
2006
2007
  }
2007
2008
  };
@@ -2340,9 +2341,6 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2340
2341
  }
2341
2342
  }
2342
2343
 
2343
- // TODO: only allows callee as identifier
2344
- // if (!name) return todo(scope, `only identifier callees (got ${decl.callee.type})`);
2345
-
2346
2344
  let idx;
2347
2345
  if (Object.hasOwn(funcIndex, name)) idx = funcIndex[name];
2348
2346
  else if (Object.hasOwn(importedFuncs, name)) idx = importedFuncs[name];
@@ -2770,6 +2768,22 @@ const generateThis = (scope, decl, _global, _name) => {
2770
2768
  }
2771
2769
 
2772
2770
  return [
2771
+ // default this to globalThis
2772
+ [ Opcodes.local_get, '#this' ],
2773
+ Opcodes.i32_to_u,
2774
+ [ Opcodes.i32_eqz ],
2775
+ [ Opcodes.if, Blocktype.void ],
2776
+ [ Opcodes.local_get, '#this#type' ],
2777
+ ...number(TYPES.object, Valtype.i32),
2778
+ [ Opcodes.i32_eq ],
2779
+ [ Opcodes.if, Blocktype.void ],
2780
+ ...generate(scope, { type: 'Identifier', name: 'globalThis' }),
2781
+ [ Opcodes.local_set, '#this' ],
2782
+ ...getType(scope, 'globalThis'),
2783
+ [ Opcodes.local_set, '#this#type' ],
2784
+ [ Opcodes.end ],
2785
+ [ Opcodes.end ],
2786
+
2773
2787
  [ Opcodes.local_get, '#this' ],
2774
2788
  ...setLastType(scope, [ [ Opcodes.local_get, '#this#type' ] ])
2775
2789
  ];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.30.12+4b2d895aa",
4
+ "version": "0.30.13+047f11fe9",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.30.12+4b2d895aa';
3
+ globalThis.version = '0.30.13+047f11fe9';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {