• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Flags: --experimental-vm-modules
4
5require('../common');
6
7const assert = require('assert');
8const { SourceTextModule } = require('vm');
9
10{
11  const m = new SourceTextModule('const a = 1');
12  const cachedData = m.createCachedData();
13
14  new SourceTextModule('const a = 1', { cachedData });
15
16  assert.throws(() => {
17    new SourceTextModule('differentSource', { cachedData });
18  }, {
19    code: 'ERR_VM_MODULE_CACHED_DATA_REJECTED',
20  });
21}
22
23assert.rejects(async () => {
24  const m = new SourceTextModule('const a = 1');
25  await m.link(() => {});
26  m.evaluate();
27  m.createCachedData();
28}, {
29  code: 'ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA',
30});
31