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

Breaks circular references in rejected jqXhr promises #12262

Merged
merged 1 commit into from
Sep 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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