From affc74460876b352ec4405234c9db33134163f15 Mon Sep 17 00:00:00 2001 From: himself65 Date: Mon, 30 Jan 2023 15:28:12 -0600 Subject: [PATCH] process: print versions by sort --- src/node_process_object.cc | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/node_process_object.cc b/src/node_process_object.cc index 26137396384489..7cc23a3f08727f 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -105,18 +105,37 @@ MaybeLocal CreateProcessObject(Realm* realm) { READONLY_PROPERTY( process, "version", FIXED_ONE_BYTE_STRING(isolate, NODE_VERSION)); - // process.versions Local versions = Object::New(isolate); - READONLY_PROPERTY(process, "versions", versions); + // node.js version is always on the top + READONLY_STRING_PROPERTY( + versions, "node", per_process::metadata.versions.node); + std::vector> versions_vec; #define V(key) \ - if (!per_process::metadata.versions.key.empty()) { \ - READONLY_STRING_PROPERTY( \ - versions, #key, per_process::metadata.versions.key); \ - } + do { \ + versions_vec.push_back( \ + std::make_pair(#key, per_process::metadata.versions.key)); \ + } while (0); NODE_VERSIONS_KEYS(V) #undef V + std::sort(versions_vec.begin(), versions_vec.end(), [](auto& a, auto& b) { + return strcmp(a.first, b.first) < 0; + }); + + for (size_t i = 0; i < versions_vec.size(); ++i) { + const auto version = versions_vec[i]; + versions + ->DefineOwnProperty(context, + OneByteString(isolate, version.first), + ToV8Value(context, version.second).ToLocalChecked(), + v8::ReadOnly) + .Check(); + } + + // process.versions + READONLY_PROPERTY(process, "versions", versions); + // process.arch READONLY_STRING_PROPERTY(process, "arch", per_process::metadata.arch);