UNPKG

noise-protocol-stream

Version:

Node stream wrapper for Noise Protocol C implementation compiled to WebAssembly

83 lines (73 loc) 3.34 kB
#if SIDE_MODULE == 0 // The Module object: Our interface to the outside world. We import // and export values on it. There are various ways Module can be used: // 1. Not defined. We create it here // 2. A function parameter, function(Module) { ..generated code.. } // 3. pre-run appended it, var Module = {}; ..generated code.. // 4. External script tag defines var Module. // We need to check if Module already exists (e.g. case 3 above). // Substitution will be replaced with actual code on later stage of the build, // this way Closure Compiler will not mangle it (e.g. case 4. above). // Note that if you want to run closure, and also to use Module // after the generated code, you will need to define var Module = {}; // before the code. Then that object will be used in the code, and you // can continue to use Module afterwards as well. #if USE_CLOSURE_COMPILER // if (!Module)` is crucial for Closure Compiler here as it will otherwise replace every `Module` occurrence with a string var Module; if (!Module) Module = "__EMSCRIPTEN_PRIVATE_MODULE_EXPORT_NAME_SUBSTITUTION__"; #else var Module = typeof {{{ EXPORT_NAME }}} !== 'undefined' ? {{{ EXPORT_NAME }}} : {}; #endif // USE_CLOSURE_COMPILER #endif // SIDE_MODULE // --pre-jses are emitted after the Module integration code, so that they can // refer to Module (if they choose; they can also define Module) // {{PRE_JSES}} // Sometimes an existing Module object exists with properties // meant to overwrite the default module functionality. Here // we collect those properties and reapply _after_ we configure // the current environment's defaults to avoid having to be so // defensive during initialization. var moduleOverrides = {}; var key; for (key in Module) { if (Module.hasOwnProperty(key)) { moduleOverrides[key] = Module[key]; } } Module['arguments'] = []; Module['thisProgram'] = './this.program'; Module['quit'] = function(status, toThrow) { throw toThrow; }; Module['preRun'] = []; Module['postRun'] = []; Module['readMemory'] = function (ptr, size) { return Buffer.from(HEAPU8.slice(ptr, ptr + size)) }; // The environment setup code below is customized to use Module. // *** Environment setup code *** var ENVIRONMENT_IS_WEB = false; var ENVIRONMENT_IS_WORKER = false; var ENVIRONMENT_IS_NODE = false; var ENVIRONMENT_IS_SHELL = false; // console.log is checked first, as 'print' on the web will open a print dialogue // printErr is preferable to console.warn (works better in shells) // bind(console) is necessary to fix IE/Edge closed dev tools panel behavior. Module['print'] = typeof console !== 'undefined' ? console.log.bind(console) : (typeof print !== 'undefined' ? print : null); Module['printErr'] = typeof printErr !== 'undefined' ? printErr : ((typeof console !== 'undefined' && console.warn.bind(console)) || Module['print']); // *** Environment setup code *** // Closure helpers Module.print = Module['print']; Module.printErr = Module['printErr']; // Merge back in the overrides for (key in moduleOverrides) { if (moduleOverrides.hasOwnProperty(key)) { Module[key] = moduleOverrides[key]; } } // Free the object hierarchy contained in the overrides, this lets the GC // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array. moduleOverrides = undefined; {{BODY}} // {{MODULE_ADDITIONS}}