Class: TracePoint

Inherits:
Object show all
Defined in:
opal/opal/corelib/trace_point.rb

Overview

backtick_javascript: true

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, &block) ⇒ TracePoint

Returns a new instance of TracePoint.



12
13
14
15
16
17
18
19
# File 'opal/opal/corelib/trace_point.rb', line 12

def initialize(event, &block)
  ::Kernel.raise 'Only the :class event is supported' unless event == :class
  @event = event
  @block = block
  @trace_object = nil
  @trace_evt = "trace_#{@event}"
  @tracers_for_evt = "tracers_for_#{@event}"
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



10
11
12
# File 'opal/opal/corelib/trace_point.rb', line 10

def event
  @event
end

Class Method Details

.trace(event, &block) ⇒ Object

partial implementation of TracePoint for the moment only supports the :class event



6
7
8
# File 'opal/opal/corelib/trace_point.rb', line 6

def self.trace(event, &block)
  new(event, &block).enable
end

Instance Method Details

#disableObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'opal/opal/corelib/trace_point.rb', line 38

def disable
  %x{
    var idx = Opal[#{@tracers_for_evt}].indexOf(self)

    if (idx > -1) {
      Opal[#{@tracers_for_evt}].splice(idx, 1);

      if (Opal[#{@tracers_for_evt}].length === 0) {
        Opal[#{@trace_evt}] = false;
      }

      return true;
    } else {
      return false;
    }
  }
end

#enable(*args, &enable_block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'opal/opal/corelib/trace_point.rb', line 21

def enable(*args, &enable_block)
  previous_state = enabled?
  %x{
    Opal[#{@tracers_for_evt}].push(self);
    Opal[#{@trace_evt}] = true;
  }
  if block_given?
    yield
    disable
  end
  previous_state
end

#enabled?Boolean

Returns:



34
35
36
# File 'opal/opal/corelib/trace_point.rb', line 34

def enabled?
  `Opal[#{@trace_evt}] && Opal[#{@tracers_for_evt}].includes(self)`
end

#selfObject



56
57
58
# File 'opal/opal/corelib/trace_point.rb', line 56

def self
  @trace_object
end