Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Difference in behavior wrt Chrome native impl #386

Closed
vicb opened this issue Apr 23, 2015 · 4 comments
Closed

[Question] Difference in behavior wrt Chrome native impl #386

vicb opened this issue Apr 23, 2015 · 4 comments

Comments

@vicb
Copy link

vicb commented Apr 23, 2015

consider this:

      RSVP.Promise.resolve('rsvp').then(function(v) { throw v; });
      Promise.resolve('native').then(function(v) { throw v; });

In Chrome there would be a "Uncaught (in promise) native" exception while rsvp implementation does not throw.

I've labelled this as "Question" because I'm not sure what the ES6 spec says about it (it's cryptic to me).

Should rsvp throw or is the current implementation correct ?

@stefanpenner
Copy link
Collaborator

I've labelled this as "Question" because I'm not sure what the ES6 spec says about it (it's cryptic to me).

It's not part of the spec, but it is a "nice thing".

As RSVP is a typically meant to be included in larger projects this functionality is disabled by default. Although I am considering enabling it be default in 4.0.

example:

var rsvp = require('rsvp');
var Promise = rsvp.Promise;
Promise.reject(new Error('OMG'));
// => nothing

but when enabled: https://github.com/tildeio/rsvp.js#error-handling

rsvp.on('error', console.error.bind(console));

no rejection handler:

Promise.reject(new Error('OMG'));
// => [Error: OMG]

with sync error handler

Promise.reject(new Error('OMG')).catch(function(e) { });
// => nothing

with micro-task error handler

var a = Promise.reject(new Error('OMG'));

Promise.ressolve().then(function() {
  return a.catch(function(){ });
});
// => nothing

with macro-task error handler (false positive scenario)

var a = Promise.reject(new Error('OMG'));
setTimeout(function(){
  a.catch(function() { });
}, 0)

// => [Error: OMG]

The false positive and overall visibility problem let me to implement a full instrumentation API: https://github.com/tildeio/rsvp.js#instrumentation

Which lead to us implementing (for ember)
68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313036313734322f313832353633312f30353739306631632d373163382d313165332d396133342d6332323338393266353964342e706e67

which was part of the inspiration for the chrome promise debugging (currently in canary). Although I am sad, as they did not expose this to user-land libs :(

@vicb
Copy link
Author

vicb commented Apr 23, 2015

@stefanpenner thanks for the detailed explanation. Closing as not a bug.

@vicb vicb closed this as completed Apr 23, 2015
@stefanpenner
Copy link
Collaborator

@vicb thanks :). I believe this should be a default in 4.0 though

@stefanpenner
Copy link
Collaborator

i added it to the eventual 4.0 todo list #261

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

No branches or pull requests

2 participants