1919
2020using System ;
2121using System . Text . Json . Serialization ;
22+ using System . Threading ;
2223using System . Threading . Tasks ;
2324
2425namespace OpenQA . Selenium . BiDi . BrowsingContext ;
@@ -29,39 +30,33 @@ internal BrowsingContext(BiDi bidi, string id)
2930 {
3031 BiDi = bidi ;
3132 Id = id ;
32-
33- _logModule = new Lazy < BrowsingContextLogModule > ( ( ) => new BrowsingContextLogModule ( this , BiDi . Log ) ) ;
34- _networkModule = new Lazy < BrowsingContextNetworkModule > ( ( ) => new BrowsingContextNetworkModule ( this , BiDi . Network ) ) ;
35- _scriptModule = new Lazy < BrowsingContextScriptModule > ( ( ) => new BrowsingContextScriptModule ( this , BiDi . Script ) ) ;
36- _storageModule = new Lazy < BrowsingContextStorageModule > ( ( ) => new BrowsingContextStorageModule ( this , BiDi . Storage ) ) ;
37- _inputModule = new Lazy < BrowsingContextInputModule > ( ( ) => new BrowsingContextInputModule ( this , BiDi . InputModule ) ) ;
3833 }
3934
40- private readonly Lazy < BrowsingContextLogModule > _logModule ;
41- private readonly Lazy < BrowsingContextNetworkModule > _networkModule ;
42- private readonly Lazy < BrowsingContextScriptModule > _scriptModule ;
43- private readonly Lazy < BrowsingContextStorageModule > _storageModule ;
44- private readonly Lazy < BrowsingContextInputModule > _inputModule ;
35+ private BrowsingContextLogModule ? _logModule ;
36+ private BrowsingContextNetworkModule ? _networkModule ;
37+ private BrowsingContextScriptModule ? _scriptModule ;
38+ private BrowsingContextStorageModule ? _storageModule ;
39+ private BrowsingContextInputModule ? _inputModule ;
4540
4641 internal string Id { get ; }
4742
4843 [ JsonIgnore ]
4944 public BiDi BiDi { get ; }
5045
5146 [ JsonIgnore ]
52- public BrowsingContextLogModule Log => _logModule . Value ;
47+ public BrowsingContextLogModule Log => _logModule ?? Interlocked . CompareExchange ( ref _logModule , new BrowsingContextLogModule ( this , BiDi . Log ) , null ) ?? _logModule ;
5348
5449 [ JsonIgnore ]
55- public BrowsingContextNetworkModule Network => _networkModule . Value ;
50+ public BrowsingContextNetworkModule Network => _networkModule ?? Interlocked . CompareExchange ( ref _networkModule , new BrowsingContextNetworkModule ( this , BiDi . Network ) , null ) ?? _networkModule ;
5651
5752 [ JsonIgnore ]
58- public BrowsingContextScriptModule Script => _scriptModule . Value ;
53+ public BrowsingContextScriptModule Script => _scriptModule ?? Interlocked . CompareExchange ( ref _scriptModule , new BrowsingContextScriptModule ( this , BiDi . Script ) , null ) ?? _scriptModule ;
5954
6055 [ JsonIgnore ]
61- public BrowsingContextStorageModule Storage => _storageModule . Value ;
56+ public BrowsingContextStorageModule Storage => _storageModule ?? Interlocked . CompareExchange ( ref _storageModule , new BrowsingContextStorageModule ( this , BiDi . Storage ) , null ) ?? _storageModule ;
6257
6358 [ JsonIgnore ]
64- public BrowsingContextInputModule Input => _inputModule . Value ;
59+ public BrowsingContextInputModule Input => _inputModule ?? Interlocked . CompareExchange ( ref _inputModule , new BrowsingContextInputModule ( this , BiDi . InputModule ) , null ) ?? _inputModule ;
6560
6661 public Task < NavigateResult > NavigateAsync ( string url , NavigateOptions ? options = null )
6762 {
0 commit comments