Skip to content

Commit

Permalink
v8: fix ERR_NOT_BUILDING_SNAPSHOT is not a constructor
Browse files Browse the repository at this point in the history
PR-URL: #47721
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
legendecas authored Apr 29, 2023
1 parent 4c62042 commit bddf341
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/internal/v8/startup_snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ const {
validateFunction,
} = require('internal/validators');
const {
ERR_NOT_BUILDING_SNAPSHOT,
ERR_DUPLICATE_STARTUP_SNAPSHOT_MAIN_FUNCTION,
codes: {
ERR_NOT_BUILDING_SNAPSHOT,
ERR_DUPLICATE_STARTUP_SNAPSHOT_MAIN_FUNCTION,
},
} = require('internal/errors');

const {
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/snapshot/v8-startup-snapshot-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ addDeserializeCallback(({ 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',
});
26 changes: 26 additions & 0 deletions test/parallel/test-v8-startup-snapshot-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

require('../common');
const assert = require('assert');

const {
isBuildingSnapshot,
addSerializeCallback,
addDeserializeCallback,
setDeserializeMainFunction
} = require('v8').startupSnapshot;

// This test verifies that the v8.startupSnapshot APIs are not available when
// it is not building snapshot.

assert(!isBuildingSnapshot());

assert.throws(() => addSerializeCallback(() => {}), {
code: 'ERR_NOT_BUILDING_SNAPSHOT',
});
assert.throws(() => addDeserializeCallback(() => {}), {
code: 'ERR_NOT_BUILDING_SNAPSHOT',
});
assert.throws(() => setDeserializeMainFunction(() => {}), {
code: 'ERR_NOT_BUILDING_SNAPSHOT',
});

0 comments on commit bddf341

Please sign in to comment.