function _wrapPromiseInstanceThen(promiseInstance) {
			var fnOriginalThen = promiseInstance.then;

			promiseInstance.then = function wrappedThen(fnOriginalResolvedCallback,fnOriginalRejectedCallback) {

				var wrappedThenCallback = fnOriginalResolvedCallback;
				if (fnOriginalResolvedCallback) {
					var wrappedThenCallback = function wrappedThenCallback() {
						// save current promise in a global var so that everyonme down the call stack in the current microtask can use it
						thenMicrotaskPromise = mPendingPromise;
						var fnOriginalThenCallbackResult = fnOriginalResolvedCallback.apply(this,arguments);
						thenMicrotaskPromise = undefined;
						return fnOriginalThenCallbackResult;
					};
				}

				var fnOriginalThenResult = fnOriginalThen.apply(this,[wrappedThenCallback,fnOriginalRejectedCallback]);

				// thenResult is a naitive promise and we need to override the .then() method again to cover the promise chaining scenario
				//return _wrapPromiseInstanceThen(fnOriginalThenResult);
				return fnOriginalThenResult;
			};

			return promiseInstance;
		}
// override .then() method of the promise instance so we can track
override .then() method of the promise instance so we can track
override . then () method of the promise instance so we can track
function _wrapPromiseInstanceThen(promiseInstance) {
			var fnOriginalThen = promiseInstance.then;
			promiseInstance.then = function wrappedThen(fnOriginalResolvedCallback,fnOriginalRejectedCallback) {
				var wrappedThenCallback = fnOriginalResolvedCallback;
				if (fnOriginalResolvedCallback) {
					var wrappedThenCallback = function wrappedThenCallback() {
						thenMicrotaskPromise = mPendingPromise;
						var fnOriginalThenCallbackResult = fnOriginalResolvedCallback.apply(this,arguments);
						thenMicrotaskPromise = undefined;
						return fnOriginalThenCallbackResult;
					};
				}
				var fnOriginalThenResult = fnOriginalThen.apply(this,[wrappedThenCallback,fnOriginalRejectedCallback]);
				return fnOriginalThenResult;
			};
			return promiseInstance;
		}
function _wrapPromiseInstanceThen ( promiseInstance ) { var fnOriginalThen = promiseInstance . then ; promiseInstance . then = function wrappedThen ( fnOriginalResolvedCallback , fnOriginalRejectedCallback ) { var wrappedThenCallback = fnOriginalResolvedCallback ; if ( fnOriginalResolvedCallback ) { var wrappedThenCallback = function wrappedThenCallback ( ) { thenMicrotaskPromise = mPendingPromise ; var fnOriginalThenCallbackResult = fnOriginalResolvedCallback . apply ( this , arguments ) ; thenMicrotaskPromise = undefined ; return fnOriginalThenCallbackResult ; } ; } var fnOriginalThenResult = fnOriginalThen . apply ( this , [ wrappedThenCallback , fnOriginalRejectedCallback ] ) ; return fnOriginalThenResult ; } ; return promiseInstance ; }
override .then() method of the promise instance so we can track
override . then () method of the promise instance so we can track
// save current promise in a global var so that everyonme down the call stack in the current microtask can use it // thenResult is a naitive promise and we need to override the .then() method again to cover the promise chaining scenario //return _wrapPromiseInstanceThen(fnOriginalThenResult);