]> git.kaiwu.me - njs.git/commitdiff
Fixed exception type for unsupported types in JSON.stringify().
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 20 Apr 2018 13:42:10 +0000 (16:42 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Fri, 20 Apr 2018 13:42:10 +0000 (16:42 +0300)
njs/njs_json.c
njs/test/njs_unit_test.c

index c7b952f910bcd33040135300a5c7cc8c4f82f25c..1f7041552c72be005d20511f39f569a59b21406e 100644 (file)
@@ -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;                                                    \
     }
 
index 7fbee6a0edb69f9f5d929fe41c87138328d946ab..6478ea2ec03719b228d2ea5bdf020128f675a116 100644 (file)
@@ -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;"