Index: tools/turbolizer/selection-broker.js |
diff --git a/tools/turbolizer/selection-broker.js b/tools/turbolizer/selection-broker.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3a223d8b643097079d68b543eadc741e797c7977 |
--- /dev/null |
+++ b/tools/turbolizer/selection-broker.js |
@@ -0,0 +1,46 @@ |
+// Copyright 2015 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+var SelectionBroker = function() { |
+ this.brokers = []; |
+ this.dispatching = false; |
+ this.lastDispatchingHandler = null; |
+}; |
+ |
+SelectionBroker.prototype.addSelectionHandler = function(handler) { |
+ this.brokers.push(handler); |
+} |
+ |
+SelectionBroker.prototype.select = function(from, ranges, selected) { |
+ if (!this.dispatching) { |
+ this.lastDispatchingHandler = from; |
+ try { |
+ this.dispatching = true; |
+ for (var b of this.brokers) { |
+ if (b != from) { |
+ b.brokeredSelect(ranges, selected); |
+ } |
+ } |
+ } |
+ finally { |
+ this.dispatching = false; |
+ } |
+ } |
+} |
+ |
+SelectionBroker.prototype.clear = function(from) { |
+ this.lastDispatchingHandler = null; |
+ if (!this.dispatching) { |
+ try { |
+ this.dispatching = true; |
+ this.brokers.forEach(function(b) { |
+ if (b != from) { |
+ b.brokeredClear(); |
+ } |
+ }); |
+ } finally { |
+ this.dispatching = false; |
+ } |
+ } |
+} |