perf: Don’t subclass Error; resulting in smaller binary (#14160)
Subclassing errors is problematic since Error returns a new instance. All of the patching which we do than prevent proper application of source maps. PR Close #14160
This commit is contained in:

committed by
Miško Hevery

parent
3c2842be96
commit
c33fda2607
@ -6,12 +6,11 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {BaseError, WrappedError} from '../facade/errors';
|
||||
|
||||
import {ERROR_DEBUG_CONTEXT, ERROR_ORIGINAL_ERROR, getDebugContext} from '../errors';
|
||||
import {DebugContext, EntryAction, ViewState} from './types';
|
||||
|
||||
export function expressionChangedAfterItHasBeenCheckedError(
|
||||
context: DebugContext, oldValue: any, currValue: any, isFirstCheck: boolean): ViewDebugError {
|
||||
context: DebugContext, oldValue: any, currValue: any, isFirstCheck: boolean): Error {
|
||||
let msg =
|
||||
`Expression has changed after it was checked. Previous value: '${oldValue}'. Current value: '${currValue}'.`;
|
||||
if (isFirstCheck) {
|
||||
@ -22,25 +21,22 @@ export function expressionChangedAfterItHasBeenCheckedError(
|
||||
return viewDebugError(msg, context);
|
||||
}
|
||||
|
||||
export function viewWrappedDebugError(originalError: any, context: DebugContext): WrappedError&
|
||||
ViewDebugError {
|
||||
const err = viewDebugError(originalError.message, context) as WrappedError & ViewDebugError;
|
||||
err.originalError = originalError;
|
||||
export function viewWrappedDebugError(originalError: any, context: DebugContext): Error {
|
||||
const err = viewDebugError(originalError.message, context);
|
||||
(err as any)[ERROR_ORIGINAL_ERROR] = originalError;
|
||||
return err;
|
||||
}
|
||||
|
||||
export interface ViewDebugError { context: DebugContext; }
|
||||
|
||||
export function viewDebugError(msg: string, context: DebugContext): ViewDebugError {
|
||||
const err = new Error(msg) as any;
|
||||
err.context = context;
|
||||
export function viewDebugError(msg: string, context: DebugContext): Error {
|
||||
const err = new Error(msg);
|
||||
(err as any)[ERROR_DEBUG_CONTEXT] = context;
|
||||
err.stack = context.source;
|
||||
context.view.state |= ViewState.Errored;
|
||||
return err;
|
||||
}
|
||||
|
||||
export function isViewDebugError(err: any): boolean {
|
||||
return err.context;
|
||||
export function isViewDebugError(err: Error): boolean {
|
||||
return !!getDebugContext(err);
|
||||
}
|
||||
|
||||
export function viewDestroyedError(action: EntryAction): Error {
|
||||
|
@ -6,9 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {isDevMode} from '../application_ref';
|
||||
import {RenderComponentType, Renderer} from '../render/api';
|
||||
|
||||
import {checkAndUpdateElementDynamic, checkAndUpdateElementInline, createElement} from './element';
|
||||
import {expressionChangedAfterItHasBeenCheckedError} from './errors';
|
||||
import {appendNgContent} from './ng_content';
|
||||
|
Reference in New Issue
Block a user