Hi,
I am having an issue using Zone.js alongside a Promise "subclass" (I say "subclass" because I am not quite sure my method of subclassing is correct). Assume the following code is run in a browser after loading Zone.js.
Promise Subclass
First, my Promise subclass:
function MyPromise(init) {
this._promise = new Promise(init);
}
MyPromise.prototype.catch = function _catch() {
return this._promise.catch.apply(this._promise, arguments);
};
MyPromise.prototype.then = function then() {
return this._promise.then.apply(this._promise, arguments);
};
Object.setPrototypeOf(MyPromise.prototype, Promise.prototype);
This is enough to get an instance of MyPromise passing an instanceof check for Promise.
Test Scenario
Promise.resolve().then(function() {
return new MyPromise(function(resolve) {
resolve(':-)');
});
}).then(function(result) {
console.log('Success', result);
}, function(error) {
console.error('Failure', error);
});
Expected Result
Actual Result
Analysis
After some digging, I think the check in resolvePromise should be more stringent. Since MyPromise inherits from Promise in the example above (which gets overwritten to ZoneAwarePromise), instances of MyPromise pass the ZoneAwarePromise instanceof check. However, instances of MyPromise do not define the __zone_symbol__state or __zone_symbol_value properties that are being checked for. The result is that resolvePromise is called again with the MyPromise instance, state undefined, and value undefined. Eventually, this leads to a call to scheduleResolveOrReject where the delegate gets set the onRejected handler.
Hi,
I am having an issue using Zone.js alongside a Promise "subclass" (I say "subclass" because I am not quite sure my method of subclassing is correct). Assume the following code is run in a browser after loading Zone.js.
Promise Subclass
First, my Promise subclass:
This is enough to get an instance of MyPromise passing an
instanceofcheck for Promise.Test Scenario
Expected Result
Actual Result
Analysis
After some digging, I think the check in
resolvePromiseshould be more stringent. Since MyPromise inherits from Promise in the example above (which gets overwritten to ZoneAwarePromise), instances of MyPromise pass the ZoneAwarePromiseinstanceofcheck. However, instances of MyPromise do not define the__zone_symbol__stateor__zone_symbol_valueproperties that are being checked for. The result is thatresolvePromiseis called again with the MyPromise instance, stateundefined, and valueundefined. Eventually, this leads to a call toscheduleResolveOrRejectwhere the delegate gets set theonRejectedhandler.