summaryrefslogtreecommitdiff
path: root/src/env.h
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-03-13 12:24:27 +0000
committerAnna Henningsen <anna@addaleax.net>2019-03-30 22:25:33 +0100
commitf5b5fe3937ec353e43d30ae976725e0773e14c6f (patch)
tree57e532e5d82dbf3c553c83bfaa41bb50c76c4b71 /src/env.h
parente4e2b0ce134ce781847272ae0b4bb889e75f223f (diff)
downloadandroid-node-v8-f5b5fe3937ec353e43d30ae976725e0773e14c6f.tar.gz
android-node-v8-f5b5fe3937ec353e43d30ae976725e0773e14c6f.tar.bz2
android-node-v8-f5b5fe3937ec353e43d30ae976725e0773e14c6f.zip
src: allow per-Environment set of env vars
Abstract the `process.env` backing mechanism in C++ to allow different kinds of backing stores for `process.env` for different Environments. PR-URL: https://github.com/nodejs/node/pull/26544 Fixes: https://github.com/nodejs/node/issues/24947 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/env.h')
-rw-r--r--src/env.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/env.h b/src/env.h
index 743c236827..e6c3a1c037 100644
--- a/src/env.h
+++ b/src/env.h
@@ -540,6 +540,23 @@ class AsyncRequest : public MemoryRetainer {
std::atomic_bool stopped_ {true};
};
+class KVStore {
+ public:
+ virtual v8::Local<v8::String> Get(v8::Isolate* isolate,
+ v8::Local<v8::String> key) const = 0;
+ virtual void Set(v8::Isolate* isolate,
+ v8::Local<v8::String> key,
+ v8::Local<v8::String> value) = 0;
+ virtual int32_t Query(v8::Isolate* isolate,
+ v8::Local<v8::String> key) const = 0;
+ virtual void Delete(v8::Isolate* isolate, v8::Local<v8::String> key) = 0;
+ virtual v8::Local<v8::Array> Enumerate(v8::Isolate* isolate) const = 0;
+};
+
+namespace per_process {
+extern std::shared_ptr<KVStore> real_environment;
+}
+
class AsyncHooks {
public:
// Reason for both UidFields and Fields are that one is stored as a double*
@@ -789,6 +806,8 @@ class Environment {
inline ImmediateInfo* immediate_info();
inline TickInfo* tick_info();
inline uint64_t timer_base() const;
+ inline std::shared_ptr<KVStore> envvars();
+ inline void set_envvars(std::shared_ptr<KVStore> envvars);
inline IsolateData* isolate_data() const;
@@ -1075,6 +1094,7 @@ class Environment {
ImmediateInfo immediate_info_;
TickInfo tick_info_;
const uint64_t timer_base_;
+ std::shared_ptr<KVStore> envvars_;
bool printed_error_ = false;
bool emit_env_nonstring_warning_ = true;
bool emit_err_name_warning_ = true;