44#include " node_external_reference.h"
55#include " node_i18n.h"
66#include " node_process-inl.h"
7+ #include " util.h"
78
89#include < time.h> // tzset(), _tzset()
910#include < optional>
@@ -16,6 +17,7 @@ using v8::DontDelete;
1617using v8::DontEnum;
1718using v8::FunctionTemplate;
1819using v8::HandleScope;
20+ using v8::IndexedPropertyHandlerConfiguration;
1921using v8::Integer;
2022using v8::Intercepted;
2123using v8::Isolate;
@@ -570,6 +572,43 @@ static Intercepted EnvDefiner(Local<Name> property,
570572 }
571573}
572574
575+ static Intercepted EnvGetterIndexed (uint32_t index,
576+ const PropertyCallbackInfo<Value>& info) {
577+ Environment* env = Environment::GetCurrent (info);
578+ Local<Name> name = Uint32ToString (env->context (), index);
579+ return EnvGetter (name, info);
580+ }
581+
582+ static Intercepted EnvSetterIndexed (uint32_t index,
583+ Local<Value> value,
584+ const PropertyCallbackInfo<void >& info) {
585+ Environment* env = Environment::GetCurrent (info);
586+ Local<Name> name = Uint32ToString (env->context (), index);
587+ return EnvSetter (name, value, info);
588+ }
589+
590+ static Intercepted EnvQueryIndexed (uint32_t index,
591+ const PropertyCallbackInfo<Integer>& info) {
592+ Environment* env = Environment::GetCurrent (info);
593+ Local<Name> name = Uint32ToString (env->context (), index);
594+ return EnvQuery (name, info);
595+ }
596+
597+ static Intercepted EnvDeleterIndexed (
598+ uint32_t index, const PropertyCallbackInfo<Boolean>& info) {
599+ Environment* env = Environment::GetCurrent (info);
600+ Local<Name> name = Uint32ToString (env->context (), index);
601+ return EnvDeleter (name, info);
602+ }
603+
604+ static Intercepted EnvDefinerIndexed (uint32_t index,
605+ const PropertyDescriptor& desc,
606+ const PropertyCallbackInfo<void >& info) {
607+ Environment* env = Environment::GetCurrent (info);
608+ Local<Name> name = Uint32ToString (env->context (), index);
609+ return EnvDefiner (name, desc, info);
610+ }
611+
573612void CreateEnvProxyTemplate (IsolateData* isolate_data) {
574613 Isolate* isolate = isolate_data->isolate ();
575614 HandleScope scope (isolate);
@@ -588,6 +627,16 @@ void CreateEnvProxyTemplate(IsolateData* isolate_data) {
588627 nullptr ,
589628 Local<Value>(),
590629 PropertyHandlerFlags::kHasNoSideEffect ));
630+ env_proxy_template->SetHandler (IndexedPropertyHandlerConfiguration (
631+ EnvGetterIndexed,
632+ EnvSetterIndexed,
633+ EnvQueryIndexed,
634+ EnvDeleterIndexed,
635+ nullptr ,
636+ EnvDefinerIndexed,
637+ nullptr ,
638+ Local<Value>(),
639+ PropertyHandlerFlags::kHasNoSideEffect ));
591640 isolate_data->set_env_proxy_template (env_proxy_template);
592641 isolate_data->set_env_proxy_ctor_template (env_proxy_ctor_template);
593642}
@@ -599,6 +648,11 @@ void RegisterEnvVarExternalReferences(ExternalReferenceRegistry* registry) {
599648 registry->Register (EnvDeleter);
600649 registry->Register (EnvEnumerator);
601650 registry->Register (EnvDefiner);
651+ registry->Register (EnvGetterIndexed);
652+ registry->Register (EnvSetterIndexed);
653+ registry->Register (EnvQueryIndexed);
654+ registry->Register (EnvDeleterIndexed);
655+ registry->Register (EnvDefinerIndexed);
602656}
603657} // namespace node
604658
0 commit comments