🏁 compatible with old browser (#1136)
This commit is contained in:
parent
a023a5c9b7
commit
107484d71b
|
|
@ -287,6 +287,15 @@ test('bounded function should not be rebounded', () => {
|
||||||
expect(isBoundedFunction(proxy.fn1)).toBeTruthy();
|
expect(isBoundedFunction(proxy.fn1)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the prototype should be kept while we create a function with prototype on proxy', () => {
|
||||||
|
const proxy = new ProxySandbox('new-function').proxy as any;
|
||||||
|
|
||||||
|
function test() {}
|
||||||
|
proxy.fn = test;
|
||||||
|
expect(proxy.fn === test).toBeFalsy();
|
||||||
|
expect(proxy.fn.prototype).toBe(test.prototype);
|
||||||
|
});
|
||||||
|
|
||||||
test('some native window property was defined with getter in safari and firefox, and they will check the caller source', () => {
|
test('some native window property was defined with getter in safari and firefox, and they will check the caller source', () => {
|
||||||
Object.defineProperty(window, 'mockSafariGetterProperty', {
|
Object.defineProperty(window, 'mockSafariGetterProperty', {
|
||||||
get(this: Window) {
|
get(this: Window) {
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,11 @@ export function getTargetValue(target: any, value: any): any {
|
||||||
boundValue[key] = value[key];
|
boundValue[key] = value[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy prototype, for performance reason, we use in operator to check rather than hasOwnProperty
|
// copy prototype if bound function not have
|
||||||
if ('prototype' in value) boundValue.prototype = value.prototype;
|
// mostly a bound function have no own prototype, but it not absolute in some old version browser, see https://github.com/umijs/qiankun/issues/1121
|
||||||
|
if (value.hasOwnProperty('prototype') && !boundValue.hasOwnProperty('prototype'))
|
||||||
|
boundValue.prototype = value.prototype;
|
||||||
|
|
||||||
functionBoundedValueMap.set(value, boundValue);
|
functionBoundedValueMap.set(value, boundValue);
|
||||||
return boundValue;
|
return boundValue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user