[njs] Fixed exception type for unsupported types in JSON.stringify().

Dmitry Volyntsev xeioex at nginx.com
Fri Apr 20 13:42:37 UTC 2018


details:   http://hg.nginx.org/njs/rev/28d75187de15
branches:  
changeset: 500:28d75187de15
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Apr 20 16:42:10 2018 +0300
description:
Fixed exception type for unsupported types in JSON.stringify().

diffstat:

 njs/njs_json.c           |  4 ++++
 njs/test/njs_unit_test.c |  3 +++
 2 files changed, 7 insertions(+), 0 deletions(-)

diffs (27 lines):

diff -r cb7115e9fa1e -r 28d75187de15 njs/njs_json.c
--- a/njs/njs_json.c	Fri Apr 20 16:42:08 2018 +0300
+++ b/njs/njs_json.c	Fri Apr 20 16:42:10 2018 +0300
@@ -1184,6 +1184,10 @@ njs_json_parse_exception(njs_json_parse_
     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 -r cb7115e9fa1e -r 28d75187de15 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Fri Apr 20 16:42:08 2018 +0300
+++ b/njs/test/njs_unit_test.c	Fri Apr 20 16:42:10 2018 +0300
@@ -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;"


More information about the nginx-devel mailing list