(javascriptCode, compress)
| 132 | * @returns {Buffer} The generated bytecode. |
| 133 | */ |
| 134 | const compileCode = function (javascriptCode, compress) { |
| 135 | if (typeof javascriptCode !== 'string') { |
| 136 | throw new Error(`javascriptCode must be string. ${typeof javascriptCode} was given.`); |
| 137 | } |
| 138 | |
| 139 | const script = new vm.Script(javascriptCode, { |
| 140 | produceCachedData: true |
| 141 | }); |
| 142 | |
| 143 | let bytecodeBuffer = (script.createCachedData && script.createCachedData.call) |
| 144 | ? script.createCachedData() |
| 145 | : script.cachedData; |
| 146 | |
| 147 | if (compress) bytecodeBuffer = brotliCompressSync(bytecodeBuffer); |
| 148 | |
| 149 | return bytecodeBuffer; |
| 150 | }; |
| 151 | |
| 152 | /** |
| 153 | * This function runs the compileCode() function (above) |
no outgoing calls
no test coverage detected
searching dependent graphs…