fix(zone.js): disable wrap uncaught promise rejection should handle primitive value (#38476)

Close #38334.

zone.js provides a flag DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION to let zone.js
throw the original error instead of wrap it when uncaught promise rejection found.
But the rejection value could be anything includes primitive value such as number.
In that case, we should not attach any additional properties to the value.

PR Close #38476
This commit is contained in:
JiaLiPassion
2020-08-15 16:34:22 +09:00
committed by Alex Rickabaugh
parent f979914d4e
commit 19d543f71e
3 changed files with 44 additions and 17 deletions

View File

@ -42,9 +42,9 @@ describe('disable wrap uncaught promise rejection', () => {
setTimeout((): any => null);
setTimeout(() => {
expect(promiseError).toBe(error);
expect((promiseError as any)['rejection']).toBe(error);
expect((promiseError as any)['zone']).toBe(zone);
expect((promiseError as any)['task']).toBe(task);
expect((promiseError as any)['rejection']).toBe(undefined);
expect((promiseError as any)['zone']).toBe(undefined);
expect((promiseError as any)['task']).toBe(undefined);
done();
});
});
@ -76,4 +76,27 @@ describe('disable wrap uncaught promise rejection', () => {
done();
});
});
it('should print original information when a primitive value is used for rejection', (done) => {
let promiseError: number|null = null;
Zone.current
.fork({
name: 'promise-error',
onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any):
boolean => {
promiseError = error;
delegate.handleError(target, error);
return false;
}
})
.run(() => {
Promise.reject(42);
expect(promiseError).toBe(null);
});
setTimeout((): any => null);
setTimeout(() => {
expect(promiseError).toBe(42);
done();
});
});
});