Skip to content

Commit

Permalink
Fixes #140891: Repair worker url computation caused by moving `defaul…
Browse files Browse the repository at this point in the history
…tWorkerFactory.ts` out of `vs/base/worker`
  • Loading branch information
alexdima committed Jan 18, 2022
1 parent 89ccb8b commit 23aa7ad
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/vs/base/browser/defaultWorkerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ import { IWorker, IWorkerCallback, IWorkerFactory, logOnceWebWorkerWarning } fro

const ttPolicy = window.trustedTypes?.createPolicy('defaultWorkerFactory', { createScriptURL: value => value });

function getWorker(workerId: string, label: string): Worker | Promise<Worker> {
function getWorker(label: string): Worker | Promise<Worker> {
// Option for hosts to overwrite the worker script (used in the standalone editor)
if (globals.MonacoEnvironment) {
if (typeof globals.MonacoEnvironment.getWorker === 'function') {
return globals.MonacoEnvironment.getWorker(workerId, label);
return globals.MonacoEnvironment.getWorker('workerMain.js', label);
}
if (typeof globals.MonacoEnvironment.getWorkerUrl === 'function') {
const workerUrl = <string>globals.MonacoEnvironment.getWorkerUrl(workerId, label);
const workerUrl = <string>globals.MonacoEnvironment.getWorkerUrl('workerMain.js', label);
return new Worker(ttPolicy ? ttPolicy.createScriptURL(workerUrl) as unknown as string : workerUrl, { name: label });
}
}
// ESM-comment-begin
if (typeof require === 'function') {
// check if the JS lives on a different origin
const workerMain = require.toUrl('./' + workerId); // explicitly using require.toUrl(), see https://github.com/microsoft/vscode/issues/107440#issuecomment-698982321
const workerMain = require.toUrl('vs/base/worker/workerMain.js'); // explicitly using require.toUrl(), see https://github.com/microsoft/vscode/issues/107440#issuecomment-698982321
const workerUrl = getWorkerBootstrapUrl(workerMain, label);
return new Worker(ttPolicy ? ttPolicy.createScriptURL(workerUrl) as unknown as string : workerUrl, { name: label });
}
Expand Down Expand Up @@ -63,7 +63,7 @@ class WebWorker implements IWorker {

constructor(moduleId: string, id: number, label: string, onMessageCallback: IWorkerCallback, onErrorCallback: (err: any) => void) {
this.id = id;
const workerOrPromise = getWorker('workerMain.js', label);
const workerOrPromise = getWorker(label);
if (isPromiseLike(workerOrPromise)) {
this.worker = workerOrPromise;
} else {
Expand Down

0 comments on commit 23aa7ad

Please sign in to comment.