Skip to content

Commit

Permalink
Fix Custom Element instance creation in IE11, redo
Browse files Browse the repository at this point in the history
This is a continuation of ampproject#25245. All of our Custom Elements extend from a common `CustomAmpElement` class, which itself extends from `HTMLElementPolyfill`. In ampproject#27470, I removed the `constructor` from `CustomAmpElement` class. But, because it's a subclass and must have a `constructor` that calls `super()`, Closure replaced it with a `constructor() { superClass.apply(this, arguments); }` when transpiling.

But, due to the same faulty inheritance chain described in ampproject#25245, `HTMLElementPolyfill` doesn't inherit an `apply` method! So doing `superClass.apply()` throws an error. 😭

This PR installs all important Function methods onto our polyfill, to be resilient to any future changes in the instance creation.
  • Loading branch information
jridgewell committed Apr 15, 2020
1 parent 29193a1 commit 881a65e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/polyfills/custom-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,8 @@ function polyfill(win) {
// And because `HTMLElementPolyfill` extends from `HTMLElement`, it doesn't
// have a `.call`! So we need to manually install it.
if (!HTMLElementPolyfill.call) {
HTMLElementPolyfill.apply = win.Function.apply;
HTMLElementPolyfill.bind = win.Function.bind;
HTMLElementPolyfill.call = win.Function.call;
}
}
Expand Down

0 comments on commit 881a65e

Please sign in to comment.