Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Encode strings to utf-8 that are passed to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jun 8, 2011
1 parent 818e835 commit 043c06b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/execjs/external_runtime.rb
Expand Up @@ -4,8 +4,10 @@ module ExecJS
class ExternalRuntime
class Context
def initialize(runtime, source = "")
source = source.encode('UTF-8') if source.respond_to?(:encode)

@runtime = runtime
@source = source.respond_to?(:encode) ? source.encode("UTF-8") : source
@source = source
end

def eval(source, options = {})
Expand Down
2 changes: 2 additions & 0 deletions lib/execjs/mustang_runtime.rb
Expand Up @@ -2,6 +2,8 @@ module ExecJS
class MustangRuntime
class Context
def initialize(source = "")
source = source.encode('UTF-8') if source.respond_to?(:encode)

@v8_context = ::Mustang::Context.new
@v8_context.eval(source)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/execjs/ruby_racer_runtime.rb
Expand Up @@ -2,6 +2,8 @@ module ExecJS
class RubyRacerRuntime
class Context
def initialize(source = "")
source = source.encode('UTF-8') if source.respond_to?(:encode)

@v8_context = ::V8::Context.new
@v8_context.eval(source)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/execjs/ruby_rhino_runtime.rb
Expand Up @@ -2,6 +2,8 @@ module ExecJS
class RubyRhinoRuntime
class Context
def initialize(source = "")
source = source.encode('UTF-8') if source.respond_to?(:encode)

@rhino_context = ::Rhino::Context.new
@rhino_context.eval(source)
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_runtime.rb
Expand Up @@ -69,7 +69,7 @@ def test_encoding_compile

assert_raise Encoding::UndefinedConversionError do
binary = "\xde\xad\xbe\xef".force_encoding("BINARY")
@runtime.eval(binary)
context.eval(binary)
end
end
end
Expand Down

0 comments on commit 043c06b

Please sign in to comment.