aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIgor Minar2013-10-11 16:46:32 -0700
committerIgor Minar2013-10-11 17:12:24 -0700
commit4357da857587d3c28790e7dc654664bec5808768 (patch)
tree37a89d65b6a03562b587483a2c9209200fef7c95 /src
parent83fbaa54f13ff94d193115de0eaa3799739af3a5 (diff)
downloadangular.js-4357da857587d3c28790e7dc654664bec5808768.tar.bz2
fix($compile): make order directives w/ same priority deterministic
Array.prototype.sort is speced out to be as potentionally unstable sort, which is how it's implemented in FF and IE. This has caused the order of directives with the same priority to vary between browsers. For consistency sake, we now consider directive name and registration, order when determining the order of directives with the same priority. Note: it is still possible to get into a situation when the directive order is underministic - when source files are loaded asynchronously in non-deterministic order and there are are directives registered with the same name and priority, the order in which they will be applied will depend on the file load order.
Diffstat (limited to 'src')
-rw-r--r--src/ng/compile.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index ff0ae99d..a13be3b8 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -186,7 +186,7 @@ function $CompileProvider($provide) {
$provide.factory(name + Suffix, ['$injector', '$exceptionHandler',
function($injector, $exceptionHandler) {
var directives = [];
- forEach(hasDirectives[name], function(directiveFactory) {
+ forEach(hasDirectives[name], function(directiveFactory, index) {
try {
var directive = $injector.invoke(directiveFactory);
if (isFunction(directive)) {
@@ -195,6 +195,7 @@ function $CompileProvider($provide) {
directive.compile = valueFn(directive.link);
}
directive.priority = directive.priority || 0;
+ directive.index = index;
directive.name = directive.name || name;
directive.require = directive.require || (directive.controller && directive.name);
directive.restrict = directive.restrict || 'A';
@@ -1277,7 +1278,10 @@ function $CompileProvider($provide) {
* Sorting function for bound directives.
*/
function byPriority(a, b) {
- return b.priority - a.priority;
+ var diff = b.priority - a.priority;
+ if (diff !== 0) return diff;
+ if (a.name !== b.name) return (a.name < b.name) ? -1 : 1;
+ return a.index - b.index;
}