ECMAScript仕様輪読会 #15
前回: ECMAScript仕様輪読会 #14
Scrapboxの招待リンク: https://scrapbox.io/projects/esspec/invitations/85b96c9fa718ce5185e307196ed8fb53
connpass: https://esspec.connpass.com/
Discord: https://discord.gg/59S3y6weQj
Twitter hashtag: #esspec
自己紹介 (近況報告)
syumai
Twitter: https://twitter.com/__syumai GitHub: https://github.com/syumai
GoとTSやってます
先週京都から戻ってきました
最近詰将棋をやってます
IPAの募集が始まったので申し込みました
Jun Yasumura / harupiyo Jun Yasumura.icon
HTML5.0仕様書を読んだ経験あり
英語はじめました https://zenn.dev/harupiyo/scraps/858cffd521fa0d
Interlisp 始めました→こんなの http://sumim.no-ip.com/collab/76
最近仮想マシンがよく壊れる...気軽に試せる実機(2011年のThinkpad T420s)を買いました
noyannoyan.icon
最近はセキュリティを学んでいます
おーみーaumy.icon
Twitter: aumy_f GitHub: aumyf
進捗妨害要素が多すぎる
ThinkPadのLinuxいじり
モンハン
tars0x9752 (たーず / naoki aoyama)
proposal-temporal の仕様読んだり polyfill のコード読んだり
proposal-temporal, temporal-polyfill に コントリビュートした(してる)
dual package hazard に詳しくなった
少しづつhome-managerでの管理に移行してみている. https://github.com/tars0x9752/home
yebis0942yebis0942.icon
近所のスーパーのタイムセールで勝利してきました
https://gitlab.com/src_prepare/src_prepare-overlay/-/merge_requests/286
Gentooの野良ebuild(パッケージ定義)にパッチ送ったりしていました
Nozomu Ikuta NozomuIkuta.icon
Twitter: https://twitter.com/NozomuIkuta
GitHub: https://github.com/NozomuIkuta
パスポート再申請しました
前回のあらすじ
21:30まで休憩 ٩(ˊᗜˋ*)و
---
今回の範囲
6.2.4 The Reference Record Specification Type の The following abstract operations are used in this specification... から
https://tc39.es/ecma262/
6.2.4 The Reference Record Specification Type
binding: 「変数に値を束縛する」という意味で使われる
もともとはラムダ計算の用語だったらしい
雑談: RubyにはBindingクラスがある
bindingとassignmentの違いは?
「再代入不可」「コンパイル時に値埋め込み」のように確定的な動作をbindingと呼ぶことが多そう
ECMAScript: let vs const -> 後者は再代入不可
Rust: ...
[[ThisValue]]
[[ThisValue]] は super keyword の場合のみ存在する.
[[ThisValue]] があるときは Super Reference Record と呼ばれる
abstract operation
IsPropertyReference ( V )
IsUnresolvableReference ( V )
IsSuperReference ( V )
[[ThisValue]]がemptyでなければsuperからの呼び出しと判定される
IsPrivateReference ( V )
Private Nameはクラスのプライベートプロパティのことらしい
専用の型があるんですね
単に先頭に#が付いたStringとして表現してもよさそうだが…?
GetValue ( V )
reference value じゃなかったらそのまま V を返す
step2: Vの型を限定していないのが気になる
それまでのabs opはVの型をreference valueと限定していた
親クラスのstatic methodを参照したら何が起きるのか?
code:js
class Rectangle {
static msg = 'I have 4 sides';
static logNbSides() {
return this.msg;
}
}
class Square extends Rectangle {
static msg = 'Hoge Fuga';
static logDescription() {
return super.logNbSides();
}
}
Square.logDescription(); // 'Hoge Fuga'
class Rectangle {
static msg = 'I have 4 sides';
static logNbSides() {
return this.msg;
}
}
class Square extends Rectangle {
static logDescription() {
return super.logNbSides();
}
}
Square.logDescription(); // 'I have 4 sides'
Reference Recordの内容
code:js
// Reference Recordの内容
class Rectangle {
static msg = 'I have 4 sides';
static logNbSides() {
return this.msg;
// return Reference Record {
// Base: ???, // => Square.logDescription(); を呼んだら Square になった
// ReferencedName: "msg",
// Strict: false,
// ThisValue: empty
// }.
}
}
class Square extends Rectangle {
static logDescription() {
return super.logNbSides();
// return Reference Record {
// Base: Square,
// ReferencedName: "logNbSides",
// Strict: false,
// ThisValue: Rectangle
// }.
}
}
superのruntime semanticsを追う
https://tc39.es/ecma262/#sec-super-keyword-runtime-semantics-evaluation
super.IdentifierNameを読む
step 1, 2でthisを解決している
step 5でreference recordを作っている
Ordinary objectの[[Get]]
定義: https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-get-p-receiver
プロパティが存在しない場合は継承元に遡って探索する
NOTE:
not accessible outside of the above abstract operation and the ordinary object [[Get]] internal method
「baseObjのスコープが制限されている」と言いたいようだが
"above"ってどういうものを指してるんだろう?
PutValue ( V, W )
アルゴリズム定義の前にVとWの関係性を書いておいてほしい気持ち
V: 代入先のreference record
W: 代入する値
Step 4: 4. If IsUnresolvableReference(V) is true, then
var, let, constなしで未定義の変数名に代入したらグローバル変数になる挙動っぽい
Step 4-aでstrictモードならエラーで落としている
code:js
(() => { 'use strict'; foo = 1; })() // Uncaught ReferenceError: foo is not defined
Step 5-d: If succeeded is false and V.[[Strict]] is true, throw a TypeError exception.
getterに代入したときはsucceeded is falseになる
code:js
const obj = { get a () { return 1 } }
obj.a = 2 // 2
obj.a // 1 (非strict modeでは単に代入が無視される)
コメント: strict modeじゃなくてもエラーにしてほしいですね