Welcome! Log In Create A New Profile

Advanced

[njs] Improved Buffer.from() with Buffer-like objects.

Dmitry Volyntsev
December 27, 2021 11:08AM
details: https://hg.nginx.org/njs/rev/2e544ef59092
branches:
changeset: 1788:2e544ef59092
user: Artem S. Povalyukhin <artem.povaluhin@gmail.com>
date: Sat Dec 25 22:45:30 2021 +0300
description:
Improved Buffer.from() with Buffer-like objects.

diffstat:

src/njs_buffer.c | 6 +++---
src/test/njs_unit_test.c | 6 ++++++
2 files changed, 9 insertions(+), 3 deletions(-)

diffs (43 lines):

diff -r 256421f5cca2 -r 2e544ef59092 src/njs_buffer.c
--- a/src/njs_buffer.c Fri Dec 24 10:00:15 2021 +0300
+++ b/src/njs_buffer.c Sat Dec 25 22:45:30 2021 +0300
@@ -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 -r 256421f5cca2 -r 2e544ef59092 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri Dec 24 10:00:15 2021 +0300
+++ b/src/test/njs_unit_test.c Sat Dec 25 22:45:30 2021 +0300
@@ -19920,6 +19920,12 @@ static njs_unit_test_t njs_buffer_modul
{ 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'],"
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Improved Buffer.from() with Buffer-like objects.

Dmitry Volyntsev 220 December 27, 2021 11:08AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 115
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready