@@ -15,18 +15,42 @@ const Events = require("sdk/event/core");
1515// See also: https://bugzilla.mozilla.org/show_bug.cgi?id=912121
1616// We can't use the core/devtools.js module since this code is
1717// executed on the backend.
18- var devtools ;
19- try {
20- devtools = Cu . import ( "resource://devtools/shared/Loader.jsm" , { } ) . devtools ;
21- } catch ( err ) {
22- try {
23- devtools = Cu . import ( "resource://gre/modules/devtools/shared/Loader.jsm" , { } ) . devtools ;
24- } catch ( err ) {
25- devtools = Cu . import ( "resource://gre/modules/devtools/Loader.jsm" , { } ) . devtools ;
18+ function safeImport ( ...args ) {
19+ for ( var i = 0 ; i < args . length ; i ++ ) {
20+ try {
21+ return Cu [ "import" ] ( args [ i ] , { } ) ;
22+ }
23+ /* eslint-disable */
24+ catch ( err ) {
25+ }
26+ /* eslint-enable */
27+ }
28+ return { } ;
29+ }
30+
31+ function safeRequire ( devtools , ...args ) {
32+ for ( var i = 0 ; i < args . length ; i ++ ) {
33+ try {
34+ return devtools [ "require" ] ( args [ i ] ) ;
35+ }
36+ catch ( err ) {
37+ }
2638 }
39+ return { } ;
2740}
41+
42+ const devtools = safeImport (
43+ "resource://devtools/shared/Loader.jsm" ,
44+ "resource://gre/modules/devtools/shared/Loader.jsm" ,
45+ "resource://gre/modules/devtools/Loader.jsm"
46+ ) . devtools ;
47+
48+ const protocol = safeRequire ( devtools ,
49+ "devtools/shared/protocol" ,
50+ "devtools/server/protocol"
51+ ) ;
52+
2853const { expectState } = devtools [ "require" ] ( "devtools/server/actors/common" ) ;
29- const protocol = devtools [ "require" ] ( "devtools/server/protocol" ) ;
3054
3155// Platform
3256const { XPCOMUtils } = Cu . import ( "resource://gre/modules/XPCOMUtils.jsm" , { } ) ;
0 commit comments