| OLD | NEW |
| 1 description("This tests element.dataset."); | 1 description("This tests element.dataset."); |
| 2 | 2 |
| 3 function testGet(attr, expected) | 3 function testGet(attr, expected) |
| 4 { | 4 { |
| 5 var d = document.createElement("div"); | 5 var d = document.createElement("div"); |
| 6 d.setAttribute(attr, "value"); | 6 d.setAttribute(attr, "value"); |
| 7 return d.dataset[expected] == "value"; | 7 return d.dataset[expected] == "value"; |
| 8 } | 8 } |
| 9 | 9 |
| 10 shouldBeTrue("testGet('data-foo', 'foo')"); | 10 shouldBeTrue("testGet('data-foo', 'foo')"); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 shouldBeTrue("testDelete('data-', '')"); | 109 shouldBeTrue("testDelete('data-', '')"); |
| 110 shouldBeTrue("testDelete('data-\xE0', '\xE0')"); | 110 shouldBeTrue("testDelete('data-\xE0', '\xE0')"); |
| 111 shouldBeTrue("testDelete('data-33', '33')"); | 111 shouldBeTrue("testDelete('data-33', '33')"); |
| 112 shouldBeTrue("testDelete('data-00033', '00033')"); | 112 shouldBeTrue("testDelete('data-00033', '00033')"); |
| 113 shouldBeTrue("testDelete('data-r2', 'r2')"); | 113 shouldBeTrue("testDelete('data-r2', 'r2')"); |
| 114 shouldBeTrue("testDelete('data-2r', '2r')"); | 114 shouldBeTrue("testDelete('data-2r', '2r')"); |
| 115 shouldBeTrue("testDelete('data-r-2', 'r-2')"); | 115 shouldBeTrue("testDelete('data-r-2', 'r-2')"); |
| 116 shouldBeTrue("testDelete('data--r-2-', 'R-2-')"); | 116 shouldBeTrue("testDelete('data--r-2-', 'R-2-')"); |
| 117 shouldBeTrue("testDelete('data--r-2r', 'R-2r')"); | 117 shouldBeTrue("testDelete('data--r-2r', 'R-2r')"); |
| 118 shouldBeTrue("testDelete('data--r-2-----r', 'R-2----R')"); | 118 shouldBeTrue("testDelete('data--r-2-----r', 'R-2----R')"); |
| 119 |
| 120 // The element.dataset deleter is only applied to properties |
| 121 // that are present; check that any underlying native property |
| 122 // is deleted instead. |
| 123 function testNativeDelete(prop, isConfigurable) |
| 124 { |
| 125 var d = document.createElement("div"); |
| 126 Object.defineProperty(d.dataset, prop, {configurable: isConfigurable, value:
"native_value"}); |
| 127 delete d.dataset[prop]; |
| 128 return isConfigurable ? !(prop in d.dataset) : (d.dataset[prop] === "native_
value"); |
| 129 } |
| 130 |
| 131 shouldBeTrue("testNativeDelete('-r-2-', false)"); |
| 132 shouldBeTrue("testNativeDelete('foo', true)"); |
| 133 |
| 119 debug(""); | 134 debug(""); |
| 120 | 135 |
| 121 shouldBeFalse("testDelete('dummy', '-foo')"); | 136 shouldBeFalse("testDelete('dummy', '-foo')"); |
| 122 debug(""); | 137 debug(""); |
| 123 | 138 |
| 124 function testForIn(array) | 139 function testForIn(array) |
| 125 { | 140 { |
| 126 var d = document.createElement("div"); | 141 var d = document.createElement("div"); |
| 127 for (var i = 0; i < array.length; ++i) { | 142 for (var i = 0; i < array.length; ++i) { |
| 128 d.setAttribute(array[i], "value"); | 143 d.setAttribute(array[i], "value"); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 shouldBe("div.getAttribute('data-a-500k')", "'updated'"); | 210 shouldBe("div.getAttribute('data-a-500k')", "'updated'"); |
| 196 | 211 |
| 197 debug(""); | 212 debug(""); |
| 198 debug("Set null:"); | 213 debug("Set null:"); |
| 199 | 214 |
| 200 var d = document.createElement("div"); | 215 var d = document.createElement("div"); |
| 201 d.dataset.foo = null; | 216 d.dataset.foo = null; |
| 202 shouldBe("d.dataset.foo", "'null'"); | 217 shouldBe("d.dataset.foo", "'null'"); |
| 203 | 218 |
| 204 debug(""); | 219 debug(""); |
| OLD | NEW |