1e484b35bSopenharmony_ci/* 2e484b35bSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3e484b35bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e484b35bSopenharmony_ci * you may not use this file except in compliance with the License. 5e484b35bSopenharmony_ci * You may obtain a copy of the License at 6e484b35bSopenharmony_ci * 7e484b35bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e484b35bSopenharmony_ci * 9e484b35bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e484b35bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e484b35bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e484b35bSopenharmony_ci * See the License for the specific language governing permissions and 13e484b35bSopenharmony_ci * limitations under the License. 14e484b35bSopenharmony_ci */ 15e484b35bSopenharmony_ci 16e484b35bSopenharmony_ciimport { appMap } from './map'; 17e484b35bSopenharmony_ci 18e484b35bSopenharmony_ci/** 19e484b35bSopenharmony_ci * Get appGlobal of App. 20e484b35bSopenharmony_ci * @param {string} packageName - Package name. 21e484b35bSopenharmony_ci * @return {Object | ProxyConstructor} 22e484b35bSopenharmony_ci */ 23e484b35bSopenharmony_ciexport function getPageGlobal(packageName: string): object | ProxyConstructor { 24e484b35bSopenharmony_ci if (!appMap[packageName] || !appMap[packageName].appGlobal) { 25e484b35bSopenharmony_ci return Object.create(global); 26e484b35bSopenharmony_ci } 27e484b35bSopenharmony_ci return new Proxy(Object.create(appMap[packageName].appGlobal), { 28e484b35bSopenharmony_ci get(trapTarget, key, receiver) { 29e484b35bSopenharmony_ci if (key === '__proto__') { 30e484b35bSopenharmony_ci return appMap[packageName].appGlobal; 31e484b35bSopenharmony_ci } 32e484b35bSopenharmony_ci return Reflect.get(trapTarget, key, receiver); 33e484b35bSopenharmony_ci } 34e484b35bSopenharmony_ci }); 35e484b35bSopenharmony_ci} 36