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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
<!doctype html>
<meta charset=utf-8>
<title>HTMLCollection getters and own properties</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
function append(t, tag, name) {
var element = document.createElement(tag);
if (name) {
element.id = name;
}
document.body.appendChild(element);
t.add_cleanup(function() { element.remove(); });
return element;
}
test(function() {
var name = "named", tag = "a";
var c = document.getElementsByTagName(tag);
var element = append(this, tag, name);
assert_equals(c[name], element);
c[name] = "foo";
assert_equals(c[name], element);
}, "Setting non-array index while named property exists (loose)");
test(function() {
"use strict";
var name = "named", tag = "b";
var c = document.getElementsByTagName(tag);
var element = append(this, tag, name);
assert_equals(c[name], element);
assert_throws_js(TypeError, function() {
c[name] = "foo";
});
assert_equals(c[name], element);
}, "Setting non-array index while named property exists (strict)");
test(function() {
var name = "named", tag = "i";
var c = document.getElementsByTagName(tag);
assert_equals(c[name], undefined);
c[name] = "foo";
assert_equals(c[name], "foo");
var element = append(this, tag, name);
assert_equals(c[name], "foo");
assert_equals(c.namedItem(name), element);
}, "Setting non-array index while named property doesn't exist (loose)");
test(function() {
"use strict";
var name = "named", tag = "p";
var c = document.getElementsByTagName(tag);
assert_equals(c[name], undefined);
c[name] = "foo";
assert_equals(c[name], "foo");
var element = append(this, tag, name);
assert_equals(c[name], "foo");
assert_equals(c.namedItem(name), element);
}, "Setting non-array index while named property doesn't exist (strict)");
test(function() {
var tag = "q";
var c = document.getElementsByTagName(tag);
var element = append(this, tag);
assert_equals(c[0], element);
c[0] = "foo";
assert_equals(c[0], element);
}, "Setting array index while indexed property exists (loose)");
test(function() {
"use strict";
var tag = "s";
var c = document.getElementsByTagName(tag);
var element = append(this, tag);
assert_equals(c[0], element);
assert_throws_js(TypeError, function() {
c[0] = "foo";
});
assert_equals(c[0], element);
}, "Setting array index while indexed property exists (strict)");
test(function() {
var tag = "u";
var c = document.getElementsByTagName(tag);
assert_equals(c[0], undefined);
c[0] = "foo";
assert_equals(c[0], undefined);
var element = append(this, tag);
assert_equals(c[0], element);
}, "Setting array index while indexed property doesn't exist (loose)");
test(function() {
"use strict";
var tag = "u";
var c = document.getElementsByTagName(tag);
assert_equals(c[0], undefined);
assert_throws_js(TypeError, function() {
c[0] = "foo";
});
assert_equals(c[0], undefined);
var element = append(this, tag);
assert_equals(c[0], element);
}, "Setting array index while indexed property doesn't exist (strict)");
</script>
|