]> git.kaiwu.me - njs.git/commitdiff
Fixed njs_property_query() while quering symbol keys.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 19 Aug 2020 12:43:23 +0000 (12:43 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 19 Aug 2020 12:43:23 +0000 (12:43 +0000)
Since 37f1f20de909, njs_object_hash_test() requires lhq->key.start
to be NULL to avoid hash collisions.

The field is zeroed by njs_property_query_init(), but the field still
might be non-zero when njs_property_query() is called inside a loop.

The fix is to ensure lhq->key.start == NULL for symbol keys.

This closes #268 issue on Github.

src/njs_value.c
src/test/njs_unit_test.c

index fc2fbd4990d9c6e33168fe6d2e8aaad54bcf4e19..4a1756fad854945690020ae59977b303466353ef 100644 (file)
@@ -568,6 +568,7 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value,
 
         if (njs_is_symbol(key)) {
             pq->lhq.key_hash = njs_symbol_key(key);
+            pq->lhq.key.start = NULL;
 
         } else {
             njs_string_get(&pq->key, &pq->lhq.key);
index d8dcddd4f28d902bbcdf1f9f6c22d86984199390..3f7f0412fd54984ad03750c2858ee70746a19689 100644 (file)
@@ -13151,6 +13151,10 @@ static njs_unit_test_t  njs_test[] =
                  "[m.hasOwnProperty('abs'), delete m.abs, m.abs(-1)]"),
       njs_str("true,true,1") },
 
+    { njs_str("var Q = Object.create({}, {a: {value: 'AAA'}, [Symbol.toStringTag]:{value: 'TAG'}});"
+              "Q[Symbol.toStringTag]"),
+      njs_str("TAG") },
+
     { njs_str("Object.getOwnPropertyDescriptor({a:1}, 'a').value"),
       njs_str("1") },