browsed 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile.lock +2 -2
  4. data/README.md +12 -17
  5. data/bin/browse +13 -10
  6. data/lib/browsed.rb +9 -2
  7. data/lib/browsed/browser.rb +82 -0
  8. data/lib/browsed/chrome.rb +21 -12
  9. data/lib/browsed/client.rb +48 -130
  10. data/lib/browsed/constants.rb +7 -1
  11. data/lib/browsed/errors.rb +1 -0
  12. data/lib/browsed/extensions/hash.rb +27 -0
  13. data/lib/browsed/firefox.rb +18 -17
  14. data/lib/browsed/manager.rb +5 -5
  15. data/lib/browsed/{poltergeist.rb → phantomjs.rb} +2 -2
  16. data/lib/browsed/proxies.rb +26 -0
  17. data/lib/browsed/{extensions → proxies}/chrome/proxy_authentication.rb +3 -3
  18. data/lib/browsed/proxies/proxy-chain-server/node_modules/.bin/portastic +1 -0
  19. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/LICENSE +21 -0
  20. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/README.md +57 -0
  21. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/changelog.md +1 -0
  22. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +3824 -0
  23. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +31 -0
  24. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +5666 -0
  25. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
  26. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/any.js +21 -0
  27. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/assert.js +55 -0
  28. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/async.js +165 -0
  29. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bind.js +67 -0
  30. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bluebird.js +11 -0
  31. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/call_get.js +123 -0
  32. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/cancel.js +129 -0
  33. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/catch_filter.js +42 -0
  34. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/context.js +69 -0
  35. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +934 -0
  36. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/direct_resolve.js +46 -0
  37. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/each.js +30 -0
  38. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/errors.js +116 -0
  39. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/es5.js +80 -0
  40. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/filter.js +12 -0
  41. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/finally.js +146 -0
  42. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/generators.js +223 -0
  43. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/join.js +168 -0
  44. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/map.js +168 -0
  45. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/method.js +55 -0
  46. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeback.js +51 -0
  47. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeify.js +58 -0
  48. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise.js +789 -0
  49. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +185 -0
  50. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promisify.js +314 -0
  51. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/props.js +118 -0
  52. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/queue.js +73 -0
  53. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/race.js +49 -0
  54. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +172 -0
  55. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/schedule.js +62 -0
  56. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/settle.js +43 -0
  57. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/some.js +148 -0
  58. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/synchronous_inspection.js +103 -0
  59. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/thenables.js +86 -0
  60. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/timers.js +93 -0
  61. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/using.js +226 -0
  62. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/util.js +389 -0
  63. data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/package.json +102 -0
  64. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/CHANGELOG.md +408 -0
  65. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/LICENSE +22 -0
  66. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/Readme.md +428 -0
  67. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/index.js +1224 -0
  68. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/package.json +70 -0
  69. data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/typings/index.d.ts +310 -0
  70. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.coveralls.yml +1 -0
  71. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.eslintrc +11 -0
  72. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.npmignore +9 -0
  73. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.travis.yml +14 -0
  74. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/CHANGELOG.md +362 -0
  75. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/LICENSE +19 -0
  76. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/Makefile +50 -0
  77. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/README.md +312 -0
  78. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/component.json +19 -0
  79. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/karma.conf.js +70 -0
  80. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/node.js +1 -0
  81. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/package.json +88 -0
  82. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/browser.js +185 -0
  83. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/debug.js +202 -0
  84. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/index.js +10 -0
  85. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/inspector-log.js +15 -0
  86. data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/node.js +248 -0
  87. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/index.js +152 -0
  88. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/license.md +21 -0
  89. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/package.json +69 -0
  90. data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/readme.md +51 -0
  91. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/LICENSE +13 -0
  92. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/README.md +148 -0
  93. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/bin/portastic +65 -0
  94. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/history.md +7 -0
  95. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/index.js +4 -0
  96. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/monitor.js +59 -0
  97. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/portastic.js +167 -0
  98. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/LICENSE +21 -0
  99. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/README.md +677 -0
  100. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/changelog.md +1730 -0
  101. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.js +4892 -0
  102. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.min.js +31 -0
  103. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/any.js +21 -0
  104. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/assert.js +55 -0
  105. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/async.js +150 -0
  106. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bind.js +72 -0
  107. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bluebird.js +11 -0
  108. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/call_get.js +123 -0
  109. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/cancel.js +48 -0
  110. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/captured_trace.js +493 -0
  111. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/catch_filter.js +66 -0
  112. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/context.js +38 -0
  113. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/debuggability.js +162 -0
  114. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/direct_resolve.js +63 -0
  115. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/each.js +12 -0
  116. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/errors.js +111 -0
  117. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/es5.js +80 -0
  118. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/filter.js +12 -0
  119. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/finally.js +98 -0
  120. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/generators.js +136 -0
  121. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/join.js +107 -0
  122. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/map.js +133 -0
  123. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/method.js +44 -0
  124. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js +59 -0
  125. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/progress.js +76 -0
  126. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise.js +759 -0
  127. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_array.js +142 -0
  128. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_resolver.js +123 -0
  129. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promisify.js +307 -0
  130. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/props.js +79 -0
  131. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/queue.js +90 -0
  132. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/race.js +47 -0
  133. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/reduce.js +148 -0
  134. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/schedule.js +35 -0
  135. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/settle.js +40 -0
  136. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/some.js +125 -0
  137. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/synchronous_inspection.js +94 -0
  138. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/thenables.js +84 -0
  139. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/timers.js +64 -0
  140. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/using.js +213 -0
  141. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/util.js +321 -0
  142. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +103 -0
  143. data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/package.json +69 -0
  144. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +109 -0
  145. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/LICENSE +201 -0
  146. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/README.md +278 -0
  147. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +100 -0
  148. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +319 -0
  149. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_custom_response.js +96 -0
  150. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +173 -0
  151. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +132 -0
  152. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +89 -0
  153. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +271 -0
  154. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/index.js +26 -0
  155. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/run_locally.js +66 -0
  156. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/server.js +595 -0
  157. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +138 -0
  158. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/testing_tcp_service.js +37 -0
  159. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tools.js +220 -0
  160. data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/package.json +104 -0
  161. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/LICENSE +23 -0
  162. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/README.md +28 -0
  163. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/package.json +81 -0
  164. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js +5 -0
  165. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js.map +1 -0
  166. data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore.js +1692 -0
  167. data/lib/browsed/proxies/proxy-chain-server/package-lock.json +63 -0
  168. data/lib/browsed/proxies/proxy-chain-server/package.json +15 -0
  169. data/lib/browsed/proxies/proxy-chain-server/server.js +25 -0
  170. data/lib/browsed/proxies/proxy_chain.rb +36 -0
  171. data/lib/browsed/version.rb +1 -1
  172. metadata +160 -4
@@ -1,6 +1,12 @@
1
1
  module Browsed
2
2
  class Constants
