From 4165c3d0d8282e23103c815298efe529a5f52a4e Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 31 Jul 2018 15:30:01 +0300 Subject: [PATCH] Improved JSON.stringify() for external values. --- njs/njs_json.c | 5 +---- njs/test/njs_unit_test.c | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/njs/njs_json.c b/njs/njs_json.c index 616a4e59..9e2a571b 100644 --- a/njs/njs_json.c +++ b/njs/njs_json.c @@ -1723,11 +1723,8 @@ njs_json_append_value(njs_json_stringify_t *stringify, const njs_value_t *value) case NJS_NULL: case NJS_INVALID: case NJS_FUNCTION: - return njs_json_buf_append(stringify, "null", 4); - default: - njs_type_error(stringify->vm, "Non-serializable object"); - return NXT_DECLINED; + return njs_json_buf_append(stringify, "null", 4); } } diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index f437c2e4..2e5ebe66 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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. */ -- 2.47.3