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

feat(patch): fix #499, let promise instance toString active like native#734

Merged
mhevery merged 1 commit intoangular:masterfrom
JiaLiPassion:promise
Apr 21, 2017
Merged

feat(patch): fix #499, let promise instance toString active like native#734
mhevery merged 1 commit intoangular:masterfrom
JiaLiPassion:promise

Conversation

@JiaLiPassion
Copy link
Copy Markdown
Collaborator

@JiaLiPassion JiaLiPassion commented Apr 12, 2017

fix #499, let

object.prototype.toString(Promise.resolve())

active as native to output

[object Promise]

instead of current

[object Object]

in ES6, we can use Symbol.toStringTag, in ES5, I didn't find a better way to do this.

@mhevery mhevery merged commit 2f11e67 into angular:master Apr 21, 2017
@JiaLiPassion JiaLiPassion deleted the promise branch May 6, 2017 04:53
Comment thread lib/common/to-string.ts
export function patchObjectToString() {
const originalObjectToString = Object.prototype.toString;
Object.prototype.toString = function() {
if (this instanceof Promise) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the reason why Promise shims are in use because Promise is not available in all common browsers today? So wouldn't this line throw

ReferenceError: Can't find variable: Promise

for projects & browsers that haven't window.Promise (neither native nor shim)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zone.js has provided Promise shim, so it will be ok even some browser or other environment doesn't provide native Promise

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZoneAwarePromise does not validate other Promise polyfills tests

4 participants