question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setPrototypeOf not supported in IE9 - IE10

See original GitHub issue

The config for Object.setPrototypeOf refers to support for IEs 9-11 (https://github.com/Financial-Times/polyfill-service/blob/master/polyfills/Object/setPrototypeOf/config.json), but the source repo refers to IE 11+ (https://github.com/paulmillr/es6-shim/blame/master/README.md#L78) – and indeed am finding errors using IE10 that boil down to the fill behaving incorrectly and causing incorrect inheritance behaviour in babel-transpiled code. (FYI Babel works around not having the setPrototypeOf method present.)

My workaround (for anyone else hitting the same issue) is to add excludes=Object.setPrototypeOf to my polyfill URL (so I’m not getting a bad fill added), and add import "core-js/fn/object/set-prototype-of"; early in my code (so that I do have a fill for compatible browsers). This works okay so far.

I’m thinking that the fix here is to not fill setPrototypeOf for IE < 11, but I would imagine lots of other fills are relying on it… happy to submit a PR once steered!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ejulianovacommented, Mar 7, 2018

Hey @JakeChampion, I have the same issue. Here’s a codepen where you can repro it in IE9/10: https://codepen.io/anon/pen/JpQQMq

Looks like Object.getPrototypeOf(Bar)) doesn’t return what we expect and the parent constructor never gets called. Note that the code is preprocessed with babel to the following:

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Foo = function Foo(options) {
  _classCallCheck(this, Foo);

  console.log('[Foo] constructor called', options);
  this.options = options;
  this.someOption = options.someOption;
};

var Bar = function (_Foo) {
  _inherits(Bar, _Foo);

  function Bar(options) {
    _classCallCheck(this, Bar);

    var _this = _possibleConstructorReturn(this, (Bar.__proto__ || Object.getPrototypeOf(Bar)).call(this, options));

    console.log('[Bar] constructor called', options);
    console.log(_this.someOption);
    return _this;
  }

  return Bar;
}(Foo);

var bar = new Bar({ someOption: { blabla: 123 } });

It works when setPrototypeOf polyfill is excluded, because babel does the following: if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;

1reaction
shaunscommented, May 21, 2018

@kentcdodds I exclude it, and then manually reimport directly from core-js to make sure IE11 and similar have it. I do wonder if the fix for this is just to set the expected browser range here to match that of the underlying polyfill.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IE9 does not recognize prototype function? - Stack Overflow
setPrototypeOf is an ECMAScript ed 6 method (which is still a draft, not a standard) and therefore not widely supported. The MDN page...
Read more >
@kt3k/proto-polyfill - npm
getPrototypeOf , Object.getOwnPropertyNames , Object.getOwnPropertyDescriptor and Object.create : IE 9; IE 10. IE 8 is not supported.
Read more >
Caveats - Babel.js
This is done through the use of Object.defineProperty which is unsupported in IE8 and below. A workaround for this is to enable the...
Read more >
Object doesn't support property or method 'setPrototypeOf ...
I've created a react app using "create-react-app" command and updated all packages in package.json, App was not working in IE(any version) ...
Read more >
angular6、7 兼容ie9、10、11 - 飞尽堂前燕- 博客园
如果IE10报错则引入一下代码到polyfills.ts 顶部如果ie9报错则注销掉此段代码最后 ... Standard animation support in Angular DOES NOT require any ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found