ECMAScript仕様輪読会 #51
前回: ECMAScript仕様輪読会 #50
Scrapboxの招待リンク: https://scrapbox.io/projects/esspec/invitations/85b96c9fa718ce5185e307196ed8fb53
connpass: https://esspec.connpass.com/
Discord: https://discord.gg/59S3y6weQj
ES Spec Draft: https://tc39.es/ecma262/
読み物リスト
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
時事ネタ
https://blog.jxck.io/entries/2024-02-06/tc39-stage-2.7.html
https://x.com/robpalmer2/status/1756521431507333383?s=20
TS 5.4 beta: https://devblogs.microsoft.com/typescript/announcing-typescript-5-4-beta/
https://azukiazusa.dev/blog/full-stack-web-framework-honox/
自己紹介 (近況報告)
syumai syumai.icon
Twitter: https://twitter.com/__syumai GitHub: https://github.com/syumai
YAPCに行きました
tars0x9752 (たーず / naoki aoyama) tars0x9752.icon
特になし
iwatsurut
とくに、イベントもなく過ごしています。
go で、svelte をホストする、golte というツールが、面白いと思いました。
もうちょっと薄いツールで https://github.com/shibukawa/frontend-go というのを触ってましたyebis0942.icon
yebis0942 (えびす) yebis0942.icon
おひさしぶり組です
YAPC行きたかった組でした
https://yapcjapan.org/2024hiroshima/
monacoを使ったページのE2Eテストを書くのに苦戦している
https://github.com/vzvu3k6k/asi-viewer
構文解析周りは全部非同期なので不安定
スクリーンショットによるassertは自動リトライしてくれない
前回のあらすじ
https://tc39.es/ecma262/#sec-this-keyword から読んでいった
今回の範囲
13.2.4.1 Runtime Semantics: ArrayAccumulation
nextIndex を加算する & CreateDataPropertyOrThrow()で値をセットする(セットすべき値があれば)
というのを再帰的に繰り返す
code:js
const b = 1,,,2
undefined
Object.keys(b)
'0', '3'
b.length === (Object.keys(b)).length
false
code:js
// Arrayのprototypeに値をセットして取得してみる
b1
undefined
b.__proto__ = { '1': 'hello!' }
{ '1': 'hello!' }
b
{ '0': 1, '3': 2 }
b1
'hello!'
code:js
const ary = 1,2,3;
undefined
const c = ,,,...ary;
undefined
c
<3 empty items>, 1, 2, 3
c.length
6
Object.keys(c)
'3', '4', '5'
code:js
const d = ,,,...ary,,,1;
undefined
d
<3 empty items>, 1, 2, 3, <2 empty items>, 1
NOTE
...even if the standard built-in Array prototype object has been modified...
とされているケースのサンプルコードを作ろうとしたが、うまく作れなかった
ArrayLiteral
最後のカンマだけを無視するための定義になっていそう
MethodDefinition
ClassとObject Initializerで完全に共有してそう
CoverInitializedName
code:js
const { x, y, z = 1 } = { x: 1, y: 2 }; // z = 1
のような分割代入構文のための定義っぽい。
LeftHandSideExpressionの中で出現するObjectLiteralは分割代入構文になる
https://tc39.es/ecma262/#prod-LeftHandSideExpression
https://tc39.es/ecma262/#sec-destructuring-assignment
https://tc39.es/ecma262/#sec-object-initializer-static-semantics-early-errors
PropertyDefinitionの中で出現した場合はSyntaxError
code:js
const obj = { a = 1 }; // SyntaxError
その他のEarly Errors
PropertyDefinition : MethodDefinition
It is a Syntax Error if HasDirectSuper of MethodDefinition is true.
HasDirectSuper SDO
Return FunctionBody Contains SuperCall.
Contains SDOの呼び出しにofがついていない
前回のEvaluate SDOと同じタイプなのでは
code:js
const o = { m() { super() } };
const o = { m() { super() } };
^^^^^
Uncaught SyntaxError: 'super' keyword unexpected here
オブジェクトではsuperは使えない
It is a Syntax Error if PrivateBoundIdentifiers of MethodDefinition is not empty.
code:js
const o2 = { #m() {} };
const o2 = { #m() {} };
^^
Uncaught SyntaxError: Unexpected identifier '#m'
code:js
// 単に構文的にNGなパターン (オブジェクトのプロパティキーにPrivateIdentifierは使えない)
const o3 = { #k: "v" };
const o3 = { #k: "v" };
^^
Uncaught SyntaxError: Unexpected identifier '#k'
__proto__に関するEarly Errors
code:js
__proto__: {},
^^^^^^^^^
SyntaxError: Duplicate __proto__ fields are not allowed in object literals
code:js
$ cat c.js
const __proto__ = 1;
const o = {
__proto__,
__proto__,
__proto__: 2,
};
console.log(o);
$ node c.js
{ '__proto__': 1 }
$ cat c.js
const __proto__ = 1;
const o = {
__proto__: 2,
__proto__,
};
console.log(o);
$ node c.js
{ '__proto__': 1 }
$ cat d.js
const o = JSON.parse(`{
"__proto__": 1,
"__proto__": 2
}`);
console.log(o);
$ node d.js
{ '__proto__': 2 }
$ cat e.js
const o = {
[__proto__]: 1,
[__proto__]: 2,
};
console.log(o);
$ node e.js
{ '__proto__': 2 }
const o = {
__proto__: 1,
...{
__proto__: 2,
},
};
console.log(o); // {}
Object.prototype.__proto__はlegacyとマークされているが、このあたりの仕様はlegacyにできていないらしい。