2012-04-13 14:32:31 -04:00
|
|
|
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
|
|
|
|
|
|
require 'redjs/load_specs'
|
|
|
|
|
|
|
|
puts "will run JavaScript specs from RedJS #{RedJS::VERSION}"
|
|
|
|
|
|
|
|
describe Rhino::Context do
|
|
|
|
|
|
|
|
it_behaves_like 'RedJS::Context'
|
2012-04-23 15:26:22 -04:00
|
|
|
|
|
|
|
# TODO: remove if present in RedJS
|
|
|
|
it "catched ScriptError in JS" do
|
|
|
|
klass = Class.new do
|
|
|
|
def muu(*args)
|
|
|
|
args && raise(ScriptError.new('muu'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
error = nil
|
|
|
|
lambda {
|
|
|
|
RedJS::Context.new do |cxt|
|
|
|
|
cxt['obj'] = klass.new
|
|
|
|
error = cxt.eval('var error; try { obj.muu(); error = null } catch(e) { error = e }')
|
|
|
|
end
|
|
|
|
}.should_not raise_error
|
|
|
|
error.should_not be nil
|
|
|
|
error.should be_a ScriptError
|
|
|
|
end
|
2012-04-13 14:32:31 -04:00
|
|
|
|
2012-04-21 13:56:05 -04:00
|
|
|
it "keeps objects iterable when property accessor is provided" do
|
|
|
|
klass = Class.new do
|
|
|
|
def [](name); name; end
|
|
|
|
attr_accessor :foo
|
|
|
|
def bar=(bar); bar; end
|
|
|
|
end
|
|
|
|
|
|
|
|
RedJS::Context.new do |cxt|
|
|
|
|
cxt['o'] = klass.new
|
|
|
|
cxt.eval('a = new Array(); for (var i in o) a.push(i);')
|
|
|
|
cxt['a'].length.should == 2 # [ 'foo', 'bar' ]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-13 14:32:31 -04:00
|
|
|
end
|