Twitter hashtag: #esspec
便利ツール
自己紹介 (近況報告)
syumai syumai.icon
最近結構忙しい
再来月締め切りの執筆が一本生まれた
tars0x9752 (たーず / naoki aoyama) tars0x9752.icon
舌の裏に口内炎ができて大変だったが治った...と思ったらまた別のところに口内炎ができた
yebis0942 (えびす) yebis0942.icon
Go, Reactを書いて暮らしています
最近はFigmaに入門したりしていました
antisatori
フィヨルドブートキャンプで学習している無職です
フロントエンドが好きでReactをよく書いてます
前回のあらすじ
今回の範囲
関数コードにBindingIdentifierを含めることの実際的な効果は、周囲のコードがストリクトモードコードでなくても、ボディに "use strict "ディレクティブを含む関数名であるBindingIdentifierには、ストリクトモードコードのアーリーエラーが適用されるということです。
下記のf2はstrict mode codeではないが、yieldの箇所でstrict modeのearly error ruleが適用されて失敗する。
code:js
const f1 = function () {
function yield() {
};
};
const f2 = function () {
function yield() {
"use strict";
};
};
/*
/Users/syumai/go/src/github.com/syumai/til/js/esspec3/0829/a.js:6
function yield() {
^^^^^
SyntaxError: Unexpected strict mode reserved word
*/
予約語が入ったタイミングには差がある
yieldは、strict modeで予約語扱いされるようになった
awaitは、ModuleがGoal Symbolの時のみ予約語扱いされる
上記のルールに引っかかるのはyieldの方のみ
その他の予約語
implements
interface
let
package
private
protected
public
static
yield
FutureReservedWordという概念がある
ES5時点から既にあった
https://scrapbox.io/files/64edd7c5a54be2001c2e7aa6.png
strict mode下のみでのreserved wordはFutureReservedWordでもない
最新の仕様では、FutureReservedWordはReserved Wordに取り込まれている
1st EditionのFuture Reserved Word
https://scrapbox.io/files/64edd849c55b2b001b2ad056.png
code:js
// OK
(function () {
use strict;
with ({ a: 1 }) {}
})();
/* NG
(function () {
"use strict";
with ({ a: 2 }) {}
})();
*/
// OK
(function () {
;"use strict";
with ({ a: 3 }) {}
})();
// OK
(function () {
"use\u0020strict";
with ({ a: 4 }) {}
})();
console.log("\f1\f2\f3\f4\n5\f6")
1
2
3
4
5
6
undefined
directive prologueの定義
the longest sequence of ExpressionStatements
occurring as the initial StatementListItems or ModuleItems of a FunctionBody, a ScriptBody, or a ModuleBody
and where each ExpressionStatement in the sequence consists entirely of a StringLiteral token followed by a semicolon.
ExpressionStatementの最長の列であって
FunctionBody, ScriptBody, ModuleBodyのいずれかの最初のStatementListItemたちで
かつ、
以下は有効なUse Strict Directiveを含むDirective Prologue
code:js
(function() {
"use not strict"; "use strict";
with ({}) {}
})();
/Users/syumai/go/src/github.com/syumai/til/js/esspec3/0829/s2.js:3
with ({}) {}
^^^^
SyntaxError: Strict mode code may not include a with statement
NOTE: 意味のないdirective prologueを検出したら警告すべき
と書かれているけど、node.jsもChromeもFirefoxも従ってなさそう
eval
direct evalとindirect eval
direct eval
普通に呼んだeval
indirect eval
間接的に呼んだeval
カンマ演算子: (0, eval)("code");
変数への代入: const myEval = eval; myEval("code");
direct evalは外側がstrict mode codeであれば内側もstrict mode codeになる
indirect evalはUse Strict directiveをコードの先頭に伴わなければ常にnon-strict code
function
普通に宣言したfunction codeは、外側がstrict mode codeであれば内側もstrict mode codeになる
Function constructorによって作られたfunction codeは、Use Strict directiveをコードの先頭に伴わなければ常にnon-strict code