selenium-webdriver 2.48.2 → 2.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (524) hide show
  1. package/CHANGES.md +57 -0
  2. package/NOTICE +1 -1
  3. package/README.md +56 -6
  4. package/builder.js +375 -358
  5. package/chrome.js +549 -586
  6. package/edge.js +378 -0
  7. package/error.js +597 -5
  8. package/example/google_search_generator.js +2 -4
  9. package/example/logging.js +6 -2
  10. package/executors.js +11 -27
  11. package/firefox/binary.js +79 -87
  12. package/firefox/extension.js +10 -18
  13. package/firefox/index.js +173 -173
  14. package/firefox/profile.js +220 -240
  15. package/http/index.js +396 -79
  16. package/http/util.js +35 -35
  17. package/ie.js +288 -309
  18. package/index.js +34 -125
  19. package/io/exec.js +58 -39
  20. package/io/index.js +54 -48
  21. package/lib/actions.js +594 -0
  22. package/lib/by.js +276 -0
  23. package/lib/capabilities.js +404 -0
  24. package/lib/{webdriver/command.js → command.js} +88 -72
  25. package/lib/{webdriver/button.js → devmode.js} +13 -8
  26. package/lib/events.js +210 -0
  27. package/lib/firefox/amd64/libnoblur64.so +0 -0
  28. package/lib/firefox/i386/libnoblur.so +0 -0
  29. package/lib/firefox/webdriver.json +5 -1
  30. package/lib/firefox/webdriver.xpi +0 -0
  31. package/lib/{webdriver/key.js → input.js} +82 -2
  32. package/lib/logging.js +668 -0
  33. package/lib/{webdriver/promise.js → promise.js} +688 -644
  34. package/lib/session.js +79 -0
  35. package/lib/{webdriver/serializable.js → symbols.js} +11 -16
  36. package/lib/test/build.js +4 -4
  37. package/lib/test/data/click_tests/html5_submit_buttons.html +2 -1
  38. package/lib/test/data/click_tests/overlapping_elements.html +15 -4
  39. package/lib/test/data/click_tests/partially_overlapping_elements.html +124 -0
  40. package/lib/test/data/click_tests/wrapped_overlapping_elements.html +13 -0
  41. package/lib/test/data/readOnlyPage.html +1 -1
  42. package/lib/test/data/selectPage.html +18 -2
  43. package/lib/test/fileserver.js +3 -4
  44. package/lib/test/index.js +7 -3
  45. package/lib/test/resources.js +1 -1
  46. package/lib/until.js +428 -0
  47. package/lib/webdriver.js +2351 -0
  48. package/net/portprober.js +15 -11
  49. package/opera.js +295 -314
  50. package/package.json +6 -5
  51. package/phantomjs.js +135 -140
  52. package/proxy.js +6 -4
  53. package/remote/index.js +229 -221
  54. package/safari.js +319 -310
  55. package/test/chrome/options_test.js +11 -9
  56. package/test/element_finding_test.js +51 -13
  57. package/test/error_test.js +163 -0
  58. package/test/execute_script_test.js +1 -1
  59. package/test/http/http_test.js +317 -55
  60. package/test/http/util_test.js +25 -23
  61. package/test/io_test.js +6 -1
  62. package/test/lib/by_test.js +127 -0
  63. package/test/lib/capabilities_test.js +84 -0
  64. package/test/lib/events_test.js +177 -0
  65. package/test/lib/logging_test.js +272 -0
  66. package/test/{promise_aplus_test.js → lib/promise_aplus_test.js} +4 -13
  67. package/test/lib/promise_error_test.js +808 -0
  68. package/test/lib/promise_flow_test.js +2282 -0
  69. package/test/lib/promise_generator_test.js +308 -0
  70. package/test/lib/promise_test.js +996 -0
  71. package/test/lib/testutil.js +90 -0
  72. package/test/lib/until_test.js +436 -0
  73. package/test/lib/webdriver_test.js +2207 -0
  74. package/test/page_loading_test.js +7 -9
  75. package/test/stale_element_test.js +2 -2
  76. package/test/testing/assert_test.js +374 -0
  77. package/test/testing/index_test.js +9 -11
  78. package/testing/assert.js +334 -17
  79. package/testing/index.js +10 -0
  80. package/_base.js +0 -200
  81. package/docs/Changes.html +0 -356
  82. package/docs/class_bot_Error.html +0 -15
  83. package/docs/class_webdriver_ActionSequence.html +0 -115
  84. package/docs/class_webdriver_Alert.html +0 -24
  85. package/docs/class_webdriver_AlertPromise.html +0 -92
  86. package/docs/class_webdriver_Capabilities.html +0 -60
  87. package/docs/class_webdriver_Command.html +0 -15
  88. package/docs/class_webdriver_EventEmitter.html +0 -35
  89. package/docs/class_webdriver_FileDetector.html +0 -21
  90. package/docs/class_webdriver_Locator.html +0 -12
  91. package/docs/class_webdriver_Serializable.html +0 -9
  92. package/docs/class_webdriver_Session.html +0 -13
  93. package/docs/class_webdriver_TouchSequence.html +0 -49
  94. package/docs/class_webdriver_UnhandledAlertError.html +0 -18
  95. package/docs/class_webdriver_WebDriver.html +0 -313
  96. package/docs/class_webdriver_WebDriver_Logs.html +0 -15
  97. package/docs/class_webdriver_WebDriver_Navigation.html +0 -16
  98. package/docs/class_webdriver_WebDriver_Options.html +0 -41
  99. package/docs/class_webdriver_WebDriver_TargetLocator.html +0 -38
  100. package/docs/class_webdriver_WebDriver_Timeouts.html +0 -29
  101. package/docs/class_webdriver_WebDriver_Window.html +0 -27
  102. package/docs/class_webdriver_WebElement.html +0 -223
  103. package/docs/class_webdriver_WebElementPromise.html +0 -274
  104. package/docs/class_webdriver_http_Executor.html +0 -22
  105. package/docs/class_webdriver_http_Request.html +0 -12
  106. package/docs/class_webdriver_http_Response.html +0 -13
  107. package/docs/class_webdriver_logging_Entry.html +0 -15
  108. package/docs/class_webdriver_logging_Level.html +0 -55
  109. package/docs/class_webdriver_logging_LogRecord.html +0 -45
  110. package/docs/class_webdriver_logging_Logger.html +0 -119
  111. package/docs/class_webdriver_logging_Preferences.html +0 -8
  112. package/docs/class_webdriver_promise_CancellationError.html +0 -17
  113. package/docs/class_webdriver_promise_ControlFlow.html +0 -153
  114. package/docs/class_webdriver_promise_Deferred.html +0 -84
  115. package/docs/class_webdriver_promise_MultipleUnhandledRejectionError.html +0 -14
  116. package/docs/class_webdriver_promise_Promise.html +0 -75
  117. package/docs/class_webdriver_stacktrace_Frame.html +0 -20
  118. package/docs/class_webdriver_stacktrace_Snapshot.html +0 -6
  119. package/docs/class_webdriver_testing_Assertion.html +0 -99
  120. package/docs/class_webdriver_testing_Assertion_DelegatingMatcher_.html +0 -13
  121. package/docs/class_webdriver_testing_ContainsMatcher.html +0 -11
  122. package/docs/class_webdriver_testing_NegatedAssertion.html +0 -97
  123. package/docs/class_webdriver_until_Condition.html +0 -7
  124. package/docs/dossier.css +0 -1
  125. package/docs/dossier.js +0 -86
  126. package/docs/enum_bot_ErrorCode.html +0 -3
  127. package/docs/enum_bot_Error_State.html +0 -2
  128. package/docs/enum_webdriver_Browser.html +0 -2
  129. package/docs/enum_webdriver_Button.html +0 -2
  130. package/docs/enum_webdriver_Capability.html +0 -33
  131. package/docs/enum_webdriver_CommandName.html +0 -3
  132. package/docs/enum_webdriver_Key.html +0 -12
  133. package/docs/enum_webdriver_logging_Type.html +0 -6
  134. package/docs/enum_webdriver_promise_ControlFlow_EventType.html +0 -9
  135. package/docs/index.html +0 -125
  136. package/docs/interface_webdriver_CommandExecutor.html +0 -9
  137. package/docs/interface_webdriver_http_Client.html +0 -10
  138. package/docs/interface_webdriver_promise_Thenable.html +0 -77
  139. package/docs/module_selenium-webdriver.html +0 -23
  140. package/docs/module_selenium-webdriver__base.html +0 -23
  141. package/docs/module_selenium-webdriver__base_class_Context.html +0 -5
  142. package/docs/module_selenium-webdriver_builder.html +0 -2
  143. package/docs/module_selenium-webdriver_builder_class_Builder.html +0 -138
  144. package/docs/module_selenium-webdriver_chrome.html +0 -90
  145. package/docs/module_selenium-webdriver_chrome_class_Driver.html +0 -280
  146. package/docs/module_selenium-webdriver_chrome_class_Options.html +0 -127
  147. package/docs/module_selenium-webdriver_chrome_class_ServiceBuilder.html +0 -46
  148. package/docs/module_selenium-webdriver_class_ActionSequence.html +0 -115
  149. package/docs/module_selenium-webdriver_class_Builder.html +0 -138
  150. package/docs/module_selenium-webdriver_class_Capabilities.html +0 -60
  151. package/docs/module_selenium-webdriver_class_Command.html +0 -15
  152. package/docs/module_selenium-webdriver_class_EventEmitter.html +0 -35
  153. package/docs/module_selenium-webdriver_class_FileDetector.html +0 -21
  154. package/docs/module_selenium-webdriver_class_Serializable.html +0 -9
  155. package/docs/module_selenium-webdriver_class_Session.html +0 -13
  156. package/docs/module_selenium-webdriver_class_WebDriver.html +0 -313
  157. package/docs/module_selenium-webdriver_class_WebElement.html +0 -223
  158. package/docs/module_selenium-webdriver_class_WebElementPromise.html +0 -274
  159. package/docs/module_selenium-webdriver_enum_Browser.html +0 -2
  160. package/docs/module_selenium-webdriver_enum_Button.html +0 -2
  161. package/docs/module_selenium-webdriver_enum_Capability.html +0 -33
  162. package/docs/module_selenium-webdriver_enum_CommandName.html +0 -3
  163. package/docs/module_selenium-webdriver_enum_Key.html +0 -12
  164. package/docs/module_selenium-webdriver_error.html +0 -4
  165. package/docs/module_selenium-webdriver_error_class_Error.html +0 -15
  166. package/docs/module_selenium-webdriver_error_enum_ErrorCode.html +0 -3
  167. package/docs/module_selenium-webdriver_executors.html +0 -10
  168. package/docs/module_selenium-webdriver_executors_class_DeferredExecutor.html +0 -12
  169. package/docs/module_selenium-webdriver_firefox.html +0 -68
  170. package/docs/module_selenium-webdriver_firefox_binary.html +0 -5
  171. package/docs/module_selenium-webdriver_firefox_binary_class_Binary.html +0 -20
  172. package/docs/module_selenium-webdriver_firefox_class_Binary.html +0 -20
  173. package/docs/module_selenium-webdriver_firefox_class_Driver.html +0 -276
  174. package/docs/module_selenium-webdriver_firefox_class_Options.html +0 -19
  175. package/docs/module_selenium-webdriver_firefox_class_Profile.html +0 -50
  176. package/docs/module_selenium-webdriver_firefox_extension.html +0 -8
  177. package/docs/module_selenium-webdriver_firefox_profile.html +0 -13
  178. package/docs/module_selenium-webdriver_firefox_profile_class_Profile.html +0 -50
  179. package/docs/module_selenium-webdriver_http.html +0 -9
  180. package/docs/module_selenium-webdriver_http_class_Executor.html +0 -22
  181. package/docs/module_selenium-webdriver_http_class_HttpClient.html +0 -16
  182. package/docs/module_selenium-webdriver_http_class_Request.html +0 -12
  183. package/docs/module_selenium-webdriver_http_class_Response.html +0 -13
  184. package/docs/module_selenium-webdriver_http_util.html +0 -17
  185. package/docs/module_selenium-webdriver_ie.html +0 -11
  186. package/docs/module_selenium-webdriver_ie_class_Driver.html +0 -274
  187. package/docs/module_selenium-webdriver_ie_class_Options.html +0 -89
  188. package/docs/module_selenium-webdriver_ie_enum_Level.html +0 -1
  189. package/docs/module_selenium-webdriver_io.html +0 -37
  190. package/docs/module_selenium-webdriver_io_exec.html +0 -6
  191. package/docs/module_selenium-webdriver_namespace_By.html +0 -56
  192. package/docs/module_selenium-webdriver_namespace_error.html +0 -4
  193. package/docs/module_selenium-webdriver_namespace_logging.html +0 -18
  194. package/docs/module_selenium-webdriver_namespace_promise.html +0 -163
  195. package/docs/module_selenium-webdriver_namespace_stacktrace.html +0 -17
  196. package/docs/module_selenium-webdriver_namespace_until.html +0 -82
  197. package/docs/module_selenium-webdriver_net.html +0 -7
  198. package/docs/module_selenium-webdriver_net_portprober.html +0 -12
  199. package/docs/module_selenium-webdriver_opera.html +0 -62
  200. package/docs/module_selenium-webdriver_opera_class_Driver.html +0 -276
  201. package/docs/module_selenium-webdriver_opera_class_Options.html +0 -44
  202. package/docs/module_selenium-webdriver_opera_class_ServiceBuilder.html +0 -35
  203. package/docs/module_selenium-webdriver_phantomjs.html +0 -2
  204. package/docs/module_selenium-webdriver_phantomjs_class_Driver.html +0 -299
  205. package/docs/module_selenium-webdriver_proxy.html +0 -28
  206. package/docs/module_selenium-webdriver_remote.html +0 -8
  207. package/docs/module_selenium-webdriver_remote_class_DriverService.html +0 -32
  208. package/docs/module_selenium-webdriver_remote_class_FileDetector.html +0 -22
  209. package/docs/module_selenium-webdriver_remote_class_SeleniumServer.html +0 -41
  210. package/docs/module_selenium-webdriver_safari.html +0 -9
  211. package/docs/module_selenium-webdriver_safari_class_Driver.html +0 -279
  212. package/docs/module_selenium-webdriver_safari_class_Options.html +0 -23
  213. package/docs/module_selenium-webdriver_testing.html +0 -74
  214. package/docs/module_selenium-webdriver_testing_assert.html +0 -9
  215. package/docs/namespace_bot.html +0 -4
  216. package/docs/namespace_bot_json.html +0 -20
  217. package/docs/namespace_bot_response.html +0 -18
  218. package/docs/namespace_bot_userAgent.html +0 -33
  219. package/docs/namespace_webdriver.html +0 -30
  220. package/docs/namespace_webdriver_By.html +0 -56
  221. package/docs/namespace_webdriver_http.html +0 -6
  222. package/docs/namespace_webdriver_logging.html +0 -70
  223. package/docs/namespace_webdriver_promise.html +0 -688
  224. package/docs/namespace_webdriver_stacktrace.html +0 -17
  225. package/docs/namespace_webdriver_testing.html +0 -7
  226. package/docs/namespace_webdriver_testing_assert.html +0 -9
  227. package/docs/namespace_webdriver_testing_asserts.html +0 -18
  228. package/docs/namespace_webdriver_until.html +0 -82
  229. package/docs/source/_base.js.src.html +0 -1
  230. package/docs/source/builder.js.src.html +0 -1
  231. package/docs/source/chrome.js.src.html +0 -1
  232. package/docs/source/error.js.src.html +0 -1
  233. package/docs/source/executors.js.src.html +0 -1
  234. package/docs/source/firefox/binary.js.src.html +0 -1
  235. package/docs/source/firefox/extension.js.src.html +0 -1
  236. package/docs/source/firefox/index.js.src.html +0 -1
  237. package/docs/source/firefox/profile.js.src.html +0 -1
  238. package/docs/source/http/index.js.src.html +0 -1
  239. package/docs/source/http/util.js.src.html +0 -1
  240. package/docs/source/ie.js.src.html +0 -1
  241. package/docs/source/index.js.src.html +0 -1
  242. package/docs/source/io/exec.js.src.html +0 -1
  243. package/docs/source/io/index.js.src.html +0 -1
  244. package/docs/source/lib/atoms/error.js.src.html +0 -1
  245. package/docs/source/lib/atoms/json.js.src.html +0 -1
  246. package/docs/source/lib/atoms/response.js.src.html +0 -1
  247. package/docs/source/lib/atoms/userAgent.js.src.html +0 -1
  248. package/docs/source/lib/goog/array/array.js.src.html +0 -1
  249. package/docs/source/lib/goog/asserts/asserts.js.src.html +0 -1
  250. package/docs/source/lib/goog/async/freelist.js.src.html +0 -1
  251. package/docs/source/lib/goog/async/nexttick.js.src.html +0 -1
  252. package/docs/source/lib/goog/async/run.js.src.html +0 -1
  253. package/docs/source/lib/goog/async/workqueue.js.src.html +0 -1
  254. package/docs/source/lib/goog/base.js.src.html +0 -1
  255. package/docs/source/lib/goog/debug/debug.js.src.html +0 -1
  256. package/docs/source/lib/goog/debug/entrypointregistry.js.src.html +0 -1
  257. package/docs/source/lib/goog/debug/error.js.src.html +0 -1
  258. package/docs/source/lib/goog/debug/logbuffer.js.src.html +0 -1
  259. package/docs/source/lib/goog/debug/logger.js.src.html +0 -1
  260. package/docs/source/lib/goog/debug/logrecord.js.src.html +0 -1
  261. package/docs/source/lib/goog/deps.js.src.html +0 -1
  262. package/docs/source/lib/goog/disposable/disposable.js.src.html +0 -1
  263. package/docs/source/lib/goog/disposable/idisposable.js.src.html +0 -1
  264. package/docs/source/lib/goog/dom/browserfeature.js.src.html +0 -1
  265. package/docs/source/lib/goog/dom/dom.js.src.html +0 -1
  266. package/docs/source/lib/goog/dom/nodetype.js.src.html +0 -1
  267. package/docs/source/lib/goog/dom/safe.js.src.html +0 -1
  268. package/docs/source/lib/goog/dom/tagname.js.src.html +0 -1
  269. package/docs/source/lib/goog/dom/tags.js.src.html +0 -1
  270. package/docs/source/lib/goog/dom/vendor.js.src.html +0 -1
  271. package/docs/source/lib/goog/events/browserevent.js.src.html +0 -1
  272. package/docs/source/lib/goog/events/browserfeature.js.src.html +0 -1
  273. package/docs/source/lib/goog/events/event.js.src.html +0 -1
  274. package/docs/source/lib/goog/events/eventid.js.src.html +0 -1
  275. package/docs/source/lib/goog/events/events.js.src.html +0 -1
  276. package/docs/source/lib/goog/events/eventtarget.js.src.html +0 -1
  277. package/docs/source/lib/goog/events/eventtype.js.src.html +0 -1
  278. package/docs/source/lib/goog/events/keycodes.js.src.html +0 -1
  279. package/docs/source/lib/goog/events/listenable.js.src.html +0 -1
  280. package/docs/source/lib/goog/events/listener.js.src.html +0 -1
  281. package/docs/source/lib/goog/events/listenermap.js.src.html +0 -1
  282. package/docs/source/lib/goog/fs/url.js.src.html +0 -1
  283. package/docs/source/lib/goog/functions/functions.js.src.html +0 -1
  284. package/docs/source/lib/goog/html/safehtml.js.src.html +0 -1
  285. package/docs/source/lib/goog/html/safescript.js.src.html +0 -1
  286. package/docs/source/lib/goog/html/safestyle.js.src.html +0 -1
  287. package/docs/source/lib/goog/html/safestylesheet.js.src.html +0 -1
  288. package/docs/source/lib/goog/html/safeurl.js.src.html +0 -1
  289. package/docs/source/lib/goog/html/trustedresourceurl.js.src.html +0 -1
  290. package/docs/source/lib/goog/html/uncheckedconversions.js.src.html +0 -1
  291. package/docs/source/lib/goog/i18n/bidi.js.src.html +0 -1
  292. package/docs/source/lib/goog/iter/iter.js.src.html +0 -1
  293. package/docs/source/lib/goog/json/json.js.src.html +0 -1
  294. package/docs/source/lib/goog/labs/testing/assertthat.js.src.html +0 -1
  295. package/docs/source/lib/goog/labs/testing/logicmatcher.js.src.html +0 -1
  296. package/docs/source/lib/goog/labs/testing/matcher.js.src.html +0 -1
  297. package/docs/source/lib/goog/labs/testing/numbermatcher.js.src.html +0 -1
  298. package/docs/source/lib/goog/labs/testing/objectmatcher.js.src.html +0 -1
  299. package/docs/source/lib/goog/labs/testing/stringmatcher.js.src.html +0 -1
  300. package/docs/source/lib/goog/labs/useragent/browser.js.src.html +0 -1
  301. package/docs/source/lib/goog/labs/useragent/engine.js.src.html +0 -1
  302. package/docs/source/lib/goog/labs/useragent/platform.js.src.html +0 -1
  303. package/docs/source/lib/goog/labs/useragent/util.js.src.html +0 -1
  304. package/docs/source/lib/goog/log/log.js.src.html +0 -1
  305. package/docs/source/lib/goog/math/box.js.src.html +0 -1
  306. package/docs/source/lib/goog/math/coordinate.js.src.html +0 -1
  307. package/docs/source/lib/goog/math/math.js.src.html +0 -1
  308. package/docs/source/lib/goog/math/rect.js.src.html +0 -1
  309. package/docs/source/lib/goog/math/size.js.src.html +0 -1
  310. package/docs/source/lib/goog/net/wrapperxmlhttpfactory.js.src.html +0 -1
  311. package/docs/source/lib/goog/net/xhrlike.js.src.html +0 -1
  312. package/docs/source/lib/goog/net/xmlhttp.js.src.html +0 -1
  313. package/docs/source/lib/goog/net/xmlhttpfactory.js.src.html +0 -1
  314. package/docs/source/lib/goog/object/object.js.src.html +0 -1
  315. package/docs/source/lib/goog/promise/promise.js.src.html +0 -1
  316. package/docs/source/lib/goog/promise/resolver.js.src.html +0 -1
  317. package/docs/source/lib/goog/promise/thenable.js.src.html +0 -1
  318. package/docs/source/lib/goog/reflect/reflect.js.src.html +0 -1
  319. package/docs/source/lib/goog/string/const.js.src.html +0 -1
  320. package/docs/source/lib/goog/string/string.js.src.html +0 -1
  321. package/docs/source/lib/goog/string/typedstring.js.src.html +0 -1
  322. package/docs/source/lib/goog/structs/collection.js.src.html +0 -1
  323. package/docs/source/lib/goog/structs/map.js.src.html +0 -1
  324. package/docs/source/lib/goog/structs/set.js.src.html +0 -1
  325. package/docs/source/lib/goog/structs/structs.js.src.html +0 -1
  326. package/docs/source/lib/goog/style/style.js.src.html +0 -1
  327. package/docs/source/lib/goog/testing/asserts.js.src.html +0 -1
  328. package/docs/source/lib/goog/testing/events/events.js.src.html +0 -1
  329. package/docs/source/lib/goog/testing/functionmock.js.src.html +0 -1
  330. package/docs/source/lib/goog/testing/jsunit.js.src.html +0 -1
  331. package/docs/source/lib/goog/testing/loosemock.js.src.html +0 -1
  332. package/docs/source/lib/goog/testing/mock.js.src.html +0 -1
  333. package/docs/source/lib/goog/testing/mockclock.js.src.html +0 -1
  334. package/docs/source/lib/goog/testing/mockcontrol.js.src.html +0 -1
  335. package/docs/source/lib/goog/testing/mockinterface.js.src.html +0 -1
  336. package/docs/source/lib/goog/testing/mockmatchers.js.src.html +0 -1
  337. package/docs/source/lib/goog/testing/objectpropertystring.js.src.html +0 -1
  338. package/docs/source/lib/goog/testing/propertyreplacer.js.src.html +0 -1
  339. package/docs/source/lib/goog/testing/recordfunction.js.src.html +0 -1
  340. package/docs/source/lib/goog/testing/stacktrace.js.src.html +0 -1
  341. package/docs/source/lib/goog/testing/strictmock.js.src.html +0 -1
  342. package/docs/source/lib/goog/testing/testcase.js.src.html +0 -1
  343. package/docs/source/lib/goog/testing/testrunner.js.src.html +0 -1
  344. package/docs/source/lib/goog/uri/uri.js.src.html +0 -1
  345. package/docs/source/lib/goog/uri/utils.js.src.html +0 -1
  346. package/docs/source/lib/goog/useragent/product.js.src.html +0 -1
  347. package/docs/source/lib/goog/useragent/product_isversion.js.src.html +0 -1
  348. package/docs/source/lib/goog/useragent/useragent.js.src.html +0 -1
  349. package/docs/source/lib/webdriver/actionsequence.js.src.html +0 -1
  350. package/docs/source/lib/webdriver/button.js.src.html +0 -1
  351. package/docs/source/lib/webdriver/capabilities.js.src.html +0 -1
  352. package/docs/source/lib/webdriver/command.js.src.html +0 -1
  353. package/docs/source/lib/webdriver/events.js.src.html +0 -1
  354. package/docs/source/lib/webdriver/http/http.js.src.html +0 -1
  355. package/docs/source/lib/webdriver/key.js.src.html +0 -1
  356. package/docs/source/lib/webdriver/locators.js.src.html +0 -1
  357. package/docs/source/lib/webdriver/logging.js.src.html +0 -1
  358. package/docs/source/lib/webdriver/promise.js.src.html +0 -1
  359. package/docs/source/lib/webdriver/serializable.js.src.html +0 -1
  360. package/docs/source/lib/webdriver/session.js.src.html +0 -1
  361. package/docs/source/lib/webdriver/stacktrace.js.src.html +0 -1
  362. package/docs/source/lib/webdriver/testing/asserts.js.src.html +0 -1
  363. package/docs/source/lib/webdriver/touchsequence.js.src.html +0 -1
  364. package/docs/source/lib/webdriver/until.js.src.html +0 -1
  365. package/docs/source/lib/webdriver/webdriver.js.src.html +0 -1
  366. package/docs/source/net/index.js.src.html +0 -1
  367. package/docs/source/net/portprober.js.src.html +0 -1
  368. package/docs/source/opera.js.src.html +0 -1
  369. package/docs/source/phantomjs.js.src.html +0 -1
  370. package/docs/source/proxy.js.src.html +0 -1
  371. package/docs/source/remote/index.js.src.html +0 -1
  372. package/docs/source/safari.js.src.html +0 -1
  373. package/docs/source/testing/assert.js.src.html +0 -1
  374. package/docs/source/testing/index.js.src.html +0 -1
  375. package/docs/types.js +0 -1
  376. package/lib/atoms/error.js +0 -202
  377. package/lib/atoms/json.js +0 -80
  378. package/lib/atoms/response.js +0 -110
  379. package/lib/atoms/userAgent.js +0 -257
  380. package/lib/goog/LICENSE +0 -176
  381. package/lib/goog/array/array.js +0 -1654
  382. package/lib/goog/asserts/asserts.js +0 -365
  383. package/lib/goog/async/freelist.js +0 -88
  384. package/lib/goog/async/nexttick.js +0 -241
  385. package/lib/goog/async/run.js +0 -133
  386. package/lib/goog/async/workqueue.js +0 -139
  387. package/lib/goog/base.js +0 -2548
  388. package/lib/goog/debug/debug.js +0 -653
  389. package/lib/goog/debug/entrypointregistry.js +0 -158
  390. package/lib/goog/debug/error.js +0 -63
  391. package/lib/goog/debug/logbuffer.js +0 -148
  392. package/lib/goog/debug/logger.js +0 -873
  393. package/lib/goog/debug/logrecord.js +0 -242
  394. package/lib/goog/deps.js +0 -151
  395. package/lib/goog/disposable/disposable.js +0 -307
  396. package/lib/goog/disposable/idisposable.js +0 -45
  397. package/lib/goog/dom/browserfeature.js +0 -72
  398. package/lib/goog/dom/dom.js +0 -2991
  399. package/lib/goog/dom/nodetype.js +0 -48
  400. package/lib/goog/dom/safe.js +0 -347
  401. package/lib/goog/dom/tagname.js +0 -160
  402. package/lib/goog/dom/tags.js +0 -41
  403. package/lib/goog/dom/vendor.js +0 -96
  404. package/lib/goog/events/browserevent.js +0 -400
  405. package/lib/goog/events/browserfeature.js +0 -85
  406. package/lib/goog/events/event.js +0 -143
  407. package/lib/goog/events/eventid.js +0 -47
  408. package/lib/goog/events/events.js +0 -984
  409. package/lib/goog/events/eventtarget.js +0 -394
  410. package/lib/goog/events/eventtype.js +0 -237
  411. package/lib/goog/events/keycodes.js +0 -427
  412. package/lib/goog/events/listenable.js +0 -335
  413. package/lib/goog/events/listener.js +0 -131
  414. package/lib/goog/events/listenermap.js +0 -308
  415. package/lib/goog/fs/url.js +0 -109
  416. package/lib/goog/functions/functions.js +0 -442
  417. package/lib/goog/html/safehtml.js +0 -757
  418. package/lib/goog/html/safescript.js +0 -234
  419. package/lib/goog/html/safestyle.js +0 -442
  420. package/lib/goog/html/safestylesheet.js +0 -276
  421. package/lib/goog/html/safeurl.js +0 -398
  422. package/lib/goog/html/trustedresourceurl.js +0 -224
  423. package/lib/goog/html/uncheckedconversions.js +0 -232
  424. package/lib/goog/i18n/bidi.js +0 -908
  425. package/lib/goog/iter/iter.js +0 -1302
  426. package/lib/goog/json/json.js +0 -363
  427. package/lib/goog/labs/testing/assertthat.js +0 -58
  428. package/lib/goog/labs/testing/logicmatcher.js +0 -212
  429. package/lib/goog/labs/testing/matcher.js +0 -80
  430. package/lib/goog/labs/testing/numbermatcher.js +0 -346
  431. package/lib/goog/labs/testing/objectmatcher.js +0 -317
  432. package/lib/goog/labs/testing/stringmatcher.js +0 -415
  433. package/lib/goog/labs/useragent/browser.js +0 -341
  434. package/lib/goog/labs/useragent/engine.js +0 -160
  435. package/lib/goog/labs/useragent/platform.js +0 -160
  436. package/lib/goog/labs/useragent/util.js +0 -148
  437. package/lib/goog/log/log.js +0 -197
  438. package/lib/goog/math/box.js +0 -398
  439. package/lib/goog/math/coordinate.js +0 -268
  440. package/lib/goog/math/math.js +0 -451
  441. package/lib/goog/math/rect.js +0 -476
  442. package/lib/goog/math/size.js +0 -227
  443. package/lib/goog/net/wrapperxmlhttpfactory.js +0 -71
  444. package/lib/goog/net/xhrlike.js +0 -124
  445. package/lib/goog/net/xmlhttp.js +0 -246
  446. package/lib/goog/net/xmlhttpfactory.js +0 -67
  447. package/lib/goog/object/object.js +0 -686
  448. package/lib/goog/promise/promise.js +0 -1350
  449. package/lib/goog/promise/resolver.js +0 -48
  450. package/lib/goog/promise/thenable.js +0 -126
  451. package/lib/goog/reflect/reflect.js +0 -77
  452. package/lib/goog/string/const.js +0 -182
  453. package/lib/goog/string/string.js +0 -1599
  454. package/lib/goog/string/typedstring.js +0 -48
  455. package/lib/goog/structs/collection.js +0 -56
  456. package/lib/goog/structs/map.js +0 -457
  457. package/lib/goog/structs/set.js +0 -279
  458. package/lib/goog/structs/structs.js +0 -354
  459. package/lib/goog/style/style.js +0 -2037
  460. package/lib/goog/testing/asserts.js +0 -1278
  461. package/lib/goog/testing/events/events.js +0 -767
  462. package/lib/goog/testing/functionmock.js +0 -175
  463. package/lib/goog/testing/jsunit.js +0 -162
  464. package/lib/goog/testing/loosemock.js +0 -242
  465. package/lib/goog/testing/mock.js +0 -645
  466. package/lib/goog/testing/mockclock.js +0 -606
  467. package/lib/goog/testing/mockcontrol.js +0 -220
  468. package/lib/goog/testing/mockinterface.js +0 -45
  469. package/lib/goog/testing/mockmatchers.js +0 -400
  470. package/lib/goog/testing/objectpropertystring.js +0 -68
  471. package/lib/goog/testing/propertyreplacer.js +0 -262
  472. package/lib/goog/testing/recordfunction.js +0 -215
  473. package/lib/goog/testing/stacktrace.js +0 -594
  474. package/lib/goog/testing/strictmock.js +0 -130
  475. package/lib/goog/testing/testcase.js +0 -1629
  476. package/lib/goog/testing/testrunner.js +0 -440
  477. package/lib/goog/uri/uri.js +0 -1524
  478. package/lib/goog/uri/utils.js +0 -1064
  479. package/lib/goog/useragent/product.js +0 -183
  480. package/lib/goog/useragent/product_isversion.js +0 -144
  481. package/lib/goog/useragent/useragent.js +0 -572
  482. package/lib/webdriver/actionsequence.js +0 -356
  483. package/lib/webdriver/builder.js +0 -207
  484. package/lib/webdriver/capabilities.js +0 -412
  485. package/lib/webdriver/events.js +0 -179
  486. package/lib/webdriver/firefoxdomexecutor.js +0 -175
  487. package/lib/webdriver/http/corsclient.js +0 -133
  488. package/lib/webdriver/http/http.js +0 -525
  489. package/lib/webdriver/http/xhrclient.js +0 -67
  490. package/lib/webdriver/locators.js +0 -257
  491. package/lib/webdriver/logging.js +0 -347
  492. package/lib/webdriver/session.js +0 -74
  493. package/lib/webdriver/stacktrace.js +0 -619
  494. package/lib/webdriver/test/builder_test.js +0 -53
  495. package/lib/webdriver/test/capabilities_test.js +0 -72
  496. package/lib/webdriver/test/events_test.js +0 -203
  497. package/lib/webdriver/test/http/corsclient_test.js +0 -151
  498. package/lib/webdriver/test/http/http_test.js +0 -428
  499. package/lib/webdriver/test/http/xhrclient_test.js +0 -196
  500. package/lib/webdriver/test/locators_test.js +0 -59
  501. package/lib/webdriver/test/logging_test.js +0 -85
  502. package/lib/webdriver/test/promise_error_test.js +0 -892
  503. package/lib/webdriver/test/promise_flow_test.js +0 -2365
  504. package/lib/webdriver/test/promise_generator_test.js +0 -323
  505. package/lib/webdriver/test/promise_test.js +0 -2012
  506. package/lib/webdriver/test/stacktrace_test.js +0 -480
  507. package/lib/webdriver/test/test_bootstrap.js +0 -67
  508. package/lib/webdriver/test/testing/asserts_test.js +0 -117
  509. package/lib/webdriver/test/testing/client_test.js +0 -88
  510. package/lib/webdriver/test/testing/testcase_test.js +0 -229
  511. package/lib/webdriver/test/testutil.js +0 -209
  512. package/lib/webdriver/test/testutil_test.js +0 -104
  513. package/lib/webdriver/test/until_test.js +0 -411
  514. package/lib/webdriver/test/webdriver_generator_test.js +0 -92
  515. package/lib/webdriver/test/webdriver_test.js +0 -2369
  516. package/lib/webdriver/testing/asserts.js +0 -487
  517. package/lib/webdriver/testing/client.js +0 -179
  518. package/lib/webdriver/testing/jsunit.js +0 -363
  519. package/lib/webdriver/testing/testcase.js +0 -168
  520. package/lib/webdriver/testing/window.js +0 -244
  521. package/lib/webdriver/touchsequence.js +0 -248
  522. package/lib/webdriver/until.js +0 -412
  523. package/lib/webdriver/webdriver.js +0 -2511
  524. package/test/_base_test.js +0 -129
@@ -1,1350 +0,0 @@
1
- // Copyright 2013 The Closure Library Authors. All Rights Reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS-IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- goog.provide('goog.Promise');
16
-
17
- goog.require('goog.Thenable');
18
- goog.require('goog.asserts');
19
- goog.require('goog.async.FreeList');
20
- goog.require('goog.async.run');
21
- goog.require('goog.async.throwException');
22
- goog.require('goog.debug.Error');
23
- goog.require('goog.promise.Resolver');
24
-
25
-
26
-
27
- /**
28
- * Promises provide a result that may be resolved asynchronously. A Promise may
29
- * be resolved by being fulfilled with a fulfillment value, rejected with a
30
- * rejection reason, or blocked by another Promise. A Promise is said to be
31
- * settled if it is either fulfilled or rejected. Once settled, the Promise
32
- * result is immutable.
33
- *
34
- * Promises may represent results of any type, including undefined. Rejection
35
- * reasons are typically Errors, but may also be of any type. Closure Promises
36
- * allow for optional type annotations that enforce that fulfillment values are
37
- * of the appropriate types at compile time.
38
- *
39
- * The result of a Promise is accessible by calling {@code then} and registering
40
- * {@code onFulfilled} and {@code onRejected} callbacks. Once the Promise
41
- * is settled, the relevant callbacks are invoked with the fulfillment value or
42
- * rejection reason as argument. Callbacks are always invoked in the order they
43
- * were registered, even when additional {@code then} calls are made from inside
44
- * another callback. A callback is always run asynchronously sometime after the
45
- * scope containing the registering {@code then} invocation has returned.
46
- *
47
- * If a Promise is resolved with another Promise, the first Promise will block
48
- * until the second is settled, and then assumes the same result as the second
49
- * Promise. This allows Promises to depend on the results of other Promises,
50
- * linking together multiple asynchronous operations.
51
- *
52
- * This implementation is compatible with the Promises/A+ specification and
53
- * passes that specification's conformance test suite. A Closure Promise may be
54
- * resolved with a Promise instance (or sufficiently compatible Promise-like
55
- * object) created by other Promise implementations. From the specification,
56
- * Promise-like objects are known as "Thenables".
57
- *
58
- * @see http://promisesaplus.com/
59
- *
60
- * @param {function(
61
- * this:RESOLVER_CONTEXT,
62
- * function((TYPE|IThenable<TYPE>|Thenable)=),
63
- * function(*=)): void} resolver
64
- * Initialization function that is invoked immediately with {@code resolve}
65
- * and {@code reject} functions as arguments. The Promise is resolved or
66
- * rejected with the first argument passed to either function.
67
- * @param {RESOLVER_CONTEXT=} opt_context An optional context for executing the
68
- * resolver function. If unspecified, the resolver function will be executed
69
- * in the default scope.
70
- * @constructor
71
- * @struct
72
- * @final
73
- * @implements {goog.Thenable<TYPE>}
74
- * @template TYPE,RESOLVER_CONTEXT
75
- */
76
- goog.Promise = function(resolver, opt_context) {
77
- /**
78
- * The internal state of this Promise. Either PENDING, FULFILLED, REJECTED, or
79
- * BLOCKED.
80
- * @private {goog.Promise.State_}
81
- */
82
- this.state_ = goog.Promise.State_.PENDING;
83
-
84
- /**
85
- * The settled result of the Promise. Immutable once set with either a
86
- * fulfillment value or rejection reason.
87
- * @private {*}
88
- */
89
- this.result_ = undefined;
90
-
91
- /**
92
- * For Promises created by calling {@code then()}, the originating parent.
93
- * @private {goog.Promise}
94
- */
95
- this.parent_ = null;
96
-
97
- /**
98
- * The linked list of {@code onFulfilled} and {@code onRejected} callbacks
99
- * added to this Promise by calls to {@code then()}.
100
- * @private {?goog.Promise.CallbackEntry_}
101
- */
102
- this.callbackEntries_ = null;
103
-
104
- /**
105
- * The tail of the linked list of {@code onFulfilled} and {@code onRejected}
106
- * callbacks added to this Promise by calls to {@code then()}.
107
- * @private {?goog.Promise.CallbackEntry_}
108
- */
109
- this.callbackEntriesTail_ = null;
110
-
111
- /**
112
- * Whether the Promise is in the queue of Promises to execute.
113
- * @private {boolean}
114
- */
115
- this.executing_ = false;
116
-
117
- if (goog.Promise.UNHANDLED_REJECTION_DELAY > 0) {
118
- /**
119
- * A timeout ID used when the {@code UNHANDLED_REJECTION_DELAY} is greater
120
- * than 0 milliseconds. The ID is set when the Promise is rejected, and
121
- * cleared only if an {@code onRejected} callback is invoked for the
122
- * Promise (or one of its descendants) before the delay is exceeded.
123
- *
124
- * If the rejection is not handled before the timeout completes, the
125
- * rejection reason is passed to the unhandled rejection handler.
126
- * @private {number}
127
- */
128
- this.unhandledRejectionId_ = 0;
129
- } else if (goog.Promise.UNHANDLED_REJECTION_DELAY == 0) {
130
- /**
131
- * When the {@code UNHANDLED_REJECTION_DELAY} is set to 0 milliseconds, a
132
- * boolean that is set if the Promise is rejected, and reset to false if an
133
- * {@code onRejected} callback is invoked for the Promise (or one of its
134
- * descendants). If the rejection is not handled before the next timestep,
135
- * the rejection reason is passed to the unhandled rejection handler.
136
- * @private {boolean}
137
- */
138
- this.hadUnhandledRejection_ = false;
139
- }
140
-
141
- if (goog.Promise.LONG_STACK_TRACES) {
142
- /**
143
- * A list of stack trace frames pointing to the locations where this Promise
144
- * was created or had callbacks added to it. Saved to add additional context
145
- * to stack traces when an exception is thrown.
146
- * @private {!Array<string>}
147
- */
148
- this.stack_ = [];
149
- this.addStackTrace_(new Error('created'));
150
-
151
- /**
152
- * Index of the most recently executed stack frame entry.
153
- * @private {number}
154
- */
155
- this.currentStep_ = 0;
156
- }
157
-
158
- // As an optimization, we can skip this if resolver is goog.nullFunction.
159
- // This value is passed internally when creating a promise which will be
160
- // resolved through a more optimized path.
161
- if (resolver != goog.nullFunction) {
162
- try {
163
- var self = this;
164
- resolver.call(
165
- opt_context,
166
- function(value) {
167
- self.resolve_(goog.Promise.State_.FULFILLED, value);
168
- },
169
- function(reason) {
170
- if (goog.DEBUG &&
171
- !(reason instanceof goog.Promise.CancellationError)) {
172
- try {
173
- // Promise was rejected. Step up one call frame to see why.
174
- if (reason instanceof Error) {
175
- throw reason;
176
- } else {
177
- throw new Error('Promise rejected.');
178
- }
179
- } catch (e) {
180
- // Only thrown so browser dev tools can catch rejections of
181
- // promises when the option to break on caught exceptions is
182
- // activated.
183
- }
184
- }
185
- self.resolve_(goog.Promise.State_.REJECTED, reason);
186
- });
187
- } catch (e) {
188
- this.resolve_(goog.Promise.State_.REJECTED, e);
189
- }
190
- }
191
- };
192
-
193
-
194
- /**
195
- * @define {boolean} Whether traces of {@code then} calls should be included in
196
- * exceptions thrown
197
- */
198
- goog.define('goog.Promise.LONG_STACK_TRACES', false);
199
-
200
-
201
- /**
202
- * @define {number} The delay in milliseconds before a rejected Promise's reason
203
- * is passed to the rejection handler. By default, the rejection handler
204
- * rethrows the rejection reason so that it appears in the developer console or
205
- * {@code window.onerror} handler.
206
- *
207
- * Rejections are rethrown as quickly as possible by default. A negative value
208
- * disables rejection handling entirely.
209
- */
210
- goog.define('goog.Promise.UNHANDLED_REJECTION_DELAY', 0);
211
-
212
-
213
- /**
214
- * The possible internal states for a Promise. These states are not directly
215
- * observable to external callers.
216
- * @enum {number}
217
- * @private
218
- */
219
- goog.Promise.State_ = {
220
- /** The Promise is waiting for resolution. */
221
- PENDING: 0,
222
-
223
- /** The Promise is blocked waiting for the result of another Thenable. */
224
- BLOCKED: 1,
225
-
226
- /** The Promise has been resolved with a fulfillment value. */
227
- FULFILLED: 2,
228
-
229
- /** The Promise has been resolved with a rejection reason. */
230
- REJECTED: 3
231
- };
232
-
233
-
234
-
235
- /**
236
- * Entries in the callback chain. Each call to {@code then},
237
- * {@code thenCatch}, or {@code thenAlways} creates an entry containing the
238
- * functions that may be invoked once the Promise is settled.
239
- *
240
- * @private @final @struct @constructor
241
- */
242
- goog.Promise.CallbackEntry_ = function() {
243
- /** @type {?goog.Promise} */
244
- this.child = null;
245
- /** @type {Function} */
246
- this.onFulfilled = null;
247
- /** @type {Function} */
248
- this.onRejected = null;
249
- /** @type {?} */
250
- this.context = null;
251
- /** @type {?goog.Promise.CallbackEntry_} */
252
- this.next = null;
253
-
254
- /**
255
- * A boolean value to indicate this is a "thenAlways" callback entry.
256
- * Unlike a normal "then/thenVoid" a "thenAlways doesn't participate
257
- * in "cancel" considerations but is simply an observer and requires
258
- * special handling.
259
- * @type {boolean}
260
- */
261
- this.always = false;
262
- };
263
-
264
-
265
- /** clear the object prior to reuse */
266
- goog.Promise.CallbackEntry_.prototype.reset = function() {
267
- this.child = null;
268
- this.onFulfilled = null;
269
- this.onRejected = null;
270
- this.context = null;
271
- this.always = false;
272
- };
273
-
274
-
275
- /**
276
- * @define {number} The number of currently unused objects to keep around for
277
- * reuse.
278
- */
279
- goog.define('goog.Promise.DEFAULT_MAX_UNUSED', 100);
280
-
281
-
282
- /** @const @private {goog.async.FreeList<!goog.Promise.CallbackEntry_>} */
283
- goog.Promise.freelist_ = new goog.async.FreeList(
284
- function() {
285
- return new goog.Promise.CallbackEntry_();
286
- },
287
- function(item) {
288
- item.reset();
289
- },
290
- goog.Promise.DEFAULT_MAX_UNUSED);
291
-
292
-
293
- /**
294
- * @param {Function} onFulfilled
295
- * @param {Function} onRejected
296
- * @param {?} context
297
- * @return {!goog.Promise.CallbackEntry_}
298
- * @private
299
- */
300
- goog.Promise.getCallbackEntry_ = function(onFulfilled, onRejected, context) {
301
- var entry = goog.Promise.freelist_.get();
302
- entry.onFulfilled = onFulfilled;
303
- entry.onRejected = onRejected;
304
- entry.context = context;
305
- return entry;
306
- };
307
-
308
-
309
- /**
310
- * @param {!goog.Promise.CallbackEntry_} entry
311
- * @private
312
- */
313
- goog.Promise.returnEntry_ = function(entry) {
314
- goog.Promise.freelist_.put(entry);
315
- };
316
-
317
-
318
- // NOTE: this is the same template expression as is used for
319
- // goog.IThenable.prototype.then
320
-
321
-
322
- /**
323
- * @param {VALUE=} opt_value
324
- * @return {RESULT} A new Promise that is immediately resolved
325
- * with the given value. If the input value is already a goog.Promise, it
326
- * will be returned immediately without creating a new instance.
327
- * @template VALUE
328
- * @template RESULT := type('goog.Promise',
329
- * cond(isUnknown(VALUE), unknown(),
330
- * mapunion(VALUE, (V) =>
331
- * cond(isTemplatized(V) && sub(rawTypeOf(V), 'IThenable'),
332
- * templateTypeOf(V, 0),
333
- * cond(sub(V, 'Thenable'),
334
- * unknown(),
335
- * V)))))
336
- * =:
337
- */
338
- goog.Promise.resolve = function(opt_value) {
339
- if (opt_value instanceof goog.Promise) {
340
- // Avoid creating a new object if we already have a promise object
341
- // of the correct type.
342
- return opt_value;
343
- }
344
-
345
- // Passing goog.nullFunction will cause the constructor to take an optimized
346
- // path that skips calling the resolver function.
347
- var promise = new goog.Promise(goog.nullFunction);
348
- promise.resolve_(goog.Promise.State_.FULFILLED, opt_value);
349
- return promise;
350
- };
351
-
352
-
353
- /**
354
- * @param {*=} opt_reason
355
- * @return {!goog.Promise} A new Promise that is immediately rejected with the
356
- * given reason.
357
- */
358
- goog.Promise.reject = function(opt_reason) {
359
- return new goog.Promise(function(resolve, reject) {
360
- reject(opt_reason);
361
- });
362
- };
363
-
364
-
365
- /**
366
- * This is identical to
367
- * {@code goog.Promise.resolve(value).then(onFulfilled, onRejected)}, but it
368
- * avoids creating an unnecessary wrapper Promise when {@code value} is already
369
- * thenable.
370
- *
371
- * @param {?(goog.Thenable<TYPE>|Thenable|TYPE)} value
372
- * @param {function(TYPE): ?} onFulfilled
373
- * @param {function(*): *} onRejected
374
- * @template TYPE
375
- * @private
376
- */
377
- goog.Promise.resolveThen_ = function(value, onFulfilled, onRejected) {
378
- var isThenable = goog.Promise.maybeThen_(
379
- value, onFulfilled, onRejected, null);
380
- if (!isThenable) {
381
- goog.async.run(goog.partial(onFulfilled, value));
382
- }
383
- };
384
-
385
-
386
- /**
387
- * @param {!Array<?(goog.Promise<TYPE>|goog.Thenable<TYPE>|Thenable|*)>}
388
- * promises
389
- * @return {!goog.Promise<TYPE>} A Promise that receives the result of the
390
- * first Promise (or Promise-like) input to settle immediately after it
391
- * settles.
392
- * @template TYPE
393
- */
394
- goog.Promise.race = function(promises) {
395
- return new goog.Promise(function(resolve, reject) {
396
- if (!promises.length) {
397
- resolve(undefined);
398
- }
399
- for (var i = 0, promise; i < promises.length; i++) {
400
- promise = promises[i];
401
- goog.Promise.resolveThen_(promise, resolve, reject);
402
- }
403
- });
404
- };
405
-
406
-
407
- /**
408
- * @param {!Array<?(goog.Promise<TYPE>|goog.Thenable<TYPE>|Thenable|*)>}
409
- * promises
410
- * @return {!goog.Promise<!Array<TYPE>>} A Promise that receives a list of
411
- * every fulfilled value once every input Promise (or Promise-like) is
412
- * successfully fulfilled, or is rejected with the first rejection reason
413
- * immediately after it is rejected.
414
- * @template TYPE
415
- */
416
- goog.Promise.all = function(promises) {
417
- return new goog.Promise(function(resolve, reject) {
418
- var toFulfill = promises.length;
419
- var values = [];
420
-
421
- if (!toFulfill) {
422
- resolve(values);
423
- return;
424
- }
425
-
426
- var onFulfill = function(index, value) {
427
- toFulfill--;
428
- values[index] = value;
429
- if (toFulfill == 0) {
430
- resolve(values);
431
- }
432
- };
433
-
434
- var onReject = function(reason) {
435
- reject(reason);
436
- };
437
-
438
- for (var i = 0, promise; i < promises.length; i++) {
439
- promise = promises[i];
440
- goog.Promise.resolveThen_(
441
- promise, goog.partial(onFulfill, i), onReject);
442
- }
443
- });
444
- };
445
-
446
-
447
- /**
448
- * @param {!Array<?(goog.Promise<TYPE>|goog.Thenable<TYPE>|Thenable|*)>}
449
- * promises
450
- * @return {!goog.Promise<!Array<{
451
- * fulfilled: boolean,
452
- * value: (TYPE|undefined),
453
- * reason: (*|undefined)}>>} A Promise that resolves with a list of
454
- * result objects once all input Promises (or Promise-like) have
455
- * settled. Each result object contains a 'fulfilled' boolean indicating
456
- * whether an input Promise was fulfilled or rejected. For fulfilled
457
- * Promises, the resulting value is stored in the 'value' field. For
458
- * rejected Promises, the rejection reason is stored in the 'reason'
459
- * field.
460
- * @template TYPE
461
- */
462
- goog.Promise.allSettled = function(promises) {
463
- return new goog.Promise(function(resolve, reject) {
464
- var toSettle = promises.length;
465
- var results = [];
466
-
467
- if (!toSettle) {
468
- resolve(results);
469
- return;
470
- }
471
-
472
- var onSettled = function(index, fulfilled, result) {
473
- toSettle--;
474
- results[index] = fulfilled ?
475
- {fulfilled: true, value: result} :
476
- {fulfilled: false, reason: result};
477
- if (toSettle == 0) {
478
- resolve(results);
479
- }
480
- };
481
-
482
- for (var i = 0, promise; i < promises.length; i++) {
483
- promise = promises[i];
484
- goog.Promise.resolveThen_(promise,
485
- goog.partial(onSettled, i, true /* fulfilled */),
486
- goog.partial(onSettled, i, false /* fulfilled */));
487
- }
488
- });
489
- };
490
-
491
-
492
- /**
493
- * @param {!Array<?(goog.Promise<TYPE>|goog.Thenable<TYPE>|Thenable|*)>}
494
- * promises
495
- * @return {!goog.Promise<TYPE>} A Promise that receives the value of the first
496
- * input to be fulfilled, or is rejected with a list of every rejection
497
- * reason if all inputs are rejected.
498
- * @template TYPE
499
- */
500
- goog.Promise.firstFulfilled = function(promises) {
501
- return new goog.Promise(function(resolve, reject) {
502
- var toReject = promises.length;
503
- var reasons = [];
504
-
505
- if (!toReject) {
506
- resolve(undefined);
507
- return;
508
- }
509
-
510
- var onFulfill = function(value) {
511
- resolve(value);
512
- };
513
-
514
- var onReject = function(index, reason) {
515
- toReject--;
516
- reasons[index] = reason;
517
- if (toReject == 0) {
518
- reject(reasons);
519
- }
520
- };
521
-
522
- for (var i = 0, promise; i < promises.length; i++) {
523
- promise = promises[i];
524
- goog.Promise.resolveThen_(
525
- promise, onFulfill, goog.partial(onReject, i));
526
- }
527
- });
528
- };
529
-
530
-
531
- /**
532
- * @return {!goog.promise.Resolver<TYPE>} Resolver wrapping the promise and its
533
- * resolve / reject functions. Resolving or rejecting the resolver
534
- * resolves or rejects the promise.
535
- * @template TYPE
536
- */
537
- goog.Promise.withResolver = function() {
538
- var resolve, reject;
539
- var promise = new goog.Promise(function(rs, rj) {
540
- resolve = rs;
541
- reject = rj;
542
- });
543
- return new goog.Promise.Resolver_(promise, resolve, reject);
544
- };
545
-
546
-
547
- /**
548
- * Adds callbacks that will operate on the result of the Promise, returning a
549
- * new child Promise.
550
- *
551
- * If the Promise is fulfilled, the {@code onFulfilled} callback will be invoked
552
- * with the fulfillment value as argument, and the child Promise will be
553
- * fulfilled with the return value of the callback. If the callback throws an
554
- * exception, the child Promise will be rejected with the thrown value instead.
555
- *
556
- * If the Promise is rejected, the {@code onRejected} callback will be invoked
557
- * with the rejection reason as argument, and the child Promise will be resolved
558
- * with the return value or rejected with the thrown value of the callback.
559
- *
560
- * @override
561
- */
562
- goog.Promise.prototype.then = function(
563
- opt_onFulfilled, opt_onRejected, opt_context) {
564
-
565
- if (opt_onFulfilled != null) {
566
- goog.asserts.assertFunction(opt_onFulfilled,
567
- 'opt_onFulfilled should be a function.');
568
- }
569
- if (opt_onRejected != null) {
570
- goog.asserts.assertFunction(opt_onRejected,
571
- 'opt_onRejected should be a function. Did you pass opt_context ' +
572
- 'as the second argument instead of the third?');
573
- }
574
-
575
- if (goog.Promise.LONG_STACK_TRACES) {
576
- this.addStackTrace_(new Error('then'));
577
- }
578
-
579
- return this.addChildPromise_(
580
- goog.isFunction(opt_onFulfilled) ? opt_onFulfilled : null,
581
- goog.isFunction(opt_onRejected) ? opt_onRejected : null,
582
- opt_context);
583
- };
584
- goog.Thenable.addImplementation(goog.Promise);
585
-
586
-
587
- /**
588
- * Adds callbacks that will operate on the result of the Promise without
589
- * returning a child Promise (unlike "then").
590
- *
591
- * If the Promise is fulfilled, the {@code onFulfilled} callback will be invoked
592
- * with the fulfillment value as argument.
593
- *
594
- * If the Promise is rejected, the {@code onRejected} callback will be invoked
595
- * with the rejection reason as argument.
596
- *
597
- * @param {?(function(this:THIS, TYPE):?)=} opt_onFulfilled A
598
- * function that will be invoked with the fulfillment value if the Promise
599
- * is fulfilled.
600
- * @param {?(function(this:THIS, *): *)=} opt_onRejected A function that will
601
- * be invoked with the rejection reason if the Promise is rejected.
602
- * @param {THIS=} opt_context An optional context object that will be the
603
- * execution context for the callbacks. By default, functions are executed
604
- * with the default this.
605
- * @package
606
- * @template THIS
607
- */
608
- goog.Promise.prototype.thenVoid = function(
609
- opt_onFulfilled, opt_onRejected, opt_context) {
610
-
611
- if (opt_onFulfilled != null) {
612
- goog.asserts.assertFunction(opt_onFulfilled,
613
- 'opt_onFulfilled should be a function.');
614
- }
615
- if (opt_onRejected != null) {
616
- goog.asserts.assertFunction(opt_onRejected,
617
- 'opt_onRejected should be a function. Did you pass opt_context ' +
618
- 'as the second argument instead of the third?');
619
- }
620
-
621
- if (goog.Promise.LONG_STACK_TRACES) {
622
- this.addStackTrace_(new Error('then'));
623
- }
624
-
625
- // Note: no default rejection handler is provided here as we need to
626
- // distinguish unhandled rejections.
627
- this.addCallbackEntry_(goog.Promise.getCallbackEntry_(
628
- opt_onFulfilled || goog.nullFunction,
629
- opt_onRejected || null,
630
- opt_context));
631
- };
632
-
633
-
634
- /**
635
- * Adds a callback that will be invoked when the Promise is settled (fulfilled
636
- * or rejected). The callback receives no argument, and no new child Promise is
637
- * created. This is useful for ensuring that cleanup takes place after certain
638
- * asynchronous operations. Callbacks added with {@code thenAlways} will be
639
- * executed in the same order with other calls to {@code then},
640
- * {@code thenAlways}, or {@code thenCatch}.
641
- *
642
- * Since it does not produce a new child Promise, cancellation propagation is
643
- * not prevented by adding callbacks with {@code thenAlways}. A Promise that has
644
- * a cleanup handler added with {@code thenAlways} will be canceled if all of
645
- * its children created by {@code then} (or {@code thenCatch}) are canceled.
646
- * Additionally, since any rejections are not passed to the callback, it does
647
- * not stop the unhandled rejection handler from running.
648
- *
649
- * @param {function(this:THIS): void} onSettled A function that will be invoked
650
- * when the Promise is settled (fulfilled or rejected).
651
- * @param {THIS=} opt_context An optional context object that will be the
652
- * execution context for the callbacks. By default, functions are executed
653
- * in the global scope.
654
- * @return {!goog.Promise<TYPE>} This Promise, for chaining additional calls.
655
- * @template THIS
656
- */
657
- goog.Promise.prototype.thenAlways = function(onSettled, opt_context) {
658
- if (goog.Promise.LONG_STACK_TRACES) {
659
- this.addStackTrace_(new Error('thenAlways'));
660
- }
661
-
662
- var entry = goog.Promise.getCallbackEntry_(onSettled, onSettled, opt_context);
663
- entry.always = true;
664
- this.addCallbackEntry_(entry);
665
- return this;
666
- };
667
-
668
-
669
- /**
670
- * Adds a callback that will be invoked only if the Promise is rejected. This
671
- * is equivalent to {@code then(null, onRejected)}.
672
- *
673
- * @param {!function(this:THIS, *): *} onRejected A function that will be
674
- * invoked with the rejection reason if the Promise is rejected.
675
- * @param {THIS=} opt_context An optional context object that will be the
676
- * execution context for the callbacks. By default, functions are executed
677
- * in the global scope.
678
- * @return {!goog.Promise} A new Promise that will receive the result of the
679
- * callback.
680
- * @template THIS
681
- */
682
- goog.Promise.prototype.thenCatch = function(onRejected, opt_context) {
683
- if (goog.Promise.LONG_STACK_TRACES) {
684
- this.addStackTrace_(new Error('thenCatch'));
685
- }
686
- return this.addChildPromise_(null, onRejected, opt_context);
687
- };
688
-
689
-
690
- /**
691
- * Cancels the Promise if it is still pending by rejecting it with a cancel
692
- * Error. No action is performed if the Promise is already resolved.
693
- *
694
- * All child Promises of the canceled Promise will be rejected with the same
695
- * cancel error, as with normal Promise rejection. If the Promise to be canceled
696
- * is the only child of a pending Promise, the parent Promise will also be
697
- * canceled. Cancellation may propagate upward through multiple generations.
698
- *
699
- * @param {string=} opt_message An optional debugging message for describing the
700
- * cancellation reason.
701
- */
702
- goog.Promise.prototype.cancel = function(opt_message) {
703
- if (this.state_ == goog.Promise.State_.PENDING) {
704
- goog.async.run(function() {
705
- var err = new goog.Promise.CancellationError(opt_message);
706
- this.cancelInternal_(err);
707
- }, this);
708
- }
709
- };
710
-
711
-
712
- /**
713
- * Cancels this Promise with the given error.
714
- *
715
- * @param {!Error} err The cancellation error.
716
- * @private
717
- */
718
- goog.Promise.prototype.cancelInternal_ = function(err) {
719
- if (this.state_ == goog.Promise.State_.PENDING) {
720
- if (this.parent_) {
721
- // Cancel the Promise and remove it from the parent's child list.
722
- this.parent_.cancelChild_(this, err);
723
- this.parent_ = null;
724
- } else {
725
- this.resolve_(goog.Promise.State_.REJECTED, err);
726
- }
727
- }
728
- };
729
-
730
-
731
- /**
732
- * Cancels a child Promise from the list of callback entries. If the Promise has
733
- * not already been resolved, reject it with a cancel error. If there are no
734
- * other children in the list of callback entries, propagate the cancellation
735
- * by canceling this Promise as well.
736
- *
737
- * @param {!goog.Promise} childPromise The Promise to cancel.
738
- * @param {!Error} err The cancel error to use for rejecting the Promise.
739
- * @private
740
- */
741
- goog.Promise.prototype.cancelChild_ = function(childPromise, err) {
742
- if (!this.callbackEntries_) {
743
- return;
744
- }
745
- var childCount = 0;
746
- var childEntry = null;
747
- var beforeChildEntry = null;
748
-
749
- // Find the callback entry for the childPromise, and count whether there are
750
- // additional child Promises.
751
- for (var entry = this.callbackEntries_; entry; entry = entry.next) {
752
- if (!entry.always) {
753
- childCount++;
754
- if (entry.child == childPromise) {
755
- childEntry = entry;
756
- }
757
- if (childEntry && childCount > 1) {
758
- break;
759
- }
760
- }
761
- if (!childEntry) {
762
- beforeChildEntry = entry;
763
- }
764
- }
765
-
766
- // Can a child entry be missing?
767
-
768
- // If the child Promise was the only child, cancel this Promise as well.
769
- // Otherwise, reject only the child Promise with the cancel error.
770
- if (childEntry) {
771
- if (this.state_ == goog.Promise.State_.PENDING && childCount == 1) {
772
- this.cancelInternal_(err);
773
- } else {
774
- if (beforeChildEntry) {
775
- this.removeEntryAfter_(beforeChildEntry);
776
- } else {
777
- this.popEntry_();
778
- }
779
-
780
- this.executeCallback_(
781
- childEntry, goog.Promise.State_.REJECTED, err);
782
- }
783
- }
784
- };
785
-
786
-
787
- /**
788
- * Adds a callback entry to the current Promise, and schedules callback
789
- * execution if the Promise has already been settled.
790
- *
791
- * @param {goog.Promise.CallbackEntry_} callbackEntry Record containing
792
- * {@code onFulfilled} and {@code onRejected} callbacks to execute after
793
- * the Promise is settled.
794
- * @private
795
- */
796
- goog.Promise.prototype.addCallbackEntry_ = function(callbackEntry) {
797
- if (!this.hasEntry_() &&
798
- (this.state_ == goog.Promise.State_.FULFILLED ||
799
- this.state_ == goog.Promise.State_.REJECTED)) {
800
- this.scheduleCallbacks_();
801
- }
802
- this.queueEntry_(callbackEntry);
803
- };
804
-
805
-
806
- /**
807
- * Creates a child Promise and adds it to the callback entry list. The result of
808
- * the child Promise is determined by the state of the parent Promise and the
809
- * result of the {@code onFulfilled} or {@code onRejected} callbacks as
810
- * specified in the Promise resolution procedure.
811
- *
812
- * @see http://promisesaplus.com/#the__method
813
- *
814
- * @param {?function(this:THIS, TYPE):
815
- * (RESULT|goog.Promise<RESULT>|Thenable)} onFulfilled A callback that
816
- * will be invoked if the Promise is fullfilled, or null.
817
- * @param {?function(this:THIS, *): *} onRejected A callback that will be
818
- * invoked if the Promise is rejected, or null.
819
- * @param {THIS=} opt_context An optional execution context for the callbacks.
820
- * in the default calling context.
821
- * @return {!goog.Promise} The child Promise.
822
- * @template RESULT,THIS
823
- * @private
824
- */
825
- goog.Promise.prototype.addChildPromise_ = function(
826
- onFulfilled, onRejected, opt_context) {
827
-
828
- /** @type {goog.Promise.CallbackEntry_} */
829
- var callbackEntry = goog.Promise.getCallbackEntry_(null, null, null);
830
-
831
- callbackEntry.child = new goog.Promise(function(resolve, reject) {
832
- // Invoke onFulfilled, or resolve with the parent's value if absent.
833
- callbackEntry.onFulfilled = onFulfilled ? function(value) {
834
- try {
835
- var result = onFulfilled.call(opt_context, value);
836
- resolve(result);
837
- } catch (err) {
838
- reject(err);
839
- }
840
- } : resolve;
841
-
842
- // Invoke onRejected, or reject with the parent's reason if absent.
843
- callbackEntry.onRejected = onRejected ? function(reason) {
844
- try {
845
- var result = onRejected.call(opt_context, reason);
846
- if (!goog.isDef(result) &&
847
- reason instanceof goog.Promise.CancellationError) {
848
- // Propagate cancellation to children if no other result is returned.
849
- reject(reason);
850
- } else {
851
- resolve(result);
852
- }
853
- } catch (err) {
854
- reject(err);
855
- }
856
- } : reject;
857
- });
858
-
859
- callbackEntry.child.parent_ = this;
860
- this.addCallbackEntry_(callbackEntry);
861
- return callbackEntry.child;
862
- };
863
-
864
-
865
- /**
866
- * Unblocks the Promise and fulfills it with the given value.
867
- *
868
- * @param {TYPE} value
869
- * @private
870
- */
871
- goog.Promise.prototype.unblockAndFulfill_ = function(value) {
872
- goog.asserts.assert(this.state_ == goog.Promise.State_.BLOCKED);
873
- this.state_ = goog.Promise.State_.PENDING;
874
- this.resolve_(goog.Promise.State_.FULFILLED, value);
875
- };
876
-
877
-
878
- /**
879
- * Unblocks the Promise and rejects it with the given rejection reason.
880
- *
881
- * @param {*} reason
882
- * @private
883
- */
884
- goog.Promise.prototype.unblockAndReject_ = function(reason) {
885
- goog.asserts.assert(this.state_ == goog.Promise.State_.BLOCKED);
886
- this.state_ = goog.Promise.State_.PENDING;
887
- this.resolve_(goog.Promise.State_.REJECTED, reason);
888
- };
889
-
890
-
891
- /**
892
- * Attempts to resolve a Promise with a given resolution state and value. This
893
- * is a no-op if the given Promise has already been resolved.
894
- *
895
- * If the given result is a Thenable (such as another Promise), the Promise will
896
- * be settled with the same state and result as the Thenable once it is itself
897
- * settled.
898
- *
899
- * If the given result is not a Thenable, the Promise will be settled (fulfilled
900
- * or rejected) with that result based on the given state.
901
- *
902
- * @see http://promisesaplus.com/#the_promise_resolution_procedure
903
- *
904
- * @param {goog.Promise.State_} state
905
- * @param {*} x The result to apply to the Promise.
906
- * @private
907
- */
908
- goog.Promise.prototype.resolve_ = function(state, x) {
909
- if (this.state_ != goog.Promise.State_.PENDING) {
910
- return;
911
- }
912
-
913
- if (this == x) {
914
- state = goog.Promise.State_.REJECTED;
915
- x = new TypeError('Promise cannot resolve to itself');
916
- }
917
-
918
- this.state_ = goog.Promise.State_.BLOCKED;
919
- var isThenable = goog.Promise.maybeThen_(
920
- x, this.unblockAndFulfill_, this.unblockAndReject_, this);
921
- if (isThenable) {
922
- return;
923
- }
924
-
925
- this.result_ = x;
926
- this.state_ = state;
927
- // Since we can no longer be canceled, remove link to parent, so that the
928
- // child promise does not keep the parent promise alive.
929
- this.parent_ = null;
930
- this.scheduleCallbacks_();
931
-
932
- if (state == goog.Promise.State_.REJECTED &&
933
- !(x instanceof goog.Promise.CancellationError)) {
934
- goog.Promise.addUnhandledRejection_(this, x);
935
- }
936
- };
937
-
938
-
939
- /**
940
- * Invokes the "then" method of an input value if that value is a Thenable. This
941
- * is a no-op if the value is not thenable.
942
- *
943
- * @param {?} value A potentially thenable value.
944
- * @param {!Function} onFulfilled
945
- * @param {!Function} onRejected
946
- * @param {?} context
947
- * @return {boolean} Whether the input value was thenable.
948
- * @private
949
- */
950
- goog.Promise.maybeThen_ = function(value, onFulfilled, onRejected, context) {
951
- if (value instanceof goog.Promise) {
952
- value.thenVoid(onFulfilled, onRejected, context);
953
- return true;
954
- } else if (goog.Thenable.isImplementedBy(value)) {
955
- value = /** @type {!goog.Thenable} */ (value);
956
- value.then(onFulfilled, onRejected, context);
957
- return true;
958
- } else if (goog.isObject(value)) {
959
- try {
960
- var then = value['then'];
961
- if (goog.isFunction(then)) {
962
- goog.Promise.tryThen_(
963
- value, then, onFulfilled, onRejected, context);
964
- return true;
965
- }
966
- } catch (e) {
967
- onRejected.call(context, e);
968
- return true;
969
- }
970
- }
971
-
972
- return false;
973
- };
974
-
975
-
976
- /**
977
- * Attempts to call the {@code then} method on an object in the hopes that it is
978
- * a Promise-compatible instance. This allows interoperation between different
979
- * Promise implementations, however a non-compliant object may cause a Promise
980
- * to hang indefinitely. If the {@code then} method throws an exception, the
981
- * dependent Promise will be rejected with the thrown value.
982
- *
983
- * @see http://promisesaplus.com/#point-70
984
- *
985
- * @param {Thenable} thenable An object with a {@code then} method that may be
986
- * compatible with the Promise/A+ specification.
987
- * @param {!Function} then The {@code then} method of the Thenable object.
988
- * @param {!Function} onFulfilled
989
- * @param {!Function} onRejected
990
- * @param {*} context
991
- * @private
992
- */
993
- goog.Promise.tryThen_ = function(
994
- thenable, then, onFulfilled, onRejected, context) {
995
-
996
- var called = false;
997
- var resolve = function(value) {
998
- if (!called) {
999
- called = true;
1000
- onFulfilled.call(context, value);
1001
- }
1002
- };
1003
-
1004
- var reject = function(reason) {
1005
- if (!called) {
1006
- called = true;
1007
- onRejected.call(context, reason);
1008
- }
1009
- };
1010
-
1011
- try {
1012
- then.call(thenable, resolve, reject);
1013
- } catch (e) {
1014
- reject(e);
1015
- }
1016
- };
1017
-
1018
-
1019
- /**
1020
- * Executes the pending callbacks of a settled Promise after a timeout.
1021
- *
1022
- * Section 2.2.4 of the Promises/A+ specification requires that Promise
1023
- * callbacks must only be invoked from a call stack that only contains Promise
1024
- * implementation code, which we accomplish by invoking callback execution after
1025
- * a timeout. If {@code startExecution_} is called multiple times for the same
1026
- * Promise, the callback chain will be evaluated only once. Additional callbacks
1027
- * may be added during the evaluation phase, and will be executed in the same
1028
- * event loop.
1029
- *
1030
- * All Promises added to the waiting list during the same browser event loop
1031
- * will be executed in one batch to avoid using a separate timeout per Promise.
1032
- *
1033
- * @private
1034
- */
1035
- goog.Promise.prototype.scheduleCallbacks_ = function() {
1036
- if (!this.executing_) {
1037
- this.executing_ = true;
1038
- goog.async.run(this.executeCallbacks_, this);
1039
- }
1040
- };
1041
-
1042
-
1043
- /**
1044
- * @return {boolean} Whether there are any pending callbacks queued.
1045
- * @private
1046
- */
1047
- goog.Promise.prototype.hasEntry_ = function() {
1048
- return !!this.callbackEntries_;
1049
- };
1050
-
1051
-
1052
- /**
1053
- * @param {goog.Promise.CallbackEntry_} entry
1054
- * @private
1055
- */
1056
- goog.Promise.prototype.queueEntry_ = function(entry) {
1057
- goog.asserts.assert(entry.onFulfilled != null);
1058
-
1059
- if (this.callbackEntriesTail_) {
1060
- this.callbackEntriesTail_.next = entry;
1061
- this.callbackEntriesTail_ = entry;
1062
- } else {
1063
- // It the work queue was empty set the head too.
1064
- this.callbackEntries_ = entry;
1065
- this.callbackEntriesTail_ = entry;
1066
- }
1067
- };
1068
-
1069
-
1070
- /**
1071
- * @return {goog.Promise.CallbackEntry_} entry
1072
- * @private
1073
- */
1074
- goog.Promise.prototype.popEntry_ = function() {
1075
- var entry = null;
1076
- if (this.callbackEntries_) {
1077
- entry = this.callbackEntries_;
1078
- this.callbackEntries_ = entry.next;
1079
- entry.next = null;
1080
- }
1081
- // It the work queue is empty clear the tail too.
1082
- if (!this.callbackEntries_) {
1083
- this.callbackEntriesTail_ = null;
1084
- }
1085
-
1086
- if (entry != null) {
1087
- goog.asserts.assert(entry.onFulfilled != null);
1088
- }
1089
- return entry;
1090
- };
1091
-
1092
-
1093
- /**
1094
- * @param {goog.Promise.CallbackEntry_} previous
1095
- * @private
1096
- */
1097
- goog.Promise.prototype.removeEntryAfter_ = function(previous) {
1098
- goog.asserts.assert(this.callbackEntries_);
1099
- goog.asserts.assert(previous != null);
1100
- // If the last entry is being removed, update the tail
1101
- if (previous.next == this.callbackEntriesTail_) {
1102
- this.callbackEntriesTail_ = previous;
1103
- }
1104
-
1105
- previous.next = previous.next.next;
1106
- };
1107
-
1108
-
1109
- /**
1110
- * Executes all pending callbacks for this Promise.
1111
- *
1112
- * @private
1113
- */
1114
- goog.Promise.prototype.executeCallbacks_ = function() {
1115
- var entry = null;
1116
- while (entry = this.popEntry_()) {
1117
- if (goog.Promise.LONG_STACK_TRACES) {
1118
- this.currentStep_++;
1119
- }
1120
- this.executeCallback_(entry, this.state_, this.result_);
1121
- }
1122
- this.executing_ = false;
1123
- };
1124
-
1125
-
1126
- /**
1127
- * Executes a pending callback for this Promise. Invokes an {@code onFulfilled}
1128
- * or {@code onRejected} callback based on the settled state of the Promise.
1129
- *
1130
- * @param {!goog.Promise.CallbackEntry_} callbackEntry An entry containing the
1131
- * onFulfilled and/or onRejected callbacks for this step.
1132
- * @param {goog.Promise.State_} state The resolution status of the Promise,
1133
- * either FULFILLED or REJECTED.
1134
- * @param {*} result The settled result of the Promise.
1135
- * @private
1136
- */
1137
- goog.Promise.prototype.executeCallback_ = function(
1138
- callbackEntry, state, result) {
1139
- // Cancel an unhandled rejection if the then/thenVoid call had an onRejected.
1140
- if (state == goog.Promise.State_.REJECTED &&
1141
- callbackEntry.onRejected && !callbackEntry.always) {
1142
- this.removeUnhandledRejection_();
1143
- }
1144
-
1145
- if (callbackEntry.child) {
1146
- // When the parent is settled, the child no longer needs to hold on to it,
1147
- // as the parent can no longer be canceled.
1148
- callbackEntry.child.parent_ = null;
1149
- goog.Promise.invokeCallback_(callbackEntry, state, result);
1150
- } else {
1151
- // Callbacks created with thenAlways or thenVoid do not have the rejection
1152
- // handling code normally set up in the child Promise.
1153
- try {
1154
- callbackEntry.always ?
1155
- callbackEntry.onFulfilled.call(callbackEntry.context) :
1156
- goog.Promise.invokeCallback_(callbackEntry, state, result);
1157
- } catch (err) {
1158
- goog.Promise.handleRejection_.call(null, err);
1159
- }
1160
- }
1161
- goog.Promise.returnEntry_(callbackEntry);
1162
- };
1163
-
1164
-
1165
- /**
1166
- * Executes the onFulfilled or onRejected callback for a callbackEntry.
1167
- *
1168
- * @param {!goog.Promise.CallbackEntry_} callbackEntry
1169
- * @param {goog.Promise.State_} state
1170
- * @param {*} result
1171
- * @private
1172
- */
1173
- goog.Promise.invokeCallback_ = function(callbackEntry, state, result) {
1174
- if (state == goog.Promise.State_.FULFILLED) {
1175
- callbackEntry.onFulfilled.call(callbackEntry.context, result);
1176
- } else if (callbackEntry.onRejected) {
1177
- callbackEntry.onRejected.call(callbackEntry.context, result);
1178
- }
1179
- };
1180
-
1181
-
1182
- /**
1183
- * Records a stack trace entry for functions that call {@code then} or the
1184
- * Promise constructor. May be disabled by unsetting {@code LONG_STACK_TRACES}.
1185
- *
1186
- * @param {!Error} err An Error object created by the calling function for
1187
- * providing a stack trace.
1188
- * @private
1189
- */
1190
- goog.Promise.prototype.addStackTrace_ = function(err) {
1191
- if (goog.Promise.LONG_STACK_TRACES && goog.isString(err.stack)) {
1192
- // Extract the third line of the stack trace, which is the entry for the
1193
- // user function that called into Promise code.
1194
- var trace = err.stack.split('\n', 4)[3];
1195
- var message = err.message;
1196
-
1197
- // Pad the message to align the traces.
1198
- message += Array(11 - message.length).join(' ');
1199
- this.stack_.push(message + trace);
1200
- }
1201
- };
1202
-
1203
-
1204
- /**
1205
- * Adds extra stack trace information to an exception for the list of
1206
- * asynchronous {@code then} calls that have been run for this Promise. Stack
1207
- * trace information is recorded in {@see #addStackTrace_}, and appended to
1208
- * rethrown errors when {@code LONG_STACK_TRACES} is enabled.
1209
- *
1210
- * @param {*} err An unhandled exception captured during callback execution.
1211
- * @private
1212
- */
1213
- goog.Promise.prototype.appendLongStack_ = function(err) {
1214
- if (goog.Promise.LONG_STACK_TRACES &&
1215
- err && goog.isString(err.stack) && this.stack_.length) {
1216
- var longTrace = ['Promise trace:'];
1217
-
1218
- for (var promise = this; promise; promise = promise.parent_) {
1219
- for (var i = this.currentStep_; i >= 0; i--) {
1220
- longTrace.push(promise.stack_[i]);
1221
- }
1222
- longTrace.push('Value: ' +
1223
- '[' + (promise.state_ == goog.Promise.State_.REJECTED ?
1224
- 'REJECTED' : 'FULFILLED') + '] ' +
1225
- '<' + String(promise.result_) + '>');
1226
- }
1227
- err.stack += '\n\n' + longTrace.join('\n');
1228
- }
1229
- };
1230
-
1231
-
1232
- /**
1233
- * Marks this rejected Promise as having being handled. Also marks any parent
1234
- * Promises in the rejected state as handled. The rejection handler will no
1235
- * longer be invoked for this Promise (if it has not been called already).
1236
- *
1237
- * @private
1238
- */
1239
- goog.Promise.prototype.removeUnhandledRejection_ = function() {
1240
- if (goog.Promise.UNHANDLED_REJECTION_DELAY > 0) {
1241
- for (var p = this; p && p.unhandledRejectionId_; p = p.parent_) {
1242
- goog.global.clearTimeout(p.unhandledRejectionId_);
1243
- p.unhandledRejectionId_ = 0;
1244
- }
1245
- } else if (goog.Promise.UNHANDLED_REJECTION_DELAY == 0) {
1246
- for (var p = this; p && p.hadUnhandledRejection_; p = p.parent_) {
1247
- p.hadUnhandledRejection_ = false;
1248
- }
1249
- }
1250
- };
1251
-
1252
-
1253
- /**
1254
- * Marks this rejected Promise as unhandled. If no {@code onRejected} callback
1255
- * is called for this Promise before the {@code UNHANDLED_REJECTION_DELAY}
1256
- * expires, the reason will be passed to the unhandled rejection handler. The
1257
- * handler typically rethrows the rejection reason so that it becomes visible in
1258
- * the developer console.
1259
- *
1260
- * @param {!goog.Promise} promise The rejected Promise.
1261
- * @param {*} reason The Promise rejection reason.
1262
- * @private
1263
- */
1264
- goog.Promise.addUnhandledRejection_ = function(promise, reason) {
1265
- if (goog.Promise.UNHANDLED_REJECTION_DELAY > 0) {
1266
- promise.unhandledRejectionId_ = goog.global.setTimeout(function() {
1267
- promise.appendLongStack_(reason);
1268
- goog.Promise.handleRejection_.call(null, reason);
1269
- }, goog.Promise.UNHANDLED_REJECTION_DELAY);
1270
-
1271
- } else if (goog.Promise.UNHANDLED_REJECTION_DELAY == 0) {
1272
- promise.hadUnhandledRejection_ = true;
1273
- goog.async.run(function() {
1274
- if (promise.hadUnhandledRejection_) {
1275
- promise.appendLongStack_(reason);
1276
- goog.Promise.handleRejection_.call(null, reason);
1277
- }
1278
- });
1279
- }
1280
- };
1281
-
1282
-
1283
- /**
1284
- * A method that is invoked with the rejection reasons for Promises that are
1285
- * rejected but have no {@code onRejected} callbacks registered yet.
1286
- * @type {function(*)}
1287
- * @private
1288
- */
1289
- goog.Promise.handleRejection_ = goog.async.throwException;
1290
-
1291
-
1292
- /**
1293
- * Sets a handler that will be called with reasons from unhandled rejected
1294
- * Promises. If the rejected Promise (or one of its descendants) has an
1295
- * {@code onRejected} callback registered, the rejection will be considered
1296
- * handled, and the rejection handler will not be called.
1297
- *
1298
- * By default, unhandled rejections are rethrown so that the error may be
1299
- * captured by the developer console or a {@code window.onerror} handler.
1300
- *
1301
- * @param {function(*)} handler A function that will be called with reasons from
1302
- * rejected Promises. Defaults to {@code goog.async.throwException}.
1303
- */
1304
- goog.Promise.setUnhandledRejectionHandler = function(handler) {
1305
- goog.Promise.handleRejection_ = handler;
1306
- };
1307
-
1308
-
1309
-
1310
- /**
1311
- * Error used as a rejection reason for canceled Promises.
1312
- *
1313
- * @param {string=} opt_message
1314
- * @constructor
1315
- * @extends {goog.debug.Error}
1316
- * @final
1317
- */
1318
- goog.Promise.CancellationError = function(opt_message) {
1319
- goog.Promise.CancellationError.base(this, 'constructor', opt_message);
1320
- };
1321
- goog.inherits(goog.Promise.CancellationError, goog.debug.Error);
1322
-
1323
-
1324
- /** @override */
1325
- goog.Promise.CancellationError.prototype.name = 'cancel';
1326
-
1327
-
1328
-
1329
- /**
1330
- * Internal implementation of the resolver interface.
1331
- *
1332
- * @param {!goog.Promise<TYPE>} promise
1333
- * @param {function((TYPE|goog.Promise<TYPE>|Thenable)=)} resolve
1334
- * @param {function(*=): void} reject
1335
- * @implements {goog.promise.Resolver<TYPE>}
1336
- * @final @struct
1337
- * @constructor
1338
- * @private
1339
- * @template TYPE
1340
- */
1341
- goog.Promise.Resolver_ = function(promise, resolve, reject) {
1342
- /** @const */
1343
- this.promise = promise;
1344
-
1345
- /** @const */
1346
- this.resolve = resolve;
1347
-
1348
- /** @const */
1349
- this.reject = reject;
1350
- };