modules-import-15.mjs 1.35 KB
Newer Older
1 2 3 4 5
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax --harmony-dynamic-import
6 7 8
//
// Note: This test fails with top level await due to test1, which tries to
//       import a module using top level await and expects it to fail.
9 10 11 12 13

var ran = false;

async function test1() {
  try {
14
    let x = await import('modules-skip-8.mjs');
15 16 17 18 19 20 21 22
    %AbortJS('failure: should be unreachable');
  } catch(e) {
    assertEquals('Unexpected reserved word', e.message);
    ran = true;
  }
}

test1();
23
%PerformMicrotaskCheckpoint();
24 25 26 27 28 29
assertTrue(ran);

ran = false;

async function test2() {
  try {
30
    let x = await import('modules-skip-9.mjs');
31 32 33 34
    %AbortJS('failure: should be unreachable');
  } catch(e) {
    assertInstanceof(e, SyntaxError);
    assertEquals(
35
      "The requested module 'modules-skip-empty.mjs' does not provide an " +
36
      "export named 'default'",
37 38 39 40 41 42
      e.message);
    ran = true;
  }
}

test2();
43
%PerformMicrotaskCheckpoint();
44 45 46 47 48 49
assertTrue(ran);

ran = false;

async function test3() {
  try {
50
    let x = await import('nonexistent-file.mjs');
51 52 53 54 55 56 57 58
    %AbortJS('failure: should be unreachable');
  } catch(e) {
    assertTrue(e.startsWith('Error reading'));
    ran = true;
  }
}

test3();
59
%PerformMicrotaskCheckpoint();
60
assertTrue(ran);