From: Artem S. Povalyukhin Date: Sat, 20 Jul 2019 10:31:59 +0000 (+0300) Subject: Fixed property setter lookup. X-Git-Tag: 0.3.4~62 X-Git-Url: http://git.kaiwu.me/sitemap.xml?a=commitdiff_plain;h=9fb2b28dac447ba8ed11d1cec57e7c97e8a9b60c;p=njs.git Fixed property setter lookup. --- 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 });"