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

Dmitry Volyntsev xeioex at nginx.com
Mon Dec 27 16:06:58 UTC 2021


details:   https://hg.nginx.org/njs/rev/2e544ef59092
branches:  
changeset: 1788:2e544ef59092
user:      Artem S. Povalyukhin <artem.povaluhin at 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'],"


More information about the nginx-devel mailing list