proxy_chain_rb 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +16 -16
  3. data/README.md +14 -5
  4. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/.yarn-integrity +23 -0
  5. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/README.md +1 -1
  6. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +254 -121
  7. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +3 -3
  8. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +284 -129
  9. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +4 -4
  10. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/async.js +3 -48
  11. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +145 -27
  12. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/join.js +4 -7
  13. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/map.js +10 -3
  14. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/promise.js +58 -28
  15. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +1 -0
  16. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +16 -5
  17. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/settle.js +4 -0
  18. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/js/release/util.js +39 -7
  19. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/bluebird/package.json +39 -63
  20. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/commander/CHANGELOG.md +11 -0
  21. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/commander/index.js +1 -1
  22. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/commander/package.json +20 -52
  23. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/debug/package.json +21 -60
  24. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/ms/package.json +19 -51
  25. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +41 -66
  26. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/portastic/package.json +23 -51
  27. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +18 -0
  28. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/README.md +8 -0
  29. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +5 -0
  30. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +86 -53
  31. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +23 -5
  32. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +3 -7
  33. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +1 -1
  34. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/index.js +3 -5
  35. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/server.js +3 -1
  36. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +245 -115
  37. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel_tools.js +138 -0
  38. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/node_modules/.bin/portastic +1 -0
  39. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/package.json +41 -68
  40. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/underscore/package.json +27 -58
  41. data/lib/proxy_chain_rb/node_js/proxy-chain-server/package.json +1 -1
  42. data/lib/proxy_chain_rb/node_js/proxy-chain-server/server.js +4 -2
  43. data/lib/proxy_chain_rb/node_js/proxy-chain-server/yarn.lock +53 -0
  44. data/lib/proxy_chain_rb/server.rb +8 -6
  45. data/lib/proxy_chain_rb/version.rb +1 -1
  46. data/proxy_chain_rb.gemspec +3 -3
  47. metadata +16 -14
  48. data/lib/proxy_chain_rb/node_js/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +0 -271
  49. data/lib/proxy_chain_rb/node_js/proxy-chain-server/package-lock.json +0 -63
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91d2d7843a127e5c9c747073ec1252c992404f4c8c712c90c3cc184b7c1d01d3
4
- data.tar.gz: e904d88febd32941a1fbbb03af5651a7a0c570e2c59a3846c0595a0c5002a1aa
3
+ metadata.gz: 55b6d5dde00b20efaefe250ac9e11d121f276c43e8e44e848124f82cef1beded
4
+ data.tar.gz: af0252ba1d5d19fae9c1102b0333839b72ce93846d56bbbdb0ddaca9f74ed9e3
5
5
  SHA512:
6
- metadata.gz: 34e4025941cb259489fbe643ced2582f04288323cf25c3ec6bed5ff54d7c77fc12cbef73ff801287ababde21f60ab1a9e3e2d8f480abed2b6342a0a605b960fc
7
- data.tar.gz: ff0233ebca5230278d69e2949ba41367209e8fac7ad7537b4c0b5badb05180448510f2765c2f146e1c33c4c9832ea251f58a9beb808c91643751a39e49155276
6
+ metadata.gz: 6dadabb4980e437ecb5269b8ee37d44403bd0c2bec217051239e3d4db217a8ccb3b948d02b99e81eb573afaac9fc471fb35c76716dbce2218171c8cb7677b294
7
+ data.tar.gz: f7c899427644d5ecd1e41b1cbc22de8e93f45df0ede536595f9e25c5ad297d07f4db42bdcac260623590cf76278a440ec44ccc7aa631cf6090ff8a88df35b112
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- proxy_chain_rb (0.1.0)
4
+ proxy_chain_rb (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,30 +12,30 @@ GEM
12
12
  pry (0.12.2)
13
13
  coderay (~> 1.1.0)
14
14
  method_source (~> 0.9.0)
15
- rake (10.5.0)
16
- rspec (3.8.0)
17
- rspec-core (~> 3.8.0)
18
- rspec-expectations (~> 3.8.0)
19
- rspec-mocks (~> 3.8.0)
20
- rspec-core (3.8.2)
21
- rspec-support (~> 3.8.0)
22
- rspec-expectations (3.8.4)
15
+ rake (13.0.0)
16
+ rspec (3.9.0)
17
+ rspec-core (~> 3.9.0)
18
+ rspec-expectations (~> 3.9.0)
19
+ rspec-mocks (~> 3.9.0)
20
+ rspec-core (3.9.0)
21
+ rspec-support (~> 3.9.0)
22
+ rspec-expectations (3.9.0)
23
23
  diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.8.0)
25
- rspec-mocks (3.8.1)
24
+ rspec-support (~> 3.9.0)
25
+ rspec-mocks (3.9.0)
26
26
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.8.0)
28
- rspec-support (3.8.2)
27
+ rspec-support (~> 3.9.0)
28
+ rspec-support (3.9.0)
29
29
 
30
30
  PLATFORMS
31
31
  ruby
32
32
 
33
33
  DEPENDENCIES
34
- bundler (~> 1.17)
34
+ bundler (>= 1.17.2)
35
35
  proxy_chain_rb!
36
36
  pry (~> 0.12.2)
37
- rake (~> 10.0)
38
- rspec (~> 3.0)
37
+ rake (>= 12.3.2)
38
+ rspec (>= 3.0)
39
39
 
40
40
  BUNDLED WITH
41
41
  1.17.2
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # ProxyChainRb
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/proxy_chain_rb`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ ProxyChainRb is a Ruby wrapper around the Node.JS library [proxy-chain](https://github.com/apifytech/proxy-chain).
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ It enables you to tunnel proxies that require authentication via non-authenticated proxies bound to localhost (making it possible to use authenticated proxies in e.g. Chrome and Firefox via Selenium).
6
+
7
+ This gem was created for scenarios where [proxifier](https://github.com/samuelkadolph/ruby-proxifier) wouldn't work. NordVPN proxies for example work with ProxyChainRb but somehow can't be used together with proxifier.
6
8
 
7
9
  ## Installation
8
10
 
@@ -22,7 +24,14 @@ Or install it yourself as:
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ ```ruby
28
+ real_proxy = "http://username:password@host:port"
29
+ server = ProxyChainRb::Server.new
30
+ generated_proxy = server.start(real_proxy)
31
+ # use generated_proxy as the proxy when opening new connections in your code
32
+ # when you're done:
33
+ server.stop
34
+ ```
26
35
 
27
36
  ## Development
28
37
 
@@ -32,7 +41,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
41
 
33
42
  ## Contributing
34
43
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/proxy_chain_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SebastianJ/proxy_chain_rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
45
 
37
46
  ## License
38
47
 
@@ -40,4 +49,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
49
 
41
50
  ## Code of Conduct
42
51
 
43
- Everyone interacting in the ProxyChainRb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/proxy_chain_rb/blob/master/CODE_OF_CONDUCT.md).
52
+ Everyone interacting in the ProxyChainRb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/SebastianJ/proxy_chain_rb/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,23 @@
1
+ {
2
+ "systemParams": "darwin-x64-72",
3
+ "modulesFolders": [
4
+ "node_modules"
5
+ ],
6
+ "flags": [],
7
+ "linkedModules": [],
8
+ "topLevelPatterns": [
9
+ "proxy-chain@^0.3.2"
10
+ ],
11
+ "lockfileEntries": {
12
+ "bluebird@^2.9.34": "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1",
13
+ "bluebird@^3.5.1": "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.0.tgz#56a6a886e03f6ae577cffedeb524f8f2450293cf",
14
+ "commander@^2.8.1": "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33",
15
+ "debug@^2.2.0": "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f",
16
+ "ms@2.0.0": "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8",
17
+ "portastic@^1.0.1": "https://registry.yarnpkg.com/portastic/-/portastic-1.0.1.tgz#1c9805d43fae8f6a40cf0dbc7794091a2e9d0d2a",
18
+ "proxy-chain@^0.3.2": "https://registry.yarnpkg.com/proxy-chain/-/proxy-chain-0.3.2.tgz#974524e3a8e7e9b12d81a9b53bb169caa5a990f5",
19
+ "underscore@^1.9.1": "https://registry.yarnpkg.com/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961"
20
+ },
21
+ "files": [],
22
+ "artifacts": {}
23
+ }
@@ -35,7 +35,7 @@ Thanks to BrowserStack for providing us with a free account which lets us suppor
35
35
 
36
36
  The MIT License (MIT)
37
37
 
38
- Copyright (c) 2013-2017 Petka Antonov
38
+ Copyright (c) 2013-2019 Petka Antonov
39
39
 
40
40
  Permission is hereby granted, free of charge, to any person obtaining a copy
41
41
  of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,7 @@
23
23
  *
24
24
  */
25
25
  /**
26
- * bluebird build version 3.5.5
26
+ * bluebird build version 3.7.0
27
27
  * Features enabled: core
28
28
  * Features disabled: race, call_get, generators, map, nodeify, promisify, props, reduce, settle, some, using, timers, filter, any, each
29
29
  */
@@ -33,7 +33,6 @@ var firstLineError;
33
33
  try {throw new Error(); } catch (e) {firstLineError = e;}
34
34
  var schedule = _dereq_("./schedule");
35
35
  var Queue = _dereq_("./queue");
36
- var util = _dereq_("./util");
37
36
 
38
37
  function Async() {
39
38
  this._customScheduler = false;
@@ -41,7 +40,6 @@ function Async() {
41
40
  this._lateQueue = new Queue(16);
42
41
  this._normalQueue = new Queue(16);
43
42
  this._haveDrainedQueues = false;
44
- this._trampolineEnabled = true;
45
43
  var self = this;
46
44
  this.drainQueues = function () {
47
45
  self._drainQueues();
@@ -60,16 +58,6 @@ Async.prototype.hasCustomScheduler = function() {
60
58
  return this._customScheduler;
61
59
  };
62
60
 
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
61
  Async.prototype.haveItemsQueued = function () {
74
62
  return this._isTickUsed || this._haveDrainedQueues;
75
63
  };
@@ -118,43 +106,10 @@ function AsyncSettlePromises(promise) {
118
106
  this._queueTick();
119
107
  }
120
108
 
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
- };
109
+ Async.prototype.invokeLater = AsyncInvokeLater;
110
+ Async.prototype.invoke = AsyncInvoke;
111
+ Async.prototype.settlePromises = AsyncSettlePromises;
137
112
 
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
113
 
159
114
  function _drainQueue(queue) {
160
115
  while (queue.length() > 0) {
@@ -194,7 +149,7 @@ Async.prototype._reset = function () {
194
149
  module.exports = Async;
195
150
  module.exports.firstLineError = firstLineError;
196
151
 
197
- },{"./queue":17,"./schedule":18,"./util":21}],2:[function(_dereq_,module,exports){
152
+ },{"./queue":17,"./schedule":18}],2:[function(_dereq_,module,exports){
198
153
  "use strict";
199
154
  module.exports = function(Promise, INTERNAL, tryConvertToPromise, debug) {
200
155
  var calledBind = false;
@@ -524,8 +479,8 @@ return Context;
524
479
 
525
480
  },{}],7:[function(_dereq_,module,exports){
526
481
  "use strict";
527
- module.exports = function(Promise, Context) {
528
- var getDomain = Promise._getDomain;
482
+ module.exports = function(Promise, Context,
483
+ enableAsyncHooks, disableAsyncHooks) {
529
484
  var async = Promise._async;
530
485
  var Warning = _dereq_("./errors").Warning;
531
486
  var util = _dereq_("./util");
@@ -555,6 +510,77 @@ var longStackTraces = !!(util.env("BLUEBIRD_LONG_STACK_TRACES") != 0 &&
555
510
  var wForgottenReturn = util.env("BLUEBIRD_W_FORGOTTEN_RETURN") != 0 &&
556
511
  (warnings || !!util.env("BLUEBIRD_W_FORGOTTEN_RETURN"));
557
512
 
513
+ var deferUnhandledRejectionCheck;
514
+ (function() {
515
+ var promises = [];
516
+
517
+ function unhandledRejectionCheck() {
518
+ for (var i = 0; i < promises.length; ++i) {
519
+ promises[i]._notifyUnhandledRejection();
520
+ }
521
+ unhandledRejectionClear();
522
+ }
523
+
524
+ function unhandledRejectionClear() {
525
+ promises.length = 0;
526
+ }
527
+
528
+ if (util.isNode) {
529
+ deferUnhandledRejectionCheck = (function() {
530
+ var timers = _dereq_("timers");
531
+ var timerSetTimeout = timers.setTimeout;
532
+ var timer = timerSetTimeout(unhandledRejectionCheck, 1);
533
+ timer.unref();
534
+
535
+ return function(promise) {
536
+ promises.push(promise);
537
+ if (typeof timer.refresh === "function") {
538
+ timer.refresh();
539
+ } else {
540
+ timerSetTimeout(unhandledRejectionCheck, 1).unref();
541
+ }
542
+ };
543
+ })();
544
+ } else if (typeof document === "object" && document.createElement) {
545
+ deferUnhandledRejectionCheck = (function() {
546
+ var iframeSetTimeout;
547
+
548
+ function checkIframe() {
549
+ if (document.body) {
550
+ var iframe = document.createElement("iframe");
551
+ document.body.appendChild(iframe);
552
+ if (iframe.contentWindow &&
553
+ iframe.contentWindow.setTimeout) {
554
+ iframeSetTimeout = iframe.contentWindow.setTimeout;
555
+ }
556
+ document.body.removeChild(iframe);
557
+ }
558
+ }
559
+ checkIframe();
560
+ return function(promise) {
561
+ promises.push(promise);
562
+ if (iframeSetTimeout) {
563
+ iframeSetTimeout(unhandledRejectionCheck, 1);
564
+ } else {
565
+ checkIframe();
566
+ }
567
+ };
568
+ })();
569
+ } else {
570
+ deferUnhandledRejectionCheck = function(promise) {
571
+ promises.push(promise);
572
+ setTimeout(unhandledRejectionCheck, 1);
573
+ };
574
+ }
575
+
576
+ es5.defineProperty(Promise, "_unhandledRejectionCheck", {
577
+ value: unhandledRejectionCheck
578
+ });
579
+ es5.defineProperty(Promise, "_unhandledRejectionClear", {
580
+ value: unhandledRejectionClear
581
+ });
582
+ })();
583
+
558
584
  Promise.prototype.suppressUnhandledRejections = function() {
559
585
  var target = this._target();
560
586
  target._bitField = ((target._bitField & (~1048576)) |
@@ -564,10 +590,7 @@ Promise.prototype.suppressUnhandledRejections = function() {
564
590
  Promise.prototype._ensurePossibleRejectionHandled = function () {
565
591
  if ((this._bitField & 524288) !== 0) return;
566
592
  this._setRejectionIsUnhandled();
567
- var self = this;
568
- setTimeout(function() {
569
- self._notifyUnhandledRejection();
570
- }, 1);
593
+ deferUnhandledRejectionCheck(this);
571
594
  };
572
595
 
573
596
  Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
@@ -625,19 +648,13 @@ Promise.prototype._warn = function(message, shouldUseOwnTrace, promise) {
625
648
  };
626
649
 
627
650
  Promise.onPossiblyUnhandledRejection = function (fn) {
628
- var domain = getDomain();
629
- possiblyUnhandledRejection =
630
- typeof fn === "function" ? (domain === null ?
631
- fn : util.domainBind(domain, fn))
632
- : undefined;
651
+ var context = Promise._getContext();
652
+ possiblyUnhandledRejection = util.contextBind(context, fn);
633
653
  };
634
654
 
635
655
  Promise.onUnhandledRejectionHandled = function (fn) {
636
- var domain = getDomain();
637
- unhandledRejectionHandled =
638
- typeof fn === "function" ? (domain === null ?
639
- fn : util.domainBind(domain, fn))
640
- : undefined;
656
+ var context = Promise._getContext();
657
+ unhandledRejectionHandled = util.contextBind(context, fn);
641
658
  };
642
659
 
643
660
  var disableLongStackTraces = function() {};
@@ -658,14 +675,12 @@ Promise.longStackTraces = function () {
658
675
  Promise.prototype._attachExtraTrace = Promise_attachExtraTrace;
659
676
  Promise.prototype._dereferenceTrace = Promise_dereferenceTrace;
660
677
  Context.deactivateLongStackTraces();
661
- async.enableTrampoline();
662
678
  config.longStackTraces = false;
663
679
  };
664
680
  Promise.prototype._captureStackTrace = longStackTracesCaptureStackTrace;
665
681
  Promise.prototype._attachExtraTrace = longStackTracesAttachExtraTrace;
666
682
  Promise.prototype._dereferenceTrace = longStackTracesDereferenceTrace;
667
683
  Context.activateLongStackTraces();
668
- async.disableTrampolineIfNecessary();
669
684
  }
670
685
  };
671
686
 
@@ -673,43 +688,85 @@ Promise.hasLongStackTraces = function () {
673
688
  return config.longStackTraces && longStackTracesIsSupported();
674
689
  };
675
690
 
691
+
692
+ var legacyHandlers = {
693
+ unhandledrejection: {
694
+ before: function() {
695
+ var ret = util.global.onunhandledrejection;
696
+ util.global.onunhandledrejection = null;
697
+ return ret;
698
+ },
699
+ after: function(fn) {
700
+ util.global.onunhandledrejection = fn;
701
+ }
702
+ },
703
+ rejectionhandled: {
704
+ before: function() {
705
+ var ret = util.global.onrejectionhandled;
706
+ util.global.onrejectionhandled = null;
707
+ return ret;
708
+ },
709
+ after: function(fn) {
710
+ util.global.onrejectionhandled = fn;
711
+ }
712
+ }
713
+ };
714
+
676
715
  var fireDomEvent = (function() {
716
+ var dispatch = function(legacy, e) {
717
+ if (legacy) {
718
+ var fn;
719
+ try {
720
+ fn = legacy.before();
721
+ return !util.global.dispatchEvent(e);
722
+ } finally {
723
+ legacy.after(fn);
724
+ }
725
+ } else {
726
+ return !util.global.dispatchEvent(e);
727
+ }
728
+ };
677
729
  try {
678
730
  if (typeof CustomEvent === "function") {
679
731
  var event = new CustomEvent("CustomEvent");
680
732
  util.global.dispatchEvent(event);
681
733
  return function(name, event) {
734
+ name = name.toLowerCase();
682
735
  var eventData = {
683
736
  detail: event,
684
737
  cancelable: true
685
738
  };
739
+ var domEvent = new CustomEvent(name, eventData);
686
740
  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);
741
+ domEvent, "promise", {value: event.promise});
742
+ es5.defineProperty(
743
+ domEvent, "reason", {value: event.reason});
744
+
745
+ return dispatch(legacyHandlers[name], domEvent);
691
746
  };
692
747
  } else if (typeof Event === "function") {
693
748
  var event = new Event("CustomEvent");
694
749
  util.global.dispatchEvent(event);
695
750
  return function(name, event) {
696
- var domEvent = new Event(name.toLowerCase(), {
751
+ name = name.toLowerCase();
752
+ var domEvent = new Event(name, {
697
753
  cancelable: true
698
754
  });
699
755
  domEvent.detail = event;
700
756
  es5.defineProperty(domEvent, "promise", {value: event.promise});
701
757
  es5.defineProperty(domEvent, "reason", {value: event.reason});
702
- return !util.global.dispatchEvent(domEvent);
758
+ return dispatch(legacyHandlers[name], domEvent);
703
759
  };
704
760
  } else {
705
761
  var event = document.createEvent("CustomEvent");
706
762
  event.initCustomEvent("testingtheevent", false, true, {});
707
763
  util.global.dispatchEvent(event);
708
764
  return function(name, event) {
765
+ name = name.toLowerCase();
709
766
  var domEvent = document.createEvent("CustomEvent");
710
- domEvent.initCustomEvent(name.toLowerCase(), false, true,
767
+ domEvent.initCustomEvent(name, false, true,
711
768
  event);
712
- return !util.global.dispatchEvent(domEvent);
769
+ return dispatch(legacyHandlers[name], domEvent);
713
770
  };
714
771
  }
715
772
  } catch (e) {}
@@ -827,6 +884,18 @@ Promise.config = function(opts) {
827
884
  Promise.prototype._fireEvent = defaultFireEvent;
828
885
  }
829
886
  }
887
+ if ("asyncHooks" in opts && util.nodeSupportsAsyncResource) {
888
+ var prev = config.asyncHooks;
889
+ var cur = !!opts.asyncHooks;
890
+ if (prev !== cur) {
891
+ config.asyncHooks = cur;
892
+ if (cur) {
893
+ enableAsyncHooks();
894
+ } else {
895
+ disableAsyncHooks();
896
+ }
897
+ }
898
+ }
830
899
  return Promise;
831
900
  };
832
901
 
@@ -1424,12 +1493,16 @@ var config = {
1424
1493
  warnings: warnings,
1425
1494
  longStackTraces: false,
1426
1495
  cancellation: false,
1427
- monitoring: false
1496
+ monitoring: false,
1497
+ asyncHooks: false
1428
1498
  };
1429
1499
 
1430
1500
  if (longStackTraces) Promise.longStackTraces();
1431
1501
 
1432
1502
  return {
1503
+ asyncHooks: function() {
1504
+ return config.asyncHooks;
1505
+ },
1433
1506
  longStackTraces: function() {
1434
1507
  return config.longStackTraces;
1435
1508
  },
@@ -1458,7 +1531,7 @@ return {
1458
1531
  };
1459
1532
  };
1460
1533
 
1461
- },{"./errors":9,"./es5":10,"./util":21}],8:[function(_dereq_,module,exports){
1534
+ },{"./errors":9,"./es5":10,"./util":21,"timers":undefined}],8:[function(_dereq_,module,exports){
1462
1535
  "use strict";
1463
1536
  module.exports = function(Promise) {
1464
1537
  function returner() {
@@ -1857,8 +1930,7 @@ return PassThroughHandlerContext;
1857
1930
  },{"./catch_filter":5,"./util":21}],12:[function(_dereq_,module,exports){
1858
1931
  "use strict";
1859
1932
  module.exports =
1860
- function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async,
1861
- getDomain) {
1933
+ function(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async) {
1862
1934
  var util = _dereq_("./util");
1863
1935
  var canEvaluate = util.canEvaluate;
1864
1936
  var tryCatch = util.tryCatch;
@@ -2004,10 +2076,8 @@ Promise.join = function () {
2004
2076
 
2005
2077
  if (!ret._isFateSealed()) {
2006
2078
  if (holder.asyncNeeded) {
2007
- var domain = getDomain();
2008
- if (domain !== null) {
2009
- holder.fn = util.domainBind(domain, holder.fn);
2010
- }
2079
+ var context = Promise._getContext();
2080
+ holder.fn = util.contextBind(context, holder.fn);
2011
2081
  }
2012
2082
  ret._setAsyncGuaranteed();
2013
2083
  ret._setOnCancel(holder);
@@ -2149,20 +2219,42 @@ var apiRejection = function(msg) {
2149
2219
  function Proxyable() {}
2150
2220
  var UNDEFINED_BINDING = {};
2151
2221
  var util = _dereq_("./util");
2222
+ util.setReflectHandler(reflectHandler);
2152
2223
 
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() {
2224
+ var getDomain = function() {
2225
+ var domain = process.domain;
2226
+ if (domain === undefined) {
2162
2227
  return null;
2228
+ }
2229
+ return domain;
2230
+ };
2231
+ var getContextDefault = function() {
2232
+ return null;
2233
+ };
2234
+ var getContextDomain = function() {
2235
+ return {
2236
+ domain: getDomain(),
2237
+ async: null
2163
2238
  };
2164
- }
2165
- util.notEnumerableProp(Promise, "_getDomain", getDomain);
2239
+ };
2240
+ var AsyncResource = util.isNode && util.nodeSupportsAsyncResource ?
2241
+ _dereq_("async_hooks").AsyncResource : null;
2242
+ var getContextAsyncHooks = function() {
2243
+ return {
2244
+ domain: getDomain(),
2245
+ async: new AsyncResource("Bluebird::Promise")
2246
+ };
2247
+ };
2248
+ var getContext = util.isNode ? getContextDomain : getContextDefault;
2249
+ util.notEnumerableProp(Promise, "_getContext", getContext);
2250
+ var enableAsyncHooks = function() {
2251
+ getContext = getContextAsyncHooks;
2252
+ util.notEnumerableProp(Promise, "_getContext", getContextAsyncHooks);
2253
+ };
2254
+ var disableAsyncHooks = function() {
2255
+ getContext = getContextDomain;
2256
+ util.notEnumerableProp(Promise, "_getContext", getContextDomain);
2257
+ };
2166
2258
 
2167
2259
  var es5 = _dereq_("./es5");
2168
2260
  var Async = _dereq_("./async");
@@ -2186,7 +2278,9 @@ var PromiseArray =
2186
2278
  var Context = _dereq_("./context")(Promise);
2187
2279
  /*jshint unused:false*/
2188
2280
  var createContext = Context.create;
2189
- var debug = _dereq_("./debuggability")(Promise, Context);
2281
+
2282
+ var debug = _dereq_("./debuggability")(Promise, Context,
2283
+ enableAsyncHooks, disableAsyncHooks);
2190
2284
  var CapturedTrace = debug.CapturedTrace;
2191
2285
  var PassThroughHandlerContext =
2192
2286
  _dereq_("./finally")(Promise, tryConvertToPromise, NEXT_FILTER);
@@ -2383,7 +2477,7 @@ Promise.prototype._then = function (
2383
2477
  this._fireEvent("promiseChained", this, promise);
2384
2478
  }
2385
2479
 
2386
- var domain = getDomain();
2480
+ var context = getContext();
2387
2481
  if (!((bitField & 50397184) === 0)) {
2388
2482
  var handler, value, settler = target._settlePromiseCtx;
2389
2483
  if (((bitField & 33554432) !== 0)) {
@@ -2401,15 +2495,14 @@ Promise.prototype._then = function (
2401
2495
  }
2402
2496
 
2403
2497
  async.invoke(settler, target, {
2404
- handler: domain === null ? handler
2405
- : (typeof handler === "function" &&
2406
- util.domainBind(domain, handler)),
2498
+ handler: util.contextBind(context, handler),
2407
2499
  promise: promise,
2408
2500
  receiver: receiver,
2409
2501
  value: value
2410
2502
  });
2411
2503
  } else {
2412
- target._addCallbacks(didFulfill, didReject, promise, receiver, domain);
2504
+ target._addCallbacks(didFulfill, didReject, promise,
2505
+ receiver, context);
2413
2506
  }
2414
2507
 
2415
2508
  return promise;
@@ -2470,7 +2563,15 @@ Promise.prototype._setWillBeCancelled = function() {
2470
2563
 
2471
2564
  Promise.prototype._setAsyncGuaranteed = function() {
2472
2565
  if (async.hasCustomScheduler()) return;
2473
- this._bitField = this._bitField | 134217728;
2566
+ var bitField = this._bitField;
2567
+ this._bitField = bitField |
2568
+ (((bitField & 536870912) >> 2) ^
2569
+ 134217728);
2570
+ };
2571
+
2572
+ Promise.prototype._setNoAsyncGuarantee = function() {
2573
+ this._bitField = (this._bitField | 536870912) &
2574
+ (~134217728);
2474
2575
  };
2475
2576
 
2476
2577
  Promise.prototype._receiverAt = function (index) {
@@ -2525,7 +2626,7 @@ Promise.prototype._addCallbacks = function (
2525
2626
  reject,
2526
2627
  promise,
2527
2628
  receiver,
2528
- domain
2629
+ context
2529
2630
  ) {
2530
2631
  var index = this._length();
2531
2632
 
@@ -2538,12 +2639,10 @@ Promise.prototype._addCallbacks = function (
2538
2639
  this._promise0 = promise;
2539
2640
  this._receiver0 = receiver;
2540
2641
  if (typeof fulfill === "function") {
2541
- this._fulfillmentHandler0 =
2542
- domain === null ? fulfill : util.domainBind(domain, fulfill);
2642
+ this._fulfillmentHandler0 = util.contextBind(context, fulfill);
2543
2643
  }
2544
2644
  if (typeof reject === "function") {
2545
- this._rejectionHandler0 =
2546
- domain === null ? reject : util.domainBind(domain, reject);
2645
+ this._rejectionHandler0 = util.contextBind(context, reject);
2547
2646
  }
2548
2647
  } else {
2549
2648
  var base = index * 4 - 4;
@@ -2551,11 +2650,11 @@ Promise.prototype._addCallbacks = function (
2551
2650
  this[base + 3] = receiver;
2552
2651
  if (typeof fulfill === "function") {
2553
2652
  this[base + 0] =
2554
- domain === null ? fulfill : util.domainBind(domain, fulfill);
2653
+ util.contextBind(context, fulfill);
2555
2654
  }
2556
2655
  if (typeof reject === "function") {
2557
2656
  this[base + 1] =
2558
- domain === null ? reject : util.domainBind(domain, reject);
2657
+ util.contextBind(context, reject);
2559
2658
  }
2560
2659
  }
2561
2660
  this._setLength(index + 1);
@@ -2575,6 +2674,7 @@ Promise.prototype._resolveCallback = function(value, shouldBind) {
2575
2674
 
2576
2675
  if (shouldBind) this._propagateFrom(maybePromise, 2);
2577
2676
 
2677
+
2578
2678
  var promise = maybePromise._target();
2579
2679
 
2580
2680
  if (promise === this) {
@@ -2591,7 +2691,7 @@ Promise.prototype._resolveCallback = function(value, shouldBind) {
2591
2691
  }
2592
2692
  this._setFollowing();
2593
2693
  this._setLength(0);
2594
- this._setFollowee(promise);
2694
+ this._setFollowee(maybePromise);
2595
2695
  } else if (((bitField & 33554432) !== 0)) {
2596
2696
  this._fulfill(promise._value());
2597
2697
  } else if (((bitField & 16777216) !== 0)) {
@@ -2882,9 +2982,9 @@ _dereq_("./cancel")(Promise, PromiseArray, apiRejection, debug);
2882
2982
  _dereq_("./direct_resolve")(Promise);
2883
2983
  _dereq_("./synchronous_inspection")(Promise);
2884
2984
  _dereq_("./join")(
2885
- Promise, PromiseArray, tryConvertToPromise, INTERNAL, async, getDomain);
2985
+ Promise, PromiseArray, tryConvertToPromise, INTERNAL, async);
2886
2986
  Promise.Promise = Promise;
2887
- Promise.version = "3.5.5";
2987
+ Promise.version = "3.7.0";
2888
2988
 
2889
2989
  util.toFastProperties(Promise);
2890
2990
  util.toFastProperties(Promise.prototype);
@@ -2910,7 +3010,7 @@ Promise.version = "3.5.5";
2910
3010
 
2911
3011
  };
2912
3012
 
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){
3013
+ },{"./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,"async_hooks":undefined}],16:[function(_dereq_,module,exports){
2914
3014
  "use strict";
2915
3015
  module.exports = function(Promise, INTERNAL, tryConvertToPromise,
2916
3016
  apiRejection, Proxyable) {
@@ -2929,6 +3029,7 @@ function PromiseArray(values) {
2929
3029
  var promise = this._promise = new Promise(INTERNAL);
2930
3030
  if (values instanceof Promise) {
2931
3031
  promise._propagateFrom(values, 3);
3032
+ values.suppressUnhandledRejections();
2932
3033
  }
2933
3034
  promise._setOnCancel(this);
2934
3035
  this._values = values;
@@ -3758,18 +3859,42 @@ function getNativePromise() {
3758
3859
  if (typeof Promise === "function") {
3759
3860
  try {
3760
3861
  var promise = new Promise(function(){});
3761
- if ({}.toString.call(promise) === "[object Promise]") {
3862
+ if (classString(promise) === "[object Promise]") {
3762
3863
  return Promise;
3763
3864
  }
3764
3865
  } catch (e) {}
3765
3866
  }
3766
3867
  }
3767
3868
 
3768
- function domainBind(self, cb) {
3769
- return self.bind(cb);
3869
+ var reflectHandler;
3870
+ function contextBind(ctx, cb) {
3871
+ if (ctx === null ||
3872
+ typeof cb !== "function" ||
3873
+ cb === reflectHandler) {
3874
+ return cb;
3875
+ }
3876
+
3877
+ if (ctx.domain !== null) {
3878
+ cb = ctx.domain.bind(cb);
3879
+ }
3880
+
3881
+ var async = ctx.async;
3882
+ if (async !== null) {
3883
+ var old = cb;
3884
+ cb = function() {
3885
+ var args = (new Array(2)).concat([].slice.call(arguments));;
3886
+ args[0] = old;
3887
+ args[1] = this;
3888
+ return async.runInAsyncScope.apply(async, args);
3889
+ };
3890
+ }
3891
+ return cb;
3770
3892
  }
3771
3893
 
3772
3894
  var ret = {
3895
+ setReflectHandler: function(fn) {
3896
+ reflectHandler = fn;
3897
+ },
3773
3898
  isClass: isClass,
3774
3899
  isIdentifier: isIdentifier,
3775
3900
  inheritedDataKeys: inheritedDataKeys,
@@ -3796,29 +3921,37 @@ var ret = {
3796
3921
  markAsOriginatingFromRejection: markAsOriginatingFromRejection,
3797
3922
  classString: classString,
3798
3923
  copyDescriptors: copyDescriptors,
3799
- hasDevTools: typeof chrome !== "undefined" && chrome &&
3800
- typeof chrome.loadTimes === "function",
3801
3924
  isNode: isNode,
3802
3925
  hasEnvVariables: hasEnvVariables,
3803
3926
  env: env,
3804
3927
  global: globalObject,
3805
3928
  getNativePromise: getNativePromise,
3806
- domainBind: domainBind
3929
+ contextBind: contextBind
3807
3930
  };
3808
3931
  ret.isRecentNode = ret.isNode && (function() {
3809
3932
  var version;
3810
- if (process.versions && process.versions.node) {
3933
+ if (process.versions && process.versions.node) {
3811
3934
  version = process.versions.node.split(".").map(Number);
3812
3935
  } else if (process.version) {
3813
3936
  version = process.version.split(".").map(Number);
3814
3937
  }
3815
3938
  return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
3816
3939
  })();
3940
+ ret.nodeSupportsAsyncResource = ret.isNode && (function() {
3941
+ var supportsAsync = false;
3942
+ try {
3943
+ var res = _dereq_("async_hooks").AsyncResource;
3944
+ supportsAsync = typeof res.prototype.runInAsyncScope === "function";
3945
+ } catch (e) {
3946
+ supportsAsync = false;
3947
+ }
3948
+ return supportsAsync;
3949
+ })();
3817
3950
 
3818
3951
  if (ret.isNode) ret.toFastProperties(process);
3819
3952
 
3820
3953
  try {throw new Error(); } catch (e) {ret.lastLineError = e;}
3821
3954
  module.exports = ret;
3822
3955
 
3823
- },{"./es5":10}]},{},[3])(3)
3956
+ },{"./es5":10,"async_hooks":undefined}]},{},[3])(3)
3824
3957
  }); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }