summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/DefineOwnProperty.html
blob: ad32f6f89f591c74de298c197366b641fd6c5f29 (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
84
85
86
87
88
89
<!DOCTYPE html>
<meta charset="utf-8">
<title>Legacy platform objects [[DefineOwnProperty]] method</title>
<link rel="help" href="https://webidl.spec.whatwg.org/#legacy-platform-object-defineownproperty">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./helper.js"></script>
<script>

test(function() {
  let span = document.createElement("span");
  span.className = "foo";
  // DOMTokenList supports an indexed property getter but not a setter.
  let domTokenList = span.classList;
  // Confirm the test settings.
  assert_equals(domTokenList.length, 1);
  assert_prop_desc_equals(domTokenList, "0",
                          {value: "foo", writable: false, enumerable: true,
                           configurable: true});
  assert_prop_desc_equals(domTokenList, "1", undefined);
  // Actual test
  assert_throws_js(TypeError, () =>
      Object.defineProperty(domTokenList, "0", {value: true, writable: true}));
  assert_throws_js(TypeError, () =>
      Object.defineProperty(domTokenList, "1", {value: true, writable: true}));
  assert_throws_js(TypeError, () =>
      Object.defineProperty(domTokenList, "0", {get: () => {}}));
  assert_throws_js(TypeError, () =>
      Object.defineProperty(domTokenList, "0", {set: () => {}}));
  assert_throws_js(TypeError, () =>
      Object.defineProperty(domTokenList, "1", {get: () => {}}));
  assert_throws_js(TypeError, () =>
      Object.defineProperty(domTokenList, "1", {set: () => {}}));
  assert_equals(domTokenList[0], "foo");
  assert_equals(domTokenList[1], undefined);
  domTokenList[0] = "bar";
  domTokenList[1] = "bar";
  assert_equals(domTokenList[0], "foo");
  assert_equals(domTokenList[1], undefined);
  assert_throws_js(TypeError, () => {
    "use strict";
    domTokenList[0] = "bar";
  });
  assert_throws_js(TypeError, () => {
    "use strict";
    domTokenList[1] = "bar";
  });
  // Nothing must change after all.
  assert_equals(domTokenList.length, 1);
  assert_prop_desc_equals(domTokenList, "0",
                          {value: "foo", writable: false, enumerable: true,
                           configurable: true});
  assert_prop_desc_equals(domTokenList, "1", undefined);
}, "Test [[DefineOwnProperty]] with no indexed property setter support.");

test(function() {
  // HTMLSelectElement supports an indexed property setter.
  let select = document.createElement("select");
  let option0 = document.createElement("option");
  let option1 = document.createElement("option");
  // Confirm the test settings.
  assert_equals(select.length, 0);
  assert_prop_desc_equals(select, "0", undefined);
  // Try to define an accessor property with non supported property index.
  assert_throws_js(TypeError, () =>
      Object.defineProperty(select, "0", {get: () => {}}));
  assert_throws_js(TypeError, () =>
      Object.defineProperty(select, "0", {set: () => {}}));
  assert_prop_desc_equals(select, "0", undefined);
  // writable, enumerable, configurable will be ignored.
  Object.defineProperty(select, "0", {value: option0, writable: false,
                                      enumerable: false, configurable: false});
  assert_prop_desc_equals(select, "0",
                          {value: option0, writable: true, enumerable: true,
                           configurable: true});
  select[1] = option1;
  assert_prop_desc_equals(select, "1",
                          {value: option1, writable: true, enumerable: true,
                           configurable: true});
  // Try to define an accessor property with a supported property index.
  assert_throws_js(TypeError, () =>
      Object.defineProperty(select, "0", {get: () => {}}));
  assert_throws_js(TypeError, () =>
      Object.defineProperty(select, "0", {set: () => {}}));
  assert_prop_desc_equals(select, "0",
                          {value: option0, writable: true, enumerable: true,
                           configurable: true});
}, "Test [[DefineOwnProperty]] with indexed property setter support.");
</script>