Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit a50e6bf

Browse files
author
Daniel Brain
committed
Additional safety in window functions
1 parent c9f2314 commit a50e6bf

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/lib/windows.js

+31-32
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,24 @@ export function isWindow(item) {
4646
return false;
4747
}
4848

49-
try {
49+
if (isSameDomain(item)) {
50+
try {
5051

51-
for (let key of [ 'setTimeout', 'setInterval', 'postMessage', 'alert' ]) {
52-
if (typeof item[key] !== 'function') {
53-
return false;
52+
for (let key of [ 'setTimeout', 'setInterval', 'postMessage', 'alert' ]) {
53+
if (typeof item[key] !== 'function') {
54+
return false;
55+
}
5456
}
55-
}
5657

57-
if (!item.document || !item.location) {
58-
return false;
59-
}
58+
if (!item.document || !item.location) {
59+
return false;
60+
}
6061

61-
return true;
62+
return true;
6263

63-
} catch (err) {
64-
// pass
64+
} catch (err) {
65+
// pass
66+
}
6567
}
6668

6769
try {
@@ -85,7 +87,11 @@ export function isWindowClosed(win) {
8587

8688
try {
8789

88-
if (!win || win.closed || (isSameDomain(win) && util.safeGet(win, 'mockclosed'))) {
90+
if (!win || win.closed) {
91+
return true;
92+
}
93+
94+
if (isSameDomain(win) && util.safeGet(win, 'mockclosed')) {
8995
return true;
9096
}
9197

@@ -201,31 +207,24 @@ export function getFrames(win) {
201207

202208
result.push(frame);
203209
}
204-
} else {
205210

206-
let i = 0;
207-
208-
while (true) {
209-
let frame;
210-
211-
try {
212-
frame = frames[i];
213-
} catch (err) {
214-
return result;
215-
}
216-
217-
if (!frame) {
218-
return result;
219-
}
211+
return result;
212+
}
220213

221-
result.push(frame);
214+
for (let i = 0; i < 100; i++) {
215+
let frame;
222216

223-
i += 1;
217+
try {
218+
frame = frames[i];
219+
} catch (err) {
220+
return result;
221+
}
224222

225-
if (i > 20) {
226-
return result;
227-
}
223+
if (!frame) {
224+
return result;
228225
}
226+
227+
result.push(frame);
229228
}
230229

231230
return result;

0 commit comments

Comments
 (0)