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 const m = new SourceTextModule('1'); 16 await m.link(common.mustNotCall()); 17 assert.strictEqual((await m.evaluate()).result, 1); 18 assert.strictEqual((await m.evaluate()).result, undefined); 19 assert.strictEqual((await m.evaluate()).result, undefined); 20 } 21 22 { 23 const m = new SourceTextModule('throw new Error()'); 24 await m.link(common.mustNotCall()); 25 26 let threw = false; 27 try { 28 await m.evaluate(); 29 } catch (err) { 30 assert(err instanceof Error); 31 threw = true; 32 } 33 assert(threw); 34 35 threw = false; 36 try { 37 await m.evaluate(); 38 } catch (err) { 39 assert(err instanceof Error); 40 threw = true; 41 } 42 assert(threw); 43 } 44 45 finished(); 46})(); 47