Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find variable: Promise on Safari

I have a site I'm working on that runs perfectly on Chrome for the desktop (Windows 8.1 & OS X Mavericks)

When I run it on iOS 7 or Safari 7.0.2 I get an error to the console that states

Error while loading route: checkIfLoggedIn

the member it specifies at the message is not a route, it is a method that returns a promise. When I debug through the ember code to figure out what is going wrong I found that it is rejecting the promise with the reason of

Can't find variable: Promise

I can't post the actual code from my site here, so I set out to create a fiddle that reproduces the error and I was able to come up with this:

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

This runs perfectly on Chrome for the desktop (Windows 8.1 & OS X Mavericks), but on iOS 7 or Safari 7.0.2 throws the following error to the console

ReferenceError: Can't find variable: Promise

Anyone have any ideas why this isn't working?

To recap:

  • I have tested on Chrome for Windows 8.1 and OS X Mavericks - It works
  • I have tested on Chrome for iOS and it does not work
  • I have tested on Safari for iOS and OS X Mavericks and it does not work
  • I have not tested on Android at all (I don't have access to any devices at this moment)

This leads me to believe that it is a Safari error as (if I recall correctly) Chrome for iOS uses a Safari control to render the page rather than Chromium

This is the code I'm using 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);
    });
};
like image 684
Robert Petz Avatar asked Mar 17 '14 18:03

Robert Petz


1 Answers

Turns out that on Safari you must use the fully qualified name when creating a 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 appears to fix it for me.

like image 171
Robert Petz Avatar answered Oct 26 '22 16:10

Robert Petz