|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | // This tests that Node.js refuses to load snapshots built with incompatible |
4 | | -// V8 configurations. |
| 4 | +// configurations (V8 or Node.js flags). |
5 | 5 |
|
6 | 6 | require('../common'); |
7 | 7 | const assert = require('assert'); |
@@ -73,3 +73,77 @@ const entry = fixtures.path('empty.js'); |
73 | 73 | assert.strictEqual(child.status, 0); |
74 | 74 | } |
75 | 75 | } |
| 76 | + |
| 77 | +// Test that --frozen-intrinsics mismatch is detected. |
| 78 | +const frozenBlobPath = tmpdir.resolve('snapshot-frozen.blob'); |
| 79 | +{ |
| 80 | + // Build a snapshot with --frozen-intrinsics. |
| 81 | + const child = spawnSync(process.execPath, [ |
| 82 | + '--frozen-intrinsics', |
| 83 | + '--snapshot-blob', |
| 84 | + frozenBlobPath, |
| 85 | + '--build-snapshot', |
| 86 | + entry, |
| 87 | + ], { |
| 88 | + cwd: tmpdir.path |
| 89 | + }); |
| 90 | + if (child.status !== 0) { |
| 91 | + console.log(child.stderr.toString()); |
| 92 | + console.log(child.stdout.toString()); |
| 93 | + assert.strictEqual(child.status, 0); |
| 94 | + } |
| 95 | + const stats = fs.statSync(frozenBlobPath); |
| 96 | + assert(stats.isFile()); |
| 97 | +} |
| 98 | + |
| 99 | +{ |
| 100 | + // Load the snapshot without --frozen-intrinsics, which should fail. |
| 101 | + const child = spawnSync(process.execPath, [ |
| 102 | + '--snapshot-blob', |
| 103 | + frozenBlobPath, |
| 104 | + ], { |
| 105 | + cwd: tmpdir.path, |
| 106 | + env: { ...process.env } |
| 107 | + }); |
| 108 | + |
| 109 | + const stderr = child.stderr.toString().trim(); |
| 110 | + assert.match(stderr, /Failed to load the startup snapshot/); |
| 111 | + assert.match(stderr, /--frozen-intrinsics/); |
| 112 | + assert.strictEqual(child.status, 14); |
| 113 | +} |
| 114 | + |
| 115 | +{ |
| 116 | + // Load it again with --frozen-intrinsics and it should work. |
| 117 | + const child = spawnSync(process.execPath, [ |
| 118 | + '--frozen-intrinsics', |
| 119 | + '--snapshot-blob', |
| 120 | + frozenBlobPath, |
| 121 | + ], { |
| 122 | + cwd: tmpdir.path, |
| 123 | + env: { ...process.env } |
| 124 | + }); |
| 125 | + |
| 126 | + if (child.status !== 0) { |
| 127 | + console.log(child.stderr.toString()); |
| 128 | + console.log(child.stdout.toString()); |
| 129 | + assert.strictEqual(child.status, 0); |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +{ |
| 134 | + // Build a snapshot without --frozen-intrinsics and load with it, which |
| 135 | + // should also fail. |
| 136 | + const child = spawnSync(process.execPath, [ |
| 137 | + '--frozen-intrinsics', |
| 138 | + '--snapshot-blob', |
| 139 | + blobPath, |
| 140 | + ], { |
| 141 | + cwd: tmpdir.path, |
| 142 | + env: { ...process.env } |
| 143 | + }); |
| 144 | + |
| 145 | + const stderr = child.stderr.toString().trim(); |
| 146 | + assert.match(stderr, /Failed to load the startup snapshot/); |
| 147 | + assert.match(stderr, /--frozen-intrinsics/); |
| 148 | + assert.strictEqual(child.status, 14); |
| 149 | +} |
0 commit comments