From 3238e85abee52568811fb8373a4e9fe90cb823cc Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Wed, 21 Jun 2023 16:29:51 -0700 Subject: [PATCH] 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. --- external/njs_query_string_module.c | 12 +++++++----- src/test/njs_unit_test.c | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/external/njs_query_string_module.c b/external/njs_query_string_module.c index a7602289..7eb066d1 100644 --- a/external/njs_query_string_module.c +++ b/external/njs_query_string_module.c @@ -422,7 +422,7 @@ njs_query_string_parse(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, 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_value_t *args, njs_uint_t nargs, 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_value_t *args, njs_uint_t nargs, 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, njs_value_t *args, njs_uint_t nargs, 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, njs_value_t *args, njs_uint_t nargs, 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 --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 541c9068..c6308f8e 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -20723,12 +20723,12 @@ static njs_unit_test_t njs_querystring_module_test[] = { 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_module_test[] = { 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)};" -- 2.47.3