Skip to content

Commit

Permalink
Implement is-cross-origin internally so it doesn't throw (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
weizman committed Jun 23, 2023
1 parent 28049dc commit a14cfc1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 50 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,5 @@
"bugs": {
"url": "https://github.com/lavamoat/snow/issues"
},
"homepage": "https://lavamoat.github.io/snow/",
"dependencies": {
"is-cross-origin": "^1.0.1"
}
"homepage": "https://lavamoat.github.io/snow/"
}
54 changes: 11 additions & 43 deletions snow.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ module.exports = hookCustoms;
/***/ 228:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {

const isCrossOrigin = __webpack_require__(851);
const workaroundChromiumBug = __webpack_require__(750);
const {
shadows,
Expand All @@ -169,10 +168,20 @@ const {
const {
forEachOpened
} = __webpack_require__(134);
function isWindow(obj) {
const o = Object(obj);
return o === o.window;
}
function isCrossOrigin(dst, src) {
return Object.getPrototypeOf.call(src, dst) === null;
}
function findWin(win, frameElement) {
let i = -1;
while (win[++i]) {
if (isCrossOrigin(win[i], win, Object)) {
if (!isWindow(win[i])) {
continue;
}
if (isCrossOrigin(win[i], win)) {
continue;
}
if (getFrameElement(win[i]) === frameElement) {
Expand Down Expand Up @@ -1554,47 +1563,6 @@ function hookWorker(win) {
}
module.exports = hookWorker;

/***/ }),

/***/ 626:
/***/ ((module) => {

module.exports = {
SRC_IS_NOT_A_WINDOW: 'provided argument "src" must be a proper window of instance Window',
DST_IS_NOT_A_WINDOW: 'provided argument "dst" must be a proper window of instance Window',
SRC_IS_NOT_SAME_ORIGIN_AS_WINDOW: 'provided argument "src" must be a window in the same origin as the current context window',
}

/***/ }),

/***/ 851:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {

const {DST_IS_NOT_A_WINDOW, SRC_IS_NOT_A_WINDOW, SRC_IS_NOT_SAME_ORIGIN_AS_WINDOW} = __webpack_require__(626);

function isWindow(obj, Object) {
const o = Object(obj);
return o === o.window;
}

function isCrossOrigin(dst, src, Object) {
return Object.getPrototypeOf.call(src, dst) === null;
}

module.exports = function(dst, src = window, Object = window.Object) {
if (!isWindow(src, Object)) {
throw new Error(SRC_IS_NOT_A_WINDOW);
}
if (!isWindow(dst, Object)) {
throw new Error(DST_IS_NOT_A_WINDOW);
}
if (isCrossOrigin(window, src, Object)) {
throw new Error(SRC_IS_NOT_SAME_ORIGIN_AS_WINDOW);
}
return isCrossOrigin(dst, src, Object);
};


/***/ })

/******/ });
Expand Down

0 comments on commit a14cfc1

Please sign in to comment.