fix: Executing polyfills code multiple times throws illegal invocation error #92
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 throughObject.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