|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { DefaultWorkerFactory } from 'vs/base/worker/defaultWorkerFactory'; |
| 6 | +import { getWorkerBootstrapUrl } from 'vs/base/worker/defaultWorkerFactory'; |
7 | 7 | import { Emitter, Event } from 'vs/base/common/event'; |
8 | | -import { DisposableStore } from 'vs/base/common/lifecycle'; |
| 8 | +import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle'; |
9 | 9 | import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc'; |
10 | 10 | import { VSBuffer } from 'vs/base/common/buffer'; |
11 | 11 | import { createMessageOfType, MessageType, isMessageOfType } from 'vs/workbench/services/extensions/common/extensionHostProtocol'; |
@@ -49,23 +49,29 @@ export class WebWorkerExtensionHostStarter implements IExtensionHostStarter { |
49 | 49 | if (!this._protocol) { |
50 | 50 |
|
51 | 51 | const emitter = new Emitter<VSBuffer>(); |
52 | | - const worker = new DefaultWorkerFactory('WorkerExtensionHost').create( |
53 | | - 'vs/workbench/services/extensions/worker/extensionHostWorker', data => { |
54 | | - if (data instanceof ArrayBuffer) { |
55 | | - emitter.fire(VSBuffer.wrap(new Uint8Array(data, 0, data.byteLength))); |
56 | | - } else { |
57 | | - console.warn('UNKNOWN data received', data); |
58 | | - this._onDidExit.fire([77, 'UNKNOWN data received']); |
59 | | - } |
60 | | - }, err => { |
61 | | - this._onDidExit.fire([81, err]); |
62 | | - console.error(err); |
| 52 | + |
| 53 | + const url = getWorkerBootstrapUrl(require.toUrl('../worker/extensionHostWorkerMain.js'), 'WorkerExtensionHost'); |
| 54 | + const worker = new Worker(url); |
| 55 | + |
| 56 | + worker.onmessage = (event) => { |
| 57 | + const { data } = event; |
| 58 | + if (!(data instanceof ArrayBuffer)) { |
| 59 | + console.warn('UNKNOWN data received', data); |
| 60 | + this._onDidExit.fire([77, 'UNKNOWN data received']); |
| 61 | + return; |
63 | 62 | } |
64 | | - ); |
| 63 | + |
| 64 | + emitter.fire(VSBuffer.wrap(new Uint8Array(data, 0, data.byteLength))); |
| 65 | + }; |
| 66 | + |
| 67 | + worker.onerror = (event) => { |
| 68 | + console.error(event.error); |
| 69 | + this._onDidExit.fire([81, event.error]); |
| 70 | + }; |
65 | 71 |
|
66 | 72 | // keep for cleanup |
67 | 73 | this._toDispose.add(emitter); |
68 | | - this._toDispose.add(worker); |
| 74 | + this._toDispose.add(toDisposable(() => worker.terminate())); |
69 | 75 |
|
70 | 76 | const protocol: IMessagePassingProtocol = { |
71 | 77 | onMessage: emitter.event, |
|
0 commit comments