Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!container || !element.contentWindow) {
throw new Error(`Iframe html can not be written unless container provided and iframe in DOM`);
}
// $FlowFixMe
writeToWindow(element.contentWindow, options.html);
} else {
element.innerHTML = options.html;
}
}
return element;
}
let awaitFrameLoadPromises : WeakMap> = new WeakMap();
export function awaitFrameLoad(frame : HTMLIFrameElement) : ZalgoPromise {
if (awaitFrameLoadPromises.has(frame)) {
let promise = awaitFrameLoadPromises.get(frame);
if (promise) {
return promise;
}
}
let promise = new ZalgoPromise((resolve, reject) => {
frame.addEventListener('load', () => {
linkFrameWindow(frame);
resolve(frame);
});
return globalStore('windowStore').getOrSet(key, () => {
const winStore = new _src.WeakMap();
const getStore = win => {
return winStore.getOrSet(win, defStore);
};
return {
has: win => {
const store = getStore(win);
return store.hasOwnProperty(key);
},
get: (win, defVal) => {
const store = getStore(win); // $FlowFixMe
return store.hasOwnProperty(key) ? store[key] : defVal;
},
set: (win, val) => {
return globalStore('windowStore').getOrSet(key, () => {
const winStore = new WeakMap();
const getStore = (win : CrossDomainWindowType | WildCard) : ObjectGetter => {
return winStore.getOrSet(win, defStore);
};
return {
has: (win) => {
const store = getStore(win);
return store.hasOwnProperty(key);
},
get: (win, defVal) => {
const store = getStore(win);
// $FlowFixMe
return store.hasOwnProperty(key) ? store[key] : defVal;
},
set: (win, val) => {
// $FlowFixMe
if (!container || !element.contentWindow) {
throw new Error('Iframe html can not be written unless container provided and iframe in DOM');
}
// $FlowFixMe
writeToWindow(element.contentWindow, options.html);
} else {
element.innerHTML = options.html;
}
}
return element;
}
var awaitFrameLoadPromises = new WeakMap();
export function awaitFrameLoad(frame) {
if (awaitFrameLoadPromises.has(frame)) {
var _promise = awaitFrameLoadPromises.get(frame);
if (_promise) {
return _promise;
}
}
var promise = new ZalgoPromise(function (resolve, reject) {
frame.addEventListener('load', function () {
linkFrameWindow(frame);
resolve(frame);
});
import { WeakMap } from 'cross-domain-safe-weakmap/src';
import { getAncestor } from 'cross-domain-utils/src';
import { ZalgoPromise } from 'zalgo-promise/src';
import { noop } from 'belter/src';
import { MESSAGE_NAME, WILDCARD } from '../conf';
import { global } from '../global';
global.readyPromises = global.readyPromises || new WeakMap();
global.knownWindows = global.knownWindows || new WeakMap();
export function onHello(handler) {
global.on(MESSAGE_NAME.HELLO, { domain: WILDCARD }, function (_ref) {
var source = _ref.source,
origin = _ref.origin;
return handler({ source: source, origin: origin });
});
}
export function sayHello(win) {
return global.send(win, MESSAGE_NAME.HELLO, {}, { domain: WILDCARD, timeout: -1 }).then(function (_ref2) {
var origin = _ref2.origin;
return { origin: origin };
});
if (obj[key] === undefined || obj[key] === null || typeof obj[key] === 'function') {
continue;
} else if (obj[key] && Array.isArray(obj[key]) && obj[key].length && obj[key].every(function (val) {
return (typeof val === 'undefined' ? 'undefined' : _typeof(val)) !== 'object';
})) {
newobj['' + prefix + key] = obj[key].join(',');
} else if (obj[key] && _typeof(obj[key]) === 'object') {
newobj = dotify(obj[key], '' + prefix + key, newobj);
} else {
newobj['' + prefix + key] = obj[key].toString();
}
}
return newobj;
}
var objectIDs = new WeakMap();
export function getObjectID(obj) {
if (obj === null || obj === undefined || (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' && typeof obj !== 'function') {
throw new Error('Invalid object');
}
var uid = objectIDs.get(obj);
if (!uid) {
uid = (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) + ':' + uniqueID();
objectIDs.set(obj, uid);
}
return uid;
}
prefix = prefix ? `${ prefix }.` : prefix;
for (let key in obj) {
if (obj[key] === undefined || obj[key] === null || typeof obj[key] === 'function') {
continue;
} else if (obj[key] && Array.isArray(obj[key]) && obj[key].length && obj[key].every(val => typeof val !== 'object')) {
newobj[`${ prefix }${ key }`] = obj[key].join(',');
} else if (obj[key] && typeof obj[key] === 'object') {
newobj = dotify(obj[key], `${ prefix }${ key }`, newobj);
} else {
newobj[`${ prefix }${ key }`] = obj[key].toString();
}
}
return newobj;
}
let objectIDs = new WeakMap();
export function getObjectID(obj : Object) : string {
if (obj === null || obj === undefined || (typeof obj !== 'object' && typeof obj !== 'function')) {
throw new Error(`Invalid object`);
}
let uid = objectIDs.get(obj);
if (!uid) {
uid = `${ typeof obj }:${ uniqueID() }`;
objectIDs.set(obj, uid);
}
return uid;
}
import { WeakMap } from 'cross-domain-safe-weakmap/src';
import { getAncestor } from 'cross-domain-utils/src';
import { ZalgoPromise } from 'zalgo-promise/src';
import { noop } from 'belter/src';
import { MESSAGE_NAME, WILDCARD } from '../conf';
import { global } from '../global';
global.readyPromises = global.readyPromises || new WeakMap();
global.knownWindows = global.knownWindows || new WeakMap();
export function onHello(handler) {
global.on(MESSAGE_NAME.HELLO, { domain: WILDCARD }, function (_ref) {
var source = _ref.source,
origin = _ref.origin;
return handler({ source: source, origin: origin });
});
}
export function sayHello(win) {
return global.send(win, MESSAGE_NAME.HELLO, {}, { domain: WILDCARD, timeout: -1 }).then(function (_ref2) {
var origin = _ref2.origin;
return { origin: origin };
import { WeakMap } from 'cross-domain-safe-weakmap/src';
import { matchDomain } from 'cross-domain-utils/src';
import { ZalgoPromise } from 'zalgo-promise/src';
import { once, uniqueID } from 'belter/src';
import { TYPE, serialize, serializeType, deserialize } from 'universal-serialize/src';
import { MESSAGE_NAME, WILDCARD } from '../conf';
import { global } from '../global';
global.methods = global.methods || new WeakMap();
var listenForFunctionCalls = once(function () {
global.on(MESSAGE_NAME.METHOD, { origin: WILDCARD }, function (_ref) {
var source = _ref.source,
origin = _ref.origin,
data = _ref.data;
var methods = global.methods.get(source);
if (!methods) {
throw new Error('Could not find any methods this window has privileges to call');
}
var meth = methods[data.id];
if (!meth) {