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AI,EAAC,cAAa,AAAC,CAAC,CAAA,MAAM,CAAC,CAAC,CAAC;AAErC,YAAO,IAAG,GAAK,CAAA,IAAG,uBAAuB,CAAG;AAC1C,YAAI,KAAK,AAAC,CAAC,IAAG,uBAAuB,IAAI,AAAC,EAAC,CAAC,CAAC;AAC7C,WAAG,EAAI,CAAA,IAAG,OAAO,CAAC;MACpB;AAAA,AACA,SAAG,gBAAgB,AAAC,CAAC,CAAA,CAAG,MAAI,CAAC,CAAC;IAChC,KAAO;AACL,UAAM,EAAA,CAAC;IACT;AAAA,EACF;AAAA,AACF;AAAA","file":"angular2/src/core/zone/vm_turn_zone.es6","sourcesContent":["import {List, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';\nimport {normalizeBlank, isPresent, global} from 'angular2/src/facade/lang';\n\n/**\n * A wrapper around zones that lets you schedule tasks after it has executed a task.\n *\n * The wrapper maintains an \"inner\" and \"outer\" `Zone`. The application code will executes\n * in the \"inner\" zone unless `runOutsideAngular` is explicitely called.\n *\n * A typical application will create a singleton `VmTurnZone` whose outer `Zone` is the root `Zone`\n * and whose default `onTurnDone` runs the Angular digest.\n *\n * @exportedAs angular2/core\n */\nexport class VmTurnZone {\n _outerZone;\n _innerZone;\n\n _onTurnStart:Function;\n _onTurnDone:Function;\n _onErrorHandler:Function;\n\n _nestedRunCounter:number;\n\n /**\n * Associates with this\n *\n * - an \"outer\" zone, which is the one that created this.\n * - an \"inner\" zone, which is a child of the outer zone.\n *\n * @param {bool} enableLongStackTrace whether to enable long stack trace. They should only be\n * enabled in development mode as they significantly impact perf.\n */\n constructor({enableLongStackTrace}) {\n this._nestedRunCounter = 0;\n this._onTurnStart = null;\n this._onTurnDone = null;\n this._onErrorHandler = null;\n\n this._outerZone = global.zone;\n this._innerZone = this._createInnerZone(this._outerZone, enableLongStackTrace);\n }\n\n /**\n * Initializes the zone hooks.\n *\n * @param {Function} onTurnStart called before code executes in the inner zone for each VM turn\n * @param {Function} onTurnDone called at the end of a VM turn if code has executed in the inner zone\n * @param {Function} onScheduleMicrotask\n * @param {Function} onErrorHandler called when an exception is thrown by a macro or micro task\n */\n initCallbacks({onTurnStart, onTurnDone, onScheduleMicrotask, onErrorHandler} = {}) {\n this._onTurnStart = normalizeBlank(onTurnStart);\n this._onTurnDone = normalizeBlank(onTurnDone);\n this._onErrorHandler = normalizeBlank(onErrorHandler);\n }\n\n /**\n * Runs `fn` in the inner zone and returns whatever it returns.\n *\n * In a typical app where the inner zone is the Angular zone, this allows one to make use of the\n * Angular's auto digest mechanism.\n *\n * ```\n * var zone: VmTurnZone = <ref to the application zone>;\n *\n * zone.run(() => {\n * // auto-digest will run after this function is called from JS\n * });\n * ```\n */\n run(fn) {\n return this._innerZone.run(fn);\n }\n\n /**\n * Runs `fn` in the outer zone and returns whatever it returns.\n *\n * In a typical app where the inner zone is the Angular zone, this allows one to escape Angular's\n * auto-digest mechanism.\n *\n * ```\n * var zone: VmTurnZone = <ref to the application zone>;\n *\n * zone.runOusideAngular(() => {\n * element.onClick(() => {\n * // Clicking on the element would not trigger the change detection\n * });\n * });\n * ```\n */\n runOutsideAngular(fn) {\n return this._outerZone.run(fn);\n }\n\n _createInnerZone(zone, enableLongStackTrace) {\n var vmTurnZone = this;\n var errorHandling;\n\n if (enableLongStackTrace) {\n errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone, {\n onError: function (e) {\n vmTurnZone._onError(this, e)\n }\n });\n } else {\n errorHandling = {\n onError: function (e) {\n vmTurnZone._onError(this, e)\n }\n };\n }\n\n return zone.fork(errorHandling).fork({\n beforeTask: () => {this._beforeTask()},\n afterTask: () => {this._afterTask()}\n });\n }\n\n _beforeTask(){\n this._nestedRunCounter ++;\n if(this._nestedRunCounter === 1 && this._onTurnStart) {\n this._onTurnStart();\n }\n }\n\n _afterTask(){\n this._nestedRunCounter --;\n if(this._nestedRunCounter === 0 && this._onTurnDone) {\n this._onTurnDone();\n }\n }\n\n _onError(zone, e) {\n if (isPresent(this._onErrorHandler)) {\n var trace = [normalizeBlank(e.stack)];\n\n while (zone && zone.constructedAtException) {\n trace.push(zone.constructedAtException.get());\n zone = zone.parent;\n }\n this._onErrorHandler(e, trace);\n } else {\n throw e;\n }\n }\n}\n"]}