Skip to content

Commit

Permalink
src: per-isolate eternal templates
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Jul 12, 2022
1 parent 57d6228 commit 88ee01d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
23 changes: 16 additions & 7 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1280,14 +1280,23 @@ void Environment::set_process_exit_handler(
#undef VY
#undef VP

#define V(PropertyName, TypeName) \
inline v8::Local<TypeName> Environment::PropertyName() const { \
return PersistentToLocal::Strong(PropertyName ## _); \
} \
inline void Environment::set_ ## PropertyName(v8::Local<TypeName> value) { \
PropertyName ## _.Reset(isolate(), value); \
#define V(PropertyName, TypeName) \
inline v8::Local<TypeName> Environment::PropertyName() const { \
return PropertyName##_.Get(isolate_); \
} \
inline void Environment::set_##PropertyName(v8::Local<TypeName> value) { \
PropertyName##_.Set(isolate(), value); \
}
PER_ISOLATE_TEMPLATES(V)
#undef V

#define V(PropertyName, TypeName) \
inline v8::Local<TypeName> Environment::PropertyName() const { \
return PersistentToLocal::Strong(PropertyName##_); \
} \
inline void Environment::set_##PropertyName(v8::Local<TypeName> value) { \
PropertyName##_.Reset(isolate(), value); \
}
ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V)
ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)
#undef V

Expand Down
4 changes: 2 additions & 2 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ EnvSerializeInfo Environment::Serialize(SnapshotCreator* creator) {
} \
id++; \
} while (0);
ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V)
PER_ISOLATE_TEMPLATES(V)
#undef V

id = 0;
Expand Down Expand Up @@ -1503,7 +1503,7 @@ void Environment::DeserializeProperties(const EnvSerializeInfo* info) {
id++;
#define V(PropertyName, TypeName) SetProperty(PropertyName, TypeName, \
templates, template, isolate_)
ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V);
PER_ISOLATE_TEMPLATES(V);
#undef V

i = 0; // index to the array
Expand Down
8 changes: 5 additions & 3 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ class NoArrayBufferZeroFillScope {
V(x_forwarded_string, "x-forwarded-for") \
V(zero_return_string, "ZERO_RETURN")

#define ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V) \
#define PER_ISOLATE_TEMPLATES(V) \
V(async_wrap_ctor_template, v8::FunctionTemplate) \
V(async_wrap_object_ctor_template, v8::FunctionTemplate) \
V(base_object_ctor_template, v8::FunctionTemplate) \
Expand Down Expand Up @@ -1359,8 +1359,8 @@ class Environment : public MemoryRetainer {
#define V(PropertyName, TypeName) \
inline v8::Local<TypeName> PropertyName() const; \
inline void set_ ## PropertyName(v8::Local<TypeName> value);
PER_ISOLATE_TEMPLATES(V)
ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)
ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V)
#undef V

inline v8::Local<v8::Context> context() const;
Expand Down Expand Up @@ -1652,9 +1652,11 @@ class Environment : public MemoryRetainer {
template <typename T>
void ForEachBaseObject(T&& iterator);

#define V(PropertyName, TypeName) v8::Eternal<TypeName> PropertyName##_;
PER_ISOLATE_TEMPLATES(V)
#undef V
#define V(PropertyName, TypeName) v8::Global<TypeName> PropertyName ## _;
ENVIRONMENT_STRONG_PERSISTENT_VALUES(V)
ENVIRONMENT_STRONG_PERSISTENT_TEMPLATES(V)
#undef V

v8::Global<v8::Context> context_;
Expand Down

0 comments on commit 88ee01d

Please sign in to comment.