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

Commit

Permalink
feat(error): fix #975, can config how to load blacklist zone stack fr…
Browse files Browse the repository at this point in the history
…ames
  • Loading branch information
JiaLiPassion committed Jun 22, 2018
1 parent 0a2f6ff commit 5f6ef41
Show file tree
Hide file tree
Showing 22 changed files with 408 additions and 161 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ 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 -no-patch-clock
- node_modules/.bin/gulp test/bluebird
- 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 jasmine@3.0.0 jasmine-core@3.0.0 mocha@5.0.1
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
2 changes: 1 addition & 1 deletion file-size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"path": "dist/zone.min.js",
"checkTarget": true,
"limit": 40000
"limit": 40144
}
]
}
12 changes: 12 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ gulp.task('test/bluebird', ['compile-node'], function(cb) {
nodeTest(specFiles, cb);
});

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

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

// Check the coding standards and programming errors
gulp.task('lint', () => {
const tslint = require('gulp-tslint');
Expand Down
2 changes: 2 additions & 0 deletions karma-base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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/whatwg-fetch/fetch.js',
Expand Down Expand Up @@ -41,6 +42,7 @@ module.exports = function(config) {
browsers: ['Chrome'],

captureTimeout: 60000,
retryLimit: 4,

autoWatch: true,
singleRun: false
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 lib/browser/define-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const _create = Object.create;
const unconfigurablesKey = zoneSymbol('unconfigurables');

export function propertyPatch() {
Object.defineProperty = function(obj, prop, desc) {
Object.defineProperty = function(obj: any, prop: string, desc: any) {
if (isUnconfigurable(obj, prop)) {
throw new TypeError('Cannot assign to read only property \'' + prop + '\' of ' + obj);
}
Expand Down
Loading

0 comments on commit 5f6ef41

Please sign in to comment.