()
| 63 | } |
| 64 | |
| 65 | export function loadZone(): ZoneType { |
| 66 | // if global['Zone'] already exists (maybe zone.js was already loaded or |
| 67 | // some other lib also registered a global object named Zone), we may need |
| 68 | // to throw an error, but sometimes user may not want this error. |
| 69 | // For example, |
| 70 | // we have two web pages, page1 includes zone.js, page2 doesn't. |
| 71 | // and the 1st time user load page1 and page2, everything work fine, |
| 72 | // but when user load page2 again, error occurs because global['Zone'] already exists. |
| 73 | // so we add a flag to let user choose whether to throw this error or not. |
| 74 | // By default, if existing Zone is from zone.js, we will not throw the error. |
| 75 | const global = globalThis as any; |
| 76 | const checkDuplicate = global[__symbol__('forceDuplicateZoneCheck')] === true; |
| 77 | if (global['Zone'] && (checkDuplicate || typeof global['Zone'].__symbol__ !== 'function')) { |
| 78 | throw new Error('Zone already loaded.'); |
| 79 | } |
| 80 | |
| 81 | // Initialize global `Zone` constant. |
| 82 | global['Zone'] ??= initZone(); |
| 83 | return global['Zone']; |
| 84 | } |
no test coverage detected
searching dependent graphs…