]> git.kaiwu.me - njs.git/commitdiff
Improved Buffer.from() with Buffer-like objects.
authorArtem S. Povalyukhin <artem.povaluhin@gmail.com>
Sat, 25 Dec 2021 19:45:30 +0000 (22:45 +0300)
committerArtem S. Povalyukhin <artem.povaluhin@gmail.com>
Sat, 25 Dec 2021 19:45:30 +0000 (22:45 +0300)
src/njs_buffer.c
src/test/njs_unit_test.c

index 778babdc325a8aa072917bac59b62335ff03aff9..131828542c737e9cd211c3c9c7df0dcccd7314fe 100644 (file)
@@ -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)) {
index 7470b4bd674b0f318e3a3ff73782f9bf2a315725..ba3c6960f7b0cdcb03a5bfcffa8642893c184128 100644 (file)
@@ -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'],"