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

util: move flagged deprecation to internal/util #18450

Closed
wants to merge 1 commit into from

Conversation

ChALkeR
Copy link
Member

@ChALkeR ChALkeR commented Jan 30, 2018

Two changes in this commit:

  1. Deprecation-related logic is moved from buffer.js to internal/util.js
    That is the new deprecator() method that generates either a
    deprecation function or a noop, depending on the deprecation type and
    runtime flags.

  2. Buffer pending deprecation stack trace is fixed, so that internal
    logic does not appear in there, and the first line of the stack
    should now point at userland code where the deprecated method was
    called.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

buffer, util


Perhaps I should benchmark this change, I am not exaclty sure if passing Buffer as an argument in that place is a great idea. This way it's more flexible, but making it an argument of deprecator could be faster (or not) — I probably need to check that.

Two changes in this commit:

1. Deprecation-related logic is moved from buffer.js to internal/util.js
   That is the new deprecator() method that generates either a
   deprecation function or a noop, depending on the deprecation type and
   runtime flags.

2. Buffer pending deprecation stack trace is fixed, so that internal
   logic does not appear in there, and the first line of the stack
   should now point at userland code where the deprecated method was
   called.
@ChALkeR ChALkeR added buffer Issues and PRs related to the buffer subsystem. util Issues and PRs related to the built-in util module. labels Jan 30, 2018
@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. util Issues and PRs related to the built-in util module. labels Jan 30, 2018
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

Overall LGTM, just some nits.

if (process.noDeprecation === true) {
return () => {};
}
if (options.pending && !pendingDeprecation) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: as this if statement does the same as the one above I would just combine these two.

}

// code should be set
if (typeof code !== 'string' || code === '')
Copy link
Member

Choose a reason for hiding this comment

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

I personally do not feel that the code === '' check is really necessary but it would actually be nice to check for the right pattern as in: !/^DEP(\d\d\d\d|00XX|0XXX|XXXX)$/.test(code).

That aside: it is in both cases not a ERR_INVALID_ARG_TYPE. It could be a ERR_INVALID_ARG_VALUE.

Copy link
Member

Choose a reason for hiding this comment

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

I don’ think it’s needed to validate the pattern.

+1 on ERR_INVALID_ARG_VALUE

if (warned) return;
warned = true;
if (codesWarned[code]) return;
codesWarned[code] = true;
Copy link
Member

Choose a reason for hiding this comment

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

As question: is warned here to prevent a lookup in the default case?

Copy link
Member Author

@ChALkeR ChALkeR Jan 31, 2018

Choose a reason for hiding this comment

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

Yes.

  1. If this specific function has already been called (which it would be in most cases) — warned will be true, and this will return asap.
  2. The second check (codesWarned[code]) is needed to catch the situation where e.g. another function has been created using the same deprecation code (or the warning was emitted through deprecate below) — we still don't want to display the warning second time in that case.

@ChALkeR
Copy link
Member Author

ChALkeR commented Jan 31, 2018

The next step will be to pending-deprecate SlowBuffer, btw, as in f12cdb5.

Btw — @nodejs/tsc — we can pending-deprecate SlowBuffer in a semver-minor 9.x release, can't we?
Buffer() is already pending-deprecated, and SlowBuffer was just overlooked probably. It's doc-deprecated (DEP0030) since 3fe204c (v7.0.0).

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.

LGTM with nits

}

// code should be set
if (typeof code !== 'string' || code === '')
Copy link
Member

Choose a reason for hiding this comment

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

I don’ think it’s needed to validate the pattern.

+1 on ERR_INVALID_ARG_VALUE

@ChALkeR ChALkeR added the wip Issues and PRs that are still a work in progress. label Feb 2, 2018
@ChALkeR
Copy link
Member Author

ChALkeR commented Feb 2, 2018

Labeling as in progress as I still have to test the performance impact.

@BridgeAR
Copy link
Member

Ping @ChALkeR

@BridgeAR
Copy link
Member

BridgeAR commented Mar 2, 2018

Ping @ChALkeR again

@BridgeAR
Copy link
Member

@ChALkeR are you still working on this?

@BridgeAR BridgeAR added the stalled Issues and PRs that are stalled. label Apr 10, 2018
@ChALkeR
Copy link
Member Author

ChALkeR commented Apr 10, 2018

@BridgeAR Yes, I am planning to fix this a bit later. It might have conflicts with other more important PRs, so let's land those first. I will take a look in a day or two.

@BridgeAR
Copy link
Member

The deprecation PR landed, so this should be good to rebase.

// For internal use only. `code` is a required argument.
// If --no-deprecation is set, then it is a no-op.
// { pending: true } are visible only when pendingDeprecation is on
function deprecator(msg, code, options = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we call this deprecate instead of deprecator

@BridgeAR
Copy link
Member

Ping @ChALkeR

@ChALkeR
Copy link
Member Author

ChALkeR commented Apr 28, 2018

@BridgeAR Yes, thanks. This is still on my radar, among with several other things…

@ChALkeR ChALkeR self-assigned this Apr 28, 2018
@ChALkeR
Copy link
Member Author

ChALkeR commented May 6, 2018

I checked this again — not usable for the two places where pendingDeprecation is currrently used, so I'm going to just close. Might reopen later if/once we add more pending deprecations, and if it would be possible to reuse code there in such a way.

@ChALkeR ChALkeR closed this May 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. stalled Issues and PRs that are stalled. util Issues and PRs related to the built-in util module. wip Issues and PRs that are still a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants