@@ -32,49 +32,53 @@ export function extensionHostWorkerMain(self: DedicatedWorkerGlobalScope): void
32
32
self . addEventListener ( 'message' , receiveExtensionURL )
33
33
34
34
function receiveExtensionURL ( ev : MessageEvent ) : void {
35
- // Only listen for the 1st URL.
36
- self . removeEventListener ( 'message' , receiveExtensionURL )
35
+ try {
36
+ // Only listen for the 1st URL.
37
+ self . removeEventListener ( 'message' , receiveExtensionURL )
37
38
38
- if ( ev . origin && ev . origin !== self . location . origin ) {
39
- console . error ( `Invalid extension host message origin: ${ ev . origin } (expected ${ self . location . origin } )` )
40
- self . close ( )
41
- }
39
+ if ( ev . origin && ev . origin !== self . location . origin ) {
40
+ console . error ( `Invalid extension host message origin: ${ ev . origin } (expected ${ self . location . origin } )` )
41
+ self . close ( )
42
+ }
42
43
43
- const initData : InitData = ev . data
44
- if ( typeof initData . bundleURL !== 'string' || ! initData . bundleURL . startsWith ( 'blob:' ) ) {
45
- console . error ( `Invalid extension bundle URL: ${ initData . bundleURL } ` )
46
- self . close ( )
47
- }
44
+ const initData : InitData = ev . data
45
+ if ( typeof initData . bundleURL !== 'string' || ! initData . bundleURL . startsWith ( 'blob:' ) ) {
46
+ console . error ( `Invalid extension bundle URL: ${ initData . bundleURL } ` )
47
+ self . close ( )
48
+ }
48
49
49
- const api = createExtensionHost ( initData )
50
- // Make `import 'sourcegraph'` or `require('sourcegraph')` return the extension host's
51
- // implementation of the `sourcegraph` module.
52
- ; ( self as any ) . require = ( modulePath : string ) : any => {
53
- if ( modulePath === 'sourcegraph' ) {
54
- return api
50
+ const api = createExtensionHost ( initData )
51
+ // Make `import 'sourcegraph'` or `require('sourcegraph')` return the extension host's
52
+ // implementation of the `sourcegraph` module.
53
+ ; ( self as any ) . require = ( modulePath : string ) : any => {
54
+ if ( modulePath === 'sourcegraph' ) {
55
+ return api
56
+ }
57
+ throw new Error ( `require: module not found: ${ modulePath } ` )
55
58
}
56
- throw new Error ( `require: module not found: ${ modulePath } ` )
57
- }
58
59
59
- // Load the extension bundle and retrieve the extension entrypoint module's exports on the global
60
- // `module` property.
61
- ; ( self as any ) . exports = { }
62
- ; ( self as any ) . module = { }
63
- self . importScripts ( initData . bundleURL )
64
- const extensionExports = ( self as any ) . module . exports
65
- delete ( self as any ) . module
60
+ // Load the extension bundle and retrieve the extension entrypoint module's exports on the global
61
+ // `module` property.
62
+ ; ( self as any ) . exports = { }
63
+ ; ( self as any ) . module = { }
64
+ self . importScripts ( initData . bundleURL )
65
+ const extensionExports = ( self as any ) . module . exports
66
+ delete ( self as any ) . module
66
67
67
- if ( 'activate' in extensionExports ) {
68
- try {
69
- tryCatchPromise ( ( ) => extensionExports . activate ( ) ) . catch ( ( err : any ) => {
70
- console . error ( `Error creating extension host:` , err )
71
- self . close ( )
72
- } )
73
- } catch ( err ) {
74
- console . error ( `Error activating extension.` , err )
68
+ if ( 'activate' in extensionExports ) {
69
+ try {
70
+ tryCatchPromise ( ( ) => extensionExports . activate ( ) ) . catch ( ( err : any ) => {
71
+ console . error ( `Error creating extension host:` , err )
72
+ self . close ( )
73
+ } )
74
+ } catch ( err ) {
75
+ console . error ( `Error activating extension.` , err )
76
+ }
77
+ } else {
78
+ console . error ( `Extension did not export an 'activate' function.` )
75
79
}
76
- } else {
77
- console . error ( `Extension did not export an 'activate' function.` )
80
+ } catch ( err ) {
81
+ console . error ( err )
78
82
}
79
83
}
80
84
}
0 commit comments