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

Function Browser

test/angular/1.2/angular.js:4389–4761  ·  view source on GitHub ↗

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

(window, document, $log, $sniffer)

Source from the content-addressed store, hash-verified

4387 * @param {object} $sniffer $sniffer service
4388 */
4389function Browser(window, document, $log, $sniffer) {
4390 var self = this,
4391 rawDocument = document[0],
4392 location = window.location,
4393 history = window.history,
4394 setTimeout = window.setTimeout,
4395 clearTimeout = window.clearTimeout,
4396 pendingDeferIds = {};
4397
4398 self.isMock = false;
4399
4400 var outstandingRequestCount = 0;
4401 var outstandingRequestCallbacks = [];
4402
4403 // TODO(vojta): remove this temporary api
4404 self.$$completeOutstandingRequest = completeOutstandingRequest;
4405 self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; };
4406
4407 /**
4408 * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks`
4409 * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed.
4410 */
4411 function completeOutstandingRequest(fn) {
4412 try {
4413 fn.apply(null, sliceArgs(arguments, 1));
4414 } finally {
4415 outstandingRequestCount--;
4416 if (outstandingRequestCount === 0) {
4417 while(outstandingRequestCallbacks.length) {
4418 try {
4419 outstandingRequestCallbacks.pop()();
4420 } catch (e) {
4421 $log.error(e);
4422 }
4423 }
4424 }
4425 }
4426 }
4427
4428 function getHash(url) {
4429 var index = url.indexOf('#');
4430 return index === -1 ? '' : url.substr(index + 1);
4431 }
4432
4433 /**
4434 * @private
4435 * Note: this method is used only by scenario runner
4436 * TODO(vojta): prefix this method with $$ ?
4437 * @param {function()} callback Function that will be called when no outstanding request
4438 */
4439 self.notifyWhenNoOutstandingRequests = function(callback) {
4440 // force browser to execute all pollFns - this is needed so that cookies and other pollers fire
4441 // at some deterministic time in respect to the test runner's actions. Leaving things up to the
4442 // regular poller would result in flaky tests.
4443 forEach(pollFns, function(pollFn){ pollFn(); });
4444
4445 if (outstandingRequestCount === 0) {
4446 callback();

Callers

nothing calls this directly

Calls 10

baseHrefMethod · 0.80
forEachFunction · 0.70
callbackFunction · 0.70
isUndefinedFunction · 0.70
startPollerFunction · 0.70
stripHashFunction · 0.70
getHashFunction · 0.70
isStringFunction · 0.70
escapeFunction · 0.50

Tested by

no test coverage detected