From: Artem S. Povalyukhin Date: Sat, 25 Dec 2021 19:45:30 +0000 (+0300) Subject: Improved Buffer.from() with Buffer-like objects. X-Git-Tag: 0.7.1~2 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=bc60f9a2bc956d4c96a36092594778b110ff92d4;p=njs.git Improved Buffer.from() with Buffer-like objects. --- 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'],"