From 9fb2b28dac447ba8ed11d1cec57e7c97e8a9b60c Mon Sep 17 00:00:00 2001 From: "Artem S. Povalyukhin" Date: Sat, 20 Jul 2019 13:31:59 +0300 Subject: [PATCH] Fixed property setter lookup. --- njs/njs_object_property.c | 12 ++++++------ njs/test/njs_unit_test.c | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/njs/njs_object_property.c b/njs/njs_object_property.c index 1934c0c5..90c94b6f 100644 --- a/njs/njs_object_property.c +++ b/njs/njs_object_property.c @@ -599,7 +599,12 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object, return NXT_ERROR; } - } else if (!njs_is_function(&prop->setter)) { + } else { + if (njs_is_function(&prop->setter)) { + return njs_function_call(vm, njs_function(&prop->setter), + object, value, 1, &vm->retval); + } + njs_type_error(vm, "Cannot set property \"%V\" of %s which has only a getter", &pq.lhq.key, njs_type_string(object->type)); @@ -623,11 +628,6 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object, break; } - if (njs_is_function(&prop->setter)) { - return njs_function_call(vm, njs_function(&prop->setter), - object, value, 1, &vm->retval); - } - goto found; case NJS_PROPERTY_REF: diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 9b922bd4..f5d1f9ed 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -9629,6 +9629,10 @@ static njs_unit_test_t njs_test[] = "Object.defineProperty(o, 'a', {get:()=>1}); o.a = 2"), nxt_string("TypeError: Cannot set property \"a\" of object which has only a getter") }, + { nxt_string("var o = Object.create(Object.defineProperty({}, 'x', { set: function(v) { this.y = v; }})); " + "o.x = 123; Object.getOwnPropertyDescriptor(o, 'y').value"), + nxt_string("123") }, + { nxt_string("var o = {};" "Object.defineProperty(o, 'a', { configurable: true, value: 0 });" "Object.defineProperty(o, 'a', { value: 1 });" -- 2.47.3