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

Commit

Permalink
Merge pull request #109 from azakus/native-proto-ie10
Browse files Browse the repository at this point in the history
Make sure we follow the spec's native prototype resolution for IE10 proto-mixin
  • Loading branch information
arv committed May 19, 2014
2 parents 9b997ca + 325a173 commit edeaaba
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 edeaaba

Please sign in to comment.