11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Flags: --experimental-vm-modules 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cirequire('../common'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst { SourceTextModule } = require('vm'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci{ 111cb0ef41Sopenharmony_ci const m = new SourceTextModule('const a = 1'); 121cb0ef41Sopenharmony_ci const cachedData = m.createCachedData(); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci new SourceTextModule('const a = 1', { cachedData }); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci assert.throws(() => { 171cb0ef41Sopenharmony_ci new SourceTextModule('differentSource', { cachedData }); 181cb0ef41Sopenharmony_ci }, { 191cb0ef41Sopenharmony_ci code: 'ERR_VM_MODULE_CACHED_DATA_REJECTED', 201cb0ef41Sopenharmony_ci }); 211cb0ef41Sopenharmony_ci} 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciassert.rejects(async () => { 241cb0ef41Sopenharmony_ci const m = new SourceTextModule('const a = 1'); 251cb0ef41Sopenharmony_ci await m.link(() => {}); 261cb0ef41Sopenharmony_ci m.evaluate(); 271cb0ef41Sopenharmony_ci m.createCachedData(); 281cb0ef41Sopenharmony_ci}, { 291cb0ef41Sopenharmony_ci code: 'ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA', 301cb0ef41Sopenharmony_ci}); 31