File tree Expand file tree Collapse file tree 4 files changed +16
-7
lines changed Expand file tree Collapse file tree 4 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -218,9 +218,11 @@ inline T* Environment::GetBindingData(v8::Local<v8::Context> context) {
218
218
context->GetAlignedPointerFromEmbedderData (
219
219
ContextEmbedderIndex::kBindingListIndex ));
220
220
DCHECK_NOT_NULL (map);
221
- auto it = map->find (static_cast <uint8_t >(T::type_int));
222
- if (UNLIKELY (it == map->end ())) return nullptr ;
223
- T* result = static_cast <T*>(it->second .get ());
221
+ constexpr size_t binding_index = static_cast <size_t >(T::type_int);
222
+ static_assert (binding_index < std::tuple_size_v<BindingDataStore>);
223
+ auto ptr = (*map)[binding_index];
224
+ if (UNLIKELY (!ptr)) return nullptr ;
225
+ T* result = static_cast <T*>(ptr.get ());
224
226
DCHECK_NOT_NULL (result);
225
227
DCHECK_EQ (result->env (), GetCurrent (context));
226
228
return result;
@@ -237,8 +239,10 @@ inline T* Environment::AddBindingData(
237
239
context->GetAlignedPointerFromEmbedderData (
238
240
ContextEmbedderIndex::kBindingListIndex ));
239
241
DCHECK_NOT_NULL (map);
240
- auto result = map->emplace (static_cast <uint8_t >(T::type_int), item);
241
- CHECK (result.second );
242
+ constexpr size_t binding_index = static_cast <size_t >(T::type_int);
243
+ static_assert (binding_index < std::tuple_size_v<BindingDataStore>);
244
+ CHECK (!(*map)[binding_index]); // Should not insert the binding twice.
245
+ (*map)[binding_index] = item;
242
246
DCHECK_EQ (GetBindingData<T>(context), item.get ());
243
247
return item.get ();
244
248
}
Original file line number Diff line number Diff line change @@ -1018,7 +1018,9 @@ MaybeLocal<Value> Environment::RunSnapshotDeserializeMain() const {
1018
1018
void Environment::RunCleanup () {
1019
1019
started_cleanup_ = true ;
1020
1020
TRACE_EVENT0 (TRACING_CATEGORY_NODE1 (environment), " RunCleanup" );
1021
- bindings_.clear ();
1021
+ for (size_t i = 0 ; i < bindings_.size (); ++i) {
1022
+ bindings_[i].reset ();
1023
+ }
1022
1024
// Only BaseObject's cleanups are registered as per-realm cleanup hooks now.
1023
1025
// Defer the BaseObject cleanup after handles are cleaned up.
1024
1026
CleanupHandles ();
Original file line number Diff line number Diff line change @@ -601,7 +601,9 @@ class Environment : public MemoryRetainer {
601
601
template <typename T>
602
602
static inline T* GetBindingData (v8::Local<v8::Context> context);
603
603
604
- typedef std::unordered_map<uint8_t , BaseObjectPtr<BaseObject>>
604
+ typedef std::array<BaseObjectPtr<BaseObject>,
605
+ static_cast <size_t >(
606
+ EmbedderObjectType::kEmbedderObjectTypeCount )>
605
607
BindingDataStore;
606
608
607
609
// Create an Environment without initializing a main Context. Use
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ enum class EmbedderObjectType : uint8_t {
37
37
#define V (PropertyName, NativeType ) k_##PropertyName,
38
38
SERIALIZABLE_OBJECT_TYPES (V) UNSERIALIZABLE_OBJECT_TYPES(V)
39
39
#undef V
40
+ kEmbedderObjectTypeCount
40
41
};
41
42
42
43
typedef size_t SnapshotIndex;
You can’t perform that action at this time.
0 commit comments