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.

[Object.defineProperty] possible to contribute a fix on 3.x series?

See original GitHub issue

What

The Object.defineProperty polyfill correctly makes use of the native version when exists, but only on very specific objects. Thus, for random general usage the polyfill blatantly ignores the native Object.defineProperty. I can’t seem to find a reason to not use the native version always if exists (why limit it to window, document, or Element ?).

We find this problem when trying to force-load the bind polyfill with: https://polyfill.io/v3/polyfill.js?features=Function.prototype.bind|always

Details

We would need this fixed on the 3.x line, given that the latest 4.x line also removes the Function.prototype.bind which is required for our use case.

I’ve prepared a branch, but I can’t contribute a PR to create a new 3.x branch in this repository. AFAIK the creation of that new branch would be required to introduce changes based on 3.111.0: https://github.com/Financial-Times/polyfill-library/compare/v3.111.0...the-hotels-network:3.x?expand=1

Please let me know if I can help this advance. Thanks a lot @JakeChampion and contributors.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
ghostcommented, Jun 21, 2022

I’d like to understand why would make sense limiting in there the nativeDefineProperty usage to window, document, element, etc?

The issue with the native Object.defineProperty is in Internet explorer 8, Object.defineProperty could only work on DOM elements, and not on any type of object.

Ouuuuch. Good insight! All finally makes sense, and nothing should be changed on 3.x then… I definetily need to push the bind polyfill free of the Object.defineProperty dep, but It can’t be done with the current polyfill-service. And shouldn’t, since that is a too specific use case. I will have to solve the situation by other means.

Thanks a lot for your help @JakeChampion @romainmenke 👏 ❤️

1reaction
JakeChampioncommented, Jun 21, 2022

I’d like to understand why would make sense limiting in there the nativeDefineProperty usage to window, document, element, etc?

The issue with the native Object.defineProperty is in Internet explorer 8, Object.defineProperty could only work on DOM elements, and not on any type of object.

The feature detection test confirms whether Object.defineProperty can work on any type of object

https://github.com/Financial-Times/polyfill-library/blob/554248173eae7554ef0a7776549d2901f02a7d51/polyfills/Object/defineProperty/detect.js#L1-L11

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object.defineProperty() - JavaScript - MDN Web Docs
defineProperty () defines a new property directly on an object, or modifies an existing property on an object, and returns the object.
Read more >
Object.defineProperty() - JavaScript
When the property already exists, Object.defineProperty() attempts to modify the property according to the values in the descriptor and the object's current ...
Read more >
687 - Object.defineProperty problems with redefining accessor ...
In case 3, no redefining is in fact assumed, instead setting "x" property of l2 object. But instead, the inherited setter is called....
Read more >
"DefineProperty" | Can I use... Support tables for ... - CanIUse
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Read more >
Strange things happen when using Object.defineProperty with ...
the property is put onto the window with writable: true . So if you use Object.defineProperty first, and then in another script tag...
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