refactor(core): move callAndReportToErrorHandler to bootstrap file (#59793)

This function is only used in the bootstrap file and does not need to be in application_ref

PR Close #59793
This commit is contained in:
Andrew Scott
2025-01-29 14:55:44 -08:00
committed by Alex Rickabaugh
parent 3f6ccfc173
commit cde83e99bc
4 changed files with 27 additions and 31 deletions
@@ -41,7 +41,6 @@ import {publishDefaultGlobalUtils as _publishDefaultGlobalUtils} from '../render
import {requiresRefreshOrTraversal} from '../render3/util/view_utils';
import {ViewRef as InternalViewRef} from '../render3/view_ref';
import {TESTABILITY} from '../testability/testability';
import {isPromise} from '../util/lang';
import {NgZone} from '../zone/ng_zone';
import {ApplicationInitStatus} from './application_init';
@@ -176,29 +175,6 @@ export interface BootstrapOptions {
/** Maximum number of times ApplicationRef will refresh all attached views in a single tick. */
const MAXIMUM_REFRESH_RERUNS = 10;
export function _callAndReportToErrorHandler(
errorHandler: ErrorHandler,
ngZone: NgZone,
callback: () => any,
): any {
try {
const result = callback();
if (isPromise(result)) {
return result.catch((e: any) => {
ngZone.runOutsideAngular(() => errorHandler.handleError(e));
// rethrow as the exception handler might not do it
throw e;
});
}
return result;
} catch (e) {
ngZone.runOutsideAngular(() => errorHandler.handleError(e));
// rethrow as the exception handler might not do it
throw e;
}
}
export function optionsReducer<T extends Object>(dst: T, objs: T | T[]): T {
if (Array.isArray(objs)) {
return objs.reduce(optionsReducer, dst);
@@ -15,7 +15,7 @@ import {assertStandaloneComponentType} from '../render3/errors';
import {EnvironmentNgModuleRefAdapter} from '../render3/ng_module_ref';
import {NgZone} from '../zone/ng_zone';
import {_callAndReportToErrorHandler, ApplicationRef} from './application_ref';
import {ApplicationRef} from './application_ref';
import {ChangeDetectionScheduler} from '../change_detection/scheduling/zoneless_scheduling';
import {ChangeDetectionSchedulerImpl} from '../change_detection/scheduling/zoneless_scheduling_impl';
import {bootstrap} from '../platform/bootstrap';
+25 -1
View File
@@ -20,11 +20,12 @@ import {setLocaleId} from '../render3/i18n/i18n_locale_id';
import {NgZone} from '../zone/ng_zone';
import {ApplicationInitStatus} from '../application/application_init';
import {_callAndReportToErrorHandler, ApplicationRef, remove} from '../application/application_ref';
import {ApplicationRef, remove} from '../application/application_ref';
import {PROVIDED_ZONELESS} from '../change_detection/scheduling/zoneless_scheduling';
import {InjectionToken, Injector} from '../di';
import {InternalNgModuleRef, NgModuleRef} from '../linker/ng_module_factory';
import {stringify} from '../util/stringify';
import {isPromise} from '../util/lang';
/**
* InjectionToken to control root component bootstrap behavior.
@@ -200,3 +201,26 @@ function moduleDoBootstrap(
}
allPlatformModules.push(moduleRef);
}
function _callAndReportToErrorHandler(
errorHandler: ErrorHandler,
ngZone: NgZone,
callback: () => any,
): any {
try {
const result = callback();
if (isPromise(result)) {
return result.catch((e: any) => {
ngZone.runOutsideAngular(() => errorHandler.handleError(e));
// rethrow as the exception handler might not do it
throw e;
});
}
return result;
} catch (e) {
ngZone.runOutsideAngular(() => errorHandler.handleError(e));
// rethrow as the exception handler might not do it
throw e;
}
}
+1 -5
View File
@@ -7,11 +7,7 @@
*/
import {compileNgModuleFactory} from '../application/application_ngmodule_factory_compiler';
import {
_callAndReportToErrorHandler,
BootstrapOptions,
optionsReducer,
} from '../application/application_ref';
import {BootstrapOptions, optionsReducer} from '../application/application_ref';
import {
getNgZoneOptions,
internalProvideZoneChangeDetection,