fix(zone.js): zone.js toString patch should check typeof Promise is function (#38350)

Close #38361

zone.js monkey patch toString, and check the instance is `Promise` or not by using `instanceof Promise`,
sometimes when Promise is not available, the `instanceof` operation fails
and throw `TypeError: Right-hand side of 'instanceof' is not an object`
this PR check `typeof Promise` equals to function or not to prevent the error.

PR Close #38350
This commit is contained in:
Dmitrii Kanatnikov
2020-08-05 22:42:50 +03:00
committed by Misko Hevery
parent cb3db0d31b
commit 18e474f522
2 changed files with 14 additions and 1 deletions

View File

@ -49,9 +49,10 @@ Zone.__load_patch('toString', (global: any) => {
const originalObjectToString = Object.prototype.toString;
const PROMISE_OBJECT_TO_STRING = '[object Promise]';
Object.prototype.toString = function() {
if (this instanceof Promise) {
if (typeof Promise === 'function' && this instanceof Promise) {
return PROMISE_OBJECT_TO_STRING;
}
return originalObjectToString.call(this);
};
});