mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Try to convert to UTF8 early
This commit is contained in:
parent
c3b3019daa
commit
0b4977e028
5 changed files with 27 additions and 0 deletions
|
@ -9,12 +9,16 @@ module ExecJS
|
|||
end
|
||||
|
||||
def eval(source, options = {})
|
||||
souce = source.encode('UTF-8') if source.respond_to?(:encode)
|
||||
|
||||
if /\S/ =~ source
|
||||
exec("return eval(#{MultiJson.encode("(#{source})")})")
|
||||
end
|
||||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
souce = source.encode('UTF-8') if source.respond_to?(:encode)
|
||||
|
||||
compile_to_tempfile([@source, source].join("\n")) do |file|
|
||||
extract_result(@runtime.send(:exec_runtime, file.path))
|
||||
end
|
||||
|
|
|
@ -7,12 +7,16 @@ module ExecJS
|
|||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
souce = source.encode('UTF-8') if source.respond_to?(:encode)
|
||||
|
||||
if /\S/ =~ source
|
||||
eval "(function(){#{source}})()", options
|
||||
end
|
||||
end
|
||||
|
||||
def eval(source, options = {})
|
||||
souce = source.encode('UTF-8') if source.respond_to?(:encode)
|
||||
|
||||
if /\S/ =~ source
|
||||
unbox @v8_context.eval("(#{source})")
|
||||
end
|
||||
|
|
|
@ -7,12 +7,16 @@ module ExecJS
|
|||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
souce = source.encode('UTF-8') if source.respond_to?(:encode)
|
||||
|
||||
if /\S/ =~ source
|
||||
eval "(function(){#{source}})()", options
|
||||
end
|
||||
end
|
||||
|
||||
def eval(source, options = {})
|
||||
souce = source.encode('UTF-8') if source.respond_to?(:encode)
|
||||
|
||||
if /\S/ =~ source
|
||||
unbox @v8_context.eval("(#{source})")
|
||||
end
|
||||
|
|
|
@ -7,12 +7,16 @@ module ExecJS
|
|||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
souce = source.encode('UTF-8') if source.respond_to?(:encode)
|
||||
|
||||
if /\S/ =~ source
|
||||
eval "(function(){#{source}})()", options
|
||||
end
|
||||
end
|
||||
|
||||
def eval(source, options = {})
|
||||
souce = source.encode('UTF-8') if source.respond_to?(:encode)
|
||||
|
||||
if /\S/ =~ source
|
||||
unbox @rhino_context.eval("(#{source})")
|
||||
end
|
||||
|
|
|
@ -36,8 +36,19 @@ module TestRuntime
|
|||
if defined? Encoding
|
||||
def test_encoding
|
||||
utf8 = Encoding.find('UTF-8')
|
||||
|
||||
assert_equal utf8, @runtime.exec("return 'hello'").encoding
|
||||
assert_equal utf8, @runtime.eval("'☃'").encoding
|
||||
|
||||
ascii = "'hello'".encode('US-ASCII')
|
||||
result = @runtime.eval(ascii)
|
||||
assert_equal "hello", result
|
||||
assert_equal utf8, result.encoding
|
||||
|
||||
assert_raise Encoding::UndefinedConversionError do
|
||||
binary = "\xde\xad\xbe\xef".force_encoding("BINARY")
|
||||
@runtime.eval(binary)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue