undetectable property: Error.prototype.stack

VERIFIED INVALID

Status

()

VERIFIED INVALID
12 years ago
11 years ago

People

(Reporter: dhtmlkitchen, Unassigned)

Tracking

Trunk
PowerPC
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

(Reporter)

Description

12 years ago
"stack" in Error.prototype; // false
Error.prototype.stack; // undefined

Error.prototype.stack should be detectable without throwing an error.
What error does it throw? What are the expected and actual results? Can you provide a testcase?
Component: General → General
Product: Firefox → Core
QA Contact: general → general
(Reporter)

Comment 2

12 years ago
> What error does it throw
Throws no error.
> What are the expected and actual results?
Expected: 
"stack" in Error.prototype;// should be true, regardless of the value.
I'd normally expect an empty Stack from a "stack" property (or getStack method)

Testcase: Type into Firebug, click run: 
Error.prototype.stack;

    
Why do you expect Error.prototype.stack to exist?
(Reporter)

Comment 4

12 years ago
stack property is on an error instance. 

https://bugzilla.mozilla.org/show_bug.cgi?id=123177

I expected it would be in the prototype.
The property is just defined on the error object directly when it's thrown:

+    ok = JS_DefineProperty(cx, obj, js_stack_str,
+                           STRING_TO_JSVAL(stack),
+                           NULL, NULL, JSPROP_ENUMERATE);

(from the patch in the cited bug).  So no, it's not on the prototype.  
Assignee: nobody → general
Component: General → JavaScript Engine
QA Contact: general → general
Version: unspecified → Trunk

Comment 6

11 years ago
Not all prototypes are instances of the class they proto for; this is, I think one of those cases.  I also think that is fine behavior.
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → INVALID
Prototypes are odd, they should appear to be instances of their class (ES3 notably dictates that RegExp.prototype is Object, but browsers don't do that and ES4 is fixing to match the de-facto standard), but if you get picky about their type you can see they must be of a different type from instances.

But that's neither here nor there. The stack property is a property of each thrown Error instance, not of Error.prototype:

js> try { function f(){throw new Error("moo")}; f()}catch(e){E=e}
Error: moo
js> 'stack' in E
true
js> 'stack' in Error.prototype
false
js> for (i in Error.prototype) print(i)
name
message
fileName
lineNumber
js> for (i in Error.prototype) print(Error.prototype[i])
Error


0
js> Error.prototype.constructor
function Error() {
    [native code]
}
js> E.constructor
function Error() {
    [native code]
}

/be
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.