add window reference binding test (#1524)

This commit is contained in:
Kuitos 2021-06-22 00:37:51 +08:00 committed by GitHub
parent 6de0ac9721
commit 3880cd5078
2 changed files with 15 additions and 1 deletions

View File

@ -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');
});

View File

@ -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.consolewindow.atob prototype isCallable && !isBoundedFunction && !isConstructable window.consolewindow.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)) {