Skip to content

Commit

Permalink
Merge pull request #12262 from xcambar/rsvp_circular_reference
Browse files Browse the repository at this point in the history
Breaks circular references in rejected jqXhr promises
  • Loading branch information
rwjblue committed Sep 2, 2015
2 parents 6d66c6b + 4f6bad2 commit e762025
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/ember-runtime/lib/ext/rsvp.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ RSVP.configure('async', function(callback, promise) {
});
});

export function onerrorDefault(e) {
export function onerrorDefault(reason) {
var error;

if (e && e.errorThrown) {
if (reason && reason.errorThrown) {
// jqXHR provides this
error = e.errorThrown;
error = reason.errorThrown;
if (typeof error === 'string') {
error = new Error(error);
}
error.__reason_with_error_thrown__ = e;
Object.defineProperty(error, '__reason_with_error_thrown__', {
value: reason,
enumerable: false
});
} else {
error = e;
error = reason;
}

if (error && error.name === "UnrecognizedURLError") {
Expand Down
24 changes: 24 additions & 0 deletions packages/ember-runtime/tests/ext/rsvp_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ QUnit.test('rejections where the errorThrown is a string should wrap the sting i
}
});

QUnit.test('rejections can be serialized to JSON', function (assert) {
expect(2);

var wasEmberTesting = Ember.testing;
var wasOnError = Ember.onerror;

try {
Ember.testing = false;
Ember.onerror = function(error) {
assert.equal(error.message, 'a fail');
assert.ok(JSON.stringify(error), 'Error can be serialized');
};

var jqXHR = {
errorThrown: new Error('a fail')
};

run(RSVP, 'reject', jqXHR);
} finally {
Ember.onerror = wasOnError;
Ember.testing = wasEmberTesting;
}
});

var wasTesting;
var reason = 'i failed';
QUnit.module('Ember.test: rejection assertions', {
Expand Down

0 comments on commit e762025

Please sign in to comment.