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

Fix JSC encoding

This commit is contained in:
Joshua Peek 2011-02-10 10:57:40 -06:00
parent badf37eb1f
commit 24a41dfe9d
2 changed files with 28 additions and 2 deletions

View file

@ -8,6 +8,7 @@ module ExecJS
@runner_path = options[:runner_path]
@test_args = options[:test_args]
@test_match = options[:test_match]
@conversion = options[:conversion]
@binary = locate_binary
end
@ -74,7 +75,7 @@ module ExecJS
end
def exec_runtime(filename)
output = `#{@binary} #{filename} 2>&1`
output = sh("#{@binary} #{filename} 2>&1")
if $?.success?
output
else
@ -82,6 +83,29 @@ module ExecJS
end
end
if "".respond_to?(:force_encoding)
def sh(command)
output, options = nil, {}
options[:internal_encoding] = @conversion[:from] if @conversion
IO.popen(command, options) { |f| output = f.read }
output.force_encoding(@conversion[:to]) if @conversion
output
end
else
require "iconv"
def sh(command)
output = nil
IO.popen(command) { |f| output = f.read }
if @conversion
Iconv.iconv(@conversion[:from], @conversion[:to], output).first
else
output
end
end
end
def extract_result(output)
status, value = output.empty? ? [] : JSON.parse(output)
if status == "ok"

View file

@ -1,3 +1,4 @@
module ExecJS
module Runtimes
def self.best_available
@ -32,7 +33,8 @@ module ExecJS
define_runtime :JavaScriptCore,
:command => "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
:runner_path => ExecJS.root + "/support/basic_runner.js"
:runner_path => ExecJS.root + "/support/basic_runner.js",
:conversion => { :from => "ISO8859-1", :to => "UTF-8" }
define_runtime :Spidermonkey,
:command => "js",