✅ add window reference binding test (#1524)
This commit is contained in:
parent
6de0ac9721
commit
3880cd5078
|
|
@ -347,3 +347,16 @@ it('should return true while [[GetPrototypeOf]] invoked by proxy object', () =>
|
||||||
expect(Reflect.getPrototypeOf(proxy)).toBe(Reflect.getPrototypeOf(window));
|
expect(Reflect.getPrototypeOf(proxy)).toBe(Reflect.getPrototypeOf(window));
|
||||||
expect(Reflect.getPrototypeOf(proxy)).toBe(Object.getPrototypeOf(window));
|
expect(Reflect.getPrototypeOf(proxy)).toBe(Object.getPrototypeOf(window));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('native window function calling should always be bound with window', () => {
|
||||||
|
const { proxy } = new ProxySandbox('mustBeBoundWithWindowReference');
|
||||||
|
proxy.nativeWindowFunction = function nativeWindowFunction(this: any) {
|
||||||
|
if (this !== undefined && this !== window) {
|
||||||
|
throw new Error('Illegal Invocation!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'success';
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(proxy.nativeWindowFunction()).toBe('success');
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ export function setCurrentRunningSandboxProxy(proxy: WindowProxy | null) {
|
||||||
|
|
||||||
export function getTargetValue(target: any, value: any): any {
|
export function getTargetValue(target: any, value: any): any {
|
||||||
/*
|
/*
|
||||||
仅绑定 isCallable && !isBoundedFunction && !isConstructable 的函数对象,如 window.console、window.atob 这类。目前没有完美的检测方式,这里通过 prototype 中是否还有可枚举的拓展方法的方式来判断
|
仅绑定 isCallable && !isBoundedFunction && !isConstructable 的函数对象,如 window.console、window.atob 这类,不然微应用中调用时会抛出 Illegal invocation 异常
|
||||||
|
目前没有完美的检测方式,这里通过 prototype 中是否还有可枚举的拓展方法的方式来判断
|
||||||
@warning 这里不要随意替换成别的判断方式,因为可能触发一些 edge case(比如在 lodash.isFunction 在 iframe 上下文中可能由于调用了 top window 对象触发的安全异常)
|
@warning 这里不要随意替换成别的判断方式,因为可能触发一些 edge case(比如在 lodash.isFunction 在 iframe 上下文中可能由于调用了 top window 对象触发的安全异常)
|
||||||
*/
|
*/
|
||||||
if (isCallable(value) && !isBoundedFunction(value) && !isConstructable(value)) {
|
if (isCallable(value) && !isBoundedFunction(value) && !isConstructable(value)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user