Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit a50debd

Browse files
committed
feat(error): can config how to load blacklist zone stack frames
1 parent 1ba8519 commit a50debd

File tree

10 files changed

+334
-117
lines changed

10 files changed

+334
-117
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ script:
3939
- node_modules/.bin/karma start karma-build-sauce-mocha.conf.js --single-run
4040
- node_modules/.bin/karma start karma-dist-sauce-selenium3-jasmine.conf.js --single-run
4141
- node_modules/.bin/karma start karma-build-sauce-selenium3-mocha.conf.js --single-run
42+
- node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run --errorpolicy=disable
43+
- node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run --errorpolicy=lazy
4244
- node_modules/.bin/gulp test/node
4345
- node_modules/.bin/gulp test/node -no-patch-clock
4446
- node_modules/.bin/gulp test/bluebird
47+
- node_modules/.bin/gulp test/node/disableerror
48+
- node_modules/.bin/gulp test/node/lazyerror
4549
- node simple-server.js 2>&1> server.log&
4650
- node ./test/webdriver/test.sauce.js
4751

MODULE.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,57 @@ you can do like this.
7676
<script src="../dist/zone.js"></script>
7777
```
7878

79+
- Error
80+
81+
By default, `zone.js/dist/zone-error` will not be loaded for performance concern.
82+
This package will provide following functionality.
83+
84+
1. Error inherit: handle `extend Error` issue.
85+
```
86+
class MyError extends Error {}
87+
const myError = new MyError();
88+
console.log('is MyError instanceof Error', (myError instanceof Error));
89+
```
90+
91+
without `zone-error` patch, the example above will output `false`, with the patch, the reuslt will be `true`.
92+
93+
2. BlacklistZoneStackFrames: remove zone.js stack from `stackTrace`, and add `zone` information. Without this patch, a lot of `zone.js` invocation stack will be shown
94+
in stack frames.
95+
96+
```
97+
at zone.run (polyfill.bundle.js: 3424)
98+
at zoneDelegate.invokeTask (polyfill.bundle.js: 3424)
99+
at zoneDelegate.runTask (polyfill.bundle.js: 3424)
100+
at zone.drainMicroTaskQueue (polyfill.bundle.js: 3424)
101+
at a.b.c (vendor.bundle.js: 12345 <angular>)
102+
at d.e.f (main.bundle.js: 23456)
103+
```
104+
105+
with this patch, those zone frames will be removed,
106+
and the zone information `<angular>/<root>` will be added
107+
108+
```
109+
at a.b.c (vendor.bundle.js: 12345 <angular>)
110+
at d.e.f (main.bundle.js: 23456 <root>)
111+
```
112+
113+
The second feature will slow down the `Error` performance, so `zone.js` provide a flag to let you be able to control the behavior.
114+
The flag is `__Zone_Error_BlacklistedStackFrames_policy`. And the available options is:
115+
116+
1. default: this is the default one, if you load `zone.js/dist/zone-error` without
117+
setting the flag, `default` will be used, and `BlackListStackFrames` will be available
118+
when `new Error()`, you can get a `error.stack` which is `zone stack free`. But this
119+
will slow down `new Error()` a little bit.
120+
121+
2. disable: this will disable `BlackListZoneStackFrame` feature, and if you load
122+
`zone.js/dist/zone-error`, you will only get a `wrapped Error` which can handle
123+
`Error inherit` issue.
124+
125+
3. lazy: this is a feature to let you be able to get `BlackListZoneStackFrame` feature,
126+
but not impact performance. But as a trade off, you can't get the `zone free stack
127+
frames` by access `error.stack`. You can only get it by access `error.zoneAwareStack`.
128+
129+
79130
- Angular(2+)
80131
81132
Angular uses zone.js to manage async operations and decide when to perform change detection. Thus, in Angular,

gulpfile.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,18 @@ gulp.task('test/bluebird', ['compile-node'], function(cb) {
442442
nodeTest(specFiles, cb);
443443
});
444444

445+
gulp.task('test/node/disableerror', ['compile-node'], function(cb) {
446+
process.env.errorpolicy = 'disable';
447+
var specFiles = ['build/test/node_error_entry_point.js'];
448+
nodeTest(specFiles, cb);
449+
});
450+
451+
gulp.task('test/node/lazyerror', ['compile-node'], function(cb) {
452+
process.env.errorpolicy = 'lazy';
453+
var specFiles = ['build/test/node_error_entry_point.js'];
454+
nodeTest(specFiles, cb);
455+
});
456+
445457
// Check the coding standards and programming errors
446458
gulp.task('lint', () => {
447459
const tslint = require('gulp-tslint');

karma-base.conf.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,35 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
module.exports = function (config) {
9+
module.exports = function(config) {
1010
config.set({
1111
basePath: '',
12+
client: {errorpolicy: config.errorpolicy},
1213
files: [
13-
'node_modules/systemjs/dist/system-polyfills.js',
14-
'node_modules/systemjs/dist/system.src.js',
14+
'node_modules/systemjs/dist/system-polyfills.js', 'node_modules/systemjs/dist/system.src.js',
1515
'node_modules/whatwg-fetch/fetch.js',
16-
{pattern: 'node_modules/rxjs/**/**/*.js', included: false, watched: false },
17-
{pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false },
18-
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
19-
{pattern: 'node_modules/es6-promise/**/*.js', included: false, watched: false },
20-
{pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
16+
{pattern: 'node_modules/rxjs/**/**/*.js', included: false, watched: false},
17+
{pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false},
18+
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},
19+
{pattern: 'node_modules/es6-promise/**/*.js', included: false, watched: false},
20+
{pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false},
2121
{pattern: 'test/assets/**/*.*', watched: true, served: true, included: false},
2222
{pattern: 'build/**/*.js.map', watched: true, served: true, included: false},
2323
{pattern: 'build/**/*.js', watched: true, served: true, included: false}
2424
],
2525

2626
plugins: [
27-
require('karma-chrome-launcher'),
28-
require('karma-firefox-launcher'),
27+
require('karma-chrome-launcher'), require('karma-firefox-launcher'),
2928
require('karma-sourcemap-loader')
3029
],
3130

32-
preprocessors: {
33-
'**/*.js': ['sourcemap']
34-
},
31+
preprocessors: {'**/*.js': ['sourcemap']},
3532

36-
exclude: [
37-
'test/microtasks.spec.ts'
38-
],
33+
exclude: ['test/microtasks.spec.ts'],
3934

4035
reporters: ['progress'],
4136

42-
//port: 9876,
37+
// port: 9876,
4338
colors: true,
4439

4540
logLevel: config.LOG_INFO,

karma-build.conf.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
module.exports = function (config) {
9+
module.exports = function(config) {
1010
require('./karma-base.conf.js')(config);
1111
config.files.push('build/test/wtf_mock.js');
1212
config.files.push('build/test/test_fake_polyfill.js');
1313
config.files.push('build/lib/zone.js');
1414
config.files.push('build/lib/common/promise.js');
15-
config.files.push('build/lib/common/error-rewrite.js');
1615
config.files.push('build/test/main.js');
1716
};

0 commit comments

Comments
 (0)