summaryrefslogtreecommitdiff
path: root/src/node_util.cc
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-08-07 01:21:09 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-08-20 02:11:46 +0200
commit3479b1ca8206c88bac1f1ee8925a2d30759747d7 (patch)
tree1e64f365138d989e9a526fc195c0278adb7b2e34 /src/node_util.cc
parent0bdb95f4cffa7d672c23c60cdb6b779451d2ea33 (diff)
downloadandroid-node-v8-3479b1ca8206c88bac1f1ee8925a2d30759747d7.tar.gz
android-node-v8-3479b1ca8206c88bac1f1ee8925a2d30759747d7.tar.bz2
android-node-v8-3479b1ca8206c88bac1f1ee8925a2d30759747d7.zip
util,assert: improve performance
This significantly improves regular and typed array performance by not checking the indices keys anymore. This can be done with a V8 API that allows to only retrieve the non indices property keys. PR-URL: https://github.com/nodejs/node/pull/22197 Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/node_util.cc')
-rw-r--r--src/node_util.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/node_util.cc b/src/node_util.cc
index 41b1307bb4..591f3e3b5e 100644
--- a/src/node_util.cc
+++ b/src/node_util.cc
@@ -16,6 +16,29 @@ using v8::Proxy;
using v8::String;
using v8::Value;
+static void GetOwnNonIndexProperties(
+ const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ Local<Context> context = env->context();
+
+ if (!args[0]->IsObject())
+ return;
+
+ v8::Local<v8::Object> object = args[0].As<v8::Object>();
+
+ // Return only non-enumerable properties by default.
+ v8::Local<v8::Array> properties;
+
+ if (!object->GetPropertyNames(
+ context, v8::KeyCollectionMode::kOwnOnly,
+ v8::ONLY_ENUMERABLE,
+ v8::IndexFilter::kSkipIndices)
+ .ToLocal(&properties)) {
+ return;
+ }
+ args.GetReturnValue().Set(properties);
+}
+
static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) {
// Return undefined if it's not a Promise.
if (!args[0]->IsPromise())
@@ -177,6 +200,8 @@ void Initialize(Local<Object> target,
env->SetMethodNoSideEffect(target, "getProxyDetails", GetProxyDetails);
env->SetMethodNoSideEffect(target, "safeToString", SafeToString);
env->SetMethodNoSideEffect(target, "previewEntries", PreviewEntries);
+ env->SetMethodNoSideEffect(target, "getOwnNonIndexProperties",
+ GetOwnNonIndexProperties);
env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog);
env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog);