[njs] Fixed Object.defineProperty() for non-boolean descriptor props.

Dmitry Volyntsev xeioex at nginx.com
Wed Aug 7 15:06:47 UTC 2019


details:   https://hg.nginx.org/njs/rev/05fb6e4fdb36
branches:  
changeset: 1113:05fb6e4fdb36
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Aug 07 17:23:47 2019 +0300
description:
Fixed Object.defineProperty() for non-boolean descriptor props.

diffstat:

 src/njs_object_prop.c    |  6 +++---
 src/test/njs_unit_test.c |  5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diffs (45 lines):

diff -r 90b8adf370d4 -r 05fb6e4fdb36 src/njs_object_prop.c
--- a/src/njs_object_prop.c	Wed Aug 07 15:17:57 2019 +0300
+++ b/src/njs_object_prop.c	Wed Aug 07 17:23:47 2019 +0300
@@ -378,7 +378,7 @@ njs_descriptor_prop(njs_vm_t *vm, const 
     pr = njs_object_property(vm, desc, &pq);
     if (pr != NULL) {
         data = 1;
-        prop->writable = pr->value.data.truth;
+        prop->writable = njs_is_true(&pr->value);
     }
 
     pq.key = njs_str_value("enumerable");
@@ -386,7 +386,7 @@ njs_descriptor_prop(njs_vm_t *vm, const 
 
     pr = njs_object_property(vm, desc, &pq);
     if (pr != NULL) {
-        prop->enumerable = pr->value.data.truth;
+        prop->enumerable = njs_is_true(&pr->value);
     }
 
     pq.key = njs_str_value("configurable");
@@ -394,7 +394,7 @@ njs_descriptor_prop(njs_vm_t *vm, const 
 
     pr = njs_object_property(vm, desc, &pq);
     if (pr != NULL) {
-        prop->configurable = pr->value.data.truth;
+        prop->configurable = njs_is_true(&pr->value);
     }
 
     if (accessor && data) {
diff -r 90b8adf370d4 -r 05fb6e4fdb36 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Wed Aug 07 15:17:57 2019 +0300
+++ b/src/test/njs_unit_test.c	Wed Aug 07 17:23:47 2019 +0300
@@ -9545,6 +9545,11 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("var o = {}; Object.defineProperty(o, 'a', Object.create({value:1})); o.a"),
       njs_str("1") },
 
+    { njs_str("var o = {}; Object.defineProperty(o, 'a', {writable:'x', enumerable:'y', configurable:'z'});"
+              "var d = Object.getOwnPropertyDescriptor(o, 'a');"
+              "d.writable && d.enumerable && d.configurable"),
+      njs_str("true") },
+
     { njs_str("var o = {a:1, c:2}; Object.defineProperty(o, 'b', {});"
                  "Object.keys(o)"),
       njs_str("a,c") },


More information about the nginx-devel mailing list