Sha256: 4dd6bf81b0171ddceb395d2adcde28799a8d2a770ddad82b2920e0a9cde77bdc

Contents?: true

Size: 964 Bytes

Versions: 37

Compression:

Stored size: 964 Bytes

Contents

require 'v8'

class Class
  def native_impl(lib)
    class << self
      def new(*args)
        js = {
          # Add more mappings here if needed. The mappings are only used by test code.
          'Gherkin::Formatter::JSONFormatter' => 'js/lib/gherkin/formatter/json_formatter.js',
          'Gherkin::Lexer::En' => 'js/lib/gherkin/lexer/en.js'
        }[self.name]
        if(js)
          Proxy.new(js, *args)
        else
          super(*args)
        end
      end
    end
  end

  class Proxy
    def initialize(js, *args)
      cxt = V8::Context.new
      cxt['module'] = {}

      # Mimic Node.js / Firebug console.log
      cxt['console'] = STDOUT
      def STDOUT.log(*a)
        puts sprintf(*a.map(&:to_s))
      end

      cxt.load(js)
      @js_obj = cxt['module']['exports'].new(*args)
    end

    def method_missing(name, *args)
      a = args.map{|a| a.respond_to?(:to_hash) ? a.to_hash : a}
      @js_obj.__send__(name, *a)
    end
  end
end

Version data entries

37 entries across 35 versions & 3 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/gherkin-2.12.2/lib/gherkin/native/therubyracer.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/gherkin-2.12.2/lib/gherkin/native/therubyracer.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/gherkin-2.12.2/lib/gherkin/native/therubyracer.rb
gherkin-2.12.2 lib/gherkin/native/therubyracer.rb
gherkin-2.12.2-x86-mswin32 lib/gherkin/native/therubyracer.rb
gherkin-2.12.2-x86-mingw32 lib/gherkin/native/therubyracer.rb
gherkin-2.12.2-java lib/gherkin/native/therubyracer.rb
gherkin-2.12.1 lib/gherkin/native/therubyracer.rb
gherkin-2.12.1-x86-mswin32 lib/gherkin/native/therubyracer.rb
gherkin-2.12.1-x86-mingw32 lib/gherkin/native/therubyracer.rb
gherkin-2.12.1-java lib/gherkin/native/therubyracer.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/gherkin-2.11.6/lib/gherkin/native/therubyracer.rb
gherkin-2.12.0 lib/gherkin/native/therubyracer.rb
gherkin-2.12.0-x86-mingw32 lib/gherkin/native/therubyracer.rb
gherkin-2.12.0-x86-mswin32 lib/gherkin/native/therubyracer.rb
gherkin-2.12.0-java lib/gherkin/native/therubyracer.rb
gherkin-2.11.8 lib/gherkin/native/therubyracer.rb
gherkin-2.11.8-x86-mswin32 lib/gherkin/native/therubyracer.rb
gherkin-2.11.8-x86-mingw32 lib/gherkin/native/therubyracer.rb
gherkin-2.11.8-java lib/gherkin/native/therubyracer.rb