access-after-element-destruction.js revision eff69b907ef2cd3a9af0351287a929c66f58e3f6
1description("Tests that accessing Attr after its Element has been destroyed works without crashing.");
2
3function gc()
4{
5    if (window.GCController)
6        return GCController.collect();
7
8    // Trigger garbage collection indirectly.
9    for (var i = 0; i < 100000; i++)
10        new String(i);
11}
12
13var element = document.createElement("p");
14element.setAttribute("a", "b");
15var attributes = element.attributes;
16element = null;
17
18gc();
19
20shouldBe("attributes.length", "1");
21shouldBe("attributes[0]", "attributes.item(0)");
22shouldBe("attributes.getNamedItem('a')", "attributes.item(0)");
23
24shouldBe("attributes.item(0).name", "'a'");
25shouldBe("attributes.item(0).specified", "true");
26shouldBe("attributes.item(0).value", "'b'");
27shouldBe("attributes.item(0).ownerElement.tagName", "'P'");
28shouldBe("attributes.item(0).style", "null");
29
30attributes.item(0).value = 'c';
31
32shouldBe("attributes.item(0).value", "'c'");
33
34attributes.removeNamedItem('a');
35
36shouldBe("attributes.length", "0");
37
38element = document.createElement("p");
39element.setAttribute("a", "b");
40var attr = element.attributes.item(0);
41element = null;
42
43gc();
44
45shouldBe("attr.name", "'a'");
46shouldBe("attr.specified", "true");
47shouldBe("attr.value", "'b'");
48shouldBe("attr.ownerElement.tagName", "'P'");
49shouldBe("attr.style", "null");
50
51attr.value = 'c';
52
53shouldBe("attr.value", "'c'");
54
55var successfullyParsed = true;
56