Unable to find variable: promise on Safari

I have a site I'm working on that works fine on Chrome for the desktop (Windows 8.1 and OS X Mavericks)

When I launch it on iOS 7 or Safari 7.0.2, I get an error in the console that says "Error loading route: checkIfLoggedIn"

the member that he indicates in the message is not a route, this is a method that returns a promise. When I debug ember code to understand what is going wrong, I find that it rejects the promise for the reason β€œCan't find the variable: Promise”

I cannot post the actual code from my site here, so I decided to create a script that reproduces the error, and I was able to come up with this:

http://jsfiddle.net/NQKvy/851/

This works fine on Chrome for the desktop (Windows 8.1 and OS X Mavericks), but on iOS 7 or Safari 7.0.2 the following error is thrown in the console "ReferenceError: cannot find the variable: Promise"

Anyone have any ideas why this is not working?

Repeat:

  • I tested Chrome for Windows 8.1 and OS X Mavericks - it works
  • I tested Chrome for iOS and it does not work.
  • I tested Safari for iOS and OS X Mavericks and it does not work.
  • I have not tested Android at all (I do not have access to any devices at the moment)

This makes me think this is a Safari bug, because (if I remember correctly) Chrome for iOS uses the Safari control to display the page, not Chromium

This is the code I use to generate the error:

App.ready = function() { var asdf = new Promise(function (resolve) { var i = 1; i++; resolve.call(this,i); }).then(function (result) { alert('I: ' + result); }); }; 
+6
source share
2 answers

It turns out that in Safari you should use the full name when creating the promise, otherwise it will not work:

 App.ready = function() { var asdf = new Ember.RSVP.Promise(function (resolve) { var i = 1; i++; resolve.call(this,i); }).then(function (result) { alert('I: ' + result); }); }; 

Note the "new Ember.RSVP.Promise" instead of the "new promise." This seems to fix it for me.

+14
source

According to this , for iOS Safari 7.1 or Safari 7 there are no promises.

However, they will receive them in iOS Safari 8 and Safari 8.

+1
source

All Articles