From 724ae376660030e8f1c09e8d04ef9e9f86991a15 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Fri, 20 Apr 2018 16:42:10 +0300 Subject: [PATCH] Fixed exception type for unsupported types in JSON.stringify(). --- njs/njs_json.c | 4 ++++ njs/test/njs_unit_test.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/njs/njs_json.c b/njs/njs_json.c index c7b952f9..1f704155 100644 --- a/njs/njs_json.c +++ b/njs/njs_json.c @@ -1184,6 +1184,10 @@ njs_json_parse_exception(njs_json_parse_ctx_t *ctx, const char* msg, state->written = 1; \ ret = njs_json_append_value(stringify, value); \ if (nxt_slow_path(ret != NXT_OK)) { \ + if (ret == NXT_DECLINED) { \ + return NXT_ERROR; \ + } \ + \ goto memory_error; \ } diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 7fbee6a0..6478ea2e 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -8708,6 +8708,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("var e = URIError('e'); e.foo = 'E'; JSON.stringify(e)"), nxt_string("{\"foo\":\"E\"}") }, + { nxt_string("JSON.stringify($r)"), + nxt_string("TypeError: Non-serializable object") }, + /* Ignoring named properties of an array. */ { nxt_string("var a = [1,2]; a.a = 1;" -- 2.47.3