Closed Bug 1357483 Opened 7 years ago Closed 7 years ago

Function#toString on a class prints more than it should

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: mgol, Unassigned)

References

Details

Attachments

(1 file)

The following code:

(class C {}) + ''

evaluates to:

"class C {})"

instead of the correct:

"class C {}"

This works fine in current Chrome, Safari & Edge.

The bug exists in latest Nightly, i.e. "55.0a1 (2017-04-18)".
Blocks: 1216630
Oh goddammit.
The bug is that for class expressions without constructors, the ClassNode's pn_pos holds the source offsets. For some reason, parsing parenthesized expressions sets the inner expression's end position to include the right paren, which is what manifests this bug.

I'm seeing what happens if we just... don't do that.
Comment on attachment 8860221 [details] [diff] [review]
Stop changing the end position of parenthesized expression ParseNodes.

Review of attachment 8860221 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/tests/ecma_6/Class/parenExprToString.js
@@ +1,5 @@
> +// Test that parenthesized class expressions don't get their toString offsets
> +// messed up.
> +
> +assertEq((class {}) + '', "class {}");
> +assertEq(((class {})) + '', "class {}");

Might as well invoke .toString() directly on them for utmost clarity, no?
Attachment #8860221 - Flags: review?(jwalden+bmo) → review+
Pushed by shu@rfrn.org:
https://hg.mozilla.org/integration/mozilla-inbound/rev/e064b7cde203
Stop changing the end position of parenthesized expression ParseNodes. (r=Waldo)
https://hg.mozilla.org/mozilla-central/rev/e064b7cde203
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: