|
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,14 +615,17 @@ 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 | + |
631 | 624 | // This adjusts the return value of base_object_created_after_bootstrap() so |
632 | 625 | // that tests that check the count do not have to account for internally |
633 | 626 | // created BaseObjects. |
| 627 | + |
| 628 | + // TODO(legendecas): track base objects by realms instead of environments. |
634 | 629 | base_object_created_by_bootstrap_ = base_object_count_; |
635 | 630 | } |
636 | 631 |
|
@@ -911,16 +906,22 @@ void Environment::set_process_exit_handler( |
911 | 906 |
|
912 | 907 | #define V(PropertyName, TypeName) \ |
913 | 908 | inline v8::Local<TypeName> Environment::PropertyName() const { \ |
914 | | - return PersistentToLocal::Strong(PropertyName##_); \ |
| 909 | + DCHECK_NOT_NULL(principal_realm_); \ |
| 910 | + return principal_realm_->PropertyName(); \ |
915 | 911 | } \ |
916 | 912 | inline void Environment::set_##PropertyName(v8::Local<TypeName> value) { \ |
917 | | - PropertyName##_.Reset(isolate(), value); \ |
| 913 | + DCHECK_NOT_NULL(principal_realm_); \ |
| 914 | + principal_realm_->set_##PropertyName(value); \ |
918 | 915 | } |
919 | | - ENVIRONMENT_STRONG_PERSISTENT_VALUES(V) |
| 916 | + PER_REALM_STRONG_PERSISTENT_VALUES(V) |
920 | 917 | #undef V |
921 | 918 |
|
922 | 919 | v8::Local<v8::Context> Environment::context() const { |
923 | | - return PersistentToLocal::Strong(context_); |
| 920 | + return principal_realm()->context(); |
| 921 | +} |
| 922 | + |
| 923 | +Realm* Environment::principal_realm() const { |
| 924 | + return principal_realm_.get(); |
924 | 925 | } |
925 | 926 |
|
926 | 927 | } // namespace node |
|
0 commit comments