Global Object

大域オブジェクト (Web)

仕様書

呼称

[82] Web IDLECMAScript 大域環境 (global environment) と呼んでいます。

[25] かつて HTML Standard が定義していた用語 JavaScript 大域環境 (global environment) は、 JavaScript の仕様書における大域環境 (global environment) と同義です >>23

大域環境の一覧

[22] JavaScript大域環境には次の種類があります。それぞれ異なる種類の大域オブジェクトを用いています。

env
大域環境
obj
大域オブジェクトインターフェイス
name
大域名
env
[18] 文書環境 (document environment) >>23
obj
Window
name
Window
env
[19] ワーカー環境 (worker environment) >>23
obj
WorkerGlobalScope
name
-
env
[20] :... 専用ワーカー環境 (dedicated worker environment) >>23
obj
DedicatedWorkerGlobalScope
name
Worker, DedicatedWorker
env
[21] :... 共有ワーカー環境 (shared worker environment) >>23
obj
SharedWorkerGlobalScope
name
Worker, SharedWorker
env
[67] :... サービスワーカー環境 (service worker environment)
obj
ServiceWorkerGlobalScope
name
Worker, ServiceWorker
name
AudioWorklet
[66] これらの大域環境名は、現在の HTML Standard では削除されています。

[26] 特記なき場合 JavaScript大域環境文書環境です >>23Window は、一次大域インターフェイスです。

[36] ワーカー環境は3つの環境の総称で、これ単独で用いられることはありません。

[27] >>18 の特殊ケースとして、大域オブジェクトWindowWindowModal の両方を実装したオブジェクトとなる >>12 ことがあります。

[28] ウィジェット実現値では Window オブジェクトWindowWidget実装することになっています。

[57] 大域オブジェクトを識別する名前を大域名 (global name) といいます。 大域名Global 拡張属性PrimaryGlobal 拡張属性識別子リストとして指定することができます。 明示されていない場合、インターフェイスの名前が大域名となります。

[60] 大域名には制約がなく、複数のインターフェイスに同じ大域名を与えることもできます。

[64] 大域名Exposed 拡張属性大域オブジェクトを指定するために使われます。

[81] 大域名Web IDL による定義のための仕様書内の情報であり、 実装により著者から観測可能なものではありません。

[43] ある文脈で適用される大域環境のことを現在大域環境といいます。

[49] オブジェクトは、大域環境に関連付けられています。

[50] 例えばコンストラクターが作成したオブジェクトは、 そのインターフェイスオブジェクト大域環境に関連付けられます。

初期オブジェクト

[46] Web IDLJavaScript 実装において IDL素片定義に対応する JavaScriptオブジェクト初期オブジェクト (initial object) といいます >>45。次のものがあります。

[47] JavaScript大域環境は、それぞれ固有の初期オブジェクトの集合を持たなければなりません >>45初期オブジェクトは、JavaScript大域環境に関連付けられた JavaScript実行文脈の制御下に入る前で、 JavaScript大域環境大域オブジェクトが作成された後に、 作成されます >>45

[48] 初期オブジェクトPrototype は、 同じ大域環境のものでなければなりません >>45

JavaScript 大域実行文脈

[30] スクリプト設定群オブジェクト大域オブジェクトWindow の時、 JavaScript大域実行文脈ThisBinding (this) はその Window オブジェクト自体ではなく、その Window オブジェクトWindowProxy オブジェクトとしなければなりません>>10

[31] ES5 仕様上は大域オブジェクト自体が this によって返されることになっていますが、 実際の Webブラウザー上は Window オブジェクトスクリプトがアクセスすることができず、 常に代わりに WindowProxy オブジェクトが返されることになっています。 これは ES 仕様書に対する HTML Standard意図的違反です >>10

大域オブジェクト

