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

Commit

Permalink
Merge branch 'stereobooster-happy-travis-ci'
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed May 17, 2012
2 parents 457c4f2 + 3514c7b commit 4cd4e45
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 36 deletions.
14 changes: 6 additions & 8 deletions .travis.yml
@@ -1,13 +1,11 @@
env: CI=1

rvm:
- 1.8.7
- 1.9.1
- 1.9.2
- jruby
- rbx
- 1.9.3
- jruby-18mode
- jruby-19mode
- jruby-head
- rbx-18mode
- rbx-19mode
- ree
- ruby-head

notifications:
disabled: true
12 changes: 8 additions & 4 deletions Gemfile
Expand Up @@ -3,9 +3,13 @@ source :rubygems
gemspec

group :test do
gem 'johnson', :platform => :mri_18
gem 'json'
gem 'mustang', :platform => :ruby
gem 'therubyracer', :platform => :ruby
gem 'therubyrhino', :platform => :jruby
# see https://github.com/jbarnette/johnson/issues/21
gem 'johnson', :platform => :mri_18
# see https://github.com/nu7hatch/mustang/issues/18
gem 'mustang', :platform => :ruby,
:git => "https://github.com/nu7hatch/mustang.git", :ref => "2a3bcfbd9fd0f34e9b004fcd92188f326b40ec2a"
# disabled for rbx, because of https://github.com/cowboyd/therubyracer/issues/157
gem 'therubyracer', :platform => :mri
gem 'therubyrhino', ">=1.73.3", :platform => :jruby
end
3 changes: 2 additions & 1 deletion Rakefile
Expand Up @@ -7,7 +7,7 @@ require "execjs/runtimes"

tests = namespace :test do |tests|
ExecJS::Runtimes.names.each do |name|
next if name == :Disabled
next if name.to_s == "Disabled"

task(name.downcase) do
ENV["EXECJS_RUNTIME"] = name.to_s
Expand Down Expand Up @@ -56,4 +56,5 @@ task :test do
banner messages.join("\n")

raise "test failures" if failed.any?
raise "all tests skipped" if !passed.any?
end
8 changes: 1 addition & 7 deletions execjs.gemspec
Expand Up @@ -7,18 +7,12 @@ Gem::Specification.new do |s|

s.homepage = "https://github.com/sstephenson/execjs"
s.summary = "Run JavaScript code from Ruby"
s.description = <<-EOS
ExecJS lets you run JavaScript code from Ruby.
EOS
s.description = "ExecJS lets you run JavaScript code from Ruby."

s.files = Dir["README.md", "LICENSE", "lib/**/*"]

s.add_dependency "multi_json", "~>1.0"
s.add_development_dependency "johnson"
s.add_development_dependency "mustang"
s.add_development_dependency "rake"
s.add_development_dependency "therubyracer"
s.add_development_dependency "therubyrhino"

s.authors = ["Sam Stephenson", "Josh Peek"]
s.email = ["sstephenson@gmail.com", "josh@joshpeek.com"]
Expand Down
6 changes: 3 additions & 3 deletions lib/execjs/external_runtime.rb
Expand Up @@ -6,22 +6,22 @@ module ExecJS
class ExternalRuntime
class Context
def initialize(runtime, source = "")
source = source.encode('UTF-8') if source.respond_to?(:encode)
source = ExecJS.encode(source)

@runtime = runtime
@source = source
end

def eval(source, options = {})
source = source.encode('UTF-8') if source.respond_to?(:encode)
source = ExecJS.encode(source)

if /\S/ =~ source
exec("return eval(#{json_encode("(#{source})")})")
end
end

def exec(source, options = {})
source = source.encode('UTF-8') if source.respond_to?(:encode)
source = ExecJS.encode(source)
source = "#{@source}\n#{source}" if @source

compile_to_tempfile(source) do |file|
Expand Down
29 changes: 29 additions & 0 deletions lib/execjs/module.rb
Expand Up @@ -34,5 +34,34 @@ def root
def windows?
@windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
end

if defined? Encoding
if (!defined?(RUBY_ENGINE) || (RUBY_ENGINE != "jruby" && RUBY_ENGINE != "rbx"))
def encode(string)
string.encode('UTF-8')
end
else
# workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588
# workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729
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
end
else
# Define no-op on 1.8
def encode(string)
string
end
end
end
end
6 changes: 3 additions & 3 deletions lib/execjs/mustang_runtime.rb
Expand Up @@ -2,22 +2,22 @@ module ExecJS
class MustangRuntime
class Context
def initialize(source = "")
source = source.encode('UTF-8') if source.respond_to?(:encode)
source = ExecJS.encode(source)

@v8_context = ::Mustang::Context.new
@v8_context.eval(source)
end

def exec(source, options = {})
source = source.encode('UTF-8') if source.respond_to?(:encode)
source = ExecJS.encode(source)

if /\S/ =~ source
eval "(function(){#{source}})()", options
end
end

def eval(source, options = {})
source = source.encode('UTF-8') if source.respond_to?(:encode)
source = ExecJS.encode(source)

if /\S/ =~ source
unbox @v8_context.eval("(#{source})")
Expand Down
20 changes: 10 additions & 10 deletions lib/execjs/ruby_rhino_runtime.rb
Expand Up @@ -2,29 +2,29 @@ module ExecJS
class RubyRhinoRuntime
class Context
def initialize(source = "")
source = source.encode('UTF-8') if source.respond_to?(:encode)
source = ExecJS.encode(source)

@rhino_context = ::Rhino::Context.new
fix_memory_limit! @rhino_context
@rhino_context.eval(source)
end

def exec(source, options = {})
source = source.encode('UTF-8') if source.respond_to?(:encode)
source = ExecJS.encode(source)

if /\S/ =~ source
eval "(function(){#{source}})()", options
end
end

def eval(source, options = {})
source = source.encode('UTF-8') if source.respond_to?(:encode)
source = ExecJS.encode(source)

if /\S/ =~ source
unbox @rhino_context.eval("(#{source})")
end
rescue ::Rhino::JavascriptError => e
if e.message == "syntax error"
rescue ::Rhino::JSError => e
if e.message =~ /^syntax error/
raise RuntimeError, e.message
else
raise ProgramError, e.message
Expand All @@ -33,7 +33,7 @@ def eval(source, options = {})

def call(properties, *args)
unbox @rhino_context.eval(properties).call(*args)
rescue ::Rhino::JavascriptError => e
rescue ::Rhino::JSError => e
if e.message == "syntax error"
raise RuntimeError, e.message
else
Expand All @@ -42,13 +42,13 @@ def call(properties, *args)
end

def unbox(value)
case value = ::Rhino::To.ruby(value)
when ::Rhino::NativeFunction
case value = ::Rhino::to_ruby(value)
when Java::OrgMozillaJavascript::NativeFunction
nil
when ::Rhino::NativeObject
when Java::OrgMozillaJavascript::NativeObject
value.inject({}) do |vs, (k, v)|
case v
when ::Rhino::NativeFunction, ::Rhino::J::Function
when Java::OrgMozillaJavascript::NativeFunction, ::Rhino::JS::Function
nil
else
vs[k] = unbox(v)
Expand Down

0 comments on commit 4cd4e45

Please sign in to comment.