Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorExE Boss <3889017+ExE-Boss@users.noreply.github.com>2021-01-18 02:30:00 +0300
committerJames M Snell <jasnell@gmail.com>2021-01-23 06:49:04 +0300
commit3ec71143f2afe2d955936f5692dd3b615dbee46e (patch)
tree03819232ad8c71406cc010efdd66d6f843cb1758 /src/env.cc
parent432a5710537ec0f0a4359f5a8d7d0fede9c9b4c4 (diff)
lib: support returning Safe collections from C++
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/36989 Refs: https://github.com/nodejs/node/pull/36652 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r--src/env.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc
index 7e89c2828f2..b618f840af8 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -273,6 +273,29 @@ void Environment::CreateProperties() {
CHECK(primordials->IsObject());
set_primordials(primordials.As<Object>());
+ Local<String> prototype_string =
+ FIXED_ONE_BYTE_STRING(isolate(), "prototype");
+
+#define V(EnvPropertyName, PrimordialsPropertyName) \
+ { \
+ Local<Value> ctor = \
+ primordials.As<Object>() \
+ ->Get(ctx, \
+ FIXED_ONE_BYTE_STRING(isolate(), PrimordialsPropertyName)) \
+ .ToLocalChecked(); \
+ CHECK(ctor->IsObject()); \
+ Local<Value> prototype = \
+ ctor.As<Object>()->Get(ctx, prototype_string).ToLocalChecked(); \
+ CHECK(prototype->IsObject()); \
+ set_##EnvPropertyName(prototype.As<Object>()); \
+ }
+
+ V(primordials_safe_map_prototype_object, "SafeMap");
+ V(primordials_safe_set_prototype_object, "SafeSet");
+ V(primordials_safe_weak_map_prototype_object, "SafeWeakMap");
+ V(primordials_safe_weak_set_prototype_object, "SafeWeakSet");
+#undef V
+
Local<Object> process_object =
node::CreateProcessObject(this).FromMaybe(Local<Object>());
set_process_object(process_object);