details: https://hg.nginx.org/njs/rev/e9c41ee90ac2 branches: changeset: 2160:e9c41ee90ac2 user: Dmitry Volyntsev <xei...@nginx.com> date: Wed Jun 21 16:29:51 2023 -0700 description: QueryString: added back custom exception types using new public API.
In fd956d2a25a3, when rewriting querystring module using public API all the exceptions types were squashed into a single Error type. This patch reintroduces the standard exception types back using new API. diffstat: external/njs_query_string_module.c | 12 +++++++----- src/test/njs_unit_test.c | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diffs (83 lines): diff -r 11fc41439e9f -r e9c41ee90ac2 external/njs_query_string_module.c --- a/external/njs_query_string_module.c Wed Jun 21 16:29:48 2023 -0700 +++ b/external/njs_query_string_module.c Wed Jun 21 16:29:51 2023 -0700 @@ -422,7 +422,7 @@ njs_query_string_parse(njs_vm_t *vm, njs if (val != NULL) { if (!njs_value_is_valid_number(val)) { - njs_vm_error(vm, "is not a number"); + njs_vm_type_error(vm, "is not a number"); return NJS_ERROR; } @@ -437,7 +437,8 @@ njs_query_string_parse(njs_vm_t *vm, njs if (val != NULL) { if (njs_slow_path(!njs_value_is_function(val))) { - njs_vm_error(vm, "option decodeURIComponent is not a function"); + njs_vm_type_error(vm, "option decodeURIComponent is not " + "a function"); return NJS_ERROR; } @@ -449,7 +450,7 @@ njs_query_string_parse(njs_vm_t *vm, njs val = njs_vm_object_prop(vm, this, &njs_unescape_str, &value); if (val == NULL || !njs_value_is_function(val)) { - njs_vm_error(vm, "QueryString.unescape is not a function"); + njs_vm_type_error(vm, "QueryString.unescape is not a function"); return NJS_ERROR; } @@ -728,7 +729,8 @@ njs_query_string_stringify(njs_vm_t *vm, if (val != NULL) { if (njs_slow_path(!njs_value_is_function(val))) { - njs_vm_error(vm, "option encodeURIComponent is not a function"); + njs_vm_type_error(vm, "option encodeURIComponent is not " + "a function"); return NJS_ERROR; } @@ -740,7 +742,7 @@ njs_query_string_stringify(njs_vm_t *vm, val = njs_vm_object_prop(vm, this, &njs_escape_str, &value); if (val == NULL || !njs_value_is_function(val)) { - njs_vm_error(vm, "QueryString.escape is not a function"); + njs_vm_type_error(vm, "QueryString.escape is not a function"); return NJS_ERROR; } diff -r 11fc41439e9f -r e9c41ee90ac2 src/test/njs_unit_test.c --- a/src/test/njs_unit_test.c Wed Jun 21 16:29:48 2023 -0700 +++ b/src/test/njs_unit_test.c Wed Jun 21 16:29:51 2023 -0700 @@ -20723,12 +20723,12 @@ static njs_unit_test_t njs_querystring_ { njs_str("var qs = require('querystring');" "qs.parse('baz=fuz&muz=tax', null, null, {decodeURIComponent: 123});"), - njs_str("Error: option decodeURIComponent is not a function") }, + njs_str("TypeError: option decodeURIComponent is not a function") }, { njs_str("var qs = require('querystring');" "qs.unescape = 123;" "qs.parse('baz=fuz&muz=tax');"), - njs_str("Error: QueryString.unescape is not a function") }, + njs_str("TypeError: QueryString.unescape is not a function") }, { njs_str("var qs = require('querystring'); var out = [];" "qs.unescape = (key) => {out.push(key)};" @@ -20841,12 +20841,12 @@ static njs_unit_test_t njs_querystring_ { njs_str("var qs = require('querystring');" "qs.stringify({'baz': 'fuz', 'muz': 'tax'}, null, null, {encodeURIComponent: 123});" "out.join('; ')"), - njs_str("Error: option encodeURIComponent is not a function") }, + njs_str("TypeError: option encodeURIComponent is not a function") }, { njs_str("var qs = require('querystring');" "qs.escape = 123;" "qs.stringify({'baz': 'fuz', 'muz': 'tax'})"), - njs_str("Error: QueryString.escape is not a function") }, + njs_str("TypeError: QueryString.escape is not a function") }, { njs_str("var qs = require('querystring'); var out = [];" "qs.escape = (key) => {out.push(key)};" _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel