Closed Bug 1611777 Opened 5 years ago Closed 5 years ago

Optional chaining assertions and unreachable code

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla74
Tracking Status
firefox74 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(16 files)

(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
var a, b;
(a + b)?.()

asserts with:

Assertion failure: (kind == ParseNodeKind::ArrayExpr || kind == ParseNodeKind::ObjectExpr || kind == ParseNodeKind::TrueExpr || kind == ParseNodeKind::FalseExpr || kind == ParseNodeKind::StringExpr || kind == ParseNodeKind::NumberExpr || kind == ParseNodeKind::RawUndefinedExpr || kind == ParseNodeKind::NullExpr || kind == ParseNodeKind::Name || kind == ParseNodeKind::Function || kind == ParseNodeKind::ThisExpr || kind == ParseNodeKind::TaggedTemplateExpr || kind == ParseNodeKind::TemplateStringExpr || kind == ParseNodeKind::AwaitExpr || kind == ParseNodeKind::RegExpExpr || kind == ParseNodeKind::ClassDecl || kind == ParseNodeKind::CommaExpr || kind == ParseNodeKind::NewExpr || kind == ParseNodeKind::SetThis || kind == ParseNodeKind::NewTargetExpr) (Unknown ParseNodeKind for OptionalChain), at /home/andre/hg/mozilla-central/js/src/frontend/BytecodeEmitter.cpp:7833

({m() { super[0]?.() }}).m()

asserts wth:

Assertion failure: initialDepth_ + 2 == depth, at /home/andre/hg/mozilla-central/js/src/frontend/OptionalEmitter.cpp:58

anba -- let me know if i can help with this.

We already assert that this case isn't allowed in the bytecode emitter. Also
report a syntax error to match normal property access.

That way we don't need the explicit cast.

Depends on D61147

Moves the isSuper() method from the base class to the (non-optional) derived
classes, because super?.x isn't valid syntax, so it's confusing to be able to
ask if an optional property access is applied on super.

The next part will further simplify BytecodeEmitter::emitDelete{Element,Property}InOptChain().

Depends on D61148

The child node of a DeleteOptionalChainExpr node can't be a super-property
accessor, so we can remove this code.

Drive-by: Reindent some stack comments.

Depends on D61151

super?.() isn't valid code, so we don't need to handle this case.

Depends on D61152

The previous list contained some invalid entries (await and comma-expression)
and was missing some possible parse node kinds.

Depends on D61153

Aligns emitOptionalElemExpression() with emitOptionalDotExpression(), so it's
easier to compare both methods against each other.

Depends on D61154

nextMember is never nullptr, so we don't need to test for it.

Depends on D61155

All callers pass allowCallSyntax=true, so we can omit this parameter.

Depends on D61156

Using optionalExpr matches the spec grammar more closely. This change also
modifies the reported error message. ++a?.b reported before this change
"unexpected token: '?.'", but now reports "invalid increment/decrement operand".

Depends on D61158

  • We don't need to test for tt == TokenKind::Eof when we return for
    tt != TokenKind::OptionalChain anyway.
  • Omit local variable for the result value and instead use a tail-call. This
    matches the local style in the parser more closely.

Depends on D61160

This change allows the bytecode emitter to use JSOp::FunCall resp. JSOp::FunApply
for calls in optional chain expressions.

Depends on D61161

This allows us to emit JSOp::CallIgnoresRv in optional chains.

Depends on D61162

Pushed by csabou@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/bdb8620ff7f5 Part 1: Report syntax error for optional property access in self-hosting code. r=yulia https://hg.mozilla.org/integration/autoland/rev/45f7fa06cc3c Part 2: Merge same blocks in emitDeleteOptionalChain(). r=yulia https://hg.mozilla.org/integration/autoland/rev/9615eaa325ed Part 3: Change emitOptionalCalleeAndThis() parameter to use CallNode. r=yulia https://hg.mozilla.org/integration/autoland/rev/95890e60c691 Part 4: `super` can't occur on the left-hand side of an optional chain. r=yulia https://hg.mozilla.org/integration/autoland/rev/9dba40e8b408 Part 5: Remove unnecessary super-handling in optional delete. r=yulia https://hg.mozilla.org/integration/autoland/rev/4a8a350bba27 Part 6: Crash for unexpected super-base in optional call. r=yulia https://hg.mozilla.org/integration/autoland/rev/5c9241e7ce20 Part 7: Add missing entries to list of valid optional chain start expressions. r=yulia https://hg.mozilla.org/integration/autoland/rev/958adec63532 Part 8: Add missing emitGet in emitOptionalElemExpression. r=yulia https://hg.mozilla.org/integration/autoland/rev/fa5be03a588c Part 9: Replace an if-statement with an assertion. r=yulia https://hg.mozilla.org/integration/autoland/rev/e82fbc9dee63 Part 10: Remove unnecessary "allowCallSyntax" parameter from Parser::optionalExpr. r=yulia https://hg.mozilla.org/integration/autoland/rev/468ff3d2cf8e Part 11: Support optional chaining in class heritage expression. r=yulia https://hg.mozilla.org/integration/autoland/rev/849b4d84f743 Part 12: Use optionalExpr() for update expressions to match spec grammar. r=yulia https://hg.mozilla.org/integration/autoland/rev/9c5786b1bccb Part 13: Remove unused default arguments from parser methods. r=yulia https://hg.mozilla.org/integration/autoland/rev/46d27864b908 Part 14: Simplify two lines in optionalExpr(). r=yulia https://hg.mozilla.org/integration/autoland/rev/075c4404c2c8 Part 15: Support FunCall/FunApply optimisations for optional chaining. r=yulia https://hg.mozilla.org/integration/autoland/rev/65c1c7d322ed Part 16: Pass through ValueUsage in optional chains. r=yulia
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: