whatwg / webidl

Web IDL Standard
https://webidl.spec.whatwg.org/
Other
405 stars 162 forks source link

'this' and nested steps #1175

Open jakearchibald opened 2 years ago

jakearchibald commented 2 years ago

https://webidl.spec.whatwg.org/#this

It isn't clear how nested steps behave in relation to this.

The foo() method steps are:

1. It's fine to access [=this=] here.
2. Queue the following steps:
  1. But is it fine to access [=this=] here?

It feels like WebIDL could explicitly allow the above, by saying this gets its value from the 'closest' constructor steps, getter steps, setter steps, or method steps.

smaug---- commented 1 year ago

I'd be ok having implicit "this" capture only when one is within the same algorithm basically. But if for example in that example, 2.1 was a link to an algorithm elsewhere, "this" shouldn't be useable there, since that would be just hard to read. Reader would effectively have to go up the stack trace to see what "this" is.

annevk commented 1 year ago

Would it prevent GC?

jakearchibald commented 1 year ago

Depends how smart we expect prose to be.

Thinking in JS terms, the queued steps would be GC'd once they'd executed. Therefore things they reference, like [=this=], would no longer be valid references.