1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15(function StoreToSuper () { 16 "use strict"; 17 class A { 18 s() { 19 super.bla = 10; 20 } 21 }; 22 23 let a = new A(); 24 (new A).s.call(a); 25 assert_equal(10 == a.bla, true); 26 27 try { 28 (new A).s.call(undefined); 29 assert_unreachable(); 30 } catch (error) { 31 assert_equal(error instanceof TypeError, true); 32 } 33 34 try { 35 (new A).s.call(42); 36 assert_unreachable(); 37 } catch (error) { 38 assert_equal(error instanceof TypeError, true); 39 } 40 41 try { 42 (new A).s.call(null); 43 assert_unreachable(); 44 } catch (error) { 45 assert_equal(error instanceof TypeError, true); 46 } 47 48 try { 49 (new A).s.call("abc"); 50 assert_unreachable(); 51 } catch (error) { 52 assert_equal(error instanceof TypeError, true); 53 } 54 55})(); 56 57 58(function LoadFromSuper () { 59 "use strict"; 60 class A { 61 s() { 62 return super.bla; 63 } 64 }; 65 66 let a = new A(); 67 assert_equal(undefined == (new A).s.call(a), true); 68 assert_equal(undefined == (new A).s.call(undefined), true); 69 assert_equal(undefined == (new A).s.call(42), true); 70 assert_equal(undefined == (new A).s.call(null), true); 71 assert_equal(undefined == (new A).s.call("abc"), true); 72})(); 73 74class TestA { 75 constructor() { 76 assert_equal("TestA "+this.constructor.name+" "+new.target.name, 'TestA TestC TestC'); 77 } 78} 79class TestB extends TestA { 80 constructor() { 81 super(); 82 assert_equal("TestB "+this.constructor.name+" "+new.target.name, 'TestB TestC TestC'); 83 this.test(); 84 } 85} 86class TestC { 87 constructor() { 88 ("TestC", this.constructor.name, new.target.name); 89 } 90 test() { 91 assert_equal("TestC", 'TestC'); 92 } 93} 94let c1 = Reflect.construct(TestB, [], TestC.prototype.constructor); 95let c2 = Reflect.construct(TestB, [], c1.constructor); 96 97test_end();