Class: Dommy::MessageEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/dommy/message_channel.rb

Overview

‘MessageEvent` — payload of `message` events on MessagePort / BroadcastChannel / WebSocket / EventSource.

Constant Summary

Constants inherited from Event

Event::AT_TARGET, Event::BUBBLING_PHASE, Event::CAPTURING_PHASE, Event::NONE

Instance Attribute Summary collapse

Attributes inherited from Event

#type

Instance Method Summary collapse

Methods inherited from Event

#__internal_clear_propagation_flags__, #__internal_mark_trusted__, #__internal_prepare_for_dispatch__, #__internal_record_path__, #__internal_set_current_target__, #__internal_set_dispatch_flag__, #__internal_set_event_phase__, #__js_set__, #bubbles?, #default_prevented?, #immediate_propagation_stopped?, #init_event, #propagation_stopped?

Methods included from Bridge::Methods

included

Constructor Details

#initialize(type, init = nil) ⇒ MessageEvent

Returns a new instance of MessageEvent.



137
138
139
140
141
142
143
144
# File 'lib/dommy/message_channel.rb', line 137

def initialize(type, init = nil)
  super
  @data = read_init(init, "data")
  @origin = (read_init(init, "origin") || "").to_s
  @last_event_id = (read_init(init, "lastEventId") || "").to_s
  @source = read_init(init, "source")
  @ports = read_init(init, "ports") || []
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



146
147
148
# File 'lib/dommy/message_channel.rb', line 146

def data
  @data
end

#last_event_idObject (readonly)

Returns the value of attribute last_event_id.



146
147
148
# File 'lib/dommy/message_channel.rb', line 146

def last_event_id
  @last_event_id
end

#originObject (readonly)

Returns the value of attribute origin.



146
147
148
# File 'lib/dommy/message_channel.rb', line 146

def origin
  @origin
end

#portsObject (readonly)

Returns the value of attribute ports.



146
147
148
# File 'lib/dommy/message_channel.rb', line 146

def ports
  @ports
end

#sourceObject (readonly)

Returns the value of attribute source.



146
147
148
# File 'lib/dommy/message_channel.rb', line 146

def source
  @source
end

Instance Method Details

#__js_call__(method, args) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/dommy/message_channel.rb', line 166

def __js_call__(method, args)
  case method
  when "initMessageEvent"
    # Deprecated initMessageEvent(type, bubbles, cancelable, data, origin,
    # lastEventId, source, ports); a no-op while the event is dispatching.
    raise Bridge::TypeError, "initMessageEvent requires a type argument" if args.empty?

    unless @dispatch_flag
      init_event(args[0], args[1], args[2])
      @data = args[3]
      @origin = (args[4] || "").to_s
      @last_event_id = (args[5] || "").to_s
      @source = args[6]
      @ports = args[7] || []
    end
    nil
  else
    super
  end
end

#__js_get__(key) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/dommy/message_channel.rb', line 148

def __js_get__(key)
  case key
  when "data"
    @data
  when "origin"
    @origin
  when "lastEventId"
    @last_event_id
  when "source"
    @source
  when "ports"
    @ports
  else
    super
  end
end