fix: errors thrown in functions over the contextBridge (#28346)

* fix: errors thrown in functions over the contextBridge

* spec: add a test

* fix: ensure exception is a v8::Object
This commit is contained in:
Shelley Vohr 2021-03-30 07:26:49 +00:00 committed by GitHub
commit 9fecf8369f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 9 deletions

View file

@ -364,6 +364,20 @@ describe('contextBridge', () => {
expect(result).equal(true);
});
it('should properly handle errors thrown in proxied functions', async () => {
await makeBindingWindow(() => {
contextBridge.exposeInMainWorld('example', () => { throw new Error('oh no'); });
});
const result = await callWithBindings(async (root: any) => {
try {
root.example();
} catch (e) {
return e.message;
}
});
expect(result).equal('oh no');
});
it('should proxy methods that are callable multiple times', async () => {
await makeBindingWindow(() => {
contextBridge.exposeInMainWorld('example', {