Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (typeof name === 'string' && typeof name.indexOf === 'function' && name.indexOf('anonymous::') === 0) {
name = name.replace('anonymous::', `${ key }::`);
}
if (ProxyWindow.isProxyWindow(destination)) {
addMethod(id, val, name, destination, domain);
// $FlowFixMe
destination.awaitWindow().then(win => {
addMethod(id, val, name, win, domain);
});
} else {
addMethod(id, val, name, destination, domain);
}
return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_FUNCTION, { id, name });
}
function serializePromise(destination, domain, val, key) {
return serializeType(CUSTOM_TYPE.CROSS_DOMAIN_ZALGO_PROMISE, {
then: serializeFunction(destination, domain, function (resolve, reject) {
return val.then(resolve, reject);
}, key)
});
}
function serializeFunction(destination, domain, val, key) {
var id = uniqueID();
var methods = global.methods.get(destination);
if (!methods) {
methods = {};
global.methods.set(destination, methods);
}
methods[id] = { domain: domain, val: val };
listenForFunctionCalls();
return serializeType(CUSTOM_TYPE.CROSS_DOMAIN_FUNCTION, { id: id, name: val.name || key });
}
export function serializePromise(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, val : Thenable, key : string, { on, send } : { on : OnType, send : SendType }) : SerializedPromise {
return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_ZALGO_PROMISE, {
then: serializeFunction(destination, domain, (resolve, reject) => val.then(resolve, reject), key, { on, send })
});
}
export function serializeWindow(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, win : CrossDomainWindowType, { send } : { send : SendType }) : SerializedWindow {
return serializeType(SERIALIZATION_TYPE.CROSS_DOMAIN_WINDOW, ProxyWindow.serialize(win, { send }));
}
function serializeMessage(destination, domain, obj, {
on,
send
}) {
return (0, _src2.serialize)(obj, {
[_src2.TYPE.PROMISE]: (val, key) => (0, _promise.serializePromise)(destination, domain, val, key, {
on,
send
}),
[_src2.TYPE.FUNCTION]: (val, key) => (0, _function.serializeFunction)(destination, domain, val, key, {
on,
send
}),
[_src2.TYPE.OBJECT]: val => {
return (0, _src.isWindow)(val) || _window.ProxyWindow.isProxyWindow(val) ? (0, _window.serializeWindow)(destination, domain, val, {
on,
send
}) : val;
}
});
}
function serializeMessage(destination, domain, obj, {
on,
send
}) {
return (0, _src2.serialize)(obj, {
[_src2.TYPE.PROMISE]: (val, key) => (0, _promise.serializePromise)(destination, domain, val, key, {
on,
send
}),
[_src2.TYPE.FUNCTION]: (val, key) => (0, _function.serializeFunction)(destination, domain, val, key, {
on,
send
}),
[_src2.TYPE.OBJECT]: val => {
return (0, _src.isWindow)(val) || _window.ProxyWindow.isProxyWindow(val) ? (0, _window.serializeWindow)(destination, domain, val, {
on,
send
}) : val;
}
});
}
export function serializeMessage(destination, domain, obj) {
var _serialize;
return serialize(obj, (_serialize = {}, _serialize[TYPE.PROMISE] = function (val, key) {
return serializePromise(destination, domain, val, key);
}, _serialize[TYPE.FUNCTION] = function (val, key) {
return serializeFunction(destination, domain, val, key);
}, _serialize));
}
export function serializeMessage(destination : CrossDomainWindowType | ProxyWindow, domain : DomainMatcher, obj : T, { on, send } : { on : OnType, send : SendType }) : string {
return serialize(obj, {
[ TYPE.PROMISE ]: (val : Thenable, key : string) : SerializedPromise => serializePromise(destination, domain, val, key, { on, send }),
[ TYPE.FUNCTION ]: (val : Function, key : string) : SerializedFunction => serializeFunction(destination, domain, val, key, { on, send }),
[ TYPE.OBJECT ]: (val : CrossDomainWindowType) : Object | SerializedWindow => {
return (isWindow(val) || ProxyWindow.isProxyWindow(val)) ? serializeWindow(destination, domain, val, { on, send }) : val;
}
});
}
export function serializeMessage(destination, domain, obj) {
var _serialize;
return serialize(obj, (_serialize = {}, _serialize[TYPE.PROMISE] = function (val, key) {
return serializePromise(destination, domain, val, key);
}, _serialize[TYPE.FUNCTION] = function (val, key) {
return serializeFunction(destination, domain, val, key);
}, _serialize));
}