[webkit-changes] [WebKit/WebKit] 23879e: Ignored TypeError upon optional function call chain

Ross Kirsling noreply at github.com
Thu Nov 24 21:45:11 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 23879e6bd1a0b8a5ee2718d9faa5d66514134218
      https://github.com/WebKit/WebKit/commit/23879e6bd1a0b8a5ee2718d9faa5d66514134218
  Author: Ross Kirsling <rkirsling at gmail.com>
  Date:   2022-11-24 (Thu, 24 Nov 2022)

  Changed paths:
    M JSTests/stress/optional-chaining.js
    M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
    M Source/JavaScriptCore/parser/ASTBuilder.h
    M Source/JavaScriptCore/parser/NodeConstructors.h
    M Source/JavaScriptCore/parser/Nodes.h
    M Source/JavaScriptCore/parser/Parser.cpp

  Log Message:
  -----------
  Ignored TypeError upon optional function call chain
https://bugs.webkit.org/show_bug.cgi?id=247431

Reviewed by Yusuke Suzuki.

Evidently, our implementation of optional chaining has always interpreted `a.b?.().c` and `a.b()?.c` as `a.b?.()?.c`.
(Hard to believe, but I guess giving more undefineds and less TypeErrors must not have troubled folks that much...)

The issue is rather JSC-specific, in that it's a confused result of our "function call node menagerie" --
ExpressionNode::isOptionalChainBase was repurposed for optional calls like `x?.()`, but that failed to recognize
that the result of a call can also be the base of an optional chain, as in `x()?.y`.

This patch adds ExpressionNode::isOptionalCall and distinguishes optional call as a separate concept throughout.

* JSTests/stress/optional-chaining.js:
(shouldThrowTypeError):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::EvalFunctionCallNode::emitBytecode):
(JSC::FunctionCallValueNode::emitBytecode):
(JSC::FunctionCallResolveNode::emitBytecode):
(JSC::FunctionCallBracketNode::emitBytecode):
(JSC::FunctionCallDotNode::emitBytecode):
(JSC::CallFunctionCallDotNode::emitBytecode):
(JSC::HasOwnPropertyFunctionCallDotNode::emitBytecode):
(JSC::ApplyFunctionCallDotNode::emitBytecode):
* Source/JavaScriptCore/parser/ASTBuilder.h:
(JSC::ASTBuilder::createOptionalChain):
(JSC::ASTBuilder::makeFunctionCallNode):
* Source/JavaScriptCore/parser/NodeConstructors.h:
(JSC::FunctionCallValueNode::FunctionCallValueNode):
(JSC::FunctionCallResolveNode::FunctionCallResolveNode):
(JSC::FunctionCallBracketNode::FunctionCallBracketNode):
(JSC::FunctionCallDotNode::FunctionCallDotNode):
(JSC::CallFunctionCallDotNode::CallFunctionCallDotNode):
(JSC::ApplyFunctionCallDotNode::ApplyFunctionCallDotNode):
(JSC::HasOwnPropertyFunctionCallDotNode::HasOwnPropertyFunctionCallDotNode):
* Source/JavaScriptCore/parser/Nodes.h:
(JSC::ExpressionNode::isOptionalCall const):
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseMemberExpression):

Canonical link: https://commits.webkit.org/257004@main




More information about the webkit-changes mailing list