From bc60f9a2bc956d4c96a36092594778b110ff92d4 Mon Sep 17 00:00:00 2001 From: "Artem S. Povalyukhin" Date: Sat, 25 Dec 2021 22:45:30 +0300 Subject: [PATCH] Improved Buffer.from() with Buffer-like objects. --- src/njs_buffer.c | 6 +++--- src/test/njs_unit_test.c | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/njs_buffer.c b/src/njs_buffer.c index 778babdc..13182854 100644 --- a/src/njs_buffer.c +++ b/src/njs_buffer.c @@ -358,12 +358,12 @@ next: ret = njs_value_property(vm, value, njs_value_arg(&njs_string_type), &retval); if (njs_slow_path(ret != NJS_OK)) { - return NJS_DECLINED; + return ret; } ret = njs_value_to_string(vm, &retval, &retval); if (njs_slow_path(ret != NJS_OK)) { - return NJS_DECLINED; + return ret; } njs_string_get(&retval, &str); @@ -375,7 +375,7 @@ next: ret = njs_value_property(vm, value, njs_value_arg(&njs_string_data), &retval); if (njs_slow_path(ret != NJS_OK)) { - return NJS_DECLINED; + return ret; } if (njs_is_object(&retval)) { diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 7470b4bd..ba3c6960 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -19920,6 +19920,12 @@ static njs_unit_test_t njs_buffer_module_test[] = { njs_str("njs.dump(Buffer.from(new String('test')))"), njs_str("Buffer [116,101,115,116]") }, + { njs_str("Buffer.from({ get type() { throw new Error('test'); } })"), + njs_str("Error: test") }, + + { njs_str("Buffer.from({ type: 'Buffer', get data() { throw new Error('test'); } })"), + njs_str("Error: test") }, + { njs_str("[" " ['6576696c', 'hex']," " ['ZXZpbA==', 'base64']," -- 2.47.3