Skip to content

Adding case for super access of a module namespace TDZ binding#5000

Open
caiolima wants to merge 1 commit intotc39:mainfrom
caiolima:module-ns-super-access-tdz
Open

Adding case for super access of a module namespace TDZ binding#5000
caiolima wants to merge 1 commit intotc39:mainfrom
caiolima:module-ns-super-access-tdz

Conversation

@caiolima
Copy link
Contributor

This PR is adding a case where we have an access to a TDZ biding of a namespace module using super.prop. The case here is that we should throw a ReferenceError instead of a TypeError, because OrdinarySet calls Receiver.[[GetOwnProperty]] before it tries to write into the object. It's important to notice that Receiver is a namespace object, because super() will change this biding before super.foo gets executed, and OrdinarySet gets executed because super creates a reference record where [[Base]] == [[FunctionObject]].[[HomeObject]].

It is related with #4980.

@caiolima caiolima requested a review from a team as a code owner March 18, 2026 15:49
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case looks good. It might be worth adding one that is the same but has a set foo(_) {} setter in the base class, and then it should not throw, right?

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Mar 18, 2026

Just to double check that I'm understanding correctly. The ReferenceRecord for the lhs is:

  • [[Base]]: A.prototype
  • [[ReferencedName]]: foo
  • [[Strict]]: true
  • [[ThisValue]]: ns

In PutValue we call A.prototype.[[Set]](ns, "foo", ...). A.prototype has no "foo", so it calls OrdinarySet(ns, "foo", ...). OrdinarySet calls ns.[[GetOwnProperty]]("foo"), which calls eventually gets ns.foo and throws a ReferenceError.

  • If that ReferenceError was not thrown (because foo is not in TDZ) then later when doing the actual Set we get a TypeError.
  • If A.prototype had a "foo" setter, we'd call it and exit before throwing the ReferenceError.

I'm approving assuming that my understanding of why this test is like this is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants