1'use strict'; 2 3// Flags: --experimental-vm-modules 4 5const common = require('../common'); 6 7const assert = require('assert'); 8 9const { SourceTextModule } = require('vm'); 10 11const finished = common.mustCall(); 12 13(async function main() { 14 { 15 globalThis.count = 0; 16 const m = new SourceTextModule('count += 1;'); 17 await m.link(common.mustNotCall()); 18 assert.strictEqual(await m.evaluate(), undefined); 19 assert.strictEqual(globalThis.count, 1); 20 assert.strictEqual(await m.evaluate(), undefined); 21 assert.strictEqual(globalThis.count, 1); 22 assert.strictEqual(await m.evaluate(), undefined); 23 assert.strictEqual(globalThis.count, 1); 24 delete globalThis.count; 25 } 26 27 { 28 const m = new SourceTextModule('throw new Error()'); 29 await m.link(common.mustNotCall()); 30 31 let threw = false; 32 try { 33 await m.evaluate(); 34 } catch (err) { 35 assert(err instanceof Error); 36 threw = true; 37 } 38 assert(threw); 39 40 threw = false; 41 try { 42 await m.evaluate(); 43 } catch (err) { 44 assert(err instanceof Error); 45 threw = true; 46 } 47 assert(threw); 48 } 49 50 finished(); 51})().then(common.mustCall()); 52