Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Executing polyfills code multiple times throws illegal invocation error #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lililili9761
Copy link

@lililili9761 lililili9761 commented Jan 19, 2023

I found out that executing polyfill code multiple times will throw "illegal invocation" error. For the first time runnint the code Z.prototype.firstElementChild == null, we set a getter for Z.prototype.FirstElementChild through Object.defineProperty, which is expected. However, if this polyfill runs again by accident (or just access Z.prototype.firstElementChild), we will get an error. Because inside the Z.prototype.firstElementChild, there is a this.childNodes in getter, which will be intercepted by the browser (I don't know why, I guess Chrome has such a restriction in case we access Node.prototype.childNodes directly), then Uncaught TypeError: Illegal invocation happened. Here's my reproduce url https://jsbin.com/sirihugoya/edit?html,console,output, you can have a check, and you can find an error in devtool console after clicking the "test" button multiple times. @kutlugsahin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant