blob: 9eccc655990572eef99540c04e23011c50f35473 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
'use strict';
const fs = require('fs');
const zlib = require('zlib');
const path = require('path');
const assert = require('assert');
const {
isBuildingSnapshot,
addSerializeCallback,
addDeserializeCallback,
setDeserializeMainFunction
} = require('v8').startupSnapshot;
const filePath = path.resolve(__dirname, '../x1024.txt');
const storage = {};
assert(isBuildingSnapshot());
addSerializeCallback(({ filePath }) => {
console.error('serializing', filePath);
storage[filePath] = zlib.gzipSync(fs.readFileSync(filePath));
}, { filePath });
addDeserializeCallback(({ filePath }) => {
console.error('deserializing', filePath);
storage[filePath] = zlib.gunzipSync(storage[filePath]);
}, { filePath });
setDeserializeMainFunction(({ filePath }) => {
console.log(storage[filePath].toString());
}, { filePath });
assert.throws(() => setDeserializeMainFunction(() => {
assert.fail('unreachable duplicated main function');
}), {
code: 'ERR_DUPLICATE_STARTUP_SNAPSHOT_MAIN_FUNCTION',
});
|