2018-05 の TC39 meeting
まとめ
決まったこと
Stage 4 (ES2019)
Optional Catch Binding
try-catch で catch で投げられた例外を取らなくても良くなった。ちょっと便利。
code: (js)
try {
// ...
} catch {
// ...
}
JSON superset
JSON 的には文字列の中に unescaped U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR が入っていても問題ないが、JavaScript の文字列に入っているとパースエラーになる問題があった。JSON は ES3 のサブセットなはずなのでおかしいということで修正された。
Stage 3
Function#toString revision (stay)
"[native code]" を返すのをちゃんと定義するやつ。
Array#{flat, flatMap} (stay)
もともと Array#flatten だったが古の mootools というやつがプロトタイプ汚染をしており、互換性の観点から別の名前にしようという話になっていた。flat に落ち着いたらしい。
Symbol#description
デバッグ用の Symbol の description を Symbol#toString の結果を変形して取得するのが面倒くさいとかそういうやつ。
code: (js)
const symbol = Symbol("hoge");
symbol.description; // "hoge"
Static Class Properties/Methods
長いこと議論されてた class の static property がようやく Stage 3 に入った。private static methods も作れるみたい。
code: (js)
export const registry = new JSDOMRegistry();
export class JSDOM {
// ... elided ...
}
async static fromURL(url, options = {}) {
normalizeFromURLOptions(options);
normalizeOptions(options);
const body = await getBodyFromURL(url);
return JSDOM.#finalizeFactoryCreated(new JSDOM(body, options), "fromURL");
}
static fromFile(filename, options = {}) {
normalizeOptions(options);
const body = await getBodyFromFilename(filename);
return JSDOM.#finalizeFactoryCreated(new JSDOM(body, options), "fromFile");
}
jsdom.#createdBy = factoryName;
jsdom.#registerWithRegistry(registry);
return jsdom;
}
}
Stage 2
Atomics.wake
Stage 2 の Atomics.wate でスリープ状態のスレッドを起こすメソッドっぽい?
Spectre 脆弱性のため SharedArrayBuffer がブラウザで使えないので検証できない……。
Object.fromEntries
Object.entries の逆。文字列の key オンリーな Map から Object が容易に作れるようになるとかそういうの。
code: (js)
const obj = Object.fromEntries(map);
Top-level await
Async Functions の中じゃない top-level でも await できるようにする提案。Dynamic Imports とか Atomic.wait と相性良さそう。
top-level await の後の export が出てきたとこのこととか結構複雑になりそうで個人的にはあまりなくてもいいのでは派。
Set methods
Set に数学のメソッドを追加する提案。順調に Stage 2 になったっぽい。
Set.prototype.intersect(iterable) - method creates new Set instance by set intersect operation.
Set.prototype.union(iterable) - method creates new Set instance by set union operation.
Set.prototype.difference(iterable) - method creates new Set without elements present in iterable.
Set.prototype.symmetricDifference(iterable) - returns Set of elements found only in either this or in iterable
Well formed JSON.stringify
UTF-16 のサロゲートペアまわりでなんかいい感じにするっていう提案。
Realms
所謂 Sync Worker。iframe とか Node.js の require("vm") を ECMAScript の仕様に入れる提案。ちょっと欲しいかも。
code: (js)
let g = window; // outer global
let r = new Realm(); // root realm
let f = r.evaluate("(function() { return 17 })");
f() === 17 // true
Reflect.getPrototypeOf(f) === g.Function.prototype // false
Reflect.getPrototypeOf(f) === r.global.Function.prototype // true
Numeric Separators (down)
数値のリテラルが 123_456 のようにかけるやつ。
将来の仕様とぶつからないか検証するために、とりあえず実装するのを取り下げて Stage 2 にしたらしい。
Stage 1
RegExp Unicode Sequence Propserties
Unicode Property Escapes は Stage 4 に入ったが、同じように Unicode Sequence Properties も入れようっていう提案。Emoji 周りを入れるっぽい。
code: (js)
const regexEmojiKeycap = /\p{Emoji_Keycap_Sequence}/u;
regexEmojiKeycap.test('4️⃣');
String#codePoints (stay)
String#[@@iterator] と似てるが文字列の index と codepoint の両方返す StringIterator を作る提案。モチベが弱そう。
Module Keys
モジュールの依存とセキュリティ周りの提案らしいが、よくわからなかった。
Static Class Blocks
C# の static constructors や Java の static initializers を ECMAScript にも入れる提案っぽい。
code: (js)
class C {
static x = ...;
static y;
static {
try {
this.y = doSomethingWith(this.x);
}
catch {
this.y = ...;
}
}
}
Class Access Expressions
メソッドの中で static propertie/methods に class.hoge でアクセスできるようにする提案。super だとか new.target みたいなメタプロパティっぽい動きをするのかな? ちょっと欲しい。
code: (js)
class C {
static f() { ... }
g() {
class.f();
}
}
Pattern Matching
我らがパターンマッチング。Stage 0 で燻ってたがようやく Stage 1 になった。
code: (js)
const res = await fetch(jsonService)
case (res) {
when {status: 200, headers: {'Content-Length': s}} -> {
console.log(size is ${s})
}
when {status: 404} -> {
console.log('JSON not found')
}
when {status} if (status >= 400) -> {
throw new RequestError(res)
}
}
総括
Static Class Properties/Methods がやっと Stage 3 に入ったし、Pattern Matching が Stage 1 に入ってよかった。
前回に比べて実りのある会議だった……というか今回提案多すぎてまとめるの大変だった。