Welcome! Log In Create A New Profile

Advanced

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

Alexander Borisov
September 11, 2019 12:48PM
details: https://hg.nginx.org/njs/rev/bdeb67672e58
branches:
changeset: 1158:bdeb67672e58
user: Alexander Borisov <alexander.borisov@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") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

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

Alexander Borisov 99 September 11, 2019 12:48PM



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

Online Users

Guests: 100
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