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