[njs] Added soft deprecation warning for deprecated methods and properties.
Dmitry Volyntsev
xeioex at nginx.com
Tue Jul 26 01:41:28 UTC 2022
details: https://hg.nginx.org/njs/rev/beaff2c39864
branches:
changeset: 1918:beaff2c39864
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Mon Jul 25 18:40:24 2022 -0700
description:
Added soft deprecation warning for deprecated methods and properties.
diffstat:
nginx/ngx_http_js_module.c | 4 ++++
src/njs.h | 11 +++++++++++
src/njs_string.c | 10 ++++++++++
3 files changed, 25 insertions(+), 0 deletions(-)
diffs (90 lines):
diff -r 14426cb84197 -r beaff2c39864 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Mon Jul 25 18:40:24 2022 -0700
+++ b/nginx/ngx_http_js_module.c Mon Jul 25 18:40:24 2022 -0700
@@ -2572,6 +2572,8 @@ ngx_http_js_ext_get_request_body(njs_vm_
ngx_http_js_ctx_t *ctx;
ngx_http_request_t *r;
+ njs_deprecated(vm, "r.requestBody");
+
r = njs_vm_external(vm, ngx_http_js_request_proto_id, value);
if (r == NULL) {
njs_value_undefined_set(retval);
@@ -3416,6 +3418,8 @@ ngx_http_js_ext_get_response_body(njs_vm
ngx_http_js_ctx_t *ctx;
ngx_http_request_t *r;
+ njs_deprecated(vm, "r.responseBody");
+
r = njs_vm_external(vm, ngx_http_js_request_proto_id, value);
if (r == NULL) {
njs_value_undefined_set(retval);
diff -r 14426cb84197 -r beaff2c39864 src/njs.h
--- a/src/njs.h Mon Jul 25 18:40:24 2022 -0700
+++ b/src/njs.h Mon Jul 25 18:40:24 2022 -0700
@@ -81,6 +81,17 @@ extern const njs_value_t njs_
#define njs_vm_err(vm, fmt, ...) njs_vm_logger(vm, NJS_LOG_LEVEL_ERROR, fmt, \
##__VA_ARGS__)
+#define njs_deprecated(vm, text) \
+ do { \
+ static njs_bool_t reported; \
+ \
+ if (!reported) { \
+ njs_vm_warn(vm, text " is deprecated " \
+ "and will be removed in the future"); \
+ reported = 1; \
+ } \
+ } while(0)
+
/*
* njs_prop_handler_t operates as a property getter/setter or delete handler.
* - retval != NULL && setval == NULL - GET context.
diff -r 14426cb84197 -r beaff2c39864 src/njs_string.c
--- a/src/njs_string.c Mon Jul 25 18:40:24 2022 -0700
+++ b/src/njs_string.c Mon Jul 25 18:40:24 2022 -0700
@@ -982,6 +982,8 @@ njs_string_prototype_from_utf8(njs_vm_t
njs_slice_prop_t slice;
njs_string_prop_t string;
+ njs_deprecated(vm, "String.prototype.fromUTF8()");
+
ret = njs_string_object_validate(vm, njs_argument(args, 0));
if (njs_slow_path(ret != NJS_OK)) {
return ret;
@@ -1025,6 +1027,8 @@ njs_string_prototype_to_utf8(njs_vm_t *v
njs_slice_prop_t slice;
njs_string_prop_t string;
+ njs_deprecated(vm, "String.prototype.toUTF8()");
+
ret = njs_string_object_validate(vm, njs_argument(args, 0));
if (njs_slow_path(ret != NJS_OK)) {
return ret;
@@ -1059,6 +1063,8 @@ njs_string_prototype_from_bytes(njs_vm_t
njs_slice_prop_t slice;
njs_string_prop_t string;
+ njs_deprecated(vm, "String.prototype.fromBytes()");
+
ret = njs_string_object_validate(vm, njs_argument(args, 0));
if (njs_slow_path(ret != NJS_OK)) {
return ret;
@@ -1125,6 +1131,8 @@ njs_string_prototype_to_bytes(njs_vm_t *
njs_string_prop_t string;
njs_unicode_decode_t ctx;
+ njs_deprecated(vm, "String.prototype.toBytes()");
+
ret = njs_string_object_validate(vm, njs_argument(args, 0));
if (njs_slow_path(ret != NJS_OK)) {
return ret;
@@ -1617,6 +1625,8 @@ njs_string_bytes_from(njs_vm_t *vm, njs_
{
njs_value_t *value;
+ njs_deprecated(vm, "String.bytesFrom()");
+
value = njs_arg(args, nargs, 1);
if (njs_is_string(value)) {
More information about the nginx-devel
mailing list