ECMAScript仕様輪読会 #12
前回: ECMAScript仕様輪読会 #11
Scrapboxの招待リンク: https://scrapbox.io/projects/esspec/invitations/85b96c9fa718ce5185e307196ed8fb53
connpass: https://esspec.connpass.com/
Discord: https://discord.gg/59S3y6weQj
Twitter hashtag: #esspec
自己紹介 (近況報告)
syumai syumai.icon
Twitter: https://twitter.com/__syumai GitHub: https://github.com/syumai
GoとTSやってます
Cloudflare Workers
https://github.com/syumai/workers
親知らず抜き終わりました
Jun Yasumura / harupiyo Jun Yasumura.icon
HTML5.0仕様書を読んだ経験あり
英語はじめました https://zenn.dev/harupiyo/scraps/858cffd521fa0d
noyannoyan.icon
Firefoxにバグ報告?をしている
https://bugzilla.mozilla.org/show_bug.cgi?id=1771863
あとで考えると、挙動として正しい気がしてきた
Windowsの環境構築をした結果、Macを開発機にしたい気持ちに
おーみーaumy.icon
Twitter: aumy_f GitHub: aumyf
寝てた
ThinkPadの直販が来ない
仕事で使ってるMacBookにmacOS 13が降ってこないことが確定した
言語処理系に気持ちが向いている
tars0x9752 (たーず / naoki aoyama)
使ってなかったWindowsののーとぱそこんにZorin OS 16 Coreを入れた
yebis0942yebis0942.icon
先々週以降に仕様書に入ったコミットを確認するやつをブラッシュアップしました
code:bash
open https://github.com/tc39/ecma262/compare/$(curl "https://api.github.com/repos/tc39/ecma262/commits?per_page=1&until=$(date -d "-15 days" --iso-8601)" | jq -r .0.sha)...main
https://github.com/tc39/ecma262/compare/7c120199bf159960d46e216aa090887c1e2e584c...main
コミットちょっと多め、全部editorial
Nozomu Ikuta NozomuIkuta.icon
Twitter: https://twitter.com/NozomuIkuta
GitHub: https://github.com/NozomuIkuta
Vue Fes Japan Online 2022 CFP 募集中です!(~6/30)
数回欠席して追いつかるか不安
Cmd+i したら "profile pageつくれ"と言われました笑
アイコンできました!ありがとうございます!ページ作成からアイコンマクロ反映までラグがあるみたい
このへんの手順が難しいですよね。タイムラグなるほど…/help-jp/自分のページyebis0942.icon
前回のあらすじ
This specification recognizes different kinds of exotic objects by those objects' internal methods. ...
同じ振る舞いをするとしても、持っているinternal methodが違うとしたら別のexotic objectとなる
具体的にどういうことなのか?
たとえば、object Aはbuy, object Bはpurchaseというメソッドを持っていて、動作は同じだけどメソッドは違う、とか?
違うkindだとしたら何が起きるのかもよく分からない
---
今回の範囲
6.1.7.2 Object Internal Methods and Internal Slots の The “Signature” column of Table 4 and other similar tables... から
https://tc39.es/ecma262/
6.1.7.2 Object Internal Methods and Internal Slots
The type names used in signatures refer to the types defined in clause 6 augmented by the following additional names.
additional nameって何なんだろうyebis0942.icon
一つしかない(namesでない)ですが、anyなのかなとおもってみましたnoyan.icon
なるほど!ありがとうございますyebis0942.icon
Table 4: Essential Internal Methods
() → Object | Null
返り値の型がObjectかNullだという意味でよさそう
[[SetPrototypeOf]]
失敗したらfalseを返すと書かれているが、どんな場合に失敗するのか?
10 Ordinary and Exotic Objects Behavioursで実装の詳細が定義されてそう
[[Get]]
引数のReceiverは常にObjectなのか?
OrdinaryCallBindThisでToObjectを呼んでるので、Objectであることは保証されてそう
yebis0942.icon「ReceiverにECMAScript specification typeが渡ることはないはず」と言うべきところで「language typeが〜」と言ってしまってました。混乱させてしまってたらすみません
引数の順番が一定してない問題
Internal methodとしての[[Get]]のsignatureはGet(propertyKey, Receiver)
Abstract Opとしての[[Get]]のsignatureはGet(object, propertyKey)
https://tc39.es/ecma262/#sec-get-o-p
(英語) be present: 存在する
if the property was not deleted and is still present
そのプロパティが削除されず、存在しつづけていた場合
Table 5: Additional Essential Internal Methods of Function Objects
functionとして呼び出せるobjectがサポートするessential internal methods
function object: [[Call]]を持つobject
constructor: [[Construct]]を持つobject
[[Construct]]を持っている場合は[[Call]]も持っている必要がある
[[Call]]
[[Construct]]
newかsuperの呼び出しでオブジェクトを生成する
yebis0942.iconcallableなもの: function, arrow function, classぐらい?
yebis0942.iconcallableかつconstructorではないものってarrow function以外にあるんだろうか(ない気がする)
(英語) clause: 節
本文中のclause 10とかメンテするの大変では、と思ったらspec.htmlで<emu-xref href="#sec-ordinary-and-exotic-objects-behaviours"></emu-xref>って書くと自動的にいい感じのリンクにしてくれるらしい
6.1.7.3 Invariants of the Essential Internal Methods
(英語) invariants: 変わらないもの
訳語難しい
ECMAScript objectと仕様書中のすべての標準のexotic objectのinternal methodsに関するinvariantsがある
ECMAScript Proxy objectsは実行時チェックによってこのinvariantsを保つ
(関係ありそう? MDN Meta_programming#handlers_and_traps)
実装が提供するexotic objectもinvariantsを守らないといけない
invariantsを破るとECMAScriptコードが予期しない動作をして、セキュリティ上の問題が起きるかもしれない
そのような場合にも実装のメモリ安全性は保たれなければいけない
実装はinvariantsを迂回する手段を提供してはいけない
Definitions:(用語の定義)
internal methodのtargetとは、internal methodがcallされたobjectである
targetがnon-extensibleであるとは、[[IsExtensible]] -> false or [[PreventExtensions]] -> trueである場合である
non-existentなプロパティとは、non-extensibleなターゲット自身のプロパティとして存在しないプロパティである
SameValueへの参照はSameValue algorithmに従う
yebis0942.icon特記する必要あるだろうか。本文でSameValueを参照するときはSameValue algorithmへのリンクを貼るだろうし…
↓ここからinvariantの規定が始まってそう
Return value:
internal methodの返り値はCompletion Recordでなければならない
そのRecordは以下のどちらかである
[[Type]] = normal, [[Target]] = empty, [[Value]]は以下のinternal methodの定義にある"normal return type"の値
[[Type]] = throw, [[Target]] = empty, [[Value]]はECMAScript language value
[[GetPrototypeOf]] ()
targetがnon-extensibleならば、返り値は常にSameValueであるべき(should)である
なぜ"must"ではなく"should"なんだろう?
他ではmustを使っている
「自然にそうなるだろう」というニュアンスのshouldなのでは
NOTE2: ordinary objectの[[GetPrototypeOf]]を使わないならプロトタイプチェーンは循環してもよい(推奨はされない; should not)。その場合はプロパティアクセスで無限ループに陥ってもよい。
code:js
// 通常のオブジェクトでは循環するチェーンは作れなそう
a = {}; b = {};
Object.setPrototypeOf(a, b)
Object.setPrototypeOf(b, a)
// Uncaught TypeError: can't set prototype: it would cause a prototype chain cycle
[[SetPrototypeOf]] ( V )
non-extensibleならfalse(ただし既存のprototypeとVが同じなら除く)
[[IsExtensible]] ( )
falseを返したら以降はずっとfalseを返さなければいけない
[[PreventExtensions]] ( )
[[GetOwnProperty]] ( P )
fully populated Property Descriptor
a non-configurable, non-writable own data property
たぶん"non-configurable and non-writable"という意味で
[[Configurable]] -> false かつ [[Writable]] -> falseなプロパティという意味っぽい
P's Value attribute
ってことはPはproperty keyじゃなくてpropertyなのか…?
「Pをキーとして取得できるpropertyのvalue」という意味のような気がする
If P's attributes other than
このあたりはGetOwnPropertyのセクションで記述することなのか疑問
may change over time
「後々変わってもよい」ぐらいの意味か
(英語)
However, violation of these invariants must never compromise the memory safety of an implementation.
「これらのinvariantsに違反したとしても、実装のメモリ安全性は保たれなければならない。」
(英語) by means of A: Aを用いて
(英語) circumvent: 制限を迂回すること
(英語) compromise:
https://en.wiktionary.org/wiki/compromise
(computer security) A breach of a computer or network's rules such that an unauthorized disclosure or loss of sensitive information may have occurred, or the unauthorized disclosure or loss itself.
「〈名声などを〉傷つける,汚す」の意味なのでは
(英語): What is "to populate" as used in software development
yebis0942.iconなんでセキュリティの話になるのかよく分かってなかったんだけど、prototype汚染が念頭に置かれているのか
yebis0942.icon「他と重複してる記述が多い」というのは確かに謎で、invariantsというセクションをわざわざ設ける必要性があんまりよくわからない。違反してる処理系が多すぎたということなのか?