Skip to content

Commit

Permalink
fixup! src: introduce node::Realm
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Aug 22, 2022
1 parent 4d66626 commit fa568fd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 30 deletions.
23 changes: 8 additions & 15 deletions src/env-inl.h
Expand Up @@ -618,17 +618,6 @@ inline bool Environment::has_run_bootstrapping_code() const {
return principal_realm_->has_run_bootstrapping_code();
}

inline void Environment::DoneBootstrapping() {
CHECK(has_run_bootstrapping_code());

// This adjusts the return value of base_object_created_after_bootstrap() so
// that tests that check the count do not have to account for internally
// created BaseObjects.

// TODO(legendecas): track base objects by realms instead of environments.
base_object_created_by_bootstrap_ = base_object_count_;
}

inline bool Environment::has_serialized_options() const {
return has_serialized_options_;
}
Expand Down Expand Up @@ -834,14 +823,18 @@ void Environment::modify_base_object_count(int64_t delta) {
base_object_count_ += delta;
}

int64_t Environment::base_object_created_after_bootstrap() const {
return base_object_count_ - base_object_created_by_bootstrap_;
}

int64_t Environment::base_object_count() const {
return base_object_count_;
}

inline void Environment::set_base_object_created_by_bootstrap(int64_t count) {
base_object_created_by_bootstrap_ = base_object_count_;
}

int64_t Environment::base_object_created_after_bootstrap() const {
return base_object_count_ - base_object_created_by_bootstrap_;
}

void Environment::set_main_utf16(std::unique_ptr<v8::String::Value> str) {
CHECK(!main_utf16_);
main_utf16_ = std::move(str);
Expand Down
7 changes: 1 addition & 6 deletions src/env.cc
Expand Up @@ -520,11 +520,6 @@ void TrackingTraceStateObserver::UpdateTraceCategoryState() {
USE(cb->Call(env_->context(), Undefined(isolate), arraysize(args), args));
}

void Environment::AssignToContext(Local<v8::Context> context,
const ContextInfo& info) {
AssignToContext(context, nullptr, info);
}

void Environment::AssignToContext(Local<v8::Context> context,
Realm* realm,
const ContextInfo& info) {
Expand Down Expand Up @@ -736,7 +731,7 @@ void Environment::InitializeMainContext(Local<Context> context,
const EnvSerializeInfo* env_info) {
principal_realm_ = std::make_unique<Realm>(
isolate_data_, this, context, MAYBE_FIELD_PTR(env_info, principal_realm));
AssignToContext(context, ContextInfo(""));
AssignToContext(context, principal_realm_.get(), ContextInfo(""));
if (env_info != nullptr) {
DeserializeProperties(env_info);
}
Expand Down
17 changes: 12 additions & 5 deletions src/env.h
Expand Up @@ -729,7 +729,6 @@ class Environment : public MemoryRetainer {
template <typename T, typename OnCloseCallback>
inline void CloseHandle(T* handle, OnCloseCallback callback);

void AssignToContext(v8::Local<v8::Context> context, const ContextInfo& info);
void AssignToContext(v8::Local<v8::Context> context,
Realm* realm,
const ContextInfo& info);
Expand Down Expand Up @@ -837,8 +836,8 @@ class Environment : public MemoryRetainer {
// as Workers aren't directly associated with their own libuv handles.
void add_refs(int64_t diff);

// Convenient getter of the principal realm's has_run_bootstrapping_code().
inline bool has_run_bootstrapping_code() const;
inline void DoneBootstrapping();

inline bool has_serialized_options() const;
inline void set_has_serialized_options(bool has_serialized_options);
Expand Down Expand Up @@ -916,12 +915,14 @@ class Environment : public MemoryRetainer {
inline void set_ ## PropertyName(v8::Local<TypeName> value);
PER_ISOLATE_TEMPLATE_PROPERTIES(V)
// Per-realm strong persistent values of the principal realm.
// Deprecated. Get/set the value with an explicit realm instead.
// Get/set the value with an explicit realm instead when possible.
// Deprecate soon.
PER_REALM_STRONG_PERSISTENT_VALUES(V)
#undef V

// Return the context of the principal realm.
// Deprecated. Get the context with an explicit realm instead.
// Get the context with an explicit realm instead when possible.
// Deprecate soon.
inline v8::Local<v8::Context> context() const;
inline Realm* principal_realm() const;

Expand Down Expand Up @@ -1007,9 +1008,15 @@ class Environment : public MemoryRetainer {
// no memory leaks caused by BaseObjects staying alive longer than expected
// (in particular, no circular BaseObjectPtr references).
inline void modify_base_object_count(int64_t delta);
inline int64_t base_object_created_after_bootstrap() const;
inline int64_t base_object_count() const;

// Base object count created in bootstrap of the principal realm.
// This adjusts the return value of base_object_created_after_bootstrap() so
// that tests that check the count do not have to account for internally
// created BaseObjects.
inline void set_base_object_created_by_bootstrap(int64_t count);
inline int64_t base_object_created_after_bootstrap() const;

inline int32_t stack_trace_limit() const { return 10; }

#if HAVE_INSPECTOR
Expand Down
2 changes: 1 addition & 1 deletion src/node_contextify.cc
Expand Up @@ -248,7 +248,7 @@ MaybeLocal<Context> ContextifyContext::CreateV8Context(
info.origin = *origin_val;
}

env->AssignToContext(ctx, info);
env->AssignToContext(ctx, nullptr, info);

return scope.Escape(ctx);
}
Expand Down
2 changes: 1 addition & 1 deletion src/node_main_instance.cc
Expand Up @@ -182,7 +182,7 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code) {
#if HAVE_INSPECTOR
env->InitializeInspector({});
#endif
env->DoneBootstrapping();
env->set_base_object_created_by_bootstrap(env->base_object_count());

#if HAVE_OPENSSL
crypto::InitCryptoOnce(isolate_);
Expand Down
4 changes: 2 additions & 2 deletions src/node_realm.cc
Expand Up @@ -295,8 +295,8 @@ MaybeLocal<Value> Realm::RunBootstrapping() {

has_run_bootstrapping_code_ = true;

// TODO(legendecas): only mark env as done bootstrapping in principal realms.
env_->DoneBootstrapping();
// TODO(legendecas): track base object count by realms.
env_->set_base_object_created_by_bootstrap(env_->base_object_count());

return scope.Escape(result);
}
Expand Down

0 comments on commit fa568fd

Please sign in to comment.