fix: exceptions during function/promise result conversions live in calling world (#37904)
This commit is contained in:
parent
c65632d404
commit
c01dff8d89
2 changed files with 115 additions and 16 deletions
|
@ -814,10 +814,21 @@ describe('contextBridge', () => {
|
|||
bad: Object(Symbol('foo'))
|
||||
};
|
||||
},
|
||||
argumentConvert: () => {}
|
||||
throwDynamic: () => {
|
||||
return {
|
||||
get bad () {
|
||||
throw new Error('damm');
|
||||
}
|
||||
};
|
||||
},
|
||||
argumentConvert: () => {},
|
||||
rejectNotClonable: async () => {
|
||||
throw Object(Symbol('foo'));
|
||||
},
|
||||
resolveNotClonable: async () => Object(Symbol('foo'))
|
||||
});
|
||||
});
|
||||
const result = await callWithBindings((root: any) => {
|
||||
const result = await callWithBindings(async (root: any) => {
|
||||
const getError = (fn: Function) => {
|
||||
try {
|
||||
fn();
|
||||
|
@ -826,15 +837,26 @@ describe('contextBridge', () => {
|
|||
}
|
||||
return null;
|
||||
};
|
||||
const getAsyncError = async (fn: Function) => {
|
||||
try {
|
||||
await fn();
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const normalIsError = Object.getPrototypeOf(getError(root.example.throwNormal)) === Error.prototype;
|
||||
const weirdIsError = Object.getPrototypeOf(getError(root.example.throwWeird)) === Error.prototype;
|
||||
const notClonableIsError = Object.getPrototypeOf(getError(root.example.throwNotClonable)) === Error.prototype;
|
||||
const notClonableNestedArrayIsError = Object.getPrototypeOf(getError(root.example.throwNotClonableNestedArray)) === Error.prototype;
|
||||
const notClonableNestedObjectIsError = Object.getPrototypeOf(getError(root.example.throwNotClonableNestedObject)) === Error.prototype;
|
||||
const dynamicIsError = Object.getPrototypeOf(getError(root.example.throwDynamic)) === Error.prototype;
|
||||
const argumentConvertIsError = Object.getPrototypeOf(getError(() => root.example.argumentConvert(Object(Symbol('test'))))) === Error.prototype;
|
||||
return [normalIsError, weirdIsError, notClonableIsError, notClonableNestedArrayIsError, notClonableNestedObjectIsError, argumentConvertIsError];
|
||||
const rejectNotClonableIsError = Object.getPrototypeOf(await getAsyncError(root.example.rejectNotClonable)) === Error.prototype;
|
||||
const resolveNotClonableIsError = Object.getPrototypeOf(await getAsyncError(root.example.resolveNotClonable)) === Error.prototype;
|
||||
return [normalIsError, weirdIsError, notClonableIsError, notClonableNestedArrayIsError, notClonableNestedObjectIsError, dynamicIsError, argumentConvertIsError, rejectNotClonableIsError, resolveNotClonableIsError];
|
||||
});
|
||||
expect(result).to.deep.equal([true, true, true, true, true, true], 'should all be errors in the current context');
|
||||
expect(result).to.deep.equal([true, true, true, true, true, true, true, true, true], 'should all be errors in the current context');
|
||||
});
|
||||
|
||||
it('should not leak prototypes', async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue