MCPcopy
hub / github.com/angular-ui/ui-router / Browser

Function Browser

test/angular/1.3/angular.js:4916–5355  ·  view source on GitHub ↗

* @param {object} window The global window object. * @param {object} document jQuery wrapped document. * @param {object} $log window.console or an object with the same interface. * @param {object} $sniffer $sniffer service

(window, document, $log, $sniffer)

Source from the content-addressed store, hash-verified

4914 * @param {object} $sniffer $sniffer service
4915 */
4916function Browser(window, document, $log, $sniffer) {
4917 var self = this,
4918 rawDocument = document[0],
4919 location = window.location,
4920 history = window.history,
4921 setTimeout = window.setTimeout,
4922 clearTimeout = window.clearTimeout,
4923 pendingDeferIds = {};
4924
4925 self.isMock = false;
4926
4927 var outstandingRequestCount = 0;
4928 var outstandingRequestCallbacks = [];
4929
4930 // TODO(vojta): remove this temporary api
4931 self.$$completeOutstandingRequest = completeOutstandingRequest;
4932 self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; };
4933
4934 /**
4935 * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks`
4936 * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed.
4937 */
4938 function completeOutstandingRequest(fn) {
4939 try {
4940 fn.apply(null, sliceArgs(arguments, 1));
4941 } finally {
4942 outstandingRequestCount--;
4943 if (outstandingRequestCount === 0) {
4944 while (outstandingRequestCallbacks.length) {
4945 try {
4946 outstandingRequestCallbacks.pop()();
4947 } catch (e) {
4948 $log.error(e);
4949 }
4950 }
4951 }
4952 }
4953 }
4954
4955 function getHash(url) {
4956 var index = url.indexOf('#');
4957 return index === -1 ? '' : url.substr(index);
4958 }
4959
4960 /**
4961 * @private
4962 * Note: this method is used only by scenario runner
4963 * TODO(vojta): prefix this method with $$ ?
4964 * @param {function()} callback Function that will be called when no outstanding request
4965 */
4966 self.notifyWhenNoOutstandingRequests = function(callback) {
4967 // force browser to execute all pollFns - this is needed so that cookies and other pollers fire
4968 // at some deterministic time in respect to the test runner's actions. Leaving things up to the
4969 // regular poller would result in flaky tests.
4970 forEach(pollFns, function(pollFn) { pollFn(); });
4971
4972 if (outstandingRequestCount === 0) {
4973 callback();

Callers

nothing calls this directly

Calls 11

baseHrefMethod · 0.80
forEachFunction · 0.70
callbackFunction · 0.70
isUndefinedFunction · 0.70
startPollerFunction · 0.70
cacheStateFunction · 0.70
stripHashFunction · 0.70
getHashFunction · 0.70
isStringFunction · 0.70
safeDecodeURIComponentFunction · 0.70

Tested by

no test coverage detected