mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-24 06:14:01 +08:00
superCallStmt asserted the class base before checking for a callable base. A class that extends an ordinary function constructor has no base class info, so the assertion held null. Node ignores the unused value; the native compiler throws the TypeError of a non-null assertion that held null, and failed to compile programs with such classes (for example the Effect stream fixtures). The base is now read after that case returns.
28 lines
768 B
JavaScript
28 lines
768 B
JavaScript
// Classes whose base is an ordinary function constructor, with a declared
|
|
// constructor calling super and with the implicit derived constructor.
|
|
function Shape(name, sides) {
|
|
this.name = name;
|
|
this.sides = sides;
|
|
}
|
|
Shape.prototype.describe = function () {
|
|
return `${this.name} with ${this.sides} sides`;
|
|
};
|
|
|
|
class Polygon extends Shape {
|
|
constructor(name, sides, length) {
|
|
super(name, sides);
|
|
this.length = length;
|
|
}
|
|
perimeter() {
|
|
return this.sides * this.length;
|
|
}
|
|
}
|
|
|
|
class Unnamed extends Shape {}
|
|
|
|
const square = new Polygon("square", 4, 3);
|
|
console.log(square.describe(), square.perimeter());
|
|
console.log(square instanceof Polygon);
|
|
const shape = new Unnamed("triangle", 3);
|
|
console.log(shape.describe(), Object.keys(shape).join(","));
|