Skip to content

Commit 606523d

Browse files
legendecastargos
authored andcommitted
v8: fix ERR_NOT_BUILDING_SNAPSHOT is not a constructor
PR-URL: #47721 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent e948bec commit 606523d

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎lib/internal/v8/startup_snapshot.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ const {
44
validateFunction,
55
}=require('internal/validators');
66
const{
7-
ERR_NOT_BUILDING_SNAPSHOT,
8-
ERR_DUPLICATE_STARTUP_SNAPSHOT_MAIN_FUNCTION,
7+
codes: {
8+
ERR_NOT_BUILDING_SNAPSHOT,
9+
ERR_DUPLICATE_STARTUP_SNAPSHOT_MAIN_FUNCTION,
10+
},
911
}=require('internal/errors');
1012

1113
const{

‎test/fixtures/snapshot/v8-startup-snapshot-api.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ addDeserializeCallback(({ filePath }) => {
3030
setDeserializeMainFunction(({ filePath })=>{
3131
console.log(storage[filePath].toString());
3232
},{ filePath });
33+
assert.throws(()=>setDeserializeMainFunction(()=>{
34+
assert.fail('unreachable duplicated main function');
35+
}),{
36+
code: 'ERR_DUPLICATE_STARTUP_SNAPSHOT_MAIN_FUNCTION',
37+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
require('../common');
4+
constassert=require('assert');
5+
6+
const{
7+
isBuildingSnapshot,
8+
addSerializeCallback,
9+
addDeserializeCallback,
10+
setDeserializeMainFunction
11+
}=require('v8').startupSnapshot;
12+
13+
// This test verifies that the v8.startupSnapshot APIs are not available when
14+
// it is not building snapshot.
15+
16+
assert(!isBuildingSnapshot());
17+
18+
assert.throws(()=>addSerializeCallback(()=>{}),{
19+
code: 'ERR_NOT_BUILDING_SNAPSHOT',
20+
});
21+
assert.throws(()=>addDeserializeCallback(()=>{}),{
22+
code: 'ERR_NOT_BUILDING_SNAPSHOT',
23+
});
24+
assert.throws(()=>setDeserializeMainFunction(()=>{}),{
25+
code: 'ERR_NOT_BUILDING_SNAPSHOT',
26+
});

0 commit comments

Comments
 (0)