diff options
| author | Stephen Blott | 2015-01-10 08:25:02 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2015-01-10 11:03:01 +0000 | 
| commit | fdcdd0113049042c94b2b56a6b716e2da58b860e (patch) | |
| tree | 5cbeacce234df58fc1f5c125f2055a591578a510 /lib/handler_stack.coffee | |
| parent | ac90db47aa2671cd663cc6a9cdf783dc30a582e9 (diff) | |
| download | vimium-fdcdd0113049042c94b2b56a6b716e2da58b860e.tar.bz2 | |
Modes; instrument for debugging...
- Set Mode.debug to true to see mode activation/deactivation on the
  console.
- Use Mode.log() to see a list of currently-active modes.
- Use handlerStack.debugOn() to enable debugging of the handler stack.
Diffstat (limited to 'lib/handler_stack.coffee')
| -rw-r--r-- | lib/handler_stack.coffee | 34 | 
1 files changed, 33 insertions, 1 deletions
| diff --git a/lib/handler_stack.coffee b/lib/handler_stack.coffee index 44c7538b..22d04941 100644 --- a/lib/handler_stack.coffee +++ b/lib/handler_stack.coffee @@ -3,6 +3,8 @@ root = exports ? window  class HandlerStack    constructor: -> +    @debug = false +    @eventNumber = 0      @stack = []      @counter = 0 @@ -22,8 +24,10 @@ class HandlerStack    # Adds a handler to the top of the stack. Returns a unique ID for that handler that can be used to remove it    # later.    push: (handler) -> -    @stack.push handler      handler.id = ++@counter +    handler._name ||= "anon-#{@counter}" +    @stack.push handler +    handler.id    # Adds a handler to the bottom of the stack. Returns a unique ID for that handler that can be used to remove    # it later. @@ -35,6 +39,7 @@ class HandlerStack    # event's propagation by returning a falsy value, or stop bubbling by returning @stopBubblingAndFalse or    # @stopBubblingAndTrue.    bubbleEvent: (type, event) -> +    @eventNumber += 1      # We take a copy of the array in order to avoid interference from concurrent removes (for example, to      # avoid calling the same handler twice, because elements have been spliced out of the array by remove).      for handler in @stack[..].reverse() @@ -42,6 +47,7 @@ class HandlerStack        if handler?.id and handler[type]          @currentId = handler.id          result = handler[type].call @, event +        @logResult type, event, handler, result if @debug          if not result            DomUtils.suppressEvent(event) if @isChromeEvent event            return false @@ -75,5 +81,31 @@ class HandlerStack      handler()      false +  # Debugging. +  debugOn: -> @debug = true +  debugOff: -> @debug = false + +  logResult: (type, event, handler, result) -> +    # FIXME(smblott).  Badge updating is too noisy, so we filter it out.  However, we do need to look at how +    # many badge update events are happening.  It seems to be more than necessary. +    return if type == "updateBadge" +    label = +      switch result +        when @stopBubblingAndTrue then "stop/true" +        when @stopBubblingAndFalse then "stop/false" +        when @restartBubbling then "rebubble" +        when true then "continue" +    label ||= if result then "continue/truthy" else "suppress" +    @log @eventNumber, type, handler._name, label + +  logRecords: [] +  log: (args...) -> +    line = args.join " " +    @logRecords.push line +    console.log line + +  clipLog: -> +    Clipboard.copy logRecords.join "\n" +  root.HandlerStack = HandlerStack  root.handlerStack = new HandlerStack | 
