Twitter hashtag: #esspec
YouTube:
自己紹介 (近況報告)
syumai
GoとTSやってます
connect-webでおもちゃが出来ました
Jun Yasumura / harupiyo Jun Yasumura.icon
爆音の出る昆虫が出ました
tars0x9752 (たーず / naoki aoyama) tars0x9752.icon
Emanote というライブラリを触ってみていた
だいたい使い方わかった
Emanote 使ってなんか作るか → esspec のメモ的なものを実験的に作り始めた
そういえば今更ですが switch を買いました
yebis0942yebis0942.icon
今日の学び: IntelのリテールCPUファンのプッシュピンは頑張れば交換できる
Nozomu Ikuta NozomuIkuta.icon
2022.10.16 (日)にオンライン開催
一般チケットは無料
おすすめ(?)企画はPeephole
↑yebis0942.icon 雑にメモしてみました
前回のあらすじ
Private Name specification type
Abstract Operations
一般的な abstract operations の定義
ToPrimitive から ToNumber あたりまで
7.1.4.1 ToNumber Applied to the String Type
NOTEにStringNumericLiteralとNumericLiteralの違いが列挙されている
ToNumberのパースと、ソースコードに数値リテラルを書いたときのパースの結果は一部異なるという話
7.1.4.1.1 StringToNumber ( str )
Stringを以下の手順でNumberに変換する
StringToCodePointsでstringをコードポイントのリストに変換する
そのリストをParseText(text, StringNumericLiteral)でパースする
ParseText(text, goalSymbol)
goalSymbolをゴールシンボルとしてtextをパースする
goalSymbol: コードの特定の範囲のかたまり
返り値は以下のどれか
Parse Node
SyntaxErrorのリスト
7.1.4.1.2 Runtime Semantics: StringNumericValue
StringNumericValue (syntax-directed operation)
syntax-directed operation of 非終端記号
::: = Numeric String Grammar opt: その非終端記号が省略可能であることを示す 01のような形式の8進数表記はlegacyらしい
0o1とか0O1のような表記はlegacyではない(アルファベットのオー)
Chromeのdevtoolではsyntax highlightされない
コントリビューションチャンス?
1. Return 𝔽(MV of NonDecimalIntegerLiteral).
5.2.5にMathematical Valueの定義はあるが、略記の説明はなさそう?
mathematical valueをnumberに変換する
変換によって精度が落ちる可能性があるのでround(丸め)としているのだろう
code:js
// 1個目 StrUnsignedDecimalLiteral
Number("10.e+10")
100000000000
Number("10.")
10
Number("10.1")
10.1
Number("10.1e-10")
1.01e-9
// 2個目 StrUnsignedDecimalLiteral
Number(".1e10")
1000000000
// これはダメ
Number(".e10")
NaN
疑問: +から始まる文字列の定義がないように見える
実験結果: Number("+1") // 1
Runtime Semantics: StringNumericValueにはそれに該当する定義がない
StringNumericValueで定義されているのは「ある文法に当てはまったらどのような値になるか」であって、数値としてパースできる文字列を定める文法そのものではないから?
文法自体はToNumber Applied to the String Typeで定義されている
しかし、StringNumericValueに+から始まる文字列にマッチする定義がないとしたら、結局は解釈不能になるのでは?
つまり「+1は文法的にはvalidなStringNumericLiteralだが、仕様上はどんな数値を意味するのか定まっていない」という状態になるのでは
仕様書の書き忘れかも?
疑問: この定義って字義通りに解釈すると無限ループ可能なのでは?
StringNumericLiteral ::: StrWhiteSpace(opt) StrNumericLiteral StrWhiteSpace(opt)
1. Return StringNumericValue of StrNumericLiteral.
strictモードでのlegacy octal literalのパース
会話とは関係ないけど見つけたのでメモyebis0942.icon
code:js
(() => { "use strict"; return 03 })()
// VM251:1 Uncaught SyntaxError: Octal literals are not allowed in strict mode.
(() => { "use strict"; return Number("03") })()
// 3
octal escape sequenceは8進数によるエスケープシーケンス
(英語) piecewise: 区分的に
7.1.4.1.3 RoundMVResult ( n )
有効数字が20桁以下なら 𝔽(n)を返す
さもなければ、実装依存で以下の値のいずれかを返す
option1:
option2:
実装の挙動を追認する形で決まった仕様のように見える
なぜ20桁なのか
関係あるか分からないですが 64bit 環境の c/c++ の整数型の最大値 ULONG_MAX や ULLONG_MAX は 20桁?っぽいですね (18446744073709551615 = 2^64-1) by tarsさん
疑問: Number型の精度では20桁も表現できないのでは?
code:hoge
// For the purposes of this abstract operation, a digit is significant if it is not zero or there is a non-zero digit to its left and there is a non-zero digit to its right.
12345678901234567890
^
significant (1は0ではない)
100
^
significant
100
^
non-significant
1000
^
non-significant
code:hoge2
10001
^
significantになるんですよね多分(yebis)
なりますね (syumai)
ありがとうございます!(えびす)
書いてある内容が正確でないような気はしていて、
- there is a non-zero digit to its left and there is a non-zero digit to its right
は、
- there is a significant digit to its left and there is a significant digit to its right
なんじゃないかという気はします (syumai)
たしかに。"its left"が「すぐ左」だけを指すのではなく、「左全部」だとしたら辻褄が合うのではという気もしてます(yebis)
なるほどそれなら良さそうです! (syumai)
書き方を明確化する余地はありそう(なのか、ネイティブスピーカー的には「この表現なら左全部、右全部になる」ということなのか)。ともあれありがとうございます!(えびす)
7.1.5 ToIntegerOrInfinity ( argument )
ECMAScript language valueを整数もしくは無限大に変換する
floor(abs(ℝ(number)))
なぜabsを使うのか?
下記のように書かれている
The mathematical function floor(x) produces the largest integer (closest to +∞) that is not larger than x.
floorは、+∞に最も近い整数を返すので、
0.5 => 0
-0.5 => -1
が返ることになって、符号なしの数値がズレてしまうのでabsを使ってそうです
うおお、解説ありがとうございますyebis0942.icon
NaNは0になる
内部的にこのabs opを使っているメソッドの例
code:js
1
7.1.6 ToInt32 ( argument )
7.1.7 ToUint32 ( argument )
ToInt32とは最後のステップが違うだけ(とNOTEにも書かれている)