Closed Bug 658800 Opened 14 years ago Closed 11 years ago

Properties on an Error become enumerable after toSource is called?

Categories

(Core :: JavaScript Engine, defect)

x86
Linux
defect
Not set
normal

Tracking

()

VERIFIED FIXED
mozilla28
Tracking Status
firefox28 --- verified

People

(Reporter: ryanli, Assigned: Waldo)

References

Details

(Whiteboard: [qa-])

User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0a1) Gecko/20110520 Firefox/6.0a1 Build Identifier: Mozilla/5.0 (X11; Linux i686; rv:6.0a1) Gecko/20110520 Firefox/6.0a1 I'm doing a test on the following code with Firebug: var i = 0; try { i += t; } catch (e) { console.log(JSON.stringify(e)); } The output result is merely {} However, if I add a line console.log(e); before JSON.stringify, the result would be: ReferenceError: t is not defined {"fileName":"https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&format=guided","lineNumber":89,"stack":"@https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&format=guided:89\n_firebugInjectedEvaluate(\"with(_FirebugCommandLine){var i = 0;\\ntry {\\n i += t;\\n}\\ncatch (e) {\\n console.log(e);\\n console.log(JSON.stringify(e));\\n}\\n\\n};\")@https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&format=guided:87\n_firebugEvalEvent([object Event])@https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&format=guided:67\n"} Here the result of console.log(JSON.stringify(e)) is what I expected. But why did it the console.log(e) line affect its behaviour? In Firefox 4 and Google Chrome I don't need this extra statement to have it work fine. Reproducible: Always
Ryan, since this works in Firefox 4, it would be super-handy if you could find the regression window for when this stopped working. http://harthur.github.com/mozregression/ is a tool to help you do this as painlessly as possible.
I suspect this changed when various properties of Error objects were made non-enumerable (per spec). evilpies probably remembers details better than I do, as he implemented the change as I recall. If that's the case this behavior is by design.
The behaviour is like this since 14 Apr, pushlog: http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=6bcaec19d09e&tochange=aa200a803e07 Perhaps related to this: http://hg.mozilla.org/mozilla-central/rev/9743d95d473e But why would the console.log(e) statement affect the output of JSON.stringify?
So this is curious. When I do |console.log(e)|, what I see in the Web Console is: (new ReferenceError("t is not defined", "file:///Users/bzbarsky/test.html", 4)) In fact, here's a testcase that shows the problem in the JS shell: try { t; } catch (e) { print(JSON.stringify(e)); e.toSource(); print(JSON.stringify(e)); } The two print() calls print different things. Why does the toSource() matter here?
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Strange error handling → Properties on an Error become enumerable after toSource is called?
Oh, I can replace the toSource with Object.getOwnPropertyDescriptor(e, "fileName") and the same thing happens. And the descriptor of course lists the property as enumerable.
probably triggers a resolve hook?
Ah, resolve hook but no enumerate hook. That's not kosher. If the resolve hook resolves properties, the enumerate hook has to make sure they're enumerated. Easy fix for anyone with time to make it.
Fixed by bug 724768.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Assignee: general → jwalden+bmo
Depends on: 724768
Target Milestone: --- → mozilla28
Ryan, please verify this is fixed in Firefox 28.
Flags: needinfo?(ryanli)
Whiteboard: [qa-]
Verified.
Flags: needinfo?(ryanli)
Thanks Ryan.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.