Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
126
gaia/dev_apps/test-agent/common/test/mocha_task.js
Executable file
126
gaia/dev_apps/test-agent/common/test/mocha_task.js
Executable file
|
|
@ -0,0 +1,126 @@
|
|||
/**
|
||||
* MochaTask manager.
|
||||
* Used to provide generator yields for mocha test.
|
||||
*/
|
||||
var MochaTask = (function() {
|
||||
var current, done, errorHandler;
|
||||
|
||||
function clearState() {
|
||||
done = null;
|
||||
current = null;
|
||||
errorHandler = null;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
/**
|
||||
* Starts a task this will
|
||||
* effect the global state of MochaTask.
|
||||
*
|
||||
*
|
||||
* @param {Function} generator generator function.
|
||||
* @param {Function} success success callback.
|
||||
* @param {Function} error error callback receives an Error instance.
|
||||
*/
|
||||
start: function(generator, success, error) {
|
||||
current = generator;
|
||||
if (!current.next) {
|
||||
current = generator.call(this);
|
||||
}
|
||||
|
||||
done = success;
|
||||
errorHandler = error;
|
||||
|
||||
if (current && current.next) {
|
||||
current.next();
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sends next value to the generator.
|
||||
* Function may be passed to functions
|
||||
* that normally require a callback.
|
||||
*
|
||||
* yield setTimeout(100, MochaTask.next)
|
||||
*
|
||||
* If next is called with a value it will be passed
|
||||
* to the generators send method so you can use it to
|
||||
* create this kind of code.
|
||||
*
|
||||
* var responseText = yield magicXhrMethod('GET', url, Mocha.next);
|
||||
*
|
||||
* @param {Object} value object to pass to generator.
|
||||
*/
|
||||
next: function(value) {
|
||||
//assign references so we
|
||||
//can clear state without messing
|
||||
//up execution order later.
|
||||
var complete = done,
|
||||
generator = current,
|
||||
handler = errorHandler;
|
||||
|
||||
try {
|
||||
generator.send(value);
|
||||
} catch (e) {
|
||||
if (e instanceof StopIteration) {
|
||||
clearState();
|
||||
|
||||
if (complete) {
|
||||
complete();
|
||||
}
|
||||
} else {
|
||||
clearState();
|
||||
|
||||
if (handler) {
|
||||
handler(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
nextNodeStyle: function(error, value) {
|
||||
//assign references so we
|
||||
//can clear state without messing
|
||||
//up execution order later.
|
||||
var complete = done,
|
||||
generator = current,
|
||||
handler = errorHandler;
|
||||
|
||||
if (error) {
|
||||
try {
|
||||
generator.throw(error);
|
||||
} catch (e) {
|
||||
if (!(e instanceof StopIteration)) {
|
||||
handler(e);
|
||||
} else {
|
||||
clearState();
|
||||
if (complete) {
|
||||
complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
generator.send(value);
|
||||
} catch (e) {
|
||||
if (e instanceof StopIteration) {
|
||||
clearState();
|
||||
if (complete) {
|
||||
complete();
|
||||
}
|
||||
} else {
|
||||
clearState();
|
||||
if (handler) {
|
||||
handler(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}());
|
||||
Loading…
Reference in a new issue