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,58 @@ 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;
579+ if (!Uint32ToString (env->context (), index).ToLocal (&name)) {
580+ return Intercepted::kYes ;
581+ }
582+ return EnvGetter (name, info);
583+ }
584+
585+ static Intercepted EnvSetterIndexed (uint32_t index,
586+ Local<Value> value,
587+ const PropertyCallbackInfo<void >& info) {
588+ Environment* env = Environment::GetCurrent (info);
589+ Local<Name> name;
590+ if (!Uint32ToString (env->context (), index).ToLocal (&name)) {
591+ return Intercepted::kYes ;
592+ }
593+ return EnvSetter (name, value, info);
594+ }
595+
596+ static Intercepted EnvQueryIndexed (uint32_t index,
597+ const PropertyCallbackInfo<Integer>& info) {
598+ Environment* env = Environment::GetCurrent (info);
599+ Local<Name> name;
600+ if (!Uint32ToString (env->context (), index).ToLocal (&name)) {
601+ return Intercepted::kYes ;
602+ }
603+ return EnvQuery (name, info);
604+ }
605+
606+ static Intercepted EnvDeleterIndexed (
607+ uint32_t index, const PropertyCallbackInfo<Boolean>& info) {
608+ Environment* env = Environment::GetCurrent (info);
609+ Local<Name> name;
610+ if (!Uint32ToString (env->context (), index).ToLocal (&name)) {
611+ return Intercepted::kYes ;
612+ }
613+ return EnvDeleter (name, info);
614+ }
615+
616+ static Intercepted EnvDefinerIndexed (uint32_t index,
617+ const PropertyDescriptor& desc,
618+ const PropertyCallbackInfo<void >& info) {
619+ Environment* env = Environment::GetCurrent (info);
620+ Local<Name> name;
621+ if (!Uint32ToString (env->context (), index).ToLocal (&name)) {
622+ return Intercepted::kYes ;
623+ }
624+ return EnvDefiner (name, desc, info);
625+ }
626+
573627void CreateEnvProxyTemplate (IsolateData* isolate_data) {
574628 Isolate* isolate = isolate_data->isolate ();
575629 HandleScope scope (isolate);
@@ -588,6 +642,16 @@ void CreateEnvProxyTemplate(IsolateData* isolate_data) {
588642 nullptr ,
589643 Local<Value>(),
590644 PropertyHandlerFlags::kHasNoSideEffect ));
645+ env_proxy_template->SetHandler (IndexedPropertyHandlerConfiguration (
646+ EnvGetterIndexed,
647+ EnvSetterIndexed,
648+ EnvQueryIndexed,
649+ EnvDeleterIndexed,
650+ nullptr ,
651+ EnvDefinerIndexed,
652+ nullptr ,
653+ Local<Value>(),
654+ PropertyHandlerFlags::kHasNoSideEffect ));
591655 isolate_data->set_env_proxy_template (env_proxy_template);
592656 isolate_data->set_env_proxy_ctor_template (env_proxy_ctor_template);
593657}
@@ -599,6 +663,11 @@ void RegisterEnvVarExternalReferences(ExternalReferenceRegistry* registry) {
599663 registry->Register (EnvDeleter);
600664 registry->Register (EnvEnumerator);
601665 registry->Register (EnvDefiner);
666+ registry->Register (EnvGetterIndexed);
667+ registry->Register (EnvSetterIndexed);
668+ registry->Register (EnvQueryIndexed);
669+ registry->Register (EnvDeleterIndexed);
670+ registry->Register (EnvDefinerIndexed);
602671}
603672} // namespace node
604673
0 commit comments