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

Commit

Permalink
fix: remove finally definition from Promise interface, will use es201…
Browse files Browse the repository at this point in the history
…8.promise in the future (#1204)
  • Loading branch information
JiaLiPassion authored and vikerman committed Mar 20, 2019
1 parent c378f87 commit 47dd3f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
10 changes: 3 additions & 7 deletions lib/common/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
interface Promise<T> {
finally<U>(onFinally?: () => U | PromiseLike<U>): Promise<T>;
}

Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
const ObjectDefineProperty = Object.defineProperty;
Expand Down Expand Up @@ -146,7 +142,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
if (state !== REJECTED && value instanceof ZoneAwarePromise &&
value.hasOwnProperty(symbolState) && value.hasOwnProperty(symbolValue) &&
(value as any)[symbolState] !== UNRESOLVED) {
clearRejectedNoCatch(<Promise<any>>value);
clearRejectedNoCatch(<Promise<any>>value as any);
resolvePromise(promise, (value as any)[symbolState], (value as any)[symbolValue]);
} else if (state !== REJECTED && typeof then === 'function') {
try {
Expand Down Expand Up @@ -379,7 +375,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
if ((this as any)[symbolState] == UNRESOLVED) {
(<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFulfilled, onRejected);
} else {
scheduleResolveOrReject(this, zone, chainPromise, onFulfilled, onRejected);
scheduleResolveOrReject(this, zone, chainPromise as any, onFulfilled, onRejected);
}
return chainPromise;
}
Expand All @@ -397,7 +393,7 @@ Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePr
if ((this as any)[symbolState] == UNRESOLVED) {
(<any[]>(this as any)[symbolValue]).push(zone, chainPromise, onFinally, onFinally);
} else {
scheduleResolveOrReject(this, zone, chainPromise, onFinally, onFinally);
scheduleResolveOrReject(this, zone, chainPromise as any, onFinally, onFinally);
}
return chainPromise;
}
Expand Down
30 changes: 16 additions & 14 deletions test/common/Promise.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,14 @@ describe(
let resolve: Function|null = null;

testZone.run(function() {
new Promise(function(resolveFn) {
resolve = resolveFn;
}).finally(function() {
expect(arguments.length).toBe(0);
expect(Zone.current).toBe(testZone);
done();
});
(new Promise(function(resolveFn) {
resolve = resolveFn;
}) as any)
.finally(function() {
expect(arguments.length).toBe(0);
expect(Zone.current).toBe(testZone);
done();
});
});

resolve!('value');
Expand All @@ -235,13 +236,14 @@ describe(
let reject: Function|null = null;

testZone.run(function() {
new Promise(function(_, rejectFn) {
reject = rejectFn;
}).finally(function() {
expect(arguments.length).toBe(0);
expect(Zone.current).toBe(testZone);
done();
});
(new Promise(function(_, rejectFn) {
reject = rejectFn;
}) as any)
.finally(function() {
expect(arguments.length).toBe(0);
expect(Zone.current).toBe(testZone);
done();
});
});

reject!('error');
Expand Down

0 comments on commit 47dd3f4

Please sign in to comment.