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

Commit

Permalink
Make sure we follow the spec's native prototype resolution for IE10 p…
Browse files Browse the repository at this point in the history
…roto-mixin

Fixes #108

add test for proper prototype
  • Loading branch information
dfreedm committed May 19, 2014
1 parent 9b997ca commit 325a173
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/CustomElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ if (useNative) {
// work out prototype when using type-extension
if (definition.is) {
var inst = document.createElement(definition.tag);
nativePrototype = Object.getPrototypeOf(inst);
var expectedPrototype = Object.getPrototypeOf(inst);
// only set nativePrototype if it will actually appear in the definition's chain
if (expectedPrototype === definition.prototype) {
nativePrototype = expectedPrototype;
}
}
// ensure __proto__ reference is installed at each point on the prototype
// chain.
Expand All @@ -210,13 +214,13 @@ if (useNative) {
// limited support for prototype traversal.
var proto = definition.prototype, ancestor;
while (proto && (proto !== nativePrototype)) {
var ancestor = Object.getPrototypeOf(proto);
ancestor = Object.getPrototypeOf(proto);
proto.__proto__ = ancestor;
proto = ancestor;
}
// cache this in case of mixin
definition.native = nativePrototype;
}
// cache this in case of mixin
definition.native = nativePrototype;
}

// SECTION 4
Expand Down
14 changes: 13 additions & 1 deletion test/js/customElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,19 @@
assert.isTrue(CustomElements.instanceof(x2, PCtor), 'instanceof failed for x-button-instance2');
assert.isTrue(CustomElements.instanceof(x2, HTMLButtonElement), 'instanceof failed for x-button-instance2');
});


test('extends and prototype mismatch', function() {
var p = Object.create(HTMLElement.prototype);
var PCtor = document.registerElement('not-button', {
extends: 'button',
prototype: p
});

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

});

htmlSuite('customElements (html)', function() {
Expand Down

0 comments on commit 325a173

Please sign in to comment.