mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-26 19:20:24 +00:00
the flag must be in all src and test files so that we get the benefit of running in the strict mode even in jstd the following script was used to modify all files: for file in `find src test -name "*.js"`; do echo -e "'use strict';\n" > temp.txt cat $file >> temp.txt mv temp.txt $file done
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* A future action in a spec.
|
|
*
|
|
* @param {string} name of the future action
|
|
* @param {Function} future callback(error, result)
|
|
* @param {Function} Optional. function that returns the file/line number.
|
|
*/
|
|
angular.scenario.Future = function(name, behavior, line) {
|
|
this.name = name;
|
|
this.behavior = behavior;
|
|
this.fulfilled = false;
|
|
this.value = undefined;
|
|
this.parser = angular.identity;
|
|
this.line = line || function() { return ''; };
|
|
};
|
|
|
|
/**
|
|
* Executes the behavior of the closure.
|
|
*
|
|
* @param {Function} doneFn Callback function(error, result)
|
|
*/
|
|
angular.scenario.Future.prototype.execute = function(doneFn) {
|
|
var self = this;
|
|
this.behavior(function(error, result) {
|
|
self.fulfilled = true;
|
|
if (result) {
|
|
try {
|
|
result = self.parser(result);
|
|
} catch(e) {
|
|
error = e;
|
|
}
|
|
}
|
|
self.value = error || result;
|
|
doneFn(error, result);
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Configures the future to convert it's final with a function fn(value)
|
|
*
|
|
* @param {Function} fn function(value) that returns the parsed value
|
|
*/
|
|
angular.scenario.Future.prototype.parsedWith = function(fn) {
|
|
this.parser = fn;
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Configures the future to parse it's final value from JSON
|
|
* into objects.
|
|
*/
|
|
angular.scenario.Future.prototype.fromJson = function() {
|
|
return this.parsedWith(angular.fromJson);
|
|
};
|
|
|
|
/**
|
|
* Configures the future to convert it's final value from objects
|
|
* into JSON.
|
|
*/
|
|
angular.scenario.Future.prototype.toJson = function() {
|
|
return this.parsedWith(angular.toJson);
|
|
};
|