Class: TracePoint
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Class Method Summary collapse
-
.trace(event, &block) ⇒ Object
partial implementation of TracePoint for the moment only supports the :class event.
Instance Method Summary collapse
- #disable ⇒ Object
- #enable(*args, &enable_block) ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(event, &block) ⇒ TracePoint
constructor
A new instance of TracePoint.
- #self ⇒ Object
Constructor Details
#initialize(event, &block) ⇒ TracePoint
Returns a new instance of TracePoint.
10 11 12 13 14 15 16 17 |
# File 'opal/opal/corelib/trace_point.rb', line 10 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
#event ⇒ Object (readonly)
Returns the value of attribute event.
8 9 10 |
# File 'opal/opal/corelib/trace_point.rb', line 8 def event @event end |
Class Method Details
.trace(event, &block) ⇒ Object
partial implementation of TracePoint for the moment only supports the :class event
4 5 6 |
# File 'opal/opal/corelib/trace_point.rb', line 4 def self.trace(event, &block) new(event, &block).enable end |
Instance Method Details
#disable ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'opal/opal/corelib/trace_point.rb', line 36 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
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'opal/opal/corelib/trace_point.rb', line 19 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
32 33 34 |
# File 'opal/opal/corelib/trace_point.rb', line 32 def enabled? `Opal[#{@trace_evt}] && Opal[#{@tracers_for_evt}].includes(self)` end |
#self ⇒ Object
54 55 56 |
# File 'opal/opal/corelib/trace_point.rb', line 54 def self @trace_object end |