Module: ExecJS::Encoding

### Home Classes Methods

### In Files

- lib/execjs/encoding.rb

### Methods

- #encode

### Class/Module Index

Quicksearch

- ExecJS
- ExecJS::DisabledRuntime
- ExecJS::DuktapeRuntime
- ExecJS::DuktapeRuntime::Context
- ExecJS::Encoding
- ExecJS::Error
- ExecJS::ExternalRuntime
- ExecJS::ExternalRuntime::Context
- ExecJS::ProgramError
- ExecJS::RubyRacerRuntime
- ExecJS::RubyRacerRuntime::Context
- ExecJS::RubyRhinoRuntime
- ExecJS::RubyRhinoRuntime::Context
- ExecJS::Runtime
- ExecJS::Runtime::Context
- ExecJS::RuntimeError
- ExecJS::RuntimeUnavailable
- ExecJS::Runtimes

No matching classes.

# ExecJS::Encoding

Encodes strings as UTF-8

### Public Instance Methods

encode(string) click to toggle source

workaround for jruby bug jira.codehaus.org/browse/JRUBY-6588 workaround for rbx bug github.com/rubinius/rubinius/issues/1729

    # File lib/execjs/encoding.rb, line 7
    def encode(string)
      if string.encoding.name == 'ASCII-8BIT'
        data = string.dup
        data.force_encoding('UTF-8')

        unless data.valid_encoding?
          raise ::Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8"
        end
      else
        data = string.encode('UTF-8')
      end
      data
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.