11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Flags: --experimental-vm-modules
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst common = require('../common');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst { SourceTextModule } = require('vm');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst finished = common.mustCall();
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci(async function main() {
141cb0ef41Sopenharmony_ci  {
151cb0ef41Sopenharmony_ci    globalThis.count = 0;
161cb0ef41Sopenharmony_ci    const m = new SourceTextModule('count += 1;');
171cb0ef41Sopenharmony_ci    await m.link(common.mustNotCall());
181cb0ef41Sopenharmony_ci    assert.strictEqual(await m.evaluate(), undefined);
191cb0ef41Sopenharmony_ci    assert.strictEqual(globalThis.count, 1);
201cb0ef41Sopenharmony_ci    assert.strictEqual(await m.evaluate(), undefined);
211cb0ef41Sopenharmony_ci    assert.strictEqual(globalThis.count, 1);
221cb0ef41Sopenharmony_ci    assert.strictEqual(await m.evaluate(), undefined);
231cb0ef41Sopenharmony_ci    assert.strictEqual(globalThis.count, 1);
241cb0ef41Sopenharmony_ci    delete globalThis.count;
251cb0ef41Sopenharmony_ci  }
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  {
281cb0ef41Sopenharmony_ci    const m = new SourceTextModule('throw new Error()');
291cb0ef41Sopenharmony_ci    await m.link(common.mustNotCall());
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci    let threw = false;
321cb0ef41Sopenharmony_ci    try {
331cb0ef41Sopenharmony_ci      await m.evaluate();
341cb0ef41Sopenharmony_ci    } catch (err) {
351cb0ef41Sopenharmony_ci      assert(err instanceof Error);
361cb0ef41Sopenharmony_ci      threw = true;
371cb0ef41Sopenharmony_ci    }
381cb0ef41Sopenharmony_ci    assert(threw);
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci    threw = false;
411cb0ef41Sopenharmony_ci    try {
421cb0ef41Sopenharmony_ci      await m.evaluate();
431cb0ef41Sopenharmony_ci    } catch (err) {
441cb0ef41Sopenharmony_ci      assert(err instanceof Error);
451cb0ef41Sopenharmony_ci      threw = true;
461cb0ef41Sopenharmony_ci    }
471cb0ef41Sopenharmony_ci    assert(threw);
481cb0ef41Sopenharmony_ci  }
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci  finished();
511cb0ef41Sopenharmony_ci})().then(common.mustCall());
52