-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
domain: runtime deprecate MakeCallback #17417
domain: runtime deprecate MakeCallback #17417
Conversation
doc/api/deprecations.md
Outdated
|
||
Users of MakeCallback that adds the domain property to carry context, | ||
should start using the async_context variant of MakeCallback or the | ||
AsyncResource class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Back-ticks around MakeCallback()
and AsyncResource
?
src/env.cc
Outdated
@@ -262,6 +262,12 @@ bool Environment::EmitNapiWarning() { | |||
return current_value; | |||
} | |||
|
|||
bool Environment::EmitDomainWarning() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a great name. The imperative suggests it performs an action but it's really a getter, although one with side effects (which itself is somewhat objectionable.)
At the very least call it something like ShouldEmitDomainWarning()
, and look into separating the check and the update. Since you're only using it in one place, I'd split it in a getter and setter and call the setter explicitly after emitting the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe. Basically just copied EmitNapiWarning
:D
src/node.cc
Outdated
"Using a domain property in MakeCallback is deprecated. Use the " | ||
"async_context variant of MakeCallback or the AsyncResource class " | ||
"instead.", | ||
"DEPXXXX"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 space indent for line continuations and env
should arguably go on a line of its own.
doc/api/deprecations.md
Outdated
<a id="DEPXXXX"></a> | ||
### MakeCallback with domain property | ||
|
||
Users of MakeCallback that adds the domain property to carry context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that adds -> that add
doc/api/deprecations.md
Outdated
<a id="DEPXXXX"></a> | ||
### MakeCallback with domain property | ||
|
||
Users of MakeCallback that adds the domain property to carry context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MakeCallback, domain, etc. should be in backticks I think.
Thanks. Please check again. |
src/node.cc
Outdated
"Using a domain property in MakeCallback is deprecated. Use the " | ||
"async_context variant of MakeCallback or the AsyncResource class " | ||
"instead.", | ||
"DEPXXXX"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you indent everything by 4 spaces?
doc/api/deprecations.md
Outdated
|
||
Users of `MakeCallback` that add the `domain` property to carry context, | ||
should start using the `async_context` variant of `MakeCallback` or the | ||
`AsyncResource` class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… or CallbackScope
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit, DEP00XX
in order for the tooling to catch these on release builds (there's a script that looks for the DEP00XX
pattern specifically)
src/node.cc
Outdated
|
||
Local<Object> process = env->process_object(); | ||
MaybeLocal<Value> emit_warning = process->Get(env->context(), | ||
FIXED_ONE_BYTE_STRING(env->isolate(), "emitWarning")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably move the FIXED_ONE_BYTE_STRING
s here into the list in env.h
?
src/node.cc
Outdated
Local<Value> args[3]; | ||
args[0] = node::OneByteString(env->isolate(), warning); | ||
args[1] = FIXED_ONE_BYTE_STRING(env->isolate(), "DeprecationWarning"); | ||
args[2] = node::OneByteString(env->isolate(), deprecation_code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deprecation_code
might make more sense as an internalized string (i.e. using String::NewFromOneByte
with v8::NewStringType::kInternalized
directly)?
src/node.cc
Outdated
|
||
// MakeCallback() unneeded, because emitWarning is internal code, it calls | ||
// process.emit('warning', ..), but does so on the nextTick. | ||
f.As<v8::Function>()->Call(process, arraysize(args), args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the overload of Call()
that takes a context
argument?
src/node.cc
Outdated
|
||
Local<Value> f; | ||
|
||
if (!emit_warning.ToLocal(&f)) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If emit_warning
is empty, we should probably return immediately after that. Creating handles to strings in between the failure and returning is probably no big deal, but at some point somebody might think it’s okay to slip in code that potentially calls back into JS instead?
Either way, one issue here is that ProcessEmitDeprecationWarning
has no way of signaling its caller whether it leaves an exception pending or not (i.e. if emit_warning
is empty or the ->Call()
below returned an empty result).
I think the options for that are:
- Return
Maybe<bool>
, like the V8 API does, which isJust(true)
on success andNothing<bool>()
on failure, and leave it for the caller to handle the issue. - Use
.ToLocalChecked()
on everything. The big downside is that emitting deprecation warnings with--throw-deprecation
on the command line does throw an error as part of regular operations.
src/node.cc
Outdated
FIXED_ONE_BYTE_STRING(env->isolate(), "emitWarning")); | ||
|
||
Local<Value> args[3]; | ||
args[0] = node::OneByteString(env->isolate(), warning); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UTF-8, to be a bit more future-proof? :)
@addaleax I basically just modified the code from |
@AndreasMadsen I see … 😄 The comments related to string creation are certainly optional and you can ignore them to keep parity (and/or leave a But |
@addaleax That's fair. Let's fix |
@AndreasMadsen Just so we’re on the same page, what’s the next step? One of us opens a separate PR with those changes? Do you do that or want me to do that? |
@addaleax Yes. Go ahead and make it. I might have a few questions just to learn :) |
IIRC, policy is that runtime deprecations are always treated as breaking changes so I've labeled this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if a test is added
- Handle exceptions when getting `process.emitWarning` or when calling it properly - Add `Maybe<bool>` to the return type, like the V8 API uses it to indicate failure conditions - Update call sites to account for that and clean up/return to JS when encountering an error - Add an internal `ProcessEmitDeprecationWarning()` sibling for use in #17417, with common code extracted to a helper function - Allow the warning to contain non-Latin-1 characters. Since the message will usually be a template string containing data passed from the user, this is the right thing to do. - Add tests for the failure modes (except string creation failures) and UTF-8 warning messages. PR-URL: #17420 Refs: #17417 Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
ping @AndreasMadsen ... can you add a test? |
Ping @AndreasMadsen this needs a rebase, thanks |
@joyeecheung Will you review it if I rebase it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM, by the way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a rebase and my comment should be looked at.
|
||
// Warning is emitted when domain property is used and domain is enabled | ||
makeCallback({ domain: d }, common.mustCall(function() { | ||
assert.strictEqual(latestWarning, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not certain when exactly the warning should be emitted but from the comment itself it seems to me that latestWarning
should not be null
. If it should be, it would be good to add a test that actually tests for notStrictEqual
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this is odd
Ping @AndreasMadsen |
Yeah, I was waiting for #18291 to land |
Ping @AndreasMadsen again. It landed 8 days ago ;-) |
Users of MakeCallback that adds the domain property to carry context, should start using the async_context variant of MakeCallback or the AsyncResource class.
@BridgeAR Complete rewrote the implementation, please check. |
fixed lint issues :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Landed in 14bc3e2 |
Users of MakeCallback that adds the domain property to carry context, should start using the async_context variant of MakeCallback or the AsyncResource class. PR-URL: nodejs#17417 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Users of MakeCallback that adds the domain property to carry context,
should start using the async_context variant of MakeCallback or the
AsyncResource class.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
domain