summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-of-promise-result.html
blob: 5514049c78ddf888b6cf7eca8ab73f3d5866e7c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<meta charset="utf-8">
<title>import() inside compiled strings inside a classic script</title>
<link rel="help" href="https://github.com/whatwg/html/pull/3163">
<link rel="help" href="https://github.com/tc39/ecma262/issues/871#issuecomment-292493142">
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<base href="scripts/foo/">
<script>
"use strict";

// This test is based on the current specification, but all browser
// implementations aren't conformant. See
// https://bugs.chromium.org/p/chromium/issues/detail?id=1245063
// https://github.com/heycam/webidl/pull/902

// Tweak the base URL of the document here to distinguish:
// - document URL
// - document base URL = ../
// - This inline script's base URL = ./scripts/foo/
document.querySelector("base").remove();
const base = document.createElement("base");
base.setAttribute("href", "../");
document.body.appendChild(base);

self.ran = false;

// The active script for the dynamic import is this inline script
// (see https://html.spec.whatwg.org/C/#hostmakejobcallback).
promise_test(t => {
  t.add_cleanup(() => {
    self.ran = false;
  })

  return Promise.resolve(`import("../../../imports-a.js?1").then(() => { self.ran = true; })`)
    .then(eval)
    .then(() => {
      assert_true(self.ran);
    });
}, "Evaled the script via eval, successful import");

promise_test(t => {
  t.add_cleanup(() => {
    self.ran = false;
  })

  return Promise.resolve(`import("bad-specifier?1").catch(() => { self.ran = true; })`)
    .then(eval)
    .then(() => {
      assert_true(self.ran);
    });
}, "Evaled the script via eval, failed import");

promise_test(t => {
  t.add_cleanup(() => {
    self.ran = false;
  })

  return Promise.resolve(`return import("../../../imports-a.js?2").then(() => { self.ran = true; })`)
    .then(Function)
    .then(Function.prototype.call.bind(Function.prototype.call))
    .then(() => {
      assert_true(self.ran);
    });
}, "Evaled the script via Function, successful import");

promise_test(t => {
  t.add_cleanup(() => {
    self.ran = false;
  })

  return Promise.resolve(`return import("bad-specifier?2").catch(() => { self.ran = true; })`)
    .then(Function)
    .then(Function.prototype.call.bind(Function.prototype.call))
    .then(() => {
      assert_true(self.ran);
    });
}, "Evaled the script via Function, failed import");
</script>