Skip to content

Commit d4888ba

Browse files
EdgarChenjgraham
authored andcommitted
Fix attributeChangedCallback isn't fired with correct newValue when the attribute value is an empty string;
MozReview-Commit-ID: L3RvNPNDfUC Upstreamed from https://bugzilla.mozilla.org/show_bug.cgi?id=1430034 [ci skip]
1 parent 64b9832 commit d4888ba

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

custom-elements/attribute-changed-callback.html

+31
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</head>
1212
<body>
1313
<div id="log"></div>
14+
<parser-created-element title></parser-created-element>
1415
<script>
1516

1617
var customElement = define_new_custom_element(['title', 'id', 'r']);
@@ -218,6 +219,36 @@
218219
assert_attribute_log_entry(calls[0], {name: 'title', oldValue: null, newValue: 'hello', namespace: null});
219220
}, 'attributedChangedCallback must not be enqueued when mutating inline style declaration if the style attribute is not observed');
220221

222+
test(function () {
223+
var calls = [];
224+
class CustomElement extends HTMLElement { }
225+
CustomElement.prototype.attributeChangedCallback = function (...args) {
226+
calls.push(create_attribute_changed_callback_log(this, ...args));
227+
}
228+
CustomElement.observedAttributes = ['title'];
229+
customElements.define('parser-created-element', CustomElement);
230+
assert_attribute_log_entry(calls[0], {name: 'title', oldValue: null, newValue: '', namespace: null});
231+
}, 'Upgrading a parser created element must enqueue and invoke attributeChangedCallback for an HTML attribute');
232+
233+
test(function () {
234+
var calls = [];
235+
class CustomElement extends HTMLElement { }
236+
CustomElement.prototype.attributeChangedCallback = function (...args) {
237+
calls.push(create_attribute_changed_callback_log(this, ...args));
238+
}
239+
CustomElement.observedAttributes = ['title'];
240+
customElements.define('cloned-element-with-attribute', CustomElement);
241+
242+
var instance = document.createElement('cloned-element-with-attribute');
243+
assert_equals(calls.length, 0);
244+
instance.title = '';
245+
assert_attribute_log_entry(calls[0], {name: 'title', oldValue: null, newValue: '', namespace: null});
246+
247+
calls = [];
248+
var clone = instance.cloneNode(false);
249+
assert_attribute_log_entry(calls[0], {name: 'title', oldValue: null, newValue: '', namespace: null});
250+
}, 'Upgrading a cloned element must enqueue and invoke attributeChangedCallback for an HTML attribute');
251+
221252
</script>
222253
</body>
223254
</html>

0 commit comments

Comments
 (0)