-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[BUGFIX release] Fix Ember.Error inheritance #15522
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
|
||
function ExtendBuiltin(klass) { | ||
function ExtendableBuiltin() { | ||
klass.apply(this, arguments); | ||
} | ||
|
||
ExtendableBuiltin.prototype = Object.create(klass.prototype); | ||
ExtendableBuiltin.prototype.constructor = ExtendableBuiltin; | ||
return ExtendableBuiltin; | ||
} | ||
|
||
/** | ||
A subclass of the JavaScript Error object for use in Ember. | ||
|
||
|
@@ -18,15 +7,12 @@ function ExtendBuiltin(klass) { | |
@constructor | ||
@public | ||
*/ | ||
export default class EmberError extends ExtendBuiltin(Error) { | ||
constructor(message) { | ||
super(); | ||
|
||
if (!(this instanceof EmberError)) { | ||
return new EmberError(message); | ||
} | ||
export default EmberError; | ||
function EmberError(message, code) { | ||
if (this instanceof EmberError) { | ||
let error = Error.call(this, message, code); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: In V8, using I'm not sure how other browsers behave though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We aren't actually using real super (getting transpiled) also we still support an unfortunate scenario calling the constructor without new. Which ES6 classes don't support. We will need to deprecate that first, then remove in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll open another PR that deprecated the call constructor behavior so by the best LTS we can drop |
||
|
||
let error = Error.call(this, message); | ||
this.stack = error.stack; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if super() is called is this still needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so in transpiled land |
||
this.description = error.description; | ||
this.fileName = error.fileName; | ||
|
@@ -35,5 +21,10 @@ export default class EmberError extends ExtendBuiltin(Error) { | |
this.name = error.name; | ||
this.number = error.number; | ||
this.code = error.code; | ||
} else { | ||
return new EmberError(message, code); | ||
} | ||
} | ||
|
||
EmberError.prototype = Object.create(Error.prototype); | ||
EmberError.constructor = EmberError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dumb question, but why make this a function instead of using the fancy ES6 classes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EmberError unfortunately supports being invoked without using new. This ends up being a less hacky solution. We should deprecate that, so we can eventually switch over entirely though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Thank you for taking a moment to respond to my question.