3
-
3
+
4
+ BROWSERS = [
5
+ :chrome,
6
+ :firefox,
7
+ :phantomjs
8
+ ]
9
+
4
10
  RESOLUTIONS = {
5
11
  desktop: [
6
12
  [1920, 1080], #17%
@@ -1,4 +1,5 @@
1
1
  module Browsed
2
+ class InvalidBrowserError < StandardError; end
2
3
  class TooManyProcessesError < StandardError; end
3
4
  class PotentiallyStaleProxyError < StandardError; end
4
5
  end
@@ -0,0 +1,27 @@
1
+ class Hash
2
+
3
+ def symbolize_keys
4
+ transform_keys{ |key| key.to_sym rescue key }
5
+ end
6
+
7
+ def transform_keys
8
+ result = {}
9
+ each_key do |key|
10
+ result[yield(key)] = self[key]
11
+ end
12
+ result
13
+ end
14
+
15
+ def deep_symbolize_keys
16
+ deep_transform_keys{ |key| key.to_sym rescue key }
17
+ end
18
+
19
+ def deep_transform_keys(&block)
20
+ result = {}
21
+ each do |key, value|
22
+ result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value
23
+ end
24
+ result
25
+ end
26
+
27
+ end
@@ -5,7 +5,6 @@ module Browsed
5
5
  def register_firefox_driver(options: {})
6
6
  open_timeout = options.fetch(:open_timeout, 60)
7
7
  read_timeout = options.fetch(:read_timeout, 60)
8
- browser_id = options.fetch(:browser_id, nil)
9
8
  download_path = options.fetch(:download_path, self.configuration.download_path)
10
9
  private_browsing = options.fetch(:private_browsing, false)
11
10
 
@@ -28,35 +27,37 @@ module Browsed
28
27
  profile["browser.tabs.warnOnCloseOtherTabs"] = false
29
28
  profile["general.useragent.override"] = self.user_agent unless self.user_agent.to_s.empty?
30
29
 
31
- id = SecureRandom.hex[0..15]
32
30
  profile = firefox_proxy_options(profile)
33
31
  options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
34
- options.args << "--browser_id=#{id}" unless browser_id.to_s.empty?
32
+ options.args << "--browser_id=#{self.browser_id}" unless self.browser_id.to_s.empty?
35
33
  options.args << "--headless" if headless?
36
34
 
37
35
  Capybara.register_driver self.driver do |app|
38
36
  client = Selenium::WebDriver::Remote::Http::Default.new(open_timeout: open_timeout, read_timeout: read_timeout)
39
37
  Capybara::Selenium::Driver.new(app, browser: :firefox, http_client: client, options: options)
40
38
  end
41
-
42
- return id
43
39
  end
44
40
 
45
41
  def firefox_proxy_options(profile)
46
- if self.proxy && !self.proxy.empty? && self.proxy.has_key?(:host) && self.proxy.has_key?(:port)
47
- proxy_config = Selenium::WebDriver::Proxy.new(
48
- http: "#{self.proxy.fetch(:host)}:#{self.proxy.fetch(:port)}",
49
- ssl: "#{self.proxy.fetch(:host)}:#{self.proxy.fetch(:port)}",
50
- socks: "#{self.proxy.fetch(:host)}:#{self.proxy.fetch(:port)}"
51
- )
52
-
53
- proxy_config.socks_username = self.proxy.fetch(:username) unless self.proxy.fetch(:username, nil).to_s.empty?
54
- proxy_config.socks_password = self.proxy.fetch(:password) unless self.proxy.fetch(:password, nil).to_s.empty?
55
-
56
- profile.proxy = proxy_config
42
+ proxy_options = nil
57
43
 
58
- log("Will use proxy #{self.proxy.fetch(:host)}:#{self.proxy.fetch(:port)} to initiate the request.")
44
+ if valid_proxy?
45
+ if self.proxy.fetch(:mode, nil).eql?(:proxy_chain) && proxy_using_auth?
46
+ log("Starting a new proxy chain server instance.")
47
+ self.proxy_chain_server = Browsed::Proxies::ProxyChain.new(self.browser_id)
48
+
49
+ generated_proxy_url = self.proxy_chain_server.start_server(generate_proxy_auth_url)
50
+
51
+ log("Started a new proxy chain server instance at #{generated_proxy_url}.")
52
+
53
+ uri = URI.parse(generated_proxy_url)
54
+ proxy_options = generate_selenium_webdriver_proxy(host: uri.host, port: uri.port)
55
+ else
56
+ proxy_options = generate_selenium_webdriver_proxy(host: self.proxy.fetch(:host), port: self.proxy.fetch(:port))
57
+ end
59
58
  end
59
+
60
+ profile.proxy = proxy_options unless proxy_options.nil?
60
61
 
61
62
  return profile
62
63
  end
@@ -16,14 +16,14 @@ module Browsed
16
16
  self.command = "ps aux | awk '/--browser_id=#{browser_id}/'"
17
17
  else
18
18
  case browser
19
- when :phantomjs
20
- self.command = "ps -ef | grep /[p]hantomjs"
21
- when :firefox
22
- self.command = "ps -ef | grep /[f]irefox-bin"
23
19
  when :chrome
24
20
  self.command = "ps -ef | grep /[c]hromedriver"
25
- else
21
+ when :firefox
22
+ self.command = "ps -ef | grep /[f]irefox-bin"
23
+ when :phantomjs
26
24
  self.command = "ps -ef | grep /[p]hantomjs"
25
+ else
26
+ self.command = "ps -ef | grep /[c]hromedriver"
27
27
  end
28
28
  end
29
29
  end
@@ -1,8 +1,8 @@
1
1
  module Browsed
2
- module Poltergeist
2
+ module Phantomjs
3
3
 
4
4
  private
5
- def register_poltergeist_driver(options: {}, timeout: 60, debug: false)
5
+ def register_phantomjs_driver(options: {}, timeout: 60, debug: false)
6
6
  phantom_opts = ['--ignore-ssl-errors=true', '--ssl-protocol=any']
7
7
  disable_images = options.fetch(:disable_images, false)
8
8
 
@@ -0,0 +1,26 @@
1
+ module Browsed
2
+ module Proxies
3
+
4
+ def valid_proxy?(proxy = self.proxy)
5
+ (proxy && !proxy.empty? && !proxy.fetch(:host, nil).to_s.empty? && !proxy.fetch(:port, nil).to_s.empty?)
6
+ end
7
+
8
+ def proxy_using_auth?(proxy = self.proxy)
9
+ (!proxy.fetch(:username, nil).to_s.empty? && !proxy.fetch(:password, nil).to_s.empty?)
10
+ end
11
+
12
+ def generate_proxy_auth_url(proxy = self.proxy)
13
+ "http://#{proxy[:username]}:#{proxy[:password]}@#{proxy[:host]}:#{proxy[:port]}"
14
+ end
15
+
16
+ def generate_selenium_webdriver_proxy(host:, port:)
17
+ log("Will use proxy #{host}:#{port} to initiate the request.")
18
+
19
+ Selenium::WebDriver::Proxy.new(
20
+ http: "#{host}:#{port}",
21
+ ssl: "#{host}:#{port}"
22
+ )
23
+ end
24
+
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module Browser
2
- module Extensions
2
+ module Proxies
3
3
  module Chrome
4
4
  module ProxyAuthentication
5
5
 
@@ -10,10 +10,10 @@ module Browser
10
10
  FileUtils.mkdir_p plugin_path
11
11
 
12
12
  manifest_file = "#{plugin_path}/manifest.json"
13
- File.open(manifest_file, 'w') { |file| file.write(::Browser::Extensions::Chrome::ProxyAuthentication::MANIFEST_JSON_TEMPLATE) }
13
+ File.open(manifest_file, 'w') { |file| file.write(::Browser::Proxies::Chrome::ProxyAuthentication::MANIFEST_JSON_TEMPLATE) }
14
14
 
15
15
  script_file = "#{plugin_path}/background.js"
16
- script_result = Browser::Extensions::Chrome::ProxyAuthentication::BACKGROUND_SCRIPT_TEMPLATE % [proxy[:host], proxy[:port], proxy[:username], proxy[:password]]
16
+ script_result = Browser::Proxies::Chrome::ProxyAuthentication::BACKGROUND_SCRIPT_TEMPLATE % [proxy[:host], proxy[:port], proxy[:username], proxy[:password]]
17
17
  File.open(script_file, 'w') { |file| file.write(script_result) }
18
18
 
19
19
  return plugin_path
@@ -0,0 +1 @@
1
+ ../portastic/bin/portastic
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013-2018 Petka Antonov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ <a href="http://promisesaplus.com/">
2
+ <img src="http://promisesaplus.com/assets/logo-small.png" alt="Promises/A+ logo"
3
+ title="Promises/A+ 1.1 compliant" align="right" />
4
+ </a>
5
+
6
+
7
+ [![Build Status](https://travis-ci.org/petkaantonov/bluebird.svg?branch=master)](https://travis-ci.org/petkaantonov/bluebird)
8
+ [![coverage-98%](https://img.shields.io/badge/coverage-98%25-brightgreen.svg?style=flat)](http://petkaantonov.github.io/bluebird/coverage/debug/index.html)
9
+
10
+ **Got a question?** Join us on [stackoverflow](http://stackoverflow.com/questions/tagged/bluebird), the [mailing list](https://groups.google.com/forum/#!forum/bluebird-js) or chat on [IRC](https://webchat.freenode.net/?channels=#promises)
11
+
12
+ # Introduction
13
+
14
+ Bluebird is a fully featured promise library with focus on innovative features and performance
15
+
16
+ See the [**bluebird website**](http://bluebirdjs.com/docs/getting-started.html) for further documentation, references and instructions. See the [**API reference**](http://bluebirdjs.com/docs/api-reference.html) here.
17
+
18
+ For bluebird 2.x documentation and files, see the [2.x tree](https://github.com/petkaantonov/bluebird/tree/2.x).
19
+
20
+ ### Note
21
+
22
+ Promises in Node.js 10 are significantly faster than before. Bluebird still includes a lot of features like cancellation, iteration methods and warnings that native promises don't. If you are using Bluebird for performance rather than for those - please consider giving native promises a shot and running the benchmarks yourself.
23
+
24
+ # Questions and issues
25
+
26
+ The [github issue tracker](https://github.com/petkaantonov/bluebird/issues) is **_only_** for bug reports and feature requests. Anything else, such as questions for help in using the library, should be posted in [StackOverflow](http://stackoverflow.com/questions/tagged/bluebird) under tags `promise` and `bluebird`.
27
+
28
+
29
+
30
+ ## Thanks
31
+
32
+ Thanks to BrowserStack for providing us with a free account which lets us support old browsers like IE8.
33
+
34
+ # License
35
+
36
+ The MIT License (MIT)
37
+
38
+ Copyright (c) 2013-2017 Petka Antonov
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining a copy
41
+ of this software and associated documentation files (the "Software"), to deal
42
+ in the Software without restriction, including without limitation the rights
43
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
44
+ copies of the Software, and to permit persons to whom the Software is
45
+ furnished to do so, subject to the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be included in
48
+ all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
53
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
56
+ THE SOFTWARE.
57
+
@@ -0,0 +1 @@
1
+ [http://bluebirdjs.com/docs/changelog.html](http://bluebirdjs.com/docs/changelog.html)
@@ -0,0 +1,3824 @@
1
+ /* @preserve
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2013-2018 Petka Antonov
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ *
24
+ */
25
+ /**
26
+ * bluebird build version 3.5.5
27
+ * Features enabled: core
28
+ * Features disabled: race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each
29
+ */
30
+ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Promise=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof _dereq_=="function"&&_dereq_;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof _dereq_=="function"&&_dereq_;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
31
+ "use strict";
32
+ var firstLineError;
33
+ try {throw new Error(); } catch (e) {firstLineError = e;}
34
+ var schedule = _dereq_("./schedule");
35
+ var Queue = _dereq_("./queue");
36
+ var util = _dereq_("./util");
37
+
38
+ function Async() {
39
+ this._customScheduler = false;
40
+ this._isTickUsed = false;
41
+ this._lateQueue = new Queue(16);
42
+ this._normalQueue = new Queue(16);
43
+ this._haveDrainedQueues = false;
44
+ this._trampolineEnabled = true;
45
+ var self = this;
46
+ this.drainQueues = function () {
47
+ self._drainQueues();
48
+ };
49
+ this._schedule = schedule;
50
+ }
51
+
52
+ Async.prototype.setScheduler = function(fn) {
53
+ var prev = this._schedule;
54
+ this._schedule = fn;
55
+ this._customScheduler = true;
56
+ return prev;
57
+ };
58
+
59
+ Async.prototype.hasCustomScheduler = function() {
60
+ return this._customScheduler;
61
+ };
62
+
63
+ Async.prototype.enableTrampoline = function() {
64
+ this._trampolineEnabled = true;
65
+ };
66
+
67
+ Async.prototype.disableTrampolineIfNecessary = function() {
68
+ if (util.hasDevTools) {
69
+ this._trampolineEnabled = false;
70
+ }
71
+ };
72
+
73
+ Async.prototype.haveItemsQueued = function () {
74
+ return this._isTickUsed || this._haveDrainedQueues;
75
+ };
76
+
77
+
78
+ Async.prototype.fatalError = function(e, isNode) {
79
+ if (isNode) {
80
+ process.stderr.write("Fatal " + (e instanceof Error ? e.stack : e) +
81
+ "\n");
82
+ process.exit(2);
83
+ } else {
84
+ this.throwLater(e);
85
+ }
86
+ };
87
+
88
+ Async.prototype.throwLater = function(fn, arg) {
89
+ if (arguments.length === 1) {
90
+ arg = fn;
91
+ fn = function () { throw arg; };
92
+ }
93
+ if (typeof setTimeout !== "undefined") {
94
+ setTimeout(function() {
95
+ fn(arg);
96
+ }, 0);
97
+ } else try {
98
+ this._schedule(function() {
99
+ fn(arg);
100
+ });
101
+ } catch (e) {
102
+ throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
103
+ }
104
+ };
105
+
106
+ function AsyncInvokeLater(fn, receiver, arg) {
107
+ this._lateQueue.push(fn, receiver, arg);
108
+ this._queueTick();
109
+ }
110
+
111
+ function AsyncInvoke(fn, receiver, arg) {
112
+ this._normalQueue.push(fn, receiver, arg);
113
+ this._queueTick();
114
+ }
115
+
116
+ function AsyncSettlePromises(promise) {
117
+ this._normalQueue._pushOne(promise);
118
+ this._queueTick();
119
+ }
120
+
121
+ if (!util.hasDevTools) {
122
+ Async.prototype.invokeLater = AsyncInvokeLater;
123
+ Async.prototype.invoke = AsyncInvoke;
124
+ Async.prototype.settlePromises = AsyncSettlePromises;
125
+ } else {
126
+ Async.prototype.invokeLater = function (fn, receiver, arg) {
127
+ if (this._trampolineEnabled) {
128
+ AsyncInvokeLater.call(this, fn, receiver, arg);
129
+ } else {
130
+ this._schedule(function() {
131
+ setTimeout(function() {
132
+ fn.call(receiver, arg);
133
+ }, 100);
134
+ });
135
+ }
136
+ };
137
+
138
+ Async.prototype.invoke = function (fn, receiver, arg) {
139
+ if (this._trampolineEnabled) {
140
+ AsyncInvoke.call(this, fn, receiver, arg);
141
+ } else {
142
+ this._schedule(function() {
143
+ fn.call(receiver, arg);
144
+ });
145
+ }
146
+ };
147
+
148
+ Async.prototype.settlePromises = function(promise) {
149
+ if (this._trampolineEnabled) {
150
+ AsyncSettlePromises.call(this, promise);
151
+ } else {
152
+ this._schedule(function() {
153
+ promise._settlePromises();
154
+ });
155
+ }
156
+ };
157
+ }
158
+
159
+ function _drainQueue(queue) {
160
+ while (queue.length() > 0) {
161
+ _drainQueueStep(queue);
162
+ }
163
+ }
164
+
165
+ function _drainQueueStep(queue) {
166
+ var fn = queue.shift();
167
+ if (typeof fn !== "function") {
168
+ fn._settlePromises();
169
+ } else {
170
+ var receiver = queue.shift();
171
+ var arg = queue.shift();
172
+ fn.call(receiver, arg);
173
+ }
174
+ }
175
+
176
+ Async.prototype._drainQueues = function () {
177
+ _drainQueue(this._normalQueue);
178
+ this._reset();
179
+ this._haveDrainedQueues = true;
180
+ _drainQueue(this._lateQueue);
181
+ };
182
+
183
+ Async.prototype._queueTick = function () {
184
+ if (!this._isTickUsed) {
185
+ this._isTickUsed = true;
186
+ this._schedule(this.drainQueues);
187
+ }
188
+ };
189
+
190
+ Async.prototype._reset = function () {
191
+ this._isTickUsed = false;
192
+ };
193
+
194
+ module.exports = Async;
195
+ module.exports.firstLineError = firstLineError;
196
+
197
+ },{"./queue":17,"./schedule":18,"./util":21}],2:[function(_dereq_,module,exports){
198
+ "use strict";
199
+ module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
200
+ var calledBind = false;
201
+ var rejectThis = function(_, e) {
202
+ this._reject(e);
203
+ };
204
+
205
+ var targetRejected = function(e, context) {
206
+ context.promiseRejectionQueued = true;
207
+ context.bindingPromise._then(rejectThis, rejectThis, null, this, e);
208
+ };
209
+
210
+ var bindingResolved = function(thisArg, context) {
211
+ if (((this._bitField & 50397184) === 0)) {
212
+ this._resolveCallback(context.target);
213
+ }
214
+ };
215
+
216
+ var bindingRejected = function(e, context) {
217
+ if (!context.promiseRejectionQueued) this._reject(e);
218
+ };
219
+
220
+ Promise.prototype.bind = function (thisArg) {
221
+ if (!calledBind) {
222
+ calledBind = true;
223
+ Promise.prototype._propagateFrom = debug.propagateFromFunction();
224
+ Promise.prototype._boundValue = debug.boundValueFunction();
225
+ }
226
+ var maybePromise = tryConvertToPromise(thisArg);
227
+ var ret = new Promise(INTERNAL);
228
+ ret._propagateFrom(this, 1);
229
+ var target = this._target();
230
+ ret._setBoundTo(maybePromise);
231
+ if (maybePromise instanceof Promise) {
232
+ var context = {
233
+ promiseRejectionQueued: false,
234
+ promise: ret,
235
+ target: target,
236
+ bindingPromise: maybePromise
237
+ };
238
+ target._then(INTERNAL, targetRejected, undefined, ret, context);
239
+ maybePromise._then(
240
+ bindingResolved, bindingRejected, undefined, ret, context);
241
+ ret._setOnCancel(maybePromise);
242
+ } else {
243
+ ret._resolveCallback(target);
244
+ }
245
+ return ret;
246
+ };
247
+
248
+ Promise.prototype._setBoundTo = function (obj) {
249
+ if (obj !== undefined) {
250
+ this._bitField = this._bitField | 2097152;
251
+ this._boundTo = obj;
252
+ } else {
253
+ this._bitField = this._bitField & (~2097152);
254
+ }
255
+ };
256
+
257
+ Promise.prototype._isBound = function () {
258
+ return (this._bitField & 2097152) === 2097152;
259
+ };
260
+
261
+ Promise.bind = function (thisArg, value) {
262
+ return Promise.resolve(value).bind(thisArg);
263
+ };
264
+ };
265
+
266
+ },{}],3:[function(_dereq_,module,exports){
267
+ "use strict";
268
+ var old;
269
+ if (typeof Promise !== "undefined") old = Promise;
270
+ function noConflict() {
271
+ try { if (Promise === bluebird) Promise = old; }
272
+ catch (e) {}
273
+ return bluebird;
274
+ }
275
+ var bluebird = _dereq_("./promise")();
276
+ bluebird.noConflict = noConflict;
277
+ module.exports = bluebird;
278
+
279
+ },{"./promise":15}],4:[function(_dereq_,module,exports){
280
+ "use strict";
281
+ module.exports = function(Promise, PromiseArray, apiRejection, debug) {
282
+ var util = _dereq_("./util");
283
+ var tryCatch = util.tryCatch;
284
+ var errorObj = util.errorObj;
285
+ var async = Promise._async;
286
+
287
+ Promise.prototype["break"] = Promise.prototype.cancel = function() {
288
+ if (!debug.cancellation()) return this._warn("cancellation is disabled");
289
+
290
+ var promise = this;
291
+ var child = promise;
292
+ while (promise._isCancellable()) {
293
+ if (!promise._cancelBy(child)) {
294
+ if (child._isFollowing()) {
295
+ child._followee().cancel();
296
+ } else {
297
+ child._cancelBranched();
298
+ }
299
+ break;
300
+ }
301
+
302
+ var parent = promise._cancellationParent;
303
+ if (parent == null || !parent._isCancellable()) {
304
+ if (promise._isFollowing()) {
305
+ promise._followee().cancel();
306
+ } else {
307
+ promise._cancelBranched();
308
+ }
309
+ break;
310
+ } else {
311
+ if (promise._isFollowing()) promise._followee().cancel();
312
+ promise._setWillBeCancelled();
313
+ child = promise;
314
+ promise = parent;
315
+ }
316
+ }
317
+ };
318
+
319
+ Promise.prototype._branchHasCancelled = function() {
320
+ this._branchesRemainingToCancel--;
321
+ };
322
+
323
+ Promise.prototype._enoughBranchesHaveCancelled = function() {
324
+ return this._branchesRemainingToCancel === undefined ||
325
+ this._branchesRemainingToCancel <= 0;
326
+ };
327
+
328
+ Promise.prototype._cancelBy = function(canceller) {
329
+ if (canceller === this) {
330
+ this._branchesRemainingToCancel = 0;
331
+ this._invokeOnCancel();
332
+ return true;
333
+ } else {
334
+ this._branchHasCancelled();
335
+ if (this._enoughBranchesHaveCancelled()) {
336
+ this._invokeOnCancel();
337
+ return true;
338
+ }
339
+ }
340
+ return false;
341
+ };
342
+
343
+ Promise.prototype._cancelBranched = function() {
344
+ if (this._enoughBranchesHaveCancelled()) {
345
+ this._cancel();
346
+ }
347
+ };
348
+
349
+ Promise.prototype._cancel = function() {
350
+ if (!this._isCancellable()) return;
351
+ this._setCancelled();
352
+ async.invoke(this._cancelPromises, this, undefined);
353
+ };
354
+
355
+ Promise.prototype._cancelPromises = function() {
356
+ if (this._length() > 0) this._settlePromises();
357
+ };
358
+
359
+ Promise.prototype._unsetOnCancel = function() {
360
+ this._onCancelField = undefined;
361
+ };
362
+
363
+ Promise.prototype._isCancellable = function() {
364
+ return this.isPending() && !this._isCancelled();
365
+ };
366
+
367
+ Promise.prototype.isCancellable = function() {
368
+ return this.isPending() && !this.isCancelled();
369
+ };
370
+
371
+ Promise.prototype._doInvokeOnCancel = function(onCancelCallback, internalOnly) {
372
+ if (util.isArray(onCancelCallback)) {
373
+ for (var i = 0; i < onCancelCallback.length; ++i) {
374
+ this._doInvokeOnCancel(onCancelCallback[i], internalOnly);
375
+ }
376
+ } else if (onCancelCallback !== undefined) {
377
+ if (typeof onCancelCallback === "function") {
378
+ if (!internalOnly) {
379
+ var e = tryCatch(onCancelCallback).call(this._boundValue());
380
+ if (e === errorObj) {
381
+ this._attachExtraTrace(e.e);
382
+ async.throwLater(e.e);
383
+ }
384
+ }
385
+ } else {
386
+ onCancelCallback._resultCancelled(this);
387
+ }
388
+ }
389
+ };
390
+
391
+ Promise.prototype._invokeOnCancel = function() {
392
+ var onCancelCallback = this._onCancel();
393
+ this._unsetOnCancel();
394
+ async.invoke(this._doInvokeOnCancel, this, onCancelCallback);
395
+ };
396
+
397
+ Promise.prototype._invokeInternalOnCancel = function() {
398
+ if (this._isCancellable()) {
399
+ this._doInvokeOnCancel(this._onCancel(), true);
400
+ this._unsetOnCancel();
401
+ }
402
+ };
403
+
404
+ Promise.prototype._resultCancelled = function() {
405
+ this.cancel();
406
+ };
407
+
408
+ };
409
+
410
+ },{"./util":21}],5:[function(_dereq_,module,exports){
411
+ "use strict";
412
+ module.exports = function(NEXT_FILTER) {
413
+ var util = _dereq_("./util");
414
+ var getKeys = _dereq_("./es5").keys;
415
+ var tryCatch = util.tryCatch;
416
+ var errorObj = util.errorObj;
417
+
418
+ function catchFilter(instances, cb, promise) {
419
+ return function(e) {
420
+ var boundTo = promise._boundValue();
421
+ predicateLoop: for (var i = 0; i < instances.length; ++i) {
422
+ var item = instances[i];
423
+
424
+ if (item === Error ||
425
+ (item != null && item.prototype instanceof Error)) {
426
+ if (e instanceof item) {
427
+ return tryCatch(cb).call(boundTo, e);
428
+ }
429
+ } else if (typeof item === "function") {
430
+ var matchesPredicate = tryCatch(item).call(boundTo, e);
431
+ if (matchesPredicate === errorObj) {
432
+ return matchesPredicate;
433
+ } else if (matchesPredicate) {
434
+ return tryCatch(cb).call(boundTo, e);
435
+ }
436
+ } else if (util.isObject(e)) {
437
+ var keys = getKeys(item);
438
+ for (var j = 0; j < keys.length; ++j) {
439
+ var key = keys[j];
440
+ if (item[key] != e[key]) {
441
+ continue predicateLoop;
442
+ }
443
+ }
444
+ return tryCatch(cb).call(boundTo, e);
445
+ }
446
+ }
447
+ return NEXT_FILTER;
448
+ };
449
+ }
450
+
451
+ return catchFilter;
452
+ };
453
+
454
+ },{"./es5":10,"./util":21}],6:[function(_dereq_,module,exports){
455
+ "use strict";
456
+ module.exports = function(Promise) {
457
+ var longStackTraces = false;
458
+ var contextStack = [];
459
+
460
+ Promise.prototype._promiseCreated = function() {};
461
+ Promise.prototype._pushContext = function() {};
462
+ Promise.prototype._popContext = function() {return null;};
463
+ Promise._peekContext = Promise.prototype._peekContext = function() {};
464
+
465
+ function Context() {
466
+ this._trace = new Context.CapturedTrace(peekContext());
467
+ }
468
+ Context.prototype._pushContext = function () {
469
+ if (this._trace !== undefined) {
470
+ this._trace._promiseCreated = null;
471
+ contextStack.push(this._trace);
472
+ }
473
+ };
474
+
475
+ Context.prototype._popContext = function () {
476
+ if (this._trace !== undefined) {
477
+ var trace = contextStack.pop();
478
+ var ret = trace._promiseCreated;
479
+ trace._promiseCreated = null;
480
+ return ret;
481
+ }
482
+ return null;
483
+ };
484
+
485
+ function createContext() {
486
+ if (longStackTraces) return new Context();
487
+ }
488
+
489
+ function peekContext() {
490
+ var lastIndex = contextStack.length - 1;
491
+ if (lastIndex >= 0) {
492
+ return contextStack[lastIndex];
493
+ }
494
+ return undefined;
495
+ }
496
+ Context.CapturedTrace = null;
497
+ Context.create = createContext;
498
+ Context.deactivateLongStackTraces = function() {};
499
+ Context.activateLongStackTraces = function() {
500
+ var Promise_pushContext = Promise.prototype._pushContext;
501
+ var Promise_popContext = Promise.prototype._popContext;
502
+ var Promise_PeekContext = Promise._peekContext;
503
+ var Promise_peekContext = Promise.prototype._peekContext;
504
+ var Promise_promiseCreated = Promise.prototype._promiseCreated;
505
+ Context.deactivateLongStackTraces = function() {
506
+ Promise.prototype._pushContext = Promise_pushContext;
507
+ Promise.prototype._popContext = Promise_popContext;
508
+ Promise._peekContext = Promise_PeekContext;
509
+ Promise.prototype._peekContext = Promise_peekContext;
510
+ Promise.prototype._promiseCreated = Promise_promiseCreated;
511
+ longStackTraces = false;
512
+ };
513
+ longStackTraces = true;
514
+ Promise.prototype._pushContext = Context.prototype._pushContext;
515
+ Promise.prototype._popContext = Context.prototype._popContext;
516
+ Promise._peekContext = Promise.prototype._peekContext = peekContext;
517
+ Promise.prototype._promiseCreated = function() {
518
+ var ctx = this._peekContext();
519
+ if (ctx && ctx._promiseCreated == null) ctx._promiseCreated = this;
520
+ };
521
+ };
522
+ return Context;
523
+ };
524
+
525
+ },{}],7:[function(_dereq_,module,exports){
526
+ "use strict";
527
+ module.exports = function(Promise, Context) {
528
+ var getDomain = Promise._getDomain;
529
+ var async = Promise._async;
530
+ var Warning = _dereq_("./errors").Warning;
531
+ var util = _dereq_("./util");
532
+ var es5 = _dereq_("./es5");
533
+ var canAttachTrace = util.canAttachTrace;
534
+ var unhandledRejectionHandled;
535
+ var possiblyUnhandledRejection;
536
+ var bluebirdFramePattern =
537
+ /[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/;
538
+ var nodeFramePattern = /\((?:timers\.js):\d+:\d+\)/;
539
+ var parseLinePattern = /[\/<\(](.+?):(\d+):(\d+)\)?\s*$/;
540
+ var stackFramePattern = null;
541
+ var formatStack = null;
542
+ var indentStackFrames = false;
543
+ var printWarning;
544
+ var debugging = !!(util.env("BLUEBIRD_DEBUG") != 0 &&
545
+ (true ||
546
+ util.env("BLUEBIRD_DEBUG") ||
547
+ util.env("NODE_ENV") === "development"));
548
+
549
+ var warnings = !!(util.env("BLUEBIRD_WARNINGS") != 0 &&
550
+ (debugging || util.env("BLUEBIRD_WARNINGS")));
551
+
552
+ var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 &&
553
+ (debugging || util.env("BLUEBIRD_LONG_STACK_TRACES")));
554
+
555
+ var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 &&
556
+ (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN"));
557
+
558
+ Promise.prototype.suppressUnhandledRejections = function() {
559
+ var target = this._target();
560
+ target._bitField = ((target._bitField & (~1048576)) |
561
+ 524288);
562
+ };
563
+
564
+ Promise.prototype._ensurePossibleRejectionHandled = function () {
565
+ if ((this._bitField & 524288) !== 0) return;
566
+ this._setRejectionIsUnhandled();
567
+ var self = this;
568
+ setTimeout(function() {
569
+ self._notifyUnhandledRejection();
570
+ }, 1);
571
+ };
572
+
573
+ Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
574
+ fireRejectionEvent("rejectionHandled",
575
+ unhandledRejectionHandled, undefined, this);
576
+ };
577
+
578
+ Promise.prototype._setReturnedNonUndefined = function() {
579
+ this._bitField = this._bitField | 268435456;
580
+ };
581
+
582
+ Promise.prototype._returnedNonUndefined = function() {
583
+ return (this._bitField & 268435456) !== 0;
584
+ };
585
+
586
+ Promise.prototype._notifyUnhandledRejection = function () {
587
+ if (this._isRejectionUnhandled()) {
588
+ var reason = this._settledValue();
589
+ this._setUnhandledRejectionIsNotified();
590
+ fireRejectionEvent("unhandledRejection",
591
+ possiblyUnhandledRejection, reason, this);
592
+ }
593
+ };
594
+
595
+ Promise.prototype._setUnhandledRejectionIsNotified = function () {
596
+ this._bitField = this._bitField | 262144;
597
+ };
598
+
599
+ Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
600
+ this._bitField = this._bitField & (~262144);
601
+ };
602
+
603
+ Promise.prototype._isUnhandledRejectionNotified = function () {
604
+ return (this._bitField & 262144) > 0;
605
+ };
606
+
607
+ Promise.prototype._setRejectionIsUnhandled = function () {
608
+ this._bitField = this._bitField | 1048576;
609
+ };
610
+
611
+ Promise.prototype._unsetRejectionIsUnhandled = function () {
612
+ this._bitField = this._bitField & (~1048576);
613
+ if (this._isUnhandledRejectionNotified()) {
614
+ this._unsetUnhandledRejectionIsNotified();
615
+ this._notifyUnhandledRejectionIsHandled();
616
+ }
617
+ };
618
+
619
+ Promise.prototype._isRejectionUnhandled = function () {
620
+ return (this._bitField & 1048576) > 0;
621
+ };
622
+
623
+ Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) {
624
+ return warn(message, shouldUseOwnTrace, promise || this);
625
+ };
626
+
627
+ Promise.onPossiblyUnhandledRejection = function (fn) {
628
+ var domain = getDomain();
629
+ possiblyUnhandledRejection =
630
+ typeof fn === "function" ? (domain === null ?
631
+ fn : util.domainBind(domain, fn))
632
+ : undefined;
633
+ };
634
+
635
+ Promise.onUnhandledRejectionHandled = function (fn) {
636
+ var domain = getDomain();
637
+ unhandledRejectionHandled =
638
+ typeof fn === "function" ? (domain === null ?
639
+ fn : util.domainBind(domain, fn))
640
+ : undefined;
641
+ };
642
+
643
+ var disableLongStackTraces = function() {};
644
+ Promise.longStackTraces = function () {
645
+ if (async.haveItemsQueued() && !config.longStackTraces) {
646
+ throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
647
+ }
648
+ if (!config.longStackTraces && longStackTracesIsSupported()) {
649
+ var Promise_captureStackTrace = Promise.prototype._captureStackTrace;
650
+ var Promise_attachExtraTrace = Promise.prototype._attachExtraTrace;
651
+ var Promise_dereferenceTrace = Promise.prototype._dereferenceTrace;
652
+ config.longStackTraces = true;
653
+ disableLongStackTraces = function() {
654
+ if (async.haveItemsQueued() && !config.longStackTraces) {
655
+ throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/MqrFmX\u000a");
656
+ }
657
+ Promise.prototype._captureStackTrace = Promise_captureStackTrace;
658
+ Promise.prototype._attachExtraTrace = Promise_attachExtraTrace;
659
+ Promise.prototype._dereferenceTrace = Promise_dereferenceTrace;
660
+ Context.deactivateLongStackTraces();
661
+ async.enableTrampoline();
662
+ config.longStackTraces = false;
663
+ };
664
+ Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;
665
+ Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;
666
+ Promise.prototype._dereferenceTrace = longStackTracesDereferenceTrace;
667
+ Context.activateLongStackTraces();
668
+ async.disableTrampolineIfNecessary();
669
+ }
670
+ };
671
+
672
+ Promise.hasLongStackTraces = function () {
673
+ return config.longStackTraces && longStackTracesIsSupported();
674
+ };
675
+
676
+ var fireDomEvent = (function() {
677
+ try {
678
+ if (typeof CustomEvent === "function") {
679
+ var event = new CustomEvent("CustomEvent");
680
+ util.global.dispatchEvent(event);
681
+ return function(name, event) {
682
+ var eventData = {
683
+ detail: event,
684
+ cancelable: true
685
+ };
686
+ es5.defineProperty(
687
+ eventData, "promise", {value: event.promise});
688
+ es5.defineProperty(eventData, "reason", {value: event.reason});
689
+ var domEvent = new CustomEvent(name.toLowerCase(), eventData);
690
+ return !util.global.dispatchEvent(domEvent);
691
+ };
692
+ } else if (typeof Event === "function") {
693
+ var event = new Event("CustomEvent");
694
+ util.global.dispatchEvent(event);
695
+ return function(name, event) {
696
+ var domEvent = new Event(name.toLowerCase(), {
697
+ cancelable: true
698
+ });
699
+ domEvent.detail = event;
700
+ es5.defineProperty(domEvent, "promise", {value: event.promise});
701
+ es5.defineProperty(domEvent, "reason", {value: event.reason});
702
+ return !util.global.dispatchEvent(domEvent);
703
+ };
704
+ } else {
705
+ var event = document.createEvent("CustomEvent");
706
+ event.initCustomEvent("testingtheevent", false, true, {});
707
+ util.global.dispatchEvent(event);
708
+ return function(name, event) {
709
+ var domEvent = document.createEvent("CustomEvent");
710
+ domEvent.initCustomEvent(name.toLowerCase(), false, true,
711
+ event);
712
+ return !util.global.dispatchEvent(domEvent);
713
+ };
714
+ }
715
+ } catch (e) {}
716
+ return function() {
717
+ return false;
718
+ };
719
+ })();
720
+
721
+ var fireGlobalEvent = (function() {
722
+ if (util.isNode) {
723
+ return function() {
724
+ return process.emit.apply(process, arguments);
725
+ };
726
+ } else {
727
+ if (!util.global) {
728
+ return function() {
729
+ return false;
730
+ };
731
+ }
732
+ return function(name) {
733
+ var methodName = "on" + name.toLowerCase();
734
+ var method = util.global[methodName];
735
+ if (!method) return false;
736
+ method.apply(util.global, [].slice.call(arguments, 1));
737
+ return true;
738
+ };
739
+ }
740
+ })();
741
+
742
+ function generatePromiseLifecycleEventObject(name, promise) {
743
+ return {promise: promise};
744
+ }
745
+
746
+ var eventToObjectGenerator = {
747
+ promiseCreated: generatePromiseLifecycleEventObject,
748
+ promiseFulfilled: generatePromiseLifecycleEventObject,
749
+ promiseRejected: generatePromiseLifecycleEventObject,
750
+ promiseResolved: generatePromiseLifecycleEventObject,
751
+ promiseCancelled: generatePromiseLifecycleEventObject,
752
+ promiseChained: function(name, promise, child) {
753
+ return {promise: promise, child: child};
754
+ },
755
+ warning: function(name, warning) {
756
+ return {warning: warning};
757
+ },
758
+ unhandledRejection: function (name, reason, promise) {
759
+ return {reason: reason, promise: promise};
760
+ },
761
+ rejectionHandled: generatePromiseLifecycleEventObject
762
+ };
763
+
764
+ var activeFireEvent = function (name) {
765
+ var globalEventFired = false;
766
+ try {
767
+ globalEventFired = fireGlobalEvent.apply(null, arguments);
768
+ } catch (e) {
769
+ async.throwLater(e);
770
+ globalEventFired = true;
771
+ }
772
+
773
+ var domEventFired = false;
774
+ try {
775
+ domEventFired = fireDomEvent(name,
776
+ eventToObjectGenerator[name].apply(null, arguments));
777
+ } catch (e) {
778
+ async.throwLater(e);
779
+ domEventFired = true;
780
+ }
781
+
782
+ return domEventFired || globalEventFired;
783
+ };
784
+
785
+ Promise.config = function(opts) {
786
+ opts = Object(opts);
787
+ if ("longStackTraces" in opts) {
788
+ if (opts.longStackTraces) {
789
+ Promise.longStackTraces();
790
+ } else if (!opts.longStackTraces && Promise.hasLongStackTraces()) {
791
+ disableLongStackTraces();
792
+ }
793
+ }
794
+ if ("warnings" in opts) {
795
+ var warningsOption = opts.warnings;
796
+ config.warnings = !!warningsOption;
797
+ wForgottenReturn = config.warnings;
798
+
799
+ if (util.isObject(warningsOption)) {
800
+ if ("wForgottenReturn" in warningsOption) {
801
+ wForgottenReturn = !!warningsOption.wForgottenReturn;
802
+ }
803
+ }
804
+ }
805
+ if ("cancellation" in opts && opts.cancellation && !config.cancellation) {
806
+ if (async.haveItemsQueued()) {
807
+ throw new Error(
808
+ "cannot enable cancellation after promises are in use");
809
+ }
810
+ Promise.prototype._clearCancellationData =
811
+ cancellationClearCancellationData;
812
+ Promise.prototype._propagateFrom = cancellationPropagateFrom;
813
+ Promise.prototype._onCancel = cancellationOnCancel;
814
+ Promise.prototype._setOnCancel = cancellationSetOnCancel;
815
+ Promise.prototype._attachCancellationCallback =
816
+ cancellationAttachCancellationCallback;
817
+ Promise.prototype._execute = cancellationExecute;
818
+ propagateFromFunction = cancellationPropagateFrom;
819
+ config.cancellation = true;
820
+ }
821
+ if ("monitoring" in opts) {
822
+ if (opts.monitoring && !config.monitoring) {
823
+ config.monitoring = true;
824
+ Promise.prototype._fireEvent = activeFireEvent;
825
+ } else if (!opts.monitoring && config.monitoring) {
826
+ config.monitoring = false;
827
+ Promise.prototype._fireEvent = defaultFireEvent;
828
+ }
829
+ }
830
+ return Promise;
831
+ };
832
+
833
+ function defaultFireEvent() { return false; }
834
+
835
+ Promise.prototype._fireEvent = defaultFireEvent;
836
+ Promise.prototype._execute = function(executor, resolve, reject) {
837
+ try {
838
+ executor(resolve, reject);
839
+ } catch (e) {
840
+ return e;
841
+ }
842
+ };
843
+ Promise.prototype._onCancel = function () {};
844
+ Promise.prototype._setOnCancel = function (handler) { ; };
845
+ Promise.prototype._attachCancellationCallback = function(onCancel) {
846
+ ;
847
+ };
848
+ Promise.prototype._captureStackTrace = function () {};
849
+ Promise.prototype._attachExtraTrace = function () {};
850
+ Promise.prototype._dereferenceTrace = function () {};
851
+ Promise.prototype._clearCancellationData = function() {};
852
+ Promise.prototype._propagateFrom = function (parent, flags) {
853
+ ;
854
+ ;
855
+ };
856
+
857
+ function cancellationExecute(executor, resolve, reject) {
858
+ var promise = this;
859
+ try {
860
+ executor(resolve, reject, function(onCancel) {
861
+ if (typeof onCancel !== "function") {
862
+ throw new TypeError("onCancel must be a function, got: " +
863
+ util.toString(onCancel));
864
+ }
865
+ promise._attachCancellationCallback(onCancel);
866
+ });
867
+ } catch (e) {
868
+ return e;
869
+ }
870
+ }
871
+
872
+ function cancellationAttachCancellationCallback(onCancel) {
873
+ if (!this._isCancellable()) return this;
874
+
875
+ var previousOnCancel = this._onCancel();
876
+ if (previousOnCancel !== undefined) {
877
+ if (util.isArray(previousOnCancel)) {
878
+ previousOnCancel.push(onCancel);
879
+ } else {
880
+ this._setOnCancel([previousOnCancel, onCancel]);
881
+ }
882
+ } else {
883
+ this._setOnCancel(onCancel);
884
+ }
885
+ }
886
+
887
+ function cancellationOnCancel() {
888
+ return this._onCancelField;
889
+ }
890
+
891
+ function cancellationSetOnCancel(onCancel) {
892
+ this._onCancelField = onCancel;
893
+ }
894
+
895
+ function cancellationClearCancellationData() {
896
+ this._cancellationParent = undefined;
897
+ this._onCancelField = undefined;
898
+ }
899
+
900
+ function cancellationPropagateFrom(parent, flags) {
901
+ if ((flags & 1) !== 0) {
902
+ this._cancellationParent = parent;
903
+ var branchesRemainingToCancel = parent._branchesRemainingToCancel;
904
+ if (branchesRemainingToCancel === undefined) {
905
+ branchesRemainingToCancel = 0;
906
+ }
907
+ parent._branchesRemainingToCancel = branchesRemainingToCancel + 1;
908
+ }
909
+ if ((flags & 2) !== 0 && parent._isBound()) {
910
+ this._setBoundTo(parent._boundTo);
911
+ }
912
+ }
913
+
914
+ function bindingPropagateFrom(parent, flags) {
915
+ if ((flags & 2) !== 0 && parent._isBound()) {
916
+ this._setBoundTo(parent._boundTo);
917
+ }
918
+ }
919
+ var propagateFromFunction = bindingPropagateFrom;
920
+
921
+ function boundValueFunction() {
922
+ var ret = this._boundTo;
923
+ if (ret !== undefined) {
924
+ if (ret instanceof Promise) {
925
+ if (ret.isFulfilled()) {
926
+ return ret.value();
927
+ } else {
928
+ return undefined;
929
+ }
930
+ }
931
+ }
932
+ return ret;
933
+ }
934
+
935
+ function longStackTracesCaptureStackTrace() {
936
+ this._trace = new CapturedTrace(this._peekContext());
937
+ }
938
+
939
+ function longStackTracesAttachExtraTrace(error, ignoreSelf) {
940
+ if (canAttachTrace(error)) {
941
+ var trace = this._trace;
942
+ if (trace !== undefined) {
943
+ if (ignoreSelf) trace = trace._parent;
944
+ }
945
+ if (trace !== undefined) {
946
+ trace.attachExtraTrace(error);
947
+ } else if (!error.__stackCleaned__) {
948
+ var parsed = parseStackAndMessage(error);
949
+ util.notEnumerableProp(error, "stack",
950
+ parsed.message + "\n" + parsed.stack.join("\n"));
951
+ util.notEnumerableProp(error, "__stackCleaned__", true);
952
+ }
953
+ }
954
+ }
955
+
956
+ function longStackTracesDereferenceTrace() {
957
+ this._trace = undefined;
958
+ }
959
+
960
+ function checkForgottenReturns(returnValue, promiseCreated, name, promise,
961
+ parent) {
962
+ if (returnValue === undefined && promiseCreated !== null &&
963
+ wForgottenReturn) {
964
+ if (parent !== undefined && parent._returnedNonUndefined()) return;
965
+ if ((promise._bitField & 65535) === 0) return;
966
+
967
+ if (name) name = name + " ";
968
+ var handlerLine = "";
969
+ var creatorLine = "";
970
+ if (promiseCreated._trace) {
971
+ var traceLines = promiseCreated._trace.stack.split("\n");
972
+ var stack = cleanStack(traceLines);
973
+ for (var i = stack.length - 1; i >= 0; --i) {
974
+ var line = stack[i];
975
+ if (!nodeFramePattern.test(line)) {
976
+ var lineMatches = line.match(parseLinePattern);
977
+ if (lineMatches) {
978
+ handlerLine = "at " + lineMatches[1] +
979
+ ":" + lineMatches[2] + ":" + lineMatches[3] + " ";
980
+ }
981
+ break;
982
+ }
983
+ }
984
+
985
+ if (stack.length > 0) {
986
+ var firstUserLine = stack[0];
987
+ for (var i = 0; i < traceLines.length; ++i) {
988
+
989
+ if (traceLines[i] === firstUserLine) {
990
+ if (i > 0) {
991
+ creatorLine = "\n" + traceLines[i - 1];
992
+ }
993
+ break;
994
+ }
995
+ }
996
+
997
+ }
998
+ }
999
+ var msg = "a promise was created in a " + name +
1000
+ "handler " + handlerLine + "but was not returned from it, " +
1001
+ "see http://goo.gl/rRqMUw" +
1002
+ creatorLine;
1003
+ promise._warn(msg, true, promiseCreated);
1004
+ }
1005
+ }
1006
+
1007
+ function deprecated(name, replacement) {
1008
+ var message = name +
1009
+ " is deprecated and will be removed in a future version.";
1010
+ if (replacement) message += " Use " + replacement + " instead.";
1011
+ return warn(message);
1012
+ }
1013
+
1014
+ function warn(message, shouldUseOwnTrace, promise) {
1015
+ if (!config.warnings) return;
1016
+ var warning = new Warning(message);
1017
+ var ctx;
1018
+ if (shouldUseOwnTrace) {
1019
+ promise._attachExtraTrace(warning);
1020
+ } else if (config.longStackTraces && (ctx = Promise._peekContext())) {
1021
+ ctx.attachExtraTrace(warning);
1022
+ } else {
1023
+ var parsed = parseStackAndMessage(warning);
1024
+ warning.stack = parsed.message + "\n" + parsed.stack.join("\n");
1025
+ }
1026
+
1027
+ if (!activeFireEvent("warning", warning)) {
1028
+ formatAndLogError(warning, "", true);
1029
+ }
1030
+ }
1031
+
1032
+ function reconstructStack(message, stacks) {
1033
+ for (var i = 0; i < stacks.length - 1; ++i) {
1034
+ stacks[i].push("From previous event:");
1035
+ stacks[i] = stacks[i].join("\n");
1036
+ }
1037
+ if (i < stacks.length) {
1038
+ stacks[i] = stacks[i].join("\n");
1039
+ }
1040
+ return message + "\n" + stacks.join("\n");
1041
+ }
1042
+
1043
+ function removeDuplicateOrEmptyJumps(stacks) {
1044
+ for (var i = 0; i < stacks.length; ++i) {
1045
+ if (stacks[i].length === 0 ||
1046
+ ((i + 1 < stacks.length) && stacks[i][0] === stacks[i+1][0])) {
1047
+ stacks.splice(i, 1);
1048
+ i--;
1049
+ }
1050
+ }
1051
+ }
1052
+
1053
+ function removeCommonRoots(stacks) {
1054
+ var current = stacks[0];
1055
+ for (var i = 1; i < stacks.length; ++i) {
1056
+ var prev = stacks[i];
1057
+ var currentLastIndex = current.length - 1;
1058
+ var currentLastLine = current[currentLastIndex];
1059
+ var commonRootMeetPoint = -1;
1060
+
1061
+ for (var j = prev.length - 1; j >= 0; --j) {
1062
+ if (prev[j] === currentLastLine) {
1063
+ commonRootMeetPoint = j;
1064
+ break;
1065
+ }
1066
+ }
1067
+
1068
+ for (var j = commonRootMeetPoint; j >= 0; --j) {
1069
+ var line = prev[j];
1070
+ if (current[currentLastIndex] === line) {
1071
+ current.pop();
1072
+ currentLastIndex--;
1073
+ } else {
1074
+ break;
1075
+ }
1076
+ }
1077
+ current = prev;
1078
+ }
1079
+ }
1080
+
1081
+ function cleanStack(stack) {
1082
+ var ret = [];
1083
+ for (var i = 0; i < stack.length; ++i) {
1084
+ var line = stack[i];
1085
+ var isTraceLine = " (No stack trace)" === line ||
1086
+ stackFramePattern.test(line);
1087
+ var isInternalFrame = isTraceLine && shouldIgnore(line);
1088
+ if (isTraceLine && !isInternalFrame) {
1089
+ if (indentStackFrames && line.charAt(0) !== " ") {
1090
+ line = " " + line;
1091
+ }
1092
+ ret.push(line);
1093
+ }
1094
+ }
1095
+ return ret;
1096
+ }
1097
+
1098
+ function stackFramesAsArray(error) {
1099
+ var stack = error.stack.replace(/\s+$/g, "").split("\n");
1100
+ for (var i = 0; i < stack.length; ++i) {
1101
+ var line = stack[i];
1102
+ if (" (No stack trace)" === line || stackFramePattern.test(line)) {
1103
+ break;
1104
+ }
1105
+ }
1106
+ if (i > 0 && error.name != "SyntaxError") {
1107
+ stack = stack.slice(i);
1108
+ }
1109
+ return stack;
1110
+ }
1111
+
1112
+ function parseStackAndMessage(error) {
1113
+ var stack = error.stack;
1114
+ var message = error.toString();
1115
+ stack = typeof stack === "string" && stack.length > 0
1116
+ ? stackFramesAsArray(error) : [" (No stack trace)"];
1117
+ return {
1118
+ message: message,
1119
+ stack: error.name == "SyntaxError" ? stack : cleanStack(stack)
1120
+ };
1121
+ }
1122
+
1123
+ function formatAndLogError(error, title, isSoft) {
1124
+ if (typeof console !== "undefined") {
1125
+ var message;
1126
+ if (util.isObject(error)) {
1127
+ var stack = error.stack;
1128
+ message = title + formatStack(stack, error);
1129
+ } else {
1130
+ message = title + String(error);
1131
+ }
1132
+ if (typeof printWarning === "function") {
1133
+ printWarning(message, isSoft);
1134
+ } else if (typeof console.log === "function" ||
1135
+ typeof console.log === "object") {
1136
+ console.log(message);
1137
+ }
1138
+ }
1139
+ }
1140
+
1141
+ function fireRejectionEvent(name, localHandler, reason, promise) {
1142
+ var localEventFired = false;
1143
+ try {
1144
+ if (typeof localHandler === "function") {
1145
+ localEventFired = true;
1146
+ if (name === "rejectionHandled") {
1147
+ localHandler(promise);
1148
+ } else {
1149
+ localHandler(reason, promise);
1150
+ }
1151
+ }
1152
+ } catch (e) {
1153
+ async.throwLater(e);
1154
+ }
1155
+
1156
+ if (name === "unhandledRejection") {
1157
+ if (!activeFireEvent(name, reason, promise) && !localEventFired) {
1158
+ formatAndLogError(reason, "Unhandled rejection ");
1159
+ }
1160
+ } else {
1161
+ activeFireEvent(name, promise);
1162
+ }
1163
+ }
1164
+
1165
+ function formatNonError(obj) {
1166
+ var str;
1167
+ if (typeof obj === "function") {
1168
+ str = "[function " +
1169
+ (obj.name || "anonymous") +
1170
+ "]";
1171
+ } else {
1172
+ str = obj && typeof obj.toString === "function"
1173
+ ? obj.toString() : util.toString(obj);
1174
+ var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
1175
+ if (ruselessToString.test(str)) {
1176
+ try {
1177
+ var newStr = JSON.stringify(obj);
1178
+ str = newStr;
1179
+ }
1180
+ catch(e) {
1181
+
1182
+ }
1183
+ }
1184
+ if (str.length === 0) {
1185
+ str = "(empty array)";
1186
+ }
1187
+ }
1188
+ return ("(<" + snip(str) + ">, no stack trace)");
1189
+ }
1190
+
1191
+ function snip(str) {
1192
+ var maxChars = 41;
1193
+ if (str.length < maxChars) {
1194
+ return str;
1195
+ }
1196
+ return str.substr(0, maxChars - 3) + "...";
1197
+ }
1198
+
1199
+ function longStackTracesIsSupported() {
1200
+ return typeof captureStackTrace === "function";
1201
+ }
1202
+
1203
+ var shouldIgnore = function() { return false; };
1204
+ var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
1205
+ function parseLineInfo(line) {
1206
+ var matches = line.match(parseLineInfoRegex);
1207
+ if (matches) {
1208
+ return {
1209
+ fileName: matches[1],
1210
+ line: parseInt(matches[2], 10)
1211
+ };
1212
+ }
1213
+ }
1214
+
1215
+ function setBounds(firstLineError, lastLineError) {
1216
+ if (!longStackTracesIsSupported()) return;
1217
+ var firstStackLines = (firstLineError.stack || "").split("\n");
1218
+ var lastStackLines = (lastLineError.stack || "").split("\n");
1219
+ var firstIndex = -1;
1220
+ var lastIndex = -1;
1221
+ var firstFileName;
1222
+ var lastFileName;
1223
+ for (var i = 0; i < firstStackLines.length; ++i) {
1224
+ var result = parseLineInfo(firstStackLines[i]);
1225
+ if (result) {
1226
+ firstFileName = result.fileName;
1227
+ firstIndex = result.line;
1228
+ break;
1229
+ }
1230
+ }
1231
+ for (var i = 0; i < lastStackLines.length; ++i) {
1232
+ var result = parseLineInfo(lastStackLines[i]);
1233
+ if (result) {
1234
+ lastFileName = result.fileName;
1235
+ lastIndex = result.line;
1236
+ break;
1237
+ }
1238
+ }
1239
+ if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
1240
+ firstFileName !== lastFileName || firstIndex >= lastIndex) {
1241
+ return;
1242
+ }
1243
+
1244
+ shouldIgnore = function(line) {
1245
+ if (bluebirdFramePattern.test(line)) return true;
1246
+ var info = parseLineInfo(line);
1247
+ if (info) {
1248
+ if (info.fileName === firstFileName &&
1249
+ (firstIndex <= info.line && info.line <= lastIndex)) {
1250
+ return true;
1251
+ }
1252
+ }
1253
+ return false;
1254
+ };
1255
+ }
1256
+
1257
+ function CapturedTrace(parent) {
1258
+ this._parent = parent;
1259
+ this._promisesCreated = 0;
1260
+ var length = this._length = 1 + (parent === undefined ? 0 : parent._length);
1261
+ captureStackTrace(this, CapturedTrace);
1262
+ if (length > 32) this.uncycle();
1263
+ }
1264
+ util.inherits(CapturedTrace, Error);
1265
+ Context.CapturedTrace = CapturedTrace;
1266
+
1267
+ CapturedTrace.prototype.uncycle = function() {
1268
+ var length = this._length;
1269
+ if (length < 2) return;
1270
+ var nodes = [];
1271
+ var stackToIndex = {};
1272
+
1273
+ for (var i = 0, node = this; node !== undefined; ++i) {
1274
+ nodes.push(node);
1275
+ node = node._parent;
1276
+ }
1277
+ length = this._length = i;
1278
+ for (var i = length - 1; i >= 0; --i) {
1279
+ var stack = nodes[i].stack;
1280
+ if (stackToIndex[stack] === undefined) {
1281
+ stackToIndex[stack] = i;
1282
+ }
1283
+ }
1284
+ for (var i = 0; i < length; ++i) {
1285
+ var currentStack = nodes[i].stack;
1286
+ var index = stackToIndex[currentStack];
1287
+ if (index !== undefined && index !== i) {
1288
+ if (index > 0) {
1289
+ nodes[index - 1]._parent = undefined;
1290
+ nodes[index - 1]._length = 1;
1291
+ }
1292
+ nodes[i]._parent = undefined;
1293
+ nodes[i]._length = 1;
1294
+ var cycleEdgeNode = i > 0 ? nodes[i - 1] : this;
1295
+
1296
+ if (index < length - 1) {
1297
+ cycleEdgeNode._parent = nodes[index + 1];
1298
+ cycleEdgeNode._parent.uncycle();
1299
+ cycleEdgeNode._length =
1300
+ cycleEdgeNode._parent._length + 1;
1301
+ } else {
1302
+ cycleEdgeNode._parent = undefined;
1303
+ cycleEdgeNode._length = 1;
1304
+ }
1305
+ var currentChildLength = cycleEdgeNode._length + 1;
1306
+ for (var j = i - 2; j >= 0; --j) {
1307
+ nodes[j]._length = currentChildLength;
1308
+ currentChildLength++;
1309
+ }
1310
+ return;
1311
+ }
1312
+ }
1313
+ };
1314
+
1315
+ CapturedTrace.prototype.attachExtraTrace = function(error) {
1316
+ if (error.__stackCleaned__) return;
1317
+ this.uncycle();
1318
+ var parsed = parseStackAndMessage(error);
1319
+ var message = parsed.message;
1320
+ var stacks = [parsed.stack];
1321
+
1322
+ var trace = this;
1323
+ while (trace !== undefined) {
1324
+ stacks.push(cleanStack(trace.stack.split("\n")));
1325
+ trace = trace._parent;
1326
+ }
1327
+ removeCommonRoots(stacks);
1328
+ removeDuplicateOrEmptyJumps(stacks);
1329
+ util.notEnumerableProp(error, "stack", reconstructStack(message, stacks));
1330
+ util.notEnumerableProp(error, "__stackCleaned__", true);
1331
+ };
1332
+
1333
+ var captureStackTrace = (function stackDetection() {
1334
+ var v8stackFramePattern = /^\s*at\s*/;
1335
+ var v8stackFormatter = function(stack, error) {
1336
+ if (typeof stack === "string") return stack;
1337
+
1338
+ if (error.name !== undefined &&
1339
+ error.message !== undefined) {
1340
+ return error.toString();
1341
+ }
1342
+ return formatNonError(error);
1343
+ };
1344
+
1345
+ if (typeof Error.stackTraceLimit === "number" &&
1346
+ typeof Error.captureStackTrace === "function") {
1347
+ Error.stackTraceLimit += 6;
1348
+ stackFramePattern = v8stackFramePattern;
1349
+ formatStack = v8stackFormatter;
1350
+ var captureStackTrace = Error.captureStackTrace;
1351
+
1352
+ shouldIgnore = function(line) {
1353
+ return bluebirdFramePattern.test(line);
1354
+ };
1355
+ return function(receiver, ignoreUntil) {
1356
+ Error.stackTraceLimit += 6;
1357
+ captureStackTrace(receiver, ignoreUntil);
1358
+ Error.stackTraceLimit -= 6;
1359
+ };
1360
+ }
1361
+ var err = new Error();
1362
+
1363
+ if (typeof err.stack === "string" &&
1364
+ err.stack.split("\n")[0].indexOf("stackDetection@") >= 0) {
1365
+ stackFramePattern = /@/;
1366
+ formatStack = v8stackFormatter;
1367
+ indentStackFrames = true;
1368
+ return function captureStackTrace(o) {
1369
+ o.stack = new Error().stack;
1370
+ };
1371
+ }
1372
+
1373
+ var hasStackAfterThrow;
1374
+ try { throw new Error(); }
1375
+ catch(e) {
1376
+ hasStackAfterThrow = ("stack" in e);
1377
+ }
1378
+ if (!("stack" in err) && hasStackAfterThrow &&
1379
+ typeof Error.stackTraceLimit === "number") {
1380
+ stackFramePattern = v8stackFramePattern;
1381
+ formatStack = v8stackFormatter;
1382
+ return function captureStackTrace(o) {
1383
+ Error.stackTraceLimit += 6;
1384
+ try { throw new Error(); }
1385
+ catch(e) { o.stack = e.stack; }
1386
+ Error.stackTraceLimit -= 6;
1387
+ };
1388
+ }
1389
+
1390
+ formatStack = function(stack, error) {
1391
+ if (typeof stack === "string") return stack;
1392
+
1393
+ if ((typeof error === "object" ||
1394
+ typeof error === "function") &&
1395
+ error.name !== undefined &&
1396
+ error.message !== undefined) {
1397
+ return error.toString();
1398
+ }
1399
+ return formatNonError(error);
1400
+ };
1401
+
1402
+ return null;
1403
+
1404
+ })([]);
1405
+
1406
+ if (typeof console !== "undefined" && typeof console.warn !== "undefined") {
1407
+ printWarning = function (message) {
1408
+ console.warn(message);
1409
+ };
1410
+ if (util.isNode && process.stderr.isTTY) {
1411
+ printWarning = function(message, isSoft) {
1412
+ var color = isSoft ? "\u001b[33m" : "\u001b[31m";
1413
+ console.warn(color + message + "\u001b[0m\n");
1414
+ };
1415
+ } else if (!util.isNode && typeof (new Error().stack) === "string") {
1416
+ printWarning = function(message, isSoft) {
1417
+ console.warn("%c" + message,
1418
+ isSoft ? "color: darkorange" : "color: red");
1419
+ };
1420
+ }
1421
+ }
1422
+
1423
+ var config = {
1424
+ warnings: warnings,
1425
+ longStackTraces: false,
1426
+ cancellation: false,
1427
+ monitoring: false
1428
+ };
1429
+
1430
+ if (longStackTraces) Promise.longStackTraces();
1431
+
1432
+ return {
1433
+ longStackTraces: function() {
1434
+ return config.longStackTraces;
1435
+ },
1436
+ warnings: function() {
1437
+ return config.warnings;
1438
+ },
1439
+ cancellation: function() {
1440
+ return config.cancellation;
1441
+ },
1442
+ monitoring: function() {
1443
+ return config.monitoring;
1444
+ },
1445
+ propagateFromFunction: function() {
1446
+ return propagateFromFunction;
1447
+ },
1448
+ boundValueFunction: function() {
1449
+ return boundValueFunction;
1450
+ },
1451
+ checkForgottenReturns: checkForgottenReturns,
1452
+ setBounds: setBounds,
1453
+ warn: warn,
1454
+ deprecated: deprecated,
1455
+ CapturedTrace: CapturedTrace,
1456
+ fireDomEvent: fireDomEvent,
1457
+ fireGlobalEvent: fireGlobalEvent
1458
+ };
1459
+ };
1460
+
1461
+ },{"./errors":9,"./es5":10,"./util":21}],8:[function(_dereq_,module,exports){
1462
+ "use strict";
1463
+ module.exports = function(Promise) {
1464
+ function returner() {
1465
+ return this.value;
1466
+ }
1467
+ function thrower() {
1468
+ throw this.reason;
1469
+ }
1470
+
1471
+ Promise.prototype["return"] =
1472
+ Promise.prototype.thenReturn = function (value) {
1473
+ if (value instanceof Promise) value.suppressUnhandledRejections();
1474
+ return this._then(
1475
+ returner, undefined, undefined, {value: value}, undefined);
1476
+ };
1477
+
1478
+ Promise.prototype["throw"] =
1479
+ Promise.prototype.thenThrow = function (reason) {
1480
+ return this._then(
1481
+ thrower, undefined, undefined, {reason: reason}, undefined);
1482
+ };
1483
+
1484
+ Promise.prototype.catchThrow = function (reason) {
1485
+ if (arguments.length <= 1) {
1486
+ return this._then(
1487
+ undefined, thrower, undefined, {reason: reason}, undefined);
1488
+ } else {
1489
+ var _reason = arguments[1];
1490
+ var handler = function() {throw _reason;};
1491
+ return this.caught(reason, handler);
1492
+ }
1493
+ };
1494
+
1495
+ Promise.prototype.catchReturn = function (value) {
1496
+ if (arguments.length <= 1) {
1497
+ if (value instanceof Promise) value.suppressUnhandledRejections();
1498
+ return this._then(
1499
+ undefined, returner, undefined, {value: value}, undefined);
1500
+ } else {
1501
+ var _value = arguments[1];
1502
+ if (_value instanceof Promise) _value.suppressUnhandledRejections();
1503
+ var handler = function() {return _value;};
1504
+ return this.caught(value, handler);
1505
+ }
1506
+ };
1507
+ };
1508
+
1509
+ },{}],9:[function(_dereq_,module,exports){
1510
+ "use strict";
1511
+ var es5 = _dereq_("./es5");
1512
+ var Objectfreeze = es5.freeze;
1513
+ var util = _dereq_("./util");
1514
+ var inherits = util.inherits;
1515
+ var notEnumerableProp = util.notEnumerableProp;
1516
+
1517
+ function subError(nameProperty, defaultMessage) {
1518
+ function SubError(message) {
1519
+ if (!(this instanceof SubError)) return new SubError(message);
1520
+ notEnumerableProp(this, "message",
1521
+ typeof message === "string" ? message : defaultMessage);
1522
+ notEnumerableProp(this, "name", nameProperty);
1523
+ if (Error.captureStackTrace) {
1524
+ Error.captureStackTrace(this, this.constructor);
1525
+ } else {
1526
+ Error.call(this);
1527
+ }
1528
+ }
1529
+ inherits(SubError, Error);
1530
+ return SubError;
1531
+ }
1532
+
1533
+ var _TypeError, _RangeError;
1534
+ var Warning = subError("Warning", "warning");
1535
+ var CancellationError = subError("CancellationError", "cancellation error");
1536
+ var TimeoutError = subError("TimeoutError", "timeout error");
1537
+ var AggregateError = subError("AggregateError", "aggregate error");
1538
+ try {
1539
+ _TypeError = TypeError;
1540
+ _RangeError = RangeError;
1541
+ } catch(e) {
1542
+ _TypeError = subError("TypeError", "type error");
1543
+ _RangeError = subError("RangeError", "range error");
1544
+ }
1545
+
1546
+ var methods = ("join pop push shift unshift slice filter forEach some " +
1547
+ "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
1548
+
1549
+ for (var i = 0; i < methods.length; ++i) {
1550
+ if (typeof Array.prototype[methods[i]] === "function") {
1551
+ AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
1552
+ }
1553
+ }
1554
+
1555
+ es5.defineProperty(AggregateError.prototype, "length", {
1556
+ value: 0,
1557
+ configurable: false,
1558
+ writable: true,
1559
+ enumerable: true
1560
+ });
1561
+ AggregateError.prototype["isOperational"] = true;
1562
+ var level = 0;
1563
+ AggregateError.prototype.toString = function() {
1564
+ var indent = Array(level * 4 + 1).join(" ");
1565
+ var ret = "\n" + indent + "AggregateError of:" + "\n";
1566
+ level++;
1567
+ indent = Array(level * 4 + 1).join(" ");
1568
+ for (var i = 0; i < this.length; ++i) {
1569
+ var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
1570
+ var lines = str.split("\n");
1571
+ for (var j = 0; j < lines.length; ++j) {
1572
+ lines[j] = indent + lines[j];
1573
+ }
1574
+ str = lines.join("\n");
1575
+ ret += str + "\n";
1576
+ }
1577
+ level--;
1578
+ return ret;
1579
+ };
1580
+
1581
+ function OperationalError(message) {
1582
+ if (!(this instanceof OperationalError))
1583
+ return new OperationalError(message);
1584
+ notEnumerableProp(this, "name", "OperationalError");
1585
+ notEnumerableProp(this, "message", message);
1586
+ this.cause = message;
1587
+ this["isOperational"] = true;
1588
+
1589
+ if (message instanceof Error) {
1590
+ notEnumerableProp(this, "message", message.message);
1591
+ notEnumerableProp(this, "stack", message.stack);
1592
+ } else if (Error.captureStackTrace) {
1593
+ Error.captureStackTrace(this, this.constructor);
1594
+ }
1595
+
1596
+ }
1597
+ inherits(OperationalError, Error);
1598
+
1599
+ var errorTypes = Error["__BluebirdErrorTypes__"];
1600
+ if (!errorTypes) {
1601
+ errorTypes = Objectfreeze({
1602
+ CancellationError: CancellationError,
1603
+ TimeoutError: TimeoutError,
1604
+ OperationalError: OperationalError,
1605
+ RejectionError: OperationalError,
1606
+ AggregateError: AggregateError
1607
+ });
1608
+ es5.defineProperty(Error, "__BluebirdErrorTypes__", {
1609
+ value: errorTypes,
1610
+ writable: false,
1611
+ enumerable: false,
1612
+ configurable: false
1613
+ });
1614
+ }
1615
+
1616
+ module.exports = {
1617
+ Error: Error,
1618
+ TypeError: _TypeError,
1619
+ RangeError: _RangeError,
1620
+ CancellationError: errorTypes.CancellationError,
1621
+ OperationalError: errorTypes.OperationalError,
1622
+ TimeoutError: errorTypes.TimeoutError,
1623
+ AggregateError: errorTypes.AggregateError,
1624
+ Warning: Warning
1625
+ };
1626
+
1627
+ },{"./es5":10,"./util":21}],10:[function(_dereq_,module,exports){
1628
+ var isES5 = (function(){
1629
+ "use strict";
1630
+ return this === undefined;
1631
+ })();
1632
+
1633
+ if (isES5) {
1634
+ module.exports = {
1635
+ freeze: Object.freeze,
1636
+ defineProperty: Object.defineProperty,
1637
+ getDescriptor: Object.getOwnPropertyDescriptor,
1638
+ keys: Object.keys,
1639
+ names: Object.getOwnPropertyNames,
1640
+ getPrototypeOf: Object.getPrototypeOf,
1641
+ isArray: Array.isArray,
1642
+ isES5: isES5,
1643
+ propertyIsWritable: function(obj, prop) {
1644
+ var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
1645
+ return !!(!descriptor || descriptor.writable || descriptor.set);
1646
+ }
1647
+ };
1648
+ } else {
1649
+ var has = {}.hasOwnProperty;
1650
+ var str = {}.toString;
1651
+ var proto = {}.constructor.prototype;
1652
+
1653
+ var ObjectKeys = function (o) {
1654
+ var ret = [];
1655
+ for (var key in o) {
1656
+ if (has.call(o, key)) {
1657
+ ret.push(key);
1658
+ }
1659
+ }
1660
+ return ret;
1661
+ };
1662
+
1663
+ var ObjectGetDescriptor = function(o, key) {
1664
+ return {value: o[key]};
1665
+ };
1666
+
1667
+ var ObjectDefineProperty = function (o, key, desc) {
1668
+ o[key] = desc.value;
1669
+ return o;
1670
+ };
1671
+
1672
+ var ObjectFreeze = function (obj) {
1673
+ return obj;
1674
+ };
1675
+
1676
+ var ObjectGetPrototypeOf = function (obj) {
1677
+ try {
1678
+ return Object(obj).constructor.prototype;
1679
+ }
1680
+ catch (e) {
1681
+ return proto;
1682
+ }
1683
+ };
1684
+
1685
+ var ArrayIsArray = function (obj) {
1686
+ try {
1687
+ return str.call(obj) === "[object Array]";
1688
+ }
1689
+ catch(e) {
1690
+ return false;
1691
+ }
1692
+ };
1693
+
1694
+ module.exports = {
1695
+ isArray: ArrayIsArray,
1696
+ keys: ObjectKeys,
1697
+ names: ObjectKeys,
1698
+ defineProperty: ObjectDefineProperty,
1699
+ getDescriptor: ObjectGetDescriptor,
1700
+ freeze: ObjectFreeze,
1701
+ getPrototypeOf: ObjectGetPrototypeOf,
1702
+ isES5: isES5,
1703
+ propertyIsWritable: function() {
1704
+ return true;
1705
+ }
1706
+ };
1707
+ }
1708
+
1709
+ },{}],11:[function(_dereq_,module,exports){
1710
+ "use strict";
1711
+ module.exports = function(Promise, tryConvertToPromise, NEXT_FILTER) {
1712
+ var util = _dereq_("./util");
1713
+ var CancellationError = Promise.CancellationError;
1714
+ var errorObj = util.errorObj;
1715
+ var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER);
1716
+
1717
+ function PassThroughHandlerContext(promise, type, handler) {
1718
+ this.promise = promise;
1719
+ this.type = type;
1720
+ this.handler = handler;
1721
+ this.called = false;
1722
+ this.cancelPromise = null;
1723
+ }
1724
+
1725
+ PassThroughHandlerContext.prototype.isFinallyHandler = function() {
1726
+ return this.type === 0;
1727
+ };
1728
+
1729
+ function FinallyHandlerCancelReaction(finallyHandler) {
1730
+ this.finallyHandler = finallyHandler;
1731
+ }
1732
+
1733
+ FinallyHandlerCancelReaction.prototype._resultCancelled = function() {
1734
+ checkCancel(this.finallyHandler);
1735
+ };
1736
+
1737
+ function checkCancel(ctx, reason) {
1738
+ if (ctx.cancelPromise != null) {
1739
+ if (arguments.length > 1) {
1740
+ ctx.cancelPromise._reject(reason);
1741
+ } else {
1742
+ ctx.cancelPromise._cancel();
1743
+ }
1744
+ ctx.cancelPromise = null;
1745
+ return true;
1746
+ }
1747
+ return false;
1748
+ }
1749
+
1750
+ function succeed() {
1751
+ return finallyHandler.call(this, this.promise._target()._settledValue());
1752
+ }
1753
+ function fail(reason) {
1754
+ if (checkCancel(this, reason)) return;
1755
+ errorObj.e = reason;
1756
+ return errorObj;
1757
+ }
1758
+ function finallyHandler(reasonOrValue) {
1759
+ var promise = this.promise;
1760
+ var handler = this.handler;
1761
+
1762
+ if (!this.called) {
1763
+ this.called = true;
1764
+ var ret = this.isFinallyHandler()
1765
+ ? handler.call(promise._boundValue())
1766
+ : handler.call(promise._boundValue(), reasonOrValue);
1767
+ if (ret === NEXT_FILTER) {
1768
+ return ret;
1769
+ } else if (ret !== undefined) {
1770
+ promise._setReturnedNonUndefined();
1771
+ var maybePromise = tryConvertToPromise(ret, promise);
1772
+ if (maybePromise instanceof Promise) {
1773
+ if (this.cancelPromise != null) {
1774
+ if (maybePromise._isCancelled()) {
1775
+ var reason =
1776
+ new CancellationError("late cancellation observer");
1777
+ promise._attachExtraTrace(reason);
1778
+ errorObj.e = reason;
1779
+ return errorObj;
1780
+ } else if (maybePromise.isPending()) {
1781
+ maybePromise._attachCancellationCallback(
1782
+ new FinallyHandlerCancelReaction(this));
1783
+ }
1784
+ }
1785
+ return maybePromise._then(
1786
+ succeed, fail, undefined, this, undefined);
1787
+ }
1788
+ }
1789
+ }
1790
+
1791
+ if (promise.isRejected()) {
1792
+ checkCancel(this);
1793
+ errorObj.e = reasonOrValue;
1794
+ return errorObj;
1795
+ } else {
1796
+ checkCancel(this);
1797
+ return reasonOrValue;
1798
+ }
1799
+ }
1800
+
1801
+ Promise.prototype._passThrough = function(handler, type, success, fail) {
1802
+ if (typeof handler !== "function") return this.then();
1803
+ return this._then(success,
1804
+ fail,
1805
+ undefined,
1806
+ new PassThroughHandlerContext(this, type, handler),
1807
+ undefined);
1808
+ };
1809
+
1810
+ Promise.prototype.lastly =
1811
+ Promise.prototype["finally"] = function (handler) {
1812
+ return this._passThrough(handler,
1813
+ 0,
1814
+ finallyHandler,
1815
+ finallyHandler);
1816
+ };
1817
+
1818
+
1819
+ Promise.prototype.tap = function (handler) {
1820
+ return this._passThrough(handler, 1, finallyHandler);
1821
+ };
1822
+
1823
+ Promise.prototype.tapCatch = function (handlerOrPredicate) {
1824
+ var len = arguments.length;
1825
+ if(len === 1) {
1826
+ return this._passThrough(handlerOrPredicate,
1827
+ 1,
1828
+ undefined,
1829
+ finallyHandler);
1830
+ } else {
1831
+ var catchInstances = new Array(len - 1),
1832
+ j = 0, i;
1833
+ for (i = 0; i < len - 1; ++i) {
1834
+ var item = arguments[i];
1835
+ if (util.isObject(item)) {
1836
+ catchInstances[j++] = item;
1837
+ } else {
1838
+ return Promise.reject(new TypeError(
1839
+ "tapCatch statement predicate: "
1840
+ + "expecting an object but got " + util.classString(item)
1841
+ ));
1842
+ }
1843
+ }
1844
+ catchInstances.length = j;
1845
+ var handler = arguments[i];
1846
+ return this._passThrough(catchFilter(catchInstances, handler, this),
1847
+ 1,
1848
+ undefined,
1849
+ finallyHandler);
1850
+ }
1851
+
1852
+ };
1853
+
1854
+ return PassThroughHandlerContext;
1855
+ };
1856
+
1857
+ },{"./catch_filter":5,"./util":21}],12:[function(_dereq_,module,exports){
1858
+ "use strict";
1859
+ module.exports =
1860
+ function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async,
1861
+ getDomain) {
1862
+ var util = _dereq_("./util");
1863
+ var canEvaluate = util.canEvaluate;
1864
+ var tryCatch = util.tryCatch;
1865
+ var errorObj = util.errorObj;
1866
+ var reject;
1867
+
1868
+ if (!true) {
1869
+ if (canEvaluate) {
1870
+ var thenCallback = function(i) {
1871
+ return new Function("value", "holder", " \n\
1872
+ 'use strict'; \n\
1873
+ holder.pIndex = value; \n\
1874
+ holder.checkFulfillment(this); \n\
1875
+ ".replace(/Index/g, i));
1876
+ };
1877
+
1878
+ var promiseSetter = function(i) {
1879
+ return new Function("promise", "holder", " \n\
1880
+ 'use strict'; \n\
1881
+ holder.pIndex = promise; \n\
1882
+ ".replace(/Index/g, i));
1883
+ };
1884
+
1885
+ var generateHolderClass = function(total) {
1886
+ var props = new Array(total);
1887
+ for (var i = 0; i < props.length; ++i) {
1888
+ props[i] = "this.p" + (i+1);
1889
+ }
1890
+ var assignment = props.join(" = ") + " = null;";
1891
+ var cancellationCode= "var promise;\n" + props.map(function(prop) {
1892
+ return " \n\
1893
+ promise = " + prop + "; \n\
1894
+ if (promise instanceof Promise) { \n\
1895
+ promise.cancel(); \n\
1896
+ } \n\
1897
+ ";
1898
+ }).join("\n");
1899
+ var passedArguments = props.join(", ");
1900
+ var name = "Holder$" + total;
1901
+
1902
+
1903
+ var code = "return function(tryCatch, errorObj, Promise, async) { \n\
1904
+ 'use strict'; \n\
1905
+ function [TheName](fn) { \n\
1906
+ [TheProperties] \n\
1907
+ this.fn = fn; \n\
1908
+ this.asyncNeeded = true; \n\
1909
+ this.now = 0; \n\
1910
+ } \n\
1911
+ \n\
1912
+ [TheName].prototype._callFunction = function(promise) { \n\
1913
+ promise._pushContext(); \n\
1914
+ var ret = tryCatch(this.fn)([ThePassedArguments]); \n\
1915
+ promise._popContext(); \n\
1916
+ if (ret === errorObj) { \n\
1917
+ promise._rejectCallback(ret.e, false); \n\
1918
+ } else { \n\
1919
+ promise._resolveCallback(ret); \n\
1920
+ } \n\
1921
+ }; \n\
1922
+ \n\
1923
+ [TheName].prototype.checkFulfillment = function(promise) { \n\
1924
+ var now = ++this.now; \n\
1925
+ if (now === [TheTotal]) { \n\
1926
+ if (this.asyncNeeded) { \n\
1927
+ async.invoke(this._callFunction, this, promise); \n\
1928
+ } else { \n\
1929
+ this._callFunction(promise); \n\
1930
+ } \n\
1931
+ \n\
1932
+ } \n\
1933
+ }; \n\
1934
+ \n\
1935
+ [TheName].prototype._resultCancelled = function() { \n\
1936
+ [CancellationCode] \n\
1937
+ }; \n\
1938
+ \n\
1939
+ return [TheName]; \n\
1940
+ }(tryCatch, errorObj, Promise, async); \n\
1941
+ ";
1942
+
1943
+ code = code.replace(/\[TheName\]/g, name)
1944
+ .replace(/\[TheTotal\]/g, total)
1945
+ .replace(/\[ThePassedArguments\]/g, passedArguments)
1946
+ .replace(/\[TheProperties\]/g, assignment)
1947
+ .replace(/\[CancellationCode\]/g, cancellationCode);
1948
+
1949
+ return new Function("tryCatch", "errorObj", "Promise", "async", code)
1950
+ (tryCatch, errorObj, Promise, async);
1951
+ };
1952
+
1953
+ var holderClasses = [];
1954
+ var thenCallbacks = [];
1955
+ var promiseSetters = [];
1956
+
1957
+ for (var i = 0; i < 8; ++i) {
1958
+ holderClasses.push(generateHolderClass(i + 1));
1959
+ thenCallbacks.push(thenCallback(i + 1));
1960
+ promiseSetters.push(promiseSetter(i + 1));
1961
+ }
1962
+
1963
+ reject = function (reason) {
1964
+ this._reject(reason);
1965
+ };
1966
+ }}
1967
+
1968
+ Promise.join = function () {
1969
+ var last = arguments.length - 1;
1970
+ var fn;
1971
+ if (last > 0 && typeof arguments[last] === "function") {
1972
+ fn = arguments[last];
1973
+ if (!true) {
1974
+ if (last <= 8 && canEvaluate) {
1975
+ var ret = new Promise(INTERNAL);
1976
+ ret._captureStackTrace();
1977
+ var HolderClass = holderClasses[last - 1];
1978
+ var holder = new HolderClass(fn);
1979
+ var callbacks = thenCallbacks;
1980
+
1981
+ for (var i = 0; i < last; ++i) {
1982
+ var maybePromise = tryConvertToPromise(arguments[i], ret);
1983
+ if (maybePromise instanceof Promise) {
1984
+ maybePromise = maybePromise._target();
1985
+ var bitField = maybePromise._bitField;
1986
+ ;
1987
+ if (((bitField & 50397184) === 0)) {
1988
+ maybePromise._then(callbacks[i], reject,
1989
+ undefined, ret, holder);
1990
+ promiseSetters[i](maybePromise, holder);
1991
+ holder.asyncNeeded = false;
1992
+ } else if (((bitField & 33554432) !== 0)) {
1993
+ callbacks[i].call(ret,
1994
+ maybePromise._value(), holder);
1995
+ } else if (((bitField & 16777216) !== 0)) {
1996
+ ret._reject(maybePromise._reason());
1997
+ } else {
1998
+ ret._cancel();
1999
+ }
2000
+ } else {
2001
+ callbacks[i].call(ret, maybePromise, holder);
2002
+ }
2003
+ }
2004
+
2005
+ if (!ret._isFateSealed()) {
2006
+ if (holder.asyncNeeded) {
2007
+ var domain = getDomain();
2008
+ if (domain !== null) {
2009
+ holder.fn = util.domainBind(domain, holder.fn);
2010
+ }
2011
+ }
2012
+ ret._setAsyncGuaranteed();
2013
+ ret._setOnCancel(holder);
2014
+ }
2015
+ return ret;
2016
+ }
2017
+ }
2018
+ }
2019
+ var args = [].slice.call(arguments);;
2020
+ if (fn) args.pop();
2021
+ var ret = new PromiseArray(args).promise();
2022
+ return fn !== undefined ? ret.spread(fn) : ret;
2023
+ };
2024
+
2025
+ };
2026
+
2027
+ },{"./util":21}],13:[function(_dereq_,module,exports){
2028
+ "use strict";
2029
+ module.exports =
2030
+ function(Promise, INTERNAL, tryConvertToPromise, apiRejection, debug) {
2031
+ var util = _dereq_("./util");
2032
+ var tryCatch = util.tryCatch;
2033
+
2034
+ Promise.method = function (fn) {
2035
+ if (typeof fn !== "function") {
2036
+ throw new Promise.TypeError("expecting a function but got " + util.classString(fn));
2037
+ }
2038
+ return function () {
2039
+ var ret = new Promise(INTERNAL);
2040
+ ret._captureStackTrace();
2041
+ ret._pushContext();
2042
+ var value = tryCatch(fn).apply(this, arguments);
2043
+ var promiseCreated = ret._popContext();
2044
+ debug.checkForgottenReturns(
2045
+ value, promiseCreated, "Promise.method", ret);
2046
+ ret._resolveFromSyncValue(value);
2047
+ return ret;
2048
+ };
2049
+ };
2050
+
2051
+ Promise.attempt = Promise["try"] = function (fn) {
2052
+ if (typeof fn !== "function") {
2053
+ return apiRejection("expecting a function but got " + util.classString(fn));
2054
+ }
2055
+ var ret = new Promise(INTERNAL);
2056
+ ret._captureStackTrace();
2057
+ ret._pushContext();
2058
+ var value;
2059
+ if (arguments.length > 1) {
2060
+ debug.deprecated("calling Promise.try with more than 1 argument");
2061
+ var arg = arguments[1];
2062
+ var ctx = arguments[2];
2063
+ value = util.isArray(arg) ? tryCatch(fn).apply(ctx, arg)
2064
+ : tryCatch(fn).call(ctx, arg);
2065
+ } else {
2066
+ value = tryCatch(fn)();
2067
+ }
2068
+ var promiseCreated = ret._popContext();
2069
+ debug.checkForgottenReturns(
2070
+ value, promiseCreated, "Promise.try", ret);
2071
+ ret._resolveFromSyncValue(value);
2072
+ return ret;
2073
+ };
2074
+
2075
+ Promise.prototype._resolveFromSyncValue = function (value) {
2076
+ if (value === util.errorObj) {
2077
+ this._rejectCallback(value.e, false);
2078
+ } else {
2079
+ this._resolveCallback(value, true);
2080
+ }
2081
+ };
2082
+ };
2083
+
2084
+ },{"./util":21}],14:[function(_dereq_,module,exports){
2085
+ "use strict";
2086
+ var util = _dereq_("./util");
2087
+ var maybeWrapAsError = util.maybeWrapAsError;
2088
+ var errors = _dereq_("./errors");
2089
+ var OperationalError = errors.OperationalError;
2090
+ var es5 = _dereq_("./es5");
2091
+
2092
+ function isUntypedError(obj) {
2093
+ return obj instanceof Error &&
2094
+ es5.getPrototypeOf(obj) === Error.prototype;
2095
+ }
2096
+
2097
+ var rErrorKey = /^(?:name|message|stack|cause)$/;
2098
+ function wrapAsOperationalError(obj) {
2099
+ var ret;
2100
+ if (isUntypedError(obj)) {
2101
+ ret = new OperationalError(obj);
2102
+ ret.name = obj.name;
2103
+ ret.message = obj.message;
2104
+ ret.stack = obj.stack;
2105
+ var keys = es5.keys(obj);
2106
+ for (var i = 0; i < keys.length; ++i) {
2107
+ var key = keys[i];
2108
+ if (!rErrorKey.test(key)) {
2109
+ ret[key] = obj[key];
2110
+ }
2111
+ }
2112
+ return ret;
2113
+ }
2114
+ util.markAsOriginatingFromRejection(obj);
2115
+ return obj;
2116
+ }
2117
+
2118
+ function nodebackForPromise(promise, multiArgs) {
2119
+ return function(err, value) {
2120
+ if (promise === null) return;
2121
+ if (err) {
2122
+ var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
2123
+ promise._attachExtraTrace(wrapped);
2124
+ promise._reject(wrapped);
2125
+ } else if (!multiArgs) {
2126
+ promise._fulfill(value);
2127
+ } else {
2128
+ var args = [].slice.call(arguments, 1);;
2129
+ promise._fulfill(args);
2130
+ }
2131
+ promise = null;
2132
+ };
2133
+ }
2134
+
2135
+ module.exports = nodebackForPromise;
2136
+
2137
+ },{"./errors":9,"./es5":10,"./util":21}],15:[function(_dereq_,module,exports){
2138
+ "use strict";
2139
+ module.exports = function() {
2140
+ var makeSelfResolutionError = function () {
2141
+ return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/MqrFmX\u000a");
2142
+ };
2143
+ var reflectHandler = function() {
2144
+ return new Promise.PromiseInspection(this._target());
2145
+ };
2146
+ var apiRejection = function(msg) {
2147
+ return Promise.reject(new TypeError(msg));
2148
+ };
2149
+ function Proxyable() {}
2150
+ var UNDEFINED_BINDING = {};
2151
+ var util = _dereq_("./util");
2152
+
2153
+ var getDomain;
2154
+ if (util.isNode) {
2155
+ getDomain = function() {
2156
+ var ret = process.domain;
2157
+ if (ret === undefined) ret = null;
2158
+ return ret;
2159
+ };
2160
+ } else {
2161
+ getDomain = function() {
2162
+ return null;
2163
+ };
2164
+ }
2165
+ util.notEnumerableProp(Promise, "_getDomain", getDomain);
2166
+
2167
+ var es5 = _dereq_("./es5");
2168
+ var Async = _dereq_("./async");
2169
+ var async = new Async();
2170
+ es5.defineProperty(Promise, "_async", {value: async});
2171
+ var errors = _dereq_("./errors");
2172
+ var TypeError = Promise.TypeError = errors.TypeError;
2173
+ Promise.RangeError = errors.RangeError;
2174
+ var CancellationError = Promise.CancellationError = errors.CancellationError;
2175
+ Promise.TimeoutError = errors.TimeoutError;
2176
+ Promise.OperationalError = errors.OperationalError;
2177
+ Promise.RejectionError = errors.OperationalError;
2178
+ Promise.AggregateError = errors.AggregateError;
2179
+ var INTERNAL = function(){};
2180
+ var APPLY = {};
2181
+ var NEXT_FILTER = {};
2182
+ var tryConvertToPromise = _dereq_("./thenables")(Promise, INTERNAL);
2183
+ var PromiseArray =
2184
+ _dereq_("./promise_array")(Promise, INTERNAL,
2185
+ tryConvertToPromise, apiRejection, Proxyable);
2186
+ var Context = _dereq_("./context")(Promise);
2187
+ /*jshint unused:false*/
2188
+ var createContext = Context.create;
2189
+ var debug = _dereq_("./debuggability")(Promise, Context);
2190
+ var CapturedTrace = debug.CapturedTrace;
2191
+ var PassThroughHandlerContext =
2192
+ _dereq_("./finally")(Promise, tryConvertToPromise, NEXT_FILTER);
2193
+ var catchFilter = _dereq_("./catch_filter")(NEXT_FILTER);
2194
+ var nodebackForPromise = _dereq_("./nodeback");
2195
+ var errorObj = util.errorObj;
2196
+ var tryCatch = util.tryCatch;
2197
+ function check(self, executor) {
2198
+ if (self == null || self.constructor !== Promise) {
2199
+ throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/MqrFmX\u000a");
2200
+ }
2201
+ if (typeof executor !== "function") {
2202
+ throw new TypeError("expecting a function but got " + util.classString(executor));
2203
+ }
2204
+
2205
+ }
2206
+
2207
+ function Promise(executor) {
2208
+ if (executor !== INTERNAL) {
2209
+ check(this, executor);
2210
+ }
2211
+ this._bitField = 0;
2212
+ this._fulfillmentHandler0 = undefined;
2213
+ this._rejectionHandler0 = undefined;
2214
+ this._promise0 = undefined;
2215
+ this._receiver0 = undefined;
2216
+ this._resolveFromExecutor(executor);
2217
+ this._promiseCreated();
2218
+ this._fireEvent("promiseCreated", this);
2219
+ }
2220
+
2221
+ Promise.prototype.toString = function () {
2222
+ return "[object Promise]";
2223
+ };
2224
+
2225
+ Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
2226
+ var len = arguments.length;
2227
+ if (len > 1) {
2228
+ var catchInstances = new Array(len - 1),
2229
+ j = 0, i;
2230
+ for (i = 0; i < len - 1; ++i) {
2231
+ var item = arguments[i];
2232
+ if (util.isObject(item)) {
2233
+ catchInstances[j++] = item;
2234
+ } else {
2235
+ return apiRejection("Catch statement predicate: " +
2236
+ "expecting an object but got " + util.classString(item));
2237
+ }
2238
+ }
2239
+ catchInstances.length = j;
2240
+ fn = arguments[i];
2241
+
2242
+ if (typeof fn !== "function") {
2243
+ throw new TypeError("The last argument to .catch() " +
2244
+ "must be a function, got " + util.toString(fn));
2245
+ }
2246
+ return this.then(undefined, catchFilter(catchInstances, fn, this));
2247
+ }
2248
+ return this.then(undefined, fn);
2249
+ };
2250
+
2251
+ Promise.prototype.reflect = function () {
2252
+ return this._then(reflectHandler,
2253
+ reflectHandler, undefined, this, undefined);
2254
+ };
2255
+
2256
+ Promise.prototype.then = function (didFulfill, didReject) {
2257
+ if (debug.warnings() && arguments.length > 0 &&
2258
+ typeof didFulfill !== "function" &&
2259
+ typeof didReject !== "function") {
2260
+ var msg = ".then() only accepts functions but was passed: " +
2261
+ util.classString(didFulfill);
2262
+ if (arguments.length > 1) {
2263
+ msg += ", " + util.classString(didReject);
2264
+ }
2265
+ this._warn(msg);
2266
+ }
2267
+ return this._then(didFulfill, didReject, undefined, undefined, undefined);
2268
+ };
2269
+
2270
+ Promise.prototype.done = function (didFulfill, didReject) {
2271
+ var promise =
2272
+ this._then(didFulfill, didReject, undefined, undefined, undefined);
2273
+ promise._setIsFinal();
2274
+ };
2275
+
2276
+ Promise.prototype.spread = function (fn) {
2277
+ if (typeof fn !== "function") {
2278
+ return apiRejection("expecting a function but got " + util.classString(fn));
2279
+ }
2280
+ return this.all()._then(fn, undefined, undefined, APPLY, undefined);
2281
+ };
2282
+
2283
+ Promise.prototype.toJSON = function () {
2284
+ var ret = {
2285
+ isFulfilled: false,
2286
+ isRejected: false,
2287
+ fulfillmentValue: undefined,
2288
+ rejectionReason: undefined
2289
+ };
2290
+ if (this.isFulfilled()) {
2291
+ ret.fulfillmentValue = this.value();
2292
+ ret.isFulfilled = true;
2293
+ } else if (this.isRejected()) {
2294
+ ret.rejectionReason = this.reason();
2295
+ ret.isRejected = true;
2296
+ }
2297
+ return ret;
2298
+ };
2299
+
2300
+ Promise.prototype.all = function () {
2301
+ if (arguments.length > 0) {
2302
+ this._warn(".all() was passed arguments but it does not take any");
2303
+ }
2304
+ return new PromiseArray(this).promise();
2305
+ };
2306
+
2307
+ Promise.prototype.error = function (fn) {
2308
+ return this.caught(util.originatesFromRejection, fn);
2309
+ };
2310
+
2311
+ Promise.getNewLibraryCopy = module.exports;
2312
+
2313
+ Promise.is = function (val) {
2314
+ return val instanceof Promise;
2315
+ };
2316
+
2317
+ Promise.fromNode = Promise.fromCallback = function(fn) {
2318
+ var ret = new Promise(INTERNAL);
2319
+ ret._captureStackTrace();
2320
+ var multiArgs = arguments.length > 1 ? !!Object(arguments[1]).multiArgs
2321
+ : false;
2322
+ var result = tryCatch(fn)(nodebackForPromise(ret, multiArgs));
2323
+ if (result === errorObj) {
2324
+ ret._rejectCallback(result.e, true);
2325
+ }
2326
+ if (!ret._isFateSealed()) ret._setAsyncGuaranteed();
2327
+ return ret;
2328
+ };
2329
+
2330
+ Promise.all = function (promises) {
2331
+ return new PromiseArray(promises).promise();
2332
+ };
2333
+
2334
+ Promise.cast = function (obj) {
2335
+ var ret = tryConvertToPromise(obj);
2336
+ if (!(ret instanceof Promise)) {
2337
+ ret = new Promise(INTERNAL);
2338
+ ret._captureStackTrace();
2339
+ ret._setFulfilled();
2340
+ ret._rejectionHandler0 = obj;
2341
+ }
2342
+ return ret;
2343
+ };
2344
+
2345
+ Promise.resolve = Promise.fulfilled = Promise.cast;
2346
+
2347
+ Promise.reject = Promise.rejected = function (reason) {
2348
+ var ret = new Promise(INTERNAL);
2349
+ ret._captureStackTrace();
2350
+ ret._rejectCallback(reason, true);
2351
+ return ret;
2352
+ };
2353
+
2354
+ Promise.setScheduler = function(fn) {
2355
+ if (typeof fn !== "function") {
2356
+ throw new TypeError("expecting a function but got " + util.classString(fn));
2357
+ }
2358
+ return async.setScheduler(fn);
2359
+ };
2360
+
2361
+ Promise.prototype._then = function (
2362
+ didFulfill,
2363
+ didReject,
2364
+ _, receiver,
2365
+ internalData
2366
+ ) {
2367
+ var haveInternalData = internalData !== undefined;
2368
+ var promise = haveInternalData ? internalData : new Promise(INTERNAL);
2369
+ var target = this._target();
2370
+ var bitField = target._bitField;
2371
+
2372
+ if (!haveInternalData) {
2373
+ promise._propagateFrom(this, 3);
2374
+ promise._captureStackTrace();
2375
+ if (receiver === undefined &&
2376
+ ((this._bitField & 2097152) !== 0)) {
2377
+ if (!((bitField & 50397184) === 0)) {
2378
+ receiver = this._boundValue();
2379
+ } else {
2380
+ receiver = target === this ? undefined : this._boundTo;
2381
+ }
2382
+ }
2383
+ this._fireEvent("promiseChained", this, promise);
2384
+ }
2385
+
2386
+ var domain = getDomain();
2387
+ if (!((bitField & 50397184) === 0)) {
2388
+ var handler, value, settler = target._settlePromiseCtx;
2389
+ if (((bitField & 33554432) !== 0)) {
2390
+ value = target._rejectionHandler0;
2391
+ handler = didFulfill;
2392
+ } else if (((bitField & 16777216) !== 0)) {
2393
+ value = target._fulfillmentHandler0;
2394
+ handler = didReject;
2395
+ target._unsetRejectionIsUnhandled();
2396
+ } else {
2397
+ settler = target._settlePromiseLateCancellationObserver;
2398
+ value = new CancellationError("late cancellation observer");
2399
+ target._attachExtraTrace(value);
2400
+ handler = didReject;
2401
+ }
2402
+
2403
+ async.invoke(settler, target, {
2404
+ handler: domain === null ? handler
2405
+ : (typeof handler === "function" &&
2406
+ util.domainBind(domain, handler)),
2407
+ promise: promise,
2408
+ receiver: receiver,
2409
+ value: value
2410
+ });
2411
+ } else {
2412
+ target._addCallbacks(didFulfill, didReject, promise, receiver, domain);
2413
+ }
2414
+
2415
+ return promise;
2416
+ };
2417
+
2418
+ Promise.prototype._length = function () {
2419
+ return this._bitField & 65535;
2420
+ };
2421
+
2422
+ Promise.prototype._isFateSealed = function () {
2423
+ return (this._bitField & 117506048) !== 0;
2424
+ };
2425
+
2426
+ Promise.prototype._isFollowing = function () {
2427
+ return (this._bitField & 67108864) === 67108864;
2428
+ };
2429
+
2430
+ Promise.prototype._setLength = function (len) {
2431
+ this._bitField = (this._bitField & -65536) |
2432
+ (len & 65535);
2433
+ };
2434
+
2435
+ Promise.prototype._setFulfilled = function () {
2436
+ this._bitField = this._bitField | 33554432;
2437
+ this._fireEvent("promiseFulfilled", this);
2438
+ };
2439
+
2440
+ Promise.prototype._setRejected = function () {
2441
+ this._bitField = this._bitField | 16777216;
2442
+ this._fireEvent("promiseRejected", this);
2443
+ };
2444
+
2445
+ Promise.prototype._setFollowing = function () {
2446
+ this._bitField = this._bitField | 67108864;
2447
+ this._fireEvent("promiseResolved", this);
2448
+ };
2449
+
2450
+ Promise.prototype._setIsFinal = function () {
2451
+ this._bitField = this._bitField | 4194304;
2452
+ };
2453
+
2454
+ Promise.prototype._isFinal = function () {
2455
+ return (this._bitField & 4194304) > 0;
2456
+ };
2457
+
2458
+ Promise.prototype._unsetCancelled = function() {
2459
+ this._bitField = this._bitField & (~65536);
2460
+ };
2461
+
2462
+ Promise.prototype._setCancelled = function() {
2463
+ this._bitField = this._bitField | 65536;
2464
+ this._fireEvent("promiseCancelled", this);
2465
+ };
2466
+
2467
+ Promise.prototype._setWillBeCancelled = function() {
2468
+ this._bitField = this._bitField | 8388608;
2469
+ };
2470
+
2471
+ Promise.prototype._setAsyncGuaranteed = function() {
2472
+ if (async.hasCustomScheduler()) return;
2473
+ this._bitField = this._bitField | 134217728;
2474
+ };
2475
+
2476
+ Promise.prototype._receiverAt = function (index) {
2477
+ var ret = index === 0 ? this._receiver0 : this[
2478
+ index * 4 - 4 + 3];
2479
+ if (ret === UNDEFINED_BINDING) {
2480
+ return undefined;
2481
+ } else if (ret === undefined && this._isBound()) {
2482
+ return this._boundValue();
2483
+ }
2484
+ return ret;
2485
+ };
2486
+
2487
+ Promise.prototype._promiseAt = function (index) {
2488
+ return this[
2489
+ index * 4 - 4 + 2];
2490
+ };
2491
+
2492
+ Promise.prototype._fulfillmentHandlerAt = function (index) {
2493
+ return this[
2494
+ index * 4 - 4 + 0];
2495
+ };
2496
+
2497
+ Promise.prototype._rejectionHandlerAt = function (index) {
2498
+ return this[
2499
+ index * 4 - 4 + 1];
2500
+ };
2501
+
2502
+ Promise.prototype._boundValue = function() {};
2503
+
2504
+ Promise.prototype._migrateCallback0 = function (follower) {
2505
+ var bitField = follower._bitField;
2506
+ var fulfill = follower._fulfillmentHandler0;
2507
+ var reject = follower._rejectionHandler0;
2508
+ var promise = follower._promise0;
2509
+ var receiver = follower._receiverAt(0);
2510
+ if (receiver === undefined) receiver = UNDEFINED_BINDING;
2511
+ this._addCallbacks(fulfill, reject, promise, receiver, null);
2512
+ };
2513
+
2514
+ Promise.prototype._migrateCallbackAt = function (follower, index) {
2515
+ var fulfill = follower._fulfillmentHandlerAt(index);
2516
+ var reject = follower._rejectionHandlerAt(index);
2517
+ var promise = follower._promiseAt(index);
2518
+ var receiver = follower._receiverAt(index);
2519
+ if (receiver === undefined) receiver = UNDEFINED_BINDING;
2520
+ this._addCallbacks(fulfill, reject, promise, receiver, null);
2521
+ };
2522
+
2523
+ Promise.prototype._addCallbacks = function (
2524
+ fulfill,
2525
+ reject,
2526
+ promise,
2527
+ receiver,
2528
+ domain
2529
+ ) {
2530
+ var index = this._length();
2531
+
2532
+ if (index >= 65535 - 4) {
2533
+ index = 0;
2534
+ this._setLength(0);
2535
+ }
2536
+
2537
+ if (index === 0) {
2538
+ this._promise0 = promise;
2539
+ this._receiver0 = receiver;
2540
+ if (typeof fulfill === "function") {
2541
+ this._fulfillmentHandler0 =
2542
+ domain === null ? fulfill : util.domainBind(domain, fulfill);
2543
+ }
2544
+ if (typeof reject === "function") {
2545
+ this._rejectionHandler0 =
2546
+ domain === null ? reject : util.domainBind(domain, reject);
2547
+ }
2548
+ } else {
2549
+ var base = index * 4 - 4;
2550
+ this[base + 2] = promise;
2551
+ this[base + 3] = receiver;
2552
+ if (typeof fulfill === "function") {
2553
+ this[base + 0] =
2554
+ domain === null ? fulfill : util.domainBind(domain, fulfill);
2555
+ }
2556
+ if (typeof reject === "function") {
2557
+ this[base + 1] =
2558
+ domain === null ? reject : util.domainBind(domain, reject);
2559
+ }
2560
+ }
2561
+ this._setLength(index + 1);
2562
+ return index;
2563
+ };
2564
+
2565
+ Promise.prototype._proxy = function (proxyable, arg) {
2566
+ this._addCallbacks(undefined, undefined, arg, proxyable, null);
2567
+ };
2568
+
2569
+ Promise.prototype._resolveCallback = function(value, shouldBind) {
2570
+ if (((this._bitField & 117506048) !== 0)) return;
2571
+ if (value === this)
2572
+ return this._rejectCallback(makeSelfResolutionError(), false);
2573
+ var maybePromise = tryConvertToPromise(value, this);
2574
+ if (!(maybePromise instanceof Promise)) return this._fulfill(value);
2575
+
2576
+ if (shouldBind) this._propagateFrom(maybePromise, 2);
2577
+
2578
+ var promise = maybePromise._target();
2579
+
2580
+ if (promise === this) {
2581
+ this._reject(makeSelfResolutionError());
2582
+ return;
2583
+ }
2584
+
2585
+ var bitField = promise._bitField;
2586
+ if (((bitField & 50397184) === 0)) {
2587
+ var len = this._length();
2588
+ if (len > 0) promise._migrateCallback0(this);
2589
+ for (var i = 1; i < len; ++i) {
2590
+ promise._migrateCallbackAt(this, i);
2591
+ }
2592
+ this._setFollowing();
2593
+ this._setLength(0);
2594
+ this._setFollowee(promise);
2595
+ } else if (((bitField & 33554432) !== 0)) {
2596
+ this._fulfill(promise._value());
2597
+ } else if (((bitField & 16777216) !== 0)) {
2598
+ this._reject(promise._reason());
2599
+ } else {
2600
+ var reason = new CancellationError("late cancellation observer");
2601
+ promise._attachExtraTrace(reason);
2602
+ this._reject(reason);
2603
+ }
2604
+ };
2605
+
2606
+ Promise.prototype._rejectCallback =
2607
+ function(reason, synchronous, ignoreNonErrorWarnings) {
2608
+ var trace = util.ensureErrorObject(reason);
2609
+ var hasStack = trace === reason;
2610
+ if (!hasStack && !ignoreNonErrorWarnings && debug.warnings()) {
2611
+ var message = "a promise was rejected with a non-error: " +
2612
+ util.classString(reason);
2613
+ this._warn(message, true);
2614
+ }
2615
+ this._attachExtraTrace(trace, synchronous ? hasStack : false);
2616
+ this._reject(reason);
2617
+ };
2618
+
2619
+ Promise.prototype._resolveFromExecutor = function (executor) {
2620
+ if (executor === INTERNAL) return;
2621
+ var promise = this;
2622
+ this._captureStackTrace();
2623
+ this._pushContext();
2624
+ var synchronous = true;
2625
+ var r = this._execute(executor, function(value) {
2626
+ promise._resolveCallback(value);
2627
+ }, function (reason) {
2628
+ promise._rejectCallback(reason, synchronous);
2629
+ });
2630
+ synchronous = false;
2631
+ this._popContext();
2632
+
2633
+ if (r !== undefined) {
2634
+ promise._rejectCallback(r, true);
2635
+ }
2636
+ };
2637
+
2638
+ Promise.prototype._settlePromiseFromHandler = function (
2639
+ handler, receiver, value, promise
2640
+ ) {
2641
+ var bitField = promise._bitField;
2642
+ if (((bitField & 65536) !== 0)) return;
2643
+ promise._pushContext();
2644
+ var x;
2645
+ if (receiver === APPLY) {
2646
+ if (!value || typeof value.length !== "number") {
2647
+ x = errorObj;
2648
+ x.e = new TypeError("cannot .spread() a non-array: " +
2649
+ util.classString(value));
2650
+ } else {
2651
+ x = tryCatch(handler).apply(this._boundValue(), value);
2652
+ }
2653
+ } else {
2654
+ x = tryCatch(handler).call(receiver, value);
2655
+ }
2656
+ var promiseCreated = promise._popContext();
2657
+ bitField = promise._bitField;
2658
+ if (((bitField & 65536) !== 0)) return;
2659
+
2660
+ if (x === NEXT_FILTER) {
2661
+ promise._reject(value);
2662
+ } else if (x === errorObj) {
2663
+ promise._rejectCallback(x.e, false);
2664
+ } else {
2665
+ debug.checkForgottenReturns(x, promiseCreated, "", promise, this);
2666
+ promise._resolveCallback(x);
2667
+ }
2668
+ };
2669
+
2670
+ Promise.prototype._target = function() {
2671
+ var ret = this;
2672
+ while (ret._isFollowing()) ret = ret._followee();
2673
+ return ret;
2674
+ };
2675
+
2676
+ Promise.prototype._followee = function() {
2677
+ return this._rejectionHandler0;
2678
+ };
2679
+
2680
+ Promise.prototype._setFollowee = function(promise) {
2681
+ this._rejectionHandler0 = promise;
2682
+ };
2683
+
2684
+ Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
2685
+ var isPromise = promise instanceof Promise;
2686
+ var bitField = this._bitField;
2687
+ var asyncGuaranteed = ((bitField & 134217728) !== 0);
2688
+ if (((bitField & 65536) !== 0)) {
2689
+ if (isPromise) promise._invokeInternalOnCancel();
2690
+
2691
+ if (receiver instanceof PassThroughHandlerContext &&
2692
+ receiver.isFinallyHandler()) {
2693
+ receiver.cancelPromise = promise;
2694
+ if (tryCatch(handler).call(receiver, value) === errorObj) {
2695
+ promise._reject(errorObj.e);
2696
+ }
2697
+ } else if (handler === reflectHandler) {
2698
+ promise._fulfill(reflectHandler.call(receiver));
2699
+ } else if (receiver instanceof Proxyable) {
2700
+ receiver._promiseCancelled(promise);
2701
+ } else if (isPromise || promise instanceof PromiseArray) {
2702
+ promise._cancel();
2703
+ } else {
2704
+ receiver.cancel();
2705
+ }
2706
+ } else if (typeof handler === "function") {
2707
+ if (!isPromise) {
2708
+ handler.call(receiver, value, promise);
2709
+ } else {
2710
+ if (asyncGuaranteed) promise._setAsyncGuaranteed();
2711
+ this._settlePromiseFromHandler(handler, receiver, value, promise);
2712
+ }
2713
+ } else if (receiver instanceof Proxyable) {
2714
+ if (!receiver._isResolved()) {
2715
+ if (((bitField & 33554432) !== 0)) {
2716
+ receiver._promiseFulfilled(value, promise);
2717
+ } else {
2718
+ receiver._promiseRejected(value, promise);
2719
+ }
2720
+ }
2721
+ } else if (isPromise) {
2722
+ if (asyncGuaranteed) promise._setAsyncGuaranteed();
2723
+ if (((bitField & 33554432) !== 0)) {
2724
+ promise._fulfill(value);
2725
+ } else {
2726
+ promise._reject(value);
2727
+ }
2728
+ }
2729
+ };
2730
+
2731
+ Promise.prototype._settlePromiseLateCancellationObserver = function(ctx) {
2732
+ var handler = ctx.handler;
2733
+ var promise = ctx.promise;
2734
+ var receiver = ctx.receiver;
2735
+ var value = ctx.value;
2736
+ if (typeof handler === "function") {
2737
+ if (!(promise instanceof Promise)) {
2738
+ handler.call(receiver, value, promise);
2739
+ } else {
2740
+ this._settlePromiseFromHandler(handler, receiver, value, promise);
2741
+ }
2742
+ } else if (promise instanceof Promise) {
2743
+ promise._reject(value);
2744
+ }
2745
+ };
2746
+
2747
+ Promise.prototype._settlePromiseCtx = function(ctx) {
2748
+ this._settlePromise(ctx.promise, ctx.handler, ctx.receiver, ctx.value);
2749
+ };
2750
+
2751
+ Promise.prototype._settlePromise0 = function(handler, value, bitField) {
2752
+ var promise = this._promise0;
2753
+ var receiver = this._receiverAt(0);
2754
+ this._promise0 = undefined;
2755
+ this._receiver0 = undefined;
2756
+ this._settlePromise(promise, handler, receiver, value);
2757
+ };
2758
+
2759
+ Promise.prototype._clearCallbackDataAtIndex = function(index) {
2760
+ var base = index * 4 - 4;
2761
+ this[base + 2] =
2762
+ this[base + 3] =
2763
+ this[base + 0] =
2764
+ this[base + 1] = undefined;
2765
+ };
2766
+
2767
+ Promise.prototype._fulfill = function (value) {
2768
+ var bitField = this._bitField;
2769
+ if (((bitField & 117506048) >>> 16)) return;
2770
+ if (value === this) {
2771
+ var err = makeSelfResolutionError();
2772
+ this._attachExtraTrace(err);
2773
+ return this._reject(err);
2774
+ }
2775
+ this._setFulfilled();
2776
+ this._rejectionHandler0 = value;
2777
+
2778
+ if ((bitField & 65535) > 0) {
2779
+ if (((bitField & 134217728) !== 0)) {
2780
+ this._settlePromises();
2781
+ } else {
2782
+ async.settlePromises(this);
2783
+ }
2784
+ this._dereferenceTrace();
2785
+ }
2786
+ };
2787
+
2788
+ Promise.prototype._reject = function (reason) {
2789
+ var bitField = this._bitField;
2790
+ if (((bitField & 117506048) >>> 16)) return;
2791
+ this._setRejected();
2792
+ this._fulfillmentHandler0 = reason;
2793
+
2794
+ if (this._isFinal()) {
2795
+ return async.fatalError(reason, util.isNode);
2796
+ }
2797
+
2798
+ if ((bitField & 65535) > 0) {
2799
+ async.settlePromises(this);
2800
+ } else {
2801
+ this._ensurePossibleRejectionHandled();
2802
+ }
2803
+ };
2804
+
2805
+ Promise.prototype._fulfillPromises = function (len, value) {
2806
+ for (var i = 1; i < len; i++) {
2807
+ var handler = this._fulfillmentHandlerAt(i);
2808
+ var promise = this._promiseAt(i);
2809
+ var receiver = this._receiverAt(i);
2810
+ this._clearCallbackDataAtIndex(i);
2811
+ this._settlePromise(promise, handler, receiver, value);
2812
+ }
2813
+ };
2814
+
2815
+ Promise.prototype._rejectPromises = function (len, reason) {
2816
+ for (var i = 1; i < len; i++) {
2817
+ var handler = this._rejectionHandlerAt(i);
2818
+ var promise = this._promiseAt(i);
2819
+ var receiver = this._receiverAt(i);
2820
+ this._clearCallbackDataAtIndex(i);
2821
+ this._settlePromise(promise, handler, receiver, reason);
2822
+ }
2823
+ };
2824
+
2825
+ Promise.prototype._settlePromises = function () {
2826
+ var bitField = this._bitField;
2827
+ var len = (bitField & 65535);
2828
+
2829
+ if (len > 0) {
2830
+ if (((bitField & 16842752) !== 0)) {
2831
+ var reason = this._fulfillmentHandler0;
2832
+ this._settlePromise0(this._rejectionHandler0, reason, bitField);
2833
+ this._rejectPromises(len, reason);
2834
+ } else {
2835
+ var value = this._rejectionHandler0;
2836
+ this._settlePromise0(this._fulfillmentHandler0, value, bitField);
2837
+ this._fulfillPromises(len, value);
2838
+ }
2839
+ this._setLength(0);
2840
+ }
2841
+ this._clearCancellationData();
2842
+ };
2843
+
2844
+ Promise.prototype._settledValue = function() {
2845
+ var bitField = this._bitField;
2846
+ if (((bitField & 33554432) !== 0)) {
2847
+ return this._rejectionHandler0;
2848
+ } else if (((bitField & 16777216) !== 0)) {
2849
+ return this._fulfillmentHandler0;
2850
+ }
2851
+ };
2852
+
2853
+ if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
2854
+ es5.defineProperty(Promise.prototype, Symbol.toStringTag, {
2855
+ get: function () {
2856
+ return "Object";
2857
+ }
2858
+ });
2859
+ }
2860
+
2861
+ function deferResolve(v) {this.promise._resolveCallback(v);}
2862
+ function deferReject(v) {this.promise._rejectCallback(v, false);}
2863
+
2864
+ Promise.defer = Promise.pending = function() {
2865
+ debug.deprecated("Promise.defer", "new Promise");
2866
+ var promise = new Promise(INTERNAL);
2867
+ return {
2868
+ promise: promise,
2869
+ resolve: deferResolve,
2870
+ reject: deferReject
2871
+ };
2872
+ };
2873
+
2874
+ util.notEnumerableProp(Promise,
2875
+ "_makeSelfResolutionError",
2876
+ makeSelfResolutionError);
2877
+
2878
+ _dereq_("./method")(Promise, INTERNAL, tryConvertToPromise, apiRejection,
2879
+ debug);
2880
+ _dereq_("./bind")(Promise, INTERNAL, tryConvertToPromise, debug);
2881
+ _dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug);
2882
+ _dereq_("./direct_resolve")(Promise);
2883
+ _dereq_("./synchronous_inspection")(Promise);
2884
+ _dereq_("./join")(
2885
+ Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain);
2886
+ Promise.Promise = Promise;
2887
+ Promise.version = "3.5.5";
2888
+
2889
+ util.toFastProperties(Promise);
2890
+ util.toFastProperties(Promise.prototype);
2891
+ function fillTypes(value) {
2892
+ var p = new Promise(INTERNAL);
2893
+ p._fulfillmentHandler0 = value;
2894
+ p._rejectionHandler0 = value;
2895
+ p._promise0 = value;
2896
+ p._receiver0 = value;
2897
+ }
2898
+ // Complete slack tracking, opt out of field-type tracking and
2899
+ // stabilize map
2900
+ fillTypes({a: 1});
2901
+ fillTypes({b: 2});
2902
+ fillTypes({c: 3});
2903
+ fillTypes(1);
2904
+ fillTypes(function(){});
2905
+ fillTypes(undefined);
2906
+ fillTypes(false);
2907
+ fillTypes(new Promise(INTERNAL));
2908
+ debug.setBounds(Async.firstLineError, util.lastLineError);
2909
+ return Promise;
2910
+
2911
+ };
2912
+
2913
+ },{"./async":1,"./bind":2,"./cancel":4,"./catch_filter":5,"./context":6,"./debuggability":7,"./direct_resolve":8,"./errors":9,"./es5":10,"./finally":11,"./join":12,"./method":13,"./nodeback":14,"./promise_array":16,"./synchronous_inspection":19,"./thenables":20,"./util":21}],16:[function(_dereq_,module,exports){
2914
+ "use strict";
2915
+ module.exports = function(Promise, INTERNAL, tryConvertToPromise,
2916
+ apiRejection, Proxyable) {
2917
+ var util = _dereq_("./util");
2918
+ var isArray = util.isArray;
2919
+
2920
+ function toResolutionValue(val) {
2921
+ switch(val) {
2922
+ case -2: return [];
2923
+ case -3: return {};
2924
+ case -6: return new Map();
2925
+ }
2926
+ }
2927
+
2928
+ function PromiseArray(values) {
2929
+ var promise = this._promise = new Promise(INTERNAL);
2930
+ if (values instanceof Promise) {
2931
+ promise._propagateFrom(values, 3);
2932
+ }
2933
+ promise._setOnCancel(this);
2934
+ this._values = values;
2935
+ this._length = 0;
2936
+ this._totalResolved = 0;
2937
+ this._init(undefined, -2);
2938
+ }
2939
+ util.inherits(PromiseArray, Proxyable);
2940
+
2941
+ PromiseArray.prototype.length = function () {
2942
+ return this._length;
2943
+ };
2944
+
2945
+ PromiseArray.prototype.promise = function () {
2946
+ return this._promise;
2947
+ };
2948
+
2949
+ PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
2950
+ var values = tryConvertToPromise(this._values, this._promise);
2951
+ if (values instanceof Promise) {
2952
+ values = values._target();
2953
+ var bitField = values._bitField;
2954
+ ;
2955
+ this._values = values;
2956
+
2957
+ if (((bitField & 50397184) === 0)) {
2958
+ this._promise._setAsyncGuaranteed();
2959
+ return values._then(
2960
+ init,
2961
+ this._reject,
2962
+ undefined,
2963
+ this,
2964
+ resolveValueIfEmpty
2965
+ );
2966
+ } else if (((bitField & 33554432) !== 0)) {
2967
+ values = values._value();
2968
+ } else if (((bitField & 16777216) !== 0)) {
2969
+ return this._reject(values._reason());
2970
+ } else {
2971
+ return this._cancel();
2972
+ }
2973
+ }
2974
+ values = util.asArray(values);
2975
+ if (values === null) {
2976
+ var err = apiRejection(
2977
+ "expecting an array or an iterable object but got " + util.classString(values)).reason();
2978
+ this._promise._rejectCallback(err, false);
2979
+ return;
2980
+ }
2981
+
2982
+ if (values.length === 0) {
2983
+ if (resolveValueIfEmpty === -5) {
2984
+ this._resolveEmptyArray();
2985
+ }
2986
+ else {
2987
+ this._resolve(toResolutionValue(resolveValueIfEmpty));
2988
+ }
2989
+ return;
2990
+ }
2991
+ this._iterate(values);
2992
+ };
2993
+
2994
+ PromiseArray.prototype._iterate = function(values) {
2995
+ var len = this.getActualLength(values.length);
2996
+ this._length = len;
2997
+ this._values = this.shouldCopyValues() ? new Array(len) : this._values;
2998
+ var result = this._promise;
2999
+ var isResolved = false;
3000
+ var bitField = null;
3001
+ for (var i = 0; i < len; ++i) {
3002
+ var maybePromise = tryConvertToPromise(values[i], result);
3003
+
3004
+ if (maybePromise instanceof Promise) {
3005
+ maybePromise = maybePromise._target();
3006
+ bitField = maybePromise._bitField;
3007
+ } else {
3008
+ bitField = null;
3009
+ }
3010
+
3011
+ if (isResolved) {
3012
+ if (bitField !== null) {
3013
+ maybePromise.suppressUnhandledRejections();
3014
+ }
3015
+ } else if (bitField !== null) {
3016
+ if (((bitField & 50397184) === 0)) {
3017
+ maybePromise._proxy(this, i);
3018
+ this._values[i] = maybePromise;
3019
+ } else if (((bitField & 33554432) !== 0)) {
3020
+ isResolved = this._promiseFulfilled(maybePromise._value(), i);
3021
+ } else if (((bitField & 16777216) !== 0)) {
3022
+ isResolved = this._promiseRejected(maybePromise._reason(), i);
3023
+ } else {
3024
+ isResolved = this._promiseCancelled(i);
3025
+ }
3026
+ } else {
3027
+ isResolved = this._promiseFulfilled(maybePromise, i);
3028
+ }
3029
+ }
3030
+ if (!isResolved) result._setAsyncGuaranteed();
3031
+ };
3032
+
3033
+ PromiseArray.prototype._isResolved = function () {
3034
+ return this._values === null;
3035
+ };
3036
+
3037
+ PromiseArray.prototype._resolve = function (value) {
3038
+ this._values = null;
3039
+ this._promise._fulfill(value);
3040
+ };
3041
+
3042
+ PromiseArray.prototype._cancel = function() {
3043
+ if (this._isResolved() || !this._promise._isCancellable()) return;
3044
+ this._values = null;
3045
+ this._promise._cancel();
3046
+ };
3047
+
3048
+ PromiseArray.prototype._reject = function (reason) {
3049
+ this._values = null;
3050
+ this._promise._rejectCallback(reason, false);
3051
+ };
3052
+
3053
+ PromiseArray.prototype._promiseFulfilled = function (value, index) {
3054
+ this._values[index] = value;
3055
+ var totalResolved = ++this._totalResolved;
3056
+ if (totalResolved >= this._length) {
3057
+ this._resolve(this._values);
3058
+ return true;
3059
+ }
3060
+ return false;
3061
+ };
3062
+
3063
+ PromiseArray.prototype._promiseCancelled = function() {
3064
+ this._cancel();
3065
+ return true;
3066
+ };
3067
+
3068
+ PromiseArray.prototype._promiseRejected = function (reason) {
3069
+ this._totalResolved++;
3070
+ this._reject(reason);
3071
+ return true;
3072
+ };
3073
+
3074
+ PromiseArray.prototype._resultCancelled = function() {
3075
+ if (this._isResolved()) return;
3076
+ var values = this._values;
3077
+ this._cancel();
3078
+ if (values instanceof Promise) {
3079
+ values.cancel();
3080
+ } else {
3081
+ for (var i = 0; i < values.length; ++i) {
3082
+ if (values[i] instanceof Promise) {
3083
+ values[i].cancel();
3084
+ }
3085
+ }
3086
+ }
3087
+ };
3088
+
3089
+ PromiseArray.prototype.shouldCopyValues = function () {
3090
+ return true;
3091
+ };
3092
+
3093
+ PromiseArray.prototype.getActualLength = function (len) {
3094
+ return len;
3095
+ };
3096
+
3097
+ return PromiseArray;
3098
+ };
3099
+
3100
+ },{"./util":21}],17:[function(_dereq_,module,exports){
3101
+ "use strict";
3102
+ function arrayMove(src, srcIndex, dst, dstIndex, len) {
3103
+ for (var j = 0; j < len; ++j) {
3104
+ dst[j + dstIndex] = src[j + srcIndex];
3105
+ src[j + srcIndex] = void 0;
3106
+ }
3107
+ }
3108
+
3109
+ function Queue(capacity) {
3110
+ this._capacity = capacity;
3111
+ this._length = 0;
3112
+ this._front = 0;
3113
+ }
3114
+
3115
+ Queue.prototype._willBeOverCapacity = function (size) {
3116
+ return this._capacity < size;
3117
+ };
3118
+
3119
+ Queue.prototype._pushOne = function (arg) {
3120
+ var length = this.length();
3121
+ this._checkCapacity(length + 1);
3122
+ var i = (this._front + length) & (this._capacity - 1);
3123
+ this[i] = arg;
3124
+ this._length = length + 1;
3125
+ };
3126
+
3127
+ Queue.prototype.push = function (fn, receiver, arg) {
3128
+ var length = this.length() + 3;
3129
+ if (this._willBeOverCapacity(length)) {
3130
+ this._pushOne(fn);
3131
+ this._pushOne(receiver);
3132
+ this._pushOne(arg);
3133
+ return;
3134
+ }
3135
+ var j = this._front + length - 3;
3136
+ this._checkCapacity(length);
3137
+ var wrapMask = this._capacity - 1;
3138
+ this[(j + 0) & wrapMask] = fn;
3139
+ this[(j + 1) & wrapMask] = receiver;
3140
+ this[(j + 2) & wrapMask] = arg;
3141
+ this._length = length;
3142
+ };
3143
+
3144
+ Queue.prototype.shift = function () {
3145
+ var front = this._front,
3146
+ ret = this[front];
3147
+
3148
+ this[front] = undefined;
3149
+ this._front = (front + 1) & (this._capacity - 1);
3150
+ this._length--;
3151
+ return ret;
3152
+ };
3153
+
3154
+ Queue.prototype.length = function () {
3155
+ return this._length;
3156
+ };
3157
+
3158
+ Queue.prototype._checkCapacity = function (size) {
3159
+ if (this._capacity < size) {
3160
+ this._resizeTo(this._capacity << 1);
3161
+ }
3162
+ };
3163
+
3164
+ Queue.prototype._resizeTo = function (capacity) {
3165
+ var oldCapacity = this._capacity;
3166
+ this._capacity = capacity;
3167
+ var front = this._front;
3168
+ var length = this._length;
3169
+ var moveItemsCount = (front + length) & (oldCapacity - 1);
3170
+ arrayMove(this, 0, this, oldCapacity, moveItemsCount);
3171
+ };
3172
+
3173
+ module.exports = Queue;
3174
+
3175
+ },{}],18:[function(_dereq_,module,exports){
3176
+ "use strict";
3177
+ var util = _dereq_("./util");
3178
+ var schedule;
3179
+ var noAsyncScheduler = function() {
3180
+ throw new Error("No async scheduler available\u000a\u000a See http://goo.gl/MqrFmX\u000a");
3181
+ };
3182
+ var NativePromise = util.getNativePromise();
3183
+ if (util.isNode && typeof MutationObserver === "undefined") {
3184
+ var GlobalSetImmediate = global.setImmediate;
3185
+ var ProcessNextTick = process.nextTick;
3186
+ schedule = util.isRecentNode
3187
+ ? function(fn) { GlobalSetImmediate.call(global, fn); }
3188
+ : function(fn) { ProcessNextTick.call(process, fn); };
3189
+ } else if (typeof NativePromise === "function" &&
3190
+ typeof NativePromise.resolve === "function") {
3191
+ var nativePromise = NativePromise.resolve();
3192
+ schedule = function(fn) {
3193
+ nativePromise.then(fn);
3194
+ };
3195
+ } else if ((typeof MutationObserver !== "undefined") &&
3196
+ !(typeof window !== "undefined" &&
3197
+ window.navigator &&
3198
+ (window.navigator.standalone || window.cordova)) &&
3199
+ ("classList" in document.documentElement)) {
3200
+ schedule = (function() {
3201
+ var div = document.createElement("div");
3202
+ var opts = {attributes: true};
3203
+ var toggleScheduled = false;
3204
+ var div2 = document.createElement("div");
3205
+ var o2 = new MutationObserver(function() {
3206
+ div.classList.toggle("foo");
3207
+ toggleScheduled = false;
3208
+ });
3209
+ o2.observe(div2, opts);
3210
+
3211
+ var scheduleToggle = function() {
3212
+ if (toggleScheduled) return;
3213
+ toggleScheduled = true;
3214
+ div2.classList.toggle("foo");
3215
+ };
3216
+
3217
+ return function schedule(fn) {
3218
+ var o = new MutationObserver(function() {
3219
+ o.disconnect();
3220
+ fn();
3221
+ });
3222
+ o.observe(div, opts);
3223
+ scheduleToggle();
3224
+ };
3225
+ })();
3226
+ } else if (typeof setImmediate !== "undefined") {
3227
+ schedule = function (fn) {
3228
+ setImmediate(fn);
3229
+ };
3230
+ } else if (typeof setTimeout !== "undefined") {
3231
+ schedule = function (fn) {
3232
+ setTimeout(fn, 0);
3233
+ };
3234
+ } else {
3235
+ schedule = noAsyncScheduler;
3236
+ }
3237
+ module.exports = schedule;
3238
+
3239
+ },{"./util":21}],19:[function(_dereq_,module,exports){
3240
+ "use strict";
3241
+ module.exports = function(Promise) {
3242
+ function PromiseInspection(promise) {
3243
+ if (promise !== undefined) {
3244
+ promise = promise._target();
3245
+ this._bitField = promise._bitField;
3246
+ this._settledValueField = promise._isFateSealed()
3247
+ ? promise._settledValue() : undefined;
3248
+ }
3249
+ else {
3250
+ this._bitField = 0;
3251
+ this._settledValueField = undefined;
3252
+ }
3253
+ }
3254
+
3255
+ PromiseInspection.prototype._settledValue = function() {
3256
+ return this._settledValueField;
3257
+ };
3258
+
3259
+ var value = PromiseInspection.prototype.value = function () {
3260
+ if (!this.isFulfilled()) {
3261
+ throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
3262
+ }
3263
+ return this._settledValue();
3264
+ };
3265
+
3266
+ var reason = PromiseInspection.prototype.error =
3267
+ PromiseInspection.prototype.reason = function () {
3268
+ if (!this.isRejected()) {
3269
+ throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/MqrFmX\u000a");
3270
+ }
3271
+ return this._settledValue();
3272
+ };
3273
+
3274
+ var isFulfilled = PromiseInspection.prototype.isFulfilled = function() {
3275
+ return (this._bitField & 33554432) !== 0;
3276
+ };
3277
+
3278
+ var isRejected = PromiseInspection.prototype.isRejected = function () {
3279
+ return (this._bitField & 16777216) !== 0;
3280
+ };
3281
+
3282
+ var isPending = PromiseInspection.prototype.isPending = function () {
3283
+ return (this._bitField & 50397184) === 0;
3284
+ };
3285
+
3286
+ var isResolved = PromiseInspection.prototype.isResolved = function () {
3287
+ return (this._bitField & 50331648) !== 0;
3288
+ };
3289
+
3290
+ PromiseInspection.prototype.isCancelled = function() {
3291
+ return (this._bitField & 8454144) !== 0;
3292
+ };
3293
+
3294
+ Promise.prototype.__isCancelled = function() {
3295
+ return (this._bitField & 65536) === 65536;
3296
+ };
3297
+
3298
+ Promise.prototype._isCancelled = function() {
3299
+ return this._target().__isCancelled();
3300
+ };
3301
+
3302
+ Promise.prototype.isCancelled = function() {
3303
+ return (this._target()._bitField & 8454144) !== 0;
3304
+ };
3305
+
3306
+ Promise.prototype.isPending = function() {
3307
+ return isPending.call(this._target());
3308
+ };
3309
+
3310
+ Promise.prototype.isRejected = function() {
3311
+ return isRejected.call(this._target());
3312
+ };
3313
+
3314
+ Promise.prototype.isFulfilled = function() {
3315
+ return isFulfilled.call(this._target());
3316
+ };
3317
+
3318
+ Promise.prototype.isResolved = function() {
3319
+ return isResolved.call(this._target());
3320
+ };
3321
+
3322
+ Promise.prototype.value = function() {
3323
+ return value.call(this._target());
3324
+ };
3325
+
3326
+ Promise.prototype.reason = function() {
3327
+ var target = this._target();
3328
+ target._unsetRejectionIsUnhandled();
3329
+ return reason.call(target);
3330
+ };
3331
+
3332
+ Promise.prototype._value = function() {
3333
+ return this._settledValue();
3334
+ };
3335
+
3336
+ Promise.prototype._reason = function() {
3337
+ this._unsetRejectionIsUnhandled();
3338
+ return this._settledValue();
3339
+ };
3340
+
3341
+ Promise.PromiseInspection = PromiseInspection;
3342
+ };
3343
+
3344
+ },{}],20:[function(_dereq_,module,exports){
3345
+ "use strict";
3346
+ module.exports = function(Promise, INTERNAL) {
3347
+ var util = _dereq_("./util");
3348
+ var errorObj = util.errorObj;
3349
+ var isObject = util.isObject;
3350
+
3351
+ function tryConvertToPromise(obj, context) {
3352
+ if (isObject(obj)) {
3353
+ if (obj instanceof Promise) return obj;
3354
+ var then = getThen(obj);
3355
+ if (then === errorObj) {
3356
+ if (context) context._pushContext();
3357
+ var ret = Promise.reject(then.e);
3358
+ if (context) context._popContext();
3359
+ return ret;
3360
+ } else if (typeof then === "function") {
3361
+ if (isAnyBluebirdPromise(obj)) {
3362
+ var ret = new Promise(INTERNAL);
3363
+ obj._then(
3364
+ ret._fulfill,
3365
+ ret._reject,
3366
+ undefined,
3367
+ ret,
3368
+ null
3369
+ );
3370
+ return ret;
3371
+ }
3372
+ return doThenable(obj, then, context);
3373
+ }
3374
+ }
3375
+ return obj;
3376
+ }
3377
+
3378
+ function doGetThen(obj) {
3379
+ return obj.then;
3380
+ }
3381
+
3382
+ function getThen(obj) {
3383
+ try {
3384
+ return doGetThen(obj);
3385
+ } catch (e) {
3386
+ errorObj.e = e;
3387
+ return errorObj;
3388
+ }
3389
+ }
3390
+
3391
+ var hasProp = {}.hasOwnProperty;
3392
+ function isAnyBluebirdPromise(obj) {
3393
+ try {
3394
+ return hasProp.call(obj, "_promise0");
3395
+ } catch (e) {
3396
+ return false;
3397
+ }
3398
+ }
3399
+
3400
+ function doThenable(x, then, context) {
3401
+ var promise = new Promise(INTERNAL);
3402
+ var ret = promise;
3403
+ if (context) context._pushContext();
3404
+ promise._captureStackTrace();
3405
+ if (context) context._popContext();
3406
+ var synchronous = true;
3407
+ var result = util.tryCatch(then).call(x, resolve, reject);
3408
+ synchronous = false;
3409
+
3410
+ if (promise && result === errorObj) {
3411
+ promise._rejectCallback(result.e, true, true);
3412
+ promise = null;
3413
+ }
3414
+
3415
+ function resolve(value) {
3416
+ if (!promise) return;
3417
+ promise._resolveCallback(value);
3418
+ promise = null;
3419
+ }
3420
+
3421
+ function reject(reason) {
3422
+ if (!promise) return;
3423
+ promise._rejectCallback(reason, synchronous, true);
3424
+ promise = null;
3425
+ }
3426
+ return ret;
3427
+ }
3428
+
3429
+ return tryConvertToPromise;
3430
+ };
3431
+
3432
+ },{"./util":21}],21:[function(_dereq_,module,exports){
3433
+ "use strict";
3434
+ var es5 = _dereq_("./es5");
3435
+ var canEvaluate = typeof navigator == "undefined";
3436
+
3437
+ var errorObj = {e: {}};
3438
+ var tryCatchTarget;
3439
+ var globalObject = typeof self !== "undefined" ? self :
3440
+ typeof window !== "undefined" ? window :
3441
+ typeof global !== "undefined" ? global :
3442
+ this !== undefined ? this : null;
3443
+
3444
+ function tryCatcher() {
3445
+ try {
3446
+ var target = tryCatchTarget;
3447
+ tryCatchTarget = null;
3448
+ return target.apply(this, arguments);
3449
+ } catch (e) {
3450
+ errorObj.e = e;
3451
+ return errorObj;
3452
+ }
3453
+ }
3454
+ function tryCatch(fn) {
3455
+ tryCatchTarget = fn;
3456
+ return tryCatcher;
3457
+ }
3458
+
3459
+ var inherits = function(Child, Parent) {
3460
+ var hasProp = {}.hasOwnProperty;
3461
+
3462
+ function T() {
3463
+ this.constructor = Child;
3464
+ this.constructor$ = Parent;
3465
+ for (var propertyName in Parent.prototype) {
3466
+ if (hasProp.call(Parent.prototype, propertyName) &&
3467
+ propertyName.charAt(propertyName.length-1) !== "$"
3468
+ ) {
3469
+ this[propertyName + "$"] = Parent.prototype[propertyName];
3470
+ }
3471
+ }
3472
+ }
3473
+ T.prototype = Parent.prototype;
3474
+ Child.prototype = new T();
3475
+ return Child.prototype;
3476
+ };
3477
+
3478
+
3479
+ function isPrimitive(val) {
3480
+ return val == null || val === true || val === false ||
3481
+ typeof val === "string" || typeof val === "number";
3482
+
3483
+ }
3484
+
3485
+ function isObject(value) {
3486
+ return typeof value === "function" ||
3487
+ typeof value === "object" && value !== null;
3488
+ }
3489
+
3490
+ function maybeWrapAsError(maybeError) {
3491
+ if (!isPrimitive(maybeError)) return maybeError;
3492
+
3493
+ return new Error(safeToString(maybeError));
3494
+ }
3495
+
3496
+ function withAppended(target, appendee) {
3497
+ var len = target.length;
3498
+ var ret = new Array(len + 1);
3499
+ var i;
3500
+ for (i = 0; i < len; ++i) {
3501
+ ret[i] = target[i];
3502
+ }
3503
+ ret[i] = appendee;
3504
+ return ret;
3505
+ }
3506
+
3507
+ function getDataPropertyOrDefault(obj, key, defaultValue) {
3508
+ if (es5.isES5) {
3509
+ var desc = Object.getOwnPropertyDescriptor(obj, key);
3510
+
3511
+ if (desc != null) {
3512
+ return desc.get == null && desc.set == null
3513
+ ? desc.value
3514
+ : defaultValue;
3515
+ }
3516
+ } else {
3517
+ return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
3518
+ }
3519
+ }
3520
+
3521
+ function notEnumerableProp(obj, name, value) {
3522
+ if (isPrimitive(obj)) return obj;
3523
+ var descriptor = {
3524
+ value: value,
3525
+ configurable: true,
3526
+ enumerable: false,
3527
+ writable: true
3528
+ };
3529
+ es5.defineProperty(obj, name, descriptor);
3530
+ return obj;
3531
+ }
3532
+
3533
+ function thrower(r) {
3534
+ throw r;
3535
+ }
3536
+
3537
+ var inheritedDataKeys = (function() {
3538
+ var excludedPrototypes = [
3539
+ Array.prototype,
3540
+ Object.prototype,
3541
+ Function.prototype
3542
+ ];
3543
+
3544
+ var isExcludedProto = function(val) {
3545
+ for (var i = 0; i < excludedPrototypes.length; ++i) {
3546
+ if (excludedPrototypes[i] === val) {
3547
+ return true;
3548
+ }
3549
+ }
3550
+ return false;
3551
+ };
3552
+
3553
+ if (es5.isES5) {
3554
+ var getKeys = Object.getOwnPropertyNames;
3555
+ return function(obj) {
3556
+ var ret = [];
3557
+ var visitedKeys = Object.create(null);
3558
+ while (obj != null && !isExcludedProto(obj)) {
3559
+ var keys;
3560
+ try {
3561
+ keys = getKeys(obj);
3562
+ } catch (e) {
3563
+ return ret;
3564
+ }
3565
+ for (var i = 0; i < keys.length; ++i) {
3566
+ var key = keys[i];
3567
+ if (visitedKeys[key]) continue;
3568
+ visitedKeys[key] = true;
3569
+ var desc = Object.getOwnPropertyDescriptor(obj, key);
3570
+ if (desc != null && desc.get == null && desc.set == null) {
3571
+ ret.push(key);
3572
+ }
3573
+ }
3574
+ obj = es5.getPrototypeOf(obj);
3575
+ }
3576
+ return ret;
3577
+ };
3578
+ } else {
3579
+ var hasProp = {}.hasOwnProperty;
3580
+ return function(obj) {
3581
+ if (isExcludedProto(obj)) return [];
3582
+ var ret = [];
3583
+
3584
+ /*jshint forin:false */
3585
+ enumeration: for (var key in obj) {
3586
+ if (hasProp.call(obj, key)) {
3587
+ ret.push(key);
3588
+ } else {
3589
+ for (var i = 0; i < excludedPrototypes.length; ++i) {
3590
+ if (hasProp.call(excludedPrototypes[i], key)) {
3591
+ continue enumeration;
3592
+ }
3593
+ }
3594
+ ret.push(key);
3595
+ }
3596
+ }
3597
+ return ret;
3598
+ };
3599
+ }
3600
+
3601
+ })();
3602
+
3603
+ var thisAssignmentPattern = /this\s*\.\s*\S+\s*=/;
3604
+ function isClass(fn) {
3605
+ try {
3606
+ if (typeof fn === "function") {
3607
+ var keys = es5.names(fn.prototype);
3608
+
3609
+ var hasMethods = es5.isES5 && keys.length > 1;
3610
+ var hasMethodsOtherThanConstructor = keys.length > 0 &&
3611
+ !(keys.length === 1 && keys[0] === "constructor");
3612
+ var hasThisAssignmentAndStaticMethods =
3613
+ thisAssignmentPattern.test(fn + "") && es5.names(fn).length > 0;
3614
+
3615
+ if (hasMethods || hasMethodsOtherThanConstructor ||
3616
+ hasThisAssignmentAndStaticMethods) {
3617
+ return true;
3618
+ }
3619
+ }
3620
+ return false;
3621
+ } catch (e) {
3622
+ return false;
3623
+ }
3624
+ }
3625
+
3626
+ function toFastProperties(obj) {
3627
+ /*jshint -W027,-W055,-W031*/
3628
+ function FakeConstructor() {}
3629
+ FakeConstructor.prototype = obj;
3630
+ var receiver = new FakeConstructor();
3631
+ function ic() {
3632
+ return typeof receiver.foo;
3633
+ }
3634
+ ic();
3635
+ ic();
3636
+ return obj;
3637
+ eval(obj);
3638
+ }
3639
+
3640
+ var rident = /^[a-z$_][a-z$_0-9]*$/i;
3641
+ function isIdentifier(str) {
3642
+ return rident.test(str);
3643
+ }
3644
+
3645
+ function filledRange(count, prefix, suffix) {
3646
+ var ret = new Array(count);
3647
+ for(var i = 0; i < count; ++i) {
3648
+ ret[i] = prefix + i + suffix;
3649
+ }
3650
+ return ret;
3651
+ }
3652
+
3653
+ function safeToString(obj) {
3654
+ try {
3655
+ return obj + "";
3656
+ } catch (e) {
3657
+ return "[no string representation]";
3658
+ }
3659
+ }
3660
+
3661
+ function isError(obj) {
3662
+ return obj instanceof Error ||
3663
+ (obj !== null &&
3664
+ typeof obj === "object" &&
3665
+ typeof obj.message === "string" &&
3666
+ typeof obj.name === "string");
3667
+ }
3668
+
3669
+ function markAsOriginatingFromRejection(e) {
3670
+ try {
3671
+ notEnumerableProp(e, "isOperational", true);
3672
+ }
3673
+ catch(ignore) {}
3674
+ }
3675
+
3676
+ function originatesFromRejection(e) {
3677
+ if (e == null) return false;
3678
+ return ((e instanceof Error["__BluebirdErrorTypes__"].OperationalError) ||
3679
+ e["isOperational"] === true);
3680
+ }
3681
+
3682
+ function canAttachTrace(obj) {
3683
+ return isError(obj) && es5.propertyIsWritable(obj, "stack");
3684
+ }
3685
+
3686
+ var ensureErrorObject = (function() {
3687
+ if (!("stack" in new Error())) {
3688
+ return function(value) {
3689
+ if (canAttachTrace(value)) return value;
3690
+ try {throw new Error(safeToString(value));}
3691
+ catch(err) {return err;}
3692
+ };
3693
+ } else {
3694
+ return function(value) {
3695
+ if (canAttachTrace(value)) return value;
3696
+ return new Error(safeToString(value));
3697
+ };
3698
+ }
3699
+ })();
3700
+
3701
+ function classString(obj) {
3702
+ return {}.toString.call(obj);
3703
+ }
3704
+
3705
+ function copyDescriptors(from, to, filter) {
3706
+ var keys = es5.names(from);
3707
+ for (var i = 0; i < keys.length; ++i) {
3708
+ var key = keys[i];
3709
+ if (filter(key)) {
3710
+ try {
3711
+ es5.defineProperty(to, key, es5.getDescriptor(from, key));
3712
+ } catch (ignore) {}
3713
+ }
3714
+ }
3715
+ }
3716
+
3717
+ var asArray = function(v) {
3718
+ if (es5.isArray(v)) {
3719
+ return v;
3720
+ }
3721
+ return null;
3722
+ };
3723
+
3724
+ if (typeof Symbol !== "undefined" && Symbol.iterator) {
3725
+ var ArrayFrom = typeof Array.from === "function" ? function(v) {
3726
+ return Array.from(v);
3727
+ } : function(v) {
3728
+ var ret = [];
3729
+ var it = v[Symbol.iterator]();
3730
+ var itResult;
3731
+ while (!((itResult = it.next()).done)) {
3732
+ ret.push(itResult.value);
3733
+ }
3734
+ return ret;
3735
+ };
3736
+
3737
+ asArray = function(v) {
3738
+ if (es5.isArray(v)) {
3739
+ return v;
3740
+ } else if (v != null && typeof v[Symbol.iterator] === "function") {
3741
+ return ArrayFrom(v);
3742
+ }
3743
+ return null;
3744
+ };
3745
+ }
3746
+
3747
+ var isNode = typeof process !== "undefined" &&
3748
+ classString(process).toLowerCase() === "[object process]";
3749
+
3750
+ var hasEnvVariables = typeof process !== "undefined" &&
3751
+ typeof process.env !== "undefined";
3752
+
3753
+ function env(key) {
3754
+ return hasEnvVariables ? process.env[key] : undefined;
3755
+ }
3756
+
3757
+ function getNativePromise() {
3758
+ if (typeof Promise === "function") {
3759
+ try {
3760
+ var promise = new Promise(function(){});
3761
+ if ({}.toString.call(promise) === "[object Promise]") {
3762
+ return Promise;
3763
+ }
3764
+ } catch (e) {}
3765
+ }
3766
+ }
3767
+
3768
+ function domainBind(self, cb) {
3769
+ return self.bind(cb);
3770
+ }
3771
+
3772
+ var ret = {
3773
+ isClass: isClass,
3774
+ isIdentifier: isIdentifier,
3775
+ inheritedDataKeys: inheritedDataKeys,
3776
+ getDataPropertyOrDefault: getDataPropertyOrDefault,
3777
+ thrower: thrower,
3778
+ isArray: es5.isArray,
3779
+ asArray: asArray,
3780
+ notEnumerableProp: notEnumerableProp,
3781
+ isPrimitive: isPrimitive,
3782
+ isObject: isObject,
3783
+ isError: isError,
3784
+ canEvaluate: canEvaluate,
3785
+ errorObj: errorObj,
3786
+ tryCatch: tryCatch,
3787
+ inherits: inherits,
3788
+ withAppended: withAppended,
3789
+ maybeWrapAsError: maybeWrapAsError,
3790
+ toFastProperties: toFastProperties,
3791
+ filledRange: filledRange,
3792
+ toString: safeToString,
3793
+ canAttachTrace: canAttachTrace,
3794
+ ensureErrorObject: ensureErrorObject,
3795
+ originatesFromRejection: originatesFromRejection,
3796
+ markAsOriginatingFromRejection: markAsOriginatingFromRejection,
3797
+ classString: classString,
3798
+ copyDescriptors: copyDescriptors,
3799
+ hasDevTools: typeof chrome !== "undefined" && chrome &&
3800
+ typeof chrome.loadTimes === "function",
3801
+ isNode: isNode,
3802
+ hasEnvVariables: hasEnvVariables,
3803
+ env: env,
3804
+ global: globalObject,
3805
+ getNativePromise: getNativePromise,
3806
+ domainBind: domainBind
3807
+ };
3808
+ ret.isRecentNode = ret.isNode && (function() {
3809
+ var version;
3810
+ if (process.versions && process.versions.node) {
3811
+ version = process.versions.node.split(".").map(Number);
3812
+ } else if (process.version) {
3813
+ version = process.version.split(".").map(Number);
3814
+ }
3815
+ return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
3816
+ })();
3817
+
3818
+ if (ret.isNode) ret.toFastProperties(process);
3819
+
3820
+ try {throw new Error(); } catch (e) {ret.lastLineError = e;}
3821
+ module.exports = ret;
3822
+
3823
+ },{"./es5":10}]},{},[3])(3)
3824
+ }); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }