Twitter hashtag: #esspec
便利ツール
自己紹介 (近況報告)
syumai
ドラムいい感じになってきました
今日はrtty使ってみます
Jun Yasumura / harupiyo Jun Yasumura.icon
tars0x9752 (たーず / naoki aoyama) tars0x9752.icon
約1周年omedetougozaimasu
最近DIYで曲を作り始めたり
yebis0942yebis0942.icon
esmetaの資料をちょっとだけ読みました
資料みたい・・・noyan.icon
ESMetaのリポジトリに貼られている資料ですが
このあたりとかが内部構造とか成り立ちとかから語り起こされていて面白かったですyebis0942.icon
ACMのPLDI (Programming Language Design and Implementation)という分科会の資料だった 韓国系のアカデミアの方が中心になって作られているのかなー
noyannoyan.icon
Flexispotで机をつくりました
でっかい机があるとたのしい!
Reactの良い記事がでていてよかった
ikuta
30代、徹夜ダメ。
12/24のAdvent Calendarまだやってない
unjsのメンバーになりました
unjsとは何?
unified javascript tools
環境に依存しない汎用的なツール群
nitro: nuxt3の本体
今のnuxtは実はunjsのツールの集合体
前回のあらすじ
今回の範囲
Runtime Semantics: ClassDefinitionEvaluation のステップ実行の続きから
ESMetaの操作メモ
break pointを置く
左側のペインのECMAScript Breakpoints
"Algorithm Name"を指定して+をクリックする
謎: "ClassDefinitionEvaluation", "ClassDefinitionEvaluation:clo"とかの区別がつかないが、これはなんなのか
コントリビューションチャンス: BreakpointsペインのUI見づらいかも。もっといい感じにできるのではないか!
Algorithm stepで変数にbindされている値を見る
左側のペインのECMAScript Environmentを開くと変数の一覧が見れる
コールスタック
Evaluate
BindingClassDeclarationEvaluation
ClassDefinitionEvaluation
yebis0942.iconたぶん中間がいろいろ抜けてそう…
Runtime Semantics: ClassDefinitionEvaluation
ClassDefinitionEvaluationというSDOの定義
引数を取る
with argument hogehoge みたいにして渡されるっぽい
NOTE:
仕様を簡単にするため、private methodsとprivate acessorはprivate fieldsと一緒にclassインスタンスの[[PrivateElement]]スロットに入っている
それぞれのメソッドやアクセサを個別にtrackしなくてもよいような実装戦略を採れるようにするため
private method, private accessorについては
private fieldsは個別にtrackしなければならない
なぜならprivate fieldだけはクラスの初期化時に例外を発生させる可能性があるから
Q. 「個別にtrackする必要がある」というのはどういうことなのか?
「生成された個別のオブジェクトが値を保持する = 個別にtrackする」ということではないか
Q. "an implementation could ..."
A. することもできる(実際にやっているかは知らないけども)ということか?
Q. "then"はどう解釈すべき?
Looking up an instance private method on an object then consists of checking that the class constructor which defines the method has been used to initialize the object, then returning the method associated with the Private Name.
(前文をうけて)そうであれば、Looking upはcheckingとその後の(論理的順序)returningで構成される。
code:js
class A {
// private class field
// private class fieldは初期化時に例外を出す可能性がある
#a = (() => { throw new Error("instantiation of a") })(); // private accessor (setter)
this.#secret = v;
}
// private accessor (getter)
return this.#secretMethod();
}
// private method
return this.#secret;
}
}
DeclarativeEnvironmentに何が束縛されるのか?
ClassBodyの中ではclass fieldに
code:class_fieldが束縛される?.js
class A {
a = 1; // これが束縛されるのでは?(まちがい!)
b = a; // reference error!
}
code:classBindingが束縛される.js
class A { // このAが束縛される
a = A;
}
the running execution context's PrivateEnvironmentが存在するのはどんな場合?
code:js
class A {
hello() {
class B {} // ここでAのprivate environmentが見える
}
}
new A().hello();
For each String dn of the PrivateBoundIdentifiers of ClassBody$ _{\rm{opt}}
ClassBodyにPrivateBoundIdentifiersというsyntax directed operationを実行して、その結果として得られるstringのリストをループで回す
PrivateBoundIdentifiersを読んでいくとproperty nameとして使える文字列の範囲が意外と広いことが分かった
code:numeric_literalがproperty_nameに使える.js
class A {
123() { return "hello" }
}
console.log(new A()123()) // "hello" #constructorはできるのか?
It is a Syntax Error if StringValue of PrivateIdentifier is "#constructor".
ECMAScriptでは明示的にSyntax Errorにされる
TypeScriptではどうか?
Syntax Errorにはならないけどprivate扱いにはならないのかな
同名のプライベートメソッドを定義したらどうなる?
code:js
class A {
#hello() {} // Uncaught SyntaxError: redeclaration of private method #hello }
どこかで弾かれているらしい
NOTE: The running execution context's PrivateEnvironment is outerPrivateEnvironment when evaluating ClassHeritage.
ClassHeritageとは?
extends Hoge
code:継承元のprivate_fieldを読む.js
class A {
hello() { console.log(this.#b); }
}
class B extends A {
}
new B().hello();
// TypeError: Cannot read private member #b from an object whose class did not declare it // at <instance_members_initializer> (REPL16:2:11)
// at new A (REPL16:1:1)
// at new B (REPL19:1:1)
code:継承元のprivate_fieldを読む (2).js
class A {
hello() { console.log(this.#b); }
}
class B extends A {
}
new B().hello(); // 1 (expected: 2)
code:継承元のpublic_fieldを読む.js
class A {
b = 1;
a = this.b;
hello() { console.log(this.b); }
}
class B extends A {
b = 2;
}
new B().hello(); // 2
このprivateとpublicのfieldの挙動の違いがClassDefinitionEvaluationの定義で説明できるのかは謎
ClassHeritage
Pro Tip: extendsの後にはLeftHandExpressionが使える
code:クラスを返すexpression.js
class A {}
const returnA = () => A;
class B extends returnA() {} // ok
code:constructorを返すexpression.js
function returnX() {
return function () {
console.log("initialized!");
};
}
class B extends returnX() {}
new B(); // initialized!
code:nullを継承する.js
Object.create(null) // これはok
Object.getPrototypeOf(o) // null
class A extends null {} // TypeError: super is not a constructor
function returnNull() { return null }
class A extends returnNull() {}
new A(); // TypeError
code:js
let C = null;
function returnC() {
return C;
}
class A extends returnC() {}
C = function () {
console.log("updated C!");
};
new A(); // TypeError: Super constructor null of A is not a constructor
// at new A (/Users/syumai/go/src/github.com/syumai/til/js/esspec/d.js:5:1)
この先どうする?
予想より規模が大きかったね…
理解進んでいるので、枝刈りしながら読み進めてもいいのでは