@@ -50,6 +50,7 @@ using v8::BackingStoreInitializationMode;
5050using v8::BackingStoreOnFailureMode;
5151using v8::BigInt;
5252using v8::Context;
53+ using v8::DictionaryTemplate;
5354using v8::EscapableHandleScope;
5455using v8::Exception;
5556using v8::Function;
@@ -229,6 +230,22 @@ struct FipsIndicatorEvent {
229230 uint32_t dropped = 0 ;
230231};
231232
233+ Local<DictionaryTemplate> GetFipsIndicatorEventTemplate (Environment* env) {
234+ auto tmpl = env->fips_indicator_event_template ();
235+ if (tmpl.IsEmpty ()) {
236+ static constexpr std::string_view names[] = {
237+ " operation" ,
238+ " reason" ,
239+ " blocked" ,
240+ " count" ,
241+ " dropped" ,
242+ };
243+ tmpl = DictionaryTemplate::New (env->isolate (), names);
244+ env->set_fips_indicator_event_template (tmpl);
245+ }
246+ return tmpl;
247+ }
248+
232249class FipsIndicatorState final {
233250 public:
234251 static FipsIndicatorState& Get () {
@@ -361,32 +378,17 @@ class FipsIndicatorState final {
361378 const uint64_t subscription_generation = subscription_generation_;
362379 for (const auto & event : events) {
363380 if (subscription_generation_ != subscription_generation) return ;
364- Local<Object> value = Object::New (isolate);
365- if (value
366- ->Set (context,
367- OneByteString (isolate, " operation" ),
368- OneByteString (isolate, event.operation ))
369- .IsNothing () ||
370- value
371- ->Set (context,
372- OneByteString (isolate, " reason" ),
373- OneByteString (isolate, event.reason ))
374- .IsNothing () ||
375- value
376- ->Set (context,
377- OneByteString (isolate, " blocked" ),
378- v8::Boolean::New (isolate, event.blocked ))
379- .IsNothing () ||
380- value
381- ->Set (context,
382- OneByteString (isolate, " count" ),
383- Uint32::New (isolate, event.count ))
384- .IsNothing () ||
385- value
386- ->Set (context,
387- OneByteString (isolate, " dropped" ),
388- Uint32::New (isolate, event.dropped ))
389- .IsNothing ()) {
381+ MaybeLocal<Value> values[] = {
382+ OneByteString (isolate, event.operation ),
383+ OneByteString (isolate, event.reason ),
384+ v8::Boolean::New (isolate, event.blocked ),
385+ Uint32::New (isolate, event.count ),
386+ Uint32::New (isolate, event.dropped ),
387+ };
388+ Local<Object> value;
389+ if (!NewDictionaryInstance (
390+ context, GetFipsIndicatorEventTemplate (env), values)
391+ .ToLocal (&value)) {
390392 return ;
391393 }
392394 channel_->Publish (env, value);
0 commit comments