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

Commit

Permalink
Revert "fix: Correct ZoneAwareError prototype chain" (#556)
Browse files Browse the repository at this point in the history
This reverts commit ba7858c.
  • Loading branch information
chuckjaz authored and mhevery committed Dec 20, 2016
1 parent c70e9ec commit a22a687
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
14 changes: 7 additions & 7 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1318,14 +1318,13 @@ const Zone: ZoneType = (function(global: any) {
function ZoneAwareError() {
// Create an Error.
let error: Error = NativeError.apply(this, arguments);
this.message = error.message;

// Save original stack trace
this.originalStack = error.stack;
error.originalStack = error.stack;

// Process the stack trace and rewrite the frames.
if (ZoneAwareError[stackRewrite] && this.originalStack) {
let frames: string[] = this.originalStack.split('\n');
if (ZoneAwareError[stackRewrite] && error.originalStack) {
let frames: string[] = error.originalStack.split('\n');
let zoneFrame = _currentZoneFrame;
let i = 0;
// Find the first frame
Expand Down Expand Up @@ -1353,12 +1352,13 @@ const Zone: ZoneType = (function(global: any) {
}
}
}
this.stack = this.zoneAwareStack = frames.join('\n');
error.stack = error.zoneAwareStack = frames.join('\n');
}
};
return error;
}

// Copy the prototype so that instanceof operator works as expected
ZoneAwareError.prototype = Object.create(NativeError.prototype);
ZoneAwareError.prototype = NativeError.prototype;
ZoneAwareError[Zone.__symbol__('blacklistedStackFrames')] = blackListedStackFrames;
ZoneAwareError[stackRewrite] = false;

Expand Down
8 changes: 0 additions & 8 deletions test/common/Error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ describe('ZoneAwareError', () => {
// and there is no point in running them.
if (!Error['stackRewrite']) return;

it('should keep error prototype chain correctly', () => {
class MyError extends Error {}
const myError = new MyError();
expect(myError instanceof Error).toBe(true);
expect(myError instanceof MyError).toBe(true);
expect(myError.stack).not.toBe(undefined);
});

it('should show zone names in stack frames and remove extra frames', () => {
const rootZone = getRootZone();
const innerZone = rootZone.fork({name: 'InnerZone'});
Expand Down

0 comments on commit a22a687

Please sign in to comment.