1/** 2 * Copyright (c) 2025 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 16let path = 'export12'; //1.2 17import(path) 18 .then((value) => { 19 // getProperty 20 ASSERT_TRUE(value !== undefined); 21 ASSERT_TRUE(typeof value.ClassA === 'function'); 22 23 let ClassA = value.ClassA; 24 let a = new ClassA(); 25 ASSERT_TRUE(typeof value.foo === 'function' && value.foo() === 'this is 1.2 foo ets'); 26 ASSERT_TRUE(value.a === 'this is 1.2 classA ets'); 27 28 // deleteProperty 29 try { 30 delete value.ClassA; 31 } catch (error) { 32 ASSERT_TRUE(error.toString() === 'TypeError: Cannot delete property'); 33 let ClassA = value.ClassA; 34 let a = new ClassA(); 35 ASSERT_TRUE(typeof a.foo === 'function' && value.foo() === 'this is 1.2 foo ets'); 36 } 37 38 // deleteProperty 39 try { 40 delete value.a; 41 } catch (error) { 42 ASSERT_TRUE(error.toString() === 'TypeError: Cannot delete property'); 43 ASSERT_TRUE(value.a === 'this is 1.2 classA ets'); 44 } 45 46 // deleteProperty 47 try { 48 delete value.foo; 49 } catch (error) { 50 ASSERT_TRUE(error.toString() === 'TypeError: Cannot delete property'); 51 ASSERT_TRUE(typeof value.foo === 'function' && value.foo() === 'this is 1.2 foo ets'); 52 } 53 54 // ownPropertyKeys 55 /** 56 ClassA 57 length 58 prototype 59 name 60 a 61 main 62 foo 63 _$init$_ 64 */ 65 let keys = Reflect.ownKeys(value); 66 ASSERT_TRUE(keys.length === 8); 67 68 // SetProperty 69 try { 70 value["ClassA"] = {}; 71 } catch (error) { 72 ASSERT_TRUE(error.toString() === 'TypeError: Cannot assign to read only property of Object Module'); 73 let ClassA = value.ClassA; 74 let a = new ClassA(); 75 ASSERT_TRUE(typeof a.foo === 'function' && a.foo() === 'this is 1.2 classA ets'); 76 } 77 78 // SetProperty 79 try { 80 value["a"] = {}; 81 } catch (error) { 82 ASSERT_TRUE(error.toString() === 'TypeError: Cannot assign to read only property of Object Module'); 83 ASSERT_TRUE(value.a === 'this is 1.2 classA ets'); 84 } 85 86 // SetProperty 87 try { 88 value["foo"] = {}; 89 } catch (error) { 90 ASSERT_TRUE(error.toString() === 'TypeError: Cannot assign to read only property of Object Module'); 91 ASSERT_TRUE(typeof value.foo === 'function' && value.foo() === 'this is 1.2 foo ets'); 92 } 93 94 // DefineOwnProperty true 95 { 96 ASSERT_TRUE(Reflect.defineProperty(value, 'ClassA', {})); 97 let ClassA = value.ClassA; 98 let a = new ClassA(); 99 ASSERT_TRUE(typeof a.foo === 'function' && a.foo() === 'this is 1.2 classA ets'); 100 } 101 { 102 ASSERT_TRUE( 103 !Reflect.defineProperty(value, 'ClassA', { 104 value: 1, 105 }) 106 ); 107 let ClassA = value.ClassA; 108 let a = new ClassA(); 109 ASSERT_TRUE(typeof a.foo === 'function' && a.foo() === 'this is 1.2 classA ets'); 110 } 111 }) 112 .catch((error) => { 113 print(error.toString()); 114 }); 115