Class: Opal::BuilderProcessors::WASMProcessor

Inherits:
Processor
  • Object
show all
Defined in:
lib/opal/webassembly/processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(source, filename, options = {}) ⇒ WASMProcessor

Override the initialization, because we really don’t want a new line mangling



10
11
12
13
14
15
# File 'lib/opal/webassembly/processor.rb', line 10

def initialize(source, filename, options = {})
  #source += "\n" unless source.end_with?("\n")
  @source, @filename, @options = source, filename, options
  @requires = []
  @required_trees = []
end

Instance Method Details

#requiresObject



38
39
40
# File 'lib/opal/webassembly/processor.rb', line 38

def requires
  ['webassembly'] + super
end

#sourceObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/opal/webassembly/processor.rb', line 17

def source
  module_name = ::Opal::Compiler.module_name(@filename)
  source = Base64.strict_encode64(@source.to_s)
  <<~END
    Opal.modules[#{module_name.inspect}] = function() {
      // WebAssembly module
      var self = Opal.top;
      self.$require("webassembly");
      Opal.WebAssembly.$load_from_base64('#{source}', #{module_name.inspect});
    };
  END
end

#source_mapObject

No source map support. Required to be mocked for tests.



31
32
33
34
35
36
# File 'lib/opal/webassembly/processor.rb', line 31

def source_map
  o = Object.new
  def o.generated_code; ""; end
  def o.to_h; {version: 3, sections: nil, sources: [], mappings: []}; end
  o
end