1
0
Fork 0
mirror of https://github.com/rubyjs/therubyrhino synced 2023-03-27 23:21:34 -04:00

1.7R4 added a ConsString for 's1' + 's2' optimalization

this is the cause of the reported regression (closes #25)
This commit is contained in:
kares 2012-08-24 11:54:49 +02:00
parent ebbbf6baf1
commit 6c84e6bf87
4 changed files with 27 additions and 32 deletions

View file

@ -8,6 +8,8 @@ module Rhino
when JS::Wrapper then object.unwrap
when JS::NativeArray then array_to_ruby(object)
when JS::NativeDate then Time.at(object.getJSTimeValue / 1000)
# Rhino 1.7R4 added ConsString for optimized String + operations :
when Java::JavaLang::CharSequence then object.toString
else object
end
end

View file

@ -1,5 +1,3 @@
var Loop = {};
Loop.toString = function() {
return 'Loop';
};
Loop = {};
Loop.toString = function() { return 'Loop'; };
exports.Loop = Loop;

View file

@ -4,7 +4,7 @@ require 'rhino'
require 'pathname'
require 'stringio'
puts "running with: #{Rhino::VERSION} using jar: #{Rhino::JAR_PATH}"
puts "Rhino #{Rhino::VERSION} (#{Rhino::JAR_PATH})"
describe 'integration' do
@ -26,9 +26,8 @@ describe 'integration' do
it "require index/loop" do # CommonJS
environment = new_environment(:console => Console)
exports = environment.require 'index'
exports.context['Loop'].should_not be nil
exports.context['Loop'].to_s.should == 'Loop'
environment.require 'index'
environment.context['Loop'].should_not be nil
end
private

View file

@ -5,53 +5,49 @@ describe Rhino::To do
describe "ruby translation" do
it "converts javascript NOT_FOUND to ruby nil" do
Rhino.to_ruby(Rhino::JS::Scriptable::NOT_FOUND).should be_nil
Rhino.to_ruby(Rhino::JS::Scriptable::NOT_FOUND).should be nil
end
it "converts javascript undefined into nil" do
Rhino.to_ruby(Rhino::JS::Undefined.instance).should be_nil
Rhino.to_ruby(Rhino::JS::Undefined.instance).should be nil
end
it "does return javascript object" do
Rhino::JS::NativeObject.new.tap do |js_obj|
Rhino.to_ruby(js_obj).tap do |rb_obj|
rb_obj.should be(js_obj)
end
Rhino.to_ruby(js_obj).should be(js_obj)
end
end
it "wraps native javascript arrays into a ruby NativeArray wrapper" do
Rhino::JS::NativeArray.new([1,2,4].to_java).tap do |js_array|
js_array = Rhino::JS::NativeArray.new([1,2,4].to_java)
Rhino.to_ruby(js_array).should == [1,2,4]
end
end
it "does return javascript function" do
it "returns a javascript function" do
klass = Class.new(Rhino::JS::BaseFunction)
klass.new.tap do |js_fn|
Rhino.to_ruby(js_fn).tap do |rb_fn|
rb_fn.should be(js_fn)
end
end
function = klass.new
Rhino.to_ruby(function).should be(function)
end
it "leaves native ruby objects alone" do
Object.new.tap do |o|
Rhino.to_ruby(o).should be(o)
end
obj = Object.new
Rhino.to_ruby(obj).should be(obj)
end
it "it unwraps wrapped java objects" do
Rhino::Context.open do |cx|
scope = cx.scope
j_str = java.lang.String.new("Hello World")
Rhino::JS::NativeJavaObject.new(scope, j_str, j_str.getClass()).tap do |o|
Rhino.to_ruby(o).should == "Hello World"
native_obj = Rhino::JS::NativeJavaObject.new(scope, j_str, j_str.getClass())
Rhino.to_ruby(native_obj).should == "Hello World"
end
end
if (Java::JavaClass.for_name('org.mozilla.javascript.ConsString') rescue nil)
it "converts a cons string" do
cons_string = org.mozilla.javascript.ConsString.new('1', '2')
Rhino.to_ruby(cons_string).should == '12'
end
end
end