test_worker_interfaces.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. // This is a list of all interfaces that are exposed to workers.
  2. // Please only add things to this list with great care and proper review
  3. // from the associated module peers.
  4. // This file lists global interfaces we want exposed and verifies they
  5. // are what we intend. Each entry in the arrays below can either be a
  6. // simple string with the interface name, or an object with a 'name'
  7. // property giving the interface name as a string, and additional
  8. // properties which qualify the exposure of that interface. For example:
  9. //
  10. // [
  11. // "AGlobalInterface",
  12. // { name: "ExperimentalThing", release: false },
  13. // { name: "ReallyExperimentalThing", nightly: true },
  14. // { name: "DesktopOnlyThing", desktop: true },
  15. // { name: "FancyControl", xbl: true },
  16. // { name: "DisabledEverywhere", disabled: true },
  17. // ];
  18. //
  19. // See createInterfaceMap() below for a complete list of properties.
  20. // IMPORTANT: Do not change this list without review from
  21. // a JavaScript Engine peer!
  22. var ecmaGlobals =
  23. [
  24. "Array",
  25. "ArrayBuffer",
  26. "Boolean",
  27. "DataView",
  28. "Date",
  29. "Error",
  30. "EvalError",
  31. "Float32Array",
  32. "Float64Array",
  33. "Function",
  34. "Infinity",
  35. "Int16Array",
  36. "Int32Array",
  37. "Int8Array",
  38. "InternalError",
  39. "Intl",
  40. "Iterator",
  41. "JSON",
  42. "Map",
  43. "Math",
  44. "NaN",
  45. "Number",
  46. "Object",
  47. "Promise",
  48. "Proxy",
  49. "RangeError",
  50. "ReferenceError",
  51. "Reflect",
  52. "RegExp",
  53. "Set",
  54. {name: "SharedArrayBuffer", release: false},
  55. {name: "SIMD", nightly: true},
  56. {name: "Atomics", release: false},
  57. "StopIteration",
  58. "String",
  59. "Symbol",
  60. "SyntaxError",
  61. {name: "TypedObject", nightly: true},
  62. "TypeError",
  63. "Uint16Array",
  64. "Uint32Array",
  65. "Uint8Array",
  66. "Uint8ClampedArray",
  67. "URIError",
  68. "WeakMap",
  69. "WeakSet",
  70. ];
  71. // IMPORTANT: Do not change the list above without review from
  72. // a JavaScript Engine peer!
  73. // IMPORTANT: Do not change the list below without review from a DOM peer!
  74. var interfaceNamesInGlobalScope =
  75. [
  76. // IMPORTANT: Do not change this list without review from a DOM peer!
  77. "Blob",
  78. // IMPORTANT: Do not change this list without review from a DOM peer!
  79. "BroadcastChannel",
  80. // IMPORTANT: Do not change this list without review from a DOM peer!
  81. "Cache",
  82. // IMPORTANT: Do not change this list without review from a DOM peer!
  83. "CacheStorage",
  84. // IMPORTANT: Do not change this list without review from a DOM peer!
  85. "Crypto",
  86. // IMPORTANT: Do not change this list without review from a DOM peer!
  87. "CustomEvent",
  88. // IMPORTANT: Do not change this list without review from a DOM peer!
  89. "DedicatedWorkerGlobalScope",
  90. // IMPORTANT: Do not change this list without review from a DOM peer!
  91. "Directory",
  92. // IMPORTANT: Do not change this list without review from a DOM peer!
  93. "DOMCursor",
  94. // IMPORTANT: Do not change this list without review from a DOM peer!
  95. "DOMError",
  96. // IMPORTANT: Do not change this list without review from a DOM peer!
  97. "DOMException",
  98. // IMPORTANT: Do not change this list without review from a DOM peer!
  99. "DOMRequest",
  100. // IMPORTANT: Do not change this list without review from a DOM peer!
  101. "DOMStringList",
  102. // IMPORTANT: Do not change this list without review from a DOM peer!
  103. "Event",
  104. // IMPORTANT: Do not change this list without review from a DOM peer!
  105. "EventTarget",
  106. // IMPORTANT: Do not change this list without review from a DOM peer!
  107. "File",
  108. // IMPORTANT: Do not change this list without review from a DOM peer!
  109. "FileReader",
  110. // IMPORTANT: Do not change this list without review from a DOM peer!
  111. "FileReaderSync",
  112. // IMPORTANT: Do not change this list without review from a DOM peer!
  113. "FormData",
  114. // IMPORTANT: Do not change this list without review from a DOM peer!
  115. "Headers",
  116. // IMPORTANT: Do not change this list without review from a DOM peer!
  117. "IDBCursor",
  118. // IMPORTANT: Do not change this list without review from a DOM peer!
  119. "IDBCursorWithValue",
  120. // IMPORTANT: Do not change this list without review from a DOM peer!
  121. "IDBDatabase",
  122. // IMPORTANT: Do not change this list without review from a DOM peer!
  123. "IDBFactory",
  124. // IMPORTANT: Do not change this list without review from a DOM peer!
  125. "IDBIndex",
  126. // IMPORTANT: Do not change this list without review from a DOM peer!
  127. "IDBKeyRange",
  128. // IMPORTANT: Do not change this list without review from a DOM peer!
  129. "IDBObjectStore",
  130. // IMPORTANT: Do not change this list without review from a DOM peer!
  131. "IDBOpenDBRequest",
  132. // IMPORTANT: Do not change this list without review from a DOM peer!
  133. "IDBRequest",
  134. // IMPORTANT: Do not change this list without review from a DOM peer!
  135. "IDBTransaction",
  136. // IMPORTANT: Do not change this list without review from a DOM peer!
  137. "IDBVersionChangeEvent",
  138. // IMPORTANT: Do not change this list without review from a DOM peer!
  139. "ImageBitmap",
  140. // IMPORTANT: Do not change this list without review from a DOM peer!
  141. "ImageBitmapRenderingContext",
  142. // IMPORTANT: Do not change this list without review from a DOM peer!
  143. "ImageData",
  144. // IMPORTANT: Do not change this list without review from a DOM peer!
  145. "MessageChannel",
  146. // IMPORTANT: Do not change this list without review from a DOM peer!
  147. "MessageEvent",
  148. // IMPORTANT: Do not change this list without review from a DOM peer!
  149. "MessagePort",
  150. // IMPORTANT: Do not change this list without review from a DOM peer!
  151. "Notification",
  152. // IMPORTANT: Do not change this list without review from a DOM peer!
  153. { name: "OffscreenCanvas", disabled: true },
  154. // IMPORTANT: Do not change this list without review from a DOM peer!
  155. "Performance",
  156. // IMPORTANT: Do not change this list without review from a DOM peer!
  157. "PerformanceEntry",
  158. // IMPORTANT: Do not change this list without review from a DOM peer!
  159. "PerformanceMark",
  160. // IMPORTANT: Do not change this list without review from a DOM peer!
  161. "PerformanceMeasure",
  162. // IMPORTANT: Do not change this list without review from a DOM peer!
  163. "PerformanceObserver",
  164. // IMPORTANT: Do not change this list without review from a DOM peer!
  165. "PerformanceObserverEntryList",
  166. // IMPORTANT: Do not change this list without review from a DOM peer!
  167. "Request",
  168. // IMPORTANT: Do not change this list without review from a DOM peer!
  169. "Response",
  170. // IMPORTANT: Do not change this list without review from a DOM peer!
  171. {name: "StorageManager", nightly: true},
  172. // IMPORTANT: Do not change this list without review from a DOM peer!
  173. "SubtleCrypto",
  174. // IMPORTANT: Do not change this list without review from a DOM peer!
  175. "TextDecoder",
  176. // IMPORTANT: Do not change this list without review from a DOM peer!
  177. "TextEncoder",
  178. // IMPORTANT: Do not change this list without review from a DOM peer!
  179. "XMLHttpRequest",
  180. // IMPORTANT: Do not change this list without review from a DOM peer!
  181. "XMLHttpRequestEventTarget",
  182. // IMPORTANT: Do not change this list without review from a DOM peer!
  183. "XMLHttpRequestUpload",
  184. // IMPORTANT: Do not change this list without review from a DOM peer!
  185. "URL",
  186. // IMPORTANT: Do not change this list without review from a DOM peer!
  187. "URLSearchParams",
  188. // IMPORTANT: Do not change this list without review from a DOM peer!
  189. { name: "WebGLActiveInfo", disabled: true },
  190. // IMPORTANT: Do not change this list without review from a DOM peer!
  191. { name: "WebGLBuffer", disabled: true },
  192. // IMPORTANT: Do not change this list without review from a DOM peer!
  193. { name: "WebGLContextEvent", disabled: true },
  194. // IMPORTANT: Do not change this list without review from a DOM peer!
  195. { name: "WebGLFramebuffer", disabled: true },
  196. // IMPORTANT: Do not change this list without review from a DOM peer!
  197. { name: "WebGLProgram", disabled: true },
  198. // IMPORTANT: Do not change this list without review from a DOM peer!
  199. { name: "WebGLRenderbuffer", disabled: true },
  200. // IMPORTANT: Do not change this list without review from a DOM peer!
  201. { name: "WebGLRenderingContext", disabled: true },
  202. // IMPORTANT: Do not change this list without review from a DOM peer!
  203. { name: "WebGLShader", disabled: true },
  204. // IMPORTANT: Do not change this list without review from a DOM peer!
  205. { name: "WebGLShaderPrecisionFormat", disabled: true },
  206. // IMPORTANT: Do not change this list without review from a DOM peer!
  207. { name: "WebGLTexture", disabled: true },
  208. // IMPORTANT: Do not change this list without review from a DOM peer!
  209. { name: "WebGLUniformLocation", disabled: true },
  210. // IMPORTANT: Do not change this list without review from a DOM peer!
  211. "WebSocket",
  212. // IMPORTANT: Do not change this list without review from a DOM peer!
  213. "Worker",
  214. // IMPORTANT: Do not change this list without review from a DOM peer!
  215. "WorkerGlobalScope",
  216. // IMPORTANT: Do not change this list without review from a DOM peer!
  217. "WorkerLocation",
  218. // IMPORTANT: Do not change this list without review from a DOM peer!
  219. "WorkerNavigator",
  220. // IMPORTANT: Do not change this list without review from a DOM peer!
  221. ];
  222. // IMPORTANT: Do not change the list above without review from a DOM peer!
  223. function createInterfaceMap(version, userAgent) {
  224. var isNightly = version.endsWith("a1");
  225. var isRelease = !version.includes("a");
  226. var isDesktop = !/Mobile|Tablet/.test(userAgent);
  227. var isAndroid = !!navigator.userAgent.includes("Android");
  228. var interfaceMap = {};
  229. function addInterfaces(interfaces)
  230. {
  231. for (var entry of interfaces) {
  232. if (typeof(entry) === "string") {
  233. interfaceMap[entry] = true;
  234. } else {
  235. ok(!("pref" in entry), "Bogus pref annotation for " + entry.name);
  236. if ((entry.nightly === !isNightly) ||
  237. (entry.nightlyAndroid === !(isAndroid && isNightly) && isAndroid) ||
  238. (entry.desktop === !isDesktop) ||
  239. (entry.android === !isAndroid && !entry.nightlyAndroid) ||
  240. (entry.release === !isRelease) ||
  241. entry.disabled) {
  242. interfaceMap[entry.name] = false;
  243. } else {
  244. interfaceMap[entry.name] = true;
  245. }
  246. }
  247. }
  248. }
  249. addInterfaces(ecmaGlobals);
  250. addInterfaces(interfaceNamesInGlobalScope);
  251. return interfaceMap;
  252. }
  253. function runTest(version, userAgent) {
  254. var interfaceMap = createInterfaceMap(version, userAgent);
  255. for (var name of Object.getOwnPropertyNames(self)) {
  256. // An interface name should start with an upper case character.
  257. if (!/^[A-Z]/.test(name)) {
  258. continue;
  259. }
  260. ok(interfaceMap[name],
  261. "If this is failing: DANGER, are you sure you want to expose the new interface " + name +
  262. " to all webpages as a property on the worker? Do not make a change to this file without a " +
  263. " review from a DOM peer for that specific change!!! (or a JS peer for changes to ecmaGlobals)");
  264. delete interfaceMap[name];
  265. }
  266. for (var name of Object.keys(interfaceMap)) {
  267. ok(name in self === interfaceMap[name],
  268. name + " should " + (interfaceMap[name] ? "" : " NOT") + " be defined on the global scope");
  269. if (!interfaceMap[name]) {
  270. delete interfaceMap[name];
  271. }
  272. }
  273. is(Object.keys(interfaceMap).length, 0,
  274. "The following interface(s) are not enumerated: " + Object.keys(interfaceMap).join(", "));
  275. }
  276. workerTestGetVersion(function(version) {
  277. workerTestGetUserAgent(function(userAgent) {
  278. runTest(version, userAgent);
  279. workerTestDone();
  280. });
  281. });