Assertion failure: cls.names() with default export and unnamed class expression

RESOLVED FIXED in Firefox 53

Status

()

--
critical
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: anba, Assigned: jonco)

Tracking

(Blocks: 1 bug)

Trunk
mozilla53
Points:
---

Firefox Tracking Flags

(firefox53 fixed)

Details

Attachments

(1 attachment)

(Reporter)

Description

2 years ago
Test case:
---
parseModule("export default (class {})");
---


Asserts with:
---
Assertion failure: cls.names(), at /home/andre/git/mozilla-central/js/src/builtin/ModuleObject.cpp:1181
---


Back trace:
---
#0  0x000000000059ec06 in js::ModuleBuilder::processExport (this=0x7fffffffb200, pn=0x7ffff69fc110) at /home/andre/git/mozilla-central/js/src/builtin/ModuleObject.cpp:1181
#1  0x00000000004bfda3 in js::frontend::Parser<js::frontend::FullParseHandler>::exportDeclaration (this=0x7fffffffbf00)
    at /home/andre/git/mozilla-central/js/src/frontend/Parser.cpp:5142
#2  0x00000000004d1ddc in js::frontend::Parser<js::frontend::FullParseHandler>::statementListItem (this=0x7fffffffbf00, yieldHandling=js::frontend::YieldIsKeyword, 
    canHaveDirectives=true) at /home/andre/git/mozilla-central/js/src/frontend/Parser.cpp:7182
#3  0x00000000004d397e in js::frontend::Parser<js::frontend::FullParseHandler>::statementList (this=0x7fffffffbf00, yieldHandling=js::frontend::YieldIsKeyword)
    at /home/andre/git/mozilla-central/js/src/frontend/Parser.cpp:3836
#4  0x00000000004bb35b in js::frontend::Parser<js::frontend::FullParseHandler>::moduleBody (this=0x7fffffffbf00, modulesc=0x7fffffffb180)
    at /home/andre/git/mozilla-central/js/src/frontend/Parser.cpp:2021
#5  0x0000000000ce84bf in BytecodeCompiler::compileModule (this=0x7fffffffb8b0) at /home/andre/git/mozilla-central/js/src/frontend/BytecodeCompiler.cpp:397
#6  0x0000000000ce9334 in js::frontend::CompileModule (cx=0x7ffff6965000, optionsInput=..., srcBuf=..., alloc=..., sourceObjectOut=0x0)
    at /home/andre/git/mozilla-central/js/src/frontend/BytecodeCompiler.cpp:598
#7  0x0000000000ce9419 in js::frontend::CompileModule (cx=0x7ffff6965000, options=..., srcBuf=...) at /home/andre/git/mozilla-central/js/src/frontend/BytecodeCompiler.cpp:609
#8  0x0000000000448d29 in ParseModule (cx=0x7ffff6965000, argc=1, vp=0x7ffff151e090) at /home/andre/git/mozilla-central/js/src/shell/js.cpp:3998
...
---



And possibly related:
---
parseModule("export default (class A {})")
---

Expected: No SyntaxError
Actual: SyntaxError: local binding for export 'A' not found
(Reporter)

Updated

2 years ago
Blocks: 568953
(Assignee)

Comment 1

2 years ago
Created attachment 8826676 [details] [diff] [review]
bug1320993-export-default-class-expr

The problem is that we get confused between |export default class ...| and |export default EXPRESSION| where the latter expression is a class expression.

The patch refactors ModuleBuilder::processExport to check for the presence of the second child of the parse node to determine whether it's an export default expression.  This is always present in this case (see the parser code here http://searchfox.org/mozilla-central/source/js/src/frontend/Parser.cpp#5093).

I also fixed the indentation in this method.
Assignee: nobody → jcoppeard
Attachment #8826676 - Flags: review?(shu)

Comment 2

2 years ago
Comment on attachment 8826676 [details] [diff] [review]
bug1320993-export-default-class-expr

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

::: js/src/builtin/ModuleObject.cpp
@@ +1196,5 @@
>          break;
> +      }
> +
> +      default:
> +          MOZ_CRASH("Unexpected parse node");

2 spaces here. Our whacky switch style.
Attachment #8826676 - Flags: review?(shu) → review+

Comment 3

2 years ago
Pushed by jcoppeard@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/473e99dde77d
Fix exporting default class expression r=shu

Comment 4

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/473e99dde77d
Status: NEW → RESOLVED
Last Resolved: 2 years ago
status-firefox53: affected → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
You need to log in before you can comment on or make changes to this bug.