porffor 0.34.20 → 0.34.21

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/CONTRIBUTING.md CHANGED
@@ -366,7 +366,7 @@ builtins/tostring_number: impl radix
366
366
 
367
367
  ## Test262
368
368
 
369
- For the first time, ensure you run `./test262/setup.sh`.
369
+ For the first time, ensure you run `./test262/setup.sh` (Unix) or `.\test262\setup.cmd` (Windows).
370
370
 
371
371
  Run `node test262` to run all the tests and get an output of total overall test results.
372
372
 
@@ -33,15 +33,11 @@ const encodeNames = funcs => {
33
33
  funcs.map(x => unsignedLEB128(x.asmIndex).concat(encodeString(x.name))),
34
34
  );
35
35
  const localsSection = encodeVector(
36
- funcs.map(x =>
37
- unsignedLEB128(x.asmIndex).concat(
38
- encodeVector(
39
- Object.entries(x.locals).map(([name, local]) =>
40
- unsignedLEB128(local.idx).concat(encodeString(name)),
41
- ),
42
- ),
43
- ),
44
- ),
36
+ funcs.map(x => unsignedLEB128(x.asmIndex).concat(encodeVector(
37
+ Object.entries(x.locals).map(([name, local]) =>
38
+ unsignedLEB128(local.idx).concat(encodeString(name))
39
+ )
40
+ )))
45
41
  );
46
42
 
47
43
  return [
@@ -49,7 +45,7 @@ const encodeNames = funcs => {
49
45
  ...encodeSection(1, functionsSection),
50
46
  ...encodeSection(2, localsSection),
51
47
  ];
52
- }
48
+ };
53
49
 
54
50
  export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) => {
55
51
  const types = [], typeCache = {};
@@ -5404,7 +5404,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
5404
5404
  const type = TYPES[x.split('_prototype')[0].slice(2).toLowerCase()];
5405
5405
  if (type == null) continue;
5406
5406
 
5407
- // do not __proto__ primitive hack for objects
5407
+ // do not __proto__ primitive hack for objects or functions
5408
5408
  if (type === TYPES.object || type === TYPES.function) continue;
5409
5409
 
5410
5410
  const ident = {
@@ -5721,27 +5721,34 @@ const generateClass = (scope, decl) => {
5721
5721
 
5722
5722
  if (decl.superClass) {
5723
5723
  out.push(
5724
- ...generateCall(scope, {
5725
- type: 'CallExpression',
5726
- callee: {
5727
- type: 'Identifier',
5728
- name: '__Porffor_object_assignAll'
5729
- },
5730
- arguments: [
5731
- proto,
5732
- {
5733
- type: 'MemberExpression',
5734
- object: decl.superClass,
5735
- property: {
5736
- type: 'Identifier',
5737
- name: 'prototype'
5738
- },
5739
- computed: false,
5740
- optional: false
5741
- }
5742
- ]
5743
- }),
5744
- [ Opcodes.drop ]
5724
+ // ...generateCall(scope, {
5725
+ // type: 'CallExpression',
5726
+ // callee: {
5727
+ // type: 'Identifier',
5728
+ // name: '__Porffor_object_assignAll'
5729
+ // },
5730
+ // arguments: [
5731
+ // proto,
5732
+ // {
5733
+ // type: 'MemberExpression',
5734
+ // object: decl.superClass,
5735
+ // property: {
5736
+ // type: 'Identifier',
5737
+ // name: 'prototype'
5738
+ // },
5739
+ // computed: false,
5740
+ // optional: false
5741
+ // }
5742
+ // ]
5743
+ // }),
5744
+ // [ Opcodes.drop ]
5745
+
5746
+ // class Foo {}
5747
+ // class Bar extends Foo {}
5748
+ // Bar.__proto__ = Foo
5749
+ // Bar.prototype.__proto__ = Foo.prototype
5750
+ ...generate(scope, setObjProp(root, '__proto__', decl.superClass)),
5751
+ ...generate(scope, setObjProp(getObjProp(root, 'prototype'), '__proto__', getObjProp(decl.superClass, 'prototype')))
5745
5752
  );
5746
5753
  }
5747
5754
 
@@ -6024,8 +6031,8 @@ const generateFunc = (scope, decl, outUnused = false) => {
6024
6031
  else func.returns = [];
6025
6032
  }
6026
6033
 
6027
- // inject promise job runner func at the end of main if job queue is used
6028
- if (Object.hasOwn(funcIndex, '__ecma262_HostEnqueuePromiseJob')) {
6034
+ // inject promise job runner func at the end of main if promises are made
6035
+ if (Object.hasOwn(funcIndex, 'Promise') || Object.hasOwn(funcIndex, '__Promise_resolve') || Object.hasOwn(funcIndex, '__Promise_reject')) {
6029
6036
  wasm.push(
6030
6037
  [ Opcodes.call, includeBuiltin(scope, '__Porffor_promise_runJobs').index ],
6031
6038
  [ Opcodes.drop ],
@@ -6358,8 +6365,8 @@ export default program => {
6358
6365
 
6359
6366
  delete globals['#ind'];
6360
6367
 
6361
- // if blank main func and other exports, remove it
6362
- if (main.wasm.length === 0 && funcs.reduce((acc, x) => acc + (x.export ? 1 : 0), 0) > 1) funcs.splice(main.index - importedFuncs.length, 1);
6368
+ // if wanted and blank main func and other exports, remove it
6369
+ if (Prefs.rmBlankMain && main.wasm.length === 0 && funcs.some(x => x.export)) funcs.splice(main.index - importedFuncs.length, 1);
6363
6370
 
6364
6371
  // make ~empty funcs for never generated funcs
6365
6372
  // todo: these should just be deleted once able
package/compiler/wrap.js CHANGED
@@ -137,6 +137,9 @@ ${flags & 0b0001 ? ` get func idx: ${get}
137
137
  // eg: __String_prototype_toLowerCase -> toLowerCase
138
138
  if (name.startsWith('__')) name = name.split('_').pop();
139
139
 
140
+ // anonymous functions
141
+ if (name.startsWith('#')) name = '';
142
+
140
143
  // make fake empty func for repl/etc
141
144
  return {[name]() {}}[name];
142
145
  }
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.34.20+ef2ae4c4d",
4
+ "version": "0.34.21+7de83876c",
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.34.20+ef2ae4c4d';
3
+ globalThis.version = '0.34.21+7de83876c';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {