| 
31 | 31 | #include "node_context_data.h"  | 
32 | 32 | #include "node_internals.h"  | 
33 | 33 | #include "node_perf_common.h"  | 
 | 34 | +#include "node_realm-inl.h"  | 
34 | 35 | #include "util-inl.h"  | 
35 | 36 | #include "uv.h"  | 
36 | 37 | #include "v8.h"  | 
@@ -177,16 +178,7 @@ inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {  | 
177 | 178 | }  | 
178 | 179 | 
 
  | 
179 | 180 | inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) {  | 
180 |  | -  if (UNLIKELY(context.IsEmpty())) {  | 
181 |  | -    return nullptr;  | 
182 |  | -  }  | 
183 |  | -  if (UNLIKELY(context->GetNumberOfEmbedderDataFields() <=  | 
184 |  | -               ContextEmbedderIndex::kContextTag)) {  | 
185 |  | -    return nullptr;  | 
186 |  | -  }  | 
187 |  | -  if (UNLIKELY(context->GetAlignedPointerFromEmbedderData(  | 
188 |  | -                   ContextEmbedderIndex::kContextTag) !=  | 
189 |  | -               Environment::kNodeContextTagPtr)) {  | 
 | 181 | +  if (UNLIKELY(!ContextEmbedderTag::IsNodeContext(context))) {  | 
190 | 182 |     return nullptr;  | 
191 | 183 |   }  | 
192 | 184 |   return static_cast<Environment*>(  | 
@@ -623,11 +615,13 @@ inline void Environment::set_can_call_into_js(bool can_call_into_js) {  | 
623 | 615 | }  | 
624 | 616 | 
 
  | 
625 | 617 | inline bool Environment::has_run_bootstrapping_code() const {  | 
626 |  | -  return has_run_bootstrapping_code_;  | 
 | 618 | +  return principal_realm_->has_run_bootstrapping_code();  | 
627 | 619 | }  | 
628 | 620 | 
 
  | 
629 | 621 | inline void Environment::DoneBootstrapping() {  | 
630 |  | -  has_run_bootstrapping_code_ = true;  | 
 | 622 | +  CHECK(has_run_bootstrapping_code());  | 
 | 623 | +  // TODO(legendecas): distinguish base objects with realms.  | 
 | 624 | + | 
631 | 625 |   // This adjusts the return value of base_object_created_after_bootstrap() so  | 
632 | 626 |   // that tests that check the count do not have to account for internally  | 
633 | 627 |   // created BaseObjects.  | 
@@ -922,16 +916,22 @@ void Environment::set_process_exit_handler(  | 
922 | 916 | 
 
  | 
923 | 917 | #define V(PropertyName, TypeName)                                              \  | 
924 | 918 |   inline v8::Local<TypeName> Environment::PropertyName() const {               \  | 
925 |  | -    return PersistentToLocal::Strong(PropertyName##_);                         \  | 
 | 919 | +    DCHECK_NOT_NULL(principal_realm_);                                         \  | 
 | 920 | +    return principal_realm_->PropertyName();                                   \  | 
926 | 921 |   }                                                                            \  | 
927 | 922 |   inline void Environment::set_##PropertyName(v8::Local<TypeName> value) {     \  | 
928 |  | -    PropertyName##_.Reset(isolate(), value);                                   \  | 
 | 923 | +    DCHECK_NOT_NULL(principal_realm_);                                         \  | 
 | 924 | +    principal_realm_->set_##PropertyName(value);                               \  | 
929 | 925 |   }  | 
930 |  | -  ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)  | 
 | 926 | +  PER_REALM_STRONG_PERSISTENT_VALUES(V)  | 
931 | 927 | #undef V  | 
932 | 928 | 
 
  | 
933 | 929 | v8::Local<v8::Context> Environment::context() const {  | 
934 |  | -  return PersistentToLocal::Strong(context_);  | 
 | 930 | +  return principal_realm()->context();  | 
 | 931 | +}  | 
 | 932 | + | 
 | 933 | +Realm* Environment::principal_realm() const {  | 
 | 934 | +  return principal_realm_.get();  | 
935 | 935 | }  | 
936 | 936 | 
 
  | 
937 | 937 | }  // namespace node  | 
 | 
0 commit comments