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

add Rhino.implementation_version for checking loaded jar

rhino 1.7R4 compatibility with prototype exposing (in specs)
This commit is contained in:
kares 2012-08-02 13:11:22 +02:00
parent e72152ea51
commit 0b55a51a91
2 changed files with 56 additions and 19 deletions

View file

@ -16,6 +16,23 @@ module Rhino
end
end
@@implementation_version = nil
# Helper to resolve what version of Rhino's .jar we're really using.
def self.implementation_version
@@implementation_version ||= begin
urls = JS::Kit.java_class.to_java.getClassLoader.
getResources('META-INF/MANIFEST.MF').to_a
rhino_jar_urls = urls.select { |url| url.toString.index(JAR_PATH) }
if rhino_jar_urls.empty?
raise "could not find #{JAR_PATH} manifest among: #{urls.map(&:toString).join(', ')}"
elsif rhino_jar_urls.size > 1
raise "could not find #{JAR_PATH} manifest among: #{urls.map(&:toString).join(', ')}"
end
manifest = java.util.jar.Manifest.new rhino_jar_urls.first.openStream
manifest.getMainAttributes.getValue 'Implementation-Version'
end
end
end
require 'rhino/version'

View file

@ -1,5 +1,19 @@
require File.expand_path('../spec_helper', File.dirname(__FILE__))
module RhinoHelpers
module_function
def add_prototype_key(hash, recurse = false)
hash['prototype'] ||= {}
hash.keys.each do |key|
val = hash[key] unless key == 'prototype'
add_prototype_key(val, recurse) if val.is_a?(Hash)
end if recurse
end
end
shared_examples_for 'ScriptableObject', :shared => true do
it "acts like a hash" do
@ -40,7 +54,7 @@ describe "NativeObject" do
end
describe "FunctionObject" do
before do
factory = Rhino::JS::ContextFactory.new
context, scope = nil, nil
@ -54,7 +68,9 @@ describe "FunctionObject" do
@object = Rhino::JS::FunctionObject.new('to_string', to_string, scope)
@object.instance_eval do
def to_h_properties
{ "arguments"=> nil, "prototype"=> {}, "name"=> "to_string", "arity"=> 0, "length"=> 0 }
h = { "arguments"=> nil, "name"=> "to_string", "arity"=> 0, "length"=> 0 }
RhinoHelpers.add_prototype_key(h) if Rhino.implementation_version < '1.7R4'
h
end
end
end
@ -115,7 +131,7 @@ describe "NativeObject (scoped)" do
end
describe "NativeFunction" do
before do
factory = Rhino::JS::ContextFactory.new
@context, @scope = nil, nil
@ -129,7 +145,9 @@ describe "NativeFunction" do
@object = Rhino::JS::ScriptableObject.getProperty(object, 'toString')
@object.instance_eval do
def to_h_properties
{ "arguments"=> nil, "prototype"=> {}, "name"=> "toString", "arity"=> 0, "length"=> 0 }
h = { "arguments"=> nil, "name"=> "toString", "arity"=> 0, "length"=> 0 }
RhinoHelpers.add_prototype_key(h) if Rhino.implementation_version < '1.7R4'
h
end
end
end
@ -187,7 +205,7 @@ describe "NativeFunction" do
end
describe "NativeFunction (constructor)" do
before do
factory = Rhino::JS::ContextFactory.new
context, scope = nil, nil
@ -200,23 +218,25 @@ describe "NativeFunction (constructor)" do
@object = Rhino::JS::ScriptableObject.getProperty(context.newObject(scope), 'constructor')
@object.instance_eval do
def to_h_properties
{
h = {
"arguments"=>nil, "prototype"=>{}, "name"=>"Object", "arity"=>1, "length"=>1,
"getPrototypeOf"=> { "arguments"=>nil, "prototype"=>{}, "name"=>"getPrototypeOf", "arity"=>1, "length"=>1},
"keys"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"keys", "arity"=>1, "length"=>1},
"getOwnPropertyNames"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"getOwnPropertyNames", "arity"=>1, "length"=>1},
"getOwnPropertyDescriptor"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"getOwnPropertyDescriptor", "arity"=>2, "length"=>2},
"defineProperty"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"defineProperty", "arity"=>3, "length"=>3},
"isExtensible"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"isExtensible", "arity"=>1, "length"=>1},
"preventExtensions"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"preventExtensions", "arity"=>1, "length"=>1},
"defineProperties"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"defineProperties", "arity"=>2, "length"=>2},
"create"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"create", "arity"=>2, "length"=>2},
"isSealed"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"isSealed", "arity"=>1, "length"=>1},
"isFrozen"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"isFrozen", "arity"=>1, "length"=>1},
"seal"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"seal", "arity"=>1, "length"=>1},
"freeze"=>{"arguments"=>nil, "prototype"=>{}, "name"=>"freeze", "arity"=>1, "length"=>1}
"getPrototypeOf"=> { "arguments"=>nil, "name"=>"getPrototypeOf", "arity"=>1, "length"=>1},
"keys"=>{"arguments"=>nil, "name"=>"keys", "arity"=>1, "length"=>1},
"getOwnPropertyNames"=>{"arguments"=>nil, "name"=>"getOwnPropertyNames", "arity"=>1, "length"=>1},
"getOwnPropertyDescriptor"=>{"arguments"=>nil, "name"=>"getOwnPropertyDescriptor", "arity"=>2, "length"=>2},
"defineProperty"=>{"arguments"=>nil, "name"=>"defineProperty", "arity"=>3, "length"=>3},
"isExtensible"=>{"arguments"=>nil, "name"=>"isExtensible", "arity"=>1, "length"=>1},
"preventExtensions"=>{"arguments"=>nil, "name"=>"preventExtensions", "arity"=>1, "length"=>1},
"defineProperties"=>{"arguments"=>nil, "name"=>"defineProperties", "arity"=>2, "length"=>2},
"create"=>{"arguments"=>nil, "name"=>"create", "arity"=>2, "length"=>2},
"isSealed"=>{"arguments"=>nil, "name"=>"isSealed", "arity"=>1, "length"=>1},
"isFrozen"=>{"arguments"=>nil, "name"=>"isFrozen", "arity"=>1, "length"=>1},
"seal"=>{"arguments"=>nil, "name"=>"seal", "arity"=>1, "length"=>1},
"freeze"=>{"arguments"=>nil, "name"=>"freeze", "arity"=>1, "length"=>1}
}
RhinoHelpers.add_prototype_key(h, :recurse) if Rhino.implementation_version < '1.7R4'
h
end
end
end