77import { globals } from 'vs/base/common/platform' ;
88import { logOnceWebWorkerWarning , IWorker , IWorkerCallback , IWorkerFactory } from 'vs/base/common/worker/simpleWorker' ;
99
10- function getWorkerUrl ( workerId : string , label : string ) : string {
11- // Option for hosts to overwrite the worker script url (used in the standalone editor)
12- if ( globals . MonacoEnvironment && typeof globals . MonacoEnvironment . getWorkerUrl === 'function' ) {
13- return globals . MonacoEnvironment . getWorkerUrl ( workerId , label ) ;
10+ function getWorker ( workerId : string , label : string ) : Worker {
11+ // Option for hosts to overwrite the worker script (used in the standalone editor)
12+ if ( globals . MonacoEnvironment ) {
13+ if ( typeof globals . MonacoEnvironment . getWorker === 'function' ) {
14+ return globals . MonacoEnvironment . getWorker ( workerId , label ) ;
15+ }
16+ if ( typeof globals . MonacoEnvironment . getWorkerUrl === 'function' ) {
17+ return new Worker ( globals . MonacoEnvironment . getWorkerUrl ( workerId , label ) ) ;
18+ }
1419 }
1520 // ESM-comment-begin
1621 if ( typeof require === 'function' ) {
17- return require . toUrl ( './' + workerId ) + '#' + label ;
22+ return new Worker ( require . toUrl ( './' + workerId ) + '#' + label ) ;
1823 }
1924 // ESM-comment-end
20- throw new Error ( `You must define a function MonacoEnvironment.getWorkerUrl` ) ;
25+ throw new Error ( `You must define a function MonacoEnvironment.getWorkerUrl or MonacoEnvironment.getWorker ` ) ;
2126}
2227
2328/**
@@ -31,7 +36,7 @@ class WebWorker implements IWorker {
3136
3237 constructor ( moduleId : string , id : number , label : string , onMessageCallback : IWorkerCallback , onErrorCallback : ( err : any ) => void ) {
3338 this . id = id ;
34- this . worker = new Worker ( getWorkerUrl ( 'workerMain.js' , label ) ) ;
39+ this . worker = getWorker ( 'workerMain.js' , label ) ;
3540 this . postMessage ( moduleId ) ;
3641 this . worker . onmessage = function ( ev : any ) {
3742 onMessageCallback ( ev . data ) ;
0 commit comments