File tree Expand file tree Collapse file tree 6 files changed +24
-0
lines changed Expand file tree Collapse file tree 6 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 22
33[ Full changelog] ( https://github.com/mozilla/glean.js/compare/v0.8.0...main )
44
5+ * [ #201 ] ( https://github.com/mozilla/glean.js/pull/201 ) : BUGFIX: Do not let the platform be changed after Glean is initialized.
56# v0.8.0 (2021-04-13)
67
78[ Full changelog] ( https://github.com/mozilla/glean.js/compare/v0.7.0...v0.8.0 )
Original file line number Diff line number Diff line change @@ -443,6 +443,14 @@ class Glean {
443443 * Please check out the available environments in the platform/ module.
444444 */
445445 static setPlatform ( platform : Platform ) : void {
446+ if ( Context . initialized ) {
447+ console . info (
448+ "Attempted to set the platform but Glean has already been initialized. Ignoring." ,
449+ `Current platform is: ${ Glean . platform . name } }`
450+ ) ;
451+ return ;
452+ }
453+
446454 Glean . instance . _platform = platform ;
447455 }
448456
Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ interface Platform {
2020 uploader : Uploader ,
2121 // The environment specifici implemtation of platform information getters
2222 info : PlatformInfo ,
23+ // The name of the platform, useful for logging and debugging purposes.
24+ name : string ,
2325}
2426
2527export default Platform ;
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ const TestPlatform: Platform = {
4343 Storage : MockStorage ,
4444 uploader : new MockUploader ( ) ,
4545 info : MockPlatformInfo ,
46+ name : "test"
4647} ;
4748
4849export default TestPlatform ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ const WebExtPlatform: Platform = {
1212 Storage,
1313 uploader,
1414 info,
15+ name : "webext"
1516} ;
1617
1718export default WebExtPlatform ;
Original file line number Diff line number Diff line change @@ -514,4 +514,15 @@ describe("Glean", function() {
514514 [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
515515 ) ;
516516 } ) ;
517+
518+ it ( "disallow changing the platform after Glean is initialized" , async function ( ) {
519+ const MockPlatform = {
520+ ...TestPlatform ,
521+ name : "mock"
522+ } ;
523+
524+ Glean . setPlatform ( MockPlatform ) ;
525+
526+ assert . strictEqual ( TestPlatform . name , Glean . platform . name ) ;
527+ } ) ;
517528} ) ;
You can’t perform that action at this time.
0 commit comments