| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | load("test-common.js"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | try { | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class X { | 
					
						
							|  |  |  |     constructor() { | 
					
						
							|  |  |  |       this.x = 3; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     getX() { | 
					
						
							|  |  |  |       return 3; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     init() { | 
					
						
							|  |  |  |       this.y = 3; | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assert(X.name === "X"); | 
					
						
							|  |  |  |   assert(X.length === 0); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class Y extends X { | 
					
						
							|  |  |  |     init() { | 
					
						
							|  |  |  |       super.init(); | 
					
						
							|  |  |  |       this.y += 3; | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assert(new Y().getX() === 3); | 
					
						
							|  |  |  |   assert(new Y().x === 3); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   let x = new X(); | 
					
						
							|  |  |  |   assert(x.x === 3); | 
					
						
							|  |  |  |   assert(x.getX() === 3); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   let y = new Y(); | 
					
						
							|  |  |  |   assert(y.x === 3); | 
					
						
							|  |  |  |   assert(y.y === undefined); | 
					
						
							|  |  |  |   y.init(); | 
					
						
							|  |  |  |   assert(y.y === 6); | 
					
						
							|  |  |  |   assert(y.hasOwnProperty("y")); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class Foo { | 
					
						
							|  |  |  |     constructor(x) { | 
					
						
							|  |  |  |       this.x = x; | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   } | 
					
						
							|  |  |  |   assert(Foo.length === 1); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class Bar extends Foo { | 
					
						
							|  |  |  |     constructor() { | 
					
						
							|  |  |  |       super(5); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class Baz { | 
					
						
							|  |  |  |     constructor() { | 
					
						
							|  |  |  |       this.foo = 55; | 
					
						
							|  |  |  |       this._bar = 33; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     get bar() { | 
					
						
							|  |  |  |       return this._bar; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     set bar(value) { | 
					
						
							|  |  |  |       this._bar = value; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     ["get" + "Foo"]() { | 
					
						
							|  |  |  |       return this.foo; | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     static get staticFoo() { | 
					
						
							|  |  |  |       assert(this === Baz); | 
					
						
							|  |  |  |       return 11; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   let barPropertyDescriptor = Object.getOwnPropertyDescriptor(Baz.prototype, "bar"); | 
					
						
							|  |  |  |   assert(barPropertyDescriptor.get.name === "get bar"); | 
					
						
							|  |  |  |   assert(barPropertyDescriptor.set.name === "set bar"); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   let baz = new Baz(); | 
					
						
							|  |  |  |   assert(baz.foo === 55); | 
					
						
							|  |  |  |   assert(baz.bar === 33); | 
					
						
							|  |  |  |   baz.bar = 22; | 
					
						
							|  |  |  |   assert(baz.bar === 22); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assert(baz.getFoo() === 55); | 
					
						
							|  |  |  |   assert(Baz.staticFoo === 11); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assert(new Bar().x === 5); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class ExtendsFunction extends function () { | 
					
						
							|  |  |  |     this.foo = 22; | 
					
						
							|  |  |  |   } {} | 
					
						
							|  |  |  |   assert(new ExtendsFunction().foo === 22); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class ExtendsString extends String {} | 
					
						
							|  |  |  |   assert(new ExtendsString() instanceof String); | 
					
						
							|  |  |  |   assert(new ExtendsString() instanceof ExtendsString); | 
					
						
							|  |  |  |   assert(new ExtendsString("abc").charAt(1) === "b"); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class MyWeirdString extends ExtendsString { | 
					
						
							|  |  |  |     charAt(i) { | 
					
						
							|  |  |  |       return "#" + super.charAt(i); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   } | 
					
						
							|  |  |  |   assert(new MyWeirdString("abc").charAt(1) === "#b"); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class ExtendsNull extends null {} | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertThrowsError( | 
					
						
							|  |  |  |     () => { | 
					
						
							|  |  |  |       new ExtendsNull(); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       error: ReferenceError, | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   ); | 
					
						
							|  |  |  |   assert(Object.getPrototypeOf(ExtendsNull.prototype) === null); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class ExtendsClassExpression extends class { | 
					
						
							|  |  |  |     constructor(x) { | 
					
						
							|  |  |  |       this.x = x; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } { | 
					
						
							|  |  |  |     constructor(y) { | 
					
						
							|  |  |  |       super(5); | 
					
						
							|  |  |  |       this.y = 6; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   let extendsClassExpression = new ExtendsClassExpression(); | 
					
						
							|  |  |  |   assert(extendsClassExpression.x === 5); | 
					
						
							|  |  |  |   assert(extendsClassExpression.y === 6); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class InStrictMode { | 
					
						
							|  |  |  |     constructor() { | 
					
						
							|  |  |  |       assert(isStrictMode()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     method() { | 
					
						
							|  |  |  |       assert(isStrictMode()); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   let resultOfAnExpression = new (class { | 
					
						
							|  |  |  |     constructor(x) { | 
					
						
							|  |  |  |       this.x = x; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     getX() { | 
					
						
							|  |  |  |       return this.x + 10; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   })(55); | 
					
						
							|  |  |  |   assert(resultOfAnExpression.x === 55); | 
					
						
							|  |  |  |   assert(resultOfAnExpression.getX() === 65); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   let ClassExpression = class Foo {}; | 
					
						
							|  |  |  |   assert(ClassExpression.name === "Foo"); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   new InStrictMode().method(); | 
					
						
							|  |  |  |   assert(!isStrictMode()); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertIsSyntaxError(`
 | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |         class GetterWithArgument { | 
					
						
							|  |  |  |             get foo(bar) { | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertIsSyntaxError(`
 | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |         class SetterWithNoArgumetns { | 
					
						
							|  |  |  |             set foo() { | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertIsSyntaxError(`
 | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |         class SetterWithMoreThanOneArgument { | 
					
						
							|  |  |  |             set foo(bar, baz) { | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertIsSyntaxError(`
 | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |         class FooBase {} | 
					
						
							|  |  |  |         class IsASyntaxError extends FooBase { | 
					
						
							|  |  |  |             bar() { | 
					
						
							|  |  |  |                 function f() { super.baz; } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertIsSyntaxError(`
 | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |         class NoBaseSuper { | 
					
						
							|  |  |  |             constructor() { | 
					
						
							|  |  |  |                 super(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     `);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertThrowsError( | 
					
						
							|  |  |  |     () => { | 
					
						
							|  |  |  |       class BadExtends extends 3 {} | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       error: TypeError, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   assertThrowsError( | 
					
						
							|  |  |  |     () => { | 
					
						
							|  |  |  |       class BadExtends extends undefined {} | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       error: TypeError, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class SuperNotASyntaxError { | 
					
						
							|  |  |  |     bar() { | 
					
						
							|  |  |  |       () => { | 
					
						
							|  |  |  |         super.baz; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   class SuperNoBasePropertyLookup { | 
					
						
							|  |  |  |     constructor() { | 
					
						
							|  |  |  |       super.foo; | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   assertThrowsError( | 
					
						
							|  |  |  |     () => { | 
					
						
							|  |  |  |       class Base {} | 
					
						
							|  |  |  |       class DerivedDoesntCallSuper extends Base { | 
					
						
							|  |  |  |         constructor() { | 
					
						
							|  |  |  |           this; | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |       new DerivedDoesntCallSuper(); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       error: ReferenceError, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  |   assertThrowsError( | 
					
						
							|  |  |  |     () => { | 
					
						
							|  |  |  |       class Base {} | 
					
						
							|  |  |  |       class CallsSuperTwice extends Base { | 
					
						
							|  |  |  |         constructor() { | 
					
						
							|  |  |  |           super(); | 
					
						
							|  |  |  |           super(); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |       new CallsSuperTwice(); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       error: ReferenceError, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   console.log("PASS"); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | } catch (e) { | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   console.log("FAIL: " + e); | 
					
						
							| 
									
										
										
										
											2020-06-08 13:31:21 -05:00
										 |  |  | } |