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

Commit

Permalink
feat(error): can config how to load blacklist zone stack frames
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Mar 12, 2018
1 parent eefe983 commit d60fd0e
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 126 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ script:
- node_modules/.bin/karma start karma-build-sauce-mocha.conf.js --single-run
- node_modules/.bin/karma start karma-dist-sauce-selenium3-jasmine.conf.js --single-run
- node_modules/.bin/karma start karma-build-sauce-selenium3-mocha.conf.js --single-run
- node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run --errorpolicy=disable
- node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run --errorpolicy=lazy
- node_modules/.bin/gulp test/node
- node_modules/.bin/gulp test/node/disableerror
- node_modules/.bin/gulp test/node/lazyerror
- node simple-server.js 2>&1> server.log&
- node ./test/webdriver/test.sauce.js
- yarn add [email protected] [email protected]
Expand Down
51 changes: 51 additions & 0 deletions MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,57 @@ you can do like this.
<script src="../dist/zone.js"></script>
```

- Error

By default, `zone.js/dist/zone-error` will not be loaded for performance concern.
This package will provide following functionality.

1. Error inherit: handle `extend Error` issue.
```
class MyError extends Error {}
const myError = new MyError();
console.log('is MyError instanceof Error', (myError instanceof Error));
```

without `zone-error` patch, the example above will output `false`, with the patch, the reuslt will be `true`.

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
in stack frames.

```
at zone.run (polyfill.bundle.js: 3424)
at zoneDelegate.invokeTask (polyfill.bundle.js: 3424)
at zoneDelegate.runTask (polyfill.bundle.js: 3424)
at zone.drainMicroTaskQueue (polyfill.bundle.js: 3424)
at a.b.c (vendor.bundle.js: 12345 <angular>)
at d.e.f (main.bundle.js: 23456)
```

with this patch, those zone frames will be removed,
and the zone information `<angular>/<root>` will be added

```
at a.b.c (vendor.bundle.js: 12345 <angular>)
at d.e.f (main.bundle.js: 23456 <root>)
```

The second feature will slow down the `Error` performance, so `zone.js` provide a flag to let you be able to control the behavior.
The flag is `__Zone_Error_BlacklistedStackFrames_policy`. And the available options is:

1. default: this is the default one, if you load `zone.js/dist/zone-error` without
setting the flag, `default` will be used, and `BlackListStackFrames` will be available
when `new Error()`, you can get a `error.stack` which is `zone stack free`. But this
will slow down `new Error()` a little bit.

2. disable: this will disable `BlackListZoneStackFrame` feature, and if you load
`zone.js/dist/zone-error`, you will only get a `wrapped Error` which can handle
`Error inherit` issue.

3. lazy: this is a feature to let you be able to get `BlackListZoneStackFrame` feature,
but not impact performance. But as a trade off, you can't get the `zone free stack
frames` by access `error.stack`. You can only get it by access `error.zoneAwareStack`.


- Angular(2+)

Angular uses zone.js to manage async operations and decide when to perform change detection. Thus, in Angular,
Expand Down
43 changes: 32 additions & 11 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,23 @@ gulp.task('build/zone-patch-socket-io.min.js', ['compile-esm'], function(cb) {
});

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

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

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

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

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

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

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

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

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

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

gulp.task('build/closure.js', function() {
Expand Down Expand Up @@ -391,12 +397,10 @@ gulp.task('build', [
'build/closure.js'
]);

gulp.task('test/node', ['compile-node'], function(cb) {
function testNode(specFiles, cb) {
var JasmineRunner = require('jasmine');
var jrunner = new JasmineRunner();

var specFiles = ['build/test/node_entry_point.js'];

jrunner.configureDefaultReporter({showColors: true});

jrunner.onComplete(function(passed) {
Expand All @@ -417,6 +421,23 @@ gulp.task('test/node', ['compile-node'], function(cb) {
jrunner.specDir = '';
jrunner.addSpecFiles(specFiles);
jrunner.execute();
};

gulp.task('test/node', ['compile-node'], function(cb) {
var specFiles = ['build/test/node_entry_point.js'];
testNode(specFiles, cb);
});

gulp.task('test/node/disableerror', ['compile-node'], function(cb) {
process.env.errorpolicy = 'disable';
var specFiles = ['build/test/node_error_entry_point.js'];
testNode(specFiles, cb);
});

gulp.task('test/node/lazyerror', ['compile-node'], function(cb) {
process.env.errorpolicy = 'lazy';
var specFiles = ['build/test/node_error_entry_point.js'];
testNode(specFiles, cb);
});

// Check the coding standards and programming errors
Expand Down
29 changes: 12 additions & 17 deletions karma-base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,35 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function (config) {
module.exports = function(config) {
config.set({
basePath: '',
client: {errorpolicy: config.errorpolicy},
files: [
'node_modules/systemjs/dist/system-polyfills.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/systemjs/dist/system-polyfills.js', 'node_modules/systemjs/dist/system.src.js',
'node_modules/whatwg-fetch/fetch.js',
{pattern: 'node_modules/rxjs/**/**/*.js', included: false, watched: false },
{pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false },
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{pattern: 'node_modules/es6-promise/**/*.js', included: false, watched: false },
{pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
{pattern: 'node_modules/rxjs/**/**/*.js', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/**/*.js.map', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},
{pattern: 'node_modules/es6-promise/**/*.js', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false},
{pattern: 'test/assets/**/*.*', watched: true, served: true, included: false},
{pattern: 'build/**/*.js.map', watched: true, served: true, included: false},
{pattern: 'build/**/*.js', watched: true, served: true, included: false}
],

plugins: [
require('karma-chrome-launcher'),
require('karma-firefox-launcher'),
require('karma-chrome-launcher'), require('karma-firefox-launcher'),
require('karma-sourcemap-loader')
],

preprocessors: {
'**/*.js': ['sourcemap']
},
preprocessors: {'**/*.js': ['sourcemap']},

exclude: [
'test/microtasks.spec.ts'
],
exclude: ['test/microtasks.spec.ts'],

reporters: ['progress'],

//port: 9876,
// port: 9876,
colors: true,

logLevel: config.LOG_INFO,
Expand Down
3 changes: 1 addition & 2 deletions karma-build.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function (config) {
module.exports = function(config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/wtf_mock.js');
config.files.push('build/test/test_fake_polyfill.js');
config.files.push('build/lib/zone.js');
config.files.push('build/lib/common/promise.js');
config.files.push('build/lib/common/error-rewrite.js');
config.files.push('build/test/main.js');
};
2 changes: 1 addition & 1 deletion karma-dist.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

module.exports = function (config) {
module.exports = function(config) {
require('./karma-base.conf.js')(config);
config.files.push('build/test/wtf_mock.js');
config.files.push('build/test/test_fake_polyfill.js');
Expand Down
Loading

0 comments on commit d60fd0e

Please sign in to comment.