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

Commit

Permalink
fix: Promise.toString() to look like native function
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Dec 23, 2016
1 parent 5c7bc01 commit f854ce0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,10 @@ const Zone: ZoneType = (function(global: any) {
}

class ZoneAwarePromise<R> implements Promise<R> {
static toString() {
return 'function ZoneAwarePromise() { [native code] }';
}

static resolve<R>(value: R): Promise<R> {
return resolvePromise(<ZoneAwarePromise<R>>new this(null), RESOLVED, value);
}
Expand Down
4 changes: 4 additions & 0 deletions test/common/Promise.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ describe(
log = [];
});

it('should pretend to be a native code', () => {
expect(String(Promise).indexOf('[native code]') >= 0).toBe(true);
});

it('should make sure that new Promise is instance of Promise', () => {
expect(Promise.resolve(123) instanceof Promise).toBe(true);
expect(new Promise(() => null) instanceof Promise).toBe(true);
Expand Down

0 comments on commit f854ce0

Please sign in to comment.