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

Commit 46b97ad

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

File tree

11 files changed

+359
-123
lines changed

11 files changed

+359
-123
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ 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/bluebird
46+
- node_modules/.bin/gulp test/node/disableerror
47+
- node_modules/.bin/gulp test/node/lazyerror
4448
- node simple-server.js 2>&1> server.log&
4549
- node ./test/webdriver/test.sauce.js
4650

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: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,23 @@ gulp.task('build/zone-patch-socket-io.min.js', ['compile-esm'], function(cb) {
221221
});
222222

223223
gulp.task('build/zone-patch-promise-testing.js', ['compile-esm'], function(cb) {
224-
return generateScript('./lib/testing/promise-testing.ts', 'zone-patch-promise-test.js', false, cb);
224+
return generateScript(
225+
'./lib/testing/promise-testing.ts', 'zone-patch-promise-test.js', false, cb);
225226
});
226227

227228
gulp.task('build/zone-patch-promise-testing.min.js', ['compile-esm'], function(cb) {
228-
return generateScript('./lib/testing/promise-testing.ts', 'zone-patch-promise-test.min.js', true, cb);
229+
return generateScript(
230+
'./lib/testing/promise-testing.ts', 'zone-patch-promise-test.min.js', true, cb);
229231
});
230232

231233
gulp.task('build/zone-patch-resize-observer.js', ['compile-esm'], function(cb) {
232-
return generateScript('./lib/browser/webapis-resize-observer.ts', 'zone-patch-resize-observer.js', false, cb);
234+
return generateScript(
235+
'./lib/browser/webapis-resize-observer.ts', 'zone-patch-resize-observer.js', false, cb);
233236
});
234237

235238
gulp.task('build/zone-patch-resize-observer.min.js', ['compile-esm'], function(cb) {
236-
return generateScript('./lib/browser/webapis-resize-observer.ts', 'zone-patch-resize-observer.min.js', true, cb);
239+
return generateScript(
240+
'./lib/browser/webapis-resize-observer.ts', 'zone-patch-resize-observer.min.js', true, cb);
237241
});
238242

239243
gulp.task('build/bluebird.js', ['compile-esm'], function(cb) {
@@ -245,11 +249,11 @@ gulp.task('build/bluebird.min.js', ['compile-esm'], function(cb) {
245249
});
246250

247251
gulp.task('build/zone-patch-jsonp.js', ['compile-esm'], function(cb) {
248-
return generateScript('./lib/extra/jsonp.ts', 'zone-patch-jsonp.js', false, cb);
252+
return generateScript('./lib/extra/jsonp.ts', 'zone-patch-jsonp.js', false, cb);
249253
});
250254

251255
gulp.task('build/zone-patch-jsonp.min.js', ['compile-esm'], function(cb) {
252-
return generateScript('./lib/extra/jsonp.ts', 'zone-patch-jsonp.min.js', true, cb);
256+
return generateScript('./lib/extra/jsonp.ts', 'zone-patch-jsonp.min.js', true, cb);
253257
});
254258

255259
gulp.task('build/jasmine-patch.js', ['compile-esm'], function(cb) {
@@ -323,11 +327,13 @@ gulp.task('build/rxjs.min.js', ['compile-esm'], function(cb) {
323327
});
324328

325329
gulp.task('build/rxjs-fake-async.js', ['compile-esm'], function(cb) {
326-
return generateScript('./lib/rxjs/rxjs-fake-async.ts', 'zone-patch-rxjs-fake-async.js', false, cb);
330+
return generateScript(
331+
'./lib/rxjs/rxjs-fake-async.ts', 'zone-patch-rxjs-fake-async.js', false, cb);
327332
});
328333

329334
gulp.task('build/rxjs-fake-async.min.js', ['compile-esm'], function(cb) {
330-
return generateScript('./lib/rxjs/rxjs-fake-async.ts', 'zone-patch-rxjs-fake-async.min.js', true, cb);
335+
return generateScript(
336+
'./lib/rxjs/rxjs-fake-async.ts', 'zone-patch-rxjs-fake-async.min.js', true, cb);
331337
});
332338

333339
gulp.task('build/closure.js', function() {
@@ -427,6 +433,18 @@ gulp.task('test/bluebird', ['compile-node'], function(cb) {
427433
nodeTest(specFiles, cb);
428434
});
429435

436+
gulp.task('test/node/disableerror', ['compile-node'], function(cb) {
437+
process.env.errorpolicy = 'disable';
438+
var specFiles = ['build/test/node_error_entry_point.js'];
439+
nodeTest(specFiles, cb);
440+
});
441+
442+
gulp.task('test/node/lazyerror', ['compile-node'], function(cb) {
443+
process.env.errorpolicy = 'lazy';
444+
var specFiles = ['build/test/node_error_entry_point.js'];
445+
nodeTest(specFiles, cb);
446+
});
447+
430448
// Check the coding standards and programming errors
431449
gulp.task('lint', () => {
432450
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
};

karma-dist.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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');

0 commit comments

Comments
 (0)