Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#4402) - fix Firefox FileReader in a WW
This also re-enables the web worker tests for Firefox. Web worker tests should only be running in Chrome and Firefox now.
- Loading branch information
1 parent
87c60b6
commit 2457a2b
Showing
7 changed files
with
134 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
"IDBKeyRange", | ||
"openDatabase", | ||
"sqlitePlugin", | ||
"chrome" | ||
"chrome", | ||
"FileReaderSync" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,72 @@ | ||
/* jshint worker: true */ | ||
'use strict'; | ||
|
||
function onError(err) { | ||
setTimeout(function () { | ||
throw err; // can catch this in the worker's 'error' listener | ||
}, 0); | ||
} | ||
|
||
function bigTest(name) { | ||
new PouchDB(name, function (err, db) { | ||
if (err) { | ||
throw err; | ||
} | ||
db.post({ | ||
_id: 'blablah', | ||
key: 'lala' | ||
}, function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
db.get('blablah', function (err, doc) { | ||
if (err) { | ||
throw err; | ||
} | ||
self.postMessage(doc.key); | ||
db.destroy(); | ||
}); | ||
var db = new PouchDB(name); | ||
db.post({ | ||
_id: 'blablah', | ||
key: 'lala' | ||
}).then(function () { | ||
return db.get('blablah'); | ||
}).then(function (doc) { | ||
return db.destroy().then(function () { | ||
self.postMessage(doc.key); | ||
}); | ||
}); | ||
}).catch(onError); | ||
} | ||
|
||
function allDocs(name) { | ||
new PouchDB(name, function (err, db) { | ||
if (err) { | ||
throw err; | ||
} | ||
db.post({ | ||
_id: 'blah', | ||
title: 'lalaa', | ||
_attachments: { | ||
'test': { | ||
data: new Blob(), | ||
content_type: '' | ||
} | ||
var db = new PouchDB(name); | ||
db.post({ | ||
_id: 'blah', | ||
title: 'lalaa', | ||
_attachments: { | ||
'test': { | ||
data: new Blob(), | ||
content_type: '' | ||
} | ||
}, function(err, doc) { | ||
db.get(doc.id, function (err, doc) { | ||
if (err) { | ||
throw err; | ||
} | ||
self.postMessage(doc); | ||
db.destroy(); | ||
}); | ||
} | ||
}).then(function () { | ||
return db.get('blah'); | ||
}).then(function (doc) { | ||
return db.destroy().then(function () { | ||
self.postMessage(doc); | ||
}); | ||
}).catch(onError); | ||
} | ||
|
||
function putAttachment(name, docId, attId, att, type) { | ||
var db = new PouchDB(name); | ||
db.putAttachment(docId, attId, att, type).then(function () { | ||
return db.getAttachment(docId, attId); | ||
}).then(function (fetchedAtt) { | ||
return db.destroy().then(function () { | ||
self.postMessage(fetchedAtt); | ||
}); | ||
}); | ||
}).catch(onError); | ||
} | ||
|
||
self.addEventListener('message', function (e) { | ||
if (typeof e.data === 'string' && e.data.indexOf('/dist/') > -1) { | ||
importScripts(e.data); | ||
} | ||
if (e.data === 'ping') { | ||
if (Array.isArray(e.data) && e.data[0] === 'source') { | ||
importScripts(e.data[1]); | ||
} else if (e.data === 'ping') { | ||
self.postMessage('pong'); | ||
} | ||
if (e.data === 'version') { | ||
} else if (e.data === 'version') { | ||
self.postMessage(PouchDB.version); | ||
} | ||
if (Array.isArray(e.data) && e.data[0] === 'create') { | ||
} else if (Array.isArray(e.data) && e.data[0] === 'create') { | ||
bigTest(e.data[1]); | ||
} | ||
if (Array.isArray(e.data) && e.data[0] === 'allDocs') { | ||
} else if (Array.isArray(e.data) && e.data[0] === 'allDocs') { | ||
allDocs(e.data[1]); | ||
} else if (Array.isArray(e.data) && e.data[0] === 'putAttachment') { | ||
putAttachment(e.data[1], e.data[2], e.data[3], e.data[4], e.data[5]); | ||
} else { | ||
onError(new Error('unknown message: ' + JSON.stringify(e.data))); | ||
} | ||
|
||
}); |