ECMAScript仕様輪読会 #29
前回: ECMAScript仕様輪読会 #28
Scrapboxの招待リンク: https://scrapbox.io/projects/esspec/invitations/85b96c9fa718ce5185e307196ed8fb53
connpass: https://esspec.connpass.com/
Discord: https://discord.gg/59S3y6weQj
Twitter hashtag: #esspec
便利ツール
esspec-memo: https://tars0x9752.github.io/esspec-memo/esspec.html
Scrapbox Codeblock Generator: https://vzvu3k6k.github.io/scrapbox-codeblock/
TC39 Terminology: https://github.com/tc39/how-we-work/blob/main/terminology.md
自己紹介 (近況報告)
syumai
Twitter: https://twitter.com/__syumai GitHub: https://github.com/syumai
https://github.com/syumai/workers
Cloudflare D1 サポートを頑張って入れてます
Jun Yasumura / harupiyo Jun Yasumura.icon
忙しくなってきた!
tars0x9752 (たーず / naoki aoyama) tars0x9752.icon
とある楽曲投稿イベントに向けて準備をしていた件→とりあえず無事おわった
また次の別の楽曲投稿イベントに向けて準備を始めた
前回のあらすじ
Environment Records
Declarative Environment Records の abstract specification methods の GetBindingValue まで
今回の範囲
Declarative Environment Records の abstract specification methodsの DeleteBinding(N)から
Declarative Environment Records の abstract specification methods
CreateMutableBinding
Dがtrueになるケース
evalの中?
特定のケースでありそう
DeleteBinding(N)
binding の 削除
削除の対象となると明示的に示されたbindingのみ削除できる
HasThisBinding()
return false
HasSuperBinding()
return false
WithBaseObject()
return undefined
Object Environment Records
with 文用のやつ
with 文なんてほぼ使わないとおもったが global env で関連してきそう
binding objectと呼ばれるObjectが束縛されたEnvironment Record
binding objectのproperty keyがEnvironment Recordに束縛された識別子になる
property keyの中で、IdentifierNameとなる文字列のみが識別子として追加される
Symbolは含まれない
ID_Startから始まらない文字列も含まれない
例) { '0a': 1 } 0 はID_Startに含まれないので、0a はObject Environment Recordに束縛されない
ID_Startの話
https://zenn.dev/awyaki/articles/ae4fb630350d2a#unicodeを確認する
束縛がObjectへのpropertyの追加 / 削除で動的に増えたり / 減ったりする
Objectへのpropertyで束縛が増減することを副作用と呼ぶ
副作用によって作られたbindingは、Writableではなくてもmutableとなる
with文の振る舞いの確認
束縛される識別子
code:js
const sym = Symbol("s");
const obj = {
'0b': 1,
a: 2,
sym: 3,
};
console.log(obj);
with(obj) {
// console.log(0b); Syntax Error
console.log(a);
// console.log(); symbolは書けない!
}
副作用の振る舞いの確認
Writable: falseはmutable bindingのはずだが、値の書き換えも、束縛の削除も出来なかった
code:js
const obj = { a: 1 };
const addB = () => { obj.b = 2; };
const delA = () => { delete obj.a; };
const defineC = () => {
Object.defineProperty(obj, "c", {
value: 3,
writable: false,
enumerable: true,
});
};
with (obj) {
console.log(a); // 1
addB();
console.log(b); // 2
delA();
// console.log(a); 識別子が見つからない
defineC();
console.log(c); // 3;
c = 4;
console.log(c); // 3 => 4に書き換わらない
b = 10;
console.log(b); // 10
delete b;
delete c;
console.log(c); // 3 => deleteされない
// console.log(b); 識別子が見つからない
}
this binding
code:js
const obj = {
a: 1,
f: function () {
console.log(this);
},
};
with (obj) {
// console.log(this); // global object
f(); // { a: 1, f: Function: f }
}
Function Environment Records
Additional Fields
[[ThisValue]]
this
[[ThisBindingStatus]]
lexical な場合はアロー関数であり local this をもたない
[[FunctionObject]]
対象の FunctionObject
[[NewTarget]]
[[Construct]] の newTarget (Construct で作られてなければ undefined)
HasThisBinding and HasSuperBinding 以外 Declarative Environment Record と同じ methods を持つ
それに加えて、BindThisValue, GetThisBinding, GetSuperBase を持つ
次回: Global Environment Records (必要に応じて Object Environment Records へもどる)