Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Fix extends/prototype mismatch test for silly Firefox instanceof hack
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed May 19, 2014
1 parent edeaaba commit 9cfef1f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions test/js/customElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* license that can be found in the LICENSE file.
*/

suite('customElements', function() {
suite('customElements', function() {
var work;
var assert = chai.assert;
var HTMLNS = 'http://www.w3.org/1999/xhtml';
Expand Down Expand Up @@ -459,7 +459,7 @@
assert.isTrue(CustomElements.instanceof(x2, PCtor), 'instanceof failed for x-instance2');
});


test('instanceof typeExtension', function() {
var p = Object.create(HTMLButtonElement.prototype);
var PCtor = document.registerElement('x-button-instance', {prototype: p, extends: 'button'});
Expand Down Expand Up @@ -490,8 +490,20 @@
});

var e = document.createElement('button', 'not-button');
assert.isFalse(CustomElements.instanceof(e, HTMLButtonElement));
assert.isTrue(CustomElements.instanceof(e, HTMLElement));

// NOTE: firefox has a hack for instanceof that uses element tagname mapping
// Work around by checking prototype manually
//
var ff = document.createElement('button'); ff.__proto__ = null;
if (ff instanceof HTMLButtonElement) {
// Base proto will be one below custom proto
var proto = e.__proto__.__proto__;
assert.isFalse(proto === HTMLButtonElement.prototype);
assert.isTrue(proto === HTMLElement.prototype);
} else {
assert.isFalse(CustomElements.instanceof(e, HTMLButtonElement));
assert.isTrue(CustomElements.instanceof(e, HTMLElement));
}
});

});
Expand Down

0 comments on commit 9cfef1f

Please sign in to comment.