ECMAScript仕様輪読会 #11
前回: ECMAScript仕様輪読会 #10
Scrapboxの招待リンク: https://scrapbox.io/projects/esspec/invitations/85b96c9fa718ce5185e307196ed8fb53
connpass: https://esspec.connpass.com/
Discord: https://discord.gg/59S3y6weQj
Twitter hashtag: #esspec
YouTube: https://www.youtube.com/watch?v=gAJys2gLODc
自己紹介 (近況報告)
syumai
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仕様書を読んだ経験あり
noyannoyan.icon
体力の衰え
おーみーaumy.icon
Twitter: aumy_f GitHub: aumyf
ここ2週間はWebに気持ちが向いている
tars0x9752 (たーず / naoki aoyama)
7月から充電期間
前回のあらすじ
---
今回の範囲
6.1.7 The Object Type の Properties are identified using key values から
https://tc39.es/ecma262/
6.1.7. The Object Type
data property
key valueと、ECMAScript language valueとBoolean attributesを結びつける
Boolean attributes…enumerableとかwritableとか
accessor property
key valueと、1または2個のaccessor functionとBoolean attributesを結びつける
property key はStringかSymbol
aumy.iconNumberはStringに変換されるって誰かが記事で言ってた気がする
obj["2"] === obj[2]
property nameはStringであるようなproperty name
integer indexはStringなpropertyでcannonical numeric stringであり $ 2^{53}-1 以下の正の整数
array indexは$ 2^{32} - 1 以下のinteger index
プロパティアクセスには2種類ある
get
set
own property
オブジェクト自身が持っているプロパティ
Object.hasOwnProperty
inherited property
継承したプロパティ
own propertyどうしが重複してはいけない
オブジェクトには複数の形態がある
6.1.7.2
attributes
オブジェクトの状態を定義、説明するのに仕様書で使われている
[[Value]]
data propertyにある
ECMAScript language value
get accessで取得される値
[[Writable]]
d
Boolean
falseのとき、ECMAScriptコード上から[[Set]]を使ってプロパティの[[Value]]を設定することはできない
[[Get]]
a
function objectかundefined
function objectの[[Call]]を毎回呼ぶ
[[Set]]
a
Objectかundefined
Setの副作用が後続のGetに影響してもよいが、必須ではない
[[Enumerable]]
d / a
Boolean
trueの場合、プロパティはfor-in enumerationによって数え上げられる
[[Configurable]]
d / a
Boolean
ちょっとわからなかった.....
falseのとき、次のことができない
プロパティの削除
プロパティのdata propertyからaccessor propertyへの変更(またはその逆)
attributeの変更
ただし以下は可能
既存の[[Value]]の置き換え
[[Writable]]をfalseにする
6.1.7.2 Object Internal Methods and Internal Slots
ECMAScript実装におけるオブジェクトのふるまいは、そのオブジェクトに関連付けられたinternal methodsによって決められる?
このへんの解釈で議論が発生した
ECMAScript engineのオブジェクトはinternal methodsに関連付けられている
engineとimplementationって本当に同じ?みたいな疑問が生えたり
internal methods
実行時の振る舞いを規定する
仕様の説明に使われる概念であって、ECMAScriptからアクセスすることはできない
処理系の内部的な実装を規定するものではない
internal methodの名前は多相的
同じ名前でも実行されるオブジェクトによってアルゴリズムが変わる
internal slotsはオブジェクトの内部的な状態を表す
プロパティではないので継承されない
ECMAScriptから直接アクセスすることはできない
[[PrivateElements]]
これは MDN: private class fields のことっぽい
code:js
class Foo {
#privateField;
}
(英語) allocate: 領域を確保する
メモリ確保みたいな低レイヤな事柄を想起してしまうけど、ここではそういう意味ではなさそう
internal methods と internal slots は [[]]で囲む
表記同じなんだ…
essential internal methods はすべてのオブジェクトが持っている
ordinary object
次の3条件を全て満たすobject
Table 4のinternal methodsでは、10.1で定義されているものを使う
internal method [[Call]]を持っている場合は、10.2.1で定義されているものを使う
internal method [[Construct]]を持っている場合は、10.2.2で定義されているものを使う
exotic object
ordinaryでないobject
How to Read the ECMAScript Specificationで出てきたやつだ