From 8abb5527d27ffaafbbd102e93876cc4854920d4b Mon Sep 17 00:00:00 2001 From: Jan Stola Date: Fri, 5 Oct 2018 11:27:00 +0200 Subject: [PATCH 1/2] Indexed (resp. named) property enumerator should return numbers (strings and symbols) only. --- src/weakref.cc | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/weakref.cc b/src/weakref.cc index 32f0790..3b742b3 100644 --- a/src/weakref.cc +++ b/src/weakref.cc @@ -128,15 +128,22 @@ NAN_INDEX_DELETER(WeakIndexedPropertyDeleter) { info.GetReturnValue().Set(!dead && Nan::Delete(obj, index).FromJust()); } +NAN_PROPERTY_ENUMERATOR(WeakNamedPropertyEnumerator) { + UNWRAP +#if NODE_MAJOR_VERSION >= 7 + info.GetReturnValue().Set(dead ? Nan::New(0) : obj->GetPropertyNames(Nan::GetCurrentContext(), KeyCollectionMode::kIncludePrototypes, ONLY_ENUMERABLE, IndexFilter::kSkipIndices).ToLocalChecked()); +#else + info.GetReturnValue().Set(dead ? Nan::New(0) : Nan::GetPropertyNames(obj).ToLocalChecked()); +#endif +} -/** - * Only one "enumerator" function needs to be defined. This function is used for - * both the property and indexed enumerator functions. - */ - -NAN_PROPERTY_ENUMERATOR(WeakPropertyEnumerator) { +NAN_INDEX_ENUMERATOR(WeakIndexedPropertyEnumerator) { UNWRAP +#if NODE_MAJOR_VERSION >= 7 + info.GetReturnValue().Set(dead ? Nan::New(0) : obj->GetPropertyNames(Nan::GetCurrentContext(), KeyCollectionMode::kIncludePrototypes, static_cast (ONLY_ENUMERABLE | SKIP_STRINGS | SKIP_SYMBOLS), IndexFilter::kIncludeIndices).ToLocalChecked()); +#else info.GetReturnValue().Set(dead ? Nan::New(0) : Nan::GetPropertyNames(obj).ToLocalChecked()); +#endif } /** @@ -282,13 +289,13 @@ NAN_MODULE_INIT(Initialize) { WeakNamedPropertySetter, WeakNamedPropertyQuery, WeakNamedPropertyDeleter, - WeakPropertyEnumerator); + WeakNamedPropertyEnumerator); Nan::SetIndexedPropertyHandler(p, WeakIndexedPropertyGetter, WeakIndexedPropertySetter, WeakIndexedPropertyQuery, WeakIndexedPropertyDeleter, - WeakPropertyEnumerator); + WeakIndexedPropertyEnumerator); p->SetInternalFieldCount(FIELD_COUNT); Nan::SetMethod(target, "get", Get); @@ -302,4 +309,4 @@ NAN_MODULE_INIT(Initialize) { } // anonymous namespace -NODE_MODULE(weakref, Initialize) +NODE_MODULE(weakref, Initialize) \ No newline at end of file From ad22558f03e5c0ba191668dff25ef14a1ba05e39 Mon Sep 17 00:00:00 2001 From: Jan Stola Date: Fri, 5 Oct 2018 11:28:28 +0200 Subject: [PATCH 2/2] Test on Node.js version 10.x as well. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f8138c6..38555b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ node_js: - "7" - "8" - "9" + - "10" install: - npm install