Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 7fbe85cfbfdc709c1d4c784a936905a78a2a2138
      
https://github.com/WebKit/WebKit/commit/7fbe85cfbfdc709c1d4c784a936905a78a2a2138
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-09-29 (Tue, 29 Sep 2026)

  Changed paths:
    A JSTests/stress/optional-chaining-parenthesized-tagged-template-nullish.js
    A JSTests/stress/optional-chaining-parenthesized-tagged-template-this.js
    M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

  Log Message:
  -----------
  [JSC] Tagged template with a parenthesized optional chain tag should keep 
`this`
https://bugs.webkit.org/show_bug.cgi?id=325401

Reviewed by Yusuke Suzuki.

    const o = { b() { return this; } };
    (o?.b)`x`; // undefined, should be o

321867@main made `(a?.b)(x)` call the function with `a` as `this` by loading 
the callee and
`this` inside the chain with OptionalChainNode::emitCallee. A tagged template 
takes `this` from
its tag in the same way [1], but TaggedTemplateNode still evaluated the 
OptionalChainNode as a
value because it is not a location, and called the tag with an undefined `this`.

This patch uses OptionalChainNode::emitCallee in TaggedTemplateNode as well.

[1]: https://tc39.es/ecma262/#sec-tagged-templates-runtime-semantics-evaluation

Tests: JSTests/stress/optional-chaining-parenthesized-tagged-template-nullish.js
       JSTests/stress/optional-chaining-parenthesized-tagged-template-this.js

* JSTests/stress/optional-chaining-parenthesized-tagged-template-nullish.js: 
Added.
(shouldBe):
(const.arg):
(const.key):
(shouldThrowTypeError):
(Private.prototype.method):
(Private.call):
(Private):
(test):
* JSTests/stress/optional-chaining-parenthesized-tagged-template-this.js: Added.
(shouldBe):
(const.arg):
(const.key):
(Private.prototype.method):
(Private.call):
(Private):
(const.receiver.b):
(const.receiver.c.d):
(const.receiver.get getter):
(const.receiver.sum):
(Field):
(testTailPosition):
(testConditionContext):
(test):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::TaggedTemplateNode::emitBytecode):

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to