Closed
Bug 976582
Opened 12 years ago
Closed 12 years ago
Custom derived Error class' lineNumber, columnNumber and fileName properties return undefined on Object.getOwnPropertyDescriptor().
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: f-moz, Unassigned)
Details
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36
Steps to reproduce:
1. Derive a custom Error type from Error using MDN recommended notation
var MyError = function() { return this; }; MyError.prototype = new Error(); MyError.prototype.constructor = MyError; var x = new MyError();
or ECMA5 way
var MyError = function() { return this; }; Object.create(Error.prototype, { constructor: { value: MyError }}); var x = new MyError();
2. evaluate any of the expressions: Object.getOwnPropertyDescriptor(x, "lineNumber");
Object.getOwnPropertyDescriptor(x, "columnNumber");
Object.getOwnPropertyDescriptor(x, "fileName");
Actual results:
Object.getOwnPropertyDescriptor returns undefined. Object.hasOwnProperty returns true.
Expected results:
Object.getOwnPropertyDescriptor returns a valid property descriptor, because the property is technically not absent as per ecma-262 8.10.
| Reporter | ||
Updated•12 years ago
|
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Comment 1•12 years ago
|
||
> Object.hasOwnProperty returns true.
You mean false? I see false returned from Object.hasOwnProperty(x, "fileName"), as expected, since the object has no own property with that name. Why were you expecting it to have one?
> or ECMA5 way
The code there makes no sense; what's the point of the unused Object.create call?
Flags: needinfo?(f-moz)
| Reporter | ||
Comment 2•12 years ago
|
||
Of course, I forgot to correctly assign the result of Object.create to the prototype of MyError:
var MyError = function() { return this; }; MyError.prototype = Object.create(Error.prototype, { constructor: { value: MyError }}); var x = new MyError();
Sorry about that!
Well, after more inspection, and after further decoupling the code from the working code I was seeing the issue in, I think the problem boils down to a difference between "Error.prototype.message" and e.g. "Error.prototype.lineNumber". I was lead to the conclusion that it had something to do with inheritance, due to the convoluted nature of the working code I had at hand.
Object.getOwnPropertyDescriptor(new Error(), "lineNumber"); // returns propertyDesc should (probably?) return undefined
Object.hasOwnProperty(new Error(), "lineNumber"); // returns false
this is in contrast to the standard defined "message" prototype as said:
Object.getOwnPropertyDescriptor(new Error(), "message"); // returns undefined
Object.hasOwnProperty(new Error(), "message"); // returns false
If that is expected behavior, the bug should be marked invalid. Sorry!
Flags: needinfo?(f-moz)
Comment 3•12 years ago
|
||
> Object.getOwnPropertyDescriptor(new Error(), "lineNumber"); // returns propertyDesc should (probably?) return undefined
No, this should return a property descriptor per spec.
> Object.hasOwnProperty(new Error(), "lineNumber"); // returns false
hasOwnProperty is not a static method on Object. It's a method on Object.prototype. So you want:
(new Error()).hasOwnProperty("lineNumber"); // returns true
> Object.getOwnPropertyDescriptor(new Error(), "message"); // returns undefined
Correct. But if you did:
Object.getOwnPropertyDescriptor(new Error("something"), "message");
you would get a descriptor. The reason is http://people.mozilla.org/~jorendorff/es6-draft.html#sec-error-message step 6, which only defines the "message" property on the return value of |new Error(something)| if "something" is not undefined.
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•