chore: clean up context bridge scopes and add specs for internal bridge (#23334)

* chore: clean up context bridge context scopes

* spec: add specs for internalContextBridge
This commit is contained in:
Samuel Attard 2020-05-11 13:41:42 -07:00 committed by GitHub
parent cf635c5fac
commit 7f9b7b2e95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 269 additions and 121 deletions

View file

@ -7,13 +7,13 @@ const checkContextIsolationEnabled = () => {
if (!contextIsolationEnabled) throw new Error('contextBridge API can only be used when contextIsolation is enabled');
};
const contextBridge = {
const contextBridge: Electron.ContextBridge = {
exposeInMainWorld: (key: string, api: Record<string, any>) => {
checkContextIsolationEnabled();
return binding.exposeAPIInMainWorld(key, api);
},
debugGC: () => binding._debugGCMaps({})
};
} as any;
if (!binding._debugGCMaps) delete contextBridge.debugGC;
@ -32,3 +32,7 @@ export const internalContextBridge = {
},
isInMainWorld: () => binding._isCalledFromMainWorld() as boolean
};
if (binding._debugGCMaps) {
contextBridge.internalContextBridge = internalContextBridge;
}