Skip to content

Commit

Permalink
Improve IE compatibility by ensuring the __proto__ chain always exists.
Browse files Browse the repository at this point in the history
In conjunction with googlearchive/CustomElements@9b4c5df,
helps address #217.
  • Loading branch information
sorvell committed Jul 30, 2013
1 parent 5ab7b2f commit 62eb34b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/declaration/polymer-element.js
Expand Up @@ -66,14 +66,17 @@
// Potentially remove when spec bug is addressed.
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=21407
this.addResolvePathApi();
// declarative features
this.desugar();
// under ShadowDOMPolyfill, transforms to approximate missing CSS features
if (window.ShadowDOMPolyfill) {
Platform.ShadowCSS.shimStyling(this.templateContent(), name, extnds);
}
// register our custom element
this.register(name);
// declarative features
// NOTE: make sure to desugar after calling register. Registration
// ensures the __proto__ chain exists on platforms that don't support it
// natively (IE10), and desugar uses the __proto__ chain.
this.desugar();
// reference constructor in a global named by 'constructor' attribute
this.publishConstructor();
},
Expand Down Expand Up @@ -132,7 +135,7 @@
// make a fresh object that inherits from a prototype object
inheritObject: function(prototype, name) {
// copy inherited properties onto a new object
prototype[name] = extend({}, prototype.__proto__[name]);
prototype[name] = extend({}, Object.getPrototypeOf(prototype)[name]);
},
// register 'prototype' to custom element 'name', store constructor
register: function(name) {
Expand Down
11 changes: 9 additions & 2 deletions src/lib/super.js
Expand Up @@ -38,7 +38,7 @@
}
// super prototype is either cached or we have to find it
// by searching __proto__ (at the 'top')
memoizeSuper(caller, nom, Object.getPrototypeOf(this));
memoizeSuper(caller, nom, getPrototypeOf(this));
}
var _super = caller._super;
if (!_super) {
Expand All @@ -61,7 +61,7 @@
// look for an inherited prototype that implements name
while (proto &&
(!proto.hasOwnProperty(name) || proto[name] === caller)) {
proto = Object.getPrototypeOf(proto);
proto = getPrototypeOf(proto);
}
return proto;
};
Expand Down Expand Up @@ -93,6 +93,13 @@
p = p.__proto__;
}
}

// NOTE: In some platforms (IE10) the prototype chain is faked via
// __proto__. Therefore, always get prototype via __proto__ instead of
// the more standard Object.getPrototypeOf.
function getPrototypeOf(prototype) {
return prototype.__proto__;
}

// exports

Expand Down

0 comments on commit 62eb34b

Please sign in to comment.