(cachedData, filename)
| 61 | } |
| 62 | |
| 63 | function generateScript (cachedData, filename) { |
| 64 | if (!isBufferV8Bytecode(cachedData)) { |
| 65 | // Try to decompress as Brotli |
| 66 | cachedData = brotliDecompressSync(cachedData); |
| 67 | |
| 68 | ok(isBufferV8Bytecode(cachedData), 'Invalid bytecode buffer'); |
| 69 | } |
| 70 | |
| 71 | if (DEBUG) { |
| 72 | console.error(`[bytenode] loading ${filename || '<buffer>'}`); |
| 73 | console.error(`[bytenode] runtime: node ${process.version}` + |
| 74 | (process.versions.electron ? `, electron ${process.versions.electron}` : '') + |
| 75 | `, v8 ${process.versions.v8}`); |
| 76 | dumpBytecodeHeader('on-disk .jsc header (before fixBytecode)', cachedData); |
| 77 | // A dummy compiled in THIS runtime process: its build-dependent header fields |
| 78 | // (version hash / flag hash / ro snapshot checksum) are what V8 will expect here. |
| 79 | try { |
| 80 | dumpBytecodeHeader('runtime dummy header (what V8 expects)', compileCode('"\u0ca0_\u0ca0"')); |
| 81 | } catch (err) { |
| 82 | console.error('[bytenode] failed to compile runtime dummy:', err && err.message); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | fixBytecode(cachedData); |
| 87 | |
| 88 | if (DEBUG) { |
| 89 | dumpBytecodeHeader('on-disk .jsc header (after fixBytecode)', cachedData); |
| 90 | } |
| 91 | |
| 92 | const length = readSourceHash(cachedData); |
| 93 | |
| 94 | let dummyCode = ''; |
| 95 | |
| 96 | if (length > 1) { |
| 97 | dummyCode = '"' + '\u200b'.repeat(length - 2) + '"'; // "\u200b" Zero width space |
| 98 | } |
| 99 | |
| 100 | if (DEBUG) { |
| 101 | console.error(`[bytenode] sourceHash/dummy length = ${length}; about to call new vm.Script(...)`); |
| 102 | } |
| 103 | |
| 104 | const script = new vm.Script(dummyCode, { cachedData, filename }); |
| 105 | |
| 106 | if (script.cachedDataRejected) { |
| 107 | throw new Error('Invalid or incompatible cached data (cachedDataRejected)'); |
| 108 | } |
| 109 | |
| 110 | if (DEBUG) { |
| 111 | console.error('[bytenode] vm.Script created, cachedData accepted.'); |
| 112 | } |
| 113 | |
| 114 | return script; |
| 115 | } |
| 116 | |
| 117 | function isBufferV8Bytecode (buffer) { |
| 118 | return ( |
no test coverage detected
searching dependent graphs…