fix: initialize asar support in worker threads (#33216)

* fix: initialize asar support in worker threads

Use `ObjectWrap` instead of gin's Wrap in `electron_api_asar.cc` because
gin isn't fully initialized (and apparently not possible to initialize
without ruining the isolate configuration and array buffer allocator) in
worker threads. In the worker thread call `setupAsarSupport` just as we
do for the main process.

* Update lib/asar/fs-wrapper.ts

Co-authored-by: Darshan Sen <raisinten@gmail.com>

* Update patches/node/worker_thread_add_asar_support.patch

Co-authored-by: Darshan Sen <raisinten@gmail.com>

* Add a test

Co-authored-by: Darshan Sen <raisinten@gmail.com>
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
Fedor Indutny 2022-03-22 17:37:55 -07:00 committed by GitHub
parent 27ddf19f3c
commit 06a00b74e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 209 additions and 70 deletions

View file

@ -1,6 +1,7 @@
import { expect } from 'chai';
import * as path from 'path';
import * as url from 'url';
import { Worker } from 'worker_threads';
import { BrowserWindow, ipcMain } from 'electron/main';
import { closeAllWindows } from './window-helpers';
import { emittedOnce } from './events-helpers';
@ -108,4 +109,19 @@ describe('asar package', () => {
expect(result).to.equal('success');
});
});
describe('worker threads', function () {
it('should start worker thread from asar file', function (callback) {
const p = path.join(asarDir, 'worker_threads.asar', 'worker.js');
const w = new Worker(p);
w.on('error', (err) => callback(err));
w.on('message', (message) => {
expect(message).to.equal('ping');
w.terminate();
callback(null);
});
});
});
});