porffor 0.57.33 → 0.58.0

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.
@@ -6226,30 +6226,61 @@ const generateClass = (scope, decl) => {
6226
6226
  func.generate();
6227
6227
 
6228
6228
  if (decl.superClass) {
6229
+ const superTmp = localTmp(scope, '#superclass');
6230
+ const superTypeTmp = localTmp(scope, '#superclass#type', Valtype.i32);
6231
+
6229
6232
  out.push(
6230
6233
  // class Foo {}
6231
6234
  // class Bar extends Foo {}
6232
- // Bar.__proto__ = Foo
6233
- ...generate(scope, {
6234
- type: 'CallExpression',
6235
- callee: { type: 'Identifier', name: '__Porffor_object_setPrototype' },
6236
- arguments: [
6237
- root,
6238
- decl.superClass
6239
- ]
6240
- }),
6241
- [ Opcodes.drop ],
6235
+ ...generate(scope, decl.superClass),
6236
+ [ Opcodes.local_set, superTmp ],
6237
+ ...getNodeType(scope, decl.superClass),
6238
+ [ Opcodes.local_tee, superTypeTmp ],
6242
6239
 
6243
- // Bar.prototype.__proto__ = Foo.prototype
6244
- ...generate(scope, {
6245
- type: 'CallExpression',
6246
- callee: { type: 'Identifier', name: '__Porffor_object_setPrototype' },
6247
- arguments: [
6248
- proto,
6249
- getObjProp(decl.superClass, 'prototype')
6250
- ]
6251
- }),
6252
- [ Opcodes.drop ]
6240
+ // check if Foo is null, if so special case
6241
+ // see also: https://github.com/tc39/ecma262/pull/1321
6242
+ number(TYPES.object, Valtype.i32),
6243
+ [ Opcodes.i32_eq ],
6244
+ [ Opcodes.local_get, superTmp ],
6245
+ ...Opcodes.eqz,
6246
+ [ Opcodes.i32_and ],
6247
+ [ Opcodes.if, Blocktype.void ],
6248
+ // Bar.prototype.__proto__ = null
6249
+ ...generate(scope, {
6250
+ type: 'CallExpression',
6251
+ callee: { type: 'Identifier', name: '__Porffor_object_setPrototype' },
6252
+ arguments: [
6253
+ proto,
6254
+ { type: 'Literal', value: null }
6255
+ ]
6256
+ }),
6257
+ [ Opcodes.drop ],
6258
+ [ Opcodes.else ],
6259
+ // Bar.__proto__ = Foo
6260
+ ...generate(scope, {
6261
+ type: 'CallExpression',
6262
+ callee: { type: 'Identifier', name: '__Porffor_object_setPrototype' },
6263
+ arguments: [
6264
+ root,
6265
+ { type: 'Identifier', name: '#superclass' }
6266
+ ]
6267
+ }),
6268
+ [ Opcodes.drop ],
6269
+
6270
+ // Bar.prototype.__proto__ = Foo.prototype
6271
+ ...generate(scope, {
6272
+ type: 'CallExpression',
6273
+ callee: { type: 'Identifier', name: '__Porffor_object_setPrototype' },
6274
+ arguments: [
6275
+ proto,
6276
+ getObjProp(
6277
+ { type: 'Identifier', name: '#superclass' },
6278
+ 'prototype'
6279
+ )
6280
+ ]
6281
+ }),
6282
+ [ Opcodes.drop ],
6283
+ [ Opcodes.end ]
6253
6284
  );
6254
6285
  }
6255
6286
 
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.33",
4
+ "version": "0.58.0",
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.33';
3
+ globalThis.version = '0.58.0';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {