Restore path parameter of initWorker method
This commit is contained in:
parent
de0a6d1259
commit
712f807e50
|
@ -50,17 +50,19 @@ var asyncProxy = null; // instance of the asyncproxy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the path for the web worker script and create an instance of the async proxy
|
* Set the path for the web worker script and create an instance of the async proxy
|
||||||
* @param {Object} [options.path=String] relative path to the worker scripts, default: 'openpgp.worker.js'
|
* @param {String} path relative path to the worker scripts, default: 'openpgp.worker.js'
|
||||||
* [options.worker=module:async_proxy~AsyncProxy] initialized AsyncProxy object to be used as a worker
|
* @param {Object} [options.worker=Object] alternative to path parameter:
|
||||||
|
* web worker initialized with 'openpgp.worker.js'
|
||||||
* @return {Boolean} true if worker created successfully
|
* @return {Boolean} true if worker created successfully
|
||||||
*/
|
*/
|
||||||
function initWorker(options) {
|
function initWorker(path, options) {
|
||||||
if (!options.worker &&
|
if (options && options.worker ||
|
||||||
(typeof window === 'undefined' || !window.Worker)) {
|
typeof window !== 'undefined' && window.Worker) {
|
||||||
|
asyncProxy = new AsyncProxy(path, options);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
asyncProxy = new AsyncProxy(options);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -38,12 +38,14 @@ var INITIAL_RANDOM_SEED = 50000, // random bytes seeded to worker
|
||||||
* Initializes a new proxy and loads the web worker
|
* Initializes a new proxy and loads the web worker
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {String} path The path to the worker or 'openpgp.worker.js' by default
|
* @param {String} path The path to the worker or 'openpgp.worker.js' by default
|
||||||
|
* @param {Object} [options.worker=Object] alternative to path parameter:
|
||||||
|
* web worker initialized with 'openpgp.worker.js'
|
||||||
*/
|
*/
|
||||||
function AsyncProxy(options) {
|
function AsyncProxy(path, options) {
|
||||||
if (options && options.worker) {
|
if (options && options.worker) {
|
||||||
this.worker = options.worker;
|
this.worker = options.worker;
|
||||||
} else {
|
} else {
|
||||||
this.worker = new Worker(options && options.path || 'openpgp.worker.js');
|
this.worker = new Worker(path || 'openpgp.worker.js');
|
||||||
}
|
}
|
||||||
this.worker.onmessage = this.onMessage.bind(this);
|
this.worker.onmessage = this.onMessage.bind(this);
|
||||||
this.worker.onerror = function(e) {
|
this.worker.onerror = function(e) {
|
||||||
|
|
|
@ -178,7 +178,7 @@ describe('Init Worker', function() {
|
||||||
|
|
||||||
it('openpgp.getWorker method', function (done) {
|
it('openpgp.getWorker method', function (done) {
|
||||||
expect(openpgp.getWorker()).to.be.null;
|
expect(openpgp.getWorker()).to.be.null;
|
||||||
var workerAvailable = openpgp.initWorker({path: '../dist/openpgp.worker.js'});
|
var workerAvailable = openpgp.initWorker('../dist/openpgp.worker.js');
|
||||||
expect(workerAvailable).to.be.true;
|
expect(workerAvailable).to.be.true;
|
||||||
expect(openpgp.getWorker()).to.exist;
|
expect(openpgp.getWorker()).to.exist;
|
||||||
privKeyRSA = openpgp.key.readArmored(priv_key_rsa).keys[0];
|
privKeyRSA = openpgp.key.readArmored(priv_key_rsa).keys[0];
|
||||||
|
@ -196,7 +196,7 @@ describe('High level API', function() {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
openpgp.initWorker({path: '../dist/openpgp.worker.js'});
|
openpgp.initWorker('../dist/openpgp.worker.js');
|
||||||
initKeys();
|
initKeys();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ describe('High level API', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Depleted random buffer in worker gives error', function (done) {
|
it('Depleted random buffer in worker gives error', function (done) {
|
||||||
var wProxy = new openpgp.AsyncProxy({path: '../dist/openpgp.worker.js'});
|
var wProxy = new openpgp.AsyncProxy('../dist/openpgp.worker.js');
|
||||||
wProxy.worker = new Worker('../dist/openpgp.worker.js');
|
wProxy.worker = new Worker('../dist/openpgp.worker.js');
|
||||||
wProxy.worker.onmessage = wProxy.onMessage.bind(wProxy);
|
wProxy.worker.onmessage = wProxy.onMessage.bind(wProxy);
|
||||||
wProxy.seedRandom(10);
|
wProxy.seedRandom(10);
|
||||||
|
@ -404,7 +404,7 @@ describe('High level API', function() {
|
||||||
var msg, proxy;
|
var msg, proxy;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
proxy = new openpgp.AsyncProxy({path: '../dist/openpgp.worker.js'});
|
proxy = new openpgp.AsyncProxy('../dist/openpgp.worker.js');
|
||||||
initKeys();
|
initKeys();
|
||||||
msg = openpgp.message.fromText(plaintext).encrypt([pubKeyRSA]);
|
msg = openpgp.message.fromText(plaintext).encrypt([pubKeyRSA]);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user