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

zlib: use new.target to check for instantiation #54694

Closed
wants to merge 1 commit into from

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Sep 1, 2024

Referring to @nicolo-ribaudo's comment: #54676 (comment)

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib subsystem. labels Sep 1, 2024
@anonrig anonrig requested a review from jasnell September 1, 2024 16:55
lib/zlib.js Outdated Show resolved Hide resolved
@anonrig anonrig added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Sep 1, 2024
@anonrig anonrig requested a review from aduh95 September 1, 2024 18:05
Copy link

codecov bot commented Sep 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.60%. Comparing base (4c844a2) to head (e74e917).
Report is 151 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #54694      +/-   ##
==========================================
+ Coverage   87.33%   87.60%   +0.27%     
==========================================
  Files         650      650              
  Lines      182832   182843      +11     
  Branches    35067    35384     +317     
==========================================
+ Hits       159670   160180     +510     
+ Misses      16421    15929     -492     
+ Partials     6741     6734       -7     
Files with missing lines Coverage Δ
lib/zlib.js 98.21% <100.00%> (+0.97%) ⬆️

... and 59 files with indirect coverage changes

@anonrig anonrig added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 1, 2024
@anonrig
Copy link
Member Author

anonrig commented Sep 1, 2024

@nodejs/tsc this is a semver-major because the removed test is broken.

@@ -706,57 +706,64 @@ Zlib.prototype.params = function params(level, strategy, callback) {
// generic zlib
// minimal 2-byte header
function Deflate(opts) {
if (!(this instanceof Deflate))
if (!new.target) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!new.target) {
if (new.target !== Deflate) {

if you also want to normalize subclasses

@mcollina
Copy link
Member

mcollina commented Sep 2, 2024

Is this more performant? Would it work with subclasses?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like something we would want to support, at least using ES6 class syntax

Copy link
Contributor

@nicolo-ribaudo nicolo-ribaudo Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the ES6 syntax this test would still pass (except if doing #54694 (comment)).

I guess this change only makes sense if done together with #54676, since this is about detecting when new is used or not.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm -1, we should keep supporting the removed test

@anonrig anonrig closed this Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version. zlib Issues and PRs related to the zlib subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants