ZoneAwarePromise does not validate other Promise polyfills tests #499
Description
Version
0.6.25
Problem
Many external libraries already include a Promise polyfill in their source code, which tests support for Promise before adding their own implementation. The problem is that the test are very specific and ZoneAwarePromise does not validate all of them.
For example, I have this very popular Promise polyfill in one of my lazyloaded dependencies : https://github.com/stefanpenner/es6-promise
The test used to detect Promise support is:
let P = local.Promise;
if (P) {
var promiseToString = null;
try {
promiseToString = Object.prototype.toString.call(P.resolve());
} catch(e) {
// silently ignored
}
if (promiseToString === '[object Promise]' && !P.cast){
return;
}
}
With ZoneAwarePromise, Object.prototype.toString.call(P.resolve());
returns [object Object]
which makes the test failing. So ZoneAwarePromise is replaced by the polyfill implementation, and change detection does not work anymore after promise resolution.
Is there anything you can do to make this test pass ?
Workaround
Currently the only ugly workaround I found is to monkey-patch Object.prototype.toString
:
const ZoneAwarePromise = self.Promise;
const originalObjectPrototypeToString = Object.prototype.toString;
// TEMP: monkey patch Object.prototype.toString
Object.prototype.toString = function() {
if(typeof this === "object" && this instanceof ZoneAwarePromise) {
return "[object Promise]";
}
return originalObjectPrototypeToString.apply(this, arguments);
};