This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +47
-0
lines changed Expand file tree Collapse file tree 5 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 9
9
module . exports = function ( config ) {
10
10
require ( './karma-base.conf.js' ) ( config ) ;
11
11
config . files . push ( 'build/test/wtf_mock.js' ) ;
12
+ config . files . push ( 'build/test/custom_error.js' ) ;
12
13
config . files . push ( 'build/lib/zone.js' ) ;
13
14
config . files . push ( 'build/test/main.js' ) ;
14
15
} ;
Original file line number Diff line number Diff line change @@ -1744,6 +1744,25 @@ const Zone: ZoneType = (function(global: any) {
1744
1744
ZoneAwareError [ Zone . __symbol__ ( 'blacklistedStackFrames' ) ] = blackListedStackFrames ;
1745
1745
ZoneAwareError [ stackRewrite ] = false ;
1746
1746
1747
+ // those properties need special handling
1748
+ const specialPropertyNames = [ 'stackTraceLimit' , 'captureStackTrace' , 'prepareStackTrace' ] ;
1749
+ // those properties of NativeError should be set to ZoneAwareError
1750
+ const nativeErrorProperties = Object . keys ( NativeError ) ;
1751
+ if ( nativeErrorProperties ) {
1752
+ nativeErrorProperties . forEach ( prop => {
1753
+ if ( specialPropertyNames . filter ( sp => sp === prop ) . length === 0 ) {
1754
+ Object . defineProperty ( ZoneAwareError , prop , {
1755
+ get : function ( ) {
1756
+ return NativeError [ prop ] ;
1757
+ } ,
1758
+ set : function ( value ) {
1759
+ NativeError [ prop ] = value ;
1760
+ }
1761
+ } ) ;
1762
+ }
1763
+ } ) ;
1764
+ }
1765
+
1747
1766
if ( NativeError . hasOwnProperty ( 'stackTraceLimit' ) ) {
1748
1767
// Extend default stack limit as we will be removing few frames.
1749
1768
NativeError . stackTraceLimit = Math . max ( NativeError . stackTraceLimit , 15 ) ;
Original file line number Diff line number Diff line change @@ -157,6 +157,18 @@ describe('ZoneAwareError', () => {
157
157
expect ( error1 . message ) . toEqual ( 'test new error message' ) ;
158
158
} ) ;
159
159
160
+ it ( 'should copy customized NativeError properties to ZoneAwareError' , ( ) => {
161
+ const spy = jasmine . createSpy ( 'errorCustomFunction' ) ;
162
+ const NativeError = global [ Zone [ '__symbol__' ] ( 'Error' ) ] ;
163
+ NativeError . customFunction = function ( args ) {
164
+ spy ( args ) ;
165
+ } ;
166
+ expect ( Error [ 'customProperty' ] ) . toBe ( 'customProperty' ) ;
167
+ expect ( typeof Error [ 'customFunction' ] ) . toBe ( 'function' ) ;
168
+ Error [ 'customFunction' ] ( 'test' ) ;
169
+ expect ( spy ) . toHaveBeenCalledWith ( 'test' ) ;
170
+ } ) ;
171
+
160
172
it ( 'should show zone names in stack frames and remove extra frames' , ( ) => {
161
173
const rootZone = getRootZone ( ) ;
162
174
const innerZone = rootZone . fork ( { name : 'InnerZone' } ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @license
3
+ * Copyright Google Inc. All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+
9
+ 'use strict' ;
10
+ ( function ( global ) {
11
+ const NativeError = global [ 'Error' ] ;
12
+ NativeError . customProperty = 'customProperty' ;
13
+ NativeError . customFunction = function ( ) { } ;
14
+ } ) ( typeof window === 'object' && window || typeof self === 'object' && self || global ) ;
Original file line number Diff line number Diff line change 8
8
9
9
// Must be loaded before zone loads, so that zone can detect WTF.
10
10
import './wtf_mock' ;
11
+ import './custom_error' ;
11
12
12
13
// Setup tests for Zone without microtask support
13
14
import '../lib/zone' ;
You can’t perform that action at this time.
0 commit comments