[89] 大域オブジェクト (global object) は、 RealmGlobalObject で指定された JavaScriptオブジェクトです >>10Realm大域オブジェクト (the Realm's global object) とは、 当該 RealmGlobalObject のことをいいます >>91

[90] 大域オブジェクト環境設定群オブジェクトRealm は、常に 1:1:1 関係にあります。

[75] 大域オブジェクトは次の状態を持ちます。

環境設定群オブジェクト
大域オブジェクトに対応する環境設定群オブジェクトです (>>11)。
Realm
大域オブジェクトに対応する Realm です。
[35] エラー報告モード
大域オブジェクトエラーの報告対象となることがあります。 エラーの報告対象 (>>34) はエラー報告モードになることがあります。
Blob URL Store
作成した Blob URL が登録されます。
Revocation List
自動revokeされる Blob URL が登録されます。
WebSocket
unloading document cleanup steps で参照されます。
EventSource
unloading document cleanup steps で参照されます。
ポート群
BroadcastChannel
保安文脈非保安文脈
保安文脈であるか否か

[95] 他に、大域オブジェクト実装する各インターフェイスの状態をも保持します。

JavaScript 大域オブジェクトの内部特性

[4]

[[Call]]
なし ES3 15.1
[[CanPut]]
標準 ES3 18.6.2.3
[[Class]]
実装依存 ES3 15.1
[[Construct]]
なし ES3 15.1
[[Default]]
標準 ES3 18.6.2.6
[[Delete]]
標準 ES3 18.6.2.5
[[Get]]
標準 ES3 18.6.2.1
[[HasProperty]]
標準 ES3 18.6.2.4
[[Prototype]]
実装依存 ES3 15.1
[[Put]]
標準 ES3 18.6.2.2

JavaScript 大域オブジェクトのメンバー

[3]

ArrayECMA 標準ES3
BooleanECMA 標準ES3
DateECMA 標準ES3
decodeURIECMA 標準ES3
decodeURIComponentECMA 標準ES3
encodeURIECMA 標準ES3
encodeURIComponentECMA 標準ES3
escapeECMA 標準 (参考)ES3 (参考)
ErrorECMA 標準ES3
evalECMA 標準ES3
EvalErrorECMA 標準ES3
FunctionECMA 標準ES3
InfinityECMA 標準ES3
isFiniteECMA 標準ES3
isNaNECMA 標準ES3
MathECMA 標準ES3
NaNECMA 標準ES3
NumberECMA 標準ES3
ObjectECMA 標準ES3
parseFloatECMA 標準ES3
parseIntECMA 標準ES3
RangeErrorECMA 標準ES3
ReferenceErrorECMA 標準ES3
RegExpECMA 標準ES3
StringECMA 標準ES3
SyntaxErrorECMA 標準ES3
TypeErrorECMA 標準ES3
undefinedECMA 標準ES3
unescapeECMA 標準 (参考)ES3 (参考)
URIErrorECMA 標準ES3

Web IDL によって大域オブジェクトに定義されるもの

[65] 次のものが Web IDL の規定と IDL素片の定義に基づき大域オブジェクト上に定義されます。

インターフェイスオブジェクト
interface により定義されたインターフェイスごとのオブジェクトが定義されることがあります。
名前付きコンストラクター
NamedConstructor 拡張属性により名前付き構築子が定義されることがあります。
DOMException
DOMException構築子オブジェクトです。 常に定義されます。

[80] 次のものは廃止されました。

例外インターフェイスオブジェクト
辞書コンストラクター
dictionaryConstructor 拡張属性により構築子が定義されることがあります。

[44] インターフェイスWeb IDL の規定に従い大域オブジェクトに現れることを、 晒されるといいます。

演算

[34] 大域オブジェクトエラーの報告対象として使われます。

[77] Web IDL の規定するアルゴリズムセキュリティー検査を実行 (perform a security check) することを求めることがあります。 これは、演算の実行や IDL属性へのアクセスが認められるべきかどうかを決めるものです。 >>76

[78] 本検査への入力は、文脈オブジェクトたるプラットフォームオブジェクトと、 演算IDL属性実装する Function オブジェクトに関連付けられた JavaScript大域環境です >>76。 出力は、認められるため何もしないか、 認められないため例外を投げるかです。

[79] HTML Standard で検査が規定されることを Web IDL は想定しています >>76 が、現時点では何の規定もありません。

大域オブジェクトと環境設定群オブジェクト

[83] JavaScript実行文脈大域オブジェクト (global object) は、 RealmGlobalObject です >>70

[84] 環境設定群オブジェクトの大域オブジェクト (the environment settings object's global object) は、 環境設定群オブジェクトRealmGlobalObjectです >>10

[11] スクリプト設定群オブジェクトを持ちますが、 その環境設定群オブジェクト大域オブジェクト (global object) を持ちます。 大域オブジェクトは、当該設定群オブジェクトを使うスクリプトが呼び出せる API を提供するオブジェクトです。 >>10

[12] これは特に JavaScript に限定せずに定義されています。ただし JavaScript 以外で利用する方法はどの仕様書でも規定されていません。
[29] 空のオブジェクト大域オブジェクトとすると、環境に対して作用できないようになります。 >>10

[32] 環境設定群オブジェクト大域オブジェクトは一対一対応関係にあります。 大域オブジェクトから見て環境設定群オブジェクトのことを大域オブジェクトの関連する設定群オブジェクトといいます。 >>10

[33] 言い換えると、同じ大域オブジェクトで実行されるスクリプト達は環境設定群オブジェクトを共有していることになります。 定義上はスクリプトかんきょう設定群オブジェクトを持つという関係になっていますが、 スクリプト大域オブジェクトを持ち、大域オブジェクト環境設定群オブジェクトの諸設定を持っていると解釈・実装することも可能です。

[98] 入口大域オブジェクト現職大域オブジェクト現在大域オブジェクト関連大域オブジェクトについては、 設定群オブジェクトを参照。

複数の大域オブジェクト

[37] 文書環境では、スクリプトは他の閲覧文脈Window オブジェクトにアクセスできます。 これを通じて現在の大域オブジェクトとは異なる大域オブジェクト/大域環境に由来するオブジェクトにアクセスすることが可能です。

[38] 例えば iframe 内の文書が作成した JavaScript Array にアクセスすることができます。その Array オブジェクトは、 本大域オブジェクトArray プロトタイプ実現値ではありません (instanceofを返します)。

[40] ワーカー環境では他の大域オブジェクト (やそこに属するオブジェクト) にアクセスする方法がありません。

[41] postMessage は、そのメソッドを呼び出した大域環境とは異なる大域オブジェクトに属するオブジェクトを作成することになります。

[39] document.openWindow (大域オブジェクト) を差し替えるので、やはり異なる大域環境オブジェクトが混在し得る状況となります。

[42] 実行中の大域環境文書document.open は当該文書Window環境設定群オブジェクトを差し替えますが、 実行中のコード (open メソッドの呼び出し元) で現に使用している設定群オブジェクト大域環境はそのままなので、 その実行が終わるまでは不思議なことが起こるかもしれません。

[51] JavaScript演算は普通大域環境に依存しない形で定義されています。

[52] 例えば isArray大域環境に関わらず、 Array であるかどうかを返します。

[53] Web IDL による型の検査も、大域環境に関わらず行われます。 プラットフォームオブジェクトの実装方法はそのような検査が行えるものである必要があります。

歴史

[17] >>15 まではスクリプト実行環境 (script execution environment) なる概念があり、 >>18 とは別に javascript: URL の実行時に空のオブジェクトをスクリプト実行環境とするケースがありました。

[1] Bug 5850 – JS global object ( 版) http://www.w3.org/Bugs/Public/show_bug.cgi?id=5850

[5] IRC logs: freenode / #whatwg / 20091202 ( 版) http://krijnhoetmer.nl/irc-logs/whatwg/20091202

[6] John Resig - Re-Securing JSON ( ( 版)) http://ejohn.org/blog/re-securing-json/

[7] Window Object 1.0 ( ( 版)) http://www.w3.org/TR/Window/#window-basic-scripting

[8] [whatwg] [[GetOwnProperty]] for named properties of the Window object ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-September/040715.html

[9] HTML Standard ( ( 版)) http://www.whatwg.org/specs/web-apps/current-work/#global-object

[68] Spec for [Global] does not seem to be quite web-compatible, and none of the UAs are really compatible with each other ( (Boris Zbarsky 著, 版)) http://lists.w3.org/Archives/Public/public-script-coord/2013OctDec/0405.html

[69] Global 拡張属性の値は、2014年7月以降、 複数指定する場合に (...) で括るように変更されました。

詳しくは Exposed を参照してください。

[71] 一次大域インターフェイス一次大域オブジェクト (primary global object) とも呼ばれていましたが、 2014年7月に修正されました >>72

[73] The SVG Micro DOM (uDOM) ( ( 版)) http://www.w3.org/TR/2006/CR-SVGMobile12-20060810/svgudom.html#global__Global

[74] The SVG Micro DOM (uDOM) ( ( 版)) http://www.w3.org/TR/2006/CR-SVGMobile12-20060810/svgudom.html#svg__SVGGlobal

[54] Update ECMAScript and IDL integration · whatwg/html@550c57f ( 版) https://github.com/whatwg/html/commit/550c57f186dd73784a8e4660440db2f642e37c0e

[55] Revert "Update ECMAScript and IDL integration" · whatwg/html@3a23548 ( 版) https://github.com/whatwg/html/commit/3a235480f1979fcddc65e07fe5a3be7bed428d17

[56] Fix #33: stop using JavaScript global environment · whatwg/xhr@1fbdcae ( 版) https://github.com/whatwg/xhr/commit/1fbdcaebffc7b98efb57121c324737634cc621f6

[58] Update ECMAScript and IDL integration · whatwg/html@52f96c4 ( 版) https://github.com/whatwg/html/commit/52f96c455a53763a7fe00162c067da6adb20e62c

[59] Update ECMAScript and IDL integration · whatwg/html@52f96c4 ( 版) https://github.com/whatwg/html/commit/52f96c455a53763a7fe00162c067da6adb20e62c

[61] Update ECMAScript and IDL integration · whatwg/html@52f96c4 ( 版) https://github.com/whatwg/html/commit/52f96c455a53763a7fe00162c067da6adb20e62c

[62] Can we eliminate the term "JavaScript global environment"? · Issue #380 · whatwg/html ( 版) https://github.com/whatwg/html/issues/380

[63] Rewrite global object initialization to delegate to ES · whatwg/html@cf0355d ( 版) https://github.com/whatwg/html/commit/cf0355d7e0e229b98f7fbd51b8c7608010c787f5

[85] Rewrite script execution on top of ES · whatwg/html@4891d18 ( 版) https://github.com/whatwg/html/commit/4891d18aaf2df1d40aa61f467a5a10cfc19dd85d

[86] 28375 – The global object has an origin in implementations, we should acknowledge this. Specifications also routinely assume it has one, e.g. IDB. ( 版) https://www.w3.org/Bugs/Public/show_bug.cgi?id=28375

[87] 28375 – The global object has an origin in implementations, we should acknowledge this. Specifications also routinely assume it has one, e.g. IDB. ( 版) https://www.w3.org/Bugs/Public/show_bug.cgi?id=28375

[88] Clarify settings object, realm, and global relationships · whatwg/html@0866f1b ( 版) https://github.com/whatwg/html/commit/0866f1b3f4b4ea5a99a30909e9bbe557dea0b460

[92] Move module map to Document/WorkerGlobalScope · whatwg/html@9a889fe ( 版) https://github.com/whatwg/html/commit/9a889fee2ecb106974fb48fa50491edd77047954

[93] Add a new section detailing the various potential realms ( (domenic著, )) https://github.com/whatwg/html/commit/6399af334edd6000bd394685923df5f0519194ab

[94] Remove support for [Constructor] on dictionaries (fixes #109). ( (Ms2ger著, )) https://github.com/heycam/webidl/commit/1982dc3f17002c07f93b39e22f69846478e4a9e2

[96] Editorial: fix typo in "Integration with IDL" ( (yuki3著, )) https://github.com/whatwg/html/commit/4bb63cf6bff37b1e8ca2815db0ff5cec202af9ea

[97] Add a new section detailing the various potential realms (domenic著, ) https://github.com/whatwg/html/commit/6399af334edd6000bd394685923df5f0519194ab

[99] Specify global object references in more detail (annevk著, ) https://github.com/whatwg/dom/commit/fa8adb6cd107cd845feaeb71c9da208971b670ca

[100] 1052139 – Try to lock down down the global prototype chain () https://bugzilla.mozilla.org/show_bug.cgi?id=1052139

[101] Make globals and things they inherit from have immutable prototypes (#… (domenic著, ) https://github.com/heycam/webidl/commit/06bae58f64f5326141036f65b1bb867aa36b84b2

[102] Remove realm argument of "perform a security check" (annevk著, ) https://github.com/heycam/webidl/commit/db9912d598bb59fed9422dd930e033e4832d52b7

[103] Remove realm argument from "perform a security check" (annevk著, ) https://github.com/whatwg/html/commit/c4c45b067bab83df44d90e24577c6f44dc5c57da

[104] Add legacy platform objects. (#230) (tobie著, ) https://github.com/heycam/webidl/commit/379685767dce3f953e187a2a8f3cb492b9b56649

[105] 29450 – perform a security check does not need realm argument () https://www.w3.org/Bugs/Public/show_bug.cgi?id=29450

[106] [worklets] Remove reference to "global environment". (bfgeek著, ) https://github.com/w3c/css-houdini-drafts/commit/5a2e381542b86830c9b1de30b1e8ccbd93834182

[107] Editorial: make domintro distinguish between window and self (annevk著, ) https://github.com/whatwg/html/commit/126a60e4694f347288fcf63e5af7e4d7d44fc848

[108] Cleanup `global object` usage to make sense with `Documents` (#254) (andypaicu著, ) https://github.com/w3c/webappsec-csp/commit/80bf6a439a744ebc7cb1b6d7373d0f0236d3584b

[109] Cleanup `global object` usage to make sense with `Documents` by andypaicu · Pull Request #254 · w3c/webappsec-csp () https://github.com/w3c/webappsec-csp/pull/254

[110] Make [Exposed] mandatory, remove [PrimaryGlobal] (#423) (tobie著, ) https://github.com/heycam/webidl/commit/d59937304702d033358b89fac5b5562c23b56096

[111] Cleanup remaining Document/Window object relations (annevk著, ) https://github.com/whatwg/html/commit/39dbb3e6de4216476cf7193ad9e5d56a861d5297

[112] document.open() simplifications, part 1 (TimothyGu著, ) https://github.com/whatwg/html/commit/6f769b8089a843066aa19f5991405bf4c84458b3

[113] Calling InitializeHostDefinedRealm in document.open is probably unnecessary · Issue #1698 · whatwg/html () https://github.com/whatwg/html/issues/1698

[114] document.open() simplifications: realm creation, unloading, tasks removal by TimothyGu · Pull Request #3918 · whatwg/html () https://github.com/whatwg/html/pull/3918

[115] Cleanup of global object/document usage (#333) (andypaicu著, ) https://github.com/w3c/webappsec-csp/commit/46bc83cc711212a6ca4ebaa6b3f5f7248429b377

[116] Cleanup of global object/document usage by andypaicu · Pull Request #333 · w3c/webappsec-csp () https://github.com/w3c/webappsec-csp/pull/333

[117] Documents are not global objects · Issue #208 · w3c/webappsec-csp () https://github.com/w3c/webappsec-csp/issues/208

[118] Only [Global] platform objects have an immutable prototype (littledan著, ) https://github.com/heycam/webidl/commit/8f48c5aef091b38854c6adc4e7e9b81e978a96fb

[119] Only [Global] platform objects are immutable prototype by littledan · Pull Request #596 · heycam/webidl () https://github.com/heycam/webidl/pull/596

[120] Correct requirement to define Global properties on the object itself (#… (Ms2ger著, ) https://github.com/heycam/webidl/commit/fc5da8f167dddda644c9a3540af7aea77c85c65a

[121] Correct requirement to define Global properties on the object itself by Ms2ger · Pull Request #639 · heycam/webidl () https://github.com/heycam/webidl/pull/639

[122] Imperatively define the global property references (Ms2ger著, ) https://github.com/heycam/webidl/commit/7bbff539127e7a7defd716cc5ae06f6778764a59

[123] Imperatively define the global property references by Ms2ger · Pull Request #648 · heycam/webidl () https://github.com/heycam/webidl/pull/648

[124] Remove references to ECMAScript global environments (Ms2ger著, ) https://github.com/heycam/webidl/commit/b4f9467f5f22871d882d833c3526c46007048982

[125] Remove references to ECMAScript global environments by Ms2ger · Pull Request #681 · heycam/webidl () https://github.com/heycam/webidl/pull/681

[126] Disallow combining Global with Constructor/NamedConstructor. (#745) (Ms2ger著, ) https://github.com/heycam/webidl/commit/a029460787be46f850abfc60f35cc6da05145b89

[127] Disallow combining Global with Constructor/NamedConstructor. by Ms2ger · Pull Request #745 · heycam/webidl () https://github.com/heycam/webidl/pull/745

[128] Should make it clear that [Global] and [Constructor] can't coexist · Issue #744 · heycam/webidl () https://github.com/heycam/webidl/issues/744