/** * This is a cross-platform event emitter with bridge interface. * It uses Flatted as dependency where code is modified slightly to allow loading as a string */ /** * Hold reference to this for security purpose * * @private */ const toString = String.prototype.toString; /** * Generate code to be executed inside a VM for bootstrap. * * @param {String|Buffer} bootCode * @return {String} */ /* eslint-disable max-len */ module.exports = function (bootCode) { return `; (function (emit) { /*! (c) 2020 Andrea Giammarchi, (ISC) */ var Flatted=function(n){"use strict";var t=JSON.parse,r=JSON.stringify,e=Object.keys,a=String,u="string",f={},i="object",c=function(n,t){return t},l=function(n){return n instanceof a?a(n):n},o=function(n,t){return typeof t===u?new a(t):t},s=function(n,t,r){var e=a(t.push(r)-1);return n.set(r,e),e};return n.parse=function(n,r){var u=t(n,o).map(l),s=u[0],p=r||c,v=typeof s===i&&s?function n(t,r,u,c){for(var l=[],o=e(u),s=o.length,p=0;p= 1)) { while (i >= 0) { (e[i] === listener) && e.splice(i, 1); i -= 1; } } if (!e.length) { delete this._events[name]; } } }; // create the dispatch function inside a closure to ensure that actual function references are never modified __uvm_dispatch = (function (bridge, bridgeEmit) { // ensure global by not using var statement return function (args) { bridgeEmit.apply(bridge, Flatted.parse(args)); }; }(bridge, bridge.emit)); }(__uvm_emit)); // boot code starts hereafter ${(typeof bootCode === 'string') ? toString.call(bootCode) : ''};`; };