feat: enable world safe JS by default (#26889)

* feat: enable world safe JS by default

* refactor: use the ctx bridge to send executeJavaScript results in a world safe way

* docs: add more info about the breaking change

* include default in IsEnabled check
This commit is contained in:
Samuel Attard 2021-01-26 14:23:35 -08:00 committed by GitHub
parent 78d4cb9f5c
commit db08f08b88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 33 deletions

View file

@ -283,7 +283,7 @@ describe('contextBridge', () => {
return err;
}
});
expect(result).to.be.an.instanceOf(Error).with.property('message', 'Uncaught Error: i-rejected');
expect(result).to.be.an.instanceOf(Error).with.property('message', 'i-rejected');
});
it('should proxy nested promises and reject with the correct value', async () => {
@ -300,7 +300,7 @@ describe('contextBridge', () => {
return err;
}
});
expect(result).to.be.an.instanceOf(Error).with.property('message', 'Uncaught Error: i-rejected');
expect(result).to.be.an.instanceOf(Error).with.property('message', 'i-rejected');
});
it('should proxy promises and resolve with the correct value if it resolves later', async () => {
@ -862,6 +862,12 @@ describe('contextBridge', () => {
getArr: () => [123, 'string', true, ['foo']],
getPromise: async () => ({ number: 123, string: 'string', boolean: true, fn: () => 'string', arr: [123, 'string', true, ['foo']] }),
getFunctionFromFunction: async () => () => null,
getError: () => new Error('foo'),
getWeirdError: () => {
const e = new Error('foo');
e.message = { garbage: true } as any;
return e;
},
object: {
number: 123,
string: 'string',
@ -921,6 +927,10 @@ describe('contextBridge', () => {
[cleanedRoot.getFunctionFromFunction, Function],
[cleanedRoot.getFunctionFromFunction(), Promise],
[await cleanedRoot.getFunctionFromFunction(), Function],
[cleanedRoot.getError(), Error],
[cleanedRoot.getError().message, String],
[cleanedRoot.getWeirdError(), Error],
[cleanedRoot.getWeirdError().message, String],
[cleanedRoot.getPromise(), Promise],
[await cleanedRoot.getPromise(), Object],
[(await cleanedRoot.getPromise()).number, Number],