From b08bd02b23fc51c2b7197a2a11f4f77239ad68b9 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 14 Aug 2019 21:48:06 +1000 Subject: [PATCH] Fixed a regression when enumerable properties were added to Object.prototype --- CHANGELOG.md | 4 ++++ src/njsBaton.c | 3 ++- src/njsConnection.c | 10 ++++------ src/njsModule.h | 2 ++ src/njsUtils.c | 21 +++++++++++++++++++++ 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98c1ddda..546062f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ **This release is under development** +- Fixed a regression when enumerable properties were added to + `Object.prototype`. + ([#1129](https://github.com/oracle/node-oracledb/issues/1129)). + - Fixed a regression with missing `metaData` from `connection.getStatementInfo()` - Fixed passing DbObjects and JavaScript objects as the `payload` attribute for diff --git a/src/njsBaton.c b/src/njsBaton.c index 3137446d..699bb7fb 100644 --- a/src/njsBaton.c +++ b/src/njsBaton.c @@ -452,7 +452,8 @@ bool njsBaton_getFetchInfoFromArg(njsBaton *baton, napi_env env, return true; // extract the property names from the object - NJS_CHECK_NAPI(env, napi_get_property_names(env, value, &keys)) + if (!njsUtils_getOwnPropertyNames(env, value, &keys)) + return false; // allocate space for the fetchInfo based on the number of keys NJS_CHECK_NAPI(env, napi_get_array_length(env, keys, &numElements)) diff --git a/src/njsConnection.c b/src/njsConnection.c index 1298d879..0436a4d4 100644 --- a/src/njsConnection.c +++ b/src/njsConnection.c @@ -1994,9 +1994,8 @@ static bool njsConnection_processExecuteBinds(njsBaton *baton, // if binding by name, get the list of bind names bindNames = NULL; - if (!isArray) { - NJS_CHECK_NAPI(env, napi_get_property_names(env, binds, &bindNames)) - } + if (!isArray && !njsUtils_getOwnPropertyNames(env, binds, &bindNames)) + return false; // initialize variables; if there are no variables, nothing further to do! baton->bindArraySize = 1; @@ -2069,9 +2068,8 @@ static bool njsConnection_processExecuteManyBinds(njsBaton *baton, // get the list of bind names, if binding by name bindNames = NULL; - if (!bindByPos) { - NJS_CHECK_NAPI(env, napi_get_property_names(env, bindDefs, &bindNames)) - } + if (!bindByPos && !njsUtils_getOwnPropertyNames(env, bindDefs, &bindNames)) + return false; // initialize variables; if there are no variables, nothing further to do! if (!njsConnection_initBindVars(baton, env, bindDefs, bindNames)) diff --git a/src/njsModule.h b/src/njsModule.h index 5170fe1c..468a0da2 100644 --- a/src/njsModule.h +++ b/src/njsModule.h @@ -943,6 +943,8 @@ bool njsUtils_getError(napi_env env, dpiErrorInfo *errorInfo, bool njsUtils_getIntArg(napi_env env, napi_value *args, int index, int32_t *result); napi_value njsUtils_getNull(napi_env env); +bool njsUtils_getOwnPropertyNames(napi_env env, napi_value value, + napi_value *names); bool njsUtils_getStringArg(napi_env env, napi_value *args, int index, char **result, size_t *resultLength); bool njsUtils_getStringFromArg(napi_env env, napi_value *args, diff --git a/src/njsUtils.c b/src/njsUtils.c index ea8b57b8..0a7755c0 100644 --- a/src/njsUtils.c +++ b/src/njsUtils.c @@ -508,6 +508,27 @@ napi_value njsUtils_getNull(napi_env env) } +//----------------------------------------------------------------------------- +// njsUtils_getOwnPropertyNames() +// Returns an array of property names owned specifically by the given object. +//----------------------------------------------------------------------------- +bool njsUtils_getOwnPropertyNames(napi_env env, napi_value value, + napi_value *names) +{ + napi_value global, globalObject, method; + + NJS_CHECK_NAPI(env, napi_get_global(env, &global)) + NJS_CHECK_NAPI(env, napi_get_named_property(env, global, "Object", + &globalObject)) + NJS_CHECK_NAPI(env, napi_get_named_property(env, globalObject, + "getOwnPropertyNames", &method)) + NJS_CHECK_NAPI(env, napi_call_function(env, globalObject, method, 1, + &value, names)) + + return true; +} + + //----------------------------------------------------------------------------- // njsUtils_getStringArg() // Gets a string from the specified parameter. If the value is not a string,