fixed race condition in instrumentation; issue #1

test-unit-sauce
Brian Ford 12 years ago
parent 5839e3651c
commit 641d70e2f5

@ -1,16 +1,6 @@
var inject = function () {
if (document.cookie.indexOf('__ngDebug=true') == -1) {
return;
}
if (document.head) {
document.head.insertBefore(
(function () {
document.head.appendChild((function () {
var fn = function (window) {
//alert('script');
var patch = function () {
if (window.angular && typeof window.angular.bootstrap === 'function') {
// do not patch twice
if (window.__ngDebug) {
return;
@ -25,9 +15,21 @@ var inject = function () {
var ng = angular.module('ng');
ng.config(function ($provide) {
$provide.decorator('$rootScope',
// patch $injector
// ---------------
/*
$provide.decorator('$injector',
function ($delegate) {
console.log($delegate);
var get = $delegate.__proto__.get;
$delegate.__proto__.get = function () {
return get.apply(this, arguments);
};
return $delegate;
});
*/
$provide.decorator('$rootScope', function ($delegate) {
var watchFnToHumanReadableString = function (fn) {
if (fn.exp) {
return fn.exp.trim();
@ -156,27 +158,17 @@ var inject = function () {
return $delegate;
});
});
} else {
setTimeout(patch, 1);
}
};
patch();
};
var script = window.document.createElement('script');
script.innerHTML = '(' + fn.toString() + '(window))';
return script;
}()),
document.head.firstChild);
} else {
setTimeout(inject, 1);
}
}()));
};
inject();
// only inject if cookie is set
if (document.cookie.indexOf('__ngDebug=true') != -1) {
document.addEventListener('DOMContentLoaded', inject);
}