1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00

Encode strings to utf-8 that are passed to compile

This commit is contained in:
Joshua Peek 2011-06-07 21:36:06 -05:00
parent 818e8351cc
commit 043c06b699
5 changed files with 10 additions and 2 deletions

View file

@ -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 = {})

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -69,7 +69,7 @@ class TestRuntime < Test::Unit::TestCase
assert_raise Encoding::UndefinedConversionError do
binary = "\xde\xad\xbe\xef".force_encoding("BINARY")
@runtime.eval(binary)
context.eval(binary)
end
end
end