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

ZoneAwarePromise does not validate other Promise polyfills tests #499

Closed
sylvainpolletvillard opened this issue Nov 3, 2016 · 3 comments · Fixed by #734
Closed

ZoneAwarePromise does not validate other Promise polyfills tests #499

sylvainpolletvillard opened this issue Nov 3, 2016 · 3 comments · Fixed by #734

Comments

@sylvainpolletvillard
Copy link

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);
};
@krassx
Copy link

krassx commented Apr 11, 2017

Ran into the same issue recently, when loaded third-party module with es6-promise. Can anyone look at this one please?

@JiaLiPassion
Copy link
Collaborator

@krassx , I will check it. thank you

@krassx
Copy link

krassx commented Apr 12, 2017

Cool, thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants