subclass.js (1095B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const GeneratorFunction = function*(){}.constructor; 6 7 class MyGen extends GeneratorFunction {} 8 9 // MyGen inherits from %GeneratorFunction%. 10 assertEq(Object.getPrototypeOf(MyGen), GeneratorFunction); 11 12 // MyGen.prototype inherits from %Generator%. 13 assertEq(Object.getPrototypeOf(MyGen.prototype), GeneratorFunction.prototype); 14 15 var fn = new MyGen("yield* [1, 2, 3]"); 16 17 // fn inherits from MyGen.prototype. 18 assertEq(Object.getPrototypeOf(fn), MyGen.prototype); 19 20 // fn.prototype inherits from %GeneratorPrototype%. 21 assertEq(Object.getPrototypeOf(fn.prototype), GeneratorFunction.prototype.prototype); 22 23 // Ensure the new generator function can be executed. 24 var it = fn(); 25 26 // it inherits from fn.prototype. 27 assertEq(Object.getPrototypeOf(it), fn.prototype); 28 29 // Computes the expected result. 30 assertEqArray([...it], [1, 2, 3]); 31 32 if (typeof reportCompare === "function") 33 reportCompare(0, 0);