File: GetOwnProperty.html

package info (click to toggle)
thunderbird 1%3A143.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,703,968 kB
  • sloc: cpp: 7,770,492; javascript: 5,943,842; ansic: 3,918,754; python: 1,418,263; xml: 653,354; asm: 474,045; java: 183,079; sh: 111,238; makefile: 20,410; perl: 14,359; objc: 13,059; yacc: 4,583; pascal: 3,405; lex: 1,720; ruby: 999; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (84 lines) | stat: -rw-r--r-- 3,903 bytes parent folder | download | duplicates (15)
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>Legacy platform objects [[GetOwnProperty]] method</title>
<link rel="help" href="https://webidl.spec.whatwg.org/#legacy-platform-object-getownproperty">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./helper.js"></script>
<script>

test(function() {
  // DOMTokenList has an indexed property getter, no indexed property setter
  // and no named property handlers.
  let div = document.createElement("div");
  div.classList.add("baz", "quux");
  const domTokenList = div.classList;
  assert_prop_desc_equals(
      domTokenList, "1",
      {value: "quux", writable: false, enumerable: true, configurable: true},
      "[[GetOwnProperty]] for indexed properties returns the right descriptor");
  assert_prop_desc_equals(
      domTokenList, "42", undefined,
      "[[GetOwnProperty]] with invalid index returns undefined");
  assert_array_equals(Object.keys(domTokenList), ["0", "1"]);
  assert_array_equals(Object.values(domTokenList), ["baz", "quux"]);

  // getElementsByTagName() returns an HTMLCollection.
  // HTMLCollection has indexed and named property getters, no setters. Its IDL
  // interface declaration has [LegacyUnenumerableNamedProperties] so its named
  // properties are not enumerable.
  let span1 = document.createElement("span");
  span1.id = "foo";
  let span2 = document.createElement("span");
  span2.id = "bar";
  document.head.appendChild(span1);
  document.head.appendChild(span2);
  const elementList = document.getElementsByTagName("span");
  assert_prop_desc_equals(
      elementList, "foo",
      {value: span1, writable: false, enumerable: false, configurable: true},
      "[[GetOwnProperty]] for named properties returns the right descriptor");
  assert_prop_desc_equals(
      elementList, "1",
      {value: span2, writable: false, enumerable: true, configurable: true},
      "[[GetOwnProperty]] for indexed properties returns the right descriptor");
  assert_prop_desc_equals(
      elementList, "unknown", undefined,
      "[[GetOwnProperty]] with invalid property name returns undefined");
  assert_array_equals(Object.keys(elementList), ["0", "1"]);
  assert_array_equals(Object.values(elementList), [span1, span2]);
}, "[[GetOwnProperty]] with getters and no setters");

test(function() {
  // DOMStringMap supports named property getters and setters, but not indexed
  // properties.
  let span = document.createElement("span");
  span.dataset.foo = "bar";
  assert_prop_desc_equals(
      span.dataset, "foo",
      {value: "bar", writable: true, enumerable: true, configurable: true},
      "[[GetOwnProperty]] for named properties returns the right descriptor");
  assert_prop_desc_equals(
      span.dataset, "unknown", undefined,
      "[[GetOwnProperty]] with invalid property name returns undefined");
  assert_array_equals(Object.keys(span.dataset), ["foo"]);
  assert_array_equals(Object.values(span.dataset), ["bar"]);
}, "[[GetOwnProperty]] with named property getters and setters");

test(function() {
  // HTMLSelectElement has indexed property getters and setters, but no support
  // for named properties.
  let selectElement = document.createElement("select");
  assert_prop_desc_equals(
      selectElement, "0", undefined,
      "[[GetOwnProperty]] with invalid property index returns undefined");
  let optionElement = document.createElement("option");
  selectElement.appendChild(optionElement);
  assert_prop_desc_equals(
      selectElement, "0",
      {value: optionElement, writable: true, enumerable: true, configurable: true},
      "[[GetOwnProperty]] for indexed properties returns the right descriptor");
  assert_array_equals(Object.keys(selectElement), ["0"]);
  assert_array_equals(Object.values(selectElement), [optionElement]);
}, "[[GetOwnProperty]] with indexed property getters and setters");
</script>