diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index ca23a4fa322f94..47f716d08c1cfa 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2230,6 +2230,13 @@ like `dns.lookup(false)` due to backward compatibility. This behavior is undocumented and is thought to be unused in real world apps. It will become an error in future versions of Node.js. + +### DEP0XXX: process.binding('uv').errname() private API + +Type: Documentation-only (supports [`--pending-deprecation`][]) + + + [`--pending-deprecation`]: cli.html#cli_pending_deprecation [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size [`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array diff --git a/src/env.cc b/src/env.cc index 14a8b23a8441e9..4f98b5590cf941 100644 --- a/src/env.cc +++ b/src/env.cc @@ -134,6 +134,7 @@ Environment::Environment(IsolateData* isolate_data, printed_error_(false), abort_on_uncaught_exception_(false), emit_env_nonstring_warning_(true), + emit_err_name_warning_(true), makecallback_cntr_(0), should_abort_on_uncaught_toggle_(isolate_, 1), trace_category_state_(isolate_, kTraceCategoryCount), diff --git a/src/env.h b/src/env.h index 1eb333b0ef31d9..2958b6b5ac4ea9 100644 --- a/src/env.h +++ b/src/env.h @@ -842,6 +842,11 @@ class Environment { emit_env_nonstring_warning_ = false; return current_value; } + inline bool EmitErrNameWarning() { + bool current_value = emit_err_name_warning_; + emit_err_name_warning_ = false; + return current_value; + } typedef void (*native_immediate_callback)(Environment* env, void* data); // cb will be called as cb(env, data) on the next event loop iteration. @@ -929,6 +934,7 @@ class Environment { bool printed_error_; bool abort_on_uncaught_exception_; bool emit_env_nonstring_warning_; + bool emit_err_name_warning_; size_t makecallback_cntr_; std::vector destroy_async_id_list_; diff --git a/src/uv.cc b/src/uv.cc index 3d070a32bdb3b4..95777c1caa4d20 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -39,10 +39,17 @@ using v8::String; using v8::Value; -// TODO(joyeecheung): deprecate this function in favor of -// lib/util.getSystemErrorName() void ErrName(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); + if (env->options()->pending_deprecation && env->EmitErrNameWarning()) { + if (ProcessEmitDeprecationWarning( + env, + "Directly calling process.binding('uv').errname() is being" + " deprecated. " + "Please make sure to use util.getSystemErrorName() instead.", + "DEP0XXX").IsNothing()) + return; + } int err; if (!args[0]->Int32Value(env->context()).To(&err)) return; CHECK_LT(err, 0); diff --git a/test/parallel/test-err-name-deprecation.js b/test/parallel/test-err-name-deprecation.js new file mode 100644 index 00000000000000..3cf750d139c27c --- /dev/null +++ b/test/parallel/test-err-name-deprecation.js @@ -0,0 +1,13 @@ +'use strict'; +const common = require('../common'); + +// Flags: --pending-deprecation + +common.expectWarning( + 'DeprecationWarning', + 'Directly calling process.binding(\'uv\').errname() is being ' + + 'deprecated. Please make sure to use util.getSystemErrorName() instead.', + 'DEP0XXX' +); + +process.binding('uv').errname(-1);