🐛 proxy sandboxshould not delete untouched globals (#2310)
This commit is contained in:
parent
cec27b6c16
commit
6544b17f9b
|
|
@ -502,6 +502,24 @@ describe('variables in whitelist', () => {
|
|||
sandbox.inactive();
|
||||
expect('__REACT_ERROR_OVERLAY_GLOBAL_HOOK__' in window).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not modify those global context that have not been touched during the app running', () => {
|
||||
const original = {
|
||||
iframeReady: function t1() {},
|
||||
};
|
||||
window.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__ = original;
|
||||
const sandbox = new ProxySandbox('whitelist-variables');
|
||||
const { proxy } = sandbox;
|
||||
sandbox.active();
|
||||
// globals in whitelist
|
||||
proxy.System = {};
|
||||
expect(window.System).toEqual({});
|
||||
// regular globals
|
||||
proxy.someOther = {};
|
||||
expect('someOther' in window).toBeFalsy();
|
||||
sandbox.inactive();
|
||||
expect(window.__REACT_ERROR_OVERLAY_GLOBAL_HOOK__).toBe(original);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should work with nest sandbox', () => {
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ export default class ProxySandbox implements SandBox {
|
|||
|
||||
if (process.env.NODE_ENV === 'test' || --activeSandboxCount === 0) {
|
||||
// reset the global value to the prev value
|
||||
globalVariableWhiteList.forEach((p) => {
|
||||
Object.keys(this.globalWhitelistPrevDescriptor).forEach((p) => {
|
||||
const descriptor = this.globalWhitelistPrevDescriptor[p];
|
||||
if (descriptor) {
|
||||
Object.defineProperty(this.globalContext, p, descriptor);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user