[njs] Fixed handing of accessor descriptors in Object.freeze().

Alexander Borisov alexander.borisov at nginx.com
Wed Sep 11 16:47:29 UTC 2019


details:   https://hg.nginx.org/njs/rev/bdeb67672e58
branches:  
changeset: 1158:bdeb67672e58
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Wed Sep 11 19:46:30 2019 +0300
description:
Fixed handing of accessor descriptors in Object.freeze().

This closes #211 issue on GitHub.

diffstat:

 src/njs_object.c         |   5 ++++-
 src/test/njs_unit_test.c |  11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletions(-)

diffs (36 lines):

diff -r 12da61ec4adb -r bdeb67672e58 src/njs_object.c
--- a/src/njs_object.c	Fri Sep 06 15:47:12 2019 +0300
+++ b/src/njs_object.c	Wed Sep 11 19:46:30 2019 +0300
@@ -1345,7 +1345,10 @@ njs_object_freeze(njs_vm_t *vm, njs_valu
             break;
         }
 
-        prop->writable = 0;
+        if (!njs_is_accessor_descriptor(prop)) {
+            prop->writable = 0;
+        }
+
         prop->configurable = 0;
     }
 
diff -r 12da61ec4adb -r bdeb67672e58 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Fri Sep 06 15:47:12 2019 +0300
+++ b/src/test/njs_unit_test.c	Wed Sep 11 19:46:30 2019 +0300
@@ -10849,6 +10849,17 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("var r = Object.freeze(new RegExp('')); r.a = 1"),
       njs_str("TypeError: Cannot add property \"a\", object is not extensible") },
 
+    { njs_str("var o = Object.freeze({ get x() { return 10; } }); o.x"),
+      njs_str("10") },
+
+    { njs_str("var o = Object.freeze({ get x() { return 10; } });"
+              "Object.getOwnPropertyDescriptors(o).x.get"),
+      njs_str("[object Function]") },
+
+    { njs_str("var o = Object.freeze({ get x() { return 10; } });"
+              "Object.getOwnPropertyDescriptor(o, 'x').writable"),
+      njs_str("undefined") },
+
     { njs_str("Object.isFrozen({a:1})"),
       njs_str("false") },
 


More information about the nginx-devel mailing list