From: Dmitry Volyntsev Date: Mon, 5 Aug 2019 18:17:27 +0000 (+0300) Subject: Fixed "in" operator for values with accessor descriptors. X-Git-Tag: 0.3.4~19 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=ba2a69d0380511a1e6e4e624c252f344e2395a14;p=njs.git Fixed "in" operator for values with accessor descriptors. --- diff --git a/src/njs_vmcode.c b/src/njs_vmcode.c index 51951451..80323e70 100644 --- a/src/njs_vmcode.c +++ b/src/njs_vmcode.c @@ -1182,45 +1182,39 @@ njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *value, njs_value_t *key, static njs_jump_off_t njs_vmcode_property_in(njs_vm_t *vm, njs_value_t *value, njs_value_t *key) { - njs_jump_off_t ret; + njs_int_t ret; + njs_bool_t found; njs_object_prop_t *prop; - const njs_value_t *retval; njs_property_query_t pq; - retval = &njs_value_false; + found = 0; njs_property_query_init(&pq, NJS_PROPERTY_QUERY_GET, 0); ret = njs_property_query(vm, &pq, value, key); + if (njs_slow_path(ret == NJS_ERROR)) { + return ret; + } - switch (ret) { - - case NJS_OK: - prop = pq.lhq.value; - - if (!njs_is_valid(&prop->value)) { - break; - } - - retval = &njs_value_true; - break; - - case NJS_DECLINED: + if (ret == NJS_DECLINED) { if (!njs_is_object(value) && !njs_is_external(value)) { njs_type_error(vm, "property in on a primitive value"); return NJS_ERROR; } - break; - - case NJS_ERROR: - default: + } else { + prop = pq.lhq.value; - return ret; + if (/* !njs_is_data_descriptor(prop) */ + prop->writable == NJS_ATTRIBUTE_UNSET + || njs_is_valid(&prop->value)) + { + found = 1; + } } - vm->retval = *retval; + njs_set_boolean(&vm->retval, found); return sizeof(njs_vmcode_3addr_t); } diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index a87ab398..c609a050 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -3309,6 +3309,15 @@ static njs_unit_test_t njs_test[] = { njs_str("'a' in {a:1}"), njs_str("true") }, + { njs_str("'1' in [0,,2]"), + njs_str("false") }, + + { njs_str("var o = {}; Object.defineProperty(o, 'a', {get:()=>und}); 'a' in o"), + njs_str("true") }, + + { njs_str("var o = {}; Object.defineProperty(o, 'a', {value:1}); ({toString(){return 'a'}}) in o"), + njs_str("true") }, + { njs_str("'a' in Object.create({a:1})"), njs_str("true") },