forked from mirrors/gecko-dev
Bug 1515695 - Remove Task.jsm. r=florian,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D118001
This commit is contained in:
parent
a0630bc990
commit
28abf1cb81
17 changed files with 120 additions and 1322 deletions
|
|
@ -207,9 +207,6 @@ toolkit/components/reader/Readerable.jsm
|
||||||
toolkit/mozapps/update/tests/data/xpcshellConstantsPP.js
|
toolkit/mozapps/update/tests/data/xpcshellConstantsPP.js
|
||||||
toolkit/modules/AppConstants.jsm
|
toolkit/modules/AppConstants.jsm
|
||||||
|
|
||||||
# Tests old non-star function generators
|
|
||||||
toolkit/modules/tests/xpcshell/test_task.js
|
|
||||||
|
|
||||||
# Uses special template formatting.
|
# Uses special template formatting.
|
||||||
tools/tryselect/selectors/chooser/templates/chooser.html
|
tools/tryselect/selectors/chooser/templates/chooser.html
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,5 @@ module.exports = {
|
||||||
"no-extend-native": "error",
|
"no-extend-native": "error",
|
||||||
|
|
||||||
"no-shadow": "error",
|
"no-shadow": "error",
|
||||||
|
|
||||||
"mozilla/no-task": "error",
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ rawPackets.set(`ReferenceError: asdf is not defined`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -67,14 +67,14 @@ rawPackets.set(`ReferenceError: asdf is not defined`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -131,7 +131,7 @@ rawPackets.set(`SyntaxError: redeclaration of let a`, {
|
||||||
"private": false,
|
"private": false,
|
||||||
"stacktrace": [
|
"stacktrace": [
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -140,14 +140,14 @@ rawPackets.set(`SyntaxError: redeclaration of let a`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -228,7 +228,7 @@ rawPackets.set(`TypeError longString message`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -237,14 +237,14 @@ rawPackets.set(`TypeError longString message`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -315,7 +315,7 @@ rawPackets.set(`throw string with URL`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -324,14 +324,14 @@ rawPackets.set(`throw string with URL`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -373,7 +373,7 @@ rawPackets.set(`throw ""`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -382,14 +382,14 @@ rawPackets.set(`throw ""`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -431,7 +431,7 @@ rawPackets.set(`throw "tomato"`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -440,14 +440,14 @@ rawPackets.set(`throw "tomato"`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -489,7 +489,7 @@ rawPackets.set(`throw false`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -498,14 +498,14 @@ rawPackets.set(`throw false`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -547,7 +547,7 @@ rawPackets.set(`throw 0`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -556,14 +556,14 @@ rawPackets.set(`throw 0`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -605,7 +605,7 @@ rawPackets.set(`throw null`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -614,14 +614,14 @@ rawPackets.set(`throw null`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -665,7 +665,7 @@ rawPackets.set(`throw undefined`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -674,14 +674,14 @@ rawPackets.set(`throw undefined`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -725,7 +725,7 @@ rawPackets.set(`throw Symbol`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -734,14 +734,14 @@ rawPackets.set(`throw Symbol`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -787,7 +787,7 @@ rawPackets.set(`throw Object`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -796,14 +796,14 @@ rawPackets.set(`throw Object`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -874,7 +874,7 @@ rawPackets.set(`throw Error Object`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -883,14 +883,14 @@ rawPackets.set(`throw Error Object`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -953,7 +953,7 @@ rawPackets.set(`throw Error Object with custom name`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -962,14 +962,14 @@ rawPackets.set(`throw Error Object with custom name`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1032,7 +1032,7 @@ rawPackets.set(`Promise reject ""`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1041,14 +1041,14 @@ rawPackets.set(`Promise reject ""`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1090,7 +1090,7 @@ rawPackets.set(`Promise reject "tomato"`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1099,14 +1099,14 @@ rawPackets.set(`Promise reject "tomato"`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1148,7 +1148,7 @@ rawPackets.set(`Promise reject false`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1157,14 +1157,14 @@ rawPackets.set(`Promise reject false`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1206,7 +1206,7 @@ rawPackets.set(`Promise reject 0`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1215,14 +1215,14 @@ rawPackets.set(`Promise reject 0`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1264,7 +1264,7 @@ rawPackets.set(`Promise reject null`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1273,14 +1273,14 @@ rawPackets.set(`Promise reject null`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1324,7 +1324,7 @@ rawPackets.set(`Promise reject undefined`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1333,14 +1333,14 @@ rawPackets.set(`Promise reject undefined`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1384,7 +1384,7 @@ rawPackets.set(`Promise reject Symbol`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1393,14 +1393,14 @@ rawPackets.set(`Promise reject Symbol`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1446,7 +1446,7 @@ rawPackets.set(`Promise reject Object`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1455,14 +1455,14 @@ rawPackets.set(`Promise reject Object`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1533,7 +1533,7 @@ rawPackets.set(`Promise reject Error Object`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1542,14 +1542,14 @@ rawPackets.set(`Promise reject Error Object`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
@ -1612,7 +1612,7 @@ rawPackets.set(`Promise reject Error Object with custom name`, {
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js line 111 > eval",
|
"filename": "resource://testing-common/content-task.js line 110 > eval",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 6,
|
"lineNumber": 6,
|
||||||
"columnNumber": 29,
|
"columnNumber": 29,
|
||||||
|
|
@ -1621,14 +1621,14 @@ rawPackets.set(`Promise reject Error Object with custom name`, {
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 112,
|
"lineNumber": 111,
|
||||||
"columnNumber": 29,
|
"columnNumber": 33,
|
||||||
"functionName": null
|
"functionName": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filename": "resource://testing-common/content-task.js",
|
"filename": "resource://testing-common/content-task.js",
|
||||||
"sourceId": null,
|
"sourceId": null,
|
||||||
"lineNumber": 65,
|
"lineNumber": 64,
|
||||||
"columnNumber": 19,
|
"columnNumber": 19,
|
||||||
"functionName": null,
|
"functionName": null,
|
||||||
"asyncCause": "MessageListener.receiveMessage"
|
"asyncCause": "MessageListener.receiveMessage"
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ It's easy to make mistakes with asynchronous code, so here are a few guidelines
|
||||||
* Prefer [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) over callbacks.
|
* Prefer [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) over callbacks.
|
||||||
* Use the `new Promise(() => {})` syntax.
|
* Use the `new Promise(() => {})` syntax.
|
||||||
* Don't forget to catch rejections by defining a rejection handler: `promise.then(() => console.log("resolved"), () => console.log("rejected"));` or `promise.catch(() => console.log("rejected"));`.
|
* Don't forget to catch rejections by defining a rejection handler: `promise.then(() => console.log("resolved"), () => console.log("rejected"));` or `promise.catch(() => console.log("rejected"));`.
|
||||||
* Make use of [`Tasks` and generator functions](https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Task.jsm) to make asynchronous code look synchronous. <!--TODO async/await as in the TODO above?-->
|
* Make use of [async and await](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/async_function).
|
||||||
|
|
||||||
## React & Redux
|
## React & Redux
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ There are React-specific code style rules in the .eslintrc file.
|
||||||
|
|
||||||
### Components
|
### Components
|
||||||
|
|
||||||
* Default to creating components as [stateless function components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions).
|
* Default to creating components as [stateless function components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions).
|
||||||
* If you need local state or lifecycle methods, use `React.createClass` instead of functions.
|
* If you need local state or lifecycle methods, use `React.createClass` instead of functions.
|
||||||
* Use React.DOM to create native elements. Assign it to a variable named `dom`, and use it like `dom.div({}, dom.span({}))`. You may also destructure specific elements directly: `const { div, ul } = React.DOM`.
|
* Use React.DOM to create native elements. Assign it to a variable named `dom`, and use it like `dom.div({}, dom.span({}))`. You may also destructure specific elements directly: `const { div, ul } = React.DOM`.
|
||||||
|
|
||||||
|
|
@ -85,5 +85,3 @@ There are React-specific code style rules in the .eslintrc file.
|
||||||
* Use `isRequired` for any required properties.
|
* Use `isRequired` for any required properties.
|
||||||
* Place the propTypes definition at the top of the component. If using a stateless function component, place it above the declaration of the function.
|
* Place the propTypes definition at the top of the component. If using a stateless function component, place it above the declaration of the function.
|
||||||
* Where the children property is used, consider [validating the children](http://www.mattzabriskie.com/blog/react-validating-children).
|
* Where the children property is used, consider [validating the children](http://www.mattzabriskie.com/blog/react-validating-children).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,10 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helpers for async functions. Async functions are generator functions that are
|
* Helpers for async functions. An async function returns a Promise for the
|
||||||
* run by Tasks. An async function returns a Promise for the resolution of the
|
* resolution of the function. When the function returns, the promise is
|
||||||
* function. When the function returns, the promise is resolved with the
|
* resolved with the returned value. If it throws the promise rejects with
|
||||||
* returned value. If it throws the promise rejects with the thrown error.
|
* the thrown error.
|
||||||
*
|
|
||||||
* See Task documentation at https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Task.jsm.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
let { Task } = ChromeUtils.import("resource://testing-common/Task.jsm");
|
|
||||||
let { ContentTaskUtils } = ChromeUtils.import(
|
let { ContentTaskUtils } = ChromeUtils.import(
|
||||||
"resource://testing-common/ContentTaskUtils.jsm"
|
"resource://testing-common/ContentTaskUtils.jsm"
|
||||||
);
|
);
|
||||||
|
|
@ -62,7 +61,7 @@ try {
|
||||||
EventUtils = null;
|
EventUtils = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
addMessageListener("content-task:spawn", function(msg) {
|
addMessageListener("content-task:spawn", async function(msg) {
|
||||||
let id = msg.data.id;
|
let id = msg.data.id;
|
||||||
let source = msg.data.runnable || "()=>{}";
|
let source = msg.data.runnable || "()=>{}";
|
||||||
|
|
||||||
|
|
@ -109,25 +108,15 @@ addMessageListener("content-task:spawn", function(msg) {
|
||||||
|
|
||||||
// eslint-disable-next-line no-eval
|
// eslint-disable-next-line no-eval
|
||||||
let runnable = eval(runnablestr);
|
let runnable = eval(runnablestr);
|
||||||
let iterator = runnable.call(this, msg.data.arg);
|
let result = await runnable.call(this, msg.data.arg);
|
||||||
Task.spawn(iterator).then(
|
|
||||||
val => {
|
|
||||||
sendAsyncMessage("content-task:complete", {
|
|
||||||
id,
|
|
||||||
result: val,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
e => {
|
|
||||||
sendAsyncMessage("content-task:complete", {
|
|
||||||
id,
|
|
||||||
error: e.toString(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
sendAsyncMessage("content-task:complete", {
|
sendAsyncMessage("content-task:complete", {
|
||||||
id,
|
id,
|
||||||
error: e.toString(),
|
result,
|
||||||
|
});
|
||||||
|
} catch (ex) {
|
||||||
|
sendAsyncMessage("content-task:complete", {
|
||||||
|
id,
|
||||||
|
error: ex.toString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
function ChromeTask_ChromeScript() {
|
function ChromeTask_ChromeScript() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { Task } = ChromeUtils.import("resource://testing-common/Task.jsm");
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const { Services } = ChromeUtils.import(
|
const { Services } = ChromeUtils.import(
|
||||||
"resource://gre/modules/Services.jsm"
|
"resource://gre/modules/Services.jsm"
|
||||||
|
|
@ -20,7 +19,7 @@ function ChromeTask_ChromeScript() {
|
||||||
"resource://testing-common/Assert.jsm"
|
"resource://testing-common/Assert.jsm"
|
||||||
);
|
);
|
||||||
|
|
||||||
addMessageListener("chrome-task:spawn", function(aData) {
|
addMessageListener("chrome-task:spawn", async function(aData) {
|
||||||
let id = aData.id;
|
let id = aData.id;
|
||||||
let source = aData.runnable || "()=>{}";
|
let source = aData.runnable || "()=>{}";
|
||||||
|
|
||||||
|
|
@ -67,25 +66,15 @@ function ChromeTask_ChromeScript() {
|
||||||
|
|
||||||
// eslint-disable-next-line no-eval
|
// eslint-disable-next-line no-eval
|
||||||
let runnable = eval(runnablestr);
|
let runnable = eval(runnablestr);
|
||||||
let iterator = runnable.call(this, aData.arg);
|
let result = await runnable.call(this, aData.arg);
|
||||||
Task.spawn(iterator).then(
|
|
||||||
val => {
|
|
||||||
sendAsyncMessage("chrome-task:complete", {
|
|
||||||
id,
|
|
||||||
result: val,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
e => {
|
|
||||||
sendAsyncMessage("chrome-task:complete", {
|
|
||||||
id,
|
|
||||||
error: e.toString(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
sendAsyncMessage("chrome-task:complete", {
|
sendAsyncMessage("chrome-task:complete", {
|
||||||
id,
|
id,
|
||||||
error: e.toString(),
|
result,
|
||||||
|
});
|
||||||
|
} catch (ex) {
|
||||||
|
sendAsyncMessage("chrome-task:complete", {
|
||||||
|
id,
|
||||||
|
error: ex.toString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ let { AppConstants: _AppConstants } = ChromeUtils.import(
|
||||||
let { PromiseTestUtils: _PromiseTestUtils } = ChromeUtils.import(
|
let { PromiseTestUtils: _PromiseTestUtils } = ChromeUtils.import(
|
||||||
"resource://testing-common/PromiseTestUtils.jsm"
|
"resource://testing-common/PromiseTestUtils.jsm"
|
||||||
);
|
);
|
||||||
let { Task: _Task } = ChromeUtils.import("resource://testing-common/Task.jsm");
|
|
||||||
|
|
||||||
let { NetUtil: _NetUtil } = ChromeUtils.import(
|
let { NetUtil: _NetUtil } = ChromeUtils.import(
|
||||||
"resource://gre/modules/NetUtil.jsm"
|
"resource://gre/modules/NetUtil.jsm"
|
||||||
|
|
@ -872,7 +871,7 @@ function _format_stack(stack) {
|
||||||
} else {
|
} else {
|
||||||
normalized = "" + stack;
|
normalized = "" + stack;
|
||||||
}
|
}
|
||||||
return _Task.Debugging.generateReadableStack(normalized, " ");
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a nice display string from an object that behaves
|
// Make a nice display string from an object that behaves
|
||||||
|
|
@ -1563,8 +1562,7 @@ function add_test(properties, func = properties, isTask = false) {
|
||||||
*
|
*
|
||||||
* Unlike add_test(), there is no need to call run_next_test(). The next test
|
* Unlike add_test(), there is no need to call run_next_test(). The next test
|
||||||
* will run automatically as soon the task function is exhausted. To trigger
|
* will run automatically as soon the task function is exhausted. To trigger
|
||||||
* premature (but successful) termination of the function, simply return or
|
* premature (but successful) termination of the function or simply return.
|
||||||
* throw a Task.Result instance.
|
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
*
|
*
|
||||||
|
|
@ -1600,8 +1598,6 @@ function add_task(properties, func = properties) {
|
||||||
return add_test(properties, func, true);
|
return add_test(properties, func, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_Task.Debugging.maintainStack = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the next test function from the list of async tests.
|
* Runs the next test function from the list of async tests.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,5 @@ module.exports = {
|
||||||
// XXX Bug 1326071 - This should be reduced down - probably to 20 or to
|
// XXX Bug 1326071 - This should be reduced down - probably to 20 or to
|
||||||
// be removed & synced with the mozilla/recommended value.
|
// be removed & synced with the mozilla/recommended value.
|
||||||
complexity: ["error", 45],
|
complexity: ["error", 45],
|
||||||
|
|
||||||
"mozilla/no-task": "error",
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -525,15 +525,6 @@ Promise.defer = function() {
|
||||||
* @return A promise that can be pending, resolved, or rejected.
|
* @return A promise that can be pending, resolved, or rejected.
|
||||||
*/
|
*/
|
||||||
Promise.resolve = function(aValue) {
|
Promise.resolve = function(aValue) {
|
||||||
if (aValue && typeof aValue == "function" && aValue.isAsyncFunction) {
|
|
||||||
throw new TypeError(
|
|
||||||
"Cannot resolve a promise with an async function. " +
|
|
||||||
"You should either invoke the async function first " +
|
|
||||||
"or use 'Task.spawn' instead of 'Task.async' to start " +
|
|
||||||
"the Task and return its promise."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aValue instanceof Promise) {
|
if (aValue instanceof Promise) {
|
||||||
return aValue;
|
return aValue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,6 @@ TESTING_JS_MODULES += [
|
||||||
"tests/modules/MockDocument.jsm",
|
"tests/modules/MockDocument.jsm",
|
||||||
"tests/modules/OSKeyStoreTestUtils.jsm",
|
"tests/modules/OSKeyStoreTestUtils.jsm",
|
||||||
"tests/modules/PromiseTestUtils.jsm",
|
"tests/modules/PromiseTestUtils.jsm",
|
||||||
"tests/modules/Task.jsm",
|
|
||||||
"tests/xpcshell/RegionTestUtils.jsm",
|
"tests/xpcshell/RegionTestUtils.jsm",
|
||||||
"tests/xpcshell/TestIntegration.jsm",
|
"tests/xpcshell/TestIntegration.jsm",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,527 +0,0 @@
|
||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
|
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
||||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
/* eslint-disable mozilla/no-task */
|
|
||||||
|
|
||||||
var EXPORTED_SYMBOLS = ["Task"];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This module implements a subset of "Task.js" <http://taskjs.org/>.
|
|
||||||
*
|
|
||||||
* Paraphrasing from the Task.js site, tasks make sequential, asynchronous
|
|
||||||
* operations simple, using the power of JavaScript's "yield" operator.
|
|
||||||
*
|
|
||||||
* Tasks are built upon generator functions and promises, documented here:
|
|
||||||
*
|
|
||||||
* <https://developer.mozilla.org/en/JavaScript/Guide/Iterators_and_Generators>
|
|
||||||
* <http://wiki.commonjs.org/wiki/Promises/A>
|
|
||||||
*
|
|
||||||
* The "Task.spawn" function takes a generator function and starts running it as
|
|
||||||
* a task. Every time the task yields a promise, it waits until the promise is
|
|
||||||
* fulfilled. "Task.spawn" returns a promise that is resolved when the task
|
|
||||||
* completes successfully, or is rejected if an exception occurs.
|
|
||||||
*
|
|
||||||
* -----------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Cu.import("resource://gre/modules/Task.jsm");
|
|
||||||
*
|
|
||||||
* Task.spawn(function* () {
|
|
||||||
*
|
|
||||||
* // This is our task. Let's create a promise object, wait on it and capture
|
|
||||||
* // its resolution value.
|
|
||||||
* let myPromise = getPromiseResolvedOnTimeoutWithValue(1000, "Value");
|
|
||||||
* let result = yield myPromise;
|
|
||||||
*
|
|
||||||
* // This part is executed only after the promise above is fulfilled (after
|
|
||||||
* // one second, in this imaginary example). We can easily loop while
|
|
||||||
* // calling asynchronous functions, and wait multiple times.
|
|
||||||
* for (let i = 0; i < 3; i++) {
|
|
||||||
* result += yield getPromiseResolvedOnTimeoutWithValue(50, "!");
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* return "Resolution result for the task: " + result;
|
|
||||||
* }).then(function (result) {
|
|
||||||
*
|
|
||||||
* // result == "Resolution result for the task: Value!!!"
|
|
||||||
*
|
|
||||||
* // The result is undefined if no value was returned.
|
|
||||||
*
|
|
||||||
* }, function (exception) {
|
|
||||||
*
|
|
||||||
* // Failure! We can inspect or report the exception.
|
|
||||||
*
|
|
||||||
* });
|
|
||||||
*
|
|
||||||
* -----------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* This module implements only the "Task.js" interfaces described above, with no
|
|
||||||
* additional features to control the task externally, or do custom scheduling.
|
|
||||||
* It also provides the following extensions that simplify task usage in the
|
|
||||||
* most common cases:
|
|
||||||
*
|
|
||||||
* - The "Task.spawn" function also accepts an iterator returned by a generator
|
|
||||||
* function, in addition to a generator function. This way, you can call into
|
|
||||||
* the generator function with the parameters you want, and with "this" bound
|
|
||||||
* to the correct value. Also, "this" is never bound to the task object when
|
|
||||||
* "Task.spawn" calls the generator function.
|
|
||||||
*
|
|
||||||
* - In addition to a promise object, a task can yield the iterator returned by
|
|
||||||
* a generator function. The iterator is turned into a task automatically.
|
|
||||||
* This reduces the syntax overhead of calling "Task.spawn" explicitly when
|
|
||||||
* you want to recurse into other task functions.
|
|
||||||
*
|
|
||||||
* - The "Task.spawn" function also accepts a primitive value, or a function
|
|
||||||
* returning a primitive value, and treats the value as the result of the
|
|
||||||
* task. This makes it possible to call an externally provided function and
|
|
||||||
* spawn a task from it, regardless of whether it is an asynchronous generator
|
|
||||||
* or a synchronous function. This comes in handy when iterating over
|
|
||||||
* function lists where some items have been converted to tasks and some not.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Globals
|
|
||||||
|
|
||||||
// The following error types are considered programmer errors, which should be
|
|
||||||
// reported (possibly redundantly) so as to let programmers fix their code.
|
|
||||||
const ERRORS_TO_REPORT = [
|
|
||||||
"EvalError",
|
|
||||||
"RangeError",
|
|
||||||
"ReferenceError",
|
|
||||||
"TypeError",
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Task currently being executed
|
|
||||||
*/
|
|
||||||
var gCurrentTask = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If `true`, capture stacks whenever entering a Task and rewrite the
|
|
||||||
* stack any exception thrown through a Task.
|
|
||||||
*/
|
|
||||||
var gMaintainStack = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Iterate through the lines of a string.
|
|
||||||
*
|
|
||||||
* @return Iterator<string>
|
|
||||||
*/
|
|
||||||
function* linesOf(string) {
|
|
||||||
let reLine = /([^\r\n])+/g;
|
|
||||||
let match;
|
|
||||||
while ((match = reLine.exec(string))) {
|
|
||||||
yield [match[0], match.index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect whether a value is a generator.
|
|
||||||
*
|
|
||||||
* @param aValue
|
|
||||||
* The value to identify.
|
|
||||||
* @return A boolean indicating whether the value is a generator.
|
|
||||||
*/
|
|
||||||
function isGenerator(aValue) {
|
|
||||||
return Object.prototype.toString.call(aValue) == "[object Generator]";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Task
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This object provides the public module functions.
|
|
||||||
*/
|
|
||||||
var Task = {
|
|
||||||
/**
|
|
||||||
* Creates and starts a new task.
|
|
||||||
*
|
|
||||||
* @param aTask
|
|
||||||
* - If you specify a generator function, it is called with no
|
|
||||||
* arguments to retrieve the associated iterator. The generator
|
|
||||||
* function is a task, that is can yield promise objects to wait
|
|
||||||
* upon.
|
|
||||||
* - If you specify the iterator returned by a generator function you
|
|
||||||
* called, the generator function is also executed as a task. This
|
|
||||||
* allows you to call the function with arguments.
|
|
||||||
* - If you specify a function that is not a generator, it is called
|
|
||||||
* with no arguments, and its return value is used to resolve the
|
|
||||||
* returned promise.
|
|
||||||
* - If you specify anything else, you get a promise that is already
|
|
||||||
* resolved with the specified value.
|
|
||||||
*
|
|
||||||
* @return A promise object where you can register completion callbacks to be
|
|
||||||
* called when the task terminates.
|
|
||||||
*/
|
|
||||||
spawn: function Task_spawn(aTask) {
|
|
||||||
return createAsyncFunction(aTask)();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create and return an 'async function' that starts a new task.
|
|
||||||
*
|
|
||||||
* This is similar to 'spawn' except that it doesn't immediately start
|
|
||||||
* the task, it binds the task to the async function's 'this' object and
|
|
||||||
* arguments, and it requires the task to be a function.
|
|
||||||
*
|
|
||||||
* It simplifies the common pattern of implementing a method via a task,
|
|
||||||
* like this simple object with a 'greet' method that has a 'name' parameter
|
|
||||||
* and spawns a task to send a greeting and return its reply:
|
|
||||||
*
|
|
||||||
* let greeter = {
|
|
||||||
* message: "Hello, NAME!",
|
|
||||||
* greet: function(name) {
|
|
||||||
* return Task.spawn((function* () {
|
|
||||||
* return yield sendGreeting(this.message.replace(/NAME/, name));
|
|
||||||
* }).bind(this);
|
|
||||||
* })
|
|
||||||
* };
|
|
||||||
*
|
|
||||||
* With Task.async, the method can be declared succinctly:
|
|
||||||
*
|
|
||||||
* let greeter = {
|
|
||||||
* message: "Hello, NAME!",
|
|
||||||
* greet: Task.async(function* (name) {
|
|
||||||
* return yield sendGreeting(this.message.replace(/NAME/, name));
|
|
||||||
* })
|
|
||||||
* };
|
|
||||||
*
|
|
||||||
* While maintaining identical semantics:
|
|
||||||
*
|
|
||||||
* greeter.greet("Mitchell").then((reply) => { ... }); // behaves the same
|
|
||||||
*
|
|
||||||
* @param aTask
|
|
||||||
* The task function to start.
|
|
||||||
*
|
|
||||||
* @return A function that starts the task function and returns its promise.
|
|
||||||
*/
|
|
||||||
async: function Task_async(aTask) {
|
|
||||||
if (typeof aTask != "function") {
|
|
||||||
throw new TypeError("aTask argument must be a function");
|
|
||||||
}
|
|
||||||
|
|
||||||
return createAsyncFunction(aTask);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a special exception that, when thrown inside a legacy generator
|
|
||||||
* function (non-star generator), allows the associated task to be resolved
|
|
||||||
* with a specific value.
|
|
||||||
*
|
|
||||||
* Example: throw new Task.Result("Value");
|
|
||||||
*/
|
|
||||||
Result: function Task_Result(aValue) {
|
|
||||||
this.value = aValue;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
function createAsyncFunction(aTask) {
|
|
||||||
let asyncFunction = function() {
|
|
||||||
let result = aTask;
|
|
||||||
if (aTask && typeof aTask == "function") {
|
|
||||||
if (aTask.isAsyncFunction) {
|
|
||||||
throw new TypeError(
|
|
||||||
"Cannot use an async function in place of a promise. " +
|
|
||||||
"You should either invoke the async function first " +
|
|
||||||
"or use 'Task.spawn' instead of 'Task.async' to start " +
|
|
||||||
"the Task and return its promise."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Let's call into the function ourselves.
|
|
||||||
result = aTask.apply(this, arguments);
|
|
||||||
} catch (ex) {
|
|
||||||
if (ex instanceof Task.Result) {
|
|
||||||
return Promise.resolve(ex.value);
|
|
||||||
}
|
|
||||||
return Promise.reject(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isGenerator(result)) {
|
|
||||||
// This is an iterator resulting from calling a generator function.
|
|
||||||
return new TaskImpl(result).promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just propagate the given value to the caller as a resolved promise.
|
|
||||||
return Promise.resolve(result);
|
|
||||||
};
|
|
||||||
|
|
||||||
asyncFunction.isAsyncFunction = true;
|
|
||||||
|
|
||||||
return asyncFunction;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TaskImpl
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the specified iterator as a task, and gives access to the promise
|
|
||||||
* that is fulfilled when the task terminates.
|
|
||||||
*/
|
|
||||||
function TaskImpl(iterator) {
|
|
||||||
if (gMaintainStack) {
|
|
||||||
this._stack = new Error().stack;
|
|
||||||
}
|
|
||||||
this.promise = new Promise((resolve, reject) => {
|
|
||||||
this._resolve = resolve;
|
|
||||||
this._reject = reject;
|
|
||||||
});
|
|
||||||
this._iterator = iterator;
|
|
||||||
this._isStarGenerator = !("send" in iterator);
|
|
||||||
this._run(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
TaskImpl.prototype = {
|
|
||||||
/**
|
|
||||||
* The promise object where task completion callbacks are registered.
|
|
||||||
*/
|
|
||||||
promise: null,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The method to resolve the promise at task completion.
|
|
||||||
*/
|
|
||||||
_resolve: null,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The method to reject the promise at task completion.
|
|
||||||
*/
|
|
||||||
_reject: null,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The iterator returned by the generator function associated with this task.
|
|
||||||
*/
|
|
||||||
_iterator: null,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether this Task is using a star generator.
|
|
||||||
*/
|
|
||||||
_isStarGenerator: false,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main execution routine, that calls into the generator function.
|
|
||||||
*
|
|
||||||
* @param aSendResolved
|
|
||||||
* If true, indicates that we should continue into the generator
|
|
||||||
* function regularly (if we were waiting on a promise, it was
|
|
||||||
* resolved). If false, indicates that we should cause an exception to
|
|
||||||
* be thrown into the generator function (if we were waiting on a
|
|
||||||
* promise, it was rejected).
|
|
||||||
* @param aSendValue
|
|
||||||
* Resolution result or rejection exception, if any.
|
|
||||||
*/
|
|
||||||
_run: function TaskImpl_run(aSendResolved, aSendValue) {
|
|
||||||
try {
|
|
||||||
gCurrentTask = this;
|
|
||||||
|
|
||||||
if (this._isStarGenerator) {
|
|
||||||
if (Cu.isDeadWrapper(this._iterator)) {
|
|
||||||
this._resolve(undefined);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
let result = aSendResolved
|
|
||||||
? this._iterator.next(aSendValue)
|
|
||||||
: this._iterator.throw(aSendValue);
|
|
||||||
|
|
||||||
if (result.done) {
|
|
||||||
// The generator function returned.
|
|
||||||
this._resolve(result.value);
|
|
||||||
} else {
|
|
||||||
// The generator function yielded.
|
|
||||||
this._handleResultValue(result.value);
|
|
||||||
}
|
|
||||||
} catch (ex) {
|
|
||||||
// The generator function failed with an uncaught exception.
|
|
||||||
this._handleException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
let yielded = aSendResolved
|
|
||||||
? this._iterator.send(aSendValue)
|
|
||||||
: this._iterator.throw(aSendValue);
|
|
||||||
this._handleResultValue(yielded);
|
|
||||||
} catch (ex) {
|
|
||||||
if (ex instanceof Task.Result) {
|
|
||||||
// The generator function threw the special exception that allows it to
|
|
||||||
// return a specific value on resolution.
|
|
||||||
this._resolve(ex.value);
|
|
||||||
} else if (ex instanceof StopIteration) {
|
|
||||||
// The generator function terminated with no specific result.
|
|
||||||
this._resolve(undefined);
|
|
||||||
} else {
|
|
||||||
// The generator function failed with an uncaught exception.
|
|
||||||
this._handleException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
//
|
|
||||||
// At this stage, the Task may have finished executing, or have
|
|
||||||
// walked through a `yield` or passed control to a sub-Task.
|
|
||||||
// Regardless, if we still own `gCurrentTask`, reset it. If we
|
|
||||||
// have not finished execution of this Task, re-entering `_run`
|
|
||||||
// will set `gCurrentTask` to `this` as needed.
|
|
||||||
//
|
|
||||||
// We just need to be careful here in case we hit the following
|
|
||||||
// pattern:
|
|
||||||
//
|
|
||||||
// Task.spawn(foo);
|
|
||||||
// Task.spawn(bar);
|
|
||||||
//
|
|
||||||
// Here, `foo` and `bar` may be interleaved, so when we finish
|
|
||||||
// executing `foo`, `gCurrentTask` may actually either `foo` or
|
|
||||||
// `bar`. If `gCurrentTask` has already been set to `bar`, leave
|
|
||||||
// it be and it will be reset to `null` once `bar` is complete.
|
|
||||||
//
|
|
||||||
if (gCurrentTask == this) {
|
|
||||||
gCurrentTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle a value yielded by a generator.
|
|
||||||
*
|
|
||||||
* @param aValue
|
|
||||||
* The yielded value to handle.
|
|
||||||
*/
|
|
||||||
_handleResultValue: function TaskImpl_handleResultValue(aValue) {
|
|
||||||
// If our task yielded an iterator resulting from calling another
|
|
||||||
// generator function, automatically spawn a task from it, effectively
|
|
||||||
// turning it into a promise that is fulfilled on task completion.
|
|
||||||
if (isGenerator(aValue)) {
|
|
||||||
aValue = Task.spawn(aValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aValue && typeof aValue.then == "function") {
|
|
||||||
// We have a promise object now. When fulfilled, call again into this
|
|
||||||
// function to continue the task, with either a resolution or rejection
|
|
||||||
// condition.
|
|
||||||
aValue.then(this._run.bind(this, true), this._run.bind(this, false));
|
|
||||||
} else {
|
|
||||||
// If our task yielded a value that is not a promise, just continue and
|
|
||||||
// pass it directly as the result of the yield statement.
|
|
||||||
this._run(true, aValue);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle an uncaught exception thrown from a generator.
|
|
||||||
*
|
|
||||||
* @param aException
|
|
||||||
* The uncaught exception to handle.
|
|
||||||
*/
|
|
||||||
_handleException: function TaskImpl_handleException(aException) {
|
|
||||||
gCurrentTask = this;
|
|
||||||
|
|
||||||
if (aException && typeof aException == "object" && "stack" in aException) {
|
|
||||||
let stack = aException.stack;
|
|
||||||
|
|
||||||
if (
|
|
||||||
gMaintainStack &&
|
|
||||||
aException._capturedTaskStack != this._stack &&
|
|
||||||
typeof stack == "string"
|
|
||||||
) {
|
|
||||||
// Rewrite the stack for more readability.
|
|
||||||
|
|
||||||
let bottomStack = this._stack;
|
|
||||||
|
|
||||||
stack = Task.Debugging.generateReadableStack(stack);
|
|
||||||
|
|
||||||
aException.stack = stack;
|
|
||||||
|
|
||||||
// If aException is reinjected in the same task and rethrown,
|
|
||||||
// we don't want to perform the rewrite again.
|
|
||||||
aException._capturedTaskStack = bottomStack;
|
|
||||||
} else if (!stack) {
|
|
||||||
stack = "Not available";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("name" in aException && ERRORS_TO_REPORT.includes(aException.name)) {
|
|
||||||
// We suspect that the exception is a programmer error, so we now
|
|
||||||
// display it using dump(). Note that we do not use Cu.reportError as
|
|
||||||
// we assume that this is a programming error, so we do not want end
|
|
||||||
// users to see it. Also, if the programmer handles errors correctly,
|
|
||||||
// they will either treat the error or log them somewhere.
|
|
||||||
|
|
||||||
dump("*************************\n");
|
|
||||||
dump("A coding exception was thrown and uncaught in a Task.\n\n");
|
|
||||||
dump("Full message: " + aException + "\n");
|
|
||||||
dump("Full stack: " + aException.stack + "\n");
|
|
||||||
dump("*************************\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._reject(aException);
|
|
||||||
},
|
|
||||||
|
|
||||||
get callerStack() {
|
|
||||||
// Cut `this._stack` at the last line of the first block that
|
|
||||||
// contains Task.jsm, keep the tail.
|
|
||||||
for (let [line, index] of linesOf(this._stack || "")) {
|
|
||||||
if (!line.includes("/Task.jsm:")) {
|
|
||||||
return this._stack.substring(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
Task.Debugging = {
|
|
||||||
/**
|
|
||||||
* Control stack rewriting.
|
|
||||||
*
|
|
||||||
* If `true`, any exception thrown from a Task will be rewritten to
|
|
||||||
* provide a human-readable stack trace. Otherwise, stack traces will
|
|
||||||
* be left unchanged.
|
|
||||||
*
|
|
||||||
* There is a (small but existing) runtime cost associated to stack
|
|
||||||
* rewriting, so you should probably not activate this in production
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
* @type {bool}
|
|
||||||
*/
|
|
||||||
get maintainStack() {
|
|
||||||
return gMaintainStack;
|
|
||||||
},
|
|
||||||
set maintainStack(x) {
|
|
||||||
if (!x) {
|
|
||||||
gCurrentTask = null;
|
|
||||||
}
|
|
||||||
gMaintainStack = x;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a human-readable stack for an error raised in
|
|
||||||
* a Task.
|
|
||||||
*
|
|
||||||
* @param {string} topStack The stack provided by the error.
|
|
||||||
* @param {string=} prefix Optionally, a prefix for each line.
|
|
||||||
*/
|
|
||||||
generateReadableStack(topStack, prefix = "") {
|
|
||||||
if (!gCurrentTask) {
|
|
||||||
return topStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cut `topStack` at the first line that contains Task.jsm, keep the head.
|
|
||||||
let lines = [];
|
|
||||||
for (let [line] of linesOf(topStack)) {
|
|
||||||
if (line.includes("/Task.jsm:")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
lines.push(prefix + line);
|
|
||||||
}
|
|
||||||
if (!prefix) {
|
|
||||||
lines.push(gCurrentTask.callerStack);
|
|
||||||
} else {
|
|
||||||
for (let [line] of linesOf(gCurrentTask.callerStack)) {
|
|
||||||
lines.push(prefix + line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lines.join("\n");
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { Promise } = ChromeUtils.import("resource://gre/modules/Promise.jsm");
|
const { Promise } = ChromeUtils.import("resource://gre/modules/Promise.jsm");
|
||||||
const { Task } = ChromeUtils.import("resource://testing-common/Task.jsm");
|
|
||||||
const { PromiseTestUtils } = ChromeUtils.import(
|
const { PromiseTestUtils } = ChromeUtils.import(
|
||||||
"resource://testing-common/PromiseTestUtils.jsm"
|
"resource://testing-common/PromiseTestUtils.jsm"
|
||||||
);
|
);
|
||||||
|
|
@ -589,19 +588,6 @@ tests.push(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test that Promise.resolve throws when its argument is an async function.
|
|
||||||
tests.push(
|
|
||||||
make_promise_test(function test_promise_resolve_throws_with_async_function(
|
|
||||||
test
|
|
||||||
) {
|
|
||||||
Assert.throws(
|
|
||||||
() => Promise.resolve(Task.async(function*() {})), // eslint-disable-line mozilla/no-task
|
|
||||||
/Cannot resolve a promise with an async function/
|
|
||||||
);
|
|
||||||
return Promise.resolve();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
// Test that the code after "then" is always executed before the callbacks
|
// Test that the code after "then" is always executed before the callbacks
|
||||||
tests.push(
|
tests.push(
|
||||||
make_promise_test(function then_returns_before_callbacks(test) {
|
make_promise_test(function then_returns_before_callbacks(test) {
|
||||||
|
|
|
||||||
|
|
@ -1,579 +0,0 @@
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This file tests the Task.jsm module.
|
|
||||||
*/
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// Globals
|
|
||||||
|
|
||||||
ChromeUtils.defineModuleGetter(this, "Task",
|
|
||||||
"resource://testing-common/Task.jsm");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a promise that will be resolved with the given value, when an event
|
|
||||||
* posted on the event loop of the main thread is processed.
|
|
||||||
*/
|
|
||||||
function promiseResolvedLater(aValue) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
Services.tm.dispatchToMainThread(() => resolve(aValue));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// Tests
|
|
||||||
|
|
||||||
function run_test()
|
|
||||||
{
|
|
||||||
run_next_test();
|
|
||||||
}
|
|
||||||
|
|
||||||
add_test(function test_spawn_primitive()
|
|
||||||
{
|
|
||||||
function fibonacci(n) {
|
|
||||||
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Polymorphism between task and non-task functions (see "test_recursion").
|
|
||||||
Task.spawn(fibonacci(6)).then(function (result) {
|
|
||||||
Assert.equal(8, result);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_spawn_function()
|
|
||||||
{
|
|
||||||
Task.spawn(function () {
|
|
||||||
return "This is not a generator.";
|
|
||||||
}).then(function (result) {
|
|
||||||
Assert.equal("This is not a generator.", result);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_spawn_function_this()
|
|
||||||
{
|
|
||||||
Task.spawn(function () {
|
|
||||||
return this;
|
|
||||||
}).then(function (result) {
|
|
||||||
// Since the task function wasn't defined in strict mode, its "this" object
|
|
||||||
// should be the same as the "this" object in this function, i.e. the global
|
|
||||||
// object.
|
|
||||||
Assert.equal(result, this);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_spawn_function_this_strict()
|
|
||||||
{
|
|
||||||
"use strict";
|
|
||||||
Task.spawn(function () {
|
|
||||||
return this;
|
|
||||||
}).then(function (result) {
|
|
||||||
// Since the task function was defined in strict mode, its "this" object
|
|
||||||
// should be undefined.
|
|
||||||
Assert.equal(typeof(result), "undefined");
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_spawn_function_returning_promise()
|
|
||||||
{
|
|
||||||
Task.spawn(function () {
|
|
||||||
return promiseResolvedLater("Resolution value.");
|
|
||||||
}).then(function (result) {
|
|
||||||
Assert.equal("Resolution value.", result);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_spawn_function_exceptions()
|
|
||||||
{
|
|
||||||
Task.spawn(function () {
|
|
||||||
throw new Error("Exception uncaught by task.");
|
|
||||||
}).then(function (result) {
|
|
||||||
do_throw("Unexpected success!");
|
|
||||||
}, function (ex) {
|
|
||||||
Assert.equal("Exception uncaught by task.", ex.message);
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_spawn_function_taskresult()
|
|
||||||
{
|
|
||||||
Task.spawn(function () {
|
|
||||||
throw new Task.Result("Task result");
|
|
||||||
}).then(function (result) {
|
|
||||||
Assert.equal("Task result", result);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_yielded_undefined()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
yield;
|
|
||||||
return "We continued correctly.";
|
|
||||||
}).then(function (result) {
|
|
||||||
Assert.equal("We continued correctly.", result);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_yielded_primitive()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
return "Primitive " + (yield "value.");
|
|
||||||
}).then(function (result) {
|
|
||||||
Assert.equal("Primitive value.", result);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_star_normal()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
let result = yield Promise.resolve("Value");
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
result += yield promiseResolvedLater("!");
|
|
||||||
}
|
|
||||||
return "Task result: " + result;
|
|
||||||
}).then(function (result) {
|
|
||||||
Assert.equal("Task result: Value!!!", result);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_star_exceptions()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
try {
|
|
||||||
yield Promise.reject("Rejection result by promise.");
|
|
||||||
do_throw("Exception expected because the promise was rejected.");
|
|
||||||
} catch (ex) {
|
|
||||||
// We catch this exception now, we will throw a different one later.
|
|
||||||
Assert.equal("Rejection result by promise.", ex);
|
|
||||||
}
|
|
||||||
throw new Error("Exception uncaught by task.");
|
|
||||||
}).then(function (result) {
|
|
||||||
do_throw("Unexpected success!");
|
|
||||||
}, function (ex) {
|
|
||||||
Assert.equal("Exception uncaught by task.", ex.message);
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_star_recursion()
|
|
||||||
{
|
|
||||||
function* task_fibonacci(n) {
|
|
||||||
return n < 2 ? n : (yield task_fibonacci(n - 1)) +
|
|
||||||
(yield task_fibonacci(n - 2));
|
|
||||||
};
|
|
||||||
|
|
||||||
Task.spawn(task_fibonacci(6)).then(function (result) {
|
|
||||||
Assert.equal(8, result);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_nested_star()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
return yield (function* () {
|
|
||||||
return yield 5;
|
|
||||||
})();
|
|
||||||
}).then(function (result) {
|
|
||||||
Assert.equal(5, result);
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_async_function_from_generator()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
let object = {
|
|
||||||
asyncFunction: Task.async(function* (param) {
|
|
||||||
Assert.equal(this, object);
|
|
||||||
return param;
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
// Ensure the async function returns a promise that resolves as expected.
|
|
||||||
Assert.equal((yield object.asyncFunction(1)), 1);
|
|
||||||
|
|
||||||
// Ensure a second call to the async function also returns such a promise.
|
|
||||||
Assert.equal((yield object.asyncFunction(3)), 3);
|
|
||||||
}).then(function () {
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_async_function_from_function()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
return Task.spawn(function* () {
|
|
||||||
let object = {
|
|
||||||
asyncFunction: Task.async(function (param) {
|
|
||||||
Assert.equal(this, object);
|
|
||||||
return param;
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
// Ensure the async function returns a promise that resolves as expected.
|
|
||||||
Assert.equal((yield object.asyncFunction(5)), 5);
|
|
||||||
|
|
||||||
// Ensure a second call to the async function also returns such a promise.
|
|
||||||
Assert.equal((yield object.asyncFunction(7)), 7);
|
|
||||||
});
|
|
||||||
}).then(function () {
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_async_function_that_throws_rejects_promise()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
let object = {
|
|
||||||
asyncFunction: Task.async(function* () {
|
|
||||||
throw "Rejected!";
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
yield object.asyncFunction();
|
|
||||||
}).then(function () {
|
|
||||||
do_throw("unexpected success calling async function that throws error");
|
|
||||||
}, function (ex) {
|
|
||||||
Assert.equal(ex, "Rejected!");
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_async_return_function()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
// Ensure an async function that returns a function resolves to the function
|
|
||||||
// itself instead of calling the function and resolving to its return value.
|
|
||||||
return Task.spawn(function* () {
|
|
||||||
let returnValue = function () {
|
|
||||||
return "These aren't the droids you're looking for.";
|
|
||||||
};
|
|
||||||
|
|
||||||
let asyncFunction = Task.async(function () {
|
|
||||||
return returnValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
Assert.equal((yield asyncFunction()), returnValue);
|
|
||||||
});
|
|
||||||
}).then(function () {
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_async_throw_argument_not_function()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
// Ensure Task.async throws if its aTask argument is not a function.
|
|
||||||
Assert.throws(() => Task.async("not a function"),
|
|
||||||
/aTask argument must be a function/);
|
|
||||||
}).then(function () {
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_async_throw_on_function_in_place_of_promise()
|
|
||||||
{
|
|
||||||
Task.spawn(function* () {
|
|
||||||
// Ensure Task.spawn throws if passed an async function.
|
|
||||||
Assert.throws(() => Task.spawn(Task.async(function* () {})),
|
|
||||||
/Cannot use an async function in place of a promise/);
|
|
||||||
}).then(function () {
|
|
||||||
run_next_test();
|
|
||||||
}, function (ex) {
|
|
||||||
do_throw("Unexpected error: " + ex);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
////////////////// Test rewriting of stack traces
|
|
||||||
|
|
||||||
// Backup Task.Debuggin.maintainStack.
|
|
||||||
// Will be restored by `exit_stack_tests`.
|
|
||||||
var maintainStack;
|
|
||||||
add_test(function enter_stack_tests() {
|
|
||||||
maintainStack = Task.Debugging.maintainStack;
|
|
||||||
Task.Debugging.maintainStack = true;
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure that a list of frames appear in a stack, in the right order
|
|
||||||
*/
|
|
||||||
function do_check_rewritten_stack(frames, ex) {
|
|
||||||
info("Checking that the expected frames appear in the right order");
|
|
||||||
info(frames.join(", "));
|
|
||||||
let stack = ex.stack;
|
|
||||||
info(stack);
|
|
||||||
|
|
||||||
let framesFound = 0;
|
|
||||||
let lineNumber = 0;
|
|
||||||
let reLine = /([^\r\n])+/g;
|
|
||||||
let match;
|
|
||||||
while (framesFound < frames.length && (match = reLine.exec(stack))) {
|
|
||||||
let line = match[0];
|
|
||||||
let frame = frames[framesFound];
|
|
||||||
info("Searching for " + frame + " in line " + line);
|
|
||||||
if (line.includes(frame)) {
|
|
||||||
info("Found " + frame);
|
|
||||||
++framesFound;
|
|
||||||
} else {
|
|
||||||
info("Didn't find " + frame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (framesFound >= frames.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
do_throw("Did not find: " + frames.slice(framesFound).join(", ") +
|
|
||||||
" in " + stack.substr(reLine.lastIndex));
|
|
||||||
|
|
||||||
info("Ensuring that we have removed Task.jsm, Promise.jsm");
|
|
||||||
Assert.ok(!stack.includes("Task.jsm"));
|
|
||||||
Assert.ok(!stack.includes("Promise.jsm"));
|
|
||||||
Assert.ok(!stack.includes("Promise-backend.js"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Test that we get an acceptable rewritten stack when we launch
|
|
||||||
// an error in a Task.spawn.
|
|
||||||
add_test(function test_spawn_throw_stack() {
|
|
||||||
Task.spawn(function* task_spawn_throw_stack() {
|
|
||||||
for (let i = 0; i < 5; ++i) {
|
|
||||||
yield Promise.resolve(); // Without stack rewrite, this would lose valuable information
|
|
||||||
}
|
|
||||||
throw new Error("BOOM");
|
|
||||||
}).then(do_throw, function(ex) {
|
|
||||||
do_check_rewritten_stack(["task_spawn_throw_stack",
|
|
||||||
"test_spawn_throw_stack"],
|
|
||||||
ex);
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test that we get an acceptable rewritten stack when we yield
|
|
||||||
// a rejection in a Task.spawn.
|
|
||||||
add_test(function test_spawn_yield_reject_stack() {
|
|
||||||
Task.spawn(function* task_spawn_yield_reject_stack() {
|
|
||||||
for (let i = 0; i < 5; ++i) {
|
|
||||||
yield Promise.resolve(); // Without stack rewrite, this would lose valuable information
|
|
||||||
}
|
|
||||||
yield Promise.reject(new Error("BOOM"));
|
|
||||||
}).then(do_throw, function(ex) {
|
|
||||||
do_check_rewritten_stack(["task_spawn_yield_reject_stack",
|
|
||||||
"test_spawn_yield_reject_stack"],
|
|
||||||
ex);
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test that we get an acceptable rewritten stack when we launch
|
|
||||||
// an error in a Task.async function.
|
|
||||||
add_test(function test_async_function_throw_stack() {
|
|
||||||
let task_async_function_throw_stack = Task.async(function*() {
|
|
||||||
for (let i = 0; i < 5; ++i) {
|
|
||||||
yield Promise.resolve(); // Without stack rewrite, this would lose valuable information
|
|
||||||
}
|
|
||||||
throw new Error("BOOM");
|
|
||||||
})().then(do_throw, function(ex) {
|
|
||||||
do_check_rewritten_stack(["task_async_function_throw_stack",
|
|
||||||
"test_async_function_throw_stack"],
|
|
||||||
ex);
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test that we get an acceptable rewritten stack when we launch
|
|
||||||
// an error in a Task.async function.
|
|
||||||
add_test(function test_async_function_yield_reject_stack() {
|
|
||||||
let task_async_function_yield_reject_stack = Task.async(function*() {
|
|
||||||
for (let i = 0; i < 5; ++i) {
|
|
||||||
yield Promise.resolve(); // Without stack rewrite, this would lose valuable information
|
|
||||||
}
|
|
||||||
yield Promise.reject(new Error("BOOM"));
|
|
||||||
})().then(do_throw, function(ex) {
|
|
||||||
do_check_rewritten_stack(["task_async_function_yield_reject_stack",
|
|
||||||
"test_async_function_yield_reject_stack"],
|
|
||||||
ex);
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test that we get an acceptable rewritten stack when we launch
|
|
||||||
// an error in a Task.async function.
|
|
||||||
add_test(function test_async_method_throw_stack() {
|
|
||||||
let object = {
|
|
||||||
task_async_method_throw_stack: Task.async(function*() {
|
|
||||||
for (let i = 0; i < 5; ++i) {
|
|
||||||
yield Promise.resolve(); // Without stack rewrite, this would lose valuable information
|
|
||||||
}
|
|
||||||
throw new Error("BOOM");
|
|
||||||
})
|
|
||||||
};
|
|
||||||
object.task_async_method_throw_stack().then(do_throw, function(ex) {
|
|
||||||
do_check_rewritten_stack(["task_async_method_throw_stack",
|
|
||||||
"test_async_method_throw_stack"],
|
|
||||||
ex);
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test that we get an acceptable rewritten stack when we launch
|
|
||||||
// an error in a Task.async function.
|
|
||||||
add_test(function test_async_method_yield_reject_stack() {
|
|
||||||
let object = {
|
|
||||||
task_async_method_yield_reject_stack: Task.async(function*() {
|
|
||||||
for (let i = 0; i < 5; ++i) {
|
|
||||||
yield Promise.resolve(); // Without stack rewrite, this would lose valuable information
|
|
||||||
}
|
|
||||||
yield Promise.reject(new Error("BOOM"));
|
|
||||||
})
|
|
||||||
};
|
|
||||||
object.task_async_method_yield_reject_stack().then(do_throw, function(ex) {
|
|
||||||
do_check_rewritten_stack(["task_async_method_yield_reject_stack",
|
|
||||||
"test_async_method_yield_reject_stack"],
|
|
||||||
ex);
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test that two tasks whose execution takes place interleaved do not capture each other's stack.
|
|
||||||
add_test(function test_throw_stack_do_not_capture_the_wrong_task() {
|
|
||||||
for (let iter_a of [3, 4, 5]) { // Vary the interleaving
|
|
||||||
for (let iter_b of [3, 4, 5]) {
|
|
||||||
Task.spawn(function* task_a() {
|
|
||||||
for (let i = 0; i < iter_a; ++i) {
|
|
||||||
yield Promise.resolve();
|
|
||||||
}
|
|
||||||
throw new Error("BOOM");
|
|
||||||
}).then(do_throw, function(ex) {
|
|
||||||
do_check_rewritten_stack(["task_a",
|
|
||||||
"test_throw_stack_do_not_capture_the_wrong_task"],
|
|
||||||
ex);
|
|
||||||
Assert.ok(!ex.stack.includes("task_b"));
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
Task.spawn(function* task_b() {
|
|
||||||
for (let i = 0; i < iter_b; ++i) {
|
|
||||||
yield Promise.resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Put things together
|
|
||||||
add_test(function test_throw_complex_stack()
|
|
||||||
{
|
|
||||||
// Setup the following stack:
|
|
||||||
// inner_method()
|
|
||||||
// task_3()
|
|
||||||
// task_2()
|
|
||||||
// task_1()
|
|
||||||
// function_3()
|
|
||||||
// function_2()
|
|
||||||
// function_1()
|
|
||||||
// test_throw_complex_stack()
|
|
||||||
(function function_1() {
|
|
||||||
return (function function_2() {
|
|
||||||
return (function function_3() {
|
|
||||||
return Task.spawn(function* task_1() {
|
|
||||||
yield Promise.resolve();
|
|
||||||
try {
|
|
||||||
yield Task.spawn(function* task_2() {
|
|
||||||
yield Promise.resolve();
|
|
||||||
yield Task.spawn(function* task_3() {
|
|
||||||
yield Promise.resolve();
|
|
||||||
let inner_object = {
|
|
||||||
inner_method: Task.async(function*() {
|
|
||||||
throw new Error("BOOM");
|
|
||||||
})
|
|
||||||
};
|
|
||||||
yield Promise.resolve();
|
|
||||||
yield inner_object.inner_method();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (ex) {
|
|
||||||
yield Promise.resolve();
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
})().then(
|
|
||||||
() => do_throw("Shouldn't have succeeded"),
|
|
||||||
(ex) => {
|
|
||||||
let expect = ["inner_method",
|
|
||||||
"task_3",
|
|
||||||
"task_2",
|
|
||||||
"task_1",
|
|
||||||
"function_3",
|
|
||||||
"function_2",
|
|
||||||
"function_1",
|
|
||||||
"test_throw_complex_stack"];
|
|
||||||
do_check_rewritten_stack(expect, ex);
|
|
||||||
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function test_without_maintainStack() {
|
|
||||||
info("Calling generateReadableStack without a Task");
|
|
||||||
Task.Debugging.generateReadableStack(new Error("Not a real error"));
|
|
||||||
|
|
||||||
Task.Debugging.maintainStack = false;
|
|
||||||
|
|
||||||
info("Calling generateReadableStack with neither a Task nor maintainStack");
|
|
||||||
Task.Debugging.generateReadableStack(new Error("Not a real error"));
|
|
||||||
|
|
||||||
info("Calling generateReadableStack without maintainStack");
|
|
||||||
Task.spawn(function*() {
|
|
||||||
Task.Debugging.generateReadableStack(new Error("Not a real error"));
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
add_test(function exit_stack_tests() {
|
|
||||||
Task.Debugging.maintainStack = maintainStack;
|
|
||||||
run_next_test();
|
|
||||||
});
|
|
||||||
|
|
@ -50,7 +50,6 @@ skip-if = os != 'mac'
|
||||||
[test_sqlite.js]
|
[test_sqlite.js]
|
||||||
skip-if = toolkit == 'android' || (verify && !debug && os == 'win')
|
skip-if = toolkit == 'android' || (verify && !debug && os == 'win')
|
||||||
[test_sqlite_shutdown.js]
|
[test_sqlite_shutdown.js]
|
||||||
[test_task.js]
|
|
||||||
[test_timer.js]
|
[test_timer.js]
|
||||||
[test_UpdateUtils_url.js]
|
[test_UpdateUtils_url.js]
|
||||||
skip-if = !updater
|
skip-if = !updater
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ module.exports = {
|
||||||
"no-arbitrary-setTimeout": require("../lib/rules/no-arbitrary-setTimeout"),
|
"no-arbitrary-setTimeout": require("../lib/rules/no-arbitrary-setTimeout"),
|
||||||
"no-compare-against-boolean-literals": require("../lib/rules/no-compare-against-boolean-literals"),
|
"no-compare-against-boolean-literals": require("../lib/rules/no-compare-against-boolean-literals"),
|
||||||
"no-define-cc-etc": require("../lib/rules/no-define-cc-etc"),
|
"no-define-cc-etc": require("../lib/rules/no-define-cc-etc"),
|
||||||
"no-task": require("../lib/rules/no-task"),
|
|
||||||
"no-throw-cr-literal": require("../lib/rules/no-throw-cr-literal"),
|
"no-throw-cr-literal": require("../lib/rules/no-throw-cr-literal"),
|
||||||
"no-useless-parameters": require("../lib/rules/no-useless-parameters"),
|
"no-useless-parameters": require("../lib/rules/no-useless-parameters"),
|
||||||
"no-useless-removeEventListener": require("../lib/rules/no-useless-removeEventListener"),
|
"no-useless-removeEventListener": require("../lib/rules/no-useless-removeEventListener"),
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
/**
|
|
||||||
* @fileoverview Reject common XPCOM methods called with useless optional
|
|
||||||
* parameters, or non-existent parameters.
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Rule Definition
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
module.exports = function(context) {
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Public
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
return {
|
|
||||||
CallExpression(node) {
|
|
||||||
let callee = node.callee;
|
|
||||||
if (
|
|
||||||
callee.type === "MemberExpression" &&
|
|
||||||
callee.object.type === "Identifier" &&
|
|
||||||
callee.object.name === "Task"
|
|
||||||
) {
|
|
||||||
context.report({ node, message: "Task.jsm is deprecated." });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Loading…
Reference in a new issue