🐛 add getPrototypeOf trap in sandbox to keep the window instanceof Window returns true in microapp (#1465)
This commit is contained in:
parent
4637fae87e
commit
08f810a28b
|
|
@ -332,3 +332,18 @@ test('falsy values should return as expected', () => {
|
||||||
expect(proxy.nullvar).toBeNull();
|
expect(proxy.nullvar).toBeNull();
|
||||||
expect(proxy.zero).toBe(0);
|
expect(proxy.zero).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return true while [[GetPrototypeOf]] invoked by proxy object', () => {
|
||||||
|
// window.__proto__ not equals window prototype in jest environment
|
||||||
|
// eslint-disable-next-line no-proto
|
||||||
|
expect(window.__proto__ === Object.getPrototypeOf(window)).toBeFalsy();
|
||||||
|
// we must to set the prototype of window as jest modified window `__proto__` property but not changed it internal [[Prototype]] property
|
||||||
|
// eslint-disable-next-line no-proto
|
||||||
|
Object.setPrototypeOf(window, window.__proto__);
|
||||||
|
|
||||||
|
const { proxy } = new ProxySandbox('window-prototype');
|
||||||
|
expect(proxy instanceof Window).toBeTruthy();
|
||||||
|
expect(Object.getPrototypeOf(proxy)).toBe(Object.getPrototypeOf(window));
|
||||||
|
expect(Reflect.getPrototypeOf(proxy)).toBe(Reflect.getPrototypeOf(window));
|
||||||
|
expect(Reflect.getPrototypeOf(proxy)).toBe(Object.getPrototypeOf(window));
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -332,6 +332,11 @@ export default class ProxySandbox implements SandBox {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// makes sure `window instanceof Window` returns truthy in micro app
|
||||||
|
getPrototypeOf() {
|
||||||
|
return Reflect.getPrototypeOf(rawWindow);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user