[njs] Improved JSON.stringify() for external values.

Dmitry Volyntsev xeioex at nginx.com
Tue Jul 31 12:59:31 UTC 2018


details:   http://hg.nginx.org/njs/rev/9d9dfeb98aff
branches:  
changeset: 578:9d9dfeb98aff
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Jul 31 15:30:01 2018 +0300
description:
Improved JSON.stringify() for external values.

diffstat:

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

diffs (30 lines):

diff -r d36e4cf4f9dc -r 9d9dfeb98aff njs/njs_json.c
--- a/njs/njs_json.c	Tue Jul 31 14:45:16 2018 +0300
+++ b/njs/njs_json.c	Tue Jul 31 15:30:01 2018 +0300
@@ -1723,11 +1723,8 @@ njs_json_append_value(njs_json_stringify
     case NJS_NULL:
     case NJS_INVALID:
     case NJS_FUNCTION:
+    default:
         return njs_json_buf_append(stringify, "null", 4);
-
-    default:
-        njs_type_error(stringify->vm, "Non-serializable object");
-        return NXT_DECLINED;
     }
 }
 
diff -r d36e4cf4f9dc -r 9d9dfeb98aff njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Jul 31 14:45:16 2018 +0300
+++ b/njs/test/njs_unit_test.c	Tue Jul 31 15:30:01 2018 +0300
@@ -9035,8 +9035,8 @@ 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") },
+    { nxt_string("JSON.stringify([$r])"),
+      nxt_string("[null]") },
 
     /* Ignoring named properties of an array. */
 


More information about the nginx-devel mailing list