-
-
Notifications
You must be signed in to change notification settings - Fork 110
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 exception on older browsers #246
Conversation
Can you add a test? |
Sure thing -- I've added tests specifically for CallableInstance that should cover this. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #246 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 1364 1372 +8
=========================================
+ Hits 1364 1372 +8 ☔ View full report in Codecov by Sentry. |
@wooorm I added some tests, please let me know if this looks good to you |
Hi again, thanks for your patience! As mentioned, we don’t support ES5, so it feels weird to include a test for ES5 support. You said that this problem also occurs more broadly. I wonder if that is the case. Can you come up with a test that shows that to be the case? In
Perhaps still your change would make sense to Or if that isn’t the case, perhaps that we don’t need this descriptor patching loop here at all? Finally: adding your tests but not including your patch to lib, the tests still run for me? |
I added the tests per your request -- are you saying you want me to remove the tests now?
Apologies, but I don't recall saying this. The problem only occurs when
Yes, but the bug is specific to CallableInstance. The Processor class just happens to be the only class inheriting from it.
I will make a change so we are instead checking the target object for an existing non-configurable property. This will ensure we're only skipping fields that are already defined and are non-configurable. This should ensure we're only skipping non-configurable properties that were defined on a brand new Function. It won't skip any non-configurable fields from the child class, so we won't be omitting anything from the class itself if they happen to define a non-configurable field.
That is because the tests run in Node, and Node does not define Functions with non-configurable properties like browsers do. I've only encountered this issue in a browser environment (Chrome). This sandbox illustrates the issue: https://playcode.io/1896334 |
No, I appreciate a test. But I was wondering if there could be a different test.
See #245 (comment)
Right, and this makes me wary: how can we be sure it’s fixed? That this fix does not introduce different problems?
You can still define non-configurable properties in the tests though?
What is the illustration? What behavior do you expect, what not, what is actual? I don’t get errors in Chrome or Safari with that sandbox.
I worry about this approach: this approach attempts to patch I can think of two alternative solutions. a) Ignore this dead/unneeded code. All the tests should still run, so it’s verified. - const names = Object.getOwnPropertyNames(value)
-
- for (const p of names) {
- const descriptor = Object.getOwnPropertyDescriptor(value, p)
- if (descriptor) Object.defineProperty(apply, p, descriptor)
- }
+ // Not needed for us in `unified`: we only call this on the `copy`
+ // function,
+ // and we don’t need to add its fields (`length`, `name`)
+ // over.
+ // See also: GH-246.
+ // const names = Object.getOwnPropertyNames(value)
+ //
+ // for (const p of names) {
+ // const descriptor = Object.getOwnPropertyDescriptor(value, p)
+ // if (descriptor) Object.defineProperty(apply, p, descriptor)
+ // } b) Create an exception for these legacy and unneeded fields: for (const p of names) {
+ // Special non-configurable legacy function fields (see: GH-246).
+ if (p === 'arguments' || p === 'caller') continue;
+
const descriptor = Object.getOwnPropertyDescriptor(value, p) (we could also probably add |
Thanks so much for thinking with me on this!
Yes please! I prefer approach A as well. |
@wooorm My pleasure! I've removed the tests and taken your suggested approach. |
This comment has been minimized.
This comment has been minimized.
released, thanks! |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [unified](https://unifiedjs.com) ([source](https://togithub.com/unifiedjs/unified)) | [`11.0.4` -> `11.0.5`](https://renovatebot.com/diffs/npm/unified/11.0.4/11.0.5) | [![age](https://developer.mend.io/api/mc/badges/age/npm/unified/11.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/unified/11.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/unified/11.0.4/11.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/unified/11.0.4/11.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>unifiedjs/unified (unified)</summary> ### [`v11.0.5`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.5) [Compare Source](https://togithub.com/unifiedjs/unified/compare/11.0.4...11.0.5) ##### Fix - [`1e0863a`](https://togithub.com/unifiedjs/unified/commit/1e0863a) Fix exception on older browsers by [@​justinbhopper](https://togithub.com/justinbhopper) in [https://github.com/unifiedjs/unified/pull/246](https://togithub.com/unifiedjs/unified/pull/246) **Full Changelog**: unifiedjs/unified@11.0.4...11.0.5 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/r4ai/r4ai.dev). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MTAuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQxMC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [unified](https://unifiedjs.com) ([source](https://togithub.com/unifiedjs/unified)) | [`11.0.4` -> `11.0.5`](https://renovatebot.com/diffs/npm/unified/11.0.4/11.0.5) | [![age](https://developer.mend.io/api/mc/badges/age/npm/unified/11.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/unified/11.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/unified/11.0.4/11.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/unified/11.0.4/11.0.5?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>unifiedjs/unified (unified)</summary> ### [`v11.0.5`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.5) [Compare Source](https://togithub.com/unifiedjs/unified/compare/11.0.4...11.0.5) ##### Fix - [`1e0863a`](https://togithub.com/unifiedjs/unified/commit/1e0863a) Fix exception on older browsers by [@​justinbhopper](https://togithub.com/justinbhopper) in [https://github.com/unifiedjs/unified/pull/246](https://togithub.com/unifiedjs/unified/pull/246) **Full Changelog**: unifiedjs/unified@11.0.4...11.0.5 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/X-oss-byte/Nextjs).
Initial checklist
Description of changes
This addresses errors caused by the unified constructor in ES5 and fixes #245.