Re: [heycam/webidl] Editorial: make more iterator-related stuff imperative (#862)

TimothyGu commented on this pull request.



> +
+    1.  If |definition| has an [=indexed property getter=], then:
+        1.  Perform [=!=] [$CreateMethodProperty$](|target|, {{@@iterator}},
+            {{%ArrayProto_values%}}).
+    1.  If |definition| has a [=value iterator=], then:
+        1.  Assert: |definition| has an [=indexed property getter=].
+        1.  Perform [=!=] [$CreateDataProperty$](|target|, "<code>entries</code>",
+            {{%ArrayProto_values%}}).
+        1.  Perform [=!=] [$CreateDataProperty$](|target|, "<code>keys</code>",
+            {{%ArrayProto_keys%}}).
+        1.  Perform [=!=] [$CreateDataProperty$](|target|, "<code>values</code>",
+            {{%ArrayProto_values%}}).
+        1.  Perform [=!=] [$CreateDataProperty$](|target|, "<code>forEach</code>",
+            {{%ArrayProto_forEach%}}).
+    1.  If |definition| has a [=pair iterator=], then:
+        1.  Define the {{@@iterator}} and <code>entries</code> methods:

Ah got it. This makes me think that there's value in the readability and navigability. The whole algorithm creates seven different functions, without anchors for each. In ES, this would correspond to seven sections; while here, it's one section. I think the optimal value is somewhere in between. (Putting everything into a single algorithm/section would be even worse for maplike/setlike: each one of those declarations creates 6–7 methods.)

Maybe something more similar to the original section layout (except the `entries`, `keys`, and `values` sections are renamed to "`entries` for pair iterators" and so on), and in the root section do something like

1. Let _steps_ be the algorithm steps defined in §&nbsp;3.7.1 `entries` for pair iterators.
2. Let _F_ be ! CreateBuiltinFunction(_steps_, « », _realm_).

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/pull/862#discussion_r397528040

Received on Tuesday, 24 March 2020 23:45:47 UTC