File: dynamic-module-map-key.html

package info (click to toggle)
firefox 147.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,324 kB
  • sloc: cpp: 7,607,156; javascript: 6,532,492; ansic: 3,775,158; python: 1,415,368; xml: 634,556; asm: 438,949; java: 186,241; sh: 62,751; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (86 lines) | stat: -rw-r--r-- 4,004 bytes parent folder | download | duplicates (2)
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
84
85
86
<!DOCTYPE html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
  const dynamicScript = document.createElement("script");
  dynamicScript.type = "importmap";
  dynamicScript.innerText = "{ \"imports\": { \"./resources/log.js?pipe=sub&name=A\": \"./resources/log.js?pipe=sub&name=B\" } }";
  document.head.appendChild(dynamicScript);
</script>

<script>
let log = [];

promise_test(() => {
  return import("./resources/log.js?pipe=sub&name=A")
    .then(() => import("./resources/log.js?pipe=sub&name=B"))
    .then(() => assert_array_equals(log, ["log:B"]))
  },
  "Module map's key is the URL after import map resolution");
</script>

<script>
  // Ensure that the Already Started flag is passed through to clones,
  // ensuring the type cannot be changed after it is set to true.
  const dynamicScriptTypeStatic = document.createElement("script");
  dynamicScriptTypeStatic.type = "text/javascript";
  dynamicScriptTypeStatic.type = "importmap";
  dynamicScriptTypeStatic.innerText = "{ \"imports\": { \"./resources/log.js?pipe=sub&name=C\": \"./resources/log.js?pipe=sub&name=D\" } }";
  document.head.appendChild(dynamicScriptTypeStatic);

  // Because the contents aren't empty, once it's connected as an import
  // map, the Already Started flag is set to true and it can't be changed
  // into a classic script.
  document.head.removeChild(dynamicScriptTypeStatic);
  dynamicScriptTypeStatic.type = "text/javascript";
  dynamicScriptTypeStatic.innerText = "test(function() { assert_unreached('Script should not be able to execute after Already Started is set.'); }";
  document.head.appendChild(dynamicScriptTypeStatic);

  // The Already Started flag is copied through to clones, even though
  // `type` is set to "text/javascript" when it is connected.
  const clonedScriptNode = dynamicScriptTypeStatic.cloneNode(/*deep=*/true);
  test(function() {
    assert_equals(clonedScriptNode.type, "text/javascript");
    assert_equals(clonedScriptNode.innerText, "test(function() { assert_unreached('Script should not be able to execute after Already Started is set.'); }");
  }, "Cloned script node copies attribute and text content.");
  document.head.appendChild(clonedScriptNode);

  // Script tags with empty contents do not set Already Started to true,
  // so the type can be changed later and on clones, even if they have
  // been connected.
  const dynamicScriptEmpty = document.createElement("script");
  dynamicScriptEmpty.type = "importmap";
  document.head.appendChild(dynamicScriptEmpty);
  document.head.removeChild(dynamicScriptEmpty);

  // The Already Started flag is copied onto clones.
  dynamicScriptEmpty.type = "text/javascript";
  const clonedEmptyScript = dynamicScriptEmpty.cloneNode(/*deep=*/true);
  test(function() {
    assert_equals(clonedEmptyScript.type, "text/javascript");
    assert_equals(clonedEmptyScript.innerText, "");
  }, "Cloned script node copies attributes and text content.");

  // Because Already Started is false, The clone can be set to a different
  // type than the original element and both can be inserted as their
  // respective types.
  clonedEmptyScript.setAttribute("type", "importmap");
  clonedEmptyScript.innerText = "{ \"imports\": { \"./resources/log.js?pipe=sub&name=E\": \"./resources/log.js?pipe=sub&name=F\" } }";
  document.head.appendChild(clonedEmptyScript);

  const t_evaluate = async_test("The Already Started flag is set when a non-empty <script> tag is connected.");
  dynamicScriptEmpty.innerText = "t_evaluate.done();";
  document.head.appendChild(dynamicScriptEmpty);
</script>

<script>
promise_test(() => {
  return import("./resources/log.js?pipe=sub&name=C")
    .then(() => import("./resources/log.js?pipe=sub&name=D"))
    .then(() => import("./resources/log.js?pipe=sub&name=E"))
    .then(() => assert_array_equals(log, ["log:B", "log:D", "log:F"]))
  },
  "The script tag's Already Started flag is passed to clones.");
</script>
</html>