-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editorial: use dot notation for accessing internal slots #591
Conversation
Some things I didn't change... There are 18 occurrences of
which I could conceivably have changed to
but didn't. Similarly 1 occurrence of
Also, there are lots of occurrences of
which could be changed to something like
but I left those unchanged. (Likewise the negative version.) Finally, we could use dot notation for internal methods more. I.e., there are occurrences of
and
that you might want changed to
Let me know if you want a follow-up commit for any of those changes. |
Will take a look in a few minutes, but did you mean to include 216a965? I like the change anyway...
Not a fan of this, current convention is better :)
I feel like this is a bit confusing - does it mean [[Foo]] has a value that is not undefined, or that the slot is there? I think the current convention is fine for now.
I think these are good! Can you think of downsides? It removes the explicit verbage telling you the slot is a method, but from what I can see that is very obviously implied by context in all of the usages... |
Do we need "the value of" everywhere? Seems unnecessary to me. Other than that (and the merge conflict I created), this change seems great! |
+1 for removing "the value of" |
Yup, because it allowed me to include those steps in the systematic changes of the main commit.
It might be that a different verb would be less confusing. (I thought of suggesting
Okay.
That was the only downside I could think of. I'll add a commit for those changes.
That occurred to me too, but I decided to leave it alone. I agree that it seems superfluous in text such as
and
But consider
vs
I think some people might read the latter as meaning that |
I disagree that "the value of" helps in those cases. I think most spec readers have enough experience with programming languages and spec-prose to understand that variable assignment is not generally pointer assignment. |
@@ -6292,7 +6292,7 @@ | |||
1. If _p_ is *null*, let _done_ be *true*. | |||
1. Else if SameValue(_p_, _O_) is *true*, return *false*. | |||
1. Else, | |||
1. If the [[GetPrototypeOf]] internal method of _p_ is not the ordinary object internal method defined in <emu-xref href="#sec-ordinary-object-internal-methods-and-internal-slots-getprototypeof"></emu-xref>, let _done_ be *true*. | |||
1. If _p_.[[GetPrototypeOf]] is not the ordinary object internal method defined in <emu-xref href="#sec-ordinary-object-internal-methods-and-internal-slots-getprototypeof"></emu-xref>, let _done_ be *true*. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think it is a good change, because at first reading it may be interpreted as "If the value of p.[[GetPrototypeOf]]"...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that first reading correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bterlson Yes if we consider that we have an internal slot whose value is an internal method. But I like to keep the distinction between internal slots and internal methods.
For clarity, I think it is a good idea to use the notation O.[[Foo]] only when it specifically means: "the value of [[Foo]]’s internal slot of O". |
Regarding "the value of", I think we can make it clear by tightening up the description in 6.2.1 to say: For example, if R is the record shown in the previous paragraph then R.[[Field2]] is shorthand for “the value of the field of R named [[Field2]]”.` |
(except that Objects aren't Records, they just use the same notation for internal slots/methods) |
Yes, that should be clarified as well :) |
What do you intend to be excluded by emphasizing the words "the value of"? (Perhaps you mean that we shouldn't change And by saying "slot", do you mean to exclude internal methods? |
For example, "O.[[Foo]] exists" when it means "O has a [[Foo]] internal slot".
Probably, yes. For internal methods, use only the notation "O.[Foo]", and use it only when it means: "the value returned by calling the [[Foo]] internal method of O with argument bar. |
... in the 4 places where it is preceded by: Let _args_ be the arguments object. (Prep for subsequent refactor.)
Specifically, change: the [[Foo]] internal slot of _O_ -> _O_.[[Foo]] (132 occ) _O_'s [[Foo]] internal slot -> _O_.[[Foo]] (265 occ) (Resolves issue tc39#574)
I am personally fine with the conceptual model where internal methods are internal slots with function-like values, but in the interest of moving this along without creating massive rebasing headaches, I think we can take everything but 000be90 and get a huge win. We can discuss using the dot-convention for methods in a separate issue. Thoughts @jmdyck? |
Fine with me. (Though I'm not sure how it works git-wise: do I resubmit 000be90 as a new PR, or do you create it, or do you just want the topic discussed first?) |
I'm sure there's a million better ways to do it, but the way I would do it is to something like
|
Note that [[RegExpMatcher]] contains a procedure, but is (rightfully) an internal slot. My guess is that we are spoiled by the JS object model where the distinction between methods and properties is blurred. :-P |
Okay, done, I think. |
Looks like you've done it, thanks! @jmdyck are you interested in doing a follow-up pr for removal of "the value of"? I can put one up too if you'd like, no worries. |
I'll think about it, but I've got another PR to do first. |
<3 yaaaay this makes specs so much more readable. Going to go change streams now. |
@ was originally introduced as a shorthand, since the ECMAScript spec always used the longhand "the value of the [[X]] internal slot of Y". As of tc39/ecma262#591, ECMAScript has now moved to Y.[[X]] as notation, so we can follow their lead. See also the original discussion where @ was settled on in #178.
Introduce variable _f_ for the active function object, which then allows the use of dot notation for _f_.[[Realm]]. (Should have done this in PR tc39#591.) (This will also allow a later refactoring.)
Introduce variable _f_ for the active function object, which then allows the use of dot notation for _f_.[[Realm]]. (Should have done this in PR #591.) (This will also allow a later refactoring.)
Fixes w3c#336. See the history here in whatwg/streams#178 → tc39/ecma262#574 → tc39/ecma262#591 → whatwg/streams@7791c58. My bad for leading people down this path.
Fixes w3c#336. See the history here in whatwg/streams#178 → tc39/ecma262#574 → tc39/ecma262#591 → whatwg/streams@7791c58. My bad for leading people down this path.
Fixes #336. See the history here in whatwg/streams#178 → tc39/ecma262#574 → tc39/ecma262#591 → whatwg/streams@7791c58. My bad for leading people down this path.
Specifically, change:
and
to
(Resolves issue #574)