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.
- package/compiler/codegen.js +51 -20
- package/package.json +1 -1
- package/runtime/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -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
|
-
|
6233
|
-
|
6234
|
-
|
6235
|
-
|
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
|
-
//
|
6244
|
-
|
6245
|
-
|
6246
|
-
|
6247
|
-
|
6248
|
-
|
6249
|
-
|
6250
|
-
|
6251
|
-
|
6252
|
-
|
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