11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Flags: --experimental-vm-modules
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst common = require('../common');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst { SourceTextModule } = require('vm');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciasync function testBasic() {
101cb0ef41Sopenharmony_ci  const m = new SourceTextModule('globalThis.importMeta = import.meta;', {
111cb0ef41Sopenharmony_ci    initializeImportMeta: common.mustCall((meta, module) => {
121cb0ef41Sopenharmony_ci      assert.strictEqual(module, m);
131cb0ef41Sopenharmony_ci      meta.prop = 42;
141cb0ef41Sopenharmony_ci    })
151cb0ef41Sopenharmony_ci  });
161cb0ef41Sopenharmony_ci  await m.link(common.mustNotCall());
171cb0ef41Sopenharmony_ci  await m.evaluate();
181cb0ef41Sopenharmony_ci  const result = globalThis.importMeta;
191cb0ef41Sopenharmony_ci  delete globalThis.importMeta;
201cb0ef41Sopenharmony_ci  assert.strictEqual(typeof result, 'object');
211cb0ef41Sopenharmony_ci  assert.strictEqual(Object.getPrototypeOf(result), null);
221cb0ef41Sopenharmony_ci  assert.strictEqual(result.prop, 42);
231cb0ef41Sopenharmony_ci  assert.deepStrictEqual(Reflect.ownKeys(result), ['prop']);
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciasync function testInvalid() {
271cb0ef41Sopenharmony_ci  for (const invalidValue of [
281cb0ef41Sopenharmony_ci    null, {}, 0, Symbol.iterator, [], 'string', false,
291cb0ef41Sopenharmony_ci  ]) {
301cb0ef41Sopenharmony_ci    assert.throws(() => {
311cb0ef41Sopenharmony_ci      new SourceTextModule('', {
321cb0ef41Sopenharmony_ci        initializeImportMeta: invalidValue
331cb0ef41Sopenharmony_ci      });
341cb0ef41Sopenharmony_ci    }, {
351cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
361cb0ef41Sopenharmony_ci      name: 'TypeError'
371cb0ef41Sopenharmony_ci    });
381cb0ef41Sopenharmony_ci  }
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci(async () => {
421cb0ef41Sopenharmony_ci  await testBasic();
431cb0ef41Sopenharmony_ci  await testInvalid();
441cb0ef41Sopenharmony_ci})().then(common.mustCall());